Merge "VMware: Use actual VM state instead of using the instance vm_state"

This commit is contained in:
Jenkins 2016-03-05 17:29:00 +00:00 committed by Gerrit Code Review
commit 5b972c62ba
4 changed files with 36 additions and 21 deletions

View File

@ -630,7 +630,6 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
self.conn.destroy(self.context, self.instance, self.network_info,
block_device_info=bdi)
mock_power_off.assert_called_once_with(self.instance)
self.assertEqual(vm_states.STOPPED, self.instance.vm_state)
mock_detach_volume.assert_called_once_with(
connection_info, self.instance, 'fake-name')
mock_destroy.assert_called_once_with(self.instance, True)
@ -1443,7 +1442,6 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
block_device_info_get_mapping.assert_called_once_with(
block_device_info)
vmops.power_off.assert_called_once_with(self.instance)
self.assertEqual(vm_states.STOPPED, self.instance.vm_state)
exp_detach_calls = [mock.call(mock.sentinel.connection_info_1,
self.instance, 'dev1'),
mock.call(mock.sentinel.connection_info_2,

View File

@ -129,8 +129,11 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
mock.patch.object(vm_util, 'get_vm_ref'),
mock.patch.object(self._volumeops, '_get_volume_ref'),
mock.patch.object(vm_util, 'get_vmdk_info',
return_value=vmdk_info)
) as (get_vm_ref, get_volume_ref, get_vmdk_info):
return_value=vmdk_info),
mock.patch.object(vm_util, 'get_vm_state',
return_value='PoweredOn')
) as (get_vm_ref, get_volume_ref, get_vmdk_info,
get_vm_state):
self.assertRaises(exception.Invalid,
self._volumeops._attach_volume_vmdk, connection_info,
instance)
@ -140,6 +143,8 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
get_volume_ref.assert_called_once_with(
connection_info['data']['volume'])
self.assertTrue(get_vmdk_info.called)
get_vm_state.assert_called_once_with(self._volumeops._session,
instance)
@mock.patch.object(vm_util, 'get_vm_extra_config_spec',
return_value=mock.sentinel.extra_config)
@ -283,9 +288,11 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
mock.patch.object(self._volumeops,
'_get_vmdk_backed_disk_device'),
mock.patch.object(vm_util, 'get_vmdk_info',
return_value=vmdk_info)
return_value=vmdk_info),
mock.patch.object(vm_util, 'get_vm_state',
return_value='PoweredOn')
) as (get_vm_ref, get_volume_ref, get_vmdk_backed_disk_device,
get_vmdk_info):
get_vmdk_info, get_vm_state):
self.assertRaises(exception.Invalid,
self._volumeops._detach_volume_vmdk, connection_info,
instance)
@ -297,6 +304,8 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
get_vmdk_backed_disk_device.assert_called_once_with(
mock.sentinel.vm_ref, connection_info['data'])
self.assertTrue(get_vmdk_info.called)
get_vm_state.assert_called_once_with(self._volumeops._session,
instance)
@mock.patch.object(vm_util, 'get_vm_ref')
@mock.patch.object(vm_util, 'get_rdm_disk')
@ -400,15 +409,21 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
device)
adapter_type = adapter_type or default_adapter_type
if adapter_type == constants.ADAPTER_TYPE_IDE:
vm_state = 'PoweredOff'
else:
vm_state = 'PoweredOn'
with test.nested(
mock.patch.object(vm_util, 'get_vm_ref', return_value=vm_ref),
mock.patch.object(self._volumeops, '_get_volume_ref'),
mock.patch.object(vm_util, 'get_vmdk_info',
return_value=vmdk_info),
mock.patch.object(self._volumeops, 'attach_disk_to_vm'),
mock.patch.object(self._volumeops, '_update_volume_details')
mock.patch.object(self._volumeops, '_update_volume_details'),
mock.patch.object(vm_util, 'get_vm_state',
return_value=vm_state)
) as (get_vm_ref, get_volume_ref, get_vmdk_info, attach_disk_to_vm,
update_volume_details):
update_volume_details, get_vm_state):
self._volumeops.attach_volume(connection_info, self._instance,
adapter_type)
@ -422,6 +437,11 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
constants.DISK_TYPE_PREALLOCATED, vmdk_path='fake-path')
update_volume_details.assert_called_once_with(
vm_ref, connection_info['data']['volume_id'], disk_uuid)
if adapter_type == constants.ADAPTER_TYPE_IDE:
get_vm_state.assert_called_once_with(self._volumeops._session,
self._instance)
else:
self.assertFalse(get_vm_state.called)
def _test_attach_volume_iscsi(self, adapter_type=None):
connection_info = {'driver_volume_type': constants.DISK_FORMAT_ISCSI,

View File

@ -32,7 +32,6 @@ from oslo_vmware import vim
from oslo_vmware import vim_util
from nova.compute import task_states
from nova.compute import vm_states
import nova.conf
from nova import exception
from nova.i18n import _, _LI, _LE, _LW
@ -417,9 +416,6 @@ class VMwareVCDriver(driver.ComputeDriver):
# plugging. Hence we need to power off the instance and update
# the instance state.
self._vmops.power_off(instance)
# TODO(garyk): update the volumeops to read the state from the
# VM instead of relying on an instance flag
instance.vm_state = vm_states.STOPPED
for disk in block_device_mapping:
connection_info = disk['connection_info']
try:

View File

@ -22,7 +22,6 @@ from oslo_log import log as logging
from oslo_vmware import exceptions as oslo_vmw_exceptions
from oslo_vmware import vim_util as vutil
from nova.compute import vm_states
from nova import exception
from nova.i18n import _, _LI, _LW
from nova.virt.vmwareapi import constants
@ -331,10 +330,11 @@ class VMwareVolumeOps(object):
adapter_type = adapter_type or vmdk.adapter_type
# IDE does not support disk hotplug
if (instance.vm_state == vm_states.ACTIVE and
adapter_type == constants.ADAPTER_TYPE_IDE):
msg = _('%s does not support disk hotplug.') % adapter_type
raise exception.Invalid(msg)
if adapter_type == constants.ADAPTER_TYPE_IDE:
state = vm_util.get_vm_state(self._session, instance)
if state.lower() != 'poweredoff':
raise exception.Invalid(_('%s does not support disk '
'hotplug.') % adapter_type)
# Attach the disk to virtual machine instance
self.attach_disk_to_vm(vm_ref, instance, adapter_type, vmdk.disk_type,
@ -530,10 +530,11 @@ class VMwareVolumeOps(object):
vmdk = vm_util.get_vmdk_info(self._session, volume_ref)
# IDE does not support disk hotplug
if (instance.vm_state == vm_states.ACTIVE and
vmdk.adapter_type == constants.ADAPTER_TYPE_IDE):
msg = _('%s does not support disk hotplug.') % vmdk.adapter_type
raise exception.Invalid(msg)
if vmdk.adapter_type == constants.ADAPTER_TYPE_IDE:
state = vm_util.get_vm_state(self._session, instance)
if state.lower() != 'poweredoff':
raise exception.Invalid(_('%s does not support disk '
'hotplug.') % vmdk.adapter_type)
self._consolidate_vmdk_volume(instance, vm_ref, device, volume_ref,
adapter_type=vmdk.adapter_type,