Raise BadRequest if unable to create subnet

The existing create_subnet method iterates over subnets looking for one
that it can use and filters out any errors for overlapping CIDRs. The
problem is if a usable subnet is not found, the code goes on to use an
undeclared variable (body).

This patch saves the last overlapping CIDR exception and raises it if no
usable subnet is found to avoid the undeclared variable usage.

Fixes bug 1186445

Change-Id: I9ba4feada05a65a592bbd04ce8b722200e80b165
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index e0e40cb..8068284 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -73,6 +73,7 @@
         cidr = netaddr.IPNetwork(cls.network_cfg.tenant_network_cidr)
         mask_bits = cls.network_cfg.tenant_network_mask_bits
         # Find a cidr that is not in use yet and create a subnet with it
+        failure = None
         for subnet_cidr in cidr.subnet(mask_bits):
             try:
                 resp, body = cls.client.create_subnet(network['id'],
@@ -82,6 +83,12 @@
                 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
+
         subnet = body['subnet']
         cls.subnets.append(subnet)
         return subnet