From 47a4ff8ccb840927f0b5688cca9de126d6b92e35 Mon Sep 17 00:00:00 2001 From: Ann Kamyshnikova Date: Mon, 17 Mar 2014 12:48:57 +0400 Subject: [PATCH] Refactor create_ and update_ methods for floating ips create_floating_ip and update_floating_ip was updated to use _create and _update from network_client_base. Change-Id: I26ff2463a0c8cdbe58fde0cc0df89671a5281de0 --- tempest/api/network/base.py | 9 +++-- tempest/api/network/test_floating_ips.py | 35 +++++++++++++------ .../services/network/json/network_client.py | 19 ---------- .../services/network/network_client_base.py | 1 - .../services/network/xml/network_client.py | 27 -------------- 5 files changed, 28 insertions(+), 63 deletions(-) diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py index 231c4bf866..afd2d27776 100644 --- a/tempest/api/network/base.py +++ b/tempest/api/network/base.py @@ -90,7 +90,7 @@ class BaseNetworkTest(tempest.test.BaseTestCase): cls.client.delete_vpnservice(vpnservice['id']) # Clean up floating IPs for floating_ip in cls.floating_ips: - cls.client.delete_floating_ip(floating_ip['id']) + cls.client.delete_floatingip(floating_ip['id']) # Clean up routers for router in cls.routers: resp, body = cls.client.list_router_interfaces(router['id']) @@ -193,11 +193,10 @@ class BaseNetworkTest(tempest.test.BaseTestCase): return router @classmethod - def create_floating_ip(cls, external_network_id, **kwargs): + def create_floatingip(cls, external_network_id): """Wrapper utility that returns a test floating IP.""" - resp, body = cls.client.create_floating_ip( - external_network_id, - **kwargs) + resp, body = cls.client.create_floatingip( + floating_network_id=external_network_id) fip = body['floatingip'] cls.floating_ips.append(fip) return fip diff --git a/tempest/api/network/test_floating_ips.py b/tempest/api/network/test_floating_ips.py index b31c09058b..06871ad0d2 100644 --- a/tempest/api/network/test_floating_ips.py +++ b/tempest/api/network/test_floating_ips.py @@ -65,8 +65,12 @@ class FloatingIPTestJSON(base.BaseNetworkTest): @test.attr(type='smoke') def test_create_list_show_update_delete_floating_ip(self): # Creates a floating IP - created_floating_ip = self.create_floating_ip( - self.ext_net_id, port_id=self.ports[0]['id']) + resp, body = self.client.create_floatingip( + floating_network_id=self.ext_net_id, port_id=self.ports[0]['id']) + self.assertEqual('201', resp['status']) + created_floating_ip = body['floatingip'] + self.addCleanup(self.client.delete_floatingip, + created_floating_ip['id']) self.assertIsNotNone(created_floating_ip['id']) self.assertIsNotNone(created_floating_ip['tenant_id']) self.assertIsNotNone(created_floating_ip['floating_ip_address']) @@ -74,7 +78,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest): self.assertEqual(created_floating_ip['floating_network_id'], self.ext_net_id) # Verifies the details of a floating_ip - resp, floating_ip = self.client.show_floating_ip( + resp, floating_ip = self.client.show_floatingip( created_floating_ip['id']) self.assertEqual('200', resp['status']) shown_floating_ip = floating_ip['floatingip'] @@ -95,7 +99,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest): floatingip_id_list.append(f['id']) self.assertIn(created_floating_ip['id'], floatingip_id_list) # Associate floating IP to the other port - resp, floating_ip = self.client.update_floating_ip( + resp, floating_ip = self.client.update_floatingip( created_floating_ip['id'], port_id=self.ports[1]['id']) self.assertEqual('200', resp['status']) updated_floating_ip = floating_ip['floatingip'] @@ -105,7 +109,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest): self.assertEqual(updated_floating_ip['router_id'], self.router['id']) # Disassociate floating IP from the port - resp, floating_ip = self.client.update_floating_ip( + resp, floating_ip = self.client.update_floatingip( created_floating_ip['id'], port_id=None) self.assertEqual('200', resp['status']) updated_floating_ip = floating_ip['floatingip'] @@ -116,17 +120,22 @@ class FloatingIPTestJSON(base.BaseNetworkTest): @test.attr(type='smoke') def test_floating_ip_delete_port(self): # Create a floating IP - created_floating_ip = self.create_floating_ip(self.ext_net_id) + resp, body = self.client.create_floatingip( + floating_network_id=self.ext_net_id) + self.assertEqual('201', resp['status']) + created_floating_ip = body['floatingip'] + self.addCleanup(self.client.delete_floatingip, + created_floating_ip['id']) # Create a port resp, port = self.client.create_port(network_id=self.network['id']) created_port = port['port'] - resp, floating_ip = self.client.update_floating_ip( + resp, floating_ip = self.client.update_floatingip( created_floating_ip['id'], port_id=created_port['id']) self.assertEqual('200', resp['status']) # Delete port self.client.delete_port(created_port['id']) # Verifies the details of the floating_ip - resp, floating_ip = self.client.show_floating_ip( + resp, floating_ip = self.client.show_floatingip( created_floating_ip['id']) self.assertEqual('200', resp['status']) shown_floating_ip = floating_ip['floatingip'] @@ -139,8 +148,12 @@ class FloatingIPTestJSON(base.BaseNetworkTest): @test.attr(type='smoke') def test_floating_ip_update_different_router(self): # Associate a floating IP to a port on a router - created_floating_ip = self.create_floating_ip( - self.ext_net_id, port_id=self.ports[1]['id']) + resp, body = self.client.create_floatingip( + floating_network_id=self.ext_net_id, port_id=self.ports[1]['id']) + self.assertEqual('201', resp['status']) + created_floating_ip = body['floatingip'] + self.addCleanup(self.client.delete_floatingip, + created_floating_ip['id']) self.assertEqual(created_floating_ip['router_id'], self.router['id']) network2 = self.create_network() subnet2 = self.create_subnet(network2) @@ -149,7 +162,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest): self.create_router_interface(router2['id'], subnet2['id']) port_other_router = self.create_port(network2) # Associate floating IP to the other port on another router - resp, floating_ip = self.client.update_floating_ip( + resp, floating_ip = self.client.update_floatingip( created_floating_ip['id'], port_id=port_other_router['id']) self.assertEqual('200', resp['status']) updated_floating_ip = floating_ip['floatingip'] diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py index a804e8e68e..27f4655ce6 100644 --- a/tempest/services/network/json/network_client.py +++ b/tempest/services/network/json/network_client.py @@ -144,25 +144,6 @@ class NetworkClientJSON(network_client_base.NetworkClientBase): body = json.loads(body) return resp, body - def create_floating_ip(self, ext_network_id, **kwargs): - post_body = { - 'floatingip': kwargs} - post_body['floatingip']['floating_network_id'] = ext_network_id - body = json.dumps(post_body) - uri = '%s/floatingips' % (self.uri_prefix) - resp, body = self.post(uri, body=body) - body = json.loads(body) - return resp, body - - def update_floating_ip(self, floating_ip_id, **kwargs): - post_body = { - 'floatingip': kwargs} - body = json.dumps(post_body) - uri = '%s/floatingips/%s' % (self.uri_prefix, floating_ip_id) - resp, body = self.put(uri, body) - body = json.loads(body) - return resp, body - def associate_health_monitor_with_pool(self, health_monitor_id, pool_id): post_body = { diff --git a/tempest/services/network/network_client_base.py b/tempest/services/network/network_client_base.py index 41a7aa49db..e21abe1c41 100644 --- a/tempest/services/network/network_client_base.py +++ b/tempest/services/network/network_client_base.py @@ -44,7 +44,6 @@ resource_plural_map = { 'security_groups': 'security_groups', 'security_group_rules': 'security_group_rules', 'ikepolicy': 'ikepolicies', - 'floating_ip': 'floatingips', 'quotas': 'quotas' } diff --git a/tempest/services/network/xml/network_client.py b/tempest/services/network/xml/network_client.py index 2a5083c2a8..68bc4247c2 100644 --- a/tempest/services/network/xml/network_client.py +++ b/tempest/services/network/xml/network_client.py @@ -166,33 +166,6 @@ class NetworkClientXML(client_base.NetworkClientBase): body = _root_tag_fetcher_and_xml_to_json_parse(body) return resp, body - def create_floating_ip(self, ext_network_id, **kwargs): - uri = '%s/floatingips' % (self.uri_prefix) - floatingip = common.Element('floatingip') - floatingip.append(common.Element("floating_network_id", - ext_network_id)) - for element, content in kwargs.iteritems(): - floatingip.append(common.Element(element, content)) - resp, body = self.post(uri, str(common.Document(floatingip))) - body = _root_tag_fetcher_and_xml_to_json_parse(body) - return resp, body - - def update_floating_ip(self, floating_ip_id, **kwargs): - uri = '%s/floatingips/%s' % (self.uri_prefix, floating_ip_id) - floatingip = common.Element('floatingip') - floatingip.add_attr('xmlns:xsi', - 'http://www.w3.org/2001/XMLSchema-instance') - for element, content in kwargs.iteritems(): - if content is None: - xml_elem = common.Element(element) - xml_elem.add_attr("xsi:nil", "true") - floatingip.append(xml_elem) - else: - floatingip.append(common.Element(element, content)) - resp, body = self.put(uri, str(common.Document(floatingip))) - body = _root_tag_fetcher_and_xml_to_json_parse(body) - return resp, body - def list_router_interfaces(self, uuid): uri = '%s/ports?device_id=%s' % (self.uri_prefix, uuid) resp, body = self.get(uri)