diff --git a/nova/tests/unit/virt/vmwareapi/test_driver_api.py b/nova/tests/unit/virt/vmwareapi/test_driver_api.py index 82a42b9bddb3..be81523fdcc1 100644 --- a/nova/tests/unit/virt/vmwareapi/test_driver_api.py +++ b/nova/tests/unit/virt/vmwareapi/test_driver_api.py @@ -1438,7 +1438,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): @mock.patch.object(driver.VMwareVCDriver, 'reboot') @mock.patch.object(vm_util, 'get_vm_state', - return_value='poweredOff') + return_value=power_state.SHUTDOWN) def test_resume_state_on_host_boot(self, mock_get_vm_state, mock_reboot): self._create_instance() @@ -1451,7 +1451,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): def test_resume_state_on_host_boot_no_reboot(self): self._create_instance() - for state in ['poweredOn', 'suspended']: + for state in [power_state.RUNNING, power_state.SUSPENDED]: with test.nested( mock.patch.object(driver.VMwareVCDriver, 'reboot'), mock.patch.object(vm_util, 'get_vm_state', diff --git a/nova/virt/vmwareapi/constants.py b/nova/virt/vmwareapi/constants.py index e5b04ad471c8..ff06249a912e 100644 --- a/nova/virt/vmwareapi/constants.py +++ b/nova/virt/vmwareapi/constants.py @@ -16,6 +16,7 @@ Shared constants across the VMware driver """ +from nova.compute import power_state from nova.network import model as network_model MIN_VC_VERSION = '5.1.0' @@ -225,3 +226,7 @@ VALID_OS_TYPES = set([ 'winXPPro64Guest', 'winXPProGuest', ]) + +POWER_STATES = {'poweredOff': power_state.SHUTDOWN, + 'poweredOn': power_state.RUNNING, + 'suspended': power_state.SUSPENDED} diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py index 4ddcbc3d2738..5b0e1bce0c63 100644 --- a/nova/virt/vmwareapi/driver.py +++ b/nova/virt/vmwareapi/driver.py @@ -30,6 +30,7 @@ from oslo_vmware import pbm from oslo_vmware import vim from oslo_vmware import vim_util +from nova.compute import power_state from nova.compute import task_states import nova.conf from nova import exception @@ -201,8 +202,8 @@ class VMwareVCDriver(driver.ComputeDriver): # Check if the instance is running already and avoid doing # anything if it is. state = vm_util.get_vm_state(self._session, instance) - ignored_states = ['poweredon', 'suspended'] - if state.lower() in ignored_states: + ignored_states = [power_state.RUNNING, power_state.SUSPENDED] + if state in ignored_states: return # Instance is not up and could be in an unknown state. # Be as absolute as possible about getting it back into diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index 067b91617842..b8c31652af29 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -1153,7 +1153,7 @@ def get_vm_state(session, instance): vm_ref = get_vm_ref(session, instance) vm_state = session._call_method(vutil, "get_object_property", vm_ref, "runtime.powerState") - return vm_state + return constants.POWER_STATES[vm_state] def get_stats_from_cluster(session, cluster): diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index 6c7a9239658d..0602fe6cf0c4 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -66,10 +66,6 @@ CONF = nova.conf.CONF LOG = logging.getLogger(__name__) -VMWARE_POWER_STATES = {'poweredOff': power_state.SHUTDOWN, - 'poweredOn': power_state.RUNNING, - 'suspended': power_state.SUSPENDED} - RESIZE_TOTAL_STEPS = 6 @@ -1517,7 +1513,7 @@ class VMwareVMOps(object): max_mem = int(vm_props.get('summary.config.memorySizeMB', 0)) * 1024 num_cpu = int(vm_props.get('summary.config.numCpu', 0)) return hardware.InstanceInfo( - state=VMWARE_POWER_STATES[vm_props['runtime.powerState']], + state=constants.POWER_STATES[vm_props['runtime.powerState']], max_mem_kb=max_mem, mem_kb=max_mem, num_cpu=num_cpu) @@ -1550,7 +1546,7 @@ class VMwareVMOps(object): data = self._get_diagnostics(instance) state = data.get('powerState') if state: - state = power_state.STATE_MAP[VMWARE_POWER_STATES[state]] + state = power_state.STATE_MAP[constants.POWER_STATES[state]] uptime = data.get('uptimeSeconds', 0) config_drive = configdrive.required_by(instance) diags = diagnostics.Diagnostics(state=state,