Esempio n. 1
0
    def create(self, block=False):
        """
        Creates the heat stack in OpenStack if it does not already exist and
        returns the domain Stack object
        :return: The Stack domain object or None
        """
        self.initialize()

        if self.__stack:
            logger.info('Found stack with name - %s', self.stack_settings.name)
            return self.__stack
        else:
            self.__stack = heat_utils.create_stack(self.__heat_cli,
                                                   self.stack_settings)
            logger.info('Created stack with name - %s',
                        self.stack_settings.name)
            if self.__stack and self.stack_complete(block=block):
                logger.info('Stack is now active with name - %s',
                            self.stack_settings.name)
                return self.__stack
            else:
                status = heat_utils.get_stack_status_reason(
                    self.__heat_cli, self.__stack.id)
                logger.error('ERROR: STACK CREATION FAILED: %s', status)
                raise StackCreationError('Failure while creating stack')
Esempio n. 2
0
    def test_create_keypair_with_stack(self):
        """
        Tests the creation of an OpenStack keypair with Heat.
        """
        self.stack = heat_utils.create_stack(self.heat_client,
                                             self.stack_settings)
        self.assertTrue(stack_active(self.heat_client, self.stack))

        keypairs = heat_utils.get_stack_keypairs(self.heat_client, self.nova,
                                                 self.stack)

        self.assertEqual(1, len(keypairs))
        keypair = keypairs[0]

        self.assertEqual(self.keypair_name, keypair.name)

        outputs = heat_utils.get_outputs(self.heat_client, self.stack)

        for output in outputs:
            if output.key == 'private_key':
                self.assertTrue(
                    output.value.startswith('-----BEGIN RSA PRIVATE KEY-----'))

        keypair = nova_utils.get_keypair_by_id(self.nova, keypair.id)
        self.assertIsNotNone(keypair)

        self.assertEqual(self.keypair_name, keypair.name)
Esempio n. 3
0
    def setUp(self):
        """
        Instantiates OpenStack instances that cannot be spawned by Heat
        """
        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
        stack_name = guid + '-stack'
        self.network_name = guid + '-net'
        self.subnet_name = guid + '-subnet'
        self.vm_inst1_name = guid + '-inst1'
        self.vm_inst2_name = guid + '-inst2'
        self.flavor1_name = guid + '-flavor1'
        self.flavor2_name = guid + '-flavor2'
        self.keypair_name = guid + '-keypair'

        self.image_creator1 = OpenStackImage(
            self.os_creds,
            openstack_tests.cirros_image_settings(
                name=guid + '-image1', image_metadata=self.image_metadata))
        self.image_creator1.create()

        self.image_creator2 = OpenStackImage(
            self.os_creds,
            openstack_tests.cirros_image_settings(
                name=guid + '-image2', image_metadata=self.image_metadata))
        self.image_creator2.create()

        env_values = {
            'image1_name': self.image_creator1.image_settings.name,
            'image2_name': self.image_creator2.image_settings.name,
            'flavor1_name': self.flavor1_name,
            'flavor2_name': self.flavor2_name,
            'net_name': self.network_name,
            'subnet_name': self.subnet_name,
            'keypair_name': self.keypair_name,
            'inst1_name': self.vm_inst1_name,
            'inst2_name': self.vm_inst2_name,
            'external_net_name': self.ext_net_name
        }
        heat_tmplt_path = pkg_resources.resource_filename(
            'snaps.openstack.tests.heat', 'floating_ip_heat_template.yaml')
        stack_settings = StackConfig(name=stack_name,
                                     template_path=heat_tmplt_path,
                                     env_values=env_values)
        self.heat_client = heat_utils.heat_client(self.os_creds,
                                                  self.os_session)
        self.stack = heat_utils.create_stack(self.heat_client, stack_settings)

        self.assertTrue(stack_active(self.heat_client, self.stack))

        self.keypair1_settings = None
        self.keypair2_settings = None
Esempio n. 4
0
    def test_create_stack_x2(self):
        """
        Tests the creation of an OpenStack keypair that does not exist.
        """
        self.stack1 = heat_utils.create_stack(self.heat_client,
                                              self.stack_settings1)

        stack1_query_1 = heat_utils.get_stack(
            self.heat_client, stack_settings=self.stack_settings1)
        self.assertEqual(self.stack1, stack1_query_1)

        stack1_query_2 = heat_utils.get_stack(
            self.heat_client, stack_name=self.stack_settings1.name)
        self.assertEqual(self.stack1, stack1_query_2)

        stack1_query_3 = heat_utils.get_stack_by_id(self.heat_client,
                                                    self.stack1.id)
        self.assertEqual(self.stack1, stack1_query_3)

        self.assertTrue(stack_active(self.heat_client, self.stack1))

        self.stack2 = heat_utils.create_stack(self.heat_client,
                                              self.stack_settings2)

        stack2_query_1 = heat_utils.get_stack(
            self.heat_client, stack_settings=self.stack_settings2)
        self.assertEqual(self.stack2, stack2_query_1)

        stack2_query_2 = heat_utils.get_stack(
            self.heat_client, stack_name=self.stack_settings2.name)
        self.assertEqual(self.stack2, stack2_query_2)

        stack2_query_3 = heat_utils.get_stack_by_id(self.heat_client,
                                                    self.stack2.id)
        self.assertEqual(self.stack2, stack2_query_3)

        self.assertTrue(stack_active(self.heat_client, self.stack2))
Esempio n. 5
0
    def test_create_stack(self):
        """
        Tests the creation of an OpenStack Heat stack1 that does not exist.
        """
        self.stack1 = heat_utils.create_stack(self.heat_client,
                                              self.stack_settings1)

        stack_query_1 = heat_utils.get_stack(
            self.heat_client, stack_settings=self.stack_settings1)
        self.assertEqual(self.stack1, stack_query_1)

        stack_query_2 = heat_utils.get_stack(
            self.heat_client, stack_name=self.stack_settings1.name)
        self.assertEqual(self.stack1, stack_query_2)

        stack_query_3 = heat_utils.get_stack_by_id(self.heat_client,
                                                   self.stack1.id)
        self.assertEqual(self.stack1, stack_query_3)

        resources = heat_utils.get_resources(self.heat_client, self.stack1.id)
        self.assertIsNotNone(resources)
        self.assertEqual(4, len(resources))

        outputs = heat_utils.get_outputs(self.heat_client, self.stack1)
        self.assertIsNotNone(outputs)
        self.assertEqual(0, len(outputs))

        self.assertTrue(stack_active(self.heat_client, self.stack1))

        neutron = neutron_utils.neutron_client(self.os_creds, self.os_session)
        networks = heat_utils.get_stack_networks(self.heat_client, neutron,
                                                 self.stack1)
        self.assertIsNotNone(networks)
        self.assertEqual(1, len(networks))
        self.assertEqual(self.network_name, networks[0].name)

        subnets = neutron_utils.get_subnets_by_network(neutron, networks[0])
        self.assertEqual(1, len(subnets))
        self.assertEqual(self.subnet_name, subnets[0].name)

        nova = nova_utils.nova_client(self.os_creds, self.os_session)
        keystone = keystone_utils.keystone_client(self.os_creds,
                                                  self.os_session)
        servers = heat_utils.get_stack_servers(self.heat_client, nova, neutron,
                                               keystone, self.stack1,
                                               self.os_creds.project_name)
        self.assertIsNotNone(servers)
        self.assertEqual(1, len(servers))
        self.assertEqual(self.vm_inst_name, servers[0].name)
Esempio n. 6
0
    def test_create_vol_types_with_stack(self):
        """
        Tests the creation of an OpenStack volume with Heat.
        """
        self.stack = heat_utils.create_stack(self.heat_client,
                                             self.stack_settings)
        self.assertTrue(stack_active(self.heat_client, self.stack))

        volume_types = heat_utils.get_stack_volume_types(
            self.heat_client, self.cinder, self.stack)

        self.assertEqual(1, len(volume_types))

        volume_type = volume_types[0]

        self.assertEqual(self.volume_type_name, volume_type.name)
        self.assertTrue(volume_type.public)
        self.assertIsNone(volume_type.qos_spec)
Esempio n. 7
0
    def test_create_vol_with_stack(self):
        """
        Tests the creation of an OpenStack volume with Heat.
        """
        self.stack = heat_utils.create_stack(self.heat_client,
                                             self.stack_settings)
        self.assertTrue(stack_active(self.heat_client, self.stack))

        volumes = heat_utils.get_stack_volumes(self.heat_client, self.cinder,
                                               self.stack)

        self.assertEqual(1, len(volumes))

        volume = volumes[0]
        self.assertEqual(self.volume_name, volume.name)
        self.assertEqual(self.volume_type_name, volume.type)
        self.assertEqual(1, volume.size)
        self.assertEqual(False, volume.multi_attach)
Esempio n. 8
0
    def test_create_router_with_stack(self):
        """
        Tests the creation of an OpenStack router with Heat and the retrieval
        of the Router Domain objects from heat_utils#get_stack_routers().
        """
        self.stack = heat_utils.create_stack(self.heat_client,
                                             self.stack_settings)

        # Wait until stack deployment has completed
        end_time = time.time() + stack_config.STACK_COMPLETE_TIMEOUT
        is_active = False
        while time.time() < end_time:
            status = heat_utils.get_stack_status(self.heat_client,
                                                 self.stack.id)
            if status == stack_config.STATUS_CREATE_COMPLETE:
                is_active = True
                break
            elif status == stack_config.STATUS_CREATE_FAILED:
                is_active = False
                break

            time.sleep(3)

        self.assertTrue(is_active)

        routers = heat_utils.get_stack_routers(self.heat_client, self.neutron,
                                               self.stack)

        self.assertEqual(1, len(routers))

        router = routers[0]
        self.assertEqual(self.router_name, router.name)

        keystone = keystone_utils.keystone_client(self.os_creds,
                                                  self.os_session)
        ext_net = neutron_utils.get_network(self.neutron,
                                            keystone,
                                            network_name=self.ext_net_name)
        self.assertEqual(ext_net.id, router.external_network_id)
Esempio n. 9
0
    def test_create_flavor_with_stack(self):
        """
        Tests the creation of an OpenStack volume with Heat.
        """
        self.stack = heat_utils.create_stack(self.heat_client,
                                             self.stack_settings)

        self.assertTrue(stack_active(self.heat_client, self.stack))

        flavors = heat_utils.get_stack_flavors(self.heat_client, self.nova,
                                               self.stack)

        self.assertEqual(1, len(flavors))

        flavor = flavors[0]
        self.assertTrue(flavor.name.startswith(self.name_prefix))
        self.assertEqual(1024, flavor.ram)
        self.assertEqual(200, flavor.disk)
        self.assertEqual(8, flavor.vcpus)
        self.assertEqual(0, flavor.ephemeral)
        self.assertIsNone(flavor.swap)
        self.assertEqual(1.0, flavor.rxtx_factor)
        self.assertTrue(flavor.is_public)
Esempio n. 10
0
    def test_create_security_group_with_stack(self):
        """
        Tests the creation of an OpenStack SecurityGroup with Heat.
        """
        self.stack = heat_utils.create_stack(self.heat_client,
                                             self.stack_settings)
        self.assertTrue(stack_active(self.heat_client, self.stack))

        sec_grp = heat_utils.get_stack_security_groups(self.heat_client,
                                                       self.neutron,
                                                       self.stack)[0]

        self.assertEqual(self.sec_grp_name, sec_grp.name)
        self.assertEqual('Test description', sec_grp.description)
        self.assertEqual(2, len(sec_grp.rules))

        has_ssh_rule = False
        has_icmp_rule = False

        for rule in sec_grp.rules:
            if (rule.security_group_id == sec_grp.id
                    and rule.direction == 'egress' and rule.ethertype == 'IPv4'
                    and rule.port_range_min == 22 and rule.port_range_max == 22
                    and rule.protocol == 'tcp' and rule.remote_group_id is None
                    and rule.remote_ip_prefix == '0.0.0.0/0'):
                has_ssh_rule = True
            if (rule.security_group_id == sec_grp.id
                    and rule.direction == 'ingress'
                    and rule.ethertype == 'IPv4'
                    and rule.port_range_min is None
                    and rule.port_range_max is None and rule.protocol == 'icmp'
                    and rule.remote_group_id is None
                    and rule.remote_ip_prefix == '0.0.0.0/0'):
                has_icmp_rule = True

        self.assertTrue(has_ssh_rule)
        self.assertTrue(has_icmp_rule)