From 2397fd0d5c350f6bc68f21e2816930e6d8de999a Mon Sep 17 00:00:00 2001 From: Assaf Muller Date: Thu, 7 Apr 2016 17:56:03 -0400 Subject: [PATCH] Fix broken Tempest conf options in API tests Tempest commit ed6e586b9f8f0ada10af7711f297afa01b2b7754 changed configuration options defined in Tempest from tenant to project. Currently we use Tempest from PyPI, and since there hasn't yet been a Tempest release with the change that breaks us, we're still safe, however the next release will break us, so let's be ready for it. Long term I think the correct thing to do would be to define new options used exclusively in the Neutron tree. Change-Id: I054b94a43d900e42872a9cb28d33a3ed45e14779 --- neutron/tests/api/base.py | 22 +++++++++++++------ .../tests/api/test_allowed_address_pair.py | 4 +++- .../tests/api/test_network_ip_availability.py | 6 +++-- neutron/tests/api/test_routers.py | 7 +++--- .../api/test_security_groups_negative.py | 3 --- neutron/tests/tempest/config.py | 18 +++++++++++++++ 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/neutron/tests/api/base.py b/neutron/tests/api/base.py index c7137f7a4b2..b56d915db16 100644 --- a/neutron/tests/api/base.py +++ b/neutron/tests/api/base.py @@ -35,11 +35,11 @@ class BaseNetworkTest(test.BaseTestCase): Therefore, v2.x of the Neutron API is assumed. It is also assumed that the following options are defined in the [network] section of etc/tempest.conf: - tenant_network_cidr with a block of cidr's from which smaller blocks + project_network_cidr with a block of cidr's from which smaller blocks can be allocated for tenant networks - tenant_network_mask_bits with the mask bits to be used to partition the - block defined by tenant-network_cidr + project_network_mask_bits with the mask bits to be used to partition + the block defined by tenant-network_cidr Finally, it is assumed that the following option is defined in the [service_available] section of etc/tempest.conf @@ -232,12 +232,20 @@ class BaseNetworkTest(test.BaseTestCase): ip_version = ip_version if ip_version is not None else cls._ip_version gateway_not_set = gateway == '' if ip_version == 4: - cidr = cidr or netaddr.IPNetwork(CONF.network.tenant_network_cidr) - mask_bits = mask_bits or CONF.network.tenant_network_mask_bits + cidr = cidr or netaddr.IPNetwork( + config.safe_get_config_value( + 'network', 'project_network_cidr')) + mask_bits = ( + mask_bits or config.safe_get_config_value( + 'network', 'project_network_mask_bits')) elif ip_version == 6: cidr = ( - cidr or netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr)) - mask_bits = mask_bits or CONF.network.tenant_network_v6_mask_bits + cidr or netaddr.IPNetwork( + config.safe_get_config_value( + 'network', 'project_network_v6_cidr'))) + mask_bits = ( + mask_bits or config.safe_get_config_value( + 'network', 'project_network_v6_mask_bits')) # Find a cidr that is not in use yet and create a subnet with it for subnet_cidr in cidr.subnet(mask_bits): if gateway_not_set: diff --git a/neutron/tests/api/test_allowed_address_pair.py b/neutron/tests/api/test_allowed_address_pair.py index f039673acb2..500c58c0b8f 100644 --- a/neutron/tests/api/test_allowed_address_pair.py +++ b/neutron/tests/api/test_allowed_address_pair.py @@ -99,7 +99,9 @@ class AllowedAddressPairTestJSON(base.BaseNetworkTest): @test.idempotent_id('4d6d178f-34f6-4bff-a01c-0a2f8fe909e4') def test_update_port_with_cidr_address_pair(self): # Update allowed address pair with cidr - cidr = str(netaddr.IPNetwork(CONF.network.tenant_network_cidr)) + cidr = str( + netaddr.IPNetwork(config.safe_get_config_value( + 'network', 'project_network_cidr'))) self._update_port_with_address(cidr) @test.attr(type='smoke') diff --git a/neutron/tests/api/test_network_ip_availability.py b/neutron/tests/api/test_network_ip_availability.py index 6cd84ad5f09..7f8e243991f 100644 --- a/neutron/tests/api/test_network_ip_availability.py +++ b/neutron/tests/api/test_network_ip_availability.py @@ -79,10 +79,12 @@ class NetworksIpAvailabilityTest(base.BaseAdminNetworkTest): def _create_subnet(self, network, ip_version): if ip_version == lib_constants.IP_VERSION_4: cidr = netaddr.IPNetwork('20.0.0.0/24') - mask_bits = CONF.network.tenant_network_mask_bits + mask_bits = config.safe_get_config_value( + 'network', 'project_network_mask_bits') elif ip_version == lib_constants.IP_VERSION_6: cidr = netaddr.IPNetwork('20:db8::/64') - mask_bits = CONF.network.tenant_network_v6_mask_bits + mask_bits = config.safe_get_config_value( + 'network', 'project_network_v6_mask_bits') subnet_cidr = cidr.subnet(mask_bits).next() prefix_len = subnet_cidr.prefixlen diff --git a/neutron/tests/api/test_routers.py b/neutron/tests/api/test_routers.py index 83ee0870572..bc041655d1d 100644 --- a/neutron/tests/api/test_routers.py +++ b/neutron/tests/api/test_routers.py @@ -34,9 +34,10 @@ class RoutersTest(base.BaseRouterTest): @classmethod def resource_setup(cls): super(RoutersTest, cls).resource_setup() - cls.tenant_cidr = (CONF.network.tenant_network_cidr - if cls._ip_version == 4 else - CONF.network.tenant_network_v6_cidr) + cls.tenant_cidr = ( + config.safe_get_config_value('network', 'project_network_cidr') + if cls._ip_version == 4 else + config.safe_get_config_value('network', 'project_network_v6_cidr')) @test.attr(type='smoke') @test.idempotent_id('c72c1c0c-2193-4aca-eeee-b1442640eeee') diff --git a/neutron/tests/api/test_security_groups_negative.py b/neutron/tests/api/test_security_groups_negative.py index 84cd87a6a7c..4e295d0fe22 100644 --- a/neutron/tests/api/test_security_groups_negative.py +++ b/neutron/tests/api/test_security_groups_negative.py @@ -24,8 +24,6 @@ CONF = config.CONF class NegativeSecGroupTest(base.BaseSecGroupTest): - _tenant_network_cidr = CONF.network.tenant_network_cidr - @classmethod @test.requires_ext(extension="security-group", service="network") def resource_setup(cls): @@ -74,4 +72,3 @@ class NegativeSecGroupTest(base.BaseSecGroupTest): class NegativeSecGroupIPv6Test(NegativeSecGroupTest): _ip_version = 6 - _tenant_network_cidr = CONF.network.tenant_network_v6_cidr diff --git a/neutron/tests/tempest/config.py b/neutron/tests/tempest/config.py index 08b235a2a5f..f50fa3954f2 100644 --- a/neutron/tests/tempest/config.py +++ b/neutron/tests/tempest/config.py @@ -14,6 +14,7 @@ from oslo_config import cfg from tempest import config + CONF = config.CONF @@ -27,3 +28,20 @@ NeutronPluginOptions = [ # transition to the Tempest plugin architecture for opt in NeutronPluginOptions: CONF.register_opt(opt, 'neutron_plugin_options') + + +config_opts_translator = { + 'project_network_cidr': 'tenant_network_cidr', + 'project_network_v6_cidr': 'tenant_network_v6_cidr', + 'project_network_mask_bits': 'tenant_network_mask_bits', + 'project_network_v6_mask_bits': 'tenant_network_v6_mask_bits'} + + +def safe_get_config_value(group, name): + """Safely get Oslo config opts from Tempest, using old and new names.""" + conf_group = getattr(CONF, group) + + try: + return getattr(conf_group, name) + except cfg.NoSuchOptError: + return getattr(conf_group, config_opts_translator[name])