Fix bug on vmware driver attach volume failed
The function "get_vm_state" in vmwareapi returns the index of the vm state in nova InstancePowerState. The "int" value do not have .lower() function. This will cause error when attach volume. Closes-Bug: #1712281 Change-Id: I7b6d581904219d1ba4615054f9676390170ab1bc
This commit is contained in:
@@ -16,6 +16,7 @@ import mock
|
||||
from oslo_vmware import exceptions as oslo_vmw_exceptions
|
||||
from oslo_vmware import vim_util as vutil
|
||||
|
||||
from nova.compute import power_state
|
||||
from nova.compute import vm_states
|
||||
from nova import context
|
||||
from nova import exception
|
||||
@@ -132,7 +133,7 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
|
||||
mock.patch.object(vm_util, 'get_vmdk_info',
|
||||
return_value=vmdk_info),
|
||||
mock.patch.object(vm_util, 'get_vm_state',
|
||||
return_value='PoweredOn')
|
||||
return_value=power_state.RUNNING)
|
||||
) as (get_vm_ref, get_volume_ref, get_vmdk_info,
|
||||
get_vm_state):
|
||||
self.assertRaises(exception.Invalid,
|
||||
@@ -291,7 +292,7 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
|
||||
mock.patch.object(vm_util, 'get_vmdk_info',
|
||||
return_value=vmdk_info),
|
||||
mock.patch.object(vm_util, 'get_vm_state',
|
||||
return_value='PoweredOn')
|
||||
return_value=power_state.RUNNING)
|
||||
) as (get_vm_ref, get_volume_ref, get_vmdk_backed_disk_device,
|
||||
get_vmdk_info, get_vm_state):
|
||||
self.assertRaises(exception.Invalid,
|
||||
@@ -411,9 +412,9 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
|
||||
adapter_type = adapter_type or default_adapter_type
|
||||
|
||||
if adapter_type == constants.ADAPTER_TYPE_IDE:
|
||||
vm_state = 'PoweredOff'
|
||||
vm_state = power_state.SHUTDOWN
|
||||
else:
|
||||
vm_state = 'PoweredOn'
|
||||
vm_state = power_state.RUNNING
|
||||
with test.nested(
|
||||
mock.patch.object(vm_util, 'get_vm_ref', return_value=vm_ref),
|
||||
mock.patch.object(self._volumeops, '_get_volume_ref'),
|
||||
|
||||
@@ -21,6 +21,7 @@ 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 power_state
|
||||
import nova.conf
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
@@ -332,7 +333,7 @@ class VMwareVolumeOps(object):
|
||||
# IDE does not support disk hotplug
|
||||
if adapter_type == constants.ADAPTER_TYPE_IDE:
|
||||
state = vm_util.get_vm_state(self._session, instance)
|
||||
if state.lower() != 'poweredoff':
|
||||
if state != power_state.SHUTDOWN:
|
||||
raise exception.Invalid(_('%s does not support disk '
|
||||
'hotplug.') % adapter_type)
|
||||
|
||||
@@ -532,7 +533,7 @@ class VMwareVolumeOps(object):
|
||||
# IDE does not support disk hotplug
|
||||
if vmdk.adapter_type == constants.ADAPTER_TYPE_IDE:
|
||||
state = vm_util.get_vm_state(self._session, instance)
|
||||
if state.lower() != 'poweredoff':
|
||||
if state != power_state.SHUTDOWN:
|
||||
raise exception.Invalid(_('%s does not support disk '
|
||||
'hotplug.') % vmdk.adapter_type)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user