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())
class CreateRouterSharedNetworksTests(OSIntegrationTestCase): """ Class for testing routers external and/or shared networks """ def setUp(self): """ Initializes objects used for router testing """ super(self.__class__, self).__start__() self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4()) self.router_creator = None ext_network_settings = NetworkConfig( name=self.guid + '-ext-net', external=True, subnet_settings=[ create_network.SubnetConfig(cidr=cidr1, name=self.guid + '-ext-subnet1') ]) self.ext_network_creator = OpenStackNetwork(self.admin_os_creds, ext_network_settings) self.ext_network_creator.create() shared_network_settings = NetworkConfig( name=self.guid + '-shared-net', shared=True, subnet_settings=[ create_network.SubnetConfig(cidr=cidr2, name=self.guid + '-shared-subnet1') ]) self.shared_network_creator = OpenStackNetwork( self.admin_os_creds, shared_network_settings) self.shared_network_creator.create() overlay_network_settings = NetworkConfig( name=self.guid + '-overlay-net', subnet_settings=[ create_network.SubnetConfig(cidr=cidr3, name=self.guid + '-overlay-subnet1') ]) self.overlay_network_creator = OpenStackNetwork( self.os_creds, overlay_network_settings) self.overlay_network_creator.create() self.neutron = neutron_utils.neutron_client(self.os_creds, self.os_session) def tearDown(self): """ Cleans the remote OpenStack objects used for router testing """ if self.router_creator: self.router_creator.clean() if self.overlay_network_creator: self.overlay_network_creator.clean() if self.shared_network_creator: self.shared_network_creator.clean() if self.ext_network_creator: self.ext_network_creator.clean() super(self.__class__, self).__clean__() def test_create_router_external(self): """ Test creation of a router with a custom external network created by admin. """ router_settings = RouterConfig( name=self.guid + '-pub-router', external_gateway=self.ext_network_creator.get_network().name) self.router_creator = create_router.OpenStackRouter( self.os_creds, router_settings) self.router_creator.create() def test_create_router_port_external(self): """ Test creation of a router with a port to an custom external network created by admin. """ router_settings = RouterConfig( name=self.guid + '-pub-router', network_name=self.ext_network_creator.get_network().name) self.router_creator = create_router.OpenStackRouter( self.os_creds, router_settings) self.router_creator.create() def test_create_router_port_shared(self): """ Test creation of a router with a port to an custom shared network created by admin. """ port_settings = [ create_network.PortConfig( name=self.guid + '-port1', network_name=self.shared_network_creator.get_network().name) ] router_settings = RouterConfig(name=self.guid + '-pub-router', port_settings=port_settings) self.router_creator = create_router.OpenStackRouter( self.os_creds, router_settings) self.router_creator.create()
class CreateNetworkIPv6Tests(OSIntegrationTestCase): """ Test for the CreateNetwork class defined in create_nework.py when """ 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.os_session) # 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_network_one_ipv6_subnet(self): """ Tests the creation of an OpenStack network without a router. """ # Create Network subnet_settings = SubnetConfig( name=self.guid + '-subnet', cidr='1:1:0:0:0:0:0:0/64', ip_version=6) network_settings = NetworkConfig( name=self.guid + '-net', subnet_settings=[subnet_settings]) self.net_creator = OpenStackNetwork(self.os_creds, network_settings) 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)) network = self.net_creator.get_network() self.assertEqual(1, len(network.subnets)) subnet = network.subnets[0] self.assertEqual(network.id, subnet.network_id) self.assertEqual(subnet_settings.name, subnet.name) self.assertEqual('1:1::/64', subnet.cidr) self.assertEqual(6, subnet.ip_version) self.assertEqual(0, len(subnet.dns_nameservers)) def test_create_network_ipv4_ipv6_subnet(self): """ Tests the creation of an OpenStack network without a router. """ # Create Network subnet4_settings = SubnetConfig( name=self.guid + '-subnet4', cidr='10.0.1.0/24', ip_version=4) subnet6_settings = SubnetConfig( name=self.guid + '-subnet6', cidr='1:1:0:0:0:0:0:0/64', ip_version=6) network_settings = NetworkConfig( name=self.guid + '-net', subnet_settings=[subnet4_settings, subnet6_settings]) self.net_creator = OpenStackNetwork(self.os_creds, network_settings) self.net_creator.create() # Validate network was created network = self.net_creator.get_network() self.assertEqual(2, len(network.subnets)) subnet4 = None subnet6 = None for subnet in network.subnets: if subnet.name == subnet4_settings.name: subnet4 = subnet if subnet.name == subnet6_settings.name: subnet6 = subnet # Validate IPv4 subnet self.assertEqual(network.id, subnet4.network_id) self.assertEqual(subnet4_settings.name, subnet4.name) self.assertEqual(subnet4_settings.cidr, subnet4.cidr) self.assertEqual(4, subnet4.ip_version) self.assertEqual(0, len(subnet4.dns_nameservers)) # Validate IPv6 subnet self.assertEqual(network.id, subnet6.network_id) self.assertEqual(subnet6_settings.name, subnet6.name) self.assertEqual('1:1::/64', subnet6.cidr) self.assertEqual(6, subnet6.ip_version) self.assertEqual(0, len(subnet6.dns_nameservers))
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( project_name=self.os_creds.project_name, net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet') self.neutron = neutron_utils.neutron_client( self.os_creds, self.os_session) # 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)
class CreateNetworkSuccessTests(OSIntegrationTestCase): """ Test for the CreateNetwork class defined in create_nework.py """ 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( project_name=self.os_creds.project_name, net_name="{}-{}".format(guid, 'pub-net'), mtu=999, subnet_name="{}-{}".format(guid, 'pub-subnet'), router_name="{}-{}".format(guid, 'pub-router'), external_net=self.ext_net_name, netconf_override=self.netconf_override) self.neutron = neutron_utils.neutron_client( self.os_creds, self.os_session) # Initialize for cleanup self.net_creator = None self.router_creator = None def tearDown(self): """ Cleans the network """ if self.router_creator: self.router_creator.clean() if self.net_creator: self.net_creator.clean() super(self.__class__, self).__clean__() def test_create_network_without_router(self): """ Tests the creation of an OpenStack network without a router. """ # Create Network self.net_creator = OpenStackNetwork( self.os_creds, self.net_config.network_settings) network = 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, mtu=999)) # Validate subnets self.assertTrue(neutron_utils_tests.validate_subnet( self.neutron, network, self.net_creator.network_settings.subnet_settings[0].name, self.net_creator.network_settings.subnet_settings[0].cidr, True)) def test_create_delete_network(self): """ 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.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, mtu=999)) neutron_utils.delete_network( self.neutron, self.net_creator.get_network()) self.assertIsNone(neutron_utils.get_network( 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() def test_create_network_with_router(self): """ Tests the creation of an OpenStack network with a router. """ # Create Network self.net_creator = OpenStackNetwork( self.os_creds, self.net_config.network_settings) network = self.net_creator.create() # Create Router self.router_creator = create_router.OpenStackRouter( self.os_creds, self.net_config.router_settings) self.router_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, mtu=999)) # Validate subnets self.assertTrue(neutron_utils_tests.validate_subnet( self.neutron, network, self.net_creator.network_settings.subnet_settings[0].name, self.net_creator.network_settings.subnet_settings[0].cidr, True)) # Validate routers neutron_utils_tests.validate_router( self.neutron, self.keystone, self.router_creator.router_settings.name, self.os_creds.project_name, True) neutron_utils_tests.validate_interface_router( self.router_creator.get_internal_router_interface(), self.router_creator.get_router(), self.net_creator.get_network().subnets[0]) def test_create_networks_same_name(self): """ Tests the creation of an OpenStack network and ensures that the OpenStackNetwork object will not create a second. """ # Create Network 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.create() self.assertEqual(self.net_creator.get_network().id, self.net_creator2.get_network().id) def test_create_network_router_admin_user_to_new_project(self): """ 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 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, 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 = project_name self.router_creator = create_router.OpenStackRouter( self.admin_os_creds, self.net_config.router_settings) self.router_creator.create() retrieved_router = neutron_utils.get_router( self.neutron, self.keystone, router_settings=self.router_creator.router_settings, project_name=self.os_creds.project_name) self.assertEqual( self.router_creator.get_router().id, retrieved_router.id) def test_create_network_router_new_user_to_admin_project(self): """ Tests the creation of an OpenStack network and router with the admin user to the new project. """ # Create Network/Subnet where the project names have been changed new_project_name = self.os_creds.project_name 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.create() retrieved_net = neutron_utils.get_network( 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) # Create Router self.net_config.router_settings.project_name = new_project_name self.router_creator = create_router.OpenStackRouter( self.admin_os_creds, self.net_config.router_settings) self.router_creator.create() retrieved_router = neutron_utils.get_router( self.neutron, self.keystone, router_settings=self.router_creator.router_settings, project_name=self.os_creds.project_name) self.assertEqual( self.router_creator.get_router().id, retrieved_router.id)