From e857bd637339315482572f130ff25778c126c9b4 Mon Sep 17 00:00:00 2001 From: Attila Fazekas Date: Mon, 21 Oct 2013 21:02:44 +0200 Subject: [PATCH] Preventing overlapping subnets in network scenarios Connecting subnets with the same cidr to the some router, is not too wise, and it might be prevented by neutron in several configuration. Change-Id: Ieb7da14be44a50b4324370b0193dd8590a3e4dac --- tempest/scenario/manager.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index 02a3c9d335..4dd51fb1bc 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -681,18 +681,32 @@ class NetworkScenarioTest(OfficialClientTest): Create a subnet for the given network within the cidr block configured for tenant networks. """ + + def cidr_in_use(cidr, tenant_id): + """ + :return True if subnet with cidr already exist in tenant + False else + """ + cidr_in_use = self._list_subnets(tenant_id=tenant_id, cidr=cidr) + return len(cidr_in_use) != 0 + tenant_cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr) result = None # Repeatedly attempt subnet creation with sequential cidr # blocks until an unallocated block is found. for subnet_cidr in tenant_cidr.subnet( CONF.network.tenant_network_mask_bits): + str_cidr = str(subnet_cidr) + if cidr_in_use(str_cidr, tenant_id=network.tenant_id): + continue + body = dict( subnet=dict( + name=data_utils.rand_name(namestart), ip_version=4, network_id=network.id, tenant_id=network.tenant_id, - cidr=str(subnet_cidr), + cidr=str_cidr, ), ) try: @@ -705,7 +719,7 @@ class NetworkScenarioTest(OfficialClientTest): self.assertIsNotNone(result, 'Unable to allocate tenant network') subnet = net_common.DeletableSubnet(client=self.network_client, **result['subnet']) - self.assertEqual(subnet.cidr, str(subnet_cidr)) + self.assertEqual(subnet.cidr, str_cidr) self.set_resource(data_utils.rand_name(namestart), subnet) return subnet