From d2c40cace00f19a835e8f0e26620d69105b43e74 Mon Sep 17 00:00:00 2001 From: zhufl Date: Tue, 18 Oct 2016 17:03:07 +0800 Subject: [PATCH] Use random name in network common function This is to use random name in network's common function, to avoid too many random name definitions outside. Change-Id: Ieb211ce48d2368b1f41109c7fd76e818ee69cfe4 --- .../admin/test_floating_ips_admin_actions.py | 4 +-- .../network/admin/test_l3_agent_scheduler.py | 3 +-- tempest/api/network/base.py | 9 ++++--- tempest/api/network/base_routers.py | 2 +- tempest/api/network/test_floating_ips.py | 7 ++--- tempest/api/network/test_networks.py | 12 +++------ tempest/api/network/test_ports.py | 3 +-- tempest/api/network/test_routers.py | 26 ++++++++----------- tempest/api/network/test_routers_negative.py | 7 +++-- 9 files changed, 30 insertions(+), 43 deletions(-) diff --git a/tempest/api/network/admin/test_floating_ips_admin_actions.py b/tempest/api/network/admin/test_floating_ips_admin_actions.py index 2686af216f..a32e7da8fd 100644 --- a/tempest/api/network/admin/test_floating_ips_admin_actions.py +++ b/tempest/api/network/admin/test_floating_ips_admin_actions.py @@ -14,7 +14,6 @@ # under the License. from tempest.api.network import base -from tempest.common.utils import data_utils from tempest import config from tempest import test @@ -44,8 +43,7 @@ class FloatingIPAdminTestJSON(base.BaseAdminNetworkTest): cls.floating_ip = cls.create_floatingip(cls.ext_net_id) cls.network = cls.create_network() cls.subnet = cls.create_subnet(cls.network) - cls.router = cls.create_router(data_utils.rand_name('router-'), - external_network_id=cls.ext_net_id) + cls.router = cls.create_router(external_network_id=cls.ext_net_id) cls.create_router_interface(cls.router['id'], cls.subnet['id']) cls.port = cls.create_port(cls.network) diff --git a/tempest/api/network/admin/test_l3_agent_scheduler.py b/tempest/api/network/admin/test_l3_agent_scheduler.py index d2e14923cc..21eda2718f 100644 --- a/tempest/api/network/admin/test_l3_agent_scheduler.py +++ b/tempest/api/network/admin/test_l3_agent_scheduler.py @@ -13,7 +13,6 @@ # under the License. from tempest.api.network import base -from tempest.common.utils import data_utils from tempest import config from tempest import exceptions from tempest import test @@ -66,7 +65,7 @@ class L3AgentSchedulerTestJSON(base.BaseAdminNetworkTest): else: msg = "L3 Agent Scheduler enabled in conf, but L3 Agent not found" raise exceptions.InvalidConfiguration(msg) - cls.router = cls.create_router(data_utils.rand_name('router')) + cls.router = cls.create_router() if CONF.network.dvr_extra_resources: # NOTE(armax): If DVR is an available extension, and the created diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py index 5c67d68984..629926d1b9 100644 --- a/tempest/api/network/base.py +++ b/tempest/api/network/base.py @@ -26,7 +26,7 @@ CONF = config.CONF class BaseNetworkTest(tempest.test.BaseTestCase): - """Base class for the Neutron tests + """Base class for the Neutron tests. Per the Neutron API Guide, API v1.x was removed from the source code tree (docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html) @@ -137,7 +137,8 @@ class BaseNetworkTest(tempest.test.BaseTestCase): @classmethod def create_network(cls, network_name=None): """Wrapper utility that returns a test network.""" - network_name = network_name or data_utils.rand_name('test-network-') + network_name = network_name or data_utils.rand_name( + cls.__name__ + "-network") body = cls.networks_client.create_network(name=network_name) network = body['network'] @@ -148,7 +149,6 @@ class BaseNetworkTest(tempest.test.BaseTestCase): def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None, ip_version=None, client=None, **kwargs): """Wrapper utility that returns a test subnet.""" - # allow tests to use admin client if not client: client = cls.subnets_client @@ -208,6 +208,9 @@ class BaseNetworkTest(tempest.test.BaseTestCase): def create_router(cls, router_name=None, admin_state_up=False, external_network_id=None, enable_snat=None, **kwargs): + router_name = router_name or data_utils.rand_name( + cls.__name__ + "-router") + ext_gw_info = {} if external_network_id: ext_gw_info['network_id'] = external_network_id diff --git a/tempest/api/network/base_routers.py b/tempest/api/network/base_routers.py index 807257ffb6..5fb52325c5 100644 --- a/tempest/api/network/base_routers.py +++ b/tempest/api/network/base_routers.py @@ -25,7 +25,7 @@ class BaseRouterTest(base.BaseAdminNetworkTest): self.delete_router(router) self.routers.remove(router) - def _create_router(self, name, admin_state_up=False, + def _create_router(self, name=None, admin_state_up=False, external_network_id=None, enable_snat=None): # associate a cleanup with created routers to avoid quota limits router = self.create_router(name, admin_state_up, diff --git a/tempest/api/network/test_floating_ips.py b/tempest/api/network/test_floating_ips.py index c64b01eaef..efe8982d99 100644 --- a/tempest/api/network/test_floating_ips.py +++ b/tempest/api/network/test_floating_ips.py @@ -14,7 +14,6 @@ # under the License. from tempest.api.network import base -from tempest.common.utils import data_utils from tempest.common.utils import net_utils from tempest import config from tempest import test @@ -55,8 +54,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest): # Create network, subnet, router and add interface cls.network = cls.create_network() cls.subnet = cls.create_subnet(cls.network, enable_dhcp=False) - cls.router = cls.create_router(data_utils.rand_name('router-'), - external_network_id=cls.ext_net_id) + cls.router = cls.create_router(external_network_id=cls.ext_net_id) cls.create_router_interface(cls.router['id'], cls.subnet['id']) # Create two ports one each for Creation and Updating of floatingIP for i in range(2): @@ -156,8 +154,7 @@ class FloatingIPTestJSON(base.BaseNetworkTest): self.assertEqual(created_floating_ip['router_id'], self.router['id']) network2 = self.create_network() subnet2 = self.create_subnet(network2) - router2 = self.create_router(data_utils.rand_name('router-'), - external_network_id=self.ext_net_id) + router2 = self.create_router(external_network_id=self.ext_net_id) 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 diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py index 819ef90dfb..dadaaba69a 100644 --- a/tempest/api/network/test_networks.py +++ b/tempest/api/network/test_networks.py @@ -175,8 +175,7 @@ class NetworksTest(base.BaseNetworkTest): @test.idempotent_id('0e269138-0da6-4efc-a46d-578161e7b221') def test_create_update_delete_network_subnet(self): # Create a network - name = data_utils.rand_name('network-') - network = self.create_network(network_name=name) + network = self.create_network() self.addCleanup(self._delete_network, network) net_id = network['id'] self.assertEqual('ACTIVE', network['status']) @@ -525,8 +524,7 @@ class NetworksIpV6Test(NetworksTest): def test_create_delete_subnet_with_gw(self): net = netaddr.IPNetwork(CONF.network.project_network_v6_cidr) gateway = str(netaddr.IPAddress(net.first + 2)) - name = data_utils.rand_name('network-') - network = self.create_network(network_name=name) + network = self.create_network() subnet = self.create_subnet(network, gateway) # Verifies Subnet GW in IPv6 self.assertEqual(subnet['gateway_ip'], gateway) @@ -535,16 +533,14 @@ class NetworksIpV6Test(NetworksTest): def test_create_delete_subnet_with_default_gw(self): net = netaddr.IPNetwork(CONF.network.project_network_v6_cidr) gateway_ip = str(netaddr.IPAddress(net.first + 1)) - name = data_utils.rand_name('network-') - network = self.create_network(network_name=name) + network = self.create_network() subnet = self.create_subnet(network) # Verifies Subnet GW in IPv6 self.assertEqual(subnet['gateway_ip'], gateway_ip) @test.idempotent_id('a9653883-b2a4-469b-8c3c-4518430a7e55') def test_create_list_subnet_with_no_gw64_one_network(self): - name = data_utils.rand_name('network-') - network = self.create_network(name) + network = self.create_network() ipv6_gateway = self.subnet_dict(['gateway'])['gateway'] subnet1 = self.create_subnet(network, ip_version=6, diff --git a/tempest/api/network/test_ports.py b/tempest/api/network/test_ports.py index e5972a93f5..a0032c1b24 100644 --- a/tempest/api/network/test_ports.py +++ b/tempest/api/network/test_ports.py @@ -72,8 +72,7 @@ class PortsTestJSON(sec_base.BaseSecGroupTest): @test.idempotent_id('67f1b811-f8db-43e2-86bd-72c074d4a42c') def test_create_bulk_port(self): network1 = self.network - name = data_utils.rand_name('network-') - network2 = self.create_network(network_name=name) + network2 = self.create_network() network_list = [network1['id'], network2['id']] port_list = [{'network_id': net_id} for net_id in network_list] body = self.ports_client.create_bulk_ports(ports=port_list) diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py index 98a4f63c1d..de2e71fd10 100644 --- a/tempest/api/network/test_routers.py +++ b/tempest/api/network/test_routers.py @@ -106,9 +106,8 @@ class RoutersTest(base.BaseRouterTest): @test.requires_ext(extension='ext-gw-mode', service='network') def test_create_router_with_default_snat_value(self): # Create a router with default snat rule - name = data_utils.rand_name('router') router = self._create_router( - name, external_network_id=CONF.network.public_network_id) + external_network_id=CONF.network.public_network_id) self._verify_router_gateway( router['id'], {'network_id': CONF.network.public_network_id, 'enable_snat': True}) @@ -136,7 +135,7 @@ class RoutersTest(base.BaseRouterTest): def test_add_remove_router_interface_with_subnet_id(self): network = self.create_network() subnet = self.create_subnet(network) - router = self._create_router(data_utils.rand_name('router-')) + router = self._create_router() # Add router interface with subnet id interface = self.routers_client.add_router_interface( router['id'], subnet_id=subnet['id']) @@ -155,7 +154,7 @@ class RoutersTest(base.BaseRouterTest): def test_add_remove_router_interface_with_port_id(self): network = self.create_network() self.create_subnet(network) - router = self._create_router(data_utils.rand_name('router-')) + router = self._create_router() port_body = self.ports_client.create_port( network_id=network['id']) # add router interface to port created above @@ -201,7 +200,7 @@ class RoutersTest(base.BaseRouterTest): @test.idempotent_id('6cc285d8-46bf-4f36-9b1a-783e3008ba79') def test_update_router_set_gateway(self): - router = self._create_router(data_utils.rand_name('router-')) + router = self._create_router() self.routers_client.update_router( router['id'], external_gateway_info={ @@ -215,7 +214,7 @@ class RoutersTest(base.BaseRouterTest): @test.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33') @test.requires_ext(extension='ext-gw-mode', service='network') def test_update_router_set_gateway_with_snat_explicit(self): - router = self._create_router(data_utils.rand_name('router-')) + router = self._create_router() self.admin_routers_client.update_router( router['id'], external_gateway_info={ @@ -230,7 +229,7 @@ class RoutersTest(base.BaseRouterTest): @test.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279') @test.requires_ext(extension='ext-gw-mode', service='network') def test_update_router_set_gateway_without_snat(self): - router = self._create_router(data_utils.rand_name('router-')) + router = self._create_router() self.admin_routers_client.update_router( router['id'], external_gateway_info={ @@ -245,7 +244,6 @@ class RoutersTest(base.BaseRouterTest): @test.idempotent_id('ad81b7ee-4f81-407b-a19c-17e623f763e8') def test_update_router_unset_gateway(self): router = self._create_router( - data_utils.rand_name('router-'), external_network_id=CONF.network.public_network_id) self.routers_client.update_router(router['id'], external_gateway_info={}) @@ -260,7 +258,6 @@ class RoutersTest(base.BaseRouterTest): @test.requires_ext(extension='ext-gw-mode', service='network') def test_update_router_reset_gateway_without_snat(self): router = self._create_router( - data_utils.rand_name('router-'), external_network_id=CONF.network.public_network_id) self.admin_routers_client.update_router( router['id'], @@ -283,8 +280,7 @@ class RoutersTest(base.BaseRouterTest): test_routes = [] routes_num = 4 # Create a router - router = self._create_router( - data_utils.rand_name('router-'), True) + router = self._create_router(admin_state_up=True) self.addCleanup( self._delete_extra_routes, router['id']) @@ -338,7 +334,7 @@ class RoutersTest(base.BaseRouterTest): @test.idempotent_id('a8902683-c788-4246-95c7-ad9c6d63a4d9') def test_update_router_admin_state(self): - router = self._create_router(data_utils.rand_name('router-')) + router = self._create_router() self.assertFalse(router['admin_state_up']) # Update router admin state update_body = self.routers_client.update_router(router['id'], @@ -357,7 +353,7 @@ class RoutersTest(base.BaseRouterTest): subnet01 = self.create_subnet(network01) sub02_cidr = netaddr.IPNetwork(self.tenant_cidr).next() subnet02 = self.create_subnet(network02, cidr=sub02_cidr) - router = self._create_router(data_utils.rand_name('router-')) + router = self._create_router() interface01 = self._add_router_interface_with_subnet_id(router['id'], subnet01['id']) self._verify_router_interface(router['id'], subnet01['id'], @@ -371,7 +367,7 @@ class RoutersTest(base.BaseRouterTest): def test_router_interface_port_update_with_fixed_ip(self): network = self.create_network() subnet = self.create_subnet(network) - router = self._create_router(data_utils.rand_name('router-')) + router = self._create_router() fixed_ip = [{'subnet_id': subnet['id']}] interface = self._add_router_interface_with_subnet_id(router['id'], subnet['id']) @@ -417,7 +413,7 @@ class DvrRoutersTest(base.BaseRouterTest): @test.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729') def test_convert_centralized_router(self): - router = self._create_router(data_utils.rand_name('router')) + router = self._create_router() self.assertNotIn('distributed', router) update_body = self.admin_routers_client.update_router(router['id'], distributed=True) diff --git a/tempest/api/network/test_routers_negative.py b/tempest/api/network/test_routers_negative.py index cd9f6adadb..354e6d1e5d 100644 --- a/tempest/api/network/test_routers_negative.py +++ b/tempest/api/network/test_routers_negative.py @@ -36,7 +36,7 @@ class RoutersNegativeTest(base.BaseRouterTest): @classmethod def resource_setup(cls): super(RoutersNegativeTest, cls).resource_setup() - cls.router = cls.create_router(data_utils.rand_name('router-')) + cls.router = cls.create_router() cls.network = cls.create_network() cls.subnet = cls.create_subnet(cls.network) cls.tenant_cidr = (CONF.network.project_network_cidr @@ -55,8 +55,7 @@ class RoutersNegativeTest(base.BaseRouterTest): @test.attr(type=['negative']) @test.idempotent_id('11836a18-0b15-4327-a50b-f0d9dc66bddd') def test_router_add_gateway_net_not_external_returns_400(self): - alt_network = self.create_network( - network_name=data_utils.rand_name('router-negative-')) + alt_network = self.create_network() sub_cidr = netaddr.IPNetwork(self.tenant_cidr).next() self.create_subnet(alt_network, cidr=sub_cidr) self.assertRaises(lib_exc.BadRequest, @@ -128,7 +127,7 @@ class DvrRoutersNegativeTest(base.BaseRouterTest): @classmethod def resource_setup(cls): super(DvrRoutersNegativeTest, cls).resource_setup() - cls.router = cls.create_router(data_utils.rand_name('router')) + cls.router = cls.create_router() cls.network = cls.create_network() cls.subnet = cls.create_subnet(cls.network)