Fix automatic subnet CIDR generation

This helps generating subnet masks by checking for
subnet masks already used from the same test class.

This also avoids having to check if a subnet with
conflicting subnet CIDR already exists treating
subnet error creation by looking in a local set
of already reserved CIDRs.

It fixes a problem that makes create_subnet
try to reuse the same CIDRs more than once
producing test failures.

It also allows methods to blank list some CIDRs
to avoid create_subnet from using it an therefore
avoid interferences.

Change-Id: I73e08a6832777d972990c3e68c582ef61568ad4e
diff --git a/neutron_tempest_plugin/scenario/test_floatingip.py b/neutron_tempest_plugin/scenario/test_floatingip.py
index 94ce482..251f21c 100644
--- a/neutron_tempest_plugin/scenario/test_floatingip.py
+++ b/neutron_tempest_plugin/scenario/test_floatingip.py
@@ -13,7 +13,6 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import netaddr
 from neutron_lib import constants as lib_constants
 from neutron_lib.services.qos import constants as qos_consts
 from tempest.common import utils
@@ -76,8 +75,7 @@
     @classmethod
     def _create_dest_network(cls):
         network = cls.create_network()
-        subnet = cls.create_subnet(network,
-            cidr=netaddr.IPNetwork('10.10.0.0/24'))
+        subnet = cls.create_subnet(network)
         cls.create_router_interface(cls.router['id'], subnet['id'])
         return network
 
diff --git a/neutron_tempest_plugin/scenario/test_mtu.py b/neutron_tempest_plugin/scenario/test_mtu.py
index 932c645..8f1c9ed 100644
--- a/neutron_tempest_plugin/scenario/test_mtu.py
+++ b/neutron_tempest_plugin/scenario/test_mtu.py
@@ -12,7 +12,6 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
-import netaddr
 
 from neutron_lib.api.definitions import provider_net
 from tempest.common import utils
@@ -83,16 +82,14 @@
     def _create_setup(self):
         self.admin_client = self.os_admin.network_client
         net_kwargs = {'tenant_id': self.client.tenant_id}
-        for sub, net_type in (
-                ('10.100.0.0/16', 'vxlan'), ('10.200.0.0/16', 'gre')):
+        for net_type in ['vxlan', 'gre']:
             net_kwargs['name'] = '-'.join([net_type, 'net'])
             net_kwargs['provider:network_type'] = net_type
             network = self.admin_client.create_network(**net_kwargs)[
                 'network']
             self.networks.append(network)
             self.addCleanup(self.admin_client.delete_network, network['id'])
-            cidr = netaddr.IPNetwork(sub)
-            subnet = self.create_subnet(network, cidr=cidr)
+            subnet = self.create_subnet(network)
             self.create_router_interface(self.router['id'], subnet['id'])
             self.addCleanup(self.client.remove_router_interface_with_subnet_id,
                             self.router['id'], subnet['id'])
@@ -165,14 +162,13 @@
         self.admin_client = self.os_admin.network_client
         net_kwargs = {'tenant_id': self.client.tenant_id,
                       'provider:network_type': 'vxlan'}
-        for sub in ('10.100.0.0/16', '10.200.0.0/16'):
+        for _ in range(2):
             net_kwargs['name'] = data_utils.rand_name('net')
             network = self.admin_client.create_network(**net_kwargs)[
                 'network']
             self.networks.append(network)
             self.addCleanup(self.admin_client.delete_network, network['id'])
-            cidr = netaddr.IPNetwork(sub)
-            subnet = self.create_subnet(network, cidr=cidr)
+            subnet = self.create_subnet(network)
             self.create_router_interface(self.router['id'], subnet['id'])
             self.addCleanup(self.client.remove_router_interface_with_subnet_id,
                             self.router['id'], subnet['id'])
diff --git a/neutron_tempest_plugin/scenario/test_trunk.py b/neutron_tempest_plugin/scenario/test_trunk.py
index 44f5ba7..77a2844 100644
--- a/neutron_tempest_plugin/scenario/test_trunk.py
+++ b/neutron_tempest_plugin/scenario/test_trunk.py
@@ -12,7 +12,6 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import netaddr
 from oslo_log import log as logging
 from tempest.common import utils as tutils
 from tempest.common import waiters
@@ -38,10 +37,6 @@
     'dhclient $IFACE.%(tag)d"')
 
 
-def get_next_subnet(cidr):
-    return netaddr.IPNetwork(cidr).next()
-
-
 class TrunkTest(base.BaseTempestTestCase):
     credentials = ['primary']
     force_tenant_isolation = False
@@ -233,9 +228,7 @@
         vlan_tag = 10
 
         vlan_network = self.create_network()
-        new_subnet_cidr = get_next_subnet(
-            config.safe_get_config_value('network', 'project_network_cidr'))
-        self.create_subnet(vlan_network, gateway=None, cidr=new_subnet_cidr)
+        self.create_subnet(vlan_network)
 
         servers = [
             self._create_server_with_port_and_subport(vlan_network, vlan_tag)