def test_03_delete_vm_snapshots(self):
        """Test to delete vm snapshots
        """

        list_snapshot_response = VmSnapshot.list(self.apiclient, vmid=self.virtual_machine.id, listall=True)

        self.assertEqual(
            isinstance(list_snapshot_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            list_snapshot_response,
            None,
            "Check if snapshot exists in ListSnapshot"
        )
        VmSnapshot.deleteVMSnapshot(self.apiclient, list_snapshot_response[0].id)

        time.sleep(self.services["sleep"] * 3)

        list_snapshot_response = VmSnapshot.list(self.apiclient, vmid=self.virtual_machine.id, listall=True)

        self.assertEqual(
            list_snapshot_response,
            None,
            "Check list vm snapshot has be deleted"
        )
Beispiel #2
0
    def test_03_delete_vm_snapshots(self):
        """Test to delete vm snapshots
        """

        list_snapshot_response = VmSnapshot.list(
            self.apiclient,
            virtualmachineid=self.virtual_machine.id,
            listall=True)

        self.assertEqual(isinstance(list_snapshot_response, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(list_snapshot_response, None,
                            "Check if snapshot exists in ListSnapshot")
        VmSnapshot.deleteVMSnapshot(self.apiclient,
                                    list_snapshot_response[0].id)

        time.sleep(30)

        list_snapshot_response = VmSnapshot.list(
            self.apiclient,
            virtualmachineid=self.virtual_machine.id,
            listall=False)
        self.debug('list_snapshot_response -------------------- %s' %
                   list_snapshot_response)

        self.assertIsNone(list_snapshot_response,
                          "snapshot is already deleted")
Beispiel #3
0
    def test_03_delete_vm_snapshots(self):
        """Test to delete vm snapshots
        """

        list_snapshot_response = VmSnapshot.list(self.apiclient, vmid=self.virtual_machine.id, listall=True)

        self.assertEqual(
            isinstance(list_snapshot_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            list_snapshot_response,
            None,
            "Check if snapshot exists in ListSnapshot"
        )
        VmSnapshot.deleteVMSnapshot(self.apiclient, list_snapshot_response[0].id)

        time.sleep(self.services["sleep"] * 3)

        list_snapshot_response = VmSnapshot.list(self.apiclient, vmid=self.virtual_machine.id, listall=True)

        self.assertEqual(
            list_snapshot_response,
            None,
            "Check list vm snapshot has be deleted"
        )
    def test_01_test_vm_volume_snapshot(self):
        """
        @Desc: Test that Volume snapshot for root volume is allowed
        when VM snapshot is present for the VM
        @Steps:
        1: Deploy a VM and create a VM snapshot for VM
        2: Try to create snapshot for the root volume of the VM,
        It should not fail
        """

        # Creating Virtual Machine
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )

        VmSnapshot.create(
            self.apiclient,
            virtual_machine.id,
        )

        volumes = Volume.list(self.apiclient,
                              virtualmachineid=virtual_machine.id,
                              type="ROOT",
                              listall=True)

        self.assertEqual(validateList(volumes)[0], PASS,
                "Failed to get root volume of the VM")

        snapshot = Snapshot.create(
            self.apiclient,
            volumes[0].id,
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.debug("Snapshot created: ID - %s" % snapshot.id)
        snapshots = list_snapshots(
            self.apiclient,
            id=snapshot.id
        )
        self.assertEqual(
            validateList(snapshots)[0],
            PASS,
            "Invalid snapshot list"
        )
        self.assertEqual(
            snapshots[0].id,
            snapshot.id,
            "Check resource id in list resources call"
        )
        return
    def test_01_test_vm_volume_snapshot(self):
        """
        @Desc: Test that Volume snapshot for root volume is allowed
        when VM snapshot is present for the VM
        @Steps:
        1: Deploy a VM and create a VM snapshot for VM
        2: Try to create snapshot for the root volume of the VM,
        It should not fail
        """

        # Creating Virtual Machine
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )

        VmSnapshot.create(
            self.apiclient,
            virtual_machine.id,
        )

        volumes = Volume.list(self.apiclient,
                              virtualmachineid=virtual_machine.id,
                              type="ROOT",
                              listall=True)

        self.assertEqual(validateList(volumes)[0], PASS,
                "Failed to get root volume of the VM")

        snapshot = Snapshot.create(
            self.apiclient,
            volumes[0].id,
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.debug("Snapshot created: ID - %s" % snapshot.id)
        snapshots = list_snapshots(
            self.apiclient,
            id=snapshot.id
        )
        self.assertEqual(
            validateList(snapshots)[0],
            PASS,
            "Invalid snapshot list"
        )
        self.assertEqual(
            snapshots[0].id,
            snapshot.id,
            "Check resource id in list resources call"
        )
        return
Beispiel #6
0
    def test_01_create_vm_snapshots(self):
        """Test to create VM snapshots
        """
        try:
            # Login to VM and write data to file system
            ssh_client = self.virtual_machine.get_ssh_client()

            cmds = [
                "echo %s > %s/%s" %
                (self.random_data_0, self.test_dir, self.random_data),
                "cat %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)
        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)
        self.assertEqual(self.random_data_0, result[0],
                         "Check the random data has be write into temp file!")

        time.sleep(30)

        MemorySnapshot = False

        vm_snapshot = VmSnapshot.create(self.apiclient,
                                        self.virtual_machine.id,
                                        MemorySnapshot, "TestSnapshot",
                                        "Display Text")
        self.assertEqual(vm_snapshot.state, "Ready",
                         "Check the snapshot of vm is ready!")

        return
Beispiel #7
0
 def create_vm_snapshot(cls, MemorySnapshot, virtual_machine):
     return  VmSnapshot.create(
         cls.testClass.apiclient,
         virtual_machine.id,
         MemorySnapshot,
         "TestSnapshot",
         "Display Text"
     )   
Beispiel #8
0
    def test_02_delete_vm_snapshot_between_reverts(self):
        '''Delete VM snapshot after revert of one vm snapshot '''
        self.virtual_machine.stop(self.apiclient, forced=True)

        try:
            cfg.logger.info("revert vm snapshot created with UUID")

            VmSnapshot.revertToSnapshot(self.apiclient, self.vm_snapshot1.id)
        except Exception as e:
            cfg.logger.info(e)

        self.virtual_machine.start(self.apiclient)
        time.sleep(20)

        try:
            ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)

            cmds = ["cat %s/%s" % (self.test_dir, self.random_data)]

            for c in cmds:
                result = ssh_client.execute(c)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        self.assertEqual(
            self.random_data_vm_snapshot1, result[0],
            "Check the random data is equal with the ramdom file!")
        cfg.logger.info("Data before taking a snapshot %s \n\
        Data after revert of snapshot %s" %
                        (self.random_data_vm_snapshot1, result[0]))

        vm_snapshot_glid = VmSnapshot.create(self.apiclient,
                                             self.virtual_machine.id, False,
                                             "TestSnapshot", "Display Text")

        deleted_vm = VmSnapshot.deleteVMSnapshot(
            self.apiclient, vmsnapshotid=vm_snapshot_glid.id)
        self.assertTrue(deleted_vm,
                        "The virtual machine snapshot was not deleted")
        deleted_vm2 = VmSnapshot.deleteVMSnapshot(
            self.apiclient, vmsnapshotid=self.vm_snapshot_for_delete.id)
        self.assertTrue(deleted_vm2, "VM snapshot was not deleted")
    def test_01_check_revert_snapshot(self):
        """ Test revert snapshot on XenServer

        # 1. Deploy a VM.
        # 2. Take VM snapshot.
        # 3. Verify that volume snapshot fails with error 
                can not create volume snapshot for VM with VM-snapshot

        """
        # Step 1
        vm = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )
        volumes_cluster_list = list_volumes(
                self.apiclient,
                virtualmachineid=vm.id,
                type='ROOT',
                listall=True
                )

        volume_list_validation = validateList(volumes_cluster_list)

	self.assertEqual(
                volume_list_validation[0],
                PASS,
                "Event list validation failed due to %s" %
		volume_list_validation[2]
            )
 
        root_volume = volumes_cluster_list[0]
        
        #Step 2
        vm_snap = VmSnapshot.create(self.apiclient,
                vm.id)

	self.assertEqual(
			vm_snap.state,
			"Ready",
			"Check the snapshot of vm is ready!"
			)


        #Step 3
        with self.assertRaises(Exception):
            Snapshot.create(
                    self.apiclient,
                    root_volume.id)

        return
    def test_03_create_vm_snapshot_vc_policy_tag(self):
        """Test to create VM snapshots
        """
        volume_attached = self.virtual_machine.attach_volume(
            self.apiclient, self.volume)

        volumes = list_volumes(self.apiclient,
                               virtualmachineid=self.virtual_machine.id,
                               listall=True)
        vm = list_virtual_machines(self.apiclient,
                                   id=self.virtual_machine.id,
                                   listall=True)
        vm_tags = vm[0].tags
        self.debug(
            '######################### test_03_create_vm_snapshot_vc-policy_tag tags ######################### '
        )

        self.vc_policy_tags(volumes, vm_tags, vm)

        self.assertEqual(volume_attached.id, self.volume.id,
                         "Is not the same volume ")
        try:
            # Login to VM and write data to file system
            ssh_client = self.virtual_machine.get_ssh_client()

            cmds = [
                "echo %s > %s/%s" %
                (self.random_data_0, self.test_dir, self.random_data), "sync",
                "sleep 1", "sync", "sleep 1",
                "cat %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)
        self.assertEqual(self.random_data_0, result[0],
                         "Check the random data has be write into temp file!")

        time.sleep(30)
        MemorySnapshot = False
        vm_snapshot = VmSnapshot.create(self.apiclient,
                                        self.virtual_machine.id,
                                        MemorySnapshot, "TestSnapshot",
                                        "Display Text")
        self.assertEqual(vm_snapshot.state, "Ready",
                         "Check the snapshot of vm is ready!")

        return
    def test_01_test_vm_volume_snapshot(self):
        """
        @Desc: Test that Volume snapshot for root volume is not allowed
        when VM snapshot is present for the VM
        @Steps:
        1: Deploy a VM and create a VM snapshot for VM
        2: Try to create snapshot for the root volume of the VM,
        It should expect Exception
        """

        # Creating Virtual Machine
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )

        VmSnapshot.create(
            self.apiclient,
            virtual_machine.id,
        )

        volumes = Volume.list(self.apiclient,
                              virtualmachineid=virtual_machine.id,
                              type="ROOT",
                              listall=True)

        self.assertEqual(
            validateList(volumes)[0], PASS,
            "Failed to get root volume of the VM")

        volume = volumes[0]

        with self.assertRaises(Exception):
            Snapshot.create(self.apiclient, volume_id=volume.id)

        return
    def test_01_test_vm_volume_snapshot(self):
        """
        @Desc: Test that Volume snapshot for root volume is not allowed
        when VM snapshot is present for the VM
        @Steps:
        1: Deploy a VM and create a VM snapshot for VM
        2: Try to create snapshot for the root volume of the VM,
        It should expect Exception
        """

        # Creating Virtual Machine
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )

        VmSnapshot.create(
            self.apiclient,
            virtual_machine.id,
        )

        volumes = Volume.list(self.apiclient,
                              virtualmachineid=virtual_machine.id,
                              type="ROOT",
                              listall=True)

        self.assertEqual(validateList(volumes)[0], PASS,
                "Failed to get root volume of the VM")

        volume = volumes[0]

        with self.assertRaises(Exception):
            Snapshot.create(self.apiclient,
                            volume_id=volume.id)

        return
    def test_01_create_vm_snapshots(self):
        """Test to create VM snapshots
        """

        try:
            # Login to VM and write data to file system
            ssh_client = self.virtual_machine.get_ssh_client()

            cmds = [
                "echo %s > %s/%s" %
                (self.random_data_0, self.test_dir, self.random_data),
                "cat %s/%s" %
                (self.test_dir, self.random_data)]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)
        self.assertEqual(
            self.random_data_0,
            result[0],
            "Check the random data has be write into temp file!"
        )

        time.sleep(self.services["sleep"])

        #KVM VM Snapshot needs to set snapshot with memory
        MemorySnapshot = False
        if self.hypervisor.lower() in (KVM.lower()):
           MemorySnapshot = True

        vm_snapshot = VmSnapshot.create(
            self.apiclient,
            self.virtual_machine.id,
            MemorySnapshot,
            "TestSnapshot",
            "Display Text"
        )
        self.assertEqual(
            vm_snapshot.state,
            "Ready",
            "Check the snapshot of vm is ready!"
        )

        return
Beispiel #14
0
    def test_01_check_revert_snapshot(self):
        """ Test revert snapshot on XenServer

        # 1. Deploy a VM.
        # 2. Take VM snapshot.
        # 3. Verify that volume snapshot fails with error 
                can not create volume snapshot for VM with VM-snapshot

        """
        # Step 1
        vm = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )
        volumes_cluster_list = list_volumes(self.apiclient,
                                            virtualmachineid=vm.id,
                                            type='ROOT',
                                            listall=True)

        volume_list_validation = validateList(volumes_cluster_list)

        self.assertEqual(
            volume_list_validation[0], PASS,
            "Event list validation failed due to %s" %
            volume_list_validation[2])

        root_volume = volumes_cluster_list[0]

        #Step 2
        vm_snap = VmSnapshot.create(self.apiclient, vm.id)

        self.assertEqual(vm_snap.state, "Ready",
                         "Check the snapshot of vm is ready!")

        #Step 3
        with self.assertRaises(Exception):
            Snapshot.create(self.apiclient, root_volume.id)

        return
Beispiel #15
0
    def delete_random_data_after_vmsnpashot(cls, vm_snapshot, virtual_machine, test_dir , random_data):
        cfg.logger.info('delete_random_data_after_vmsnpashot')
        assert_equal(
            vm_snapshot.state,
            "Ready",
            "Check the snapshot of vm is ready!"
        )

        try:
            ssh_client = virtual_machine.get_ssh_client(reconnect = True)
     
            cmds = [
                "rm -rf %s/%s" % (test_dir, random_data),
                "ls %s/%s" % (test_dir, random_data)
            ]
     
            for c in cmds:
                result = ssh_client.execute(c)
     
        except Exception:
            cls.testClass.fail("SSH failed for Virtual machine: %s" %
                      virtual_machine.ipaddress)
     
        if str(result[0]).index("No such file or directory") == -1:
            cls.testClass.fail("Check the random data has be delete from temp file!")
     
        time.sleep(30)
     
        list_snapshot_response = VmSnapshot.list(
            cls.testClass.apiclient,
            virtualmachineid=virtual_machine.id,
            listall=True)
     
        assert_equal(
            isinstance(list_snapshot_response, list),
            True,
            "Check list response returns a valid list"
        )
        assert_not_equal(
            list_snapshot_response,
            None,
            "Check if snapshot exists in ListSnapshot"
        )
    def test_04_check_vm_snapshot_creation_after_Instance_creation(self):
        """
        @summary: Test  if Snapshot creation is successful
        after VM deployment
        CLOUDSTACK-8830 : VM snapshot creation fails for 12 min

        Step1: Create a VM with any Service offering
        Step2: Create a VM snapshot
        Step3: Verify is VM SS creation is failed
        """

        if self.hypervisor.lower() not in ['vmware']:
            self.skipTest(
                "This test case is only for vmware. Hence, skipping the test")
        vm = VirtualMachine.create(self.userapiclient,
                                   self.services["virtual_machine"],
                                   accountid=self.account.name,
                                   domainid=self.account.domainid,
                                   serviceofferingid=self.service_offering.id,
                                   templateid=self.template.id,
                                   zoneid=self.zone.id)

        snapshot_created_1 = VmSnapshot.create(self.userapiclient, vm.id)
        self.assertIsNotNone(snapshot_created_1, "VM Snapshot creation failed")
Beispiel #17
0
    def test_03_revert_vm_snapshot(self):
        ''' Revert few vm snapshots'''

        # revert vm snapshot created with globalid
        self.virtual_machine.stop(self.apiclient, forced=True)
        global vm_snapshot_glId
        global random_data_vm_snapshot_glid

        try:
            cfg.logger.info("revert vm snapshot created with globalid")
            VmSnapshot.revertToSnapshot(self.apiclient, vm_snapshot_glId.id)
        except Exception as e:
            cfg.logger.info(e)

        self.virtual_machine.start(self.apiclient)
        time.sleep(20)

        try:
            ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)

            cmds = ["cat %s/%s" % (self.test_dir, self.random_data)]

            for c in cmds:
                result = ssh_client.execute(c)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        self.assertEqual(
            random_data_vm_snapshot_glid, result[0],
            "Check the random data is equal with the ramdom file!")
        cfg.logger.info("Data before taking a snapshot %s \n\
        Data after revert of snapshot %s" %
                        (random_data_vm_snapshot_glid, result[0]))
        # revert second snapshot
        self.virtual_machine.stop(self.apiclient, forced=True)

        try:
            cfg.logger.info("revert vm snapshot created with UUID")

            VmSnapshot.revertToSnapshot(self.apiclient, self.vm_snapshot2.id)
        except Exception as e:
            cfg.logger.info(e)

        self.virtual_machine.start(self.apiclient)
        time.sleep(20)

        try:
            ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)

            cmds = ["cat %s/%s" % (self.test_dir, self.random_data)]

            for c in cmds:
                result = ssh_client.execute(c)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        self.assertEqual(
            self.random_data_vm_snapshot2, result[0],
            "Check the random data is equal with the ramdom file!")
        cfg.logger.info("Data before taking a snapshot %s \n\
        Data after revert of snapshot %s" %
                        (self.random_data_vm_snapshot2, result[0]))
Beispiel #18
0
    def test_02_revert_vm_snapshots(self):
        """Test to revert VM snapshots
        """

        try:
            ssh_client = self.virtual_machine.get_ssh_client()

            cmds = [
                "rm -rf %s/%s" % (self.test_dir, self.random_data),
                "ls %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        if str(result[0]).index("No such file or directory") == -1:
            self.fail("Check the random data has be delete from temp file!")

        time.sleep(30)

        list_snapshot_response = VmSnapshot.list(
            self.apiclient,
            virtualmachineid=self.virtual_machine.id,
            listall=True)

        self.assertEqual(isinstance(list_snapshot_response, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(list_snapshot_response, None,
                            "Check if snapshot exists in ListSnapshot")

        self.assertEqual(list_snapshot_response[0].state, "Ready",
                         "Check the snapshot of vm is ready!")

        self.virtual_machine.stop(self.apiclient)

        VmSnapshot.revertToSnapshot(self.apiclient,
                                    list_snapshot_response[0].id)

        self.virtual_machine.start(self.apiclient)

        try:
            ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)

            cmds = ["cat %s/%s" % (self.test_dir, self.random_data)]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        self.assertEqual(
            self.random_data_0, result[0],
            "Check the random data is equal with the ramdom file!")
Beispiel #19
0
    def test_08_create_vm_snpashot(self):
        '''Test Create virtual machine snapshot with attached disk created with globalid'''

        volume = Volume.create(
            self.apiclient,
            {"diskname": "StorPoolDisk-GlId"},
            zoneid=self.zone.id,
            diskofferingid=self.disk_offering.id,
        )
        self._cleanup.append(volume)

        self.virtual_machine3.attach_volume(self.apiclient, volume)
        #attached disk created with globalid
        list = list_volumes(self.apiclient,
                            virtualmachineid=self.virtual_machine3.id,
                            id=volume.id)
        volume = list[0]
        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
        except spapi.ApiError as err:
            cfg.logger.info(err)
            raise Exception(err)

        random_data_vm_snapshot = random_gen(size=100)

        self.helper.write_on_disks(random_data_vm_snapshot,
                                   self.virtual_machine3, self.test_dir,
                                   self.random_data)

        MemorySnapshot = False
        vm_snapshot = self.helper.create_vm_snapshot(MemorySnapshot,
                                                     self.virtual_machine3)
        self.helper.delete_random_data_after_vmsnpashot(
            vm_snapshot, self.virtual_machine3, self.test_dir,
            self.random_data)

        self.virtual_machine3.stop(self.apiclient, forced=True)

        try:
            cfg.logger.info("revert vm snapshot created with globalId")

            VmSnapshot.revertToSnapshot(self.apiclient, vm_snapshot.id)
        except Exception as e:
            cfg.logger.info(e)

        self.virtual_machine3.start(self.apiclient)
        time.sleep(20)

        try:
            ssh_client = self.virtual_machine3.get_ssh_client(reconnect=True)

            cmds = ["cat %s/%s" % (self.test_dir, self.random_data)]

            for c in cmds:
                result = ssh_client.execute(c)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine3.ipaddress)

        self.assertEqual(
            random_data_vm_snapshot, result[0],
            "Check the random data is equal with the ramdom file!")
        cfg.logger.info("Data before taking a snapshot %s \n\
        Data after revert of snapshot %s" %
                        (random_data_vm_snapshot, result[0]))
    def test_02_take_VM_snapshot_with_data_disk(self):
        self.virtual_machine.start(self.apiClient)

        data_volume = Volume.create(
            self.apiClient,
            self.testdata[TestData.volume_1],
            account=self.account.name,
            domainid=self.domain.id,
            zoneid=self.zone.id,
            diskofferingid=self.disk_offering.id
        )

        self.cleanup = [data_volume]

        self.virtual_machine.attach_volume(self.apiClient, data_volume)

        root_volumes = list_volumes(self.apiClient, type="ROOT", listAll="true")

        self._check_list(root_volumes, 1, TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        root_volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(root_volume_id)
        sf_iscsi_root_volume_name = sf_iscsi_name_result['apivolumeiscsiname']['volumeiScsiName']

        self._check_iscsi_name(sf_iscsi_root_volume_name)

        root_volume_path_1 = self._get_path(root_volume_id)

        data_volumes = list_volumes(self.apiClient, type="DATADISK", listAll="true")

        self._check_list(data_volumes, 1, "There should only be one data volume.")

        data_volume = data_volumes[0]

        data_volume_id = {'volumeid': data_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(data_volume_id)
        sf_iscsi_data_volume_name = sf_iscsi_name_result['apivolumeiscsiname']['volumeiScsiName']

        self._check_iscsi_name(sf_iscsi_data_volume_name)

        data_volume_path_1 = self._get_path(data_volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(
            self.apiClient,
            vmid=self.virtual_machine.id,
            snapshotmemory="false",
            name="Test Snapshot",
            description="Test Snapshot Desc"
        )

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(root_volume_id)

        self.assertEqual(
            root_volume_path_1,
            root_volume_path_2,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        data_volume_path_2 = self._get_path(data_volume_id)

        self.assertEqual(
            data_volume_path_1,
            data_volume_path_2,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        root_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_root_volume_name)[0]

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(root_volume_xen_sr)

        self._check_list(root_volume_xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_create = self._get_vdis(root_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(root_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            root_volume_vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        data_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_data_volume_name)[0]

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(data_volume_xen_sr)

        self._check_list(data_volume_xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_create = self._get_vdis(data_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(data_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            data_volume_vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._check_list(list_vm_snapshots, 1, TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(root_volume_id)

        self.assertNotEqual(
            root_volume_path_1,
            root_volume_path_3,
            TestVMSnapshots._path_should_have_changed_err_msg
        )

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(root_volume_xen_sr)

        self._check_list(root_volume_xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_revert = self._get_vdis(root_volume_xen_vdis)

        self.assertNotEqual(
            root_volume_vdis_after_create.active_vdi["uuid"],
            root_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg
        )

        self.assertEqual(
            root_volume_vdis_after_create.snapshot_vdi["uuid"],
            root_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg
        )

        self.assertEqual(
            root_volume_vdis_after_create.base_vdi["uuid"],
            root_volume_vdis_after_revert.base_vdi["uuid"],
            TestVMSnapshots._base_vdis_should_be_the_same_err_msg
        )

        data_volume_path_3 = self._get_path(data_volume_id)

        self.assertNotEqual(
            data_volume_path_1,
            data_volume_path_3,
            TestVMSnapshots._path_should_have_changed_err_msg
        )

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(data_volume_xen_sr)

        self._check_list(data_volume_xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_revert = self._get_vdis(data_volume_xen_vdis)

        self.assertNotEqual(
            data_volume_vdis_after_create.active_vdi["uuid"],
            data_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg
        )

        self.assertEqual(
            data_volume_vdis_after_create.snapshot_vdi["uuid"],
            data_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg
        )

        self.assertEqual(
            data_volume_vdis_after_create.base_vdi["uuid"],
            data_volume_vdis_after_revert.base_vdi["uuid"],
            TestVMSnapshots._base_vdis_should_be_the_same_err_msg
        )

        #######################################
        #######################################
        ##### STEP 3: Delete VM snapshot  #####
        #######################################
        #######################################
        VmSnapshot.deleteVMSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self.assertEqual(
            list_vm_snapshots,
            None,
            TestVMSnapshots._should_be_no_vm_snapshots_err_msg
        )

        root_volume_path_4 = self._get_path(root_volume_id)

        self.assertEqual(
            root_volume_path_3,
            root_volume_path_4,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(root_volume_xen_sr)

        self._check_list(root_volume_xen_vdis, 1, TestVMSnapshots._should_only_be_one_vdi_err_msg)

        root_volume_vdis_after_delete = self._get_vdis(root_volume_xen_vdis, True)

        self.assertEqual(
            root_volume_vdis_after_revert.active_vdi["uuid"],
            root_volume_vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg
        )

        data_volume_path_4 = self._get_path(data_volume_id)

        self.assertEqual(
            data_volume_path_3,
            data_volume_path_4,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(data_volume_xen_sr)

        self._check_list(data_volume_xen_vdis, 1, TestVMSnapshots._should_only_be_one_vdi_err_msg)

        data_volume_vdis_after_delete = self._get_vdis(data_volume_xen_vdis, True)

        self.assertEqual(
            data_volume_vdis_after_revert.active_vdi["uuid"],
            data_volume_vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg
        )

        #######################################
        #######################################
        #####      STEP 4: Start VM       #####
        #######################################
        #######################################
        self.virtual_machine.detach_volume(self.apiClient, data_volume)

        self.virtual_machine.start(self.apiClient)
    def test_01_take_VM_snapshot(self):
        self.virtual_machine.start(self.apiClient)

        root_volumes = list_volumes(self.apiClient, type="ROOT", listAll="true")

        self._check_list(root_volumes, 1, TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(volume_id)
        sf_iscsi_name = sf_iscsi_name_result['apivolumeiscsiname']['volumeiScsiName']

        self._check_iscsi_name(sf_iscsi_name)

        root_volume_path_1 = self._get_path(volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(
            self.apiClient,
            vmid=self.virtual_machine.id,
            snapshotmemory="false",
            name="Test Snapshot",
            description="Test Snapshot Desc"
        )

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(volume_id)

        self.assertEqual(
            root_volume_path_1,
            root_volume_path_2,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_name)[0]

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        self._check_list(xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_create = self._get_vdis(xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._check_list(list_vm_snapshots, 1, TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(volume_id)

        self.assertNotEqual(
            root_volume_path_1,
            root_volume_path_3,
            TestVMSnapshots._path_should_have_changed_err_msg
        )

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        self._check_list(xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_revert = self._get_vdis(xen_vdis)

        self.assertNotEqual(
            vdis_after_create.active_vdi["uuid"],
            vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg
        )

        self.assertEqual(
            vdis_after_create.snapshot_vdi["uuid"],
            vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg
        )

        self.assertEqual(
            vdis_after_create.base_vdi["uuid"],
            vdis_after_revert.base_vdi["uuid"],
            TestVMSnapshots._base_vdis_should_be_the_same_err_msg
        )

        #######################################
        #######################################
        ##### STEP 3: Delete VM snapshot  #####
        #######################################
        #######################################
        VmSnapshot.deleteVMSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self.assertEqual(
            list_vm_snapshots,
            None,
            TestVMSnapshots._should_be_no_vm_snapshots_err_msg
        )

        root_volume_path_4 = self._get_path(volume_id)

        self.assertEqual(
            root_volume_path_3,
            root_volume_path_4,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        self._check_list(xen_vdis, 1, TestVMSnapshots._should_only_be_one_vdi_err_msg)

        vdis_after_delete = self._get_vdis(xen_vdis, True)

        self.assertEqual(
            vdis_after_revert.active_vdi["uuid"],
            vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg
        )

        #######################################
        #######################################
        #####      STEP 4: Start VM       #####
        #######################################
        #######################################
        self.virtual_machine.start(self.apiClient)
    def test_change_service_offering_for_vm_with_snapshots(self):
        """Test to change service offering for instances with vm snapshots
        """
        
        # 1) Create Virtual Machine using service offering 1
        self.debug("Creating VM using Service Offering 1")
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["small"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            templateid=self.template.id,
            zoneid=self.zone.id,
            hypervisor=self.hypervisor,
            mode=self.zone.networktype,
            serviceofferingid=self.service_offering_1.id
        )
        
        # Verify Service OFfering 1 CPU cores and memory
        try:
            ssh_client = virtual_machine.get_ssh_client(reconnect=True)
            self.checkCPUAndMemory(ssh_client, self.service_offering_1)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" % (virtual_machine.ipaddress, e))
        
        # 2) Take VM Snapshot
        self.debug("Taking VM Snapshot for VM - ID: %s" % virtual_machine.id)
        vm_snapshot = VmSnapshot.create(
            self.apiclient,
            virtual_machine.id,
        )
        
        # 3) Stop Virtual Machine
        self.debug("Stopping VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)
        
        # 4) Change service offering for VM with snapshots from Service Offering 1 to Service Offering 2
        self.debug("Changing service offering from Service Offering 1 to Service Offering 2 for VM - ID: %s" % virtual_machine.id)
        virtual_machine.change_service_offering(self.apiclient, self.service_offering_2.id)
        
        # 5) Start VM
        self.debug("Starting VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start virtual machine: %s, %s" % (virtual_machine.name, e))
        
        # Wait for vm to start
        timeout = self.wait_vm_start(self.apiclient, virtual_machine.id, self.services["timeout"],
                            self.services["sleep"])
        if timeout == 0:
            self.fail("The virtual machine %s failed to start even after %s minutes"
                   % (virtual_machine.name, self.services["timeout"]))
        
        list_vm_response = list_virtual_machines(
            self.apiclient,
            id=virtual_machine.id
        )
        self.assertEqual(
            isinstance(list_vm_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            len(list_vm_response),
            0,
            "Check VM avaliable in List Virtual Machines"
        )
        self.assertEqual(
            list_vm_response[0].state,
            "Running",
            "Check virtual machine is in running state"
        )
        self.assertEqual(
            list_vm_response[0].id,
            virtual_machine.id,
            "Check virtual machine id"
        )
        
        # 6) Verify service offering has changed
        try:
            ssh_client_2 = virtual_machine.get_ssh_client(reconnect=True)
            self.checkCPUAndMemory(ssh_client_2, self.service_offering_2)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" % (virtual_machine.ipaddress, e))
        
        # 7) Stop Virtual Machine
        self.debug("Stopping VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        time.sleep(30)
        # 8) Revert to VM Snapshot
        self.debug("Revert to vm snapshot: %s" % vm_snapshot.id)
        try:
            VmSnapshot.revertToSnapshot(
                self.apiclient,
                vm_snapshot.id
            )
        except Exception as e:
            self.fail("Failed to revert to VM Snapshot: %s - %s" % (vm_snapshot.id, e))
        
        # 9) Start VM
        self.debug("Starting VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start virtual machine: %s, %s" % (virtual_machine.name, e))
            
        # 10) Verify service offering has changed to Service Offering 1 (from VM Snapshot)
        try:
            ssh_client_3 = virtual_machine.get_ssh_client(reconnect=True)
            self.checkCPUAndMemory(ssh_client_3, self.service_offering_1)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" % (virtual_machine.ipaddress, e))
        
        return
Beispiel #23
0
    def test_03_list_vm_snapshots_pagination(self):
        """
        @Desc: Test to List VM Snapshots pagination
        @Steps:
        Step1: Listing all the VM snapshots for a user
        Step2: Verifying that list size is 0
        Step3: Creating (page size + 1) number of VM snapshots
        Step4: Listing all the VM snapshots again for a user
        Step5: Verifying that list size is (page size + 1)
        Step6: Listing all the VM snapshots in page1
        Step7: Verifying that list size is (page size)
        Step8: Listing all the VM snapshots in page2
        Step9: Verifying that list size is 1
        Step10: Deleting the VM snapshot present in page 2
        Step11: Listing all the volume snapshots in page2
        Step12: Verifying that list size is 0
        """
        if self.hypervisor.lower() in ['kvm', 'hyperv']:
            raise unittest.SkipTest("This feature is not supported on existing hypervisor. Hence, skipping the test")
        # Listing all the VM snapshots for a User
        list_vm_snaps_before = VmSnapshot.list(
                                               self.userapiclient,
                                               listall=self.services["listall"]
                                               )
        # Verifying list size is 0
        self.assertIsNone(
                          list_vm_snaps_before,
                          "VM snapshots exists for newly created user"
                          )
        # Creating pagesize + 1 number of VM snapshots
        for i in range(0, (self.services["pagesize"] + 1)):
            snapshot_created = VmSnapshot.create(
                                                 self.userapiclient,
                                                 self.virtual_machine.id,
                                                 )
            self.assertIsNotNone(
                                 snapshot_created,
                                 "Snapshot creation failed"
                                 )

        # Listing all the VM snapshots for user again
        list_vm_snaps_after = VmSnapshot.list(
                                              self.userapiclient,
                                              listall=self.services["listall"]
                                              )
        status = validateList(list_vm_snaps_after)
        self.assertEquals(
                          PASS,
                          status[0],
                          "VM snapshot creation failed"
                          )
        # Verifying that list size is pagesize + 1
        self.assertEquals(
                          self.services["pagesize"] + 1,
                          len(list_vm_snaps_after),
                          "Failed to create pagesize + 1 number of VM snapshots"
                          )
        # Listing all the VM snapshots in page 1
        list_vm_snaps_page1 = VmSnapshot.list(
                                              self.userapiclient,
                                              listall=self.services["listall"],
                                              page=1,
                                              pagesize=self.services["pagesize"]
                                              )
        status = validateList(list_vm_snaps_page1)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Failed to list vm snapshots in page 1"
                          )
        # Verifying the list size to be equal to pagesize
        self.assertEquals(
                          self.services["pagesize"],
                          len(list_vm_snaps_page1),
                          "Size of vm snapshots in page 1 is not matching"
                          )
        # Listing all the vm snapshots in page 2
        list_vm_snaps_page2 = VmSnapshot.list(
                                              self.userapiclient,
                                              listall=self.services["listall"],
                                              page=2,
                                              pagesize=self.services["pagesize"]
                                              )
        status = validateList(list_vm_snaps_page2)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Failed to list vm snapshots in page 2"
                          )
        # Verifying the list size to be equal to pagesize
        self.assertEquals(
                          1,
                          len(list_vm_snaps_page2),
                          "Size of vm snapshots in page 2 is not matching"
                          )
        # Deleting the vm snapshot present in page 2
        VmSnapshot.deleteVMSnapshot(
                                    self.userapiclient,
                                    snapshot_created.id
                                    )
        # Listing all the snapshots in page 2 again
        list_vm_snaps_page2 = VmSnapshot.list(
                                              self.userapiclient,
                                              listall=self.services["listall"],
                                              page=2,
                                              pagesize=self.services["pagesize"]
                                              )
        # Verifying that list size is 0
        self.assertIsNone(
                          list_vm_snaps_page2,
                          "VM snapshot not deleted from page 2"
                          )
        # Deleting all the existing VM snapshots
        list_vm_snaps = VmSnapshot.list(
                                         self.userapiclient,
                                         listall=self.services["listall"],
                                         )
        status = validateList(list_vm_snaps)
        self.assertEquals(
                          PASS,
                          status[0],
                          "All VM snapshots deleted"
                          )
        # Verifying that list size is equal to page size
        self.assertEquals(
                          self.services["pagesize"],
                          len(list_vm_snaps),
                          "VM Snapshots count is not matching"
                          )
        # Deleting all the existing VM snapshots
        for i in range(0, len(list_vm_snaps)):
            VmSnapshot.deleteVMSnapshot(
                                    self.userapiclient,
                                    list_vm_snaps[i].id
                                    )
        return
    def test_02_check_hypervisor_vm_snapshot(self):
        """ Test hypervisor vmsnapshotenabled effect

        # 1. Set vmsnapshotenabled to false for hypervisor
        # 2. List capabilities and verify value
        # 3. Deploy a VM
        # 4. Try VM snapshot, it should fail
        # 5. Set vmsnapshotenabled to true for hypervisor
        # 6. Try VM snapshot again, it should succeed
        """
        if self.hypervisor == "KVM":
            self.skipTest(
                "Skipping test: Reason -  VM Snapshot of running VM is not supported for KVM"
            )
        self.updateHostHypervisorCapability(self.hostCapability.id, None,
                                            False)
        capabilities = self.listHostHypervisorCapabilities(
            self.hostCapability.id)
        self.assertTrue(
            isinstance(capabilities, list),
            "listHypervisorCapabilities response not a valid list")
        self.assertEqual(len(capabilities), 1,
                         "listHypervisorCapabilities response not valid")
        self.assertEqual(
            capabilities[0].vmsnapshotenabled, False,
            "listHypervisorCapabilities response vmsnapshotenabled value not False"
        )

        Host.update(self.apiclient, id=self.host.id, hosttags="host1")
        vm = VirtualMachine.create(self.userapiclient,
                                   self.services["small"],
                                   templateid=self.template.id,
                                   accountid=self.account.name,
                                   domainid=self.account.domainid,
                                   serviceofferingid=self.service_offering.id,
                                   zoneid=self.zone.id)
        self.cleanup.append(vm)

        try:
            fail_snapshot = VmSnapshot.create(self.userapiclient,
                                              vmid=vm.id,
                                              snapshotmemory="false",
                                              name="Test Snapshot",
                                              description="Test Snapshot Desc")
            self.cleanup.append(fail_snapshot)
            self.fail(
                "Successful to take VM snapshot even when vmsnapshotenabled was set to False"
            )
        except Exception as e:
            self.debug(
                "Failed to take VM snapshot even vmsnapshotenabled was set to False: %s"
                % e)

        self.updateHostHypervisorCapability(self.hostCapability.id, None, True)

        vm_snapshot = VmSnapshot.create(self.userapiclient,
                                        vmid=vm.id,
                                        snapshotmemory="false",
                                        name="Test Snapshot",
                                        description="Test Snapshot Desc")
        self.cleanup.append(vm_snapshot)
    def test_02_revert_vm_snapshots(self):
        """Test to revert VM snapshots
        """

        try:
            ssh_client = self.virtual_machine.get_ssh_client()

            cmds = [
                "rm -rf %s/%s" % (self.test_dir, self.random_data),
                "ls %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        if str(result[0]).index("No such file or directory") == -1:
            self.fail("Check the random data has be delete from temp file!")

        time.sleep(self.services["sleep"])

        list_snapshot_response = VmSnapshot.list(self.apiclient, vmid=self.virtual_machine.id, listall=True)

        self.assertEqual(
            isinstance(list_snapshot_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            list_snapshot_response,
            None,
            "Check if snapshot exists in ListSnapshot"
        )

        self.assertEqual(
            list_snapshot_response[0].state,
            "Ready",
            "Check the snapshot of vm is ready!"
        )

        VmSnapshot.revertToSnapshot(self.apiclient, list_snapshot_response[0].id)

        list_vm_response = list_virtual_machines(
            self.apiclient,
            id=self.virtual_machine.id
        )

        self.assertEqual(
            list_vm_response[0].state,
            "Stopped",
            "Check the state of vm is Stopped!"
        )

        cmd = startVirtualMachine.startVirtualMachineCmd()
        cmd.id = list_vm_response[0].id
        self.apiclient.startVirtualMachine(cmd)

        time.sleep(self.services["sleep"])

        try:
            ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)

            cmds = [
                "cat %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        self.assertEqual(
            self.random_data_0,
            result[0],
            "Check the random data is equal with the ramdom file!"
        )
Beispiel #26
0
    def test_01_take_VM_snapshot(self):
        self.virtual_machine.start(self.apiClient)

        root_volumes = list_volumes(self.apiClient,
                                    type="ROOT",
                                    listAll="true")

        sf_util.check_list(
            root_volumes, 1, self,
            TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(volume_id)
        sf_iscsi_name = sf_iscsi_name_result['apivolumeiscsiname'][
            'volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_name, self)

        root_volume_path_1 = self._get_path(volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(self.apiClient,
                                        vmid=self.virtual_machine.id,
                                        snapshotmemory="false",
                                        name="Test Snapshot",
                                        description="Test Snapshot Desc")

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(volume_id)

        self.assertEqual(root_volume_path_1, root_volume_path_2,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_name)[0]

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_create = self._get_vdis(xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(
            vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(vdiSnapshotOf["uuid"],
                         vdis_after_create.active_vdi["uuid"],
                         TestVMSnapshots._snapshot_parent_not_correct_err_msg)

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient,
                                    vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        sf_util.check_list(
            list_vm_snapshots, 1, self,
            TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(volume_id)

        self.assertNotEqual(root_volume_path_1, root_volume_path_3,
                            TestVMSnapshots._path_should_have_changed_err_msg)

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_revert = self._get_vdis(xen_vdis)

        self.assertNotEqual(
            vdis_after_create.active_vdi["uuid"],
            vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg)

        self.assertEqual(
            vdis_after_create.snapshot_vdi["uuid"],
            vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg)

        self.assertEqual(vdis_after_create.base_vdi["uuid"],
                         vdis_after_revert.base_vdi["uuid"],
                         TestVMSnapshots._base_vdis_should_be_the_same_err_msg)

        #######################################
        #######################################
        ##### STEP 3: Delete VM snapshot  #####
        #######################################
        #######################################
        VmSnapshot.deleteVMSnapshot(self.apiClient,
                                    vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self.assertEqual(list_vm_snapshots, None,
                         TestVMSnapshots._should_be_no_vm_snapshots_err_msg)

        root_volume_path_4 = self._get_path(volume_id)

        self.assertEqual(root_volume_path_3, root_volume_path_4,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        sf_util.check_list(xen_vdis, 1, self,
                           TestVMSnapshots._should_only_be_one_vdi_err_msg)

        vdis_after_delete = self._get_vdis(xen_vdis, True)

        self.assertEqual(
            vdis_after_revert.active_vdi["uuid"],
            vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg)

        #######################################
        #######################################
        #####      STEP 4: Start VM       #####
        #######################################
        #######################################
        self.virtual_machine.start(self.apiClient)
Beispiel #27
0
    def test_04_list_vm_snapshots_byid(self):
        """
        @summary: Test to List VM Snapshots by Id

        Step1: Listing all the VM snapshots for a user
        Step2: Verifying that list size is 0
        Step3: Creating a VM snapshot
        Step4: Listing all the VM snapshots again for a user
        Step5: Verifying that list size is 1
        Step6: Listing all the VM snapshots by specifying snapshot id
        Step7: Verifying that list size is 1
        Step8: Verifying details of the listed VM snapshot
        """
        if self.hypervisor.lower() in ['kvm', 'hyperv']:
            raise unittest.SkipTest("This feature is not supported on existing hypervisor. Hence, skipping the test")
        # Listing all the VM snapshots for a User
        list_vm_snaps_before = VmSnapshot.list(
                                               self.userapiclient,
                                               listall=self.services["listall"]
                                               )
        # Verifying list size is 0
        self.assertIsNone(
                          list_vm_snaps_before,
                          "VM snapshots exists for newly created user"
                          )
        # Creating a VM snapshot
        snapshot_created = VmSnapshot.create(
                                             self.userapiclient,
                                             self.virtual_machine.id,
                                             )
        self.assertIsNotNone(
                             snapshot_created,
                             "Snapshot creation failed"
                             )
        # Listing all the VM snapshots for user again
        list_vm_snaps_after = VmSnapshot.list(
                                              self.userapiclient,
                                              listall=self.services["listall"]
                                              )
        status = validateList(list_vm_snaps_after)
        self.assertEquals(
                          PASS,
                          status[0],
                          "VM snapshot creation failed"
                          )
        # Verifying that list size is 1
        self.assertEquals(
                          1,
                          len(list_vm_snaps_after),
                          "Failed to create VM snapshot"
                          )
        # Listing vm snapshot by id
        list_vm_snapshot = VmSnapshot.list(
                                           self.userapiclient,
                                           listall=self.services["listall"],
                                           vmsnapshotid=snapshot_created.id
                                          )
        status = validateList(list_vm_snapshot)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Failed to list VM snapshot by Id"
                          )
        # Verifying that list size is 1
        self.assertEquals(
                          1,
                          len(list_vm_snapshot),
                          "Size of the list vm snapshot by Id is not matching"
                          )
        # Verifying details of the listed snapshot to be same as snapshot created above
        # Creating expected and actual values dictionaries
        expected_dict = {
                         "id":snapshot_created.id,
                         "name":snapshot_created.name,
                         "state":snapshot_created.state,
                         "vmid":snapshot_created.virtualmachineid,
                         }
        actual_dict = {
                       "id":list_vm_snapshot[0].id,
                       "name":list_vm_snapshot[0].name,
                       "state":list_vm_snapshot[0].state,
                       "vmid":list_vm_snapshot[0].virtualmachineid,
                       }
        vm_snapshot_status = self.__verify_values(
                                                  expected_dict,
                                                  actual_dict
                                                  )
        self.assertEqual(
                         True,
                         vm_snapshot_status,
                         "Listed VM Snapshot details are not as expected"
                         )
        return
Beispiel #28
0
    def test_02_take_VM_snapshot_with_data_disk(self):
        self.virtual_machine.start(self.apiClient)

        data_volume = Volume.create(self.apiClient,
                                    self.testdata[TestData.volume_1],
                                    account=self.account.name,
                                    domainid=self.domain.id,
                                    zoneid=self.zone.id,
                                    diskofferingid=self.disk_offering.id)

        self.cleanup = [data_volume]

        self.virtual_machine.attach_volume(self.apiClient, data_volume)

        root_volumes = list_volumes(self.apiClient,
                                    type="ROOT",
                                    listAll="true")

        sf_util.check_list(
            root_volumes, 1, self,
            TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        root_volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(root_volume_id)
        sf_iscsi_root_volume_name = sf_iscsi_name_result['apivolumeiscsiname'][
            'volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_root_volume_name, self)

        root_volume_path_1 = self._get_path(root_volume_id)

        data_volumes = list_volumes(self.apiClient,
                                    type="DATADISK",
                                    listAll="true")

        sf_util.check_list(data_volumes, 1, self,
                           "There should only be one data volume.")

        data_volume = data_volumes[0]

        data_volume_id = {'volumeid': data_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(data_volume_id)
        sf_iscsi_data_volume_name = sf_iscsi_name_result['apivolumeiscsiname'][
            'volumeiScsiName']

        sf_util.check_iscsi_name(sf_iscsi_data_volume_name, self)

        data_volume_path_1 = self._get_path(data_volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(self.apiClient,
                                        vmid=self.virtual_machine.id,
                                        snapshotmemory="false",
                                        name="Test Snapshot",
                                        description="Test Snapshot Desc")

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(root_volume_id)

        self.assertEqual(root_volume_path_1, root_volume_path_2,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        data_volume_path_2 = self._get_path(data_volume_id)

        self.assertEqual(data_volume_path_1, data_volume_path_2,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        root_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(
            sf_iscsi_root_volume_name)[0]

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_create = self._get_vdis(root_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(
            root_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(vdiSnapshotOf["uuid"],
                         root_volume_vdis_after_create.active_vdi["uuid"],
                         TestVMSnapshots._snapshot_parent_not_correct_err_msg)

        data_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(
            sf_iscsi_data_volume_name)[0]

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_create = self._get_vdis(data_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(
            data_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(vdiSnapshotOf["uuid"],
                         data_volume_vdis_after_create.active_vdi["uuid"],
                         TestVMSnapshots._snapshot_parent_not_correct_err_msg)

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient,
                                    vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        sf_util.check_list(
            list_vm_snapshots, 1, self,
            TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(root_volume_id)

        self.assertNotEqual(root_volume_path_1, root_volume_path_3,
                            TestVMSnapshots._path_should_have_changed_err_msg)

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_revert = self._get_vdis(root_volume_xen_vdis)

        self.assertNotEqual(
            root_volume_vdis_after_create.active_vdi["uuid"],
            root_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg)

        self.assertEqual(
            root_volume_vdis_after_create.snapshot_vdi["uuid"],
            root_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg)

        self.assertEqual(root_volume_vdis_after_create.base_vdi["uuid"],
                         root_volume_vdis_after_revert.base_vdi["uuid"],
                         TestVMSnapshots._base_vdis_should_be_the_same_err_msg)

        data_volume_path_3 = self._get_path(data_volume_id)

        self.assertNotEqual(data_volume_path_1, data_volume_path_3,
                            TestVMSnapshots._path_should_have_changed_err_msg)

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 3, self,
                           TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_revert = self._get_vdis(data_volume_xen_vdis)

        self.assertNotEqual(
            data_volume_vdis_after_create.active_vdi["uuid"],
            data_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg)

        self.assertEqual(
            data_volume_vdis_after_create.snapshot_vdi["uuid"],
            data_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg)

        self.assertEqual(data_volume_vdis_after_create.base_vdi["uuid"],
                         data_volume_vdis_after_revert.base_vdi["uuid"],
                         TestVMSnapshots._base_vdis_should_be_the_same_err_msg)

        #######################################
        #######################################
        ##### STEP 3: Delete VM snapshot  #####
        #######################################
        #######################################
        VmSnapshot.deleteVMSnapshot(self.apiClient,
                                    vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self.assertEqual(list_vm_snapshots, None,
                         TestVMSnapshots._should_be_no_vm_snapshots_err_msg)

        root_volume_path_4 = self._get_path(root_volume_id)

        self.assertEqual(root_volume_path_3, root_volume_path_4,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            root_volume_xen_sr)

        sf_util.check_list(root_volume_xen_vdis, 1, self,
                           TestVMSnapshots._should_only_be_one_vdi_err_msg)

        root_volume_vdis_after_delete = self._get_vdis(root_volume_xen_vdis,
                                                       True)

        self.assertEqual(
            root_volume_vdis_after_revert.active_vdi["uuid"],
            root_volume_vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg)

        data_volume_path_4 = self._get_path(data_volume_id)

        self.assertEqual(data_volume_path_3, data_volume_path_4,
                         TestVMSnapshots._path_should_not_have_changed_err_msg)

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(
            data_volume_xen_sr)

        sf_util.check_list(data_volume_xen_vdis, 1, self,
                           TestVMSnapshots._should_only_be_one_vdi_err_msg)

        data_volume_vdis_after_delete = self._get_vdis(data_volume_xen_vdis,
                                                       True)

        self.assertEqual(
            data_volume_vdis_after_revert.active_vdi["uuid"],
            data_volume_vdis_after_delete.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_be_the_same_err_msg)

        #######################################
        #######################################
        #####      STEP 4: Start VM       #####
        #######################################
        #######################################
        self.virtual_machine.detach_volume(self.apiClient, data_volume)

        self.virtual_machine.start(self.apiClient)
    def test_change_service_offering_for_vm_with_snapshots(self):
        """Test to change service offering for instances with vm snapshots
        """

        # 1) Create Virtual Machine using service offering 1
        self.debug("Creating VM using Service Offering 1")
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["small"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            templateid=self.template.id,
            zoneid=self.zone.id,
            hypervisor=self.hypervisor,
            mode=self.zone.networktype,
            serviceofferingid=self.service_offering_1.id)

        # Verify Service OFfering 1 CPU cores and memory
        try:
            ssh_client = virtual_machine.get_ssh_client(reconnect=True)
            self.checkCPUAndMemory(ssh_client, self.service_offering_1)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                      (virtual_machine.ipaddress, e))

        # 2) Take VM Snapshot
        self.debug("Taking VM Snapshot for VM - ID: %s" % virtual_machine.id)
        vm_snapshot = VmSnapshot.create(
            self.apiclient,
            virtual_machine.id,
        )

        # 3) Stop Virtual Machine
        self.debug("Stopping VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.stop(self.apiclient)

            timeout = self.services["timeout"]

            while True:
                time.sleep(self.services["sleep"])

                # Ensure that VM is in stopped state
                list_vm_response = list_virtual_machines(self.apiclient,
                                                         id=virtual_machine.id)

                if isinstance(list_vm_response, list):
                    vm = list_vm_response[0]
                    if vm.state == 'Stopped':
                        self.debug("VM state: %s" % vm.state)
                        break

                if timeout == 0:
                    raise Exception(
                        "Failed to stop VM (ID: %s) in change service offering"
                        % vm.id)

                timeout = timeout - 1
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        # 4) Change service offering for VM with snapshots from Service Offering 1 to Service Offering 2
        self.debug(
            "Changing service offering from Service Offering 1 to Service Offering 2 for VM - ID: %s"
            % virtual_machine.id)
        virtual_machine.change_service_offering(self.apiclient,
                                                self.service_offering_2.id)

        # 5) Start VM
        self.debug("Starting VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start virtual machine: %s, %s" %
                      (virtual_machine.name, e))

        # Wait for vm to start
        timeout = self.wait_vm_start(self.apiclient, virtual_machine.id,
                                     self.services["timeout"],
                                     self.services["sleep"])
        if timeout == 0:
            self.fail(
                "The virtual machine %s failed to start even after %s minutes"
                % (virtual_machine.name, self.services["timeout"]))

        list_vm_response = list_virtual_machines(self.apiclient,
                                                 id=virtual_machine.id)
        self.assertEqual(isinstance(list_vm_response, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(len(list_vm_response), 0,
                            "Check VM avaliable in List Virtual Machines")
        self.assertEqual(list_vm_response[0].state, "Running",
                         "Check virtual machine is in running state")
        self.assertEqual(list_vm_response[0].id, virtual_machine.id,
                         "Check virtual machine id")

        # 6) Verify service offering has changed
        try:
            ssh_client_2 = virtual_machine.get_ssh_client(reconnect=True)
            self.checkCPUAndMemory(ssh_client_2, self.service_offering_2)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                      (virtual_machine.ipaddress, e))

        # 7) Stop Virtual Machine
        self.debug("Stopping VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        time.sleep(30)
        # 8) Revert to VM Snapshot
        self.debug("Revert to vm snapshot: %s" % vm_snapshot.id)
        try:
            VmSnapshot.revertToSnapshot(self.apiclient, vm_snapshot.id)
        except Exception as e:
            self.fail("Failed to revert to VM Snapshot: %s - %s" %
                      (vm_snapshot.id, e))

        # 9) Start VM
        self.debug("Starting VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start virtual machine: %s, %s" %
                      (virtual_machine.name, e))

        # 10) Verify service offering has changed to Service Offering 1 (from VM Snapshot)
        try:
            ssh_client_3 = virtual_machine.get_ssh_client(reconnect=True)
            self.checkCPUAndMemory(ssh_client_3, self.service_offering_1)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                      (virtual_machine.ipaddress, e))

        return