예제 #1
0
    def test_04_create_template_snapshot(self):
        """Test create snapshot and templates from volume

        # Validate the following
        1. Create parent domain with two child sub-domains (and their admin accounts)
        Follow these steps for both the domains
        # 1. Create template from snapshot and verify secondary storage resource count
        # 2. Create Volume from Snapshot and verify primary storage resource count
        # 3. Attach volume to instance which was created from snapshot and
        #    verify primary storage resource count
        # 4. Detach volume from instance which was created from snapshot and
        #    verify the primary storage resource count
        # 5. Delete volume which was created from snapshot and verify primary storage
             resource count"""

        if self.hypervisor.lower() in ['hyperv']:
            self.skipTest("Snapshots feature is not supported on Hyper-V")

        result = self.setupAccounts()
        if result[0] == FAIL:
            self.fail("Failure while setting up accounts and domains: %s" %
                      result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            try:
                apiclient = self.testClient.getUserApiClient(
                    UserName=self.account.name, DomainName=self.account.domain)
                self.assertNotEqual(
                    apiclient, FAILED,
                    "Failed to create api client for account: %s" %
                    self.account.name)

                vm = VirtualMachine.create(
                    apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=self.disk_offering.id,
                    serviceofferingid=self.service_offering.id)

                templatesize = (self.template.size / (1024**3))

                initialResourceCount = expectedCount = templatesize + \
                    self.disk_offering.disksize
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, initialResourceCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                vm.stop(self.apiclient)

                response = createSnapshotFromVirtualMachineVolume(
                    apiclient, self.account, vm.id)
                self.assertEqual(response[0], PASS, response[1])
                snapshot = response[1]

                response = snapshot.validateState(apiclient,
                                                  Snapshot.BACKED_UP)
                self.assertEqual(response[0], PASS, response[1])

                self.services["volume"]["size"] = self.services[
                    "disk_offering"]["disksize"]
                volume = Volume.create_from_snapshot(
                    apiclient,
                    snapshot_id=snapshot.id,
                    services=self.services["volume"],
                    account=self.account.name,
                    domainid=self.account.domainid)
                volumeSize = (volume.size / (1024**3))
                vm.attach_volume(apiclient, volume)
                expectedCount = initialResourceCount + (volumeSize)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                expectedCount -= volumeSize
                vm.detach_volume(apiclient, volume)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                volume.delete(apiclient)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed with exception : %s" % e)
        return
예제 #2
0
    def test_create_template_snapshot(self, value):
        """Test create snapshot and templates from volume

        # Validate the following
        # 1. Deploy VM with custoom disk offering and check the
        #    primary storage resource count
        # 2. Stop the VM and create Snapshot from VM's volume
        # 3. Create volume againt from this snapshto and attach to VM
        # 4. Verify that primary storage count increases by the volume size
        # 5. Detach and delete volume, verify primary storage count decreaes by volume size"""
        if self.hypervisor.lower() in ['hyperv']:
            self.skipTest("Snapshots feature is not supported on Hyper-V")
        response = self.setupAccount(value)
        self.debug(response[0])
        self.debug(response[1])
        self.assertEqual(response[0], PASS, response[1])

        apiclient = self.apiclient
        if value == CHILD_DOMAIN_ADMIN:
            apiclient = self.testClient.getUserApiClient(
                                        UserName=self.account.name,
                                        DomainName=self.account.domain
                                        )
            self.assertNotEqual(apiclient, FAIL, "Failure while getting api\
                    client of account: %s" % self.account.name)

        try:
            self.virtualMachine.stop(apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)
        expectedCount = self.initialResourceCount
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        self.debug("Creating snapshot from ROOT volume: %s" % self.virtualMachine.name)
        snapshot = None
        response = createSnapshotFromVirtualMachineVolume(apiclient, self.account, self.virtualMachine.id)
        self.assertEqual(response[0], PASS, response[1])
        snapshot = response[1]
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            self.services["volume"]["size"] = self.services["disk_offering"]["disksize"]
            volume = Volume.create_from_snapshot(apiclient,
                                        snapshot_id=snapshot.id,
                                        services=self.services["volume"],
                                        account=self.account.name,
                                        domainid=self.account.domainid)

            self.debug("Attaching the volume to vm: %s" % self.virtualMachine.name)
            self.virtualMachine.attach_volume(apiclient, volume)
        except Exception as e:
            self.fail("Failure in volume operation: %s" % e)

        expectedCount += int(self.services["volume"]["size"])
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            self.virtualMachine.detach_volume(apiclient, volume)
        except Exception as e:
            self.fail("Failure in detach volume operation: %s" % e)

        try:
            self.debug("deleting the volume: %s" % volume.name)
            volume.delete(apiclient)
        except Exception as e:
            self.fail("Failure while deleting volume: %s" % e)

        expectedCount -= int(self.services["volume"]["size"])
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_managed_clustered_filesystems_limit(self):
        args = {
            "id": self.testdata[TestData.clusterId2],
            TestData.allocationstate: "Disabled"
        }

        Cluster.update(self.apiClient, **args)

        virtual_machine_names = {"name": "TestVM1", "displayname": "Test VM 1"}

        virtual_machine_1 = self._create_vm(virtual_machine_names)

        list_volumes_response = list_volumes(
            self.apiClient,
            virtualmachineid=virtual_machine_1.id,
            listall=True)

        sf_util.check_list(
            list_volumes_response, 1, self, TestManagedClusteredFilesystems.
            _should_only_be_one_volume_in_list_err_msg)

        vm_1_root_volume = list_volumes_response[0]

        virtual_machine_names = {"name": "TestVM2", "displayname": "Test VM 2"}

        virtual_machine_2 = self._create_vm(virtual_machine_names)

        virtual_machine_names = {"name": "TestVM3", "displayname": "Test VM 3"}

        class VMStartedException(Exception):
            def __init__(self, *args, **kwargs):
                Exception.__init__(self, *args, **kwargs)

        try:
            # The VM should fail to be created as there should be an insufficient number of clustered filesystems
            # remaining in the compute cluster.
            self._create_vm(virtual_machine_names)

            raise VMStartedException("The VM should have failed to start.")
        except VMStartedException:
            raise
        except Exception:
            pass

        vol_snap = Snapshot.create(self.apiClient,
                                   volume_id=vm_1_root_volume.id)

        services = {
            "diskname": "Vol-1",
            "zoneid": self.testdata[TestData.zoneId],
            "ispublic": True
        }

        volume_created_from_snapshot_1 = Volume.create_from_snapshot(
            self.apiClient,
            vol_snap.id,
            services,
            account=self.account.name,
            domainid=self.domain.id)

        class VolumeAttachedException(Exception):
            def __init__(self, *args, **kwargs):
                Exception.__init__(self, *args, **kwargs)

        try:
            # The volume should fail to be attached as there should be an insufficient number of clustered filesystems
            # remaining in the compute cluster.
            virtual_machine_2.attach_volume(self.apiClient,
                                            volume_created_from_snapshot_1)

            raise VolumeAttachedException(
                TestManagedClusteredFilesystems.
                _volume_should_have_failed_to_attach_to_vm)
        except VolumeAttachedException:
            raise
        except Exception:
            pass

        args = {
            "id": self.testdata[TestData.clusterId2],
            TestData.allocationstate: "Enabled"
        }

        Cluster.update(self.apiClient, **args)

        try:
            # The volume should fail to be attached as there should be an insufficient number of clustered filesystems
            # remaining in the compute cluster.
            virtual_machine_2.attach_volume(self.apiClient,
                                            volume_created_from_snapshot_1)

            raise VolumeAttachedException(
                TestManagedClusteredFilesystems.
                _volume_should_have_failed_to_attach_to_vm)
        except VolumeAttachedException:
            raise
        except Exception:
            pass

        virtual_machine_names = {"name": "TestVMA", "displayname": "Test VM A"}

        virtual_machine_a = self._create_vm(virtual_machine_names)

        host_for_vm_1 = list_hosts(self.apiClient,
                                   id=virtual_machine_1.hostid)[0]
        host_for_vm_a = list_hosts(self.apiClient,
                                   id=virtual_machine_a.hostid)[0]

        self.assertTrue(host_for_vm_1.clusterid != host_for_vm_a.clusterid,
                        "VMs 1 and VM a should be in different clusters.")

        virtual_machine_1.delete(self.apiClient, True)

        volume_created_from_snapshot_1 = virtual_machine_2.attach_volume(
            self.apiClient, volume_created_from_snapshot_1)

        virtual_machine_2.detach_volume(self.apiClient,
                                        volume_created_from_snapshot_1)

        volume_created_from_snapshot_1 = virtual_machine_2.attach_volume(
            self.apiClient, volume_created_from_snapshot_1)

        services = {
            "diskname": "Vol-2",
            "zoneid": self.testdata[TestData.zoneId],
            "ispublic": True
        }

        volume_created_from_snapshot_2 = Volume.create_from_snapshot(
            self.apiClient,
            vol_snap.id,
            services,
            account=self.account.name,
            domainid=self.domain.id)

        try:
            # The volume should fail to be attached as there should be an insufficient number of clustered filesystems
            # remaining in the compute cluster.
            virtual_machine_2.attach_volume(self.apiClient,
                                            volume_created_from_snapshot_2)

            raise VolumeAttachedException(
                TestManagedClusteredFilesystems.
                _volume_should_have_failed_to_attach_to_vm)
        except VolumeAttachedException:
            raise
        except Exception:
            pass

        virtual_machine_a.attach_volume(self.apiClient,
                                        volume_created_from_snapshot_2)
예제 #4
0
    def test_06_create_volume_from_non_native_snapshot(self):

        old_supports_resign = self.supports_resign
        self._set_supports_resign(False)

        primary_storage_db_id = self._get_cs_storage_pool_db_id(
            self.primary_storage)

        virtual_machine = VirtualMachine.create(
            self.apiClient,
            self.testdata[TestData.virtualMachine],
            accountid=self.account.name,
            zoneid=self.zone.id,
            serviceofferingid=self.compute_offering.id,
            templateid=self.template.id,
            domainid=self.domain.id,
            startvm=True)

        self.assertEqual(virtual_machine.state.lower(), "running",
                         TestSnapshots._vm_not_in_running_state_err_msg)

        list_volumes_response = list_volumes(
            self.apiClient, virtualmachineid=virtual_machine.id, listall=True)

        self._check_list(
            list_volumes_response, 1,
            TestSnapshots._should_only_be_one_volume_in_list_err_msg)

        vm_1_root_volume = list_volumes_response[0]

        dt_volume_1 = self._get_dt_volume_for_cs_volume(vm_1_root_volume)

        self.assertNotEqual(dt_volume_1, None,
                            TestSnapshots._should_be_a_valid_volume_err)

        vol_snap_a = self._create_and_test_non_native_snapshot(
            vm_1_root_volume.id, primary_storage_db_id, 1,
            TestSnapshots._should_only_be_one_snapshot_in_list_err_msg)

        services = {
            "diskname": "Vol-1",
            "zoneid": self.testdata[TestData.zoneId],
            "size": 100,
            "ispublic": True
        }

        volume_created_from_snapshot = Volume.create_from_snapshot(
            self.apiClient,
            vol_snap_a.id,
            services,
            account=self.account.name,
            domainid=self.domain.id)

        dt_snapshot_volume = self._get_dt_volume_for_cs_volume(
            volume_created_from_snapshot)

        self.assertNotEqual(dt_snapshot_volume, None,
                            TestSnapshots._should_be_a_valid_volume_err)

        volume_created_from_snapshot = virtual_machine.attach_volume(
            self.apiClient, volume_created_from_snapshot)

        self._delete_and_test_non_native_snapshot(vol_snap_a)

        virtual_machine.delete(self.apiClient, True)

        list_volumes_response = list_volumes(self.apiClient, listall=True)

        self._check_list(
            list_volumes_response, 1,
            TestSnapshots._should_only_be_one_volume_in_list_err_msg)

        data_volume = list_volumes_response[0]

        data_volume_2 = Volume(data_volume.__dict__)

        data_volume_2.delete(self.apiClient)

        self._get_dt_volume_for_cs_volume(data_volume, should_exist=False)

        self._set_supports_resign(old_supports_resign)
예제 #5
0
    def test_create_template_snapshot(self, value):
        """Test create snapshot and templates from volume

        # Validate the following
        # 1. Deploy VM with custoom disk offering and check the
        #    primary storage resource count
        # 2. Stop the VM and create Snapshot from VM's volume
        # 3. Create volume againt from this snapshto and attach to VM
        # 4. Verify that primary storage count increases by the volume size
        # 5. Detach and delete volume, verify primary storage count decreaes by volume size"""

        response = self.setupAccount(value)
        self.debug(response[0])
        self.debug(response[1])
        self.assertEqual(response[0], PASS, response[1])

        apiclient = self.apiclient
        if value == CHILD_DOMAIN_ADMIN:
            apiclient = self.testClient.getUserApiClient(
                UserName=self.account.name, DomainName=self.account.domain)
            self.assertNotEqual(
                apiclient, FAIL, "Failure while getting api\
                    client of account: %s" % self.account.name)

        try:
            self.virtualMachine.stop(apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)
        expectedCount = self.initialResourceCount
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        self.debug("Creating snapshot from ROOT volume: %s" %
                   self.virtualMachine.name)
        snapshot = None
        response = createSnapshotFromVirtualMachineVolume(
            apiclient, self.account, self.virtualMachine.id)
        self.assertEqual(response[0], PASS, response[1])
        snapshot = response[1]
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            self.services["volume"]["size"] = self.services["disk_offering"][
                "disksize"]
            volume = Volume.create_from_snapshot(
                apiclient,
                snapshot_id=snapshot.id,
                services=self.services["volume"],
                account=self.account.name,
                domainid=self.account.domainid)

            self.debug("Attaching the volume to vm: %s" %
                       self.virtualMachine.name)
            self.virtualMachine.attach_volume(apiclient, volume)
        except Exception as e:
            self.fail("Failure in volume operation: %s" % e)

        expectedCount += int(self.services["volume"]["size"])
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            self.virtualMachine.detach_volume(apiclient, volume)
        except Exception as e:
            self.fail("Failure in detach volume operation: %s" % e)

        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            self.debug("deleting the volume: %s" % volume.name)
            volume.delete(apiclient)
        except Exception as e:
            self.fail("Failure while deleting volume: %s" % e)

        expectedCount -= int(self.services["volume"]["size"])
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_01_volume_snapshot(self):
        """ Test Volume (root) Snapshot
        # 1. Deploy a VM on primary storage and .
        # 2. Take snapshot on root disk
        # 3. Verify the snapshot's entry in the "snapshots" table 
                and presence of the corresponding 
                snapshot on the Secondary Storage
        # 4. Create Template from the Snapshot and Deploy a 
                VM using the Template
        # 5. Log in to the VM from template and make verify 
                the contents of the ROOT disk matches with the snapshot.
        # 6. Delete Snapshot and Deploy a Linux VM from the 
             Template and verify the successful deployment of the VM.
        # 7. Create multiple snapshots on the same volume and 
                Check the integrity of all the snapshots by creating 
                a template from the snapshot and deploying a Vm from it 
                and delete one of the snapshots
        # 8. Verify that the original checksum matches with the checksum 
                of VM's created from remaning snapshots
        # 9. Make verify the contents of the ROOT disk 
                matches with the snapshot
        # 10.Verify that Snapshot of both DATA and ROOT volume should 
                succeed when snapshot of Data disk of a VM is taken 
                when snapshot of ROOT volume of VM is in progress
        # 11.Create snapshot of data disk and verify the original checksum 
                matches with the volume created from snapshot
        # 12.Verify that volume's state should not change when snapshot of 
                a DATA volume is taken that is attached to a VM
        # 13.Verify that volume's state should not change when snapshot of 
                a DATA volume is taken that is not attached to a VM
        # 14.Verify that create Snapshot with quiescevm=True should succeed
        # 15.revertSnapshot() to revert VM to a specified 
                Volume snapshot for root volume
        """

        # Step 1
        # Get ROOT Volume Id
        root_volumes_cluster_list = list_volumes(self.apiclient,
                                                 virtualmachineid=self.vm_1.id,
                                                 type='ROOT',
                                                 listall=True)

        root_volume_cluster = root_volumes_cluster_list[0]

        disk_volumes_cluster_list = list_volumes(self.apiclient,
                                                 virtualmachineid=self.vm_1.id,
                                                 type='DATADISK',
                                                 listall=True)

        data_disk = disk_volumes_cluster_list[0]

        root_vol_state = root_volume_cluster.state

        ckecksum_random_root_cluster = createChecksum(
            service=self.testdata,
            virtual_machine=self.vm_1,
            disk=root_volume_cluster,
            disk_type="rootdiskdevice")

        self.vm_1.stop(self.apiclient)
        root_vol_snap = Snapshot.create(self.apiclient, root_volume_cluster.id)

        self.assertEqual(root_vol_snap.state, "BackedUp",
                         "Check if the snapshot state is correct ")

        self.assertEqual(root_vol_state, root_volume_cluster.state,
                         "Check if volume state has changed")

        self.vm_1.start(self.apiclient)
        # Step 2
        snapshot_list = list_snapshots(self.apiclient, id=root_vol_snap.id)

        self.assertNotEqual(snapshot_list, None,
                            "Check if result exists in list item call")
        self.assertEqual(snapshot_list[0].id, root_vol_snap.id,
                         "Check resource id in list resources call")

        self.assertTrue(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, root_vol_snap.id))

        events = list_events(self.apiclient,
                             account=self.account.name,
                             domainid=self.account.domainid,
                             type='SNAPSHOT.CREATE')

        event_list_validation_result = validateList(events)

        self.assertEqual(
            event_list_validation_result[0], PASS,
            "event list validation failed due to %s" %
            event_list_validation_result[2])
        self.debug("Events list contains event SNAPSHOT.CREATE")

        qresultset = self.dbclient.execute(
            "select * from event where type='SNAPSHOT.CREATE' AND \
                    description like '%%%s%%' AND state='Completed';" %
            root_volume_cluster.id)

        event_validation_result = validateList(qresultset)

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

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")

        qresult = str(qresultset)
        self.assertEqual(
            qresult.count('SNAPSHOT.CREATE') > 0, True,
            "Check SNAPSHOT.CREATE event in events table")

        #Usage_Event
        qresultset = self.dbclient.execute(
            "select * from usage_event where type='SNAPSHOT.CREATE' AND \
                        resource_name='%s'" % root_vol_snap.name)

        usage_event_validation_result = validateList(qresultset)

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

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")

        self.assertEqual(
            self.dbclient.execute(
                "select size from usage_event where type='SNAPSHOT.CREATE' AND \
            resource_name='%s'" % root_vol_snap.name)[0][0],
            root_vol_snap.physicalsize)

        # Step 3
        # create template from snapshot root_vol_snap
        templateFromSnapshot = Template.create_from_snapshot(
            self.apiclient, root_vol_snap, self.testdata["template_2"])

        self.assertNotEqual(templateFromSnapshot, None,
                            "Check if result exists in list item call")

        vm_from_temp = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=templateFromSnapshot.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype)

        self.assertNotEqual(vm_from_temp, None,
                            "Check if result exists in list item call")

        compareChecksum(self.apiclient,
                        service=self.testdata,
                        original_checksum=ckecksum_random_root_cluster,
                        disk_type="rootdiskdevice",
                        virt_machine=vm_from_temp)
        vm_from_temp.delete(self.apiclient)
        # Step 4
        root_vol_snap.delete(self.userapiclient)

        self.assertEqual(
            list_snapshots(
                self.apiclient,
                volumeid=root_volume_cluster.id,
            ), None, "Snapshot list should be empty")

        events = list_events(self.apiclient,
                             account=self.account.name,
                             domainid=self.account.domainid,
                             type='SNAPSHOT.DELETE')

        event_list_validation_result = validateList(events)

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

        self.debug("Events list contains event SNAPSHOT.DELETE")

        self.debug("select id from account where uuid = '%s';" %
                   self.account.id)

        qresultset = self.dbclient.execute(
            "select id from account where uuid = '%s';" % self.account.id)

        account_validation_result = validateList(qresultset)

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

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = qresultset[0]

        account_id = qresult[0]

        qresultset = self.dbclient.execute(
            "select * from event where type='SNAPSHOT.DELETE' AND \
                    account_id='%s' AND state='Completed';" % account_id)

        delete_snap_validation_result = validateList(qresultset)

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

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")

        qresult = str(qresultset)
        self.assertEqual(
            qresult.count('SNAPSHOT.DELETE') > 0, True,
            "Check SNAPSHOT.DELETE event in events table")

        # Step 5
        # delete snapshot and deploy vm from snapshot
        vm_from_temp_2 = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=templateFromSnapshot.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype)

        self.assertNotEqual(vm_from_temp_2, None,
                            "Check if result exists in list item call")

        # Step 6:
        compareChecksum(self.apiclient,
                        service=self.testdata,
                        original_checksum=ckecksum_random_root_cluster,
                        disk_type="rootdiskdevice",
                        virt_machine=vm_from_temp_2)

        vm_from_temp_2.delete(self.apiclient)
        # Step 7
        # Multiple Snapshots
        self.vm_1.stop(self.apiclient)
        snaps = []
        for i in range(2):

            root_vol_snap = Snapshot.create(self.apiclient,
                                            root_volume_cluster.id)

            self.assertEqual(
                root_vol_snap.state, "BackedUp",
                "Check if the data vol snapshot state is correct ")

            snaps.append(root_vol_snap)

            templateFromSnapshot = Template.create_from_snapshot(
                self.apiclient, root_vol_snap, self.testdata["template_2"])

            self.assertNotEqual(templateFromSnapshot, None,
                                "Check if result exists in list item call")

            vm_from_temp = VirtualMachine.create(
                self.userapiclient,
                self.testdata["small"],
                templateid=templateFromSnapshot.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                zoneid=self.zone.id,
                mode=self.zone.networktype)

            self.assertNotEqual(vm_from_temp, None,
                                "Check if result exists in list item call")

            compareChecksum(self.apiclient,
                            service=self.testdata,
                            original_checksum=ckecksum_random_root_cluster,
                            disk_type="rootdiskdevice",
                            virt_machine=vm_from_temp)
            vm_from_temp.delete(self.apiclient)
            templateFromSnapshot.delete(self.apiclient)

        self.vm_1.start(self.apiclient)

        delete_snap = snaps.pop(1)
        delete_snap.delete(self.apiclient)

        self.assertEqual(Snapshot.list(self.apiclient, id=delete_snap.id),
                         None, "Snapshot list should be empty")

        # Step 8
        for snap in snaps:

            templateFromSnapshot = Template.create_from_snapshot(
                self.apiclient, snap, self.testdata["template_2"])

            self.assertNotEqual(templateFromSnapshot, None,
                                "Check if result exists in list item call")

            vm_from_temp = VirtualMachine.create(
                self.userapiclient,
                self.testdata["small"],
                templateid=templateFromSnapshot.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                zoneid=self.zone.id,
                mode=self.zone.networktype)

            self.assertNotEqual(vm_from_temp, None,
                                "Check if result exists in list item call")

            compareChecksum(self.apiclient,
                            service=self.testdata,
                            original_checksum=ckecksum_random_root_cluster,
                            disk_type="rootdiskdevice",
                            virt_machine=vm_from_temp)

            templateFromSnapshot.delete(self.apiclient)
            vm_from_temp.delete(self.apiclient)

        for snap in snaps:
            snap.delete(self.apiclient)

        # Step 9
        ckecksum_root_cluster = createChecksum(service=self.testdata,
                                               virtual_machine=self.vm_1,
                                               disk=root_volume_cluster,
                                               disk_type="rootdiskdevice")

        self.vm_1.stop(self.apiclient)

        root_vol_snap_2 = Snapshot.create(self.apiclient,
                                          root_volume_cluster.id)

        self.assertEqual(root_vol_snap_2.state, "BackedUp",
                         "Check if the data vol snapshot state is correct ")
        snap_list_validation_result = validateList(events)

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

        self.assertNotEqual(snapshot_list, None,
                            "Check if result exists in list item call")

        templateFromSnapshot = Template.create_from_snapshot(
            self.apiclient, root_vol_snap_2, self.testdata["template_2"])

        self.debug("create template event comlites with template %s name" %
                   templateFromSnapshot.name)

        self.assertNotEqual(templateFromSnapshot, None,
                            "Check if result exists in list item call")

        vm_from_temp_2 = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=templateFromSnapshot.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype)

        self.assertNotEqual(vm_from_temp_2, None,
                            "Check if result exists in list item call")

        compareChecksum(self.apiclient,
                        service=self.testdata,
                        original_checksum=ckecksum_root_cluster,
                        disk_type="rootdiskdevice",
                        virt_machine=vm_from_temp_2)

        vm_from_temp_2.delete(self.apiclient)

        # Step 10
        # Take snapshot of Data disk of a VM , when snapshot of ROOT volume of
        # VM is in progress
        try:
            self.vm_1.stop(self.apiclient)

            t1 = Thread(target=Snapshot.create,
                        args=(self.apiclient, root_volume_cluster.id))

            t2 = Thread(target=Snapshot.create,
                        args=(self.apiclient, data_disk.id))

            t1.start()
            t2.start()
            t1.join()
            t2.join()

        except:
            self.debug("Error: unable to start thread")

        # Step 11
        # Data Disk
        self.vm_1.start(self.apiclient)
        ckecksum_data_disk = createChecksum(service=self.testdata,
                                            virtual_machine=self.vm_1,
                                            disk=data_disk,
                                            disk_type="datadiskdevice_1")

        data_vol_state = data_disk.state

        self.vm_1.stop(self.apiclient)

        data_vol_snap = Snapshot.create(self.apiclient, data_disk.id)

        self.assertEqual(data_vol_snap.state, "BackedUp",
                         "Check if the data vol snapshot state is correct ")

        self.assertEqual(data_vol_state, data_disk.state,
                         "Check if volume state has changed")

        data_snapshot_list = list_snapshots(self.apiclient,
                                            id=data_vol_snap.id)

        self.assertNotEqual(data_snapshot_list, None,
                            "Check if result exists in list item call")
        self.assertEqual(data_snapshot_list[0].id, data_vol_snap.id,
                         "Check resource id in list resources call")

        self.assertTrue(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, data_vol_snap.id))

        events = list_events(self.apiclient,
                             account=self.account.name,
                             domainid=self.account.domainid,
                             type='SNAPSHOT.CREATE')

        event_list_validation_result = validateList(events)

        self.assertEqual(
            event_list_validation_result[0], PASS,
            "event list validation failed due to %s" %
            event_list_validation_result[2])
        self.debug("Events list contains event SNAPSHOT.CREATE")

        self.testdata["volume"]["zoneid"] = self.zone.id
        volumeFromSnap = Volume.create_from_snapshot(
            self.apiclient,
            data_vol_snap.id,
            self.testdata["volume"],
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertTrue(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, data_vol_snap.id))

        new_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,
            mode=self.zone.networktype)

        new_vm.attach_volume(self.apiclient, volumeFromSnap)

        new_vm.reboot(self.apiclient)

        compareChecksum(self.apiclient,
                        service=self.testdata,
                        original_checksum=ckecksum_data_disk,
                        disk_type="datadiskdevice_1",
                        virt_machine=new_vm)

        # Step 12
        data_volume_2 = Volume.create(self.apiclient,
                                      self.testdata["volume"],
                                      zoneid=self.zone.id,
                                      account=self.account.name,
                                      domainid=self.account.domainid,
                                      diskofferingid=self.disk_offering.id)

        self.vm_1.start(self.apiclient)
        self.vm_1.attach_volume(self.userapiclient, data_volume_2)

        self.vm_1.reboot(self.apiclient)
        self.vm_1.stop(self.apiclient)

        data_vol_snap_1 = Snapshot.create(self.apiclient, data_volume_2.id)

        self.assertEqual(data_vol_snap_1.state, "BackedUp",
                         "Check if the snapshot state is correct ")

        data_disk_2_list = Volume.list(self.userapiclient,
                                       listall=self.testdata["listall"],
                                       id=data_volume_2.id)

        self.vm_1.start(self.apiclient)

        checksum_data_2 = createChecksum(service=self.testdata,
                                         virtual_machine=self.vm_1,
                                         disk=data_disk_2_list[0],
                                         disk_type="datadiskdevice_2")

        # Step 13
        self.vm_1.detach_volume(self.apiclient, data_volume_2)

        self.vm_1.reboot(self.apiclient)

        prev_state = data_volume_2.state

        data_vol_snap_2 = Snapshot.create(self.apiclient, data_volume_2.id)

        self.assertEqual(data_vol_snap_2.state, prev_state,
                         "Check if the volume state is correct ")

        data_snapshot_list_2 = list_snapshots(self.apiclient,
                                              id=data_vol_snap_2.id)

        self.assertNotEqual(data_snapshot_list_2, None,
                            "Check if result exists in list item call")

        self.assertEqual(data_snapshot_list_2[0].id, data_vol_snap_2.id,
                         "Check resource id in list resources call")

        self.testdata["volume"]["zoneid"] = self.zone.id
        volumeFromSnap_2 = Volume.create_from_snapshot(
            self.apiclient,
            data_vol_snap_2.id,
            self.testdata["volume"],
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.vm_2.attach_volume(self.userapiclient, volumeFromSnap_2)

        self.vm_2.reboot(self.apiclient)

        data_disk_2_list = Volume.list(self.userapiclient,
                                       listall=self.testdata["listall"],
                                       id=volumeFromSnap_2.id)

        compareChecksum(self.apiclient,
                        service=self.testdata,
                        original_checksum=checksum_data_2,
                        disk_type="datadiskdevice_2",
                        virt_machine=self.vm_2)

        # Step 14
        self.vm_1.stop(self.apiclient)
        with self.assertRaises(Exception):
            root_vol_snap.revertVolToSnapshot(self.apiclient)

        # Step 15
        root_snap = Snapshot.create(self.apiclient, root_volume_cluster.id)

        with self.assertRaises(Exception):
            root_snap.revertVolToSnapshot(self.apiclient)

        return
예제 #7
0
    def test_01_volume_from_snapshot(self):
        """Test Creating snapshot from volume having spaces in name(KVM)
        """
        # Validate the following
        # 1. Create a virtual machine and data volume
        # 2. Attach data volume to VM
        # 3. Login to machine; create temp/test directories on data volume
        #    and write some random data
        # 4. Snapshot the Volume
        # 5. Create another Volume from snapshot
        # 6. Mount/Attach volume to another virtual machine
        # 7. Compare data, data should match

        random_data_0 = random_gen(size=100)
        random_data_1 = random_gen(size=100)

        self.debug("random_data_0 : %s" % random_data_0)
        self.debug("random_data_1: %s" % random_data_1)

        try:
            ssh_client = self.virtual_machine.get_ssh_client()
        except Exception as e:
            self.fail("SSH failed for VM: %s" % self.virtual_machine.ipaddress)

        volume = Volume.create(self.apiclient,
                               self.services["volume"],
                               zoneid=self.zone.id,
                               account=self.account.name,
                               domainid=self.account.domainid,
                               diskofferingid=self.disk_offering.id)
        self.debug("Created volume with ID: %s" % volume.id)
        self.virtual_machine.attach_volume(self.apiclient, volume)
        self.debug("Attach volume: %s to VM: %s" %
                   (volume.id, self.virtual_machine.id))

        self.debug("Formatting volume: %s to ext3" % volume.id)
        # Format partition using ext3
        # Note that this is the second data disk partition of virtual machine
        # as it was already containing data disk before attaching the new
        # volume, Hence datadiskdevice_2
        format_volume_to_ext3(
            ssh_client,
            self.services["volume"][self.hypervisor]["datadiskdevice_2"])
        cmds = [
            "fdisk -l",
            "mkdir -p %s" % self.services["paths"]["mount_dir"],
            "mount -t ext3 %s1 %s" %
            (self.services["volume"][self.hypervisor]["datadiskdevice_2"],
             self.services["paths"]["mount_dir"]),
            "mkdir -p %s/%s/{%s,%s} " %
            (self.services["paths"]["mount_dir"],
             self.services["paths"]["sub_dir"],
             self.services["paths"]["sub_lvl_dir1"],
             self.services["paths"]["sub_lvl_dir2"]),
            "echo %s > %s/%s/%s/%s" %
            (random_data_0, self.services["paths"]["mount_dir"],
             self.services["paths"]["sub_dir"],
             self.services["paths"]["sub_lvl_dir1"],
             self.services["paths"]["random_data"]),
            "echo %s > %s/%s/%s/%s" %
            (random_data_1, self.services["paths"]["mount_dir"],
             self.services["paths"]["sub_dir"],
             self.services["paths"]["sub_lvl_dir2"],
             self.services["paths"]["random_data"]),
            "cat %s/%s/%s/%s" % (self.services["paths"]["mount_dir"],
                                 self.services["paths"]["sub_dir"],
                                 self.services["paths"]["sub_lvl_dir1"],
                                 self.services["paths"]["random_data"])
        ]
        for c in cmds:
            self.debug("Command: %s" % c)
            result = ssh_client.execute(c)
            self.debug(result)

        # Unmount the Sec Storage
        cmds = [
            "umount %s" % (self.services["paths"]["mount_dir"]),
        ]
        for c in cmds:
            self.debug("Command: %s" % c)
            ssh_client.execute(c)

        list_volume_response = Volume.list(
            self.apiclient,
            virtualmachineid=self.virtual_machine.id,
            type='DATADISK',
            id=volume.id)

        self.assertEqual(isinstance(list_volume_response, list), True,
                         "Check list volume response for valid data")
        volume_response = list_volume_response[0]
        # Create snapshot from attached volume
        snapshot = Snapshot.create(self.apiclient,
                                   volume_response.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
        self.debug("Created snapshot: %s" % snapshot.id)
        # Create volume from snapshot
        volume_from_snapshot = Volume.create_from_snapshot(
            self.apiclient,
            snapshot.id,
            self.services["volume"],
            account=self.account.name,
            domainid=self.account.domainid)

        # Detach the volume from virtual machine
        self.virtual_machine.detach_volume(self.apiclient, volume)
        self.debug("Detached volume: %s from VM: %s" %
                   (volume.id, self.virtual_machine.id))

        self.debug("Created Volume: %s from Snapshot: %s" %
                   (volume_from_snapshot.id, snapshot.id))
        volumes = Volume.list(self.apiclient, id=volume_from_snapshot.id)
        self.assertEqual(isinstance(volumes, list), True,
                         "Check list response returns a valid list")

        self.assertNotEqual(len(volumes), None, "Check Volume list Length")
        self.assertEqual(volumes[0].id, volume_from_snapshot.id,
                         "Check Volume in the List Volumes")
        # Attaching volume to new VM
        new_virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["server_without_disk"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            mode=self.services["mode"])
        self.debug("Deployed new VM for account: %s" % self.account.name)
        # self.cleanup.append(new_virtual_machine)

        self.debug("Attaching volume: %s to VM: %s" %
                   (volume_from_snapshot.id, new_virtual_machine.id))

        new_virtual_machine.attach_volume(self.apiclient, volume_from_snapshot)

        # Rebooting is required so that newly attached disks are detected
        self.debug("Rebooting : %s" % new_virtual_machine.id)

        new_virtual_machine.reboot(self.apiclient)

        try:
            # Login to VM to verify test directories and files
            ssh = new_virtual_machine.get_ssh_client()

            # Mount datadiskdevice_1 because this is the first data disk of the
            # new virtual machine
            cmds = [
                "fdisk -l",
                "mkdir -p %s" % self.services["paths"]["mount_dir"],
                "mount -t ext3 %s1 %s" %
                (self.services["volume"][self.hypervisor]["datadiskdevice_1"],
                 self.services["paths"]["mount_dir"]),
            ]

            for c in cmds:
                self.debug("Command: %s" % c)
                result = ssh.execute(c)
                self.debug(result)

            returned_data_0 = ssh.execute(
                "cat %s/%s/%s/%s" % (self.services["paths"]["mount_dir"],
                                     self.services["paths"]["sub_dir"],
                                     self.services["paths"]["sub_lvl_dir1"],
                                     self.services["paths"]["random_data"]))
            returned_data_1 = ssh.execute(
                "cat %s/%s/%s/%s" % (self.services["paths"]["mount_dir"],
                                     self.services["paths"]["sub_dir"],
                                     self.services["paths"]["sub_lvl_dir2"],
                                     self.services["paths"]["random_data"]))
        except Exception as e:
            self.fail("SSH access failed for VM: %s, Exception: %s" %
                      (new_virtual_machine.ipaddress, e))

        self.debug("returned_data_0: %s" % returned_data_0[0])
        self.debug("returned_data_1: %s" % returned_data_1[0])

        # Verify returned data
        self.assertEqual(
            random_data_0, returned_data_0[0],
            "Verify newly attached volume contents with existing one")
        self.assertEqual(
            random_data_1, returned_data_1[0],
            "Verify newly attached volume contents with existing one")
        # Unmount the Sec Storage
        cmds = [
            "umount %s" % (self.services["paths"]["mount_dir"]),
        ]
        for c in cmds:
            self.debug("Command: %s" % c)
            ssh_client.execute(c)
        return
    def test_01_volume_snapshot(self):
        """ Test Volume (root) Snapshot
        # 1. Deploy a VM on primary storage and .
        # 2. Take snapshot on root disk
        # 3. Verify the snapshot's entry in the "snapshots" table 
                and presence of the corresponding 
                snapshot on the Secondary Storage
        # 4. Create Template from the Snapshot and Deploy a 
                VM using the Template
        # 5. Log in to the VM from template and make verify 
                the contents of the ROOT disk matches with the snapshot.
        # 6. Delete Snapshot and Deploy a Linux VM from the 
             Template and verify the successful deployment of the VM.
        # 7. Create multiple snapshots on the same volume and 
                Check the integrity of all the snapshots by creating 
                a template from the snapshot and deploying a Vm from it 
                and delete one of the snapshots
        # 8. Verify that the original checksum matches with the checksum 
                of VM's created from remaning snapshots
        # 9. Make verify the contents of the ROOT disk 
                matches with the snapshot
        # 10.Verify that Snapshot of both DATA and ROOT volume should 
                succeed when snapshot of Data disk of a VM is taken 
                when snapshot of ROOT volume of VM is in progress
        # 11.Create snapshot of data disk and verify the original checksum 
                matches with the volume created from snapshot
        # 12.Verify that volume's state should not change when snapshot of 
                a DATA volume is taken that is attached to a VM
        # 13.Verify that volume's state should not change when snapshot of 
                a DATA volume is taken that is not attached to a VM
        # 14.Verify that create Snapshot with quiescevm=True should succeed
        # 15.revertSnapshot() to revert VM to a specified 
                Volume snapshot for root volume
        """

        # Step 1
        # Get ROOT Volume Id
        root_volumes_cluster_list = list_volumes(
            self.apiclient,
            virtualmachineid=self.vm_1.id,
            type='ROOT',
            listall=True
        )

        root_volume_cluster = root_volumes_cluster_list[0]

        disk_volumes_cluster_list = list_volumes(
            self.apiclient,
            virtualmachineid=self.vm_1.id,
            type='DATADISK',
            listall=True
        )

        data_disk = disk_volumes_cluster_list[0]

        root_vol_state = root_volume_cluster.state

        ckecksum_random_root_cluster = createChecksum(
            service=self.testdata,
            virtual_machine=self.vm_1,
            disk=root_volume_cluster,
            disk_type="rootdiskdevice")

        self.vm_1.stop(self.apiclient)
        root_vol_snap = Snapshot.create(
            self.apiclient,
            root_volume_cluster.id)

        self.assertEqual(
            root_vol_snap.state,
            "BackedUp",
            "Check if the snapshot state is correct "
        )

        self.assertEqual(
            root_vol_state,
            root_volume_cluster.state,
            "Check if volume state has changed"
        )

        self.vm_1.start(self.apiclient)
        # Step 2
        snapshot_list = list_snapshots(
            self.apiclient,
            id=root_vol_snap.id
        )

        self.assertNotEqual(
            snapshot_list,
            None,
            "Check if result exists in list item call"
        )
        self.assertEqual(
            snapshot_list[0].id,
            root_vol_snap.id,
            "Check resource id in list resources call"
        )

        self.assertTrue(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                root_vol_snap.id))

        events = list_events(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            type='SNAPSHOT.CREATE')

        event_list_validation_result = validateList(events)

        self.assertEqual(
            event_list_validation_result[0],
            PASS,
            "event list validation failed due to %s" %
            event_list_validation_result[2])
        self.debug("Events list contains event SNAPSHOT.CREATE")

        qresultset = self.dbclient.execute(
            "select * from event where type='SNAPSHOT.CREATE' AND \
                    description like '%%%s%%' AND state='Completed';" %
            root_volume_cluster.id)

        event_validation_result = validateList(qresultset)

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

        self.assertNotEqual(
            len(qresultset),
            0,
            "Check DB Query result set"
        )

        qresult = str(qresultset)
        self.assertEqual(
            qresult.count('SNAPSHOT.CREATE') > 0,
            True,
            "Check SNAPSHOT.CREATE event in events table"
        )

        #Usage_Event
        qresultset = self.dbclient.execute(
                "select * from usage_event where type='SNAPSHOT.CREATE' AND \
                        resource_name='%s'" %
                root_vol_snap.name)

        usage_event_validation_result = validateList(qresultset)

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

        self.assertNotEqual(
               len(qresultset),
               0,
               "Check DB Query result set"
              )

        self.assertEqual(
            self.dbclient.execute("select size from usage_event where type='SNAPSHOT.CREATE' AND \
            resource_name='%s'" %
            root_vol_snap.name)[0][0],
            root_vol_snap.physicalsize)

        # Step 3
        # create template from snapshot root_vol_snap
        templateFromSnapshot = Template.create_from_snapshot(
            self.apiclient,
            root_vol_snap,
            self.testdata["template_2"])

        self.assertNotEqual(
            templateFromSnapshot,
            None,
            "Check if result exists in list item call"
        )

        vm_from_temp = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=templateFromSnapshot.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype
        )

        self.assertNotEqual(
            vm_from_temp,
            None,
            "Check if result exists in list item call"
        )

        compareChecksum(
            self.apiclient,
            service=self.testdata,
            original_checksum=ckecksum_random_root_cluster,
            disk_type="rootdiskdevice",
            virt_machine=vm_from_temp
        )
        vm_from_temp.delete(self.apiclient)
        # Step 4
        root_vol_snap.delete(self.userapiclient)

        self.assertEqual(
            list_snapshots(
                self.apiclient,
                volumeid=root_volume_cluster.id,
            ), None, "Snapshot list should be empty")

        events = list_events(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            type='SNAPSHOT.DELETE')

        event_list_validation_result = validateList(events)

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

        self.debug("Events list contains event SNAPSHOT.DELETE")

        self.debug("select id from account where uuid = '%s';"
                   % self.account.id)

        qresultset = self.dbclient.execute(
            "select id from account where uuid = '%s';"
            % self.account.id
        )

        account_validation_result = validateList(qresultset)

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

        self.assertNotEqual(
            len(qresultset),
            0,
            "Check DB Query result set"
        )
        qresult = qresultset[0]

        account_id = qresult[0]

        qresultset = self.dbclient.execute(
            "select * from event where type='SNAPSHOT.DELETE' AND \
                    account_id='%s' AND state='Completed';" %
            account_id)

        delete_snap_validation_result = validateList(qresultset)

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

        self.assertNotEqual(
            len(qresultset),
            0,
            "Check DB Query result set"
        )

        qresult = str(qresultset)
        self.assertEqual(
            qresult.count('SNAPSHOT.DELETE') > 0,
            True,
            "Check SNAPSHOT.DELETE event in events table"
        )

        # Step 5
        # delete snapshot and deploy vm from snapshot
        vm_from_temp_2 = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=templateFromSnapshot.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype
        )

        self.assertNotEqual(
            vm_from_temp_2,
            None,
            "Check if result exists in list item call"
        )

        # Step 6:
        compareChecksum(
            self.apiclient,
            service=self.testdata,
            original_checksum=ckecksum_random_root_cluster,
            disk_type="rootdiskdevice",
            virt_machine=vm_from_temp_2
        )

        vm_from_temp_2.delete(self.apiclient)
        # Step 7
        # Multiple Snapshots
        self.vm_1.stop(self.apiclient)
        snaps = []
        for i in range(2):

            root_vol_snap = Snapshot.create(
                self.apiclient,
                root_volume_cluster.id)

            self.assertEqual(
                root_vol_snap.state,
                "BackedUp",
                "Check if the data vol snapshot state is correct "
            )

            snaps.append(root_vol_snap)

            templateFromSnapshot = Template.create_from_snapshot(
                self.apiclient,
                root_vol_snap,
                self.testdata["template_2"])

            self.assertNotEqual(
                templateFromSnapshot,
                None,
                "Check if result exists in list item call"
            )

            vm_from_temp = VirtualMachine.create(
                self.apiclient,
                self.testdata["small"],
                templateid=templateFromSnapshot.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                zoneid=self.zone.id,
                mode=self.zone.networktype
            )

            self.assertNotEqual(
                vm_from_temp,
                None,
                "Check if result exists in list item call"
            )

            compareChecksum(
                self.apiclient,
                service=self.testdata,
                original_checksum=ckecksum_random_root_cluster,
                disk_type="rootdiskdevice",
                virt_machine=vm_from_temp
            )
            vm_from_temp.delete(self.apiclient)
            templateFromSnapshot.delete(self.apiclient)

        self.vm_1.start(self.apiclient)

        delete_snap = snaps.pop(1)
        delete_snap.delete(self.apiclient)

        self.assertEqual(
            Snapshot.list(
                self.apiclient,
                id=delete_snap.id
            ), None, "Snapshot list should be empty")

        # Step 8
        for snap in snaps:

            templateFromSnapshot = Template.create_from_snapshot(
                self.apiclient,
                snap,
                self.testdata["template_2"])

            self.assertNotEqual(
                templateFromSnapshot,
                None,
                "Check if result exists in list item call"
            )

            vm_from_temp = VirtualMachine.create(
                self.apiclient,
                self.testdata["small"],
                templateid=templateFromSnapshot.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                zoneid=self.zone.id,
                mode=self.zone.networktype
            )

            self.assertNotEqual(
                vm_from_temp,
                None,
                "Check if result exists in list item call"
            )

            compareChecksum(
                self.apiclient,
                service=self.testdata,
                original_checksum=ckecksum_random_root_cluster,
                disk_type="rootdiskdevice",
                virt_machine=vm_from_temp
            )

            templateFromSnapshot.delete(self.apiclient)
            vm_from_temp.delete(self.apiclient)

        for snap in snaps:
            snap.delete(self.apiclient)

        # Step 9
        ckecksum_root_cluster = createChecksum(
            service=self.testdata,
            virtual_machine=self.vm_1,
            disk=root_volume_cluster,
            disk_type="rootdiskdevice")

        self.vm_1.stop(self.apiclient)

        root_vol_snap_2 = Snapshot.create(
            self.apiclient,
            root_volume_cluster.id)

        self.assertEqual(
            root_vol_snap_2.state,
            "BackedUp",
            "Check if the data vol snapshot state is correct "
        )
        snap_list_validation_result = validateList(events)

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

        self.assertNotEqual(
            snapshot_list,
            None,
            "Check if result exists in list item call"
        )

        templateFromSnapshot = Template.create_from_snapshot(
            self.apiclient,
            root_vol_snap_2,
            self.testdata["template_2"])

        self.debug(
            "create template event comlites with template %s name" %
            templateFromSnapshot.name)

        self.assertNotEqual(
            templateFromSnapshot,
            None,
            "Check if result exists in list item call"
        )

        vm_from_temp_2 = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=templateFromSnapshot.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype
        )

        self.assertNotEqual(
            vm_from_temp_2,
            None,
            "Check if result exists in list item call"
        )

        compareChecksum(
            self.apiclient,
            service=self.testdata,
            original_checksum=ckecksum_root_cluster,
            disk_type="rootdiskdevice",
            virt_machine=vm_from_temp_2
        )

        vm_from_temp_2.delete(self.apiclient)

        # Step 10
        # Take snapshot of Data disk of a VM , when snapshot of ROOT volume of 
        # VM is in progress
        try:
            self.vm_1.stop(self.apiclient)

            t1 = Thread(
                target=Snapshot.create,
                args=(
                    self.apiclient,
                    root_volume_cluster.id
                ))

            t2 = Thread(
                target=Snapshot.create,
                args=(
                    self.apiclient,
                    data_disk.id
                ))

            t1.start()
            t2.start()
            t1.join()
            t2.join()

        except:
            self.debug("Error: unable to start thread")

        # Step 11
        # Data Disk
        self.vm_1.start(self.apiclient)
        ckecksum_data_disk = createChecksum(
            service=self.testdata,
            virtual_machine=self.vm_1,
            disk=data_disk,
            disk_type="datadiskdevice_1")

        data_vol_state = data_disk.state

        self.vm_1.stop(self.apiclient)

        data_vol_snap = Snapshot.create(
            self.apiclient,
            data_disk.id)

        self.assertEqual(
            data_vol_snap.state,
            "BackedUp",
            "Check if the data vol snapshot state is correct "
        )

        self.assertEqual(
            data_vol_state,
            data_disk.state,
            "Check if volume state has changed"
        )

        data_snapshot_list = list_snapshots(
            self.apiclient,
            id=data_vol_snap.id
        )

        self.assertNotEqual(
            data_snapshot_list,
            None,
            "Check if result exists in list item call"
        )
        self.assertEqual(
            data_snapshot_list[0].id,
            data_vol_snap.id,
            "Check resource id in list resources call"
        )

        self.assertTrue(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                data_vol_snap.id))

        events = list_events(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            type='SNAPSHOT.CREATE')

        event_list_validation_result = validateList(events)

        self.assertEqual(
            event_list_validation_result[0],
            PASS,
            "event list validation failed due to %s" %
            event_list_validation_result[2])
        self.debug("Events list contains event SNAPSHOT.CREATE")

        volumeFromSnap = Volume.create_from_snapshot(
            self.apiclient,
            data_vol_snap.id,
            self.testdata["volume"],
            account=self.account.name,
            domainid=self.account.domainid,
            zoneid=self.zone.id
        )

        self.assertTrue(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                data_vol_snap.id))

        new_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,
            mode=self.zone.networktype
        )

        new_vm.attach_volume(
            self.apiclient,
            volumeFromSnap
        )

        new_vm.reboot(self.apiclient)

        compareChecksum(
            self.apiclient,
            service=self.testdata,
            original_checksum=ckecksum_data_disk,
            disk_type="datadiskdevice_1",
            virt_machine=new_vm
        )

        # Step 12
        data_volume_2 = Volume.create(
            self.apiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id
        )

        self.vm_1.start(self.apiclient)
        self.vm_1.attach_volume(
            self.userapiclient,
            data_volume_2
        )

        self.vm_1.reboot(self.apiclient)       
        self.vm_1.stop(self.apiclient)

        data_vol_snap_1 = Snapshot.create(
            self.apiclient,
            data_volume_2.id)

        self.assertEqual(
            data_vol_snap_1.state,
            "BackedUp",
            "Check if the snapshot state is correct "
        )

        data_disk_2_list = Volume.list(
            self.userapiclient,
            listall=self.testdata["listall"],
            id=data_volume_2.id
        )

        self.vm_1.start(self.apiclient)

        checksum_data_2 = createChecksum(
            service=self.testdata,
            virtual_machine=self.vm_1,
            disk=data_disk_2_list[0],
            disk_type="datadiskdevice_2")

        # Step 13
        self.vm_1.detach_volume(self.apiclient,
                           data_volume_2)

        self.vm_1.reboot(self.apiclient)

        prev_state = data_volume_2.state

        data_vol_snap_2 = Snapshot.create(
            self.apiclient,
            data_volume_2.id)

        self.assertEqual(
            data_vol_snap_2.state,
            prev_state,
            "Check if the volume state is correct "
        )

        data_snapshot_list_2 = list_snapshots(
            self.apiclient,
            id=data_vol_snap_2.id
        )

        self.assertNotEqual(
            data_snapshot_list_2,
            None,
            "Check if result exists in list item call"
        )

        self.assertEqual(
            data_snapshot_list_2[0].id,
            data_vol_snap_2.id,
            "Check resource id in list resources call"
        )

        volumeFromSnap_2 = Volume.create_from_snapshot(
            self.apiclient,
            data_vol_snap_2.id,
            self.testdata["volume"],
            account=self.account.name,
            domainid=self.account.domainid,
            zoneid=self.zone.id
        )

        self.vm_2.attach_volume(
            self.userapiclient,
            volumeFromSnap_2
        )

        self.vm_2.reboot(self.apiclient)

        data_disk_2_list = Volume.list(
            self.userapiclient,
            listall=self.testdata["listall"],
            id=volumeFromSnap_2.id
        )

        compareChecksum(
            self.apiclient,
            service=self.testdata,
            original_checksum=checksum_data_2,
            disk_type="datadiskdevice_2",
            virt_machine=self.vm_2
        )

        # Step 14
        self.vm_1.stop(self.apiclient)
        with self.assertRaises(Exception):
            root_vol_snap.revertVolToSnapshot(self.apiclient)

        # Step 15
        root_snap = Snapshot.create(
            self.apiclient,
            root_volume_cluster.id)

        with self.assertRaises(Exception):
            root_snap.revertVolToSnapshot(self.apiclient)

        return
    def test_04_create_template_snapshot(self):
        """Test create snapshot and templates from volume

        # Validate the following
        1. Create parent domain with two child sub-domains (and their admin accounts)
        Follow these steps for both the domains
        # 1. Create template from snapshot and verify secondary storage resource count
        # 2. Create Volume from Snapshot and verify primary storage resource count
        # 3. Attach volume to instance which was created from snapshot and
        #    verify primary storage resource count
        # 4. Detach volume from instance which was created from snapshot and
        #    verify the primary storage resource count
        # 5. Delete volume which was created from snapshot and verify primary storage
             resource count"""

        result = self.setupAccounts()
        if result[0] == FAIL:
            self.fail(
                "Failure while setting up accounts and domains: %s" %
                result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            try:
                apiclient = self.testClient.getUserApiClient(
                    UserName=self.account.name,
                    DomainName=self.account.domain)
                self.assertNotEqual(
                    apiclient,
                    FAILED,
                    "Failed to create api client for account: %s" %
                    self.account.name)

                vm = VirtualMachine.create(
                    apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=self.disk_offering.id,
                    serviceofferingid=self.service_offering.id)

                templatesize = (self.template.size / (1024 ** 3))

                initialResourceCount = expectedCount = templatesize + \
                    self.disk_offering.disksize
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    initialResourceCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                vm.stop(self.apiclient)

                response = createSnapshotFromVirtualMachineVolume(
                    apiclient,
                    self.account,
                    vm.id)
                self.assertEqual(response[0], PASS, response[1])
                snapshot = response[1]

                response = snapshot.validateState(
                    apiclient,
                    Snapshot.BACKED_UP)
                self.assertEqual(response[0], PASS, response[1])

                self.services["volume"]["size"] = self.services[
                    "disk_offering"]["disksize"]
                volume = Volume.create_from_snapshot(
                    apiclient,
                    snapshot_id=snapshot.id,
                    services=self.services["volume"],
                    account=self.account.name,
                    domainid=self.account.domainid)
                volumeSize = (volume.size / (1024 ** 3))
                vm.attach_volume(apiclient, volume)
                expectedCount = initialResourceCount + (volumeSize)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    expectedCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                expectedCount -= volumeSize
                vm.detach_volume(apiclient, volume)
                volume.delete(apiclient)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    expectedCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed with exception : %s" % e)
        return
예제 #10
0
    def test_01_volume_from_snapshot(self):
        """Test Creating snapshot from volume having spaces in name(KVM)
        """
        # Validate the following
        # 1. Create a virtual machine and data volume
        # 2. Attach data volume to VM
        # 3. Login to machine; create temp/test directories on data volume
        #    and write some random data
        # 4. Snapshot the Volume
        # 5. Create another Volume from snapshot
        # 6. Mount/Attach volume to another virtual machine
        # 7. Compare data, data should match

        if self.hypervisor.lower() in ['hyperv']:
            self.skipTest("Snapshots feature is not supported on Hyper-V")

        random_data_0 = random_gen(size=100)
        random_data_1 = random_gen(size=100)

        self.debug("random_data_0 : %s" % random_data_0)
        self.debug("random_data_1: %s" % random_data_1)

        try:
            ssh_client = self.virtual_machine.get_ssh_client()
        except Exception as e:
            self.fail("SSH failed for VM: %s" %
                      self.virtual_machine.ipaddress)

        volume = Volume.create(
            self.apiclient,
            self.services["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id
        )
        self.debug("Created volume with ID: %s" % volume.id)
        self.virtual_machine.attach_volume(
            self.apiclient,
            volume
        )
        self.debug("Attach volume: %s to VM: %s" %
                   (volume.id, self.virtual_machine.id))

        self.debug("Formatting volume: %s to ext3" % volume.id)
        # Format partition using ext3
        # Note that this is the second data disk partition of virtual machine
        # as it was already containing data disk before attaching the new
        # volume, Hence datadiskdevice_2
        format_volume_to_ext3(
            ssh_client,
            self.services["volume"][self.hypervisor]["datadiskdevice_2"]
        )
        cmds = [
            "fdisk -l",
            "mkdir -p %s" %
            self.services["paths"]["mount_dir"],
            "mount -t ext3 %s1 %s" %
            (self.services["volume"][
                self.hypervisor]["datadiskdevice_2"],
                self.services["paths"]["mount_dir"]),
            "mkdir -p %s/%s/{%s,%s} " %
            (self.services["paths"]["mount_dir"],
                self.services["paths"]["sub_dir"],
                self.services["paths"]["sub_lvl_dir1"],
                self.services["paths"]["sub_lvl_dir2"]),
            "echo %s > %s/%s/%s/%s" %
            (random_data_0,
                self.services["paths"]["mount_dir"],
                self.services["paths"]["sub_dir"],
                self.services["paths"]["sub_lvl_dir1"],
                self.services["paths"]["random_data"]),
            "echo %s > %s/%s/%s/%s" %
            (random_data_1,
                self.services["paths"]["mount_dir"],
                self.services["paths"]["sub_dir"],
                self.services["paths"]["sub_lvl_dir2"],
                self.services["paths"]["random_data"]),
            "cat %s/%s/%s/%s" %
            (self.services["paths"]["mount_dir"],
                self.services["paths"]["sub_dir"],
                self.services["paths"]["sub_lvl_dir1"],
                self.services["paths"]["random_data"])]
        for c in cmds:
            self.debug("Command: %s" % c)
            result = ssh_client.execute(c)
            self.debug(result)

        # Unmount the Sec Storage
        cmds = [
            "umount %s" % (self.services["paths"]["mount_dir"]),
        ]
        for c in cmds:
            self.debug("Command: %s" % c)
            ssh_client.execute(c)

        list_volume_response = Volume.list(
            self.apiclient,
            virtualmachineid=self.virtual_machine.id,
            type='DATADISK',
            id=volume.id
        )

        self.assertEqual(
            isinstance(list_volume_response, list),
            True,
            "Check list volume response for valid data"
        )
        volume_response = list_volume_response[0]
        # Create snapshot from attached volume
        snapshot = Snapshot.create(
            self.apiclient,
            volume_response.id,
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.debug("Created snapshot: %s" % snapshot.id)
        # Create volume from snapshot
        volume_from_snapshot = Volume.create_from_snapshot(
            self.apiclient,
            snapshot.id,
            self.services["volume"],
            account=self.account.name,
            domainid=self.account.domainid
        )

        # Detach the volume from virtual machine
        self.virtual_machine.detach_volume(
            self.apiclient,
            volume
        )
        self.debug("Detached volume: %s from VM: %s" %
                   (volume.id, self.virtual_machine.id))

        self.debug("Created Volume: %s from Snapshot: %s" % (
            volume_from_snapshot.id,
            snapshot.id))
        volumes = Volume.list(
            self.apiclient,
            id=volume_from_snapshot.id
        )
        self.assertEqual(
            isinstance(volumes, list),
            True,
            "Check list response returns a valid list"
        )

        self.assertNotEqual(
            len(volumes),
            None,
            "Check Volume list Length"
        )
        self.assertEqual(
            volumes[0].id,
            volume_from_snapshot.id,
            "Check Volume in the List Volumes"
        )
        # Attaching volume to new VM
        new_virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["server_without_disk"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            mode=self.services["mode"]
        )
        self.debug("Deployed new VM for account: %s" % self.account.name)
        # self.cleanup.append(new_virtual_machine)

        self.debug("Attaching volume: %s to VM: %s" % (
            volume_from_snapshot.id,
            new_virtual_machine.id
        ))

        new_virtual_machine.attach_volume(
            self.apiclient,
            volume_from_snapshot
        )

        # Rebooting is required so that newly attached disks are detected
        self.debug("Rebooting : %s" % new_virtual_machine.id)

        new_virtual_machine.reboot(self.apiclient)

        try:
            # Login to VM to verify test directories and files
            ssh = new_virtual_machine.get_ssh_client()

            # Mount datadiskdevice_1 because this is the first data disk of the
            # new virtual machine
            cmds = [
                "fdisk -l",
                "mkdir -p %s" %
                self.services["paths"]["mount_dir"],
                "mount -t ext3 %s1 %s" %
                (self.services["volume"][
                    self.hypervisor]["datadiskdevice_1"],
                    self.services["paths"]["mount_dir"]),
            ]

            for c in cmds:
                self.debug("Command: %s" % c)
                result = ssh.execute(c)
                self.debug(result)

            returned_data_0 = ssh.execute(
                "cat %s/%s/%s/%s" % (
                    self.services["paths"]["mount_dir"],
                    self.services["paths"]["sub_dir"],
                    self.services["paths"]["sub_lvl_dir1"],
                    self.services["paths"]["random_data"]
                ))
            returned_data_1 = ssh.execute(
                "cat %s/%s/%s/%s" % (
                    self.services["paths"]["mount_dir"],
                    self.services["paths"]["sub_dir"],
                    self.services["paths"]["sub_lvl_dir2"],
                    self.services["paths"]["random_data"]
                ))
        except Exception as e:
            self.fail("SSH access failed for VM: %s, Exception: %s" %
                      (new_virtual_machine.ipaddress, e))

        self.debug("returned_data_0: %s" % returned_data_0[0])
        self.debug("returned_data_1: %s" % returned_data_1[0])

        # Verify returned data
        self.assertEqual(
            random_data_0,
            returned_data_0[0],
            "Verify newly attached volume contents with existing one"
        )
        self.assertEqual(
            random_data_1,
            returned_data_1[0],
            "Verify newly attached volume contents with existing one"
        )
        # Unmount the Sec Storage
        cmds = [
            "umount %s" % (self.services["paths"]["mount_dir"]),
        ]
        for c in cmds:
            self.debug("Command: %s" % c)
            ssh_client.execute(c)
        return
def checkIntegrityOfSnapshot(
        self, snapshotsToRestore, checksumToCompare, disk_type=ROOT):
    """
    Check integrity of snapshot created of ROOT or DATA Disk:

    If ROOT Disk: Deploy a Vm from a template created from the snapshot
                  and checking the contents of the ROOT disk.
    If DATA Disk: Users can create a volume from the snapshot.
                  The volume can then be mounted to a VM and files
                  recovered as needed.

    Inputs:
    1. snapshotsToRestore: Snapshots whose integrity is
                           to be checked.

    2. checksumToCompare:  The contents of ROOT Disk to be compared.

    3. disk_type:          The type of disk - ROOT or DATA Disk
                           of which snapshot was created.

    """
    if disk_type == ROOT:
        # Create template from snapshot
        template_from_snapshot = Template.create_from_snapshot(
            self.apiclient,
            snapshotsToRestore,
            self.testdata["template_2"])

        self.assertNotEqual(
            template_from_snapshot,
            None,
            "Check if result exists in list item call"
        )

        # Deploy VM
        vm_from_temp = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=template_from_snapshot.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype
        )

        self.assertNotEqual(
            vm_from_temp,
            None,
            "Check if result exists in list item call"
        )

        # Verify contents of ROOT disk match with snapshot

        compareChecksum(
            self.apiclient,
            service=self.testdata,
            original_checksum=checksumToCompare,
            disk_type="rootdiskdevice",
            virt_machine=vm_from_temp
        )

        vm_from_temp.delete(self.apiclient)
        template_from_snapshot.delete(self.apiclient)
    else:
        volumeFormSnap = Volume.create_from_snapshot(
            self.apiclient,
            snapshotsToRestore.id,
            self.testdata["volume"],
            account=self.account.name,
            domainid=self.account.domainid,
            zoneid=self.zone.id
        )

        temp_vm = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype
        )
        temp_vm.attach_volume(
            self.apiclient,
            volumeFormSnap
        )

        temp_vm.reboot(self.apiclient)

        compareChecksum(
            self.apiclient,
            self.testdata,
            checksumToCompare,
            "datadiskdevice_1",
            temp_vm
        )

        temp_vm.delete(self.apiclient)
        volumeFormSnap.delete(self.apiclient)

    return
예제 #12
0
def checkIntegrityOfSnapshot(self,
                             snapshotsToRestore,
                             checksumToCompare,
                             disk_type=ROOT):
    """
    Check integrity of snapshot created of ROOT or DATA Disk:

    If ROOT Disk: Deploy a Vm from a template created from the snapshot
                  and checking the contents of the ROOT disk.
    If DATA Disk: Users can create a volume from the snapshot.
                  The volume can then be mounted to a VM and files
                  recovered as needed.

    Inputs:
    1. snapshotsToRestore: Snapshots whose integrity is
                           to be checked.

    2. checksumToCompare:  The contents of ROOT Disk to be compared.

    3. disk_type:          The type of disk - ROOT or DATA Disk
                           of which snapshot was created.

    """
    if disk_type == ROOT:
        # Create template from snapshot
        template_from_snapshot = Template.create_from_snapshot(
            self.apiclient, snapshotsToRestore, self.testdata["template_2"])

        self.assertNotEqual(template_from_snapshot, None,
                            "Check if result exists in list item call")

        # Deploy VM
        vm_from_temp = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=template_from_snapshot.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype)

        self.assertNotEqual(vm_from_temp, None,
                            "Check if result exists in list item call")

        # Verify contents of ROOT disk match with snapshot

        compareChecksum(self.apiclient,
                        service=self.testdata,
                        original_checksum=checksumToCompare,
                        disk_type="rootdiskdevice",
                        virt_machine=vm_from_temp)

        vm_from_temp.delete(self.apiclient)
        template_from_snapshot.delete(self.apiclient)
    else:
        volumeFormSnap = Volume.create_from_snapshot(
            self.apiclient,
            snapshotsToRestore.id,
            self.testdata["volume"],
            account=self.account.name,
            domainid=self.account.domainid,
            zoneid=self.zone.id)

        temp_vm = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            mode=self.zone.networktype)
        temp_vm.attach_volume(self.apiclient, volumeFormSnap)

        temp_vm.reboot(self.apiclient)

        compareChecksum(self.apiclient, self.testdata, checksumToCompare,
                        "datadiskdevice_1", temp_vm)

        temp_vm.delete(self.apiclient)
        volumeFormSnap.delete(self.apiclient)

    return