Cleanup subnet creation in network api tests
This commit accomplishes 2 things, first it deduplicates the subnet
creation code by changing test_create_update_delete_network_subnet()
to use the common create_subnet() class method. Secondly the common
create_subnet() method is changed to properly use else after the for
loop instead of what was done before.
Change-Id: I04b0516e03eeb8b8f95d72259aa78f573db6ae45
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index 8720985..ba6a617 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -152,8 +152,6 @@
cidr = netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr)
mask_bits = CONF.network.tenant_network_v6_mask_bits
# Find a cidr that is not in use yet and create a subnet with it
- body = None
- failure = None
for subnet_cidr in cidr.subnet(mask_bits):
try:
resp, body = cls.client.create_subnet(
@@ -165,12 +163,9 @@
is_overlapping_cidr = 'overlaps with another subnet' in str(e)
if not is_overlapping_cidr:
raise
- # save the failure in case all of the CIDRs are overlapping
- failure = e
-
- if not body and failure:
- raise failure
-
+ else:
+ message = 'Available CIDR for subnet creation could not be found'
+ raise exceptions.BuildErrorException(message)
subnet = body['subnet']
cls.subnets.append(subnet)
return subnet