Beispiel #1
0
    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_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 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 _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]
Beispiel #5
0
    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_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'])
Beispiel #8
0
    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 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'])
Beispiel #10
0
 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 _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)