summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2018-02-27 13:27:47 -0700
committerspisarski <s.pisarski@cablelabs.com>2018-02-27 14:58:03 -0700
commit65f23fa8e2f0a6a402546229a321a5fea4bc2ffb (patch)
tree35f22cc15366cac91b9d0529a6242820eeebad3f
parentc711acf8ae3e4ad6f746500747857bcc9fd6f7be (diff)
Fixed subnet gateway support to allow for disabling the gateway.
JIRA: SNAPS-276 Change-Id: Ia676b91ee881097ca7502fb4b9f5c64961de2214 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--docs/how-to-use/IntegrationTests.rst19
-rw-r--r--snaps/config/network.py10
-rw-r--r--snaps/openstack/tests/create_network_tests.py135
-rw-r--r--snaps/test_suite_builder.py8
4 files changed, 169 insertions, 3 deletions
diff --git a/docs/how-to-use/IntegrationTests.rst b/docs/how-to-use/IntegrationTests.rst
index cdadd96..4329120 100644
--- a/docs/how-to-use/IntegrationTests.rst
+++ b/docs/how-to-use/IntegrationTests.rst
@@ -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
------------------------------------------------
diff --git a/snaps/config/network.py b/snaps/config/network.py
index a2d008a..6805b30 100644
--- a/snaps/config/network.py
+++ b/snaps/config/network.py
@@ -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:
diff --git a/snaps/openstack/tests/create_network_tests.py b/snaps/openstack/tests/create_network_tests.py
index 42222ae..c0accc5 100644
--- a/snaps/openstack/tests/create_network_tests.py
+++ b/snaps/openstack/tests/create_network_tests.py
@@ -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
diff --git a/snaps/test_suite_builder.py b/snaps/test_suite_builder.py
index aae6618..29429be 100644
--- a/snaps/test_suite_builder.py
+++ b/snaps/test_suite_builder.py
@@ -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)
@@ -504,6 +505,11 @@ def add_openstack_integration_tests(suite, os_creds, ext_net_name,
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,
flavor_metadata=flavor_metadata, image_metadata=image_metadata,