def test_combine_should_combine_base_snapshot_location_with_snapshot_name( self): # Act snapshot_path = SnapshotRetriever.combine('snapshot1/snapshot2', 'snapshot3') # Assert self.assertEqual(snapshot_path, 'snapshot1/snapshot2/snapshot3')
def test_empty_dict_when_vm_has_no_snapshots(self): # Arrange vm = Mock() vm.snapshot = None # Act all_snapshots = SnapshotRetriever.get_vm_snapshots(vm) # assert self.assertSequenceEqual(all_snapshots, {})
def test_cet_current_snapshot_returns_none_when_no_snapshot_exists(self): # Arrange vm = Mock() vm.snapshot = None # Act current_snapshot_name = SnapshotRetriever.get_current_snapshot_name(vm) # assert self.assertIsNone(current_snapshot_name)
def get_snapshots(self, si, logger, vm_uuid): """ Restores a virtual machine to a snapshot :param vim.ServiceInstance si: py_vmomi service instance :param logger: Logger :param vm_uuid: uuid of the virtual machine """ vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid) logger.info("Get snapshots") return SnapshotRetriever.get_vm_snapshots(vm).keys()
def test_one_snapshot_when_one_snapshot_exists(self): # Arrange snapshot = Mock() snapshot.name = 'snap1' snapshot.childSnapshotList = [] vm = Mock() vm.snapshot = Mock() vm.snapshot.rootSnapshotList = [snapshot] # Act all_snapshots = SnapshotRetriever.get_vm_snapshots(vm) # assert self.assertSequenceEqual(all_snapshots.keys(), ['snap1'])
def _get_snapshot(vm, snapshot_name): """ Returns snapshot object by its name :param vm: :param snapshot_name: :type snapshot_name: str :return: Snapshot by its name :rtype vim.vm.Snapshot """ snapshots = SnapshotRetriever.get_vm_snapshots(vm) if snapshot_name not in snapshots: raise SnapshotNotFoundException('Snapshot {0} was not found'.format(snapshot_name)) return snapshots[snapshot_name]
def test_two_snapshots_when_root_snapshot_has_a_child(self): # Arrange child = Mock() child.name = 'child' child.childSnapshotList = [] root = Mock() root.name = 'root' root.childSnapshotList = [child] vm = Mock() vm.snapshot = Mock() vm.snapshot.rootSnapshotList = [root] # Act all_snapshots = SnapshotRetriever.get_vm_snapshots(vm) # assert self.assertSequenceEqual(all_snapshots.keys(), ['root', 'root/child'])
def _verify_snapshot_uniquness(snapshot_path_to_be_created, vm): all_snapshots = SnapshotRetriever.get_vm_snapshots(vm) if snapshot_path_to_be_created in all_snapshots: raise SnapshotAlreadyExistsException(SNAPSHOT_ALREADY_EXISTS)
def test_ctor(self): snapshot_retriever = SnapshotRetriever() self.assertIsNotNone(snapshot_retriever)
def test_combine_should_combine_base_snapshot_location_with_snapshot_name(self): # Act snapshot_path = SnapshotRetriever.combine('snapshot1/snapshot2', 'snapshot3') # Assert self.assertEqual(snapshot_path, 'snapshot1/snapshot2/snapshot3')
def _get_snapshot_name_to_be_created(snapshot_name, vm): current_snapshot_name = SnapshotRetriever.get_current_snapshot_name(vm) if not current_snapshot_name: return snapshot_name return SnapshotRetriever.combine(current_snapshot_name, snapshot_name)