Allow setting VM snapshot types

On WS 2016, Hyper-V will attempt to take production checkpoints by
default, if the guest advertises this feature. The issue is that
the mechanism that automatically detects the VM checkpoint type
supported by the guest is not entirely safe.

We've had issues with older LIS versions in which case this feature
was not properly advertised and production checkpoints were attempted
but failed.

This change will allow explicitly setting the VM snapshot type to
be used for a given instance.

Partial-Bug: #1664941

Change-Id: I9fba30143bb0f653f1aaf7c97e5c3008a9f03120
This commit is contained in:
Lucian Petrut
2017-01-19 23:01:27 +02:00
parent 86cb811192
commit 4ddc77bbe2
5 changed files with 37 additions and 12 deletions

View File

@@ -204,3 +204,9 @@ VLAN_MODE_TRUNK = 2
HOST_SHUTDOWN_ACTION_TURN_OFF = 2
HOST_SHUTDOWN_ACTION_SAVE = 3
HOST_SHUTDOWN_ACTION_SHUTDOWN = 4
# VM snapshot types
VM_SNAPSHOT_TYPE_DISABLED = 2
VM_SNAPSHOT_TYPE_PROD_FALLBACK = 3
VM_SNAPSHOT_TYPE_PROD_ENFORCED = 4
VM_SNAPSHOT_TYPE_STANDARD = 5

View File

@@ -301,9 +301,12 @@ class VMUtilsTestCase(test_base.OsWinBaseTestCase):
@mock.patch.object(vmutils.VMUtils, '_modify_virtual_system')
@mock.patch.object(vmutils.VMUtils, '_set_vm_vcpus')
@mock.patch.object(vmutils.VMUtils, '_set_vm_memory')
@mock.patch.object(vmutils.VMUtils, '_set_vm_snapshot_type')
@mock.patch.object(vmutils.VMUtils, '_lookup_vm_check')
def test_update_vm(self, mock_lookup_vm_check, mock_set_mem,
mock_set_vcpus, mock_modify_virtual_system,
def test_update_vm(self, mock_lookup_vm_check,
mock_set_vm_snap_type,
mock_set_mem, mock_set_vcpus,
mock_modify_virtual_system,
host_shutdown_action=None,
configuration_root_dir=None, vnuma_enabled=None):
mock_vmsettings = mock_lookup_vm_check.return_value
@@ -313,7 +316,8 @@ class VMUtilsTestCase(test_base.OsWinBaseTestCase):
mock.sentinel.vcpus_per_numa, mock.sentinel.limit_cpu_features,
mock.sentinel.dynamic_mem_ratio, configuration_root_dir,
host_shutdown_action=host_shutdown_action,
vnuma_enabled=vnuma_enabled)
vnuma_enabled=vnuma_enabled,
snapshot_type=mock.sentinel.snap_type)
mock_lookup_vm_check.assert_called_once_with(mock.sentinel.vm_name)
mock_set_mem.assert_called_once_with(
@@ -340,11 +344,11 @@ class VMUtilsTestCase(test_base.OsWinBaseTestCase):
if vnuma_enabled:
self.assertEqual(vnuma_enabled, mock_vmsettings.VirtualNumaEnabled)
if configuration_root_dir or host_shutdown_action or vnuma_enabled:
mock_modify_virtual_system.assert_called_once_with(
mock_vmsettings)
else:
mock_modify_virtual_system.assert_not_called()
mock_set_vm_snap_type.assert_called_once_with(
mock_vmsettings, mock.sentinel.snap_type)
mock_modify_virtual_system.assert_called_once_with(
mock_vmsettings)
@mock.patch.object(vmutils.VMUtils, '_set_vm_memory')
@mock.patch.object(vmutils.VMUtils, '_create_vm_obj')

View File

@@ -349,3 +349,12 @@ class VMUtils10TestCase(test_base.OsWinBaseTestCase):
self._vmutils._jobutils.remove_multiple_virt_resources)
mock_remove_multiple_virt_resource.assert_called_once_with(
mock_get_element_associated_class.return_value)
def test_set_snapshot_type(self):
vmsettings = mock.Mock()
self._vmutils._set_vm_snapshot_type(
vmsettings, mock.sentinel.snapshot_type)
self.assertEqual(mock.sentinel.snapshot_type,
vmsettings.UserSnapshotType)

View File

@@ -287,6 +287,7 @@ class VMUtils(baseutils.BaseUtilsVirt):
vcpus_per_numa_node, limit_cpu_features, dynamic_mem_ratio,
configuration_root_dir=None, snapshot_dir=None,
host_shutdown_action=None, vnuma_enabled=None,
snapshot_type=constants.VM_SNAPSHOT_TYPE_PROD_FALLBACK,
is_planned_vm=False):
vmsetting = self._lookup_vm_check(vm_name)
@@ -308,11 +309,9 @@ class VMUtils(baseutils.BaseUtilsVirt):
self._set_vm_vcpus(vmsetting, vcpus_num, vcpus_per_numa_node,
limit_cpu_features)
update_needed = (configuration_root_dir or host_shutdown_action or
vnuma_enabled is not None)
self._set_vm_snapshot_type(vmsetting, snapshot_type)
if update_needed:
self._modify_virtual_system(vmsetting)
self._modify_virtual_system(vmsetting)
def check_admin_permissions(self):
if not self._compat_conn.Msvm_VirtualSystemManagementService():
@@ -1205,4 +1204,7 @@ class VMUtils(baseutils.BaseUtilsVirt):
There are no PCI devices attached to Windows / Hyper-V Server 2012 R2
or older VMs.
"""
def _set_vm_snapshot_type(self, vmsettings, snapshot_type):
# Supported on Windows Server 2016 or newer.
pass

View File

@@ -288,3 +288,7 @@ class VMUtils10(vmutils.VMUtils):
if pci_sds:
self._jobutils.remove_multiple_virt_resources(pci_sds)
def _set_vm_snapshot_type(self, vmsettings, snapshot_type):
# We expect the caller to actually push the vmsettings update.
vmsettings.UserSnapshotType = snapshot_type