Exemple #1
0
 def test_instance_info_cache_delete(self):
     self.mox.StubOutWithMock(db, "instance_info_cache_delete")
     db.instance_info_cache_delete(self.context, "fake-uuid")
     self.mox.ReplayAll()
     self.conductor.instance_info_cache_delete(self.context, {"uuid": "fake-uuid"})
 def delete(self, context):
     db.instance_info_cache_delete(context, self.instance_uuid)
 def delete(self):
     db.instance_info_cache_delete(self._context, self.instance_uuid)
Exemple #4
0
 def test_instance_info_cache_delete(self):
     self.mox.StubOutWithMock(db, 'instance_info_cache_delete')
     db.instance_info_cache_delete(self.context, 'fake-uuid')
     self.mox.ReplayAll()
     self.conductor.instance_info_cache_delete(self.context,
                                               {'uuid': 'fake-uuid'})
Exemple #5
0
 def test_instance_info_cache_delete(self):
     self.mox.StubOutWithMock(db, 'instance_info_cache_delete')
     db.instance_info_cache_delete(self.context, 'fake-uuid')
     self.mox.ReplayAll()
     self.conductor.instance_info_cache_delete(self.context,
                                               {'uuid': 'fake-uuid'})
Exemple #6
0
    def _test_delete(self, delete_type, **attrs):
        inst = self._create_instance_obj()
        inst.update(attrs)
        inst._context = self.context
        delete_time = datetime.datetime(1955, 11, 5, 9, 30,
                                        tzinfo=iso8601.iso8601.Utc())
        timeutils.set_time_override(delete_time)
        task_state = (delete_type == 'soft_delete' and
                      task_states.SOFT_DELETING or task_states.DELETING)
        db_inst = obj_base.obj_to_primitive(inst)
        updates = {'progress': 0, 'task_state': task_state}
        if delete_type == 'soft_delete':
            updates['deleted_at'] = delete_time
        self.mox.StubOutWithMock(inst, 'save')
        self.mox.StubOutWithMock(db,
                                 'block_device_mapping_get_all_by_instance')
        self.mox.StubOutWithMock(self.compute_api, '_create_reservations')
        self.mox.StubOutWithMock(self.context, 'elevated')
        self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
        self.mox.StubOutWithMock(self.compute_api.servicegroup_api,
                                 'service_is_up')
        self.mox.StubOutWithMock(db, 'migration_get_by_instance_and_status')
        self.mox.StubOutWithMock(self.compute_api, '_downsize_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(db, 'instance_info_cache_delete')
        self.mox.StubOutWithMock(self.compute_api.network_api,
                                 'deallocate_for_instance')
        self.mox.StubOutWithMock(db, 'instance_system_metadata_get')
        self.mox.StubOutWithMock(db, 'instance_destroy')
        self.mox.StubOutWithMock(compute_utils,
                                 'notify_about_instance_usage')
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')

        db.block_device_mapping_get_all_by_instance(
            self.context, inst.uuid).AndReturn([])
        inst.save()
        self.compute_api._create_reservations(
            self.context, inst, inst.instance_type_id, inst.project_id,
            inst.user_id).AndReturn('fake-resv')

        if inst.vm_state == vm_states.RESIZED:
            self._test_delete_resized_part(inst)

        self.context.elevated().MultipleTimes().AndReturn(self.context)
        db.service_get_by_compute_host(self.context, inst.host).AndReturn(
            'fake-service')
        self.compute_api.servicegroup_api.service_is_up(
            'fake-service').AndReturn(inst.host != 'down-host')

        if self.is_cells:
            rpcapi = self.compute_api.cells_rpcapi
        else:
            rpcapi = self.compute_api.compute_rpcapi

        self.mox.StubOutWithMock(rpcapi, 'terminate_instance')
        self.mox.StubOutWithMock(rpcapi, 'soft_delete_instance')

        if inst.host == 'down-host':
            db.instance_info_cache_delete(self.context, inst.uuid)
            compute_utils.notify_about_instance_usage(self.context,
                                                      inst,
                                                      '%s.start' % delete_type)
            self.compute_api.network_api.deallocate_for_instance(
                self.context, inst)
            db.instance_system_metadata_get(self.context, inst.uuid
                                            ).AndReturn('sys-meta')
            state = ('soft' in delete_type and vm_states.SOFT_DELETED or
                     vm_states.DELETED)
            updates.update({'vm_state': state,
                            'task_state': None,
                            'terminated_at': delete_time})
            inst.save()
            if self.is_cells:
                if delete_type == 'soft_delete':
                    rpcapi.soft_delete_instance(self.context, inst,
                                                reservations=None)
                else:
                    rpcapi.terminate_instance(self.context, inst, [],
                                              reservations=None)
            db.instance_destroy(self.context, inst.uuid)
            compute_utils.notify_about_instance_usage(
                self.context, inst, '%s.end' % delete_type,
                system_metadata='sys-meta')

        if inst.host == 'down-host':
            quota.QUOTAS.commit(self.context, 'fake-resv',
                                project_id=inst.project_id,
                                user_id=inst.user_id)
        elif delete_type == 'soft_delete':
            self.compute_api._record_action_start(self.context, inst,
                                                  instance_actions.DELETE)
            rpcapi.soft_delete_instance(self.context, inst,
                                        reservations='fake-resv')
        elif delete_type in ['delete', 'force_delete']:
            self.compute_api._record_action_start(self.context, inst,
                                                  instance_actions.DELETE)
            rpcapi.terminate_instance(self.context, inst, [],
                                      reservations='fake-resv')

        self.mox.ReplayAll()

        getattr(self.compute_api, delete_type)(self.context, inst)
        for k, v in updates.items():
            self.assertEqual(inst[k], v)
Exemple #7
0
    def _test_delete(self, delete_type, **attrs):
        inst = self._create_instance_obj()
        inst.update(attrs)
        delete_time = datetime.datetime(1955, 11, 5, 9, 30)
        timeutils.set_time_override(delete_time)
        task_state = (delete_type == 'soft_delete' and
                      task_states.SOFT_DELETING or task_states.DELETING)
        db_inst = obj_base.obj_to_primitive(inst)
        updates = {'progress': 0, 'task_state': task_state}
        if delete_type == 'soft_delete':
            updates['deleted_at'] = delete_time
        new_inst = dict(db_inst, **updates)
        self.mox.StubOutWithMock(db,
                                 'block_device_mapping_get_all_by_instance')
        self.mox.StubOutWithMock(self.compute_api, '_create_reservations')
        self.mox.StubOutWithMock(self.context, 'elevated')
        self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
        self.mox.StubOutWithMock(self.compute_api.servicegroup_api,
                                 'service_is_up')
        self.mox.StubOutWithMock(db, 'migration_get_by_instance_and_status')
        self.mox.StubOutWithMock(self.compute_api, '_downsize_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(db, 'instance_info_cache_delete')
        self.mox.StubOutWithMock(self.compute_api.network_api,
                                 'deallocate_for_instance')
        self.mox.StubOutWithMock(db, 'instance_system_metadata_get')
        self.mox.StubOutWithMock(db, 'instance_destroy')
        self.mox.StubOutWithMock(compute_utils,
                                 'notify_about_instance_usage')
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
        self.mox.StubOutWithMock(self.compute_api.compute_rpcapi,
                                 'terminate_instance')
        self.mox.StubOutWithMock(self.compute_api.compute_rpcapi,
                                 'soft_delete_instance')

        db.block_device_mapping_get_all_by_instance(
            self.context, inst.uuid).AndReturn([])
        db.instance_update_and_get_original(
            self.context, inst.uuid, updates).AndReturn((db_inst, new_inst))
        self.compute_api._create_reservations(
            self.context, db_inst, new_inst, inst.project_id, inst.user_id
            ).AndReturn('fake-resv')

        if inst.vm_state == vm_states.RESIZED:
            self._test_delete_resized_part(db_inst)

        self.context.elevated().MultipleTimes().AndReturn(self.context)
        db.service_get_by_compute_host(self.context, inst.host).AndReturn(
            'fake-service')
        self.compute_api.servicegroup_api.service_is_up(
            'fake-service').AndReturn(inst.host != 'down-host')

        if inst.host == 'down-host' and (
                not self.is_cells or not inst.cell_name):
            db.instance_info_cache_delete(self.context, inst.uuid)
            compute_utils.notify_about_instance_usage(self.context,
                                                      db_inst, 'delete.start')
            self.compute_api.network_api.deallocate_for_instance(
                self.context, db_inst)
            db.instance_system_metadata_get(self.context, inst.uuid
                                            ).AndReturn('sys-meta')
            updates = {'vm_state': vm_states.DELETED,
                       'task_state': None,
                       'terminated_at': delete_time}
            del_inst = dict(new_inst, **updates)
            db.instance_update_and_get_original(
                self.context, inst.uuid, updates
                ).AndReturn((db_inst, del_inst))
            db.instance_destroy(self.context, inst.uuid)
            compute_utils.notify_about_instance_usage(
                self.context, del_inst, 'delete.end',
                system_metadata='sys-meta')
        if inst.host == 'down-host':
            quota.QUOTAS.commit(self.context, 'fake-resv',
                                project_id=inst.project_id,
                                user_id=inst.user_id)
        elif delete_type == 'soft_delete':
            self.compute_api._record_action_start(self.context, db_inst,
                                                  instance_actions.DELETE)
            self.compute_api.compute_rpcapi.soft_delete_instance(
                self.context, db_inst, reservations='fake-resv')
        elif delete_type in ['delete', 'force_delete']:
            self.compute_api._record_action_start(self.context, db_inst,
                                                  instance_actions.DELETE)
            self.compute_api.compute_rpcapi.terminate_instance(
                self.context, db_inst, [], reservations='fake-resv')

        if self.is_cells:
            self.mox.StubOutWithMock(self.compute_api, '_cast_to_cells')
            self.compute_api._cast_to_cells(
                self.context, db_inst, delete_type)

        self.mox.ReplayAll()

        getattr(self.compute_api, delete_type)(self.context, db_inst)
Exemple #8
0
    def _test_delete(self, delete_type, **attrs):
        inst = self._create_instance_obj()
        inst.update(attrs)
        inst._context = self.context
        delete_time = datetime.datetime(1955,
                                        11,
                                        5,
                                        9,
                                        30,
                                        tzinfo=iso8601.iso8601.Utc())
        timeutils.set_time_override(delete_time)
        task_state = (delete_type == 'soft_delete'
                      and task_states.SOFT_DELETING or task_states.DELETING)
        db_inst = obj_base.obj_to_primitive(inst)
        updates = {'progress': 0, 'task_state': task_state}
        if delete_type == 'soft_delete':
            updates['deleted_at'] = delete_time
        self.mox.StubOutWithMock(inst, 'save')
        self.mox.StubOutWithMock(db,
                                 'block_device_mapping_get_all_by_instance')
        self.mox.StubOutWithMock(self.compute_api, '_create_reservations')
        self.mox.StubOutWithMock(self.context, 'elevated')
        self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
        self.mox.StubOutWithMock(self.compute_api.servicegroup_api,
                                 'service_is_up')
        self.mox.StubOutWithMock(db, 'migration_get_by_instance_and_status')
        self.mox.StubOutWithMock(self.compute_api, '_downsize_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(db, 'instance_info_cache_delete')
        self.mox.StubOutWithMock(self.compute_api.network_api,
                                 'deallocate_for_instance')
        self.mox.StubOutWithMock(db, 'instance_system_metadata_get')
        self.mox.StubOutWithMock(db, 'instance_destroy')
        self.mox.StubOutWithMock(compute_utils, 'notify_about_instance_usage')
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')

        db.block_device_mapping_get_all_by_instance(self.context,
                                                    inst.uuid).AndReturn([])
        inst.save()
        self.compute_api._create_reservations(
            self.context, inst, inst.instance_type_id, inst.project_id,
            inst.user_id).AndReturn('fake-resv')

        if inst.vm_state == vm_states.RESIZED:
            self._test_delete_resized_part(inst)

        self.context.elevated().MultipleTimes().AndReturn(self.context)
        db.service_get_by_compute_host(self.context,
                                       inst.host).AndReturn('fake-service')
        self.compute_api.servicegroup_api.service_is_up(
            'fake-service').AndReturn(inst.host != 'down-host')

        if self.is_cells:
            rpcapi = self.compute_api.cells_rpcapi
        else:
            rpcapi = self.compute_api.compute_rpcapi

        self.mox.StubOutWithMock(rpcapi, 'terminate_instance')
        self.mox.StubOutWithMock(rpcapi, 'soft_delete_instance')

        if inst.host == 'down-host':
            db.instance_info_cache_delete(self.context, inst.uuid)
            compute_utils.notify_about_instance_usage(self.context, inst,
                                                      '%s.start' % delete_type)
            self.compute_api.network_api.deallocate_for_instance(
                self.context, inst)
            db.instance_system_metadata_get(self.context,
                                            inst.uuid).AndReturn('sys-meta')
            state = ('soft' in delete_type and vm_states.SOFT_DELETED
                     or vm_states.DELETED)
            updates.update({
                'vm_state': state,
                'task_state': None,
                'terminated_at': delete_time
            })
            inst.save()
            if self.is_cells:
                if delete_type == 'soft_delete':
                    rpcapi.soft_delete_instance(self.context,
                                                inst,
                                                reservations=None)
                else:
                    rpcapi.terminate_instance(self.context,
                                              inst, [],
                                              reservations=None)
            db.instance_destroy(self.context, inst.uuid)
            compute_utils.notify_about_instance_usage(
                self.context,
                inst,
                '%s.end' % delete_type,
                system_metadata='sys-meta')

        if inst.host == 'down-host':
            quota.QUOTAS.commit(self.context,
                                'fake-resv',
                                project_id=inst.project_id,
                                user_id=inst.user_id)
        elif delete_type == 'soft_delete':
            self.compute_api._record_action_start(self.context, inst,
                                                  instance_actions.DELETE)
            rpcapi.soft_delete_instance(self.context,
                                        inst,
                                        reservations='fake-resv')
        elif delete_type in ['delete', 'force_delete']:
            self.compute_api._record_action_start(self.context, inst,
                                                  instance_actions.DELETE)
            rpcapi.terminate_instance(self.context,
                                      inst, [],
                                      reservations='fake-resv')

        self.mox.ReplayAll()

        getattr(self.compute_api, delete_type)(self.context, inst)
        for k, v in updates.items():
            self.assertEqual(inst[k], v)