Merge "vmware: support both hard and soft reboot"

This commit is contained in:
Jenkins 2015-03-06 03:04:18 +00:00 committed by Gerrit Code Review
commit 69b4ecb598
4 changed files with 62 additions and 3 deletions

View File

@ -1303,6 +1303,16 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
info = self._get_info()
self._check_vm_info(info, power_state.RUNNING)
def test_reboot_hard(self):
self._create_vm()
info = self._get_info()
self._check_vm_info(info, power_state.RUNNING)
reboot_type = "HARD"
self.conn.reboot(self.context, self.instance, self.network_info,
reboot_type)
info = self._get_info()
self._check_vm_info(info, power_state.RUNNING)
def test_reboot_with_uuid(self):
"""Test fall back to use name when can't find by uuid."""
self._create_vm()

View File

@ -1874,3 +1874,51 @@ class VMwareVMOpsTestCase(test.NoDBTestCase):
self.flags(image_cache_subdirectory_name='_base')
base_folder = self._vmops._get_base_folder()
self.assertEqual('my_prefix_base', base_folder)
def _test_reboot_vm(self, reboot_type="SOFT"):
expected_methods = ['get_object_properties']
if reboot_type == "SOFT":
expected_methods.append('RebootGuest')
else:
expected_methods.append('ResetVM_Task')
query = {}
query['runtime.powerState'] = "poweredOn"
query['summary.guest.toolsStatus'] = "toolsOk"
query['summary.guest.toolsRunningStatus'] = "guestToolsRunning"
def fake_call_method(module, method, *args, **kwargs):
expected_method = expected_methods.pop(0)
self.assertEqual(expected_method, method)
if (expected_method == 'get_object_properties'):
return 'fake-props'
elif (expected_method == 'ResetVM_Task'):
return 'fake-task'
with contextlib.nested(
mock.patch.object(vm_util, "get_vm_ref",
return_value='fake-vm-ref'),
mock.patch.object(vm_util, "get_values_from_object_properties",
return_value=query),
mock.patch.object(self._session, "_call_method",
fake_call_method),
mock.patch.object(self._session, "_wait_for_task")
) as (_get_vm_ref, _get_values_from_object_properties,
fake_call_method, _wait_for_task):
self._vmops.reboot(self._instance, self.network_info, reboot_type)
_get_vm_ref.assert_called_once_with(self._session,
self._instance)
_get_values_from_object_properties.assert_called_once_with(
self._session,
'fake-props')
if reboot_type == "HARD":
_wait_for_task.assert_has_calls([
mock.call('fake-task')])
def test_reboot_vm_soft(self):
self._test_reboot_vm()
def test_reboot_vm_hard(self):
self._test_reboot_vm(reboot_type="HARD")

View File

@ -501,7 +501,7 @@ class VMwareVCDriver(driver.ComputeDriver):
def reboot(self, context, instance, network_info, reboot_type,
block_device_info=None, bad_volumes_callback=None):
"""Reboot VM instance."""
self._vmops.reboot(instance, network_info)
self._vmops.reboot(instance, network_info, reboot_type)
def destroy(self, context, instance, network_info, block_device_info=None,
destroy_disks=True, migrate_data=None):

View File

@ -853,7 +853,7 @@ class VMwareVMOps(object):
# TODO(vui) Add handling for when vmdk volume is attached.
self._delete_vm_snapshot(instance, vm_ref, snapshot_ref)
def reboot(self, instance, network_info):
def reboot(self, instance, network_info, reboot_type="SOFT"):
"""Reboot a VM instance."""
vm_ref = vm_util.get_vm_ref(self._session, instance)
lst_properties = ["summary.guest.toolsStatus", "runtime.powerState",
@ -874,7 +874,8 @@ class VMwareVMOps(object):
# If latest vmware tools are installed in the VM, and that the tools
# are running, then only do a guest reboot. Otherwise do a hard reset.
if (tools_status == "toolsOk" and
tools_running_status == "guestToolsRunning"):
tools_running_status == "guestToolsRunning" and
reboot_type == "SOFT"):
LOG.debug("Rebooting guest OS of VM", instance=instance)
self._session._call_method(self._session.vim, "RebootGuest",
vm_ref)