X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=snaps%2Fopenstack%2Ftests%2Fcreate_network_tests.py;h=42222aec039f36075999d6c9661d47526310e3a9;hb=c711acf8ae3e4ad6f746500747857bcc9fd6f7be;hp=966cbd0fd6eeb3f26d80493ea42ab999587670d1;hpb=4f405406ff3f16c7e6c8ebbebd9c83dd94d02048;p=snaps.git diff --git a/snaps/openstack/tests/create_network_tests.py b/snaps/openstack/tests/create_network_tests.py index 966cbd0..42222ae 100644 --- a/snaps/openstack/tests/create_network_tests.py +++ b/snaps/openstack/tests/create_network_tests.py @@ -24,7 +24,7 @@ from snaps.openstack.create_network import ( from snaps.openstack.tests import openstack_tests from snaps.openstack.tests.os_source_file_test import ( OSIntegrationTestCase, OSComponentTestCase) -from snaps.openstack.utils import neutron_utils +from snaps.openstack.utils import neutron_utils, keystone_utils from snaps.openstack.utils.tests import neutron_utils_tests from snaps.openstack.create_network import IPv6Mode as IPv6Mode_old @@ -136,8 +136,7 @@ class SubnetSettingsUnitTests(unittest.TestCase): self.assertIsNone(settings.start) self.assertIsNone(settings.end) self.assertIsNone(settings.enable_dhcp) - self.assertEqual(1, len(settings.dns_nameservers)) - self.assertEqual('8.8.8.8', settings.dns_nameservers[0]) + self.assertEqual(0, len(settings.dns_nameservers)) self.assertIsNone(settings.host_routes) self.assertIsNone(settings.destination) self.assertIsNone(settings.nexthop) @@ -154,8 +153,7 @@ class SubnetSettingsUnitTests(unittest.TestCase): self.assertIsNone(settings.end) self.assertIsNone(settings.gateway_ip) self.assertIsNone(settings.enable_dhcp) - self.assertEqual(1, len(settings.dns_nameservers)) - self.assertEqual('8.8.8.8', settings.dns_nameservers[0]) + self.assertEqual(0, len(settings.dns_nameservers)) self.assertIsNone(settings.host_routes) self.assertIsNone(settings.destination) self.assertIsNone(settings.nexthop) @@ -392,13 +390,15 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): Tests the creation of an OpenStack network without a router. """ # Create Network - self.net_creator = OpenStackNetwork(self.os_creds, - self.net_config.network_settings) + self.net_creator = OpenStackNetwork( + self.os_creds, self.net_config.network_settings) self.net_creator.create() # Validate network was created self.assertTrue(neutron_utils_tests.validate_network( - self.neutron, self.net_creator.network_settings.name, True)) + 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( @@ -411,18 +411,22 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): Tests the creation of an OpenStack network, it's deletion, then cleanup """ # Create Network - self.net_creator = OpenStackNetwork(self.os_creds, - self.net_config.network_settings) + self.net_creator = OpenStackNetwork( + self.os_creds, self.net_config.network_settings) self.net_creator.create() # Validate network was created self.assertTrue(neutron_utils_tests.validate_network( - self.neutron, self.net_creator.network_settings.name, True)) + self.neutron, self.keystone, + self.net_creator.network_settings.name, True, + self.os_creds.project_name)) - neutron_utils.delete_network(self.neutron, - self.net_creator.get_network()) + neutron_utils.delete_network( + self.neutron, self.net_creator.get_network()) self.assertIsNone(neutron_utils.get_network( - self.neutron, network_settings=self.net_creator.network_settings)) + self.neutron, self.keystone, + network_settings=self.net_creator.network_settings, + project_name=self.os_creds.project_name)) # This shall not throw an exception here self.net_creator.clean() @@ -432,8 +436,8 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): Tests the creation of an OpenStack network with a router. """ # Create Network - self.net_creator = OpenStackNetwork(self.os_creds, - self.net_config.network_settings) + self.net_creator = OpenStackNetwork( + self.os_creds, self.net_config.network_settings) self.net_creator.create() # Create Router @@ -443,7 +447,9 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): # Validate network was created self.assertTrue(neutron_utils_tests.validate_network( - self.neutron, self.net_creator.network_settings.name, True)) + 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( @@ -466,12 +472,12 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): OpenStackNetwork object will not create a second. """ # Create Network - self.net_creator = OpenStackNetwork(self.os_creds, - self.net_config.network_settings) + self.net_creator = OpenStackNetwork( + self.os_creds, self.net_config.network_settings) self.net_creator.create() - self.net_creator2 = OpenStackNetwork(self.os_creds, - self.net_config.network_settings) + self.net_creator2 = OpenStackNetwork( + self.os_creds, self.net_config.network_settings) self.net_creator2.create() self.assertEqual(self.net_creator.get_network().id, @@ -479,27 +485,36 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): def test_create_network_router_admin_user_to_new_project(self): """ - Tests the creation of an OpenStack network and router with the current - user to the admin project. + Tests the creation of an OpenStack network to the the current using + the credentials to the admin project. """ # Create Network/Subnet where the project names have been changed - admin_project_name = self.admin_os_creds.project_name - self.net_config.network_settings.project_name = admin_project_name - self.net_config.network_settings.subnet_settings[0].project_name = \ - admin_project_name - self.net_creator = OpenStackNetwork(self.os_creds, - self.net_config.network_settings) + project_name = self.os_creds.project_name + config = self.net_config.network_settings + config.project_name = project_name + config.subnet_settings[0].project_name = project_name + + self.net_creator = OpenStackNetwork(self.admin_os_creds, config) self.net_creator.create() retrieved_net = neutron_utils.get_network( - self.neutron, network_settings=self.net_config.network_settings) + self.neutron, self.keystone, + network_name=self.net_config.network_settings.name, + project_name=self.os_creds.project_name) self.assertEqual(self.net_creator.get_network().id, retrieved_net.id) + # Initialize with actual credentials + config.project_name = None + config.subnet_settings[0].project_name = None + proj_net_creator = OpenStackNetwork(self.os_creds, config) + proj_net = proj_net_creator.create() + self.assertEqual(retrieved_net, proj_net) + # Create Router - self.net_config.router_settings.project_name = admin_project_name + self.net_config.router_settings.project_name = project_name self.router_creator = create_router.OpenStackRouter( - self.os_creds, self.net_config.router_settings) + self.admin_os_creds, self.net_config.router_settings) self.router_creator.create() retrieved_router = neutron_utils.get_router( @@ -517,12 +532,14 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): self.net_config.network_settings.project_name = new_project_name self.net_config.network_settings.subnet_settings[0].project_name = \ new_project_name - self.net_creator = OpenStackNetwork(self.admin_os_creds, - self.net_config.network_settings) + self.net_creator = OpenStackNetwork( + self.admin_os_creds, self.net_config.network_settings) self.net_creator.create() retrieved_net = neutron_utils.get_network( - self.neutron, network_settings=self.net_config.network_settings) + self.neutron, self.keystone, + network_settings=self.net_config.network_settings, + project_name=self.os_creds.project_name) self.assertEqual(self.net_creator.get_network().id, retrieved_net.id) @@ -540,7 +557,7 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase): class CreateNetworkIPv6Tests(OSIntegrationTestCase): """ - Test for the CreateNetwork class defined in create_nework.py when + Test for the CreateNetwork class defined in create_nework.py when """ def setUp(self): @@ -580,7 +597,9 @@ class CreateNetworkIPv6Tests(OSIntegrationTestCase): # Validate network was created self.assertTrue(neutron_utils_tests.validate_network( - self.neutron, self.net_creator.network_settings.name, True)) + self.neutron, self.keystone, + self.net_creator.network_settings.name, True, + self.os_creds.project_name)) network = self.net_creator.get_network() self.assertEqual(1, len(network.subnets)) @@ -627,7 +646,7 @@ class CreateNetworkIPv6Tests(OSIntegrationTestCase): self.assertEqual(subnet4_settings.name, subnet4.name) self.assertEqual(subnet4_settings.cidr, subnet4.cidr) self.assertEqual(4, subnet4.ip_version) - self.assertEqual(1, len(subnet4.dns_nameservers)) + self.assertEqual(0, len(subnet4.dns_nameservers)) # Validate IPv6 subnet self.assertEqual(network.id, subnet6.network_id) @@ -652,6 +671,7 @@ class CreateNetworkTypeTests(OSComponentTestCase): net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet') self.neutron = neutron_utils.neutron_client(self.os_creds) + self.keystone = keystone_utils.keystone_client(self.os_creds) # Initialize for cleanup self.net_creator = None @@ -680,7 +700,8 @@ class CreateNetworkTypeTests(OSComponentTestCase): # Validate network was created self.assertTrue(neutron_utils_tests.validate_network( - self.neutron, net_settings.name, True)) + self.neutron, self.keystone, net_settings.name, True, + self.os_creds.project_name)) self.assertEquals(network_type, network.type) @@ -709,7 +730,8 @@ class CreateNetworkTypeTests(OSComponentTestCase): # Validate network was created self.assertTrue(neutron_utils_tests.validate_network( - self.neutron, net_settings.name, True)) + self.neutron, self.keystone, net_settings.name, True, + self.os_creds.project_name)) self.assertEquals(network_type, network.type) @@ -730,7 +752,8 @@ class CreateNetworkTypeTests(OSComponentTestCase): # Validate network was created self.assertTrue(neutron_utils_tests.validate_network( - self.neutron, net_settings.name, True)) + self.neutron, self.keystone, net_settings.name, True, + self.os_creds.project_name)) self.assertEqual(network_type, network.type) @@ -753,7 +776,8 @@ class CreateNetworkTypeTests(OSComponentTestCase): # Validate network was created self.assertTrue(neutron_utils_tests.validate_network( - self.neutron, net_settings.name, True)) + self.neutron, self.keystone, net_settings.name, True, + self.os_creds.project_name)) self.assertEquals(network_type, network.type) @@ -771,3 +795,92 @@ class CreateNetworkTypeTests(OSComponentTestCase): self.net_creator = OpenStackNetwork(self.os_creds, net_settings) with self.assertRaises(Exception): self.net_creator.create() + + +class CreateMultipleNetworkTests(OSIntegrationTestCase): + """ + Test for the CreateNetwork class and how it interacts with networks + groups within other projects with the same name + """ + + def setUp(self): + """ + Sets up object for test + """ + super(self.__class__, self).__start__() + + guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) + self.net_config = openstack_tests.get_pub_net_config( + net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet') + + self.neutron = neutron_utils.neutron_client(self.os_creds) + + # Initialize for cleanup + self.admin_net_creator = None + self.proj_net_creator = None + + def tearDown(self): + """ + Cleans the network + """ + if self.admin_net_creator: + self.admin_net_creator.clean() + if self.proj_net_creator: + self.proj_net_creator.clean() + + super(self.__class__, self).__clean__() + + def test_network_same_name_diff_proj(self): + """ + Tests the creation of an OpenStackNetwork with the same name + within a different project/tenant when not configured but implied by + the OSCreds. + """ + # Create Network + + self.admin_net_creator = OpenStackNetwork( + self.admin_os_creds, self.net_config.network_settings) + self.admin_net_creator.create() + + self.proj_net_creator = OpenStackNetwork( + self.os_creds, self.net_config.network_settings) + self.proj_net_creator.create() + + self.assertNotEqual( + self.admin_net_creator.get_network().id, + self.proj_net_creator.get_network().id) + + admin_creator2 = OpenStackNetwork( + self.admin_os_creds, self.net_config.network_settings) + admin_creator2.create() + self.assertEqual( + self.admin_net_creator.get_network(), admin_creator2.get_network()) + + proj_creator2 = OpenStackNetwork( + self.os_creds, self.net_config.network_settings) + proj_creator2.create() + self.assertEqual(self.proj_net_creator.get_network(), + proj_creator2.get_network()) + + def test_network_create_by_admin_to_different_project(self): + """ + Tests the creation of an OpenStackNetwork by the admin user and + initialize again with tenant credentials. + """ + # Create Network + + net_settings = self.net_config.network_settings + + net_settings.project_name = self.os_creds.project_name + + self.admin_net_creator = OpenStackNetwork( + self.admin_os_creds, net_settings) + self.admin_net_creator.create() + + self.proj_net_creator = OpenStackNetwork( + self.os_creds, self.net_config.network_settings) + self.proj_net_creator.create() + + self.assertEqual( + self.admin_net_creator.get_network().id, + self.proj_net_creator.get_network().id)