Beispiel #1
0
    def test_create_delete_router(self):
        """
        Test that clean() will not raise an exception if the router is deleted
        by another process.
        """
        self.router_settings = RouterConfig(name=self.guid + '-pub-router',
                                            external_gateway=self.ext_net_name)

        self.router_creator = create_router.OpenStackRouter(
            self.os_creds, self.router_settings)
        created_router = self.router_creator.create()
        self.assertIsNotNone(created_router)
        retrieved_router = neutron_utils.get_router(
            self.neutron,
            self.keystone,
            router_settings=self.router_settings,
            project_name=self.os_creds.project_name)
        self.assertIsNotNone(retrieved_router)

        neutron_utils.delete_router(self.neutron, created_router)

        retrieved_router = neutron_utils.get_router(
            self.neutron,
            self.keystone,
            router_settings=self.router_settings,
            project_name=self.os_creds.project_name)
        self.assertIsNone(retrieved_router)

        # Should not raise an exception
        self.router_creator.clean()
Beispiel #2
0
    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)
Beispiel #3
0
    def test_create_router_with_ext_port(self):
        """
        Test creation of a router with a port to an external network as an
        'admin' user.
        """
        port_settings = [
            create_network.PortConfig(name=self.guid + '-port1',
                                      network_name=self.ext_net_name)
        ]

        router_settings = RouterConfig(name=self.guid + '-pub-router',
                                       port_settings=port_settings)
        self.router_creator = create_router.OpenStackRouter(
            self.admin_os_creds, router_settings)
        self.router_creator.create()

        admin_neutron = neutron_utils.neutron_client(self.admin_os_creds,
                                                     self.admin_os_session)
        admin_keystone = keystone_utils.keystone_client(
            self.admin_os_creds, self.admin_os_session)
        router = neutron_utils.get_router(
            admin_neutron,
            admin_keystone,
            router_settings=router_settings,
            project_name=self.admin_os_creds.project_name)

        self.assertIsNotNone(router)
        self.assertEquals(router, self.router_creator.get_router())

        ext_net = neutron_utils.get_network(admin_neutron,
                                            admin_keystone,
                                            network_name=self.ext_net_name)

        self.assertIsNotNone(ext_net)
        self.assertIsNotNone(router.port_subnets)

        id_found = False
        for port, subnets in router.port_subnets:
            self.assertIsNotNone(subnets)
            self.assertIsNotNone(port)

            if ext_net.id == port.network_id:
                id_found = True
                for subnet in subnets:
                    self.assertIsNotNone(subnet)
                    self.assertEqual(ext_net.id, subnet.network_id)
        self.assertTrue(id_found)
Beispiel #4
0
 def __ext_gateway_by_router(self, router_name):
     """
     Returns network name for the external network attached to a router or
     None if not found
     :param router_name: The name of the router to lookup
     :return: the external network name or None
     """
     router = neutron_utils.get_router(
         self.__neutron,
         self.__keystone,
         router_name=router_name,
         project_name=self._os_creds.project_name)
     if router and router.external_network_id:
         network = neutron_utils.get_network_by_id(
             self.__neutron, router.external_network_id)
         if network:
             return network.name
     return None
Beispiel #5
0
    def test_create_router_external_network(self):
        """
        Test creation of a router connected to an external network and a
        private network.
        """
        network_settings = NetworkConfig(
            name=self.guid + '-pub-net1',
            subnet_settings=[
                create_network.SubnetConfig(cidr=cidr1,
                                            name=self.guid + '-pub-subnet1',
                                            gateway_ip=static_gateway_ip1)
            ])
        self.network_creator1 = OpenStackNetwork(self.os_creds,
                                                 network_settings)
        self.network_creator1.create()

        port_settings = [
            create_network.PortConfig(
                name=self.guid + '-port1',
                ip_addrs=[{
                    'subnet_name': network_settings.subnet_settings[0].name,
                    'ip': static_gateway_ip1
                }],
                network_name=network_settings.name)
        ]

        router_settings = RouterConfig(name=self.guid + '-pub-router',
                                       external_gateway=self.ext_net_name,
                                       port_settings=port_settings)
        self.router_creator = create_router.OpenStackRouter(
            self.os_creds, router_settings)
        self.router_creator.create()

        router = neutron_utils.get_router(
            self.neutron,
            self.keystone,
            router_settings=router_settings,
            project_name=self.os_creds.project_name)

        self.assertEquals(router, self.router_creator.get_router())

        self.check_router_recreation(router, router_settings)
Beispiel #6
0
    def test_create_router_admin_state_True(self):
        """
        Test creation of a basic router with admin state Up.
        """
        router_settings = RouterConfig(name=self.guid + '-pub-router',
                                       admin_state_up=True)

        self.router_creator = create_router.OpenStackRouter(
            self.os_creds, router_settings)
        self.router_creator.create()

        router = neutron_utils.get_router(
            self.neutron,
            self.keystone,
            router_settings=router_settings,
            project_name=self.os_creds.project_name)
        self.assertIsNotNone(router)

        self.assertEqual(self.router_creator.get_router(), router)

        self.check_router_recreation(router, router_settings)
Beispiel #7
0
    def test_create_router_vanilla(self):
        """
        Test creation of a most basic router with minimal options.
        """
        router_settings = RouterConfig(name=self.guid + '-pub-router',
                                       external_gateway=self.ext_net_name)

        self.router_creator = create_router.OpenStackRouter(
            self.os_creds, router_settings)
        self.router_creator.create()

        router = neutron_utils.get_router(
            self.neutron,
            self.keystone,
            router_settings=router_settings,
            project_name=self.os_creds.project_name)
        self.assertIsNotNone(router)

        self.assertEqual(self.router_creator.get_router(), router)

        self.check_router_recreation(router, router_settings)
Beispiel #8
0
    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)
Beispiel #9
0
    def test_create_router_new_user_as_admin_project(self):
        """
        Test creation of a most basic router with the new user pointing
        to the admin project.
        """
        router_settings = RouterConfig(name=self.guid + '-pub-router',
                                       external_gateway=self.ext_net_name,
                                       project_name=self.os_creds.project_name)

        self.router_creator = create_router.OpenStackRouter(
            self.admin_os_creds, router_settings)
        self.router_creator.create()

        router = neutron_utils.get_router(
            self.neutron,
            self.keystone,
            router_settings=router_settings,
            project_name=self.os_creds.project_name)
        self.assertIsNotNone(router)

        self.assertEqual(self.router_creator.get_router().id, router.id)

        self.check_router_recreation(router, router_settings)
Beispiel #10
0
    def initialize(self):
        """
        Loads the existing router.
        :return: the Router domain object
        """
        super(self.__class__, self).initialize()

        try:
            self.__router = neutron_utils.get_router(
                self._neutron,
                self._keystone,
                router_settings=self.router_settings,
                project_name=self._os_creds.project_name)
        except Unauthorized as e:
            logger.warn('Unable to lookup router with name %s - %s',
                        self.router_settings.name, e)

        if self.__router:
            for sub_config in self.router_settings.internal_subnets:
                internal_subnet = self.__get_internal_subnet(sub_config)
                if internal_subnet:
                    self.__internal_subnets.append(internal_subnet)
                else:
                    raise RouterCreationError('Subnet not found with name ' +
                                              internal_subnet.name)

            for port_setting in self.router_settings.port_settings:
                port = neutron_utils.get_port(
                    self._neutron,
                    self._keystone,
                    port_settings=port_setting,
                    project_name=self._os_creds.project_name)
                if port:
                    self.__ports.append(port)

        return self.__router
Beispiel #11
0
    def test_create_router_private_network(self):
        """
        Test creation of a router connected with two private networks and no
        external gateway
        """
        network_settings1 = NetworkConfig(
            name=self.guid + '-pub-net1',
            subnet_settings=[
                create_network.SubnetConfig(cidr=cidr1,
                                            name=self.guid + '-pub-subnet1',
                                            gateway_ip=static_gateway_ip1)
            ])
        network_settings2 = NetworkConfig(
            name=self.guid + '-pub-net2',
            subnet_settings=[
                create_network.SubnetConfig(cidr=cidr2,
                                            name=self.guid + '-pub-subnet2',
                                            gateway_ip=static_gateway_ip2)
            ])

        self.network_creator1 = OpenStackNetwork(self.os_creds,
                                                 network_settings1)
        self.network_creator2 = OpenStackNetwork(self.os_creds,
                                                 network_settings2)

        self.network_creator1.create()
        self.network_creator2.create()

        port_settings = [
            create_network.PortConfig(
                name=self.guid + '-port1',
                ip_addrs=[{
                    'subnet_name': network_settings1.subnet_settings[0].name,
                    'ip': static_gateway_ip1
                }],
                network_name=network_settings1.name),
            create_network.PortConfig(
                name=self.guid + '-port2',
                ip_addrs=[{
                    'subnet_name': network_settings2.subnet_settings[0].name,
                    'ip': static_gateway_ip2
                }],
                network_name=network_settings2.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()

        router = neutron_utils.get_router(
            self.neutron,
            self.keystone,
            router_settings=router_settings,
            project_name=self.os_creds.project_name)

        self.assertEqual(router, self.router_creator.get_router())

        # Instantiate second identical creator to ensure a second router
        # has not been created
        router_creator2 = create_router.OpenStackRouter(
            self.os_creds, router_settings)
        router2 = router_creator2.create()
        self.assertIsNotNone(self.router_creator.get_router(), router2)

        self.check_router_recreation(router2, router_settings)