From 49c0fe5630d0eb8dbc95b2df8f147fa3a33830ca Mon Sep 17 00:00:00 2001 From: John Warren Date: Thu, 22 Oct 2015 12:35:54 -0400 Subject: [PATCH] Split out Neutron ports client Splitting out a ports client for Neutron. Partially implements blueprint consistent-service-method-names Change-Id: I1248cc6132f4a2e40ad13f6177c7ecda834db57d --- .../admin/test_dhcp_agent_scheduler.py | 2 +- .../admin/test_external_networks_negative.py | 2 +- tempest/api/network/base.py | 12 +-- .../api/network/test_allowed_address_pair.py | 16 ++-- tempest/api/network/test_dhcp_ipv6.py | 10 +-- .../api/network/test_extra_dhcp_options.py | 10 +-- tempest/api/network/test_floating_ips.py | 10 +-- tempest/api/network/test_networks.py | 6 +- tempest/api/network/test_networks_negative.py | 9 +- tempest/api/network/test_ports.py | 87 ++++++++++--------- tempest/api/network/test_routers.py | 12 +-- .../stacks/test_neutron_resources.py | 2 +- tempest/clients.py | 9 ++ tempest/cmd/cleanup_service.py | 5 +- tempest/common/dynamic_creds.py | 7 +- tempest/scenario/manager.py | 13 +-- tempest/scenario/test_baremetal_basic_ops.py | 2 +- tempest/scenario/test_network_basic_ops.py | 10 +-- .../test_security_groups_basic_ops.py | 15 ++-- .../services/network/json/network_client.py | 32 ++----- tempest/services/network/json/ports_client.py | 38 ++++++++ tempest/services/network/resources.py | 3 +- tempest/tests/common/test_dynamic_creds.py | 2 +- 23 files changed, 176 insertions(+), 138 deletions(-) create mode 100644 tempest/services/network/json/ports_client.py diff --git a/tempest/api/network/admin/test_dhcp_agent_scheduler.py b/tempest/api/network/admin/test_dhcp_agent_scheduler.py index 86b49732ed..7692b561df 100644 --- a/tempest/api/network/admin/test_dhcp_agent_scheduler.py +++ b/tempest/api/network/admin/test_dhcp_agent_scheduler.py @@ -61,7 +61,7 @@ class DHCPAgentSchedulersTestJSON(base.BaseAdminNetworkTest): @test.idempotent_id('a0856713-6549-470c-a656-e97c8df9a14d') def test_add_remove_network_from_dhcp_agent(self): # The agent is now bound to the network, we can free the port - self.client.delete_port(self.port['id']) + self.ports_client.delete_port(self.port['id']) self.ports.remove(self.port) agent = dict() agent['agent_type'] = None diff --git a/tempest/api/network/admin/test_external_networks_negative.py b/tempest/api/network/admin/test_external_networks_negative.py index c2fa0dd679..8dfce248f2 100644 --- a/tempest/api/network/admin/test_external_networks_negative.py +++ b/tempest/api/network/admin/test_external_networks_negative.py @@ -49,6 +49,6 @@ class ExternalNetworksAdminNegativeTestJSON(base.BaseAdminNetworkTest): # create a port which will internally create an instance-ip self.assertRaises(lib_exc.Conflict, - client.create_port, + self.admin_ports_client.create_port, network_id=CONF.network.public_network_id, fixed_ips=fixed_ips) diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py index 17adfa5ffb..5198ae8ba7 100644 --- a/tempest/api/network/base.py +++ b/tempest/api/network/base.py @@ -75,6 +75,7 @@ class BaseNetworkTest(tempest.test.BaseTestCase): cls.client = cls.os.network_client cls.networks_client = cls.os.networks_client cls.subnets_client = cls.os.subnets_client + cls.ports_client = cls.os.ports_client @classmethod def resource_setup(cls): @@ -108,7 +109,7 @@ class BaseNetworkTest(tempest.test.BaseTestCase): metering_label['id']) # Clean up ports for port in cls.ports: - cls._try_delete_resource(cls.client.delete_port, + cls._try_delete_resource(cls.ports_client.delete_port, port['id']) # Clean up routers for router in cls.routers: @@ -201,8 +202,8 @@ class BaseNetworkTest(tempest.test.BaseTestCase): @classmethod def create_port(cls, network, **kwargs): """Wrapper utility that returns a test port.""" - body = cls.client.create_port(network_id=network['id'], - **kwargs) + body = cls.ports_client.create_port(network_id=network['id'], + **kwargs) port = body['port'] cls.ports.append(port) return port @@ -210,8 +211,8 @@ class BaseNetworkTest(tempest.test.BaseTestCase): @classmethod def update_port(cls, port, **kwargs): """Wrapper utility that updates a test port.""" - body = cls.client.update_port(port['id'], - **kwargs) + body = cls.ports_client.update_port(port['id'], + **kwargs) return body['port'] @classmethod @@ -269,6 +270,7 @@ class BaseAdminNetworkTest(BaseNetworkTest): cls.admin_client = cls.os_adm.network_client cls.admin_networks_client = cls.os_adm.networks_client cls.admin_subnets_client = cls.os_adm.subnets_client + cls.admin_ports_client = cls.os_adm.ports_client @classmethod def create_metering_label(cls, name, description): diff --git a/tempest/api/network/test_allowed_address_pair.py b/tempest/api/network/test_allowed_address_pair.py index 5d7f00e025..41714aa9b8 100644 --- a/tempest/api/network/test_allowed_address_pair.py +++ b/tempest/api/network/test_allowed_address_pair.py @@ -60,14 +60,14 @@ class AllowedAddressPairTestJSON(base.BaseNetworkTest): # Create port with allowed address pair attribute allowed_address_pairs = [{'ip_address': self.ip_address, 'mac_address': self.mac_address}] - body = self.client.create_port( + body = self.ports_client.create_port( network_id=self.network['id'], allowed_address_pairs=allowed_address_pairs) port_id = body['port']['id'] - self.addCleanup(self.client.delete_port, port_id) + self.addCleanup(self.ports_client.delete_port, port_id) # Confirm port was created with allowed address pair attribute - body = self.client.list_ports() + body = self.ports_client.list_ports() ports = body['ports'] port = [p for p in ports if p['id'] == port_id] msg = 'Created port not found in list of ports returned by Neutron' @@ -76,9 +76,9 @@ class AllowedAddressPairTestJSON(base.BaseNetworkTest): def _update_port_with_address(self, address, mac_address=None, **kwargs): # Create a port without allowed address pair - body = self.client.create_port(network_id=self.network['id']) + body = self.ports_client.create_port(network_id=self.network['id']) port_id = body['port']['id'] - self.addCleanup(self.client.delete_port, port_id) + self.addCleanup(self.ports_client.delete_port, port_id) if mac_address is None: mac_address = self.mac_address @@ -87,7 +87,7 @@ class AllowedAddressPairTestJSON(base.BaseNetworkTest): 'mac_address': mac_address}] if kwargs: allowed_address_pairs.append(kwargs['allowed_address_pairs']) - body = self.client.update_port( + body = self.ports_client.update_port( port_id, allowed_address_pairs=allowed_address_pairs) allowed_address_pair = body['port']['allowed_address_pairs'] self.assertEqual(allowed_address_pair, allowed_address_pairs) @@ -106,9 +106,9 @@ class AllowedAddressPairTestJSON(base.BaseNetworkTest): @test.idempotent_id('b3f20091-6cd5-472b-8487-3516137df933') def test_update_port_with_multiple_ip_mac_address_pair(self): # Create an ip _address and mac_address through port create - resp = self.client.create_port(network_id=self.network['id']) + resp = self.ports_client.create_port(network_id=self.network['id']) newportid = resp['port']['id'] - self.addCleanup(self.client.delete_port, newportid) + self.addCleanup(self.ports_client.delete_port, newportid) ipaddress = resp['port']['fixed_ips'][0]['ip_address'] macaddress = resp['port']['mac_address'] diff --git a/tempest/api/network/test_dhcp_ipv6.py b/tempest/api/network/test_dhcp_ipv6.py index 631a38bcc7..27713a2ae8 100644 --- a/tempest/api/network/test_dhcp_ipv6.py +++ b/tempest/api/network/test_dhcp_ipv6.py @@ -63,7 +63,7 @@ class NetworksTestDHCPv6(base.BaseNetworkTest): del things_list[index] def _clean_network(self): - body = self.client.list_ports() + body = self.ports_client.list_ports() ports = body['ports'] for port in ports: if (port['device_owner'].startswith('network:router_interface') @@ -73,7 +73,7 @@ class NetworksTestDHCPv6(base.BaseNetworkTest): ) else: if port['id'] in [p['id'] for p in self.ports]: - self.client.delete_port(port['id']) + self.ports_client.delete_port(port['id']) self._remove_from_list_by_index(self.ports, port) body = self.subnets_client.list_subnets() subnets = body['subnets'] @@ -203,9 +203,9 @@ class NetworksTestDHCPv6(base.BaseNetworkTest): real_dhcp_ip, real_eui_ip = [real_ips[sub['id']] for sub in [subnet_dhcp, subnet_slaac]] - self.client.delete_port(port['id']) + self.ports_client.delete_port(port['id']) self.ports.pop() - body = self.client.list_ports() + body = self.ports_client.list_ports() ports_id_list = [i['id'] for i in body['ports']] self.assertNotIn(port['id'], ports_id_list) self._clean_network() @@ -362,7 +362,7 @@ class NetworksTestDHCPv6(base.BaseNetworkTest): admin_state_up=True) port = self.create_router_interface(router['id'], subnet['id']) - body = self.client.show_port(port['port_id']) + body = self.ports_client.show_port(port['port_id']) return subnet, body['port'] @test.idempotent_id('e98f65db-68f4-4330-9fea-abd8c5192d4d') diff --git a/tempest/api/network/test_extra_dhcp_options.py b/tempest/api/network/test_extra_dhcp_options.py index 87e3413af9..7924f387c0 100644 --- a/tempest/api/network/test_extra_dhcp_options.py +++ b/tempest/api/network/test_extra_dhcp_options.py @@ -59,14 +59,14 @@ class ExtraDHCPOptionsTestJSON(base.BaseNetworkTest): @test.idempotent_id('d2c17063-3767-4a24-be4f-a23dbfa133c9') def test_create_list_port_with_extra_dhcp_options(self): # Create a port with Extra DHCP Options - body = self.client.create_port( + body = self.ports_client.create_port( network_id=self.network['id'], extra_dhcp_opts=self.extra_dhcp_opts) port_id = body['port']['id'] - self.addCleanup(self.client.delete_port, port_id) + self.addCleanup(self.ports_client.delete_port, port_id) # Confirm port created has Extra DHCP Options - body = self.client.list_ports() + body = self.ports_client.list_ports() ports = body['ports'] port = [p for p in ports if p['id'] == port_id] self.assertTrue(port) @@ -76,12 +76,12 @@ class ExtraDHCPOptionsTestJSON(base.BaseNetworkTest): def test_update_show_port_with_extra_dhcp_options(self): # Update port with extra dhcp options name = data_utils.rand_name('new-port-name') - body = self.client.update_port( + body = self.ports_client.update_port( self.port['id'], name=name, extra_dhcp_opts=self.extra_dhcp_opts) # Confirm extra dhcp options were added to the port - body = self.client.show_port(self.port['id']) + body = self.ports_client.show_port(self.port['id']) self._confirm_extra_dhcp_options(body['port'], self.extra_dhcp_opts) def _confirm_extra_dhcp_options(self, port, extra_dhcp_opts): diff --git a/tempest/api/network/test_floating_ips.py b/tempest/api/network/test_floating_ips.py index 4b4a4e279e..b7963114b3 100644 --- a/tempest/api/network/test_floating_ips.py +++ b/tempest/api/network/test_floating_ips.py @@ -130,13 +130,13 @@ class FloatingIPTestJSON(base.BaseNetworkTest): self.addCleanup(self.client.delete_floatingip, created_floating_ip['id']) # Create a port - port = self.client.create_port(network_id=self.network['id']) + port = self.ports_client.create_port(network_id=self.network['id']) created_port = port['port'] floating_ip = self.client.update_floatingip( created_floating_ip['id'], port_id=created_port['id']) # Delete port - self.client.delete_port(created_port['id']) + self.ports_client.delete_port(created_port['id']) # Verifies the details of the floating_ip floating_ip = self.client.show_floatingip(created_floating_ip['id']) shown_floating_ip = floating_ip['floatingip'] @@ -197,10 +197,10 @@ class FloatingIPTestJSON(base.BaseNetworkTest): list_ips = [str(ip) for ip in ips[-3:-1]] fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}] # Create port - body = self.client.create_port(network_id=self.network['id'], - fixed_ips=fixed_ips) + body = self.ports_client.create_port(network_id=self.network['id'], + fixed_ips=fixed_ips) port = body['port'] - self.addCleanup(self.client.delete_port, port['id']) + self.addCleanup(self.ports_client.delete_port, port['id']) # Create floating ip body = self.client.create_floatingip( floating_network_id=self.ext_net_id, diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py index c5b2080b3c..5039a69422 100644 --- a/tempest/api/network/test_networks.py +++ b/tempest/api/network/test_networks.py @@ -444,9 +444,9 @@ class BulkNetworkOpsTestJSON(base.BaseNetworkTest): def _delete_ports(self, created_ports): for n in created_ports: - self.client.delete_port(n['id']) + self.ports_client.delete_port(n['id']) # Asserting that the ports are not found in the list after deletion - body = self.client.list_ports() + body = self.ports_client.list_ports() ports_list = [port['id'] for port in body['ports']] for n in created_ports: self.assertNotIn(n['id'], ports_list) @@ -522,7 +522,7 @@ class BulkNetworkOpsTestJSON(base.BaseNetworkTest): created_ports = body['ports'] self.addCleanup(self._delete_ports, created_ports) # Asserting that the ports are found in the list after creation - body = self.client.list_ports() + body = self.ports_client.list_ports() ports_list = [port['id'] for port in body['ports']] for n in created_ports: self.assertIsNotNone(n['id']) diff --git a/tempest/api/network/test_networks_negative.py b/tempest/api/network/test_networks_negative.py index 4fe31cf20a..0ef96a6637 100644 --- a/tempest/api/network/test_networks_negative.py +++ b/tempest/api/network/test_networks_negative.py @@ -41,7 +41,7 @@ class NetworksNegativeTestJSON(base.BaseNetworkTest): @test.idempotent_id('a954861d-cbfd-44e8-b0a9-7fab111f235d') def test_show_non_existent_port(self): non_exist_id = data_utils.rand_uuid() - self.assertRaises(lib_exc.NotFound, self.client.show_port, + self.assertRaises(lib_exc.NotFound, self.ports_client.show_port, non_exist_id) @test.attr(type=['negative']) @@ -79,13 +79,14 @@ class NetworksNegativeTestJSON(base.BaseNetworkTest): def test_create_port_on_non_existent_network(self): non_exist_net_id = data_utils.rand_uuid() self.assertRaises(lib_exc.NotFound, - self.client.create_port, network_id=non_exist_net_id) + self.ports_client.create_port, + network_id=non_exist_net_id) @test.attr(type=['negative']) @test.idempotent_id('cf8eef21-4351-4f53-adcd-cc5cb1e76b92') def test_update_non_existent_port(self): non_exist_port_id = data_utils.rand_uuid() - self.assertRaises(lib_exc.NotFound, self.client.update_port, + self.assertRaises(lib_exc.NotFound, self.ports_client.update_port, non_exist_port_id, name='new_name') @test.attr(type=['negative']) @@ -93,4 +94,4 @@ class NetworksNegativeTestJSON(base.BaseNetworkTest): def test_delete_non_existent_port(self): non_exist_port_id = data_utils.rand_uuid() self.assertRaises(lib_exc.NotFound, - self.client.delete_port, non_exist_port_id) + self.ports_client.delete_port, non_exist_port_id) diff --git a/tempest/api/network/test_ports.py b/tempest/api/network/test_ports.py index 6f58075673..d0ed1f263b 100644 --- a/tempest/api/network/test_ports.py +++ b/tempest/api/network/test_ports.py @@ -45,8 +45,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): cls.port = cls.create_port(cls.network) def _delete_port(self, port_id): - self.client.delete_port(port_id) - body = self.client.list_ports() + self.ports_client.delete_port(port_id) + body = self.ports_client.list_ports() ports_list = body['ports'] self.assertFalse(port_id in [n['id'] for n in ports_list]) @@ -54,16 +54,16 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): @test.idempotent_id('c72c1c0c-2193-4aca-aaa4-b1442640f51c') def test_create_update_delete_port(self): # Verify port creation - body = self.client.create_port(network_id=self.network['id']) + body = self.ports_client.create_port(network_id=self.network['id']) port = body['port'] # Schedule port deletion with verification upon test completion self.addCleanup(self._delete_port, port['id']) self.assertTrue(port['admin_state_up']) # Verify port update new_name = "New_Port" - body = self.client.update_port(port['id'], - name=new_name, - admin_state_up=False) + body = self.ports_client.update_port(port['id'], + name=new_name, + admin_state_up=False) updated_port = body['port'] self.assertEqual(updated_port['name'], new_name) self.assertFalse(updated_port['admin_state_up']) @@ -107,8 +107,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): 'end': str(address + 6)}]} subnet = self.create_subnet(network, **allocation_pools) self.addCleanup(self.subnets_client.delete_subnet, subnet['id']) - body = self.client.create_port(network_id=net_id) - self.addCleanup(self.client.delete_port, body['port']['id']) + body = self.ports_client.create_port(network_id=net_id) + self.addCleanup(self.ports_client.delete_port, body['port']['id']) port = body['port'] ip_address = port['fixed_ips'][0]['ip_address'] start_ip_address = allocation_pools['allocation_pools'][0]['start'] @@ -120,7 +120,7 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): @test.idempotent_id('c9a685bd-e83f-499c-939f-9f7863ca259f') def test_show_port(self): # Verify the details of port - body = self.client.show_port(self.port['id']) + body = self.ports_client.show_port(self.port['id']) port = body['port'] self.assertIn('id', port) # TODO(Santosh)- This is a temporary workaround to compare create_port @@ -134,8 +134,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): def test_show_port_fields(self): # Verify specific fields of a port fields = ['id', 'mac_address'] - body = self.client.show_port(self.port['id'], - fields=fields) + body = self.ports_client.show_port(self.port['id'], + fields=fields) port = body['port'] self.assertEqual(sorted(port.keys()), sorted(fields)) for field_name in fields: @@ -145,7 +145,7 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): @test.idempotent_id('cf95b358-3e92-4a29-a148-52445e1ac50e') def test_list_ports(self): # Verify the port exists in the list of all ports - body = self.client.list_ports() + body = self.ports_client.list_ports() ports = [port['id'] for port in body['ports'] if port['id'] == self.port['id']] self.assertNotEmpty(ports, "Created port not found in the list") @@ -157,14 +157,14 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): subnet = self.create_subnet(network) self.addCleanup(self.subnets_client.delete_subnet, subnet['id']) # Create two ports - port_1 = self.client.create_port(network_id=network['id']) - self.addCleanup(self.client.delete_port, port_1['port']['id']) - port_2 = self.client.create_port(network_id=network['id']) - self.addCleanup(self.client.delete_port, port_2['port']['id']) + port_1 = self.ports_client.create_port(network_id=network['id']) + self.addCleanup(self.ports_client.delete_port, port_1['port']['id']) + port_2 = self.ports_client.create_port(network_id=network['id']) + self.addCleanup(self.ports_client.delete_port, port_2['port']['id']) # List ports filtered by fixed_ips port_1_fixed_ip = port_1['port']['fixed_ips'][0]['ip_address'] fixed_ips = 'ip_address=' + port_1_fixed_ip - port_list = self.client.list_ports(fixed_ips=fixed_ips) + port_list = self.ports_client.list_ports(fixed_ips=fixed_ips) # Check that we got the desired port ports = port_list['ports'] tenant_ids = set([port['tenant_id'] for port in ports]) @@ -190,14 +190,14 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): self.addCleanup(self.subnets_client.delete_subnet, subnet['id']) router = self.create_router(data_utils.rand_name('router-')) self.addCleanup(self.client.delete_router, router['id']) - port = self.client.create_port(network_id=network['id']) + port = self.ports_client.create_port(network_id=network['id']) # Add router interface to port created above self.client.add_router_interface_with_port_id( router['id'], port['port']['id']) self.addCleanup(self.client.remove_router_interface_with_port_id, router['id'], port['port']['id']) # List ports filtered by router_id - port_list = self.client.list_ports(device_id=router['id']) + port_list = self.ports_client.list_ports(device_id=router['id']) ports = port_list['ports'] self.assertEqual(len(ports), 1) self.assertEqual(ports[0]['id'], port['port']['id']) @@ -207,7 +207,7 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): def test_list_ports_fields(self): # Verify specific fields of ports fields = ['id', 'mac_address'] - body = self.client.list_ports(fields=fields) + body = self.ports_client.list_ports(fields=fields) ports = body['ports'] self.assertNotEmpty(ports, "Port list returned is empty") # Asserting the fields returned are correct @@ -231,7 +231,7 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): # Create a port with multiple IP addresses port = self.create_port(network, fixed_ips=fixed_ips) - self.addCleanup(self.client.delete_port, port['id']) + self.addCleanup(self.ports_client.delete_port, port['id']) self.assertEqual(2, len(port['fixed_ips'])) check_fixed_ips = [subnet_1['id'], subnet_2['id']] for item in port['fixed_ips']: @@ -269,8 +269,8 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): "network_id": self.network['id'], "admin_state_up": True, "fixed_ips": fixed_ip_1} - body = self.client.create_port(**post_body) - self.addCleanup(self.client.delete_port, body['port']['id']) + body = self.ports_client.create_port(**post_body) + self.addCleanup(self.ports_client.delete_port, body['port']['id']) port = body['port'] # Update the port with security groups @@ -280,7 +280,7 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): "admin_state_up": False, "fixed_ips": fixed_ip_2, "security_groups": security_groups_list} - body = self.client.update_port(port['id'], **update_body) + body = self.ports_client.update_port(port['id'], **update_body) port_show = body['port'] # Verify the security groups and other attributes updated to port exclude_keys = set(port_show).symmetric_difference(update_body) @@ -308,16 +308,16 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): @test.idempotent_id('13e95171-6cbd-489c-9d7c-3f9c58215c18') def test_create_show_delete_port_user_defined_mac(self): # Create a port for a legal mac - body = self.client.create_port(network_id=self.network['id']) + body = self.ports_client.create_port(network_id=self.network['id']) old_port = body['port'] free_mac_address = old_port['mac_address'] - self.client.delete_port(old_port['id']) + self.ports_client.delete_port(old_port['id']) # Create a new port with user defined mac - body = self.client.create_port(network_id=self.network['id'], - mac_address=free_mac_address) - self.addCleanup(self.client.delete_port, body['port']['id']) + body = self.ports_client.create_port(network_id=self.network['id'], + mac_address=free_mac_address) + self.addCleanup(self.ports_client.delete_port, body['port']['id']) port = body['port'] - body = self.client.show_port(port['id']) + body = self.ports_client.show_port(port['id']) show_port = body['port'] self.assertEqual(free_mac_address, show_port['mac_address']) @@ -330,7 +330,7 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): subnet = self.create_subnet(network) self.addCleanup(self.subnets_client.delete_subnet, subnet['id']) port = self.create_port(network, security_groups=[]) - self.addCleanup(self.client.delete_port, port['id']) + self.addCleanup(self.ports_client.delete_port, port['id']) self.assertIsNotNone(port['security_groups']) self.assertEmpty(port['security_groups']) @@ -352,9 +352,9 @@ class PortsAdminExtendedAttrsTestJSON(base.BaseAdminNetworkTest): def test_create_port_binding_ext_attr(self): post_body = {"network_id": self.network['id'], "binding:host_id": self.host_id} - body = self.admin_client.create_port(**post_body) + body = self.admin_ports_client.create_port(**post_body) port = body['port'] - self.addCleanup(self.admin_client.delete_port, port['id']) + self.addCleanup(self.admin_ports_client.delete_port, port['id']) host_id = port['binding:host_id'] self.assertIsNotNone(host_id) self.assertEqual(self.host_id, host_id) @@ -362,11 +362,11 @@ class PortsAdminExtendedAttrsTestJSON(base.BaseAdminNetworkTest): @test.idempotent_id('6f6c412c-711f-444d-8502-0ac30fbf5dd5') def test_update_port_binding_ext_attr(self): post_body = {"network_id": self.network['id']} - body = self.admin_client.create_port(**post_body) + body = self.admin_ports_client.create_port(**post_body) port = body['port'] - self.addCleanup(self.admin_client.delete_port, port['id']) + self.addCleanup(self.admin_ports_client.delete_port, port['id']) update_body = {"binding:host_id": self.host_id} - body = self.admin_client.update_port(port['id'], **update_body) + body = self.admin_ports_client.update_port(port['id'], **update_body) updated_port = body['port'] host_id = updated_port['binding:host_id'] self.assertIsNotNone(host_id) @@ -376,18 +376,18 @@ class PortsAdminExtendedAttrsTestJSON(base.BaseAdminNetworkTest): def test_list_ports_binding_ext_attr(self): # Create a new port post_body = {"network_id": self.network['id']} - body = self.admin_client.create_port(**post_body) + body = self.admin_ports_client.create_port(**post_body) port = body['port'] - self.addCleanup(self.admin_client.delete_port, port['id']) + self.addCleanup(self.admin_ports_client.delete_port, port['id']) # Update the port's binding attributes so that is now 'bound' # to a host update_body = {"binding:host_id": self.host_id} - self.admin_client.update_port(port['id'], **update_body) + self.admin_ports_client.update_port(port['id'], **update_body) # List all ports, ensure new port is part of list and its binding # attributes are set and accurate - body = self.admin_client.list_ports() + body = self.admin_ports_client.list_ports() ports_list = body['ports'] pids_list = [p['id'] for p in ports_list] self.assertIn(port['id'], pids_list) @@ -399,10 +399,11 @@ class PortsAdminExtendedAttrsTestJSON(base.BaseAdminNetworkTest): @test.idempotent_id('b54ac0ff-35fc-4c79-9ca3-c7dbd4ea4f13') def test_show_port_binding_ext_attr(self): - body = self.admin_client.create_port(network_id=self.network['id']) + body = self.admin_ports_client.create_port( + network_id=self.network['id']) port = body['port'] - self.addCleanup(self.admin_client.delete_port, port['id']) - body = self.admin_client.show_port(port['id']) + self.addCleanup(self.admin_ports_client.delete_port, port['id']) + body = self.admin_ports_client.show_port(port['id']) show_port = body['port'] self.assertEqual(port['binding:host_id'], show_port['binding:host_id']) diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py index 29855e1527..ed191b60fd 100644 --- a/tempest/api/network/test_routers.py +++ b/tempest/api/network/test_routers.py @@ -144,7 +144,7 @@ class RoutersTest(base.BaseRouterTest): self.assertIn('subnet_id', interface.keys()) self.assertIn('port_id', interface.keys()) # Verify router id is equal to device id in port details - show_port_body = self.client.show_port( + show_port_body = self.ports_client.show_port( interface['port_id']) self.assertEqual(show_port_body['port']['device_id'], router['id']) @@ -155,7 +155,7 @@ class RoutersTest(base.BaseRouterTest): network = self.create_network() self.create_subnet(network) router = self._create_router(data_utils.rand_name('router-')) - port_body = self.client.create_port( + port_body = self.ports_client.create_port( network_id=network['id']) # add router interface to port created above interface = self.client.add_router_interface_with_port_id( @@ -165,7 +165,7 @@ class RoutersTest(base.BaseRouterTest): self.assertIn('subnet_id', interface.keys()) self.assertIn('port_id', interface.keys()) # Verify router id is equal to device id in port details - show_port_body = self.client.show_port( + show_port_body = self.ports_client.show_port( interface['port_id']) self.assertEqual(show_port_body['port']['device_id'], router['id']) @@ -181,7 +181,7 @@ class RoutersTest(base.BaseRouterTest): self.assertEqual(v, actual_ext_gw_info[k]) def _verify_gateway_port(self, router_id): - list_body = self.admin_client.list_ports( + list_body = self.admin_ports_client.list_ports( network_id=CONF.network.public_network_id, device_id=router_id) self.assertEqual(len(list_body['ports']), 1) @@ -245,7 +245,7 @@ class RoutersTest(base.BaseRouterTest): self.client.update_router(router['id'], external_gateway_info={}) self._verify_router_gateway(router['id']) # No gateway port expected - list_body = self.admin_client.list_ports( + list_body = self.admin_ports_client.list_ports( network_id=CONF.network.public_network_id, device_id=router['id']) self.assertFalse(list_body['ports']) @@ -357,7 +357,7 @@ class RoutersTest(base.BaseRouterTest): interface02['port_id']) def _verify_router_interface(self, router_id, subnet_id, port_id): - show_port_body = self.client.show_port(port_id) + show_port_body = self.ports_client.show_port(port_id) interface_port = show_port_body['port'] self.assertEqual(router_id, interface_port['device_id']) self.assertEqual(subnet_id, diff --git a/tempest/api/orchestration/stacks/test_neutron_resources.py b/tempest/api/orchestration/stacks/test_neutron_resources.py index 070150da00..d22fb25654 100644 --- a/tempest/api/orchestration/stacks/test_neutron_resources.py +++ b/tempest/api/orchestration/stacks/test_neutron_resources.py @@ -164,7 +164,7 @@ class NeutronResourcesTestJSON(base.BaseOrchestrationTest): router_id = self.test_resources.get('Router')['physical_resource_id'] network_id = self.test_resources.get('Network')['physical_resource_id'] subnet_id = self.test_resources.get('Subnet')['physical_resource_id'] - body = self.network_client.list_ports() + body = self.ports_client.list_ports() ports = body['ports'] router_ports = filter(lambda port: port['device_id'] == router_id, ports) diff --git a/tempest/clients.py b/tempest/clients.py index 84e85446ef..e8a9fd50d0 100644 --- a/tempest/clients.py +++ b/tempest/clients.py @@ -107,6 +107,7 @@ from tempest.services.messaging.json.messaging_client import \ MessagingClient from tempest.services.network.json.network_client import NetworkClient from tempest.services.network.json.networks_client import NetworksClient +from tempest.services.network.json.ports_client import PortsClient from tempest.services.network.json.subnets_client import SubnetsClient from tempest.services.object_storage.account_client import AccountClient from tempest.services.object_storage.container_client import ContainerClient @@ -213,6 +214,14 @@ class Manager(manager.Manager): build_interval=CONF.network.build_interval, build_timeout=CONF.network.build_timeout, **self.default_params) + self.ports_client = PortsClient( + self.auth_provider, + CONF.network.catalog_type, + CONF.network.region or CONF.identity.region, + endpoint_type=CONF.network.endpoint_type, + build_interval=CONF.network.build_interval, + build_timeout=CONF.network.build_timeout, + **self.default_params) self.messaging_client = MessagingClient( self.auth_provider, CONF.messaging.catalog_type, diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py index 64e1303f74..1ef6f81731 100644 --- a/tempest/cmd/cleanup_service.py +++ b/tempest/cmd/cleanup_service.py @@ -383,6 +383,7 @@ class NetworkService(BaseService): self.client = manager.network_client self.networks_client = manager.networks_client self.subnets_client = manager.subnets_client + self.ports_client = manager.ports_client def _filter_by_conf_networks(self, item_list): if not item_list or not all(('network_id' in i for i in item_list)): @@ -620,7 +621,7 @@ class NetworkMeteringLabelService(NetworkService): class NetworkPortService(NetworkService): def list(self): - client = self.client + client = self.ports_client ports = [port for port in client.list_ports(**self.tenant_filter)['ports'] if port["device_owner"] == "" or @@ -633,7 +634,7 @@ class NetworkPortService(NetworkService): return ports def delete(self): - client = self.client + client = self.ports_client ports = self.list() for port in ports: try: diff --git a/tempest/common/dynamic_creds.py b/tempest/common/dynamic_creds.py index e2df560b23..ce69c84649 100644 --- a/tempest/common/dynamic_creds.py +++ b/tempest/common/dynamic_creds.py @@ -43,7 +43,8 @@ class DynamicCredentialProvider(cred_provider.CredentialProvider): identity_version=self.identity_version) (self.identity_admin_client, self.network_admin_client, self.networks_admin_client, - self.subnets_admin_client) = self._get_admin_clients() + self.subnets_admin_client, + self.ports_admin_client) = self._get_admin_clients() # Domain where isolated credentials are provisioned (v3 only). # Use that of the admin account is None is configured. self.creds_domain_name = None @@ -64,10 +65,10 @@ class DynamicCredentialProvider(cred_provider.CredentialProvider): os = clients.Manager(self.default_admin_creds) if self.identity_version == 'v2': return (os.identity_client, os.network_client, os.networks_client, - os.subnets_client) + os.subnets_client, os.ports_client) else: return (os.identity_v3_client, os.network_client, - os.networks_client, os.subnets_client) + os.networks_client, os.subnets_client, os.ports_client) def _create_creds(self, suffix="", admin=False, roles=None): """Create random credentials under the following schema. diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index a10dc831a5..859e3a7c51 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -62,6 +62,7 @@ class ScenarioTest(tempest.test.BaseTestCase): # Neutron network client cls.network_client = cls.manager.network_client cls.networks_client = cls.manager.networks_client + cls.ports_client = cls.manager.ports_client cls.subnets_client = cls.manager.subnets_client # Heat client cls.orchestration_client = cls.manager.orchestration_client @@ -661,7 +662,7 @@ class NetworkScenarioTest(ScenarioTest): def _list_ports(self, *args, **kwargs): """List ports using admin creds """ - ports_list = self.admin_manager.network_client.list_ports( + ports_list = self.admin_manager.ports_client.list_ports( *args, **kwargs) return ports_list['ports'] @@ -735,14 +736,14 @@ class NetworkScenarioTest(ScenarioTest): def _create_port(self, network_id, client=None, namestart='port-quotatest', **kwargs): if not client: - client = self.network_client + client = self.ports_client name = data_utils.rand_name(namestart) result = client.create_port( name=name, network_id=network_id, **kwargs) self.assertIsNotNone(result, 'Unable to allocate port') - port = net_resources.DeletablePort(client=client, + port = net_resources.DeletablePort(ports_client=client, **result['port']) self.addCleanup(self.delete_wrapper, port.delete) return port @@ -1127,11 +1128,13 @@ class NetworkScenarioTest(ScenarioTest): def create_server(self, name=None, image=None, flavor=None, wait_on_boot=True, wait_on_delete=True, network_client=None, networks_client=None, - create_kwargs=None): + ports_client=None, create_kwargs=None): if network_client is None: network_client = self.network_client if networks_client is None: networks_client = self.networks_client + if ports_client is None: + ports_client = self.ports_client vnic_type = CONF.network.port_vnic_type @@ -1175,7 +1178,7 @@ class NetworkScenarioTest(ScenarioTest): for net in networks: net_id = net['uuid'] port = self._create_port(network_id=net_id, - client=network_client, + client=ports_client, **create_port_body) ports.append({'port': port.id}) if ports: diff --git a/tempest/scenario/test_baremetal_basic_ops.py b/tempest/scenario/test_baremetal_basic_ops.py index c0b5a44ceb..c0b82b6001 100644 --- a/tempest/scenario/test_baremetal_basic_ops.py +++ b/tempest/scenario/test_baremetal_basic_ops.py @@ -117,7 +117,7 @@ class BaremetalBasicOps(manager.BaremetalScenarioTest): def validate_ports(self): for port in self.get_ports(self.node['uuid']): n_port_id = port['extra']['vif_port_id'] - body = self.network_client.show_port(n_port_id) + body = self.ports_client.show_port(n_port_id) n_port = body['port'] self.assertEqual(n_port['device_id'], self.instance['id']) self.assertEqual(n_port['mac_address'], port['address']) diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py index 31ccd5beaa..dc5ca08f27 100644 --- a/tempest/scenario/test_network_basic_ops.py +++ b/tempest/scenario/test_network_basic_ops.py @@ -250,7 +250,7 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest): net_id=self.new_net.id)['interfaceAttachment'] self.addCleanup(self.network_client.wait_for_resource_deletion, 'port', - interface['port_id']) + interface['port_id'], client=self.ports_client) self.addCleanup(self.delete_wrapper, self.interface_client.delete_interface, server['id'], interface['port_id']) @@ -268,7 +268,7 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest): "Old port: %s. Number of new ports: %d" % ( CONF.network.build_timeout, old_port, len(self.new_port_list))) - new_port = net_resources.DeletablePort(client=self.network_client, + new_port = net_resources.DeletablePort(ports_client=self.ports_client, **self.new_port_list[0]) def check_new_nic(): @@ -609,12 +609,12 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest): self.check_public_network_connectivity( should_connect=True, msg="before updating " "admin_state_up of instance port to False") - self.network_client.update_port(port_id, admin_state_up=False) + self.ports_client.update_port(port_id, admin_state_up=False) self.check_public_network_connectivity( should_connect=False, msg="after updating " "admin_state_up of instance port to False", should_check_floating_ip_status=False) - self.network_client.update_port(port_id, admin_state_up=True) + self.ports_client.update_port(port_id, admin_state_up=True) self.check_public_network_connectivity( should_connect=True, msg="after updating " "admin_state_up of instance port to True") @@ -653,7 +653,7 @@ class TestNetworkBasicOps(manager.NetworkScenarioTest): waiters.wait_for_server_termination(self.servers_client, server['id']) # Assert the port still exists on the network but is unbound from # the deleted server. - port = self.network_client.show_port(port_id)['port'] + port = self.ports_client.show_port(port_id)['port'] self.assertEqual(self.network['id'], port['network_id']) self.assertEqual('', port['device_id']) self.assertEqual('', port['device_owner']) diff --git a/tempest/scenario/test_security_groups_basic_ops.py b/tempest/scenario/test_security_groups_basic_ops.py index 3c11c2255d..d2a7ec62cb 100644 --- a/tempest/scenario/test_security_groups_basic_ops.py +++ b/tempest/scenario/test_security_groups_basic_ops.py @@ -250,6 +250,7 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest): name=name, network_client=tenant.manager.network_client, networks_client=tenant.manager.networks_client, + ports_client=tenant.manager.ports_client, create_kwargs=create_kwargs) self.assertEqual( sorted([s['name'] for s in security_groups]), @@ -514,7 +515,7 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest): port_id = self._list_ports(device_id=server_id)[0]['id'] # update port with new security group and check connectivity - self.network_client.update_port(port_id, security_groups=[ + self.ports_client.update_port(port_id, security_groups=[ new_tenant.security_groups['new_sg'].id]) self._check_connectivity( access_point=access_point_ssh, @@ -581,16 +582,16 @@ class TestSecurityGroupsBasicOps(manager.NetworkScenarioTest): # Flip the port's port security and check connectivity try: - self.network_client.update_port(port_id, - port_security_enabled=True, - security_groups=[]) + self.ports_client.update_port(port_id, + port_security_enabled=True, + security_groups=[]) self._check_connectivity(access_point=access_point_ssh, ip=self._get_server_ip(server), should_succeed=False) - self.network_client.update_port(port_id, - port_security_enabled=False, - security_groups=[]) + self.ports_client.update_port(port_id, + port_security_enabled=False, + security_groups=[]) self._check_connectivity( access_point=access_point_ssh, ip=self._get_server_ip(server)) diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py index 7821f37bd5..d811c516ac 100644 --- a/tempest/services/network/json/network_client.py +++ b/tempest/services/network/json/network_client.py @@ -34,28 +34,6 @@ class NetworkClient(base.BaseNetworkClient): quotas """ - 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) - def create_floatingip(self, **kwargs): uri = '/floatingips' post_data = {'floatingip': kwargs} @@ -175,20 +153,22 @@ class NetworkClient(base.BaseNetworkClient): uri = '/ports' return self.create_resource(uri, post_data) - def wait_for_resource_deletion(self, resource_type, id): + def wait_for_resource_deletion(self, resource_type, id, client=None): """Waits for a resource to be deleted.""" start_time = int(time.time()) while True: - if self.is_resource_deleted(resource_type, id): + if self.is_resource_deleted(resource_type, id, client=client): return if int(time.time()) - start_time >= self.build_timeout: raise exceptions.TimeoutException time.sleep(self.build_interval) - def is_resource_deleted(self, resource_type, id): + def is_resource_deleted(self, resource_type, id, client=None): + if client is None: + client = self method = 'show_' + resource_type try: - getattr(self, method)(id) + getattr(client, method)(id) except AttributeError: raise Exception("Unknown resource type %s " % resource_type) except lib_exc.NotFound: diff --git a/tempest/services/network/json/ports_client.py b/tempest/services/network/json/ports_client.py new file mode 100644 index 0000000000..d52d65ee9a --- /dev/null +++ b/tempest/services/network/json/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.services.network.json 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/services/network/resources.py b/tempest/services/network/resources.py index 16d9823fb5..ae30312331 100644 --- a/tempest/services/network/resources.py +++ b/tempest/services/network/resources.py @@ -44,6 +44,7 @@ class DeletableResource(AttributeDict): self.network_client = kwargs.pop('network_client', None) self.networks_client = kwargs.pop('networks_client', None) self.subnets_client = kwargs.pop('subnets_client', None) + self.ports_client = kwargs.pop('ports_client', None) super(DeletableResource, self).__init__(*args, **kwargs) def __str__(self): @@ -152,7 +153,7 @@ class DeletableFloatingIp(DeletableResource): class DeletablePort(DeletableResource): def delete(self): - self.client.delete_port(self.id) + self.ports_client.delete_port(self.id) class DeletableSecurityGroup(DeletableResource): diff --git a/tempest/tests/common/test_dynamic_creds.py b/tempest/tests/common/test_dynamic_creds.py index 59a5523740..73e180e69b 100644 --- a/tempest/tests/common/test_dynamic_creds.py +++ b/tempest/tests/common/test_dynamic_creds.py @@ -376,7 +376,7 @@ class TestDynamicCredentialProvider(base.TestCase): 'tempest.services.network.json.network_client.NetworkClient.' 'remove_router_interface_with_subnet_id') return_values = ({'status': 200}, {'ports': []}) - port_list_mock = mock.patch.object(creds.network_admin_client, + port_list_mock = mock.patch.object(creds.ports_admin_client, 'list_ports', return_value=return_values)