From 65f23fa8e2f0a6a402546229a321a5fea4bc2ffb Mon Sep 17 00:00:00 2001 From: spisarski Date: Tue, 27 Feb 2018 13:27:47 -0700 Subject: Fixed subnet gateway support to allow for disabling the gateway. JIRA: SNAPS-276 Change-Id: Ia676b91ee881097ca7502fb4b9f5c64961de2214 Signed-off-by: spisarski --- snaps/openstack/tests/create_network_tests.py | 135 ++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) (limited to 'snaps/openstack/tests/create_network_tests.py') 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 -- cgit 1.2.3-korg