コード例 #1
0
ファイル: heat_utils_tests.py プロジェクト: opnfv/snaps
    def tearDown(self):
        """
        Cleans the stack and image
        """
        if self.stack1:
            try:
                heat_utils.delete_stack(self.heat_client, self.stack1)
            except:
                pass

        if self.stack2:
            try:
                heat_utils.delete_stack(self.heat_client, self.stack2)
            except:
                pass

        if self.image_creator:
            try:
                self.image_creator.clean()
            except:
                pass

        if self.flavor_creator:
            try:
                self.flavor_creator.clean()
            except:
                pass

        super(self.__class__, self).__clean__()
コード例 #2
0
ファイル: heat_utils_tests.py プロジェクト: opnfv/snaps
    def tearDown(self):
        """
        Cleans the stack
        """
        if self.stack:
            try:
                heat_utils.delete_stack(self.heat_client, self.stack)
            except:
                pass

        super(self.__class__, self).__clean__()
コード例 #3
0
ファイル: heat_utils_tests.py プロジェクト: opnfv/snaps
    def tearDown(self):
        """
        Cleans the image and downloaded image file
        """
        if self.stack:
            try:
                heat_utils.delete_stack(self.heat_client, self.stack)
            except:
                pass

        super(self.__class__, self).__clean__()
コード例 #4
0
    def clean(self):
        """
        Cleanse environment of all artifacts
        :return: void
        """
        if self.__stack:
            try:
                logger.info('Deleting stack - %s', self.__stack.name)
                heat_utils.delete_stack(self.__heat_cli, self.__stack)

                try:
                    self.stack_deleted(block=True)
                except StackError as e:
                    # Stack deletion seems to fail quite a bit
                    logger.warn('Stack did not delete properly - %s', e)

                    # Delete VMs first
                    for vm_inst_creator in self.get_vm_inst_creators():
                        try:
                            vm_inst_creator.clean()
                            if not vm_inst_creator.vm_deleted(block=True):
                                logger.warn('Unable to deleted VM - %s',
                                            vm_inst_creator.get_vm_inst().name)
                        except:
                            logger.warn('Unexpected error deleting VM - %s ',
                                        vm_inst_creator.get_vm_inst().name)

                logger.info('Attempting to delete again stack - %s',
                            self.__stack.name)

                # Delete Stack again
                heat_utils.delete_stack(self.__heat_cli, self.__stack)
                deleted = self.stack_deleted(block=True)
                if not deleted:
                    raise StackError('Stack could not be deleted ' +
                                     self.__stack.name)
            except HTTPNotFound:
                pass

            self.__stack = None

        self.__neutron.httpclient.session.session.close()
        self.__nova.client.session.session.close()
        self.__glance.http_client.session.session.close()
        self.__cinder.client.session.session.close()

        super(self.__class__, self).clean()
コード例 #5
0
ファイル: heat_utils_tests.py プロジェクト: opnfv/snaps
    def tearDown(self):
        """
        Cleans the stack and image
        """
        if self.stack:
            try:
                heat_utils.delete_stack(self.heat_client, self.stack)
                # Wait until stack deployment has completed
                end_time = (time.time() + stack_config.STACK_COMPLETE_TIMEOUT)
                is_deleted = False
                while time.time() < end_time:
                    status = heat_utils.get_stack_status(
                        self.heat_client, self.stack.id)
                    if status == stack_config.STATUS_DELETE_COMPLETE:
                        is_deleted = True
                        break
                    elif status == stack_config.STATUS_DELETE_FAILED:
                        is_deleted = False
                        break

                    time.sleep(3)

                if not is_deleted:
                    nova = nova_utils.nova_client(self.os_creds,
                                                  self.os_session)
                    keystone = keystone_utils.keystone_client(
                        self.os_creds, self.os_session)
                    neutron = neutron_utils.neutron_client(
                        self.os_creds, self.os_session)
                    glance = glance_utils.glance_client(
                        self.os_creds, self.os_session)

                    servers = heat_utils.get_stack_servers(
                        self.heat_client, nova, neutron, keystone, self.stack,
                        self.os_creds.project_name)
                    for server in servers:
                        vm_settings = settings_utils.create_vm_inst_config(
                            nova, keystone, neutron, server,
                            self.os_creds.project_name)
                        img_settings = settings_utils.determine_image_config(
                            glance, server, [
                                self.image_creator1.image_settings,
                                self.image_creator2.image_settings
                            ])
                        vm_creator = OpenStackVmInstance(
                            self.os_creds, vm_settings, img_settings)
                        vm_creator.initialize()
                        vm_creator.clean()
                        vm_creator.vm_deleted(block=True)

                    heat_utils.delete_stack(self.heat_client, self.stack)
                    time.sleep(20)
            except:
                raise

        if self.image_creator1:
            try:
                self.image_creator1.clean()
            except:
                pass

        if self.image_creator2:
            try:
                self.image_creator2.clean()
            except:
                pass

        if self.keypair1_settings:
            expanded_path = os.path.expanduser(
                self.keypair1_settings.private_filepath)
            os.chmod(expanded_path, 0o755)
            os.remove(expanded_path)

        if self.keypair2_settings:
            expanded_path = os.path.expanduser(
                self.keypair2_settings.private_filepath)
            os.chmod(expanded_path, 0o755)
            os.remove(expanded_path)

        super(self.__class__, self).__clean__()