From 815c89a44d662e55b7533d180c31baceef1161aa Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Thu, 17 Dec 2015 00:32:41 +0000 Subject: [PATCH] Migrated 6 network clients from tempest This migrates the above files from tempest. This includes tempest commits: * base.py : Icf9f6fa4ea52a1fe72253391abf4880b1f8ed497 * floating_ips_client.py : Iaeabf6cb827e4153d72353dab6d1d66f0f246eb6 * metering_label_rules_client.py: Iddecde5f6f5c1ac88a18d71aab1fc26370b26ba8 * metering_labels_client.py : I3364fc9320640b875f5232c2ae5a4ae98121d821 * networks_client.py : Iff82c07bae2b1c82e5ff914ca90fcf5fc7de8daa * ports_client.py : I1248cc6132f4a2e40ad13f6177c7ecda834db57d * subnets_client.py : I52c9d099b97540440fa98343c736b894d130a07e to see the commit history for these files refer to the above Change-Ids in the tempest repository. Partially implements blueprint migrate-service-clients-to-tempest-lib Change-Id: Ic840c3697f727612dfe754948e9a5890e7f2505d --- tempest_lib/services/network/__init__.py | 0 tempest_lib/services/network/base.py | 71 +++++++++++++++++++ .../services/network/floating_ips_client.py | 38 ++++++++++ .../network/metering_label_rules_client.py | 33 +++++++++ .../network/metering_labels_client.py | 33 +++++++++ .../services/network/networks_client.py | 38 ++++++++++ tempest_lib/services/network/ports_client.py | 38 ++++++++++ .../services/network/subnets_client.py | 38 ++++++++++ 8 files changed, 289 insertions(+) create mode 100644 tempest_lib/services/network/__init__.py create mode 100644 tempest_lib/services/network/base.py create mode 100644 tempest_lib/services/network/floating_ips_client.py create mode 100644 tempest_lib/services/network/metering_label_rules_client.py create mode 100644 tempest_lib/services/network/metering_labels_client.py create mode 100644 tempest_lib/services/network/networks_client.py create mode 100644 tempest_lib/services/network/ports_client.py create mode 100644 tempest_lib/services/network/subnets_client.py diff --git a/tempest_lib/services/network/__init__.py b/tempest_lib/services/network/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tempest_lib/services/network/base.py b/tempest_lib/services/network/base.py new file mode 100644 index 0000000..063e436 --- /dev/null +++ b/tempest_lib/services/network/base.py @@ -0,0 +1,71 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_serialization import jsonutils as json +from six.moves.urllib import parse as urllib + +from tempest_lib.common import rest_client + + +class BaseNetworkClient(rest_client.RestClient): + + """Base class for Tempest REST clients for Neutron. + + Child classes use v2 of the Neutron API, since the V1 API has been + removed from the code base. + """ + + version = '2.0' + uri_prefix = "v2.0" + + def list_resources(self, uri, **filters): + req_uri = self.uri_prefix + uri + if filters: + req_uri += '?' + urllib.urlencode(filters, doseq=1) + resp, body = self.get(req_uri) + body = json.loads(body) + self.expected_success(200, resp.status) + return rest_client.ResponseBody(resp, body) + + def delete_resource(self, uri): + req_uri = self.uri_prefix + uri + resp, body = self.delete(req_uri) + self.expected_success(204, resp.status) + return rest_client.ResponseBody(resp, body) + + def show_resource(self, uri, **fields): + # fields is a dict which key is 'fields' and value is a + # list of field's name. An example: + # {'fields': ['id', 'name']} + req_uri = self.uri_prefix + uri + if fields: + req_uri += '?' + urllib.urlencode(fields, doseq=1) + resp, body = self.get(req_uri) + body = json.loads(body) + self.expected_success(200, resp.status) + return rest_client.ResponseBody(resp, body) + + def create_resource(self, uri, post_data): + req_uri = self.uri_prefix + uri + req_post_data = json.dumps(post_data) + resp, body = self.post(req_uri, req_post_data) + body = json.loads(body) + self.expected_success(201, resp.status) + return rest_client.ResponseBody(resp, body) + + def update_resource(self, uri, post_data): + req_uri = self.uri_prefix + uri + req_post_data = json.dumps(post_data) + resp, body = self.put(req_uri, req_post_data) + body = json.loads(body) + self.expected_success(200, resp.status) + return rest_client.ResponseBody(resp, body) diff --git a/tempest_lib/services/network/floating_ips_client.py b/tempest_lib/services/network/floating_ips_client.py new file mode 100644 index 0000000..2ab9d7c --- /dev/null +++ b/tempest_lib/services/network/floating_ips_client.py @@ -0,0 +1,38 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest_lib.services.network import base + + +class FloatingIPsClient(base.BaseNetworkClient): + + def create_floatingip(self, **kwargs): + uri = '/floatingips' + post_data = {'floatingip': kwargs} + return self.create_resource(uri, post_data) + + def update_floatingip(self, floatingip_id, **kwargs): + uri = '/floatingips/%s' % floatingip_id + post_data = {'floatingip': kwargs} + return self.update_resource(uri, post_data) + + def show_floatingip(self, floatingip_id, **fields): + uri = '/floatingips/%s' % floatingip_id + return self.show_resource(uri, **fields) + + def delete_floatingip(self, floatingip_id): + uri = '/floatingips/%s' % floatingip_id + return self.delete_resource(uri) + + def list_floatingips(self, **filters): + uri = '/floatingips' + return self.list_resources(uri, **filters) diff --git a/tempest_lib/services/network/metering_label_rules_client.py b/tempest_lib/services/network/metering_label_rules_client.py new file mode 100644 index 0000000..5ddea0b --- /dev/null +++ b/tempest_lib/services/network/metering_label_rules_client.py @@ -0,0 +1,33 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest_lib.services.network import base + + +class MeteringLabelRulesClient(base.BaseNetworkClient): + + def create_metering_label_rule(self, **kwargs): + uri = '/metering/metering-label-rules' + post_data = {'metering_label_rule': kwargs} + return self.create_resource(uri, post_data) + + def show_metering_label_rule(self, metering_label_rule_id, **fields): + uri = '/metering/metering-label-rules/%s' % metering_label_rule_id + return self.show_resource(uri, **fields) + + def delete_metering_label_rule(self, metering_label_rule_id): + uri = '/metering/metering-label-rules/%s' % metering_label_rule_id + return self.delete_resource(uri) + + def list_metering_label_rules(self, **filters): + uri = '/metering/metering-label-rules' + return self.list_resources(uri, **filters) diff --git a/tempest_lib/services/network/metering_labels_client.py b/tempest_lib/services/network/metering_labels_client.py new file mode 100644 index 0000000..e71e4ce --- /dev/null +++ b/tempest_lib/services/network/metering_labels_client.py @@ -0,0 +1,33 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest_lib.services.network import base + + +class MeteringLabelsClient(base.BaseNetworkClient): + + def create_metering_label(self, **kwargs): + uri = '/metering/metering-labels' + post_data = {'metering_label': kwargs} + return self.create_resource(uri, post_data) + + def show_metering_label(self, metering_label_id, **fields): + uri = '/metering/metering-labels/%s' % metering_label_id + return self.show_resource(uri, **fields) + + def delete_metering_label(self, metering_label_id): + uri = '/metering/metering-labels/%s' % metering_label_id + return self.delete_resource(uri) + + def list_metering_labels(self, **filters): + uri = '/metering/metering-labels' + return self.list_resources(uri, **filters) diff --git a/tempest_lib/services/network/networks_client.py b/tempest_lib/services/network/networks_client.py new file mode 100644 index 0000000..71699db --- /dev/null +++ b/tempest_lib/services/network/networks_client.py @@ -0,0 +1,38 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest_lib.services.network import base + + +class NetworksClient(base.BaseNetworkClient): + + def create_network(self, **kwargs): + uri = '/networks' + post_data = {'network': kwargs} + return self.create_resource(uri, post_data) + + def update_network(self, network_id, **kwargs): + uri = '/networks/%s' % network_id + post_data = {'network': kwargs} + return self.update_resource(uri, post_data) + + def show_network(self, network_id, **fields): + uri = '/networks/%s' % network_id + return self.show_resource(uri, **fields) + + def delete_network(self, network_id): + uri = '/networks/%s' % network_id + return self.delete_resource(uri) + + def list_networks(self, **filters): + uri = '/networks' + return self.list_resources(uri, **filters) diff --git a/tempest_lib/services/network/ports_client.py b/tempest_lib/services/network/ports_client.py new file mode 100644 index 0000000..92bf07b --- /dev/null +++ b/tempest_lib/services/network/ports_client.py @@ -0,0 +1,38 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest_lib.services.network import base + + +class PortsClient(base.BaseNetworkClient): + + def create_port(self, **kwargs): + uri = '/ports' + post_data = {'port': kwargs} + return self.create_resource(uri, post_data) + + def update_port(self, port_id, **kwargs): + uri = '/ports/%s' % port_id + post_data = {'port': kwargs} + return self.update_resource(uri, post_data) + + def show_port(self, port_id, **fields): + uri = '/ports/%s' % port_id + return self.show_resource(uri, **fields) + + def delete_port(self, port_id): + uri = '/ports/%s' % port_id + return self.delete_resource(uri) + + def list_ports(self, **filters): + uri = '/ports' + return self.list_resources(uri, **filters) diff --git a/tempest_lib/services/network/subnets_client.py b/tempest_lib/services/network/subnets_client.py new file mode 100644 index 0000000..f824d48 --- /dev/null +++ b/tempest_lib/services/network/subnets_client.py @@ -0,0 +1,38 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest_lib.services.network import base + + +class SubnetsClient(base.BaseNetworkClient): + + def create_subnet(self, **kwargs): + uri = '/subnets' + post_data = {'subnet': kwargs} + return self.create_resource(uri, post_data) + + def update_subnet(self, subnet_id, **kwargs): + uri = '/subnets/%s' % subnet_id + post_data = {'subnet': kwargs} + return self.update_resource(uri, post_data) + + def show_subnet(self, subnet_id, **fields): + uri = '/subnets/%s' % subnet_id + return self.show_resource(uri, **fields) + + def delete_subnet(self, subnet_id): + uri = '/subnets/%s' % subnet_id + return self.delete_resource(uri) + + def list_subnets(self, **filters): + uri = '/subnets' + return self.list_resources(uri, **filters)