def test_get_power_state(self, mock_vm_info):
        mock_vm_info.side_effect = [
            {constants.VM_POWER_STATE: mock.sentinel.unknown_power_state},
            {constants.VM_POWER_STATE: 'poweroff'}]

        self.assertEqual(mock.sentinel.unknown_power_state,
                         vmutils.get_power_state(self._instance))
        self.assertEqual('poweroff',
                         vmutils.get_power_state(self._instance))
Beispiel #2
0
    def test_get_power_state(self, mock_vm_info):
        mock_vm_info.side_effect = [{
            constants.VM_POWER_STATE:
            mock.sentinel.unknown_power_state
        }, {
            constants.VM_POWER_STATE: 'poweroff'
        }]

        self.assertEqual(mock.sentinel.unknown_power_state,
                         vmutils.get_power_state(self._instance))
        self.assertEqual('poweroff', vmutils.get_power_state(self._instance))
Beispiel #3
0
    def destroy(self,
                instance,
                context=None,
                network_info=None,
                block_device_info=None,
                destroy_disks=True,
                migrate_data=None):
        """Destroy the specified instance from the Hypervisor."""
        LOG.info(i18n._("Got request to destroy instance"), instance=instance)
        if not self.instance_exists(instance):
            LOG.warning(i18n._("Instance do not exists."), instance=instance)
            return

        power_state = vmutils.get_power_state(instance)
        if power_state not in (constants.STATE_POWER_OFF,
                               constants.STATE_SAVED):
            self._vbox_manage.control_vm(instance, constants.STATE_POWER_OFF)

        try:
            self._vbox_manage.unregister_vm(instance, delete=destroy_disks)
            if destroy_disks:
                pathutils.instance_basepath(instance,
                                            action=constants.PATH_DELETE)
        except vbox_exc.VBoxException:
            with excutils.save_and_reraise_exception():
                LOG.exception(i18n._('Failed to destroy instance: %s'),
                              instance.name)
    def destroy(self,
                instance,
                context=None,
                network_info=None,
                block_device_info=None,
                destroy_disks=True,
                migrate_data=None):
        """Destroy the specified instance from the Hypervisor."""
        LOG.info(i18n._("Got request to destroy instance"), instance=instance)
        if not self.instance_exists(instance):
            LOG.warning(i18n._("Instance do not exists."), instance=instance)
            return

        power_state = vmutils.get_power_state(instance)
        if power_state not in (constants.STATE_POWER_OFF,
                               constants.STATE_SAVED):
            self._vbox_manage.control_vm(instance, constants.STATE_POWER_OFF)

        try:
            self._vbox_manage.unregister_vm(instance, delete=destroy_disks)
            if destroy_disks:
                pathutils.instance_basepath(
                    instance, action=constants.PATH_DELETE)
        except vbox_exc.VBoxException:
            with excutils.save_and_reraise_exception():
                LOG.exception(
                    i18n._('Failed to destroy instance: %s'), instance.name)