Network API: default to ipv4, add ipv6 tests

Change-Id: I34da0ede4d7b92b2e752c2da82172c495e1946b1
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 990cb37..913f41c 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -525,13 +525,20 @@
 # value)
 #region=
 
-# The cidr block to allocate tenant networks from (string
+# The cidr block to allocate tenant ipv4 subnets from (string
 # value)
 #tenant_network_cidr=10.100.0.0/16
 
-# The mask bits for tenant networks (integer value)
+# The mask bits for tenant ipv4 subnets (integer value)
 #tenant_network_mask_bits=28
 
+# The cidr block to allocate tenant ipv6 subnets from (string
+# value)
+#tenant_network_v6_cidr=2003::/64
+
+# The mask bits for tenant ipv6 subnets (integer value)
+#tenant_network_v6_mask_bits=96
+
 # Whether tenant network connectivity should be evaluated
 # directly (boolean value)
 #tenant_networks_reachable=false
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index b129786..e188a45 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -51,6 +51,11 @@
 
     force_tenant_isolation = False
 
+    # Default to ipv4.
+    _ip_version = 4
+    _tenant_network_cidr = CONF.network.tenant_network_cidr
+    _tenant_network_mask_bits = CONF.network.tenant_network_mask_bits
+
     @classmethod
     def setUpClass(cls):
         # Create no network resources for these test.
@@ -130,10 +135,11 @@
         return network
 
     @classmethod
-    def create_subnet(cls, network, ip_version=4):
+    def create_subnet(cls, network):
         """Wrapper utility that returns a test subnet."""
-        cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
-        mask_bits = CONF.network.tenant_network_mask_bits
+        # The cidr and mask_bits depend on the ip version.
+        cidr = netaddr.IPNetwork(cls._tenant_network_cidr)
+        mask_bits = cls._tenant_network_mask_bits
         # Find a cidr that is not in use yet and create a subnet with it
         body = None
         failure = None
@@ -142,7 +148,7 @@
                 resp, body = cls.client.create_subnet(
                     network_id=network['id'],
                     cidr=str(subnet_cidr),
-                    ip_version=ip_version)
+                    ip_version=cls._ip_version)
                 break
             except exceptions.BadRequest as e:
                 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py
index aee2a44..c3ce7c9 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -45,14 +45,20 @@
         network update
         subnet update
 
+        All subnet tests are run once with ipv4 and once with ipv6.
+
     v2.0 of the Neutron API is assumed. It is also assumed that the following
     options are defined in the [network] section of etc/tempest.conf:
 
         tenant_network_cidr with a block of cidr's from which smaller blocks
-        can be allocated for tenant networks
+        can be allocated for tenant ipv4 subnets
+
+        tenant_network_v6_cidr is the equivalent for ipv6 subnets
 
         tenant_network_mask_bits with the mask bits to be used to partition the
-        block defined by tenant-network_cidr
+        block defined by tenant_network_cidr
+
+        tenant_network_v6_mask_bits is the equivalent for ipv6 subnets
     """
 
     @classmethod
@@ -79,14 +85,14 @@
         updated_net = body['network']
         self.assertEqual(updated_net['name'], new_name)
         # Find a cidr that is not in use yet and create a subnet with it
-        cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
-        mask_bits = CONF.network.tenant_network_mask_bits
+        cidr = netaddr.IPNetwork(self._tenant_network_cidr)
+        mask_bits = self._tenant_network_mask_bits
         for subnet_cidr in cidr.subnet(mask_bits):
             try:
                 resp, body = self.client.create_subnet(
                     network_id=net_id,
                     cidr=str(subnet_cidr),
-                    ip_version=4)
+                    ip_version=self._ip_version)
                 break
             except exceptions.BadRequest as e:
                 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
@@ -392,3 +398,13 @@
 
 class BulkNetworkOpsTestXML(BulkNetworkOpsTestJSON):
     _interface = 'xml'
+
+
+class NetworksIpV6TestJSON(NetworksTestJSON):
+    _ip_version = 6
+    _tenant_network_cidr = CONF.network.tenant_network_v6_cidr
+    _tenant_network_mask_bits = CONF.network.tenant_network_v6_mask_bits
+
+
+class NetworksIpV6TestXML(NetworksIpV6TestJSON):
+    _interface = 'xml'
diff --git a/tempest/config.py b/tempest/config.py
index 068193b..6c11272 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -314,10 +314,16 @@
                     "used."),
     cfg.StrOpt('tenant_network_cidr',
                default="10.100.0.0/16",
-               help="The cidr block to allocate tenant networks from"),
+               help="The cidr block to allocate tenant ipv4 subnets from"),
     cfg.IntOpt('tenant_network_mask_bits',
                default=28,
-               help="The mask bits for tenant networks"),
+               help="The mask bits for tenant ipv4 subnets"),
+    cfg.StrOpt('tenant_network_v6_cidr',
+               default="2003::/64",
+               help="The cidr block to allocate tenant ipv6 subnets from"),
+    cfg.IntOpt('tenant_network_v6_mask_bits',
+               default=96,
+               help="The mask bits for tenant ipv6 subnets"),
     cfg.BoolOpt('tenant_networks_reachable',
                 default=False,
                 help="Whether tenant network connectivity should be "