From 330ebbb1b14cc0f7abf0cd7873461c858a1e645f Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Tue, 20 Jun 2017 19:58:58 +0000 Subject: [PATCH] functional-tests: Make addresses for tunneling unique OVS can hold only one tunnel with same endpoints. Some tests had hardcoded values for both tunnel endpoints which made them unable to run in parallel manner. This patch takes always exclusive address using resource allocator. Change-Id: If81296d54656551b24917d561f235edb96a6c2df Closes-bug: #1697533 --- .../common/exclusive_resources/ip_address.py | 21 +++++++++++++++++++ neutron/tests/functional/agent/linux/base.py | 9 ++++++++ .../tests/functional/agent/test_ovs_flows.py | 4 ++-- .../tests/functional/agent/test_ovs_lib.py | 4 ++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/neutron/tests/common/exclusive_resources/ip_address.py b/neutron/tests/common/exclusive_resources/ip_address.py index c74b9d987d7..8935c7888ad 100644 --- a/neutron/tests/common/exclusive_resources/ip_address.py +++ b/neutron/tests/common/exclusive_resources/ip_address.py @@ -19,6 +19,27 @@ import netaddr from neutron.tests.common.exclusive_resources import resource_allocator +TEST_NET_RANGE = { + 1: ('192.0.2.1', '192.0.2.254'), + 2: ('198.51.100.1', '198.51.100.254'), + 3: ('203.0.113.1', '203.0.113.254'), +} + + +def get_test_net_address_fixture(test_net_number): + """Return exclusive ip address on the system based on RFC 5737. + + :param block: One of following constants: 1, 2, 3 + + https://tools.ietf.org/html/rfc5737 + """ + try: + net_range = TEST_NET_RANGE[test_net_number] + except KeyError: + raise ValueError("Unknown constant for TEST-NET: %d" % test_net_number) + + return ExclusiveIPAddress(*net_range) + def get_random_ip(low, high): parent_range = netaddr.IPRange(low, high) diff --git a/neutron/tests/functional/agent/linux/base.py b/neutron/tests/functional/agent/linux/base.py index 36baa9b564c..9b520a52366 100644 --- a/neutron/tests/functional/agent/linux/base.py +++ b/neutron/tests/functional/agent/linux/base.py @@ -14,6 +14,7 @@ import testscenarios +from neutron.tests.common.exclusive_resources import ip_address from neutron.tests.functional import base @@ -37,3 +38,11 @@ class BaseOVSLinuxTestCase(testscenarios.WithScenarios, base.BaseSudoTestCase): def setUp(self): super(BaseOVSLinuxTestCase, self).setUp() self.config(group='OVS', ovsdb_interface=self.ovsdb_interface) + + def get_test_net_address(self, block): + """Return exclusive address based on RFC 5737. + + :param block: One of constants 1, 2 or 3 + """ + return str(self.useFixture( + ip_address.get_test_net_address_fixture(block)).address) diff --git a/neutron/tests/functional/agent/test_ovs_flows.py b/neutron/tests/functional/agent/test_ovs_flows.py index c4cd8b993bb..5e0161f5248 100644 --- a/neutron/tests/functional/agent/test_ovs_flows.py +++ b/neutron/tests/functional/agent/test_ovs_flows.py @@ -428,8 +428,8 @@ class OVSFlowTestCase(OVSAgentTestBase): @helpers.skip_if_ovs_older_than("2.5.1") def test_install_flood_to_tun(self): attrs = { - 'remote_ip': '192.0.2.1', # RFC 5737 TEST-NET-1 - 'local_ip': '198.51.100.1', # RFC 5737 TEST-NET-2 + 'remote_ip': self.get_test_net_address(1), + 'local_ip': self.get_test_net_address(2), } kwargs = {'vlan': 777, 'tun_id': 888} port_name = common_utils.get_rand_device_name(net_helpers.PORT_PREFIX) diff --git a/neutron/tests/functional/agent/test_ovs_lib.py b/neutron/tests/functional/agent/test_ovs_lib.py index 32df6964596..b5a32684cc4 100644 --- a/neutron/tests/functional/agent/test_ovs_lib.py +++ b/neutron/tests/functional/agent/test_ovs_lib.py @@ -206,8 +206,8 @@ class OVSBridgeTestCase(OVSBridgeTestBase): def test_add_tunnel_port_ipv4(self): attrs = { - 'remote_ip': '192.0.2.1', # RFC 5737 TEST-NET-1 - 'local_ip': '198.51.100.1', # RFC 5737 TEST-NET-2 + 'remote_ip': self.get_test_net_address(1), + 'local_ip': self.get_test_net_address(2), } self._test_add_tunnel_port(attrs)