Merge "XenAPI: Fix data loss on resize up"
This commit is contained in:
@@ -710,6 +710,7 @@ class MigrateDiskAndPowerOffTestCase(VMOpsTestBase):
|
||||
None, instance, None, flavor, None)
|
||||
|
||||
|
||||
@mock.patch.object(vm_utils, 'get_vdi_for_vm_safely')
|
||||
@mock.patch.object(vm_utils, 'migrate_vhd')
|
||||
@mock.patch.object(vmops.VMOps, '_resize_ensure_vm_is_shutdown')
|
||||
@mock.patch.object(vm_utils, 'get_all_vdi_uuids_for_vm')
|
||||
@@ -733,7 +734,7 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
def test_migrate_disk_resizing_up_works_no_ephemeral(self,
|
||||
mock_is_booted_from_volume,
|
||||
mock_apply_orig, mock_update_progress, mock_get_all_vdi_uuids,
|
||||
mock_shutdown, mock_migrate_vhd):
|
||||
mock_shutdown, mock_migrate_vhd, mock_get_vdi_for_vm):
|
||||
context = "ctxt"
|
||||
instance = {"name": "fake", "uuid": "uuid"}
|
||||
dest = "dest"
|
||||
@@ -741,6 +742,7 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
sr_path = "sr_path"
|
||||
|
||||
mock_get_all_vdi_uuids.return_value = None
|
||||
mock_get_vdi_for_vm.return_value = ({}, {"uuid": "root"})
|
||||
|
||||
with mock.patch.object(vm_utils, '_snapshot_attached_here_impl',
|
||||
self._fake_snapshot_attached_here):
|
||||
@@ -756,7 +758,7 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
dest, sr_path, 1),
|
||||
mock.call(self.vmops._session, instance, "grandp",
|
||||
dest, sr_path, 2),
|
||||
mock.call(self.vmops._session, instance, "leaf",
|
||||
mock.call(self.vmops._session, instance, "root",
|
||||
dest, sr_path, 0)]
|
||||
self.assertEqual(m_vhd_expected, mock_migrate_vhd.call_args_list)
|
||||
|
||||
@@ -774,7 +776,7 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
def test_migrate_disk_resizing_up_works_with_two_ephemeral(self,
|
||||
mock_is_booted_from_volume,
|
||||
mock_apply_orig, mock_update_progress, mock_get_all_vdi_uuids,
|
||||
mock_shutdown, mock_migrate_vhd):
|
||||
mock_shutdown, mock_migrate_vhd, mock_get_vdi_for_vm):
|
||||
context = "ctxt"
|
||||
instance = {"name": "fake", "uuid": "uuid"}
|
||||
dest = "dest"
|
||||
@@ -782,6 +784,9 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
sr_path = "sr_path"
|
||||
|
||||
mock_get_all_vdi_uuids.return_value = ["vdi-eph1", "vdi-eph2"]
|
||||
mock_get_vdi_for_vm.side_effect = [({}, {"uuid": "root"}),
|
||||
({}, {"uuid": "4-root"}),
|
||||
({}, {"uuid": "5-root"})]
|
||||
|
||||
with mock.patch.object(vm_utils, '_snapshot_attached_here_impl',
|
||||
self._fake_snapshot_attached_here):
|
||||
@@ -802,11 +807,11 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
mock.call(self.vmops._session, instance,
|
||||
"5-parent", dest, sr_path, 1, 2),
|
||||
mock.call(self.vmops._session, instance,
|
||||
"leaf", dest, sr_path, 0),
|
||||
"root", dest, sr_path, 0),
|
||||
mock.call(self.vmops._session, instance,
|
||||
"4-leaf", dest, sr_path, 0, 1),
|
||||
"4-root", dest, sr_path, 0, 1),
|
||||
mock.call(self.vmops._session, instance,
|
||||
"5-leaf", dest, sr_path, 0, 2)]
|
||||
"5-root", dest, sr_path, 0, 2)]
|
||||
self.assertEqual(m_vhd_expected, mock_migrate_vhd.call_args_list)
|
||||
|
||||
prog_expected = [
|
||||
@@ -823,7 +828,7 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
def test_migrate_disk_resizing_up_booted_from_volume(self,
|
||||
mock_is_booted_from_volume,
|
||||
mock_apply_orig, mock_update_progress, mock_get_all_vdi_uuids,
|
||||
mock_shutdown, mock_migrate_vhd):
|
||||
mock_shutdown, mock_migrate_vhd, mock_get_vdi_for_vm):
|
||||
context = "ctxt"
|
||||
instance = {"name": "fake", "uuid": "uuid"}
|
||||
dest = "dest"
|
||||
@@ -831,6 +836,8 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
sr_path = "sr_path"
|
||||
|
||||
mock_get_all_vdi_uuids.return_value = ["vdi-eph1", "vdi-eph2"]
|
||||
mock_get_vdi_for_vm.side_effect = [({}, {"uuid": "4-root"}),
|
||||
({}, {"uuid": "5-root"})]
|
||||
|
||||
with mock.patch.object(vm_utils, '_snapshot_attached_here_impl',
|
||||
self._fake_snapshot_attached_here):
|
||||
@@ -847,9 +854,9 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
mock.call(self.vmops._session, instance,
|
||||
"5-parent", dest, sr_path, 1, 2),
|
||||
mock.call(self.vmops._session, instance,
|
||||
"4-leaf", dest, sr_path, 0, 1),
|
||||
"4-root", dest, sr_path, 0, 1),
|
||||
mock.call(self.vmops._session, instance,
|
||||
"5-leaf", dest, sr_path, 0, 2)]
|
||||
"5-root", dest, sr_path, 0, 2)]
|
||||
self.assertEqual(m_vhd_expected, mock_migrate_vhd.call_args_list)
|
||||
|
||||
prog_expected = [
|
||||
@@ -868,7 +875,7 @@ class MigrateDiskResizingUpTestCase(VMOpsTestBase):
|
||||
mock_is_booted_from_volume,
|
||||
mock_restore,
|
||||
mock_apply_orig, mock_update_progress, mock_get_all_vdi_uuids,
|
||||
mock_shutdown, mock_migrate_vhd):
|
||||
mock_shutdown, mock_migrate_vhd, mock_get_vdi_for_vm):
|
||||
context = "ctxt"
|
||||
instance = {"name": "fake", "uuid": "fake"}
|
||||
dest = "dest"
|
||||
|
||||
@@ -996,14 +996,12 @@ class VMOps(object):
|
||||
|
||||
@step
|
||||
def transfer_immutable_vhds(root_vdi_uuids):
|
||||
active_root_vdi_uuid = root_vdi_uuids[0]
|
||||
immutable_root_vdi_uuids = root_vdi_uuids[1:]
|
||||
for vhd_num, vdi_uuid in enumerate(immutable_root_vdi_uuids,
|
||||
start=1):
|
||||
vm_utils.migrate_vhd(self._session, instance, vdi_uuid, dest,
|
||||
sr_path, vhd_num)
|
||||
LOG.debug("Migrated root base vhds", instance=instance)
|
||||
return active_root_vdi_uuid
|
||||
|
||||
def _process_ephemeral_chain_recursive(ephemeral_chains,
|
||||
active_vdi_uuids):
|
||||
@@ -1041,7 +1039,10 @@ class VMOps(object):
|
||||
vm_ref, label, str(userdevice)) as chain_vdi_uuids:
|
||||
|
||||
# remember active vdi, we will migrate these later
|
||||
active_vdi_uuids.append(chain_vdi_uuids[0])
|
||||
vdi_ref, vm_vdi_rec = vm_utils.get_vdi_for_vm_safely(
|
||||
self._session, vm_ref, str(userdevice))
|
||||
active_uuid = vm_vdi_rec['uuid']
|
||||
active_vdi_uuids.append(active_uuid)
|
||||
|
||||
# migrate inactive vhds
|
||||
inactive_vdi_uuids = chain_vdi_uuids[1:]
|
||||
@@ -1113,7 +1114,10 @@ class VMOps(object):
|
||||
fake_step_to_show_snapshot_complete()
|
||||
|
||||
# transfer all the non-active VHDs in the root disk chain
|
||||
active_root_vdi_uuid = transfer_immutable_vhds(root_vdi_uuids)
|
||||
transfer_immutable_vhds(root_vdi_uuids)
|
||||
vdi_ref, vm_vdi_rec = vm_utils.get_vdi_for_vm_safely(
|
||||
self._session, vm_ref)
|
||||
active_root_vdi_uuid = vm_vdi_rec['uuid']
|
||||
|
||||
# snapshot and transfer all ephemeral disks
|
||||
# then power down and transfer any diffs since
|
||||
|
||||
Reference in New Issue
Block a user