Fixed subnet gateway support to allow for disabling the gateway. 77/52777/3
authorspisarski <s.pisarski@cablelabs.com>
Tue, 27 Feb 2018 20:27:47 +0000 (13:27 -0700)
committerspisarski <s.pisarski@cablelabs.com>
Tue, 27 Feb 2018 21:58:03 +0000 (14:58 -0700)
JIRA: SNAPS-276

Change-Id: Ia676b91ee881097ca7502fb4b9f5c64961de2214
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
docs/how-to-use/IntegrationTests.rst
snaps/config/network.py
snaps/openstack/tests/create_network_tests.py
snaps/test_suite_builder.py

index cdadd96..4329120 100644 (file)
@@ -196,6 +196,25 @@ create_network_tests.py - CreateNetworkSuccessTests
 |                                       |               | 'admin' project ID                                        |
 +---------------------------------------+---------------+-----------------------------------------------------------+
 
+create_network_tests.py - CreateNetworkGatewayTests
+---------------------------------------------------
+
++---------------------------------------+---------------+-----------------------------------------------------------+
+| Test Name                             | Neutron API   | Description                                               |
++=======================================+===============+===========================================================+
+| test_create_subnet_default_gateway_ip | 2             | Ensures that a network can be created with a Subnet that  |
+|                                       |               | has the gateway_ip automatically assigned                 |
++---------------------------------------+---------------+-----------------------------------------------------------+
+| test_create_subnet_valid_gateway_ip   | 2             | Ensures that a network can be created with a Subnet that  |
+|                                       |               | has the gateway_ip statically assigned with a valid IP    |
++---------------------------------------+---------------+-----------------------------------------------------------+
+| test_create_subnet_no_gateway         | 2             | Ensures that a network can be created where no gateway_ip |
+|                                       |               | is assigned                                               |
++---------------------------------------+---------------+-----------------------------------------------------------+
+| test_create_subnet_invalid_gateway_ip | 2             | Ensures that a network cannot be created with a Subnet    |
+|                                       |               | has an invalid gateway_ip value such as 'foo'             |
++---------------------------------------+---------------+-----------------------------------------------------------+
+
 create_network_tests.py - CreateNetworkIPv6Tests
 ------------------------------------------------
 
index a2d008a..6805b30 100644 (file)
@@ -175,7 +175,10 @@ class SubnetConfig(object):
                              through authorization policies (optional)
         :param start: The start address for the allocation pools (optional)
         :param end: The end address for the allocation pools (optional)
-        :param gateway_ip: The gateway IP address (optional)
+        :param gateway_ip: The gateway IP address (optional). When not
+                           configured, the IP address will be automatically
+                           assigned; when 'none', no gateway address will be
+                           assigned, else the value must be valid
         :param enable_dhcp: Set to true if DHCP is enabled and false if DHCP is
                             disabled (optional)
         :param dns_nameservers: A list of DNS name servers for the subnet.
@@ -267,7 +270,10 @@ class SubnetConfig(object):
         if self.start and self.end:
             out['allocation_pools'] = [{'start': self.start, 'end': self.end}]
         if self.gateway_ip:
-            out['gateway_ip'] = self.gateway_ip
+            if self.gateway_ip == 'none':
+                out['gateway_ip'] = None
+            else:
+                out['gateway_ip'] = self.gateway_ip
         if self.enable_dhcp is not None:
             out['enable_dhcp'] = self.enable_dhcp
         if self.dns_nameservers and len(self.dns_nameservers) > 0:
index 42222ae..c0accc5 100644 (file)
@@ -15,6 +15,8 @@
 import unittest
 import uuid
 
+from neutronclient.common.exceptions import BadRequest
+
 from snaps.config.network import (
     NetworkConfig, SubnetConfig, SubnetConfigError, NetworkConfigError,
     PortConfigError, IPv6Mode)
@@ -555,6 +557,139 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase):
             self.router_creator.get_router().id, retrieved_router.id)
 
 
+class CreateNetworkGatewayTests(OSIntegrationTestCase):
+    """
+    Test for the CreateNetwork class defined in create_nework.py
+    """
+
+    def setUp(self):
+        """
+        Sets up object for test
+        """
+        super(self.__class__, self).__start__()
+
+        self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
+
+        self.neutron = neutron_utils.neutron_client(self.os_creds)
+
+        self.ip_prfx = '10.1.0.'
+
+        # Initialize for cleanup
+        self.net_creator = None
+
+    def tearDown(self):
+        """
+        Cleans the network
+        """
+        if self.net_creator:
+            self.net_creator.clean()
+
+        super(self.__class__, self).__clean__()
+
+    def test_create_subnet_default_gateway_ip(self):
+        """
+        Tests the creation of an OpenStack network with a subnet that has a
+        default value assigned to the gateway IP.
+        """
+        # Create Network
+        subnet_config = SubnetConfig(
+            name=self.guid + '-subnet', cidr=self.ip_prfx + '0/24')
+        net_config = NetworkConfig(
+            name=self.guid + '-net', subnets=[subnet_config])
+        self.net_creator = OpenStackNetwork(
+            self.os_creds, net_config)
+        out_net = self.net_creator.create()
+
+        # Validate network was created
+        self.assertTrue(neutron_utils_tests.validate_network(
+            self.neutron, self.keystone,
+            self.net_creator.network_settings.name, True,
+            self.os_creds.project_name))
+
+        # Validate subnets
+        self.assertTrue(neutron_utils_tests.validate_subnet(
+            self.neutron,
+            self.net_creator.network_settings.subnet_settings[0].name,
+            self.net_creator.network_settings.subnet_settings[0].cidr, True))
+
+        self.assertEqual(self.ip_prfx + '1', out_net.subnets[0].gateway_ip)
+
+    def test_create_subnet_valid_gateway_ip(self):
+        """
+        Tests the creation of an OpenStack network with a subnet that has a
+        valid value assigned to the gateway IP.
+        """
+        # Create Network
+        subnet_config = SubnetConfig(
+            name=self.guid + '-subnet', cidr=self.ip_prfx + '0/24',
+            gateway_ip=self.ip_prfx + '2')
+        net_config = NetworkConfig(
+            name=self.guid + '-net', subnets=[subnet_config])
+        self.net_creator = OpenStackNetwork(
+            self.os_creds, net_config)
+        out_net = self.net_creator.create()
+
+        # Validate network was created
+        self.assertTrue(neutron_utils_tests.validate_network(
+            self.neutron, self.keystone,
+            self.net_creator.network_settings.name, True,
+            self.os_creds.project_name))
+
+        # Validate subnets
+        self.assertTrue(neutron_utils_tests.validate_subnet(
+            self.neutron,
+            self.net_creator.network_settings.subnet_settings[0].name,
+            self.net_creator.network_settings.subnet_settings[0].cidr, True))
+
+        self.assertEqual(self.ip_prfx + '2', out_net.subnets[0].gateway_ip)
+
+    def test_create_subnet_no_gateway(self):
+        """
+        Tests the creation of an OpenStack network with a subnet that has a
+        valid value assigned to the gateway IP.
+        """
+        # Create Network
+        subnet_config = SubnetConfig(
+            name=self.guid + '-subnet', cidr=self.ip_prfx + '0/24',
+            gateway_ip='none')
+        net_config = NetworkConfig(
+            name=self.guid + '-net', subnets=[subnet_config])
+        self.net_creator = OpenStackNetwork(
+            self.os_creds, net_config)
+        out_net = self.net_creator.create()
+
+        # Validate network was created
+        self.assertTrue(neutron_utils_tests.validate_network(
+            self.neutron, self.keystone,
+            self.net_creator.network_settings.name, True,
+            self.os_creds.project_name))
+
+        # Validate subnets
+        self.assertTrue(neutron_utils_tests.validate_subnet(
+            self.neutron,
+            self.net_creator.network_settings.subnet_settings[0].name,
+            self.net_creator.network_settings.subnet_settings[0].cidr, True))
+
+        self.assertIsNone(out_net.subnets[0].gateway_ip)
+
+    def test_create_subnet_invalid_gateway_ip(self):
+        """
+        Tests the creation of an OpenStack network with a subnet that has an
+        invalid value assigned to the gateway IP.
+        """
+        # Create Network
+        subnet_config = SubnetConfig(
+            name=self.guid + '-subnet', cidr=self.ip_prfx + '0/24',
+            gateway_ip='foo')
+        net_config = NetworkConfig(
+            name=self.guid + '-net', subnets=[subnet_config])
+        self.net_creator = OpenStackNetwork(
+            self.os_creds, net_config)
+
+        with self.assertRaises(BadRequest):
+            self.net_creator.create()
+
+
 class CreateNetworkIPv6Tests(OSIntegrationTestCase):
     """
     Test for the CreateNetwork class defined in create_nework.py when
index aae6618..29429be 100644 (file)
@@ -76,7 +76,8 @@ from snaps.openstack.tests.create_keypairs_tests import (
     CreateKeypairsTests, KeypairSettingsUnitTests, CreateKeypairsCleanupTests)
 from snaps.openstack.tests.create_network_tests import (
     CreateNetworkSuccessTests, NetworkSettingsUnitTests, PortSettingsUnitTests,
-    SubnetSettingsUnitTests, CreateNetworkTypeTests, CreateNetworkIPv6Tests)
+    SubnetSettingsUnitTests, CreateNetworkTypeTests, CreateNetworkIPv6Tests,
+    CreateNetworkGatewayTests)
 from snaps.openstack.tests.create_project_tests import (
     CreateProjectSuccessTests, ProjectSettingsUnitTests,
     CreateProjectUserTests)
@@ -503,6 +504,11 @@ def add_openstack_integration_tests(suite, os_creds, ext_net_name,
         ext_net_name=ext_net_name, use_keystone=use_keystone,
         flavor_metadata=flavor_metadata, image_metadata=image_metadata,
         log_level=log_level))
+    suite.addTest(OSIntegrationTestCase.parameterize(
+        CreateNetworkGatewayTests, os_creds=os_creds,
+        ext_net_name=ext_net_name, use_keystone=use_keystone,
+        flavor_metadata=flavor_metadata, image_metadata=image_metadata,
+        log_level=log_level))
     suite.addTest(OSIntegrationTestCase.parameterize(
         CreateNetworkIPv6Tests, os_creds=os_creds,
         ext_net_name=ext_net_name, use_keystone=use_keystone,