Add unit tests for cloning from snapshot (#37414)

This commit is contained in:
Aditya Kulkarni 2016-11-02 13:22:37 -04:00 committed by Nicole Thomas
parent ecd794a233
commit e9b4620fac

View file

@ -1098,6 +1098,83 @@ class VMwareTestCase(ExtendedTestCase):
call='function')
class CloneFromSnapshotTest(TestCase):
'''
Test functionality to clone from snapshot
'''
@skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
def test_quick_linked_clone(self):
'''
Test that disk move type is
set to createNewChildDiskBacking
'''
self._test_clone_type(vmware.QUICK_LINKED_CLONE)
@skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
def test_current_state_linked_clone(self):
'''
Test that disk move type is
set to moveChildMostDiskBacking
'''
self._test_clone_type(vmware.CURRENT_STATE_LINKED_CLONE)
@skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
def test_copy_all_disks_full_clone(self):
'''
Test that disk move type is
set to moveAllDiskBackingsAndAllowSharing
'''
self._test_clone_type(vmware.COPY_ALL_DISKS_FULL_CLONE)
@skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
def test_flatten_all_all_disks_full_clone(self):
'''
Test that disk move type is
set to moveAllDiskBackingsAndDisallowSharing
'''
self._test_clone_type(vmware.FLATTEN_DISK_FULL_CLONE)
@skipIf(HAS_LIBS is False, "Install pyVmomi to be able to run this unit test.")
def test_raises_error_for_invalid_disk_move_type(self):
'''
Test that invalid disk move type
raises error
'''
with self.assertRaises(SaltCloudSystemExit):
self._test_clone_type('foobar')
def _test_clone_type(self, clone_type):
'''
Assertions for checking that a certain clone type
works
'''
obj_ref = MagicMock()
obj_ref.snapshot = vim.vm.Snapshot(None, None)
obj_ref.snapshot.currentSnapshot = vim.vm.Snapshot(None, None)
clone_spec = vmware.handle_snapshot(
vim.vm.ConfigSpec(),
obj_ref,
vim.vm.RelocateSpec(),
False,
{'snapshot': {
'disk_move_type': clone_type}})
self.assertEqual(clone_spec.location.diskMoveType, clone_type)
obj_ref2 = MagicMock()
obj_ref2.snapshot = vim.vm.Snapshot(None, None)
obj_ref2.snapshot.currentSnapshot = vim.vm.Snapshot(None, None)
clone_spec2 = vmware.handle_snapshot(
vim.vm.ConfigSpec(),
obj_ref2,
vim.vm.RelocateSpec(),
True,
{'snapshot': {
'disk_move_type': clone_type}})
self.assertEqual(clone_spec2.location.diskMoveType, clone_type)
if __name__ == '__main__':
from integration import run_tests
run_tests(VMwareTestCase, needs_daemon=False)
run_tests(CloneFromSnapshotTest, needs_daemon=False)