コード例 #1
0
    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')
コード例 #2
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, {})
コード例 #3
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, {})
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
 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()
コード例 #7
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'])
コード例 #8
0
    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]
コード例 #9
0
    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]
コード例 #10
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'])
コード例 #11
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'])
コード例 #12
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'])
コード例 #13
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)
コード例 #14
0
 def test_ctor(self):
     snapshot_retriever = SnapshotRetriever()
     self.assertIsNotNone(snapshot_retriever)
コード例 #15
0
    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')
コード例 #16
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)
コード例 #17
0
 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)
コード例 #18
0
 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)