Пример #1
0
    def test_01_verify_events_table(self):
        """ Test events table

        # 1. Deploy a VM.
        # 2. Take VM snapshot.
        # 3. Verify that events table records UUID of the volume in descrption
            instead of volume ID
        """
        # Step 1
        # Create VM
        vm = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )
        volumes_list = list_volumes(self.apiclient,
                                    virtualmachineid=vm.id,
                                    type='ROOT',
                                    listall=True)

        volume_list_validation = validateList(volumes_list)
        self.assertEqual(
            volume_list_validation[0], PASS,
            "volume list validation failed due to %s" %
            volume_list_validation[2])
        root_volume = volumes_list[0]

        # Step 2
        # Create snapshot of root volume
        snapshot = Snapshot.create(self.apiclient, root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        self.assertEqual(snapshot.state, "BackedUp",
                         "Check if snapshot gets created properly")

        # Step 3
        qresultset = self.dbclient.execute(
            "select  description from event where type='SNAPSHOT.CREATE' AND \
                        description like '%%%s%%'" % root_volume.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 if events table records UUID of the volume")

        return
    def test_03_list_snapshots(self):
        """Test listing Snapshots using 'ids' parameter
        """
        list_snapshot_response = Snapshot.list(
                                    self.apiclient,
                                    ids=[self.snapshot_1.id, self.snapshot_2.id, self.snapshot_3.id],
                                    listAll=True
                                    )
        self.assertEqual(
            isinstance(list_snapshot_response, list),
            True,
            "ListSnapshots response was not a valid list"
        )
        self.assertEqual(
            len(list_snapshot_response),
            3,
            "ListSnapshots response expected 3 Snapshots, received %s" % len(list_snapshot_response)
        )

    #PLEASE UNCOMMENT ONCE VM SNAPSHOT DELAY BUG AFTER VM CREATION IS FIXED
    #@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
    #def test_04_list_vm_snapshots(self):
        """Test listing VMSnapshots using 'vmsnapshotids' parameter
        """
        """list_vm_snapshot_response = VmSnapshot.list(
Пример #3
0
 def test_03_list_snapshots(self):
     """Test listing Snapshots using 'ids' parameter
     """
     list_snapshot_response = Snapshot.list(
         self.apiclient,
         ids=[self.snapshot_1.id, self.snapshot_2.id, self.snapshot_3.id],
         listAll=True)
     self.assertEqual(isinstance(list_snapshot_response, list), True,
                      "ListSnapshots response was not a valid list")
     self.assertEqual(
         len(list_snapshot_response), 3,
         "ListSnapshots response expected 3 Snapshots, received %s" %
         len(list_snapshot_response))
Пример #4
0
    def test_02_check_size_snapshotTemplate(self):
        """TS_BUG_010-Test check size of snapshot and template
        """

        # Validate the following
        # 1. Deploy VM using default template, small service offering
        #    and small data disk offering.
        # 2. Perform snapshot on the root disk of this VM.
        # 3. Create a template from snapshot.
        # 4. Check the size of snapshot and template

        # Create a snapshot from the ROOTDISK
        snapshot = Snapshot.create(self.apiclient,
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
        self.debug("Created snapshot with ID: %s" % snapshot.id)
        snapshots = Snapshot.list(self.apiclient, id=snapshot.id)
        self.assertEqual(isinstance(snapshots, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(snapshots, None,
                            "Check if result exists in list snapshots call")
        self.assertEqual(snapshots[0].id, snapshot.id,
                         "Check snapshot id in list resources call")

        # Generate template from the snapshot
        template = Template.create_from_snapshot(self.apiclient, snapshot,
                                                 self.services["template"])
        self.cleanup.append(template)

        self.debug("Created template from snapshot with ID: %s" % template.id)
        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(isinstance(templates, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(templates, None,
                            "Check if result exists in list item call")

        self.assertEqual(templates[0].isready, True,
                         "Check new template state in list templates call")
        # check size of template with that of snapshot
        self.assertEqual(
            templates[0].size, self.volume.size,
            "Derived template size (%s) does not match snapshot size (%s)" %
            (templates[0].size, self.volume.size))
        return
Пример #5
0
def createSnapshotFromVirtualMachineVolume(apiclient, account, vmid):
    """Create snapshot from volume"""

    try:
        volumes = Volume.list(apiclient, account=account.name, domainid=account.domainid, virtualmachineid=vmid)
        validationresult = validateList(volumes)
        assert validateList(volumes)[0] == PASS, "List volumes should return a valid response"
        snapshot = Snapshot.create(apiclient, volume_id=volumes[0].id, account=account.name, domainid=account.domainid)
        snapshots = Snapshot.list(apiclient, id=snapshot.id, listall=True)
        validationresult = validateList(snapshots)
        assert validationresult[0] == PASS, "List snapshot should return a valid list"
    except Exception as e:
        return [FAIL, e]
    return [PASS, snapshot]
Пример #6
0
def createSnapshotFromVirtualMachineVolume(apiclient, account, vmid):
    """Create snapshot from volume"""

    try:
        volumes = Volume.list(apiclient, account=account.name,
                              domainid=account.domainid, virtualmachineid=vmid)
        validationresult = validateList(volumes)
        assert validateList(volumes)[0] == PASS,\
                            "List volumes should return a valid response"
        snapshot = Snapshot.create(apiclient, volume_id=volumes[0].id,
                                   account=account.name, domainid=account.domainid)
        snapshots = Snapshot.list(apiclient, id=snapshot.id,
                                      listall=True)
        validationresult = validateList(snapshots)
        assert validationresult[0] == PASS,\
               "List snapshot should return a valid list"
    except Exception as e:
       return[FAIL, e]
    return [PASS, snapshot]
Пример #7
0
    def test_03_list_snapshots(self):
        """Test listing Snapshots using 'ids' parameter
        """
        list_snapshot_response = Snapshot.list(
            self.apiclient,
            ids=[self.snapshot_1.id, self.snapshot_2.id, self.snapshot_3.id],
            listAll=True)
        self.assertEqual(isinstance(list_snapshot_response, list), True,
                         "ListSnapshots response was not a valid list")
        self.assertEqual(
            len(list_snapshot_response), 3,
            "ListSnapshots response expected 3 Snapshots, received %s" %
            len(list_snapshot_response))

        #PLEASE UNCOMMENT ONCE VM SNAPSHOT DELAY BUG AFTER VM CREATION IS FIXED
        #@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
        #def test_04_list_vm_snapshots(self):
        """Test listing VMSnapshots using 'vmsnapshotids' parameter
        """
        """list_vm_snapshot_response = VmSnapshot.list(
Пример #8
0
    def test_06_create_snapshots_in_project(self):
        """Test create snapshots in project
        """
        # Validate the following
        # 1. Create a project
        # 2. Add some snapshots to the project
        # 3. Verify snapshot created inside project can only be used in inside
        #    the project

        self.debug("Deploying VM for Project: %s" % self.project.id)
        virtual_machine_1 = VirtualMachine.create(
            self.apiclient,
            self.services["server"],
            templateid=self.template.id,
            serviceofferingid=self.service_offering.id,
            projectid=self.project.id,
        )
        self.cleanup.append(virtual_machine_1)
        # Verify VM state
        self.assertEqual(virtual_machine_1.state, "Running", "Check VM state is Running or not")

        # Get the Root disk of VM
        volumes = list_volumes(self.apiclient, projectid=self.project.id, type="ROOT", listall=True)
        self.assertEqual(isinstance(volumes, list), True, "Check for list volume response return valid data")

        self.debug("Creating snapshot from volume: %s" % volumes[0].id)
        # Create a snapshot from the ROOTDISK
        snapshot = Snapshot.create(self.apiclient, volumes[0].id, projectid=self.project.id)
        self.cleanup.append(snapshot)
        # Verify Snapshot state
        self.assertEqual(
            snapshot.state in ["BackedUp", "CreatedOnPrimary", "Allocated"],
            True,
            "Check Snapshot state is in one of the mentioned possible states, \
                                    It is currently: %s"
            % snapshot.state,
        )

        snapshots = Snapshot.list(self.apiclient, account=self.account.name, domainid=self.account.domainid)
        self.assertEqual(snapshots, None, "Snapshots should not be available outside the project")
        return
    def test_02_snapshot_size_check(self):
        """ Check Snapshots size in database
            1. Create file on ROOT disk of deployed VM.
            2. Create Snapshot of ROOT disk.
            3. Check if physiacal_size parameter of snapshot_store_ref table
               has physical size of snapshot
        """
        if self.hypervisor.lower() not in ["xenserver", "vmware"]:
            self.skipTest("Test not to be run on %s" % self.hypervisor)

        root_volumes_list = list_volumes(
            self.apiclient,
            virtualmachineid=self.vm.id,
            type=ROOT,
            listall=True
        )

        status = validateList(root_volumes_list)
        self.assertEqual(
            status[0],
            PASS,
            "Check listVolumes response for ROOT Disk")

        root_volume = root_volumes_list[0]

        # Get Secondary Storage Value from Database
        qryresult_before_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)

        self.assertNotEqual(
            len(qryresult_before_snapshot),
            0,
            "Check sql query to return SecondaryStorageTotal of account")

        storage_qry_result_old = qryresult_before_snapshot[0]
        secondary_storage_old = storage_qry_result_old[2]

        createChecksum(
            self.testdata,
            self.vm,
            root_volume,
            "rootdiskdevice")

        time.sleep(30)

        root_vol_snapshot = Snapshot.create(
            self.apiclient,
            root_volume.id)

        snapshots_list = Snapshot.list(self.apiclient,
                                       id=root_vol_snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Check listSnapshots response")
        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ],
            True,
            "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state
        )

        self.assertEqual(
            snapshots_list[0].volumeid,
            root_volume.id,
            "Snapshot volume id is not matching with the vm's volume id")

        qryresult_snp_id = self.dbclient.execute(
            "select id\
                        from snapshots where uuid = '%s';" %
            snapshots_list[0].id)

        self.assertNotEqual(
            len(qryresult_snp_id),
            0,
            "Check sql query to return physical size of the snapshot")

        snp_id_result = qryresult_snp_id[0]
        snp_id = snp_id_result[0]

        qryresult_physical_size = self.dbclient.execute(
            " select id, store_id, physical_size\
                        from snapshot_store_ref where snapshot_id = '%s' \
                        and store_role='Image';" %
            snp_id)

        self.assertNotEqual(
            len(qryresult_physical_size),
            0,
            "Check sql query to return SecondaryStorageTotal of account")

        snapshot_physical_size_result = qryresult_physical_size[0]
        snapshot_physical_size = snapshot_physical_size_result[
            2]

        # Step 3
        qryresult_after_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)
        self.assertNotEqual(
            len(qryresult_after_snapshot),
            0,
            "Check sql query to return SecondaryStorageTotal of account")

        storage_qry_result_from_database = qryresult_after_snapshot[0]
        secondary_storage_new = storage_qry_result_from_database[
            2]

        secondary_storage_after_snapshot = secondary_storage_new - \
            secondary_storage_old

        self.assertEqual(
            snapshot_physical_size,
            secondary_storage_after_snapshot,
            "Check if physical_size attribute of snapshot_store_ref table \
                stores correct value"
        )

        return
    def test_01_volume_snapshot(self):
        """ Test Volume (root) Snapshot
        # 1. Create Hourly, Daily,Weekly recurring snapshot policy for ROOT disk and
                    Verify the presence of the corresponding snapshots on the Secondary Storage
        # 2. Delete the snapshot policy and verify the entry as Destroyed in snapshot_schedule
        # 3. Verify that maxsnaps should not consider manual snapshots for deletion
        # 4. Snapshot policy should reflect the correct timezone
        # 5. Verify that listSnapshotPolicies() should return all snapshot policies
                that belong to the account (both manual and recurring snapshots)
        # 6. Verify that listSnapshotPolicies() should not return snapshot
                policies that have been deleted
        # 7. Verify that snapshot should not be created for VM in Destroyed state
        # 8. Verify that snapshot should get created after resuming the VM
        # 9. Verify that All the recurring policies associated with the VM should be
                deleted after VM get destroyed.
        """
        # Step 1
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'

        recurring_snapshot = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])
        # ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot.id,
            volumeid=self.volume[0].id)
        list_validation = validateList(list_snapshots_policy)

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

        timeout = self.testdata["timeout"]
        while True:
            snapshots = list_snapshots(
                self.apiclient,
                volumeid=self.volume[0].id,
                intervaltype=self.testdata["recurring_snapshot"]
                ["intervaltype"],
                snapshottype='RECURRING',
                listall=True)

            if isinstance(snapshots, list):
                break

            elif timeout == 0:
                raise Exception("List snapshots API call failed.")

        for snapshot in snapshots:
            self.assertEqual(
                self.dbclient.execute(
                    "select type_description from snapshots where name='%s'" %
                    snapshot.name)[0][0], "HOURLY")

        time.sleep(180)

        for snapshot in snapshots:
            self.assertTrue(
                is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                                   self.zone.id, snapshot.id))

        recurring_snapshot.delete(self.apiclient)

        self.assertEqual(
            self.dbclient.execute(
                "select * from snapshot_policy where uuid='%s'" %
                recurring_snapshot.id), [])

        self.testdata["recurring_snapshot"]["intervaltype"] = 'DAILY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00'
        recurring_snapshot_daily = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        list_snapshots_policy_daily = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_daily.id,
            volumeid=self.volume[0].id)

        list_validation = validateList(list_snapshots_policy_daily)

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

        snap_db_daily = self.dbclient.execute(
            "select * from snapshot_policy where uuid='%s'" %
            recurring_snapshot_daily.id)

        validation_result_1 = validateList(snap_db_daily)

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

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

        recurring_snapshot_daily.delete(self.apiclient)

        self.assertEqual(
            self.dbclient.execute(
                "select * from snapshot_policy where uuid='%s'" %
                recurring_snapshot_daily.id), [])

        self.testdata["recurring_snapshot"]["intervaltype"] = 'WEEKLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_weekly = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        list_snapshots_policy_weekly = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_weekly.id,
            volumeid=self.volume[0].id)

        list_validation = validateList(list_snapshots_policy_weekly)

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

        snap_sch_2 = self.dbclient.execute(
            "select * from snapshot_policy where uuid='%s'" %
            recurring_snapshot_weekly.id)

        validation_result_2 = validateList(snap_sch_2)

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

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

        recurring_snapshot_weekly.delete(self.apiclient)

        self.assertEqual(
            self.dbclient.execute(
                "select * from snapshot_policy where uuid='%s'" %
                recurring_snapshot_weekly.id), [])

        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_monthly = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        list_snapshots_policy_monthly = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_monthly.id,
            volumeid=self.volume[0].id)

        list_validation = validateList(list_snapshots_policy_monthly)

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

        snap_sch_3 = self.dbclient.execute(
            "select * from snapshot_policy where uuid='%s'" %
            recurring_snapshot_monthly.id)

        validation_result = validateList(snap_sch_3)

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

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

        recurring_snapshot_monthly.delete(self.apiclient)

        self.assertEqual(
            self.dbclient.execute(
                "select * from snapshot_policy where uuid='%s'" %
                recurring_snapshot_weekly.id), [])

        snapshots = list_snapshots(
            self.apiclient,
            volumeid=self.volume[0].id,
            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
            snapshottype='RECURRING',
            listall=True)

        # Step 3
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
        self.testdata["recurring_snapshot"]["schedule"] = 1
        recurring_snapshot_1 = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])
        # ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_1.id,
            volumeid=self.volume[0].id)
        list_validation = validateList(list_snapshots_policy)

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

        timeout = self.testdata["timeout"]
        while True:
            snapshots = list_snapshots(
                self.apiclient,
                volumeid=self.volume[0].id,
                intervaltype=self.testdata["recurring_snapshot"]
                ["intervaltype"],
                snapshottype='RECURRING',
                listall=True)

            if isinstance(snapshots, list):
                break

            elif timeout == 0:
                raise Exception("List snapshots API call failed.")

        snap_to_delete = snapshots[0]

        time.sleep((self.testdata["recurring_snapshot"]["maxsnaps"]) * 3600)

        snapshots_1 = list_snapshots(
            self.apiclient,
            volumeid=self.volume[0].id,
            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
            snapshottype='RECURRING',
            listall=True)

        self.assertTrue(snap_to_delete not in snapshots_1)

        time.sleep(360)

        self.assertEqual(
            self.dbclient.execute(
                "select status  from snapshots where uuid='%s'" %
                snap_to_delete.id)[0][0], "Destroyed")

        self.assertFalse(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, snap_to_delete.id))

        # Step 4
        recurring_snapshot = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])
        # ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot.id,
            volumeid=self.volume[0].id)
        list_validation = validateList(list_snapshots_policy)

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

        time.sleep(180)
        snap_time_hourly = self.dbclient.execute(
            "select scheduled_timestamp from \
            snapshot_schedule where uuid='%s'" % recurring_snapshot.id)

        self.debug("Timestamp for hourly snapshot %s" % snap_time_hourly)
        recurring_snapshot.delete(self.apiclient)

        self.testdata["recurring_snapshot"]["intervaltype"] = 'DAILY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00'
        recurring_snapshot_daily = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        list_snapshots_policy_daily = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_daily.id,
            volumeid=self.volume[0].id)

        list_validation = validateList(list_snapshots_policy_daily)

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

        time.sleep(180)
        snap_time_daily = self.dbclient.execute(
            "select scheduled_timestamp from \
                    snapshot_schedule where uuid='%s'" %
            recurring_snapshot_daily.id)

        self.debug("Timestamp for daily snapshot %s" % snap_time_daily)
        recurring_snapshot_daily.delete(self.apiclient)

        self.testdata["recurring_snapshot"]["intervaltype"] = 'WEEKLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_weekly = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        list_snapshots_policy_weekly = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_weekly.id,
            volumeid=self.volume[0].id)

        list_validation = validateList(list_snapshots_policy_weekly)

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

        time.sleep(180)
        snap_time_weekly = self.dbclient.execute(
            "select scheduled_timestamp from \
                    snapshot_schedule where uuid='%s'" %
            recurring_snapshot_weekly.id)

        self.debug("Timestamp for monthly snapshot %s" % snap_time_weekly)
        recurring_snapshot_weekly.delete(self.apiclient)

        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_monthly = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        list_snapshots_policy_monthly = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_monthly.id,
            volumeid=self.volume[0].id)

        list_validation = validateList(list_snapshots_policy_monthly)

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

        time.sleep(180)
        snap_time_monthly = self.dbclient.execute(
            "select scheduled_timestamp from \
                    snapshot_schedule where uuid='%s'" %
            recurring_snapshot_monthly.id)

        self.debug("Timestamp for monthly snapshot %s" % snap_time_monthly)

        recurring_snapshot_monthly.delete(self.apiclient)

        # Step 5
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
        self.testdata["recurring_snapshot"]["schedule"] = 1
        recurring_snapshot_hourly = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])
        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_monthly = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        list_snapshots_policy = list_snapshot_policy(
            self.apiclient, volumeid=self.volume[0].id)

        list_validation = validateList(list_snapshots_policy)

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

        for rec in [recurring_snapshot_hourly, recurring_snapshot_monthly]:
            self.assertTrue(rec.id in any(policy['id'])
                            for policy in list_snapshots_policy)

        recurring_snapshot_hourly.delete(self.apiclient)
        recurring_snapshot_monthly.delete(self.apiclient)

        # Step 6
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
        self.testdata["recurring_snapshot"]["schedule"] = 1
        recurring_snapshot_hourly = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_monthly = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])

        recurring_snapshot_monthly.delete(self.apiclient)

        list_snapshots_policy = list_snapshot_policy(
            self.apiclient, volumeid=self.volume[0].id)

        list_validation = validateList(list_snapshots_policy)

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

        self.assertTrue(recurring_snapshot_hourly.id in any(policy['id'])
                        for policy in list_snapshots_policy)

        self.assertTrue(recurring_snapshot_monthly.id not in any(policy['id'])
                        for policy in list_snapshots_policy)

        # Step 7
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
        self.testdata["recurring_snapshot"]["schedule"] = 1
        recurring_snapshot = SnapshotPolicy.create(
            self.apiclient, self.volume[0].id,
            self.testdata["recurring_snapshot"])
        # ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot.id,
            volumeid=self.volume[0].id)
        list_validation = validateList(list_snapshots_policy)

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

        timeout = self.testdata["timeout"]
        while True:
            snapshots = list_snapshots(
                self.apiclient,
                volumeid=self.volume[0].id,
                intervaltype=self.testdata["recurring_snapshot"]
                ["intervaltype"],
                snapshottype='RECURRING',
                listall=True)

            if isinstance(snapshots, list):
                break

            elif timeout == 0:
                raise Exception("List snapshots API call failed.")

        self.vm_1.delete(self.apiclient, expunge=False)

        time.sleep(3600)
        snapshot_list = Snapshot.list(self.apiclient,
                                      volumeid=self.volume[0].id)

        list_validation = validateList(snapshot_list)

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

        self.assertEqual(
            len(snapshot_list), 1,
            "Verify that snapsot is not created after VM deletion")
        # Step 8
        self.vm_1.recover(self.apiclient)
        time.sleep(3600)

        snapshot_list = Snapshot.list(self.apiclient,
                                      volumeid=self.volume[0].id)

        self.assertEqual(
            len(snapshot_list), 2,
            "Verify that snapsot is not created after VM deletion")
        # Step 9
        self.vm_1.delete(self.apiclient)
        time.sleep(180)
        with self.assertRaises(Exception):
            list_snapshots_policy = list_snapshot_policy(
                self.apiclient, volumeid=self.volume[0].id)
Пример #11
0
    def test_02_list_snapshots_with_removed_data_store(self):
        """Test listing volume snapshots with removed data stores
        """

        # 1) Create new Primary Storage
        clusters = list_clusters(self.apiclient, zoneid=self.zone.id)
        assert isinstance(clusters, list) and len(clusters) > 0

        storage = StoragePool.create(self.apiclient,
                                     self.services["nfs"],
                                     clusterid=clusters[0].id,
                                     zoneid=self.zone.id,
                                     podid=self.pod.id)
        self.assertEqual(storage.state, 'Up', "Check primary storage state")
        self.assertEqual(storage.type, 'NetworkFilesystem',
                         "Check storage pool type")
        storage_pools_response = list_storage_pools(self.apiclient,
                                                    id=storage.id)
        self.assertEqual(isinstance(storage_pools_response, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(len(storage_pools_response), 0,
                            "Check list Hosts response")
        storage_response = storage_pools_response[0]
        self.assertEqual(storage_response.id, storage.id,
                         "Check storage pool ID")
        self.assertEqual(storage.type, storage_response.type,
                         "Check storage pool type ")

        # 2) Migrate VM ROOT volume to new Primary Storage
        volumes = list_volumes(
            self.apiclient,
            virtualmachineid=self.virtual_machine_with_disk.id,
            type='ROOT',
            listall=True)
        Volume.migrate(self.apiclient,
                       storageid=storage.id,
                       volumeid=volumes[0].id,
                       livemigrate="true")

        volume_response = list_volumes(
            self.apiclient,
            id=volumes[0].id,
        )
        self.assertNotEqual(len(volume_response), 0,
                            "Check list Volumes response")
        volume_migrated = volume_response[0]
        self.assertEqual(volume_migrated.storageid, storage.id,
                         "Check volume storage id")
        self.cleanup.append(self.virtual_machine_with_disk)
        self.cleanup.append(storage)

        # 3) Take snapshot of VM ROOT volume
        snapshot = Snapshot.create(self.apiclient,
                                   volume_migrated.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
        self.debug("Snapshot created: ID - %s" % snapshot.id)

        # 4) Delete VM and created Primery Storage
        cleanup_resources(self.apiclient, self.cleanup)

        # 5) List snapshot and verify it gets properly listed although Primary Storage was removed
        snapshot_response = Snapshot.list(self.apiclient, id=snapshot.id)
        self.assertNotEqual(len(snapshot_response), 0,
                            "Check list Snapshot response")
        self.assertEqual(snapshot_response[0].id, snapshot.id,
                         "Check snapshot id")

        # 6) Delete snapshot and verify it gets properly deleted (should not be listed)
        self.cleanup = [snapshot]
        cleanup_resources(self.apiclient, self.cleanup)

        snapshot_response_2 = Snapshot.list(self.apiclient, id=snapshot.id)
        self.assertEqual(snapshot_response_2, None,
                         "Check list Snapshot response")

        return
    def test_01_storage_snapshots_limits(self):
        """ Storage and Snapshot Limit
            1.   Create Snapshot of ROOT disk.
            2.   Verify the Secondary Storage value
                 is increased by the size of snapshot.
            3.   Delete Snaphshot.
            4.   Verify the Secondary
                 Storage value is decreased by the size of snapshot.
            5.   Set the Snapshot limit of Account.
            6.   Create Snasphots till limit is reached.
            7.   Create Snapshot of ROOT Volume.
                 Creation should fail.
            8.   Delete few Snapshots.
            9.   Create Snapshot again.
                 Creation should succeed.
        """

        # Get ROOT Volume
        root_volumes_list = Volume.list(self.userapiclient,
                                        virtualmachineid=self.vm.id,
                                        type='ROOT')

        status = validateList(root_volumes_list)
        self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed")

        root_volume = root_volumes_list[0]

        self.data_volume_created = Volume.create(
            self.userapiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id)

        self.cleanup.append(self.data_volume_created)

        data_volumes_list = Volume.list(self.userapiclient,
                                        id=self.data_volume_created.id)

        status = validateList(data_volumes_list)
        self.assertEqual(status[0], PASS, "DATA Volume List Validation Failed")

        self.data_volume = data_volumes_list[0]

        self.vm.attach_volume(self.userapiclient, self.data_volume)

        # Get Secondary Storage Value from Database
        qryresult_before_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_before_snapshot)
        self.assertEqual(
            status[0], PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageBeforeSnapshot = qryresult_before_snapshot[0][2]

        # Step 1
        snapshot = Snapshot.create(self.userapiclient, root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ], True, "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state)

        # Step 2
        qryresult_after_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_after_snapshot)
        self.assertEqual(
            status[0], PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageAfterSnapshotCreated = qryresult_after_snapshot[0][2]

        snapshot_size = snapshots_list[0].physicalsize
        secStorageIncreased = secStorageBeforeSnapshot + \
            snapshot_size

        self.assertEqual(
            secStorageIncreased, secStorageAfterSnapshotCreated,
            "Secondary storage Total after Snapshot\
                        should be incremented by size of snapshot.")

        # Step 3
        snapshot.delete(self.apiclient)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Step 4
        qryresult_after_snapshot_deleted = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_after_snapshot_deleted)
        self.assertEqual(
            status[0], PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageAfterSnapshotDeleted = qryresult_after_snapshot_deleted[0][2]

        secStorageDecreased = secStorageAfterSnapshotCreated - \
            snapshot_size

        self.assertEqual(
            secStorageDecreased, secStorageAfterSnapshotDeleted,
            "Secondary storage Total after Snapshot\
                        should be incremented by size of snapshot.")

        # Step 5
        # Set Snapshot Limit for account
        Resources.updateLimit(self.apiclient,
                              resourcetype=3,
                              max=1,
                              account=self.account.name,
                              domainid=self.account.domainid)

        # Step 6
        snapshot = Snapshot.create(self.userapiclient, root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ], True, "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state)

        # Step 7
        with self.assertRaises(Exception):
            Snapshot.create(self.userapiclient, self.data_volume.id)

        # Step 8
        snapshot.delete(self.userapiclient)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Step 9
        snapshot = Snapshot.create(self.userapiclient, root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ], True, "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state)

        return
Пример #13
0
 def test_02_list_volume_snapshots_byid(self):
     """
     @Desc: Test to List Volume Snapshots by Id
     @Steps:
     Step1: Listing all the volume snapshots for a user
     Step2: Verifying that list size is 0
     Step3: Creating a volume snapshot
     Step4: Listing all the volume snapshots again for a user
     Step5: Verifying that list size is 1
     Step6: Listing all the volume snapshots by specifying snapshot id
     Step7: Verifying that list size is 1
     Step8: Verifying details of the listed volume snapshot
     """
     if self.hypervisor.lower() in ['hyperv']:
         raise unittest.SkipTest("This feature is not supported on existing hypervisor. Hence, skipping the test")
     # Listing all the volume snapshots for a User
     list_vol_snaps_before = Snapshot.list(
                                           self.userapiclient,
                                           listall=self.services["listall"]
                                           )
     # Verifying list size is 0
     self.assertIsNone(
                       list_vol_snaps_before,
                       "Volume snapshots exists for newly created user"
                       )
     # Listing the root volumes available for the user
     volumes_list = Volume.list(
                                self.userapiclient,
                                listall=self.services["listall"]
                                )
     status = validateList(volumes_list)
     self.assertEquals(
                       PASS,
                       status[0],
                       "Root volume did not get created while deploying a VM"
                       )
     # Verifying list size to be 1
     self.assertEquals(
                       1,
                       len(volumes_list),
                       "More than 1 root volume created for deployed VM"
                       )
     root_volume = volumes_list[0]
     # Creating a volume snapshot
     snapshot_created = Snapshot.create(
                                        self.userapiclient,
                                        root_volume.id,
                                        )
     self.assertIsNotNone(
                          snapshot_created,
                          "Snapshot creation failed"
                          )
     self.cleanup.append(snapshot_created)
     # Listing all the volume snapshots for user again
     list_vol_snaps_after = Snapshot.list(
                                          self.userapiclient,
                                          listall=self.services["listall"]
                                          )
     status = validateList(list_vol_snaps_after)
     self.assertEquals(
                       PASS,
                       status[0],
                       "Volume snapshot creation failed"
                       )
     # Verifying that list size is 1
     self.assertEquals(
                       1,
                       len(list_vol_snaps_after),
                       "Failed to create Volume snapshot"
                       )
     # Listing volume snapshot by id
     list_vol_snapshot = Snapshot.list(
                                       self.userapiclient,
                                       listall=self.services["listall"],
                                       id=snapshot_created.id
                                       )
     status = validateList(list_vol_snapshot)
     self.assertEquals(
                       PASS,
                       status[0],
                       "Failed to list Volume snapshot by Id"
                       )
     # Verifying that list size is 1
     self.assertEquals(
                       1,
                       len(list_vol_snapshot),
                       "Size of the list volume snapshot by Id is not matching"
                       )
     # Verifying details of the listed snapshot to be same as snapshot created above
     # Creating expected and actual values dictionaries
     expected_dict = {
                      "id":snapshot_created.id,
                      "name":snapshot_created.name,
                      "state":snapshot_created.state,
                      "intervaltype":snapshot_created.intervaltype,
                      "account":snapshot_created.account,
                      "domain":snapshot_created.domainid,
                      "volume":snapshot_created.volumeid
                      }
     actual_dict = {
                    "id":list_vol_snapshot[0].id,
                    "name":list_vol_snapshot[0].name,
                    "state":list_vol_snapshot[0].state,
                    "intervaltype":list_vol_snapshot[0].intervaltype,
                    "account":list_vol_snapshot[0].account,
                    "domain":list_vol_snapshot[0].domainid,
                    "volume":list_vol_snapshot[0].volumeid
                    }
     vol_snapshot_status = self.__verify_values(
                                                expected_dict,
                                                actual_dict
                                                )
     self.assertEqual(
                      True,
                      vol_snapshot_status,
                      "Listed Volume Snapshot details are not as expected"
                      )
     return
Пример #14
0
    def test_03_reuse_template_name(self):
        """TS_BUG_011-Test Reusing deleted template name
        """


        # Validate the following
        # 1. Deploy VM using default template, small service offering
        #    and small data disk offering.
        # 2. Perform snapshot on the root disk of this VM.
        # 3. Create a template from snapshot.
        # 4. Delete the template and create a new template with same name
        # 5. Template should be created succesfully

        # Create a snapshot from the ROOTDISK
        snapshot = Snapshot.create(
                                   self.apiclient,
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid
                                   )
        self.debug("Created snapshot with ID: %s" % snapshot.id)
        snapshots = Snapshot.list(
                                   self.apiclient,
                                   id=snapshot.id
                                   )
        self.assertEqual(
                            isinstance(snapshots, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            snapshots,
                            None,
                            "Check if result exists in list snapshots call"
                            )
        self.assertEqual(
                            snapshots[0].id,
                            snapshot.id,
                            "Check snapshot id in list resources call"
                        )

        # Generate template from the snapshot
        template = Template.create_from_snapshot(
                                    self.apiclient,
                                    snapshot,
                                    self.services["template"],
                                    random_name=False
                                    )
        self.debug("Created template from snapshot: %s" % template.id)
        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(
                            isinstance(templates, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            templates,
                            None,
                            "Check if result exists in list item call"
                            )

        self.assertEqual(
                            templates[0].isready,
                            True,
                            "Check new template state in list templates call"
                        )

        self.debug("Deleting template: %s" % template.id)
        template.delete(self.apiclient)

        # Wait for some time to ensure template state is reflected in other calls
        time.sleep(self.services["sleep"])

        # Generate template from the snapshot
        self.debug("Creating template from snapshot: %s with same name" %
                                                                template.id)
        template = Template.create_from_snapshot(
                                    self.apiclient,
                                    snapshot,
                                    self.services["template"],
                                    random_name=False
                                    )

        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(
                            isinstance(templates, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            templates,
                            None,
                            "Check if result exists in list item call"
                            )

        self.assertEqual(
                            templates[0].name,
                            self.services["template"]["name"],
                            "Check the name of the template"
                        )
        return
    def test_01_volume_snapshot(self):
        """ Test Volume (root) Snapshot
        # 1. Create Hourly, Daily,Weekly recurring snapshot policy for ROOT disk and 
                    Verify the presence of the corresponding snapshots on the Secondary Storage
        # 2. Delete the snapshot policy and verify the entry as Destroyed in snapshot_schedule
        # 3. Verify that maxsnaps should not consider manual snapshots for deletion
        # 4. Snapshot policy should reflect the correct timezone
        # 5. Verify that listSnapshotPolicies() should return all snapshot policies
                that belong to the account (both manual and recurring snapshots)
        # 6. Verify that listSnapshotPolicies() should not return snapshot 
                policies that have been deleted
        # 7. Verify that snapshot should not be created for VM in Destroyed state
        # 8. Verify that snapshot should get created after resuming the VM
        # 9. Verify that All the recurring policies associated with the VM should be 
                deleted after VM get destroyed.
        """
        # Step 1
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'

        recurring_snapshot = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )
        # ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot.id,
            volumeid=self.volume[0].id
        )
        list_validation = validateList(list_snapshots_policy)

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

        timeout = self.testdata["timeout"]
        while True:
            snapshots = list_snapshots(
                self.apiclient,
                volumeid=self.volume[0].id,
                intervaltype=self.testdata[
                    "recurring_snapshot"]["intervaltype"],
                snapshottype='RECURRING',
                listall=True
            )

            if isinstance(snapshots, list):
                break

            elif timeout == 0:
                raise Exception("List snapshots API call failed.")

        for snapshot in snapshots:
            self.assertEqual(
                self.dbclient.execute(
                    "select type_description from snapshots where name='%s'" %
                    snapshot.name)[0][0],
                "HOURLY"
            )

        time.sleep(180)

        for snapshot in snapshots:
            self.assertTrue(
                is_snapshot_on_nfs(
                    self.apiclient,
                    self.dbclient,
                    self.config,
                    self.zone.id,
                    snapshot.id))

        recurring_snapshot.delete(self.apiclient)

        self.assertEqual(
            self.dbclient.execute(
                "select * from snapshot_policy where uuid='%s'" %
                recurring_snapshot.id),
            []
        )

        self.testdata["recurring_snapshot"]["intervaltype"] = 'DAILY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00'
        recurring_snapshot_daily = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        list_snapshots_policy_daily = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_daily.id,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(list_snapshots_policy_daily)

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

        snap_db_daily = self.dbclient.execute(
            "select * from snapshot_policy where uuid='%s'" %
            recurring_snapshot_daily.id)

        validation_result_1 = validateList(snap_db_daily)

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

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

        recurring_snapshot_daily.delete(self.apiclient)

        self.assertEqual(
            self.dbclient.execute(
                "select * from snapshot_policy where uuid='%s'" %
                recurring_snapshot_daily.id),
            []
        )
    
        self.testdata["recurring_snapshot"]["intervaltype"] = 'WEEKLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_weekly = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        list_snapshots_policy_weekly = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_weekly.id,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(list_snapshots_policy_weekly)

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

        snap_sch_2 = self.dbclient.execute(
            "select * from snapshot_policy where uuid='%s'" %
            recurring_snapshot_weekly.id)

        validation_result_2 = validateList(snap_sch_2)

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

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

        recurring_snapshot_weekly.delete(self.apiclient)

        self.assertEqual(
            self.dbclient.execute(
                "select * from snapshot_policy where uuid='%s'" %
                recurring_snapshot_weekly.id),
            []
        )

        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_monthly = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        list_snapshots_policy_monthly = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_monthly.id,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(list_snapshots_policy_monthly)

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

        snap_sch_3 = self.dbclient.execute(
            "select * from snapshot_policy where uuid='%s'" %
            recurring_snapshot_monthly.id)

        validation_result = validateList(snap_sch_3)

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

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

        recurring_snapshot_monthly.delete(self.apiclient)

        self.assertEqual(
            self.dbclient.execute(
                "select * from snapshot_policy where uuid='%s'" %
                recurring_snapshot_weekly.id),
            []
        )

        snapshots = list_snapshots(
            self.apiclient,
            volumeid=self.volume[0].id,
            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
            snapshottype='RECURRING',
            listall=True
        )

        # Step 3
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
        self.testdata["recurring_snapshot"]["schedule"] = 1
        recurring_snapshot_1 = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )
        # ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_1.id,
            volumeid=self.volume[0].id
        )
        list_validation = validateList(list_snapshots_policy)

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

        timeout = self.testdata["timeout"]
        while True:
            snapshots = list_snapshots(
                self.apiclient,
                volumeid=self.volume[0].id,
                intervaltype=self.testdata[
                    "recurring_snapshot"]["intervaltype"],
                snapshottype='RECURRING',
                listall=True
            )

            if isinstance(snapshots, list):
                break

            elif timeout == 0:
                raise Exception("List snapshots API call failed.")

        snap_to_delete = snapshots[0]

        time.sleep(
            (self.testdata["recurring_snapshot"]["maxsnaps"]) * 3600
        )

        snapshots_1 = list_snapshots(
            self.apiclient,
            volumeid=self.volume[0].id,
            intervaltype=self.testdata["recurring_snapshot"]["intervaltype"],
            snapshottype='RECURRING',
            listall=True
        )

        self.assertTrue(snap_to_delete not in snapshots_1)

        time.sleep(360)

        self.assertEqual(
            self.dbclient.execute(
                "select status  from snapshots where uuid='%s'" %
                snap_to_delete.id)[0][0],
            "Destroyed"
        )

        self.assertFalse(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                snap_to_delete.id))

        # Step 4
        recurring_snapshot = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )
        # ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot.id,
            volumeid=self.volume[0].id
        )
        list_validation = validateList(list_snapshots_policy)

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

        time.sleep(180)
        snap_time_hourly = self.dbclient.execute(
            "select scheduled_timestamp from \
            snapshot_schedule where uuid='%s'" %
            recurring_snapshot.id)

        self.debug("Timestamp for hourly snapshot %s" % snap_time_hourly)
        recurring_snapshot.delete(self.apiclient)

        self.testdata["recurring_snapshot"]["intervaltype"] = 'DAILY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00'
        recurring_snapshot_daily = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        list_snapshots_policy_daily = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_daily.id,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(list_snapshots_policy_daily)

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

        time.sleep(180)
        snap_time_daily = self.dbclient.execute(
            "select scheduled_timestamp from \
                    snapshot_schedule where uuid='%s'" %
            recurring_snapshot_daily.id)

        self.debug("Timestamp for daily snapshot %s" % snap_time_daily)
        recurring_snapshot_daily.delete(self.apiclient)

        self.testdata["recurring_snapshot"]["intervaltype"] = 'WEEKLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_weekly = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        list_snapshots_policy_weekly = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_weekly.id,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(list_snapshots_policy_weekly)

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

        time.sleep(180)
        snap_time_weekly = self.dbclient.execute(
            "select scheduled_timestamp from \
                    snapshot_schedule where uuid='%s'" %
            recurring_snapshot_weekly.id)

        self.debug("Timestamp for monthly snapshot %s" % snap_time_weekly)
        recurring_snapshot_weekly.delete(self.apiclient)

        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_monthly = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        list_snapshots_policy_monthly = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot_monthly.id,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(list_snapshots_policy_monthly)

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

        time.sleep(180)
        snap_time_monthly = self.dbclient.execute(
            "select scheduled_timestamp from \
                    snapshot_schedule where uuid='%s'" %
            recurring_snapshot_monthly.id)

        self.debug("Timestamp for monthly snapshot %s" % snap_time_monthly)

        recurring_snapshot_monthly.delete(self.apiclient)

        # Step 5
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
        self.testdata["recurring_snapshot"]["schedule"] = 1
        recurring_snapshot_hourly = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )
        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_monthly = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(list_snapshots_policy)

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

        for rec in [recurring_snapshot_hourly, recurring_snapshot_monthly]:
            self.assertTrue(
                rec.id in any(
                    policy['id']) for policy in list_snapshots_policy)

        recurring_snapshot_hourly.delete(self.apiclient)
        recurring_snapshot_monthly.delete(self.apiclient)

        # Step 6
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
        self.testdata["recurring_snapshot"]["schedule"] = 1
        recurring_snapshot_hourly = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        self.testdata["recurring_snapshot"]["intervaltype"] = 'MONTHLY'
        self.testdata["recurring_snapshot"]["schedule"] = '00:00:1'
        recurring_snapshot_monthly = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )

        recurring_snapshot_monthly.delete(self.apiclient)

        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(list_snapshots_policy)

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

        self.assertTrue(
            recurring_snapshot_hourly.id in any(
                policy['id']) for policy in list_snapshots_policy)

        self.assertTrue(
            recurring_snapshot_monthly.id not in any(
                policy['id']) for policy in list_snapshots_policy)

        # Step 7
        self.testdata["recurring_snapshot"]["intervaltype"] = 'HOURLY'
        self.testdata["recurring_snapshot"]["schedule"] = 1
        recurring_snapshot = SnapshotPolicy.create(
            self.apiclient,
            self.volume[0].id,
            self.testdata["recurring_snapshot"]
        )
        # ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = list_snapshot_policy(
            self.apiclient,
            id=recurring_snapshot.id,
            volumeid=self.volume[0].id
        )
        list_validation = validateList(list_snapshots_policy)

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

        timeout = self.testdata["timeout"]
        while True:
            snapshots = list_snapshots(
                self.apiclient,
                volumeid=self.volume[0].id,
                intervaltype=self.testdata[
                    "recurring_snapshot"]["intervaltype"],
                snapshottype='RECURRING',
                listall=True
            )

            if isinstance(snapshots, list):
                break

            elif timeout == 0:
                raise Exception("List snapshots API call failed.")

        self.vm_1.delete(self.apiclient, expunge=False)

        time.sleep(3600)
        snapshot_list = Snapshot.list(
            self.apiclient,
            volumeid=self.volume[0].id
        )

        list_validation = validateList(snapshot_list)

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

        self.assertEqual(len(snapshot_list),
                         1,
                         "Verify that snapsot is not created after VM deletion"
                         )
        # Step 8
        self.vm_1.recover(self.apiclient)
        time.sleep(3600)

        snapshot_list = Snapshot.list(
            self.apiclient,
            volumeid=self.volume[0].id
        )

        self.assertEqual(len(snapshot_list),
                         2,
                         "Verify that snapsot is not created after VM deletion"
                         )
        # Step 9
        self.vm_1.delete(self.apiclient)
        time.sleep(180)
        with self.assertRaises(Exception):
            list_snapshots_policy = list_snapshot_policy(
                self.apiclient,
                volumeid=self.volume[0].id
            )
Пример #16
0
    def test_01_multiple_snapshot_in_zwps(self):
        """ Test multiple volume snapshot in zwps

        # 1. Verify if setup has a ZWPS and 2 CWPS
        # 2. Deploy a VM with data disk in ZWPS
        # 1. Verify ROOT and DATA Disk of the VM is in ZWPS.
        # 2. Take a snapshot of VM.
        # 3. Create Multiple Snapshots till operation fails.
        """
        try:
            self.pools = StoragePool.list(self.apiclient, zoneid=self.zone.id)
            status = validateList(self.pools)

            self.assertEqual(
                status[0], PASS,
                "Check: Failed to list storage pools due to %s" % status[2])

            zonepoolList = list(storagePool for storagePool in self.pools
                                if storagePool.scope == "ZONE")

            if len(zonepoolList) < 1:
                self.skipTest("There must be at least one zone wide\
                storage pools available in the setup")
            if len(
                    list(storagePool for storagePool in self.pools
                         if storagePool.scope == "CLUSTER")) < 2:
                self.skipTest("There must be at atleast two cluster wide\
                storage pools available in the setup")
        except Exception as e:
            self.skipTest(e)

        # Adding tags to Storage Pools
        zone_no = 1
        StoragePool.update(self.apiclient,
                           id=zonepoolList[0].id,
                           tags=[ZONETAG1[:-1] + repr(zone_no)])

        self.vm_zwps = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_zwps.id,
            diskofferingid=self.disk_offering_zwps.id,
            zoneid=self.zone.id,
        )

        self.cleanup.append(self.vm_zwps)

        # Step 1
        volumes_root_list = list_volumes(self.apiclient,
                                         virtualmachineid=self.vm_zwps.id,
                                         type=ROOT,
                                         listall=True)
        status = validateList(volumes_root_list)

        self.assertEqual(
            status[0], PASS,
            "Check: Failed to list root vloume due to %s" % status[2])

        root_volume = volumes_root_list[0]

        if root_volume.storage != zonepoolList[0].name:
            self.fail("Root Volume not in Zone-Wide Storage Pool !")

        volumes_data_list = list_volumes(self.apiclient,
                                         virtualmachineid=self.vm_zwps.id,
                                         type=DATA,
                                         listall=True)
        status = validateList(volumes_data_list)

        self.assertEqual(
            status[0], PASS,
            "Check: Failed to list data vloume due to %s" % status[2])

        data_volume = volumes_data_list[0]

        if data_volume.storage != zonepoolList[0].name:
            self.fail("Data Volume not in Zone-Wide Storage Pool !")

        # Step 2
        self.vm_zwps.stop(self.apiclient)

        self.debug(
            "Creation of Snapshot of Data Volume after VM is stopped.....")

        Snapshot.create(self.apiclient, data_volume.id)

        snapshots_list = Snapshot.list(self.apiclient,
                                       volumeid=data_volume.id,
                                       listall=True)

        snap_list_validation_result = validateList(snapshots_list)

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

        snap_count = len(snapshots_list)

        # Step 3
        self.debug(
            "Creating Multiple Snapshots(Should create more than 10).....")
        try:
            while snap_count <= 12:
                Snapshot.create(self.apiclient, data_volume.id)

                snapshots_list = Snapshot.list(self.apiclient,
                                               volumeid=data_volume.id,
                                               listall=True)

                snap_list_validation_result = validateList(snapshots_list)

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

                snap_count = len(snapshots_list)
        except Exception as e:
            snapshots_list = Snapshot.list(self.apiclient,
                                           volumeid=data_volume.id,
                                           listall=True)

            snap_list_validation_result = validateList(snapshots_list)

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

            assert len(snapshots_list) >= 10,\
                "Less than 10 snapshots created...."
            raise Exception("Snapshot creation failed !: %s" % e)

        return
Пример #17
0
    def test_02_list_snapshots_with_removed_data_store(self):
        """Test listing volume snapshots with removed data stores
        """

        # 1 - Create new volume -> V
        # 2 - Create new Primary Storage -> PS
        # 3 - Attach and detach volume V from vm
        # 4 - Migrate volume V to PS
        # 5 - Take volume V snapshot -> S
        # 6 - List snapshot and verify it gets properly listed although Primary Storage was removed

        # Create new volume
        vol = Volume.create(
            self.apiclient,
            self.services["volume"],
            diskofferingid=self.disk_offering.id,
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
        )
        self.cleanup.append(vol)
        self.assertIsNotNone(vol, "Failed to create volume")
        vol_res = Volume.list(self.apiclient, id=vol.id)
        self.assertEqual(
            validateList(vol_res)[0], PASS,
            "Invalid response returned for list volumes")
        vol_uuid = vol_res[0].id
        clusters = list_clusters(self.apiclient, zoneid=self.zone.id)
        assert isinstance(clusters, list) and len(clusters) > 0

        # Attach created volume to vm, then detach it to be able to migrate it
        self.virtual_machine_with_disk.stop(self.apiclient)
        self.virtual_machine_with_disk.attach_volume(self.apiclient, vol)

        # Create new Primary Storage
        storage = StoragePool.create(self.apiclient,
                                     self.services["nfs2"],
                                     clusterid=clusters[0].id,
                                     zoneid=self.zone.id,
                                     podid=self.pod.id)

        self.cleanup.append(storage)
        self.assertEqual(storage.state, 'Up', "Check primary storage state")
        self.assertEqual(storage.type, 'NetworkFilesystem',
                         "Check storage pool type")
        storage_pools_response = list_storage_pools(self.apiclient,
                                                    id=storage.id)
        self.assertEqual(isinstance(storage_pools_response, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(len(storage_pools_response), 0,
                            "Check list Hosts response")
        storage_response = storage_pools_response[0]
        self.assertEqual(storage_response.id, storage.id,
                         "Check storage pool ID")
        self.assertEqual(storage.type, storage_response.type,
                         "Check storage pool type ")

        self.virtual_machine_with_disk.detach_volume(self.apiclient, vol)

        # Migrate volume to new Primary Storage
        Volume.migrate(self.apiclient, storageid=storage.id, volumeid=vol.id)

        volume_response = list_volumes(
            self.apiclient,
            id=vol.id,
        )
        self.assertNotEqual(len(volume_response), 0,
                            "Check list Volumes response")
        volume_migrated = volume_response[0]
        self.assertEqual(volume_migrated.storageid, storage.id,
                         "Check volume storage id")

        # Take snapshot of new volume
        snapshot = Snapshot.create(self.apiclient,
                                   volume_migrated.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)

        self.debug("Snapshot created: ID - %s" % snapshot.id)

        # Delete volume, VM and created Primary Storage
        cleanup_resources(self.apiclient, self.cleanup)

        # List snapshot and verify it gets properly listed although Primary Storage was removed
        snapshot_response = Snapshot.list(self.apiclient, id=snapshot.id)
        self.assertNotEqual(len(snapshot_response), 0,
                            "Check list Snapshot response")
        self.assertEqual(snapshot_response[0].id, snapshot.id,
                         "Check snapshot id")

        # Delete snapshot and verify it gets properly deleted (should not be listed)
        self.cleanup = [snapshot]
        cleanup_resources(self.apiclient, self.cleanup)

        self.cleanup = []
        snapshot_response_2 = Snapshot.list(self.apiclient, id=snapshot.id)
        self.assertEqual(snapshot_response_2, None,
                         "Check list Snapshot response")

        return
    def test_01_snapshot_on_rootVolume(self):
        """Test create VM with default cent os template and create snapshot
            on root disk of the vm
        """
        # Validate the following
        # 1. Deploy a Linux VM using default CentOS template, use small service
        #    offering, disk offering
        # 2. Create snapshot on the root disk of this newly cteated vm
        # 3. listSnapshots should list the snapshot that was created.
        # 4. verify that secondary storage NFS share contains the reqd
        # volume under /secondary/snapshots/$accountid/$volumeid/$snapshot_uuid
        # 5. verify backup_snap_id was non null in the `snapshots` table

        # Create virtual machine with small systerm offering and disk offering
        new_virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            templateid=self.template.id,
            zoneid=self.zone.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            diskofferingid=self.disk_offering.id,
        )
        self.debug("Virtual machine got created with id: %s" %
                   new_virtual_machine.id)
        list_virtual_machine_response = VirtualMachine.list(
            self.apiclient, id=new_virtual_machine.id)
        self.assertEqual(isinstance(list_virtual_machine_response, list), True,
                         "Check listVirtualMachines returns a valid list")

        self.assertNotEqual(len(list_virtual_machine_response), 0,
                            "Check listVirtualMachines response")
        self.cleanup.append(new_virtual_machine)

        # Getting root volume id of the vm created above
        list_volume_response = Volume.list(
            self.apiclient,
            virtualmachineid=list_virtual_machine_response[0].id,
            type="ROOT",
            account=self.account.name,
            domainid=self.account.domainid)

        self.assertEqual(isinstance(list_volume_response, list), True,
                         "Check listVolumes returns a valid list")
        self.assertNotEqual(len(list_volume_response), 0,
                            "Check listVolumes response")
        self.debug(
            "Snapshot will be created on the volume with voluem id: %s" %
            list_volume_response[0].id)

        # Perform snapshot on the root volume
        root_volume_snapshot = Snapshot.create(
            self.apiclient, volume_id=list_volume_response[0].id)
        self.debug(
            "Created snapshot: %s for vm: %s" %
            (root_volume_snapshot.id, list_virtual_machine_response[0].id))
        list_snapshot_response = Snapshot.list(self.apiclient,
                                               id=root_volume_snapshot.id,
                                               account=self.account.name,
                                               domainid=self.account.domainid)
        self.assertEqual(isinstance(list_snapshot_response, list), True,
                         "Check listSnapshots returns a valid list")

        self.assertNotEqual(len(list_snapshot_response), 0,
                            "Check listSnapshots response")
        # Verify Snapshot state
        self.assertEqual(
            list_snapshot_response[0].state
            in ['BackedUp', 'CreatedOnPrimary'], True,
            "Snapshot state is not as expected. It is %s" %
            list_snapshot_response[0].state)

        self.assertEqual(
            list_snapshot_response[0].volumeid, list_volume_response[0].id,
            "Snapshot volume id is not matching with the vm's volume id")
        self.cleanup.append(root_volume_snapshot)

        # Below code is to verify snapshots in the backend and in db.
        # Verify backup_snap_id field in the snapshots table for the snapshot created, it should not be null

        self.debug(
            "select id, removed, backup_snap_id from snapshots where uuid = '%s';"
            % root_volume_snapshot.id)
        qryresult = self.dbclient.execute(
            "select id, removed, backup_snap_id from snapshots where uuid = '%s';"
            % root_volume_snapshot.id)
        self.assertNotEqual(len(qryresult), 0,
                            "Check sql query to return snapshots list")
        snapshot_qry_response = qryresult[0]
        snapshot_id = snapshot_qry_response[0]
        is_removed = snapshot_qry_response[1]
        backup_snap_id = snapshot_qry_response[2]
        self.assertNotEqual(
            is_removed, "NULL",
            "Snapshot is removed from CS, please check the logs")
        msg = "Backup snapshot id is set to null for the backedup snapshot :%s" % snapshot_id
        self.assertNotEqual(backup_snap_id, "NULL", msg)

        # Check if the snapshot is present on the secondary storage
        self.assertTrue(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, root_volume_snapshot.id))

        return
Пример #19
0
    def test_01_verify_events_table(self):
        """ Test events table

        # 1. Deploy a VM.
        # 2. Take VM snapshot.
        # 3. Verify that events table records UUID of the volume in descrption
            instead of volume ID
        """
        # Step 1
        # Create VM
        vm = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )
        volumes_list = list_volumes(
            self.apiclient,
            virtualmachineid=vm.id,
            type='ROOT',
            listall=True
        )

        volume_list_validation = validateList(volumes_list)
        self.assertEqual(
            volume_list_validation[0],
            PASS,
            "volume list validation failed due to %s" %
            volume_list_validation[2]
        )
        root_volume = volumes_list[0]

        # Step 2
        # Create snapshot of root volume
        snapshot = Snapshot.create(
            self.apiclient,
            root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient,
                                        id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        self.assertEqual(
            snapshot.state,
            "BackedUp",
            "Check if snapshot gets created properly"
        )

        # Step 3
        qresultset = self.dbclient.execute(
            "select  description from event where type='SNAPSHOT.CREATE' AND \
                        description like '%%%s%%'" % root_volume.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 if events table records UUID of the volume"
        )

        return
Пример #20
0
    def test_01_concurrent_snapshot_global_limit(self):
        """ Test if global value concurrent.snapshots.threshold.perhost
            value respected
            This is positive test cases and tests if we are able to create
            as many snapshots mentioned in global value
        # 1. Create an account and a VM in it
        # 2. Read the global value for concurrent.snapshots.threshold.perhost
        # 3. If the value is Null, create at least 10 concurrent snapshots
             and verify they are created successfully
        # 4. Else, create as many snapshots specified in the global value, and
             verify they are created successfully
        """

        # Create an account
        account = Account.create(self.apiclient,
                                 self.testdata["account"],
                                 domainid=self.domain.id)

        self.cleanup.append(account)
        # Create user api client of the account
        userapiclient = self.testClient.getUserApiClient(
            UserName=account.name, DomainName=account.domain)

        # Create VM
        virtual_machine = VirtualMachine.create(
            userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=account.name,
            domainid=account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id)

        # Create 10 concurrent snapshots by default
        # We can have any value, so keeping it 10 as it
        # seems good enough to test
        concurrentSnapshots = 10

        # Step 1
        # Get ROOT Volume Id
        volumes = Volume.list(self.apiclient,
                              virtualmachineid=virtual_machine.id,
                              type='ROOT',
                              listall=True)

        self.assertEqual(
            validateList(volumes)[0], PASS, "Volumes list validation failed")

        root_volume = volumes[0]

        config = Configurations.list(
            self.apiclient, name="concurrent.snapshots.threshold.perhost")
        if config[0].value:
            self.assertEqual(
                isinstance(config, list), True,
                "concurrent.snapshots.threshold.perhost should be present\
				in global config")
            concurrentSnapshots = int(config[0].value)
        self.debug("concurrent Snapshots: %s" % concurrentSnapshots)

        threads = []
        for i in range(0, (concurrentSnapshots)):
            thread = Thread(target=Snapshot.create,
                            args=(self.apiclient, root_volume.id))
            threads.append(thread)
            thread.start()
        for thread in threads:
            thread.join()

        snapshots = Snapshot.list(self.apiclient,
                                  volumeid=root_volume.id,
                                  listall=True)

        self.assertEqual(
            validateList(snapshots)[0], PASS,
            "Snapshots list validation failed")
        self.assertEqual(
            len(snapshots), concurrentSnapshots,
            "There should be exactly %s snapshots present" %
            concurrentSnapshots)

        for snapshot in snapshots:
            self.assertEqual(
                str(snapshot.state).lower(), BACKED_UP,
                "Snapshot state should be backedUp but it is\
                            %s" % snapshot.state)
        return
Пример #21
0
    def test_02_list_snapshots_with_removed_data_store(self):
        """Test listing volume snapshots with removed data stores
        """

        # 1 - Create new volume -> V
        # 2 - Create new Primary Storage -> PS
        # 3 - Attach and detach volume V from vm
        # 4 - Migrate volume V to PS
        # 5 - Take volume V snapshot -> S
        # 6 - List snapshot and verify it gets properly listed although Primary Storage was removed
        
        # Create new volume
        vol = Volume.create(
            self.apiclient,
            self.services["volume"],
            diskofferingid=self.disk_offering.id,
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
        )
        self.cleanup.append(vol)
        self.assertIsNotNone(vol, "Failed to create volume")
        vol_res = Volume.list(
            self.apiclient,
            id=vol.id
        )
        self.assertEqual(
            validateList(vol_res)[0],
            PASS,
            "Invalid response returned for list volumes")
        vol_uuid = vol_res[0].id
        
        # Create new Primary Storage
        clusters = list_clusters(
            self.apiclient,
            zoneid=self.zone.id
        )
        assert isinstance(clusters,list) and len(clusters)>0

        storage = StoragePool.create(self.apiclient,
                                     self.services["nfs2"],
                                     clusterid=clusters[0].id,
                                     zoneid=self.zone.id,
                                     podid=self.pod.id
                                     )
        self.cleanup.append(self.virtual_machine_with_disk)
        self.cleanup.append(storage)

        self.assertEqual(
            storage.state,
            'Up',
            "Check primary storage state"
        )
        self.assertEqual(
            storage.type,
            'NetworkFilesystem',
            "Check storage pool type"
        )
        storage_pools_response = list_storage_pools(self.apiclient,
                                                    id=storage.id)
        self.assertEqual(
            isinstance(storage_pools_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            len(storage_pools_response),
            0,
            "Check list Hosts response"
        )
        storage_response = storage_pools_response[0]
        self.assertEqual(
            storage_response.id,
            storage.id,
            "Check storage pool ID"
        )
        self.assertEqual(
            storage.type,
            storage_response.type,
            "Check storage pool type "
        )

        # Attach created volume to vm, then detach it to be able to migrate it
        self.virtual_machine_with_disk.stop(self.apiclient)
        self.virtual_machine_with_disk.attach_volume(
            self.apiclient,
            vol
        )
        self.virtual_machine_with_disk.detach_volume(
            self.apiclient,
            vol
        )

        # Migrate volume to new Primary Storage
        Volume.migrate(self.apiclient,
            storageid=storage.id,
            volumeid=vol.id
        )

        volume_response = list_volumes(
            self.apiclient,
            id=vol.id,
        )
        self.assertNotEqual(
            len(volume_response),
            0,
            "Check list Volumes response"
        )
        volume_migrated = volume_response[0]
        self.assertEqual(
            volume_migrated.storageid,
            storage.id,
            "Check volume storage id"
        )

        # Take snapshot of new volume
        snapshot = Snapshot.create(
            self.apiclient,
            volume_migrated.id,
            account=self.account.name,
            domainid=self.account.domainid
        )

        self.debug("Snapshot created: ID - %s" % snapshot.id)

        # Delete volume, VM and created Primary Storage
        cleanup_resources(self.apiclient, self.cleanup)

        # List snapshot and verify it gets properly listed although Primary Storage was removed
        snapshot_response = Snapshot.list(
            self.apiclient,
            id=snapshot.id
        )
        self.assertNotEqual(
            len(snapshot_response),
            0,
            "Check list Snapshot response"
        )
        self.assertEqual(
            snapshot_response[0].id,
            snapshot.id,
            "Check snapshot id"
        )

        # Delete snapshot and verify it gets properly deleted (should not be listed)
        self.cleanup = [snapshot]
        cleanup_resources(self.apiclient, self.cleanup)

        self.cleanup = []
        snapshot_response_2 = Snapshot.list(
            self.apiclient,
            id=snapshot.id
        )
        self.assertEqual(
            snapshot_response_2,
            None,
            "Check list Snapshot response"
        )

        return
Пример #22
0
    def test_03_reuse_template_name(self):
        """TS_BUG_011-Test Reusing deleted template name
        """

        # Validate the following
        # 1. Deploy VM using default template, small service offering
        #    and small data disk offering.
        # 2. Perform snapshot on the root disk of this VM.
        # 3. Create a template from snapshot.
        # 4. Delete the template and create a new template with same name
        # 5. Template should be created succesfully

        # Create a snapshot from the ROOTDISK
        snapshot = Snapshot.create(self.apiclient,
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
        self.debug("Created snapshot with ID: %s" % snapshot.id)
        snapshots = Snapshot.list(self.apiclient, id=snapshot.id)
        self.assertEqual(isinstance(snapshots, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(snapshots, None,
                            "Check if result exists in list snapshots call")
        self.assertEqual(snapshots[0].id, snapshot.id,
                         "Check snapshot id in list resources call")

        # Generate template from the snapshot
        template = Template.create_from_snapshot(self.apiclient,
                                                 snapshot,
                                                 self.services["template"],
                                                 random_name=False)
        self.debug("Created template from snapshot: %s" % template.id)
        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(isinstance(templates, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(templates, None,
                            "Check if result exists in list item call")

        self.assertEqual(templates[0].isready, True,
                         "Check new template state in list templates call")

        self.debug("Deleting template: %s" % template.id)
        template.delete(self.apiclient)

        # Wait for some time to ensure template state is reflected in other calls
        time.sleep(self.services["sleep"])

        # Generate template from the snapshot
        self.debug("Creating template from snapshot: %s with same name" %
                   template.id)
        template = Template.create_from_snapshot(self.apiclient,
                                                 snapshot,
                                                 self.services["template"],
                                                 random_name=False)

        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(isinstance(templates, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(templates, None,
                            "Check if result exists in list item call")

        self.assertEqual(templates[0].name, self.services["template"]["name"],
                         "Check the name of the template")
        return
Пример #23
0
    def test_01_snapshot_on_rootVolume(self):
        """Test create VM with default cent os template and create snapshot
            on root disk of the vm
        """
        # Validate the following
        # 1. Deploy a Linux VM using default CentOS template, use small service
        #    offering, disk offering
        # 2. Create snapshot on the root disk of this newly cteated vm
        # 3. listSnapshots should list the snapshot that was created.
        # 4. verify that secondary storage NFS share contains the reqd
        # volume under /secondary/snapshots/$accountid/$volumeid/$snapshot_uuid
        # 5. verify backup_snap_id was non null in the `snapshots` table

        # Create virtual machine with small systerm offering and disk offering
        new_virtual_machine = VirtualMachine.create(
                                    self.apiclient,
                                    self.services["virtual_machine"],
                                    templateid=self.template.id,
                                    zoneid=self.zone.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    serviceofferingid=self.service_offering.id,
                                    diskofferingid=self.disk_offering.id,
                                )
        self.debug("Virtual machine got created with id: %s" %
                                                    new_virtual_machine.id)
        list_virtual_machine_response = VirtualMachine.list(
                                                    self.apiclient,
                                                    id=new_virtual_machine.id)
        self.assertEqual(isinstance(list_virtual_machine_response, list),
                         True,
                         "Check listVirtualMachines returns a valid list")

        self.assertNotEqual(len(list_virtual_machine_response),
                            0,
                            "Check listVirtualMachines response")
        self.cleanup.append(new_virtual_machine)

        # Getting root volume id of the vm created above
        list_volume_response = Volume.list(
                                self.apiclient,
                                virtualmachineid=list_virtual_machine_response[0].id,
                                type="ROOT",
                                account=self.account.name,
                                domainid=self.account.domainid)

        self.assertEqual(isinstance(list_volume_response, list),
                         True,
                         "Check listVolumes returns a valid list")
        self.assertNotEqual(len(list_volume_response),
                            0,
                            "Check listVolumes response")
        self.debug(
            "Snapshot will be created on the volume with voluem id: %s" %
                                                    list_volume_response[0].id)

        # Perform snapshot on the root volume
        root_volume_snapshot = Snapshot.create(
                                        self.apiclient,
                                       volume_id=list_volume_response[0].id)
        self.debug("Created snapshot: %s for vm: %s" % (
                                        root_volume_snapshot.id,
                                        list_virtual_machine_response[0].id))
        list_snapshot_response = Snapshot.list(
                                        self.apiclient,
                                        id=root_volume_snapshot.id,
                                        account=self.account.name,
                                        domainid=self.account.domainid)
        self.assertEqual(isinstance(list_snapshot_response, list),
                         True,
                         "Check listSnapshots returns a valid list")

        self.assertNotEqual(len(list_snapshot_response),
                            0,
                            "Check listSnapshots response")
        # Verify Snapshot state
        self.assertEqual(
                            list_snapshot_response[0].state in [
                                                                'BackedUp',
                                                                'CreatedOnPrimary'
                                                                ],
                            True,
                            "Snapshot state is not as expected. It is %s" %
                            list_snapshot_response[0].state
                        )

        self.assertEqual(
                list_snapshot_response[0].volumeid,
                list_volume_response[0].id,
                "Snapshot volume id is not matching with the vm's volume id")
        self.cleanup.append(root_volume_snapshot)

        # Below code is to verify snapshots in the backend and in db.
        # Verify backup_snap_id field in the snapshots table for the snapshot created, it should not be null

        self.debug("select id, removed, backup_snap_id from snapshots where uuid = '%s';" % root_volume_snapshot.id)
        qryresult = self.dbclient.execute("select id, removed, backup_snap_id from snapshots where uuid = '%s';" % root_volume_snapshot.id)
        self.assertNotEqual(len(qryresult), 0, "Check sql query to return snapshots list")
        snapshot_qry_response = qryresult[0]
        snapshot_id = snapshot_qry_response[0]
        is_removed = snapshot_qry_response[1]
        backup_snap_id = snapshot_qry_response[2]
        self.assertNotEqual(is_removed, "NULL", "Snapshot is removed from CS, please check the logs")
        msg = "Backup snapshot id is set to null for the backedup snapshot :%s" % snapshot_id
        self.assertNotEqual(backup_snap_id, "NULL", msg )

        # Check if the snapshot is present on the secondary storage
        self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, root_volume_snapshot.id))

        return
Пример #24
0
    def test_01_list_volume_snapshots_pagination(self):
        """
        @Desc: Test to List Volume Snapshots pagination
        @steps:
        Step1: Listing all the volume snapshots for a user
        Step2: Verifying that list size is 0
        Step3: Creating (page size + 1) number of volume snapshots
        Step4: Listing all the volume snapshots again for a user
        Step5: Verifying that list size is (page size + 1)
        Step6: Listing all the volume snapshots in page1
        Step7: Verifying that list size is (page size)
        Step8: Listing all the volume snapshots in page2
        Step9: Verifying that list size is 1
        Step10: Deleting the volume snapshot present in page 2
        Step11: Listing all the volume snapshots in page2
        Step12: Verifying that list size is 0
        """
        if self.hypervisor.lower() in ['hyperv']:
            raise unittest.SkipTest("This feature is not supported on existing hypervisor. Hence, skipping the test")
        # Listing all the volume snapshots for a User
        list_vol_snaps_before = Snapshot.list(
                                              self.userapiclient,
                                              listall=self.services["listall"]
                                              )
        # Verifying list size is 0
        self.assertIsNone(
                          list_vol_snaps_before,
                          "Volume snapshots exists for newly created user"
                          )
        # Listing the root volumes available for the user
        volumes_list = Volume.list(
                                   self.userapiclient,
                                   listall=self.services["listall"]
                                   )
        status = validateList(volumes_list)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Root volume did not get created while deploying a VM"
                          )
        # Verifying list size to be 1
        self.assertEquals(
                          1,
                          len(volumes_list),
                          "More than 1 root volume created for deployed VM"
                          )
        root_volume = volumes_list[0]
        # Creating pagesize + 1 number of volume snapshots
        for i in range(0, (self.services["pagesize"] + 1)):
            snapshot_created = Snapshot.create(
                                               self.userapiclient,
                                               root_volume.id,
                                               )
            self.assertIsNotNone(
                                 snapshot_created,
                                 "Snapshot creation failed"
                                 )
            self.cleanup.append(snapshot_created)

        # Listing all the volume snapshots for user again
        list_vol_snaps_after = Snapshot.list(
                                             self.userapiclient,
                                             listall=self.services["listall"]
                                             )
        status = validateList(list_vol_snaps_after)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Volume snapshot creation failed"
                          )
        # Verifying that list size is pagesize + 1
        self.assertEquals(
                          self.services["pagesize"] + 1,
                          len(list_vol_snaps_after),
                          "Failed to create pagesize + 1 number of Volume snapshots"
                          )
        # Listing all the volume snapshots in page 1
        list_vol_snaps_page1 = Snapshot.list(
                                             self.userapiclient,
                                             listall=self.services["listall"],
                                             page=1,
                                             pagesize=self.services["pagesize"]
                                             )
        status = validateList(list_vol_snaps_page1)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Failed to list volume snapshots in page 1"
                          )
        # Verifying the list size to be equal to pagesize
        self.assertEquals(
                          self.services["pagesize"],
                          len(list_vol_snaps_page1),
                          "Size of volume snapshots in page 1 is not matching"
                          )
        # Listing all the volume snapshots in page 2
        list_vol_snaps_page2 = Snapshot.list(
                                             self.userapiclient,
                                             listall=self.services["listall"],
                                             page=2,
                                             pagesize=self.services["pagesize"]
                                             )
        status = validateList(list_vol_snaps_page2)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Failed to list volume snapshots in page 2"
                          )
        # Verifying the list size to be equal to pagesize
        self.assertEquals(
                          1,
                          len(list_vol_snaps_page2),
                          "Size of volume snapshots in page 2 is not matching"
                          )
        # Deleting the volume snapshot present in page 2
        Snapshot.delete(
                        snapshot_created,
                        self.userapiclient
                        )
        self.cleanup.remove(snapshot_created)
        # Listing all the snapshots in page 2 again
        list_vol_snaps_page2 = Snapshot.list(
                                             self.userapiclient,
                                             listall=self.services["listall"],
                                             page=2,
                                             pagesize=self.services["pagesize"]
                                             )
        # Verifying that list size is 0
        self.assertIsNone(
                          list_vol_snaps_page2,
                          "Volume snapshot not deleted from page 2"
                          )
        return
    def test_01_delta_snapshots(self):
        """ Delta Snapshots
            1. Create file on ROOT disk of deployed VM.
            2. Create Snapshot of ROOT disk.
            3. Verify secondary storage count.
            4. Check integrity of Full Snapshot.
            5. Delete delta snaphshot and check integrity of\
               remaining snapshots.
            6. Delete full snapshot and verify it is deleted from\
               secondary storage.
        """
        checksum_created = []
        full_snapshot_count = 0
        delta_snapshot_count = 0

        # Mulitply delta max value by 2 to set loop counter
        # to create 2 Snapshot chains
        snapshot_loop_count = int(self.delta_max) * 2

        # Get ROOT Volume
        root_volumes_list = list_volumes(
            self.apiclient,
            virtualmachineid=self.vm.id,
            type=ROOT,
            listall=True
        )

        status = validateList(root_volumes_list)
        self.assertEqual(
            status[0],
            PASS,
            "Check listVolumes response for ROOT Disk")

        root_volume = root_volumes_list[0]

        # Get Secondary Storage Value from Database
        qryresult_before_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)

        self.assertNotEqual(
            len(qryresult_before_snapshot),
            0,
            "Check sql query to return SecondaryStorageTotal of account")

        storage_qry_result_old = qryresult_before_snapshot[0]
        secondary_storage_old = storage_qry_result_old[2]

        # Create Snapshots

        for i in range(snapshot_loop_count):

            # Step 1
            checksum_root = createChecksum(
                self.testdata,
                self.vm,
                root_volume,
                "rootdiskdevice")

            time.sleep(30)
            checksum_created.append(checksum_root)

            # Step 2
            root_vol_snapshot = Snapshot.create(
                self.apiclient,
                root_volume.id)

            self.snapshots_created.append(root_vol_snapshot)

            snapshots_list = Snapshot.list(self.apiclient,
                                           id=root_vol_snapshot.id)

            status = validateList(snapshots_list)
            self.assertEqual(status[0], PASS, "Check listSnapshots response")

            # Verify Snapshot state
            self.assertEqual(
                snapshots_list[0].state.lower() in [
                    BACKED_UP,
                ],
                True,
                "Snapshot state is not as expected. It is %s" %
                snapshots_list[0].state
            )

            self.assertEqual(
                snapshots_list[0].volumeid,
                root_volume.id,
                "Snapshot volume id is not matching with the vm's volume id")

            # Step 3
            qryresult_after_snapshot = self.dbclient.execute(
                " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
                self.account.name)

            self.assertNotEqual(
                len(qryresult_after_snapshot),
                0,
                "Check sql query to return SecondaryStorageTotal of account")

            storage_qry_result_from_database = qryresult_after_snapshot[0]
            secondary_storage_from_database = storage_qry_result_from_database[
                2]

            snapshot_size = snapshots_list[0].physicalsize
            secondary_storage_after_snapshot = secondary_storage_old + \
                snapshot_size

            # Reset full_snapshot_count to 0 before start of new snapshot chain
            if delta_snapshot_count == (int(self.delta_max) - 1):
                full_snapshot_count = 0
                delta_snapshot_count = 0

            # Full Snapshot of each Snapshot chain
            if full_snapshot_count == 0:

                full_snapshot_count += 1
                full_snapshot_size = snapshot_size

                # Check secondary storage count for Full Snapshots
                self.assertEqual(
                    secondary_storage_from_database,
                    secondary_storage_after_snapshot,
                    "Secondary storage count after full snapshot\
                                should be incremented by size of snapshot.")
                # Step 4
                checkIntegrityOfSnapshot(
                    self,
                    snapshots_list[0],
                    checksum_root,
                    disk_type=DATA)

            else:

                # Delta Snapshot of each Snapshot chain
                delta_snapshot_count += 1
                delta_snapshot_size = snapshot_size

                # Check secondary storage count for Delta Snapshots
                self.assertTrue(delta_snapshot_size < full_snapshot_size,
                                "Delta Snapshot size should be less than\
                                Full Snapshot.")

                self.assertEqual(
                    secondary_storage_from_database,
                    secondary_storage_after_snapshot,
                    "Secondary storage count after delta snapshot\
                                should be incremented by size of snapshot.")

            secondary_storage_old = secondary_storage_from_database

        # Step 5

        # Check in Secondary Storage- Snapshots: S1, S2, S3 are present
        for i in range(int(self.delta_max)):
            self.assertTrue(
                is_snapshot_on_nfs(
                    self.apiclient,
                    self.dbclient,
                    self.config,
                    self.zone.id,
                    self.snapshots_created[i].id),
                "Check: Snapshot is not on Secondary Storage.")

        # Delete S2

        Snapshot.delete(self.snapshots_created[1], self.apiclient)

        snapshots_list = Snapshot.list(self.apiclient,
                                       id=self.snapshots_created[1].id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Check integrity of Snapshots for S1 and S3
        checkIntegrityOfSnapshot(
            self,
            self.snapshots_created[0],
            checksum_created[0],
            disk_type=DATA)

        checkIntegrityOfSnapshot(
            self,
            self.snapshots_created[2],
            checksum_created[2],
            disk_type=DATA)

        # Delete S3

        Snapshot.delete(self.snapshots_created[2], self.apiclient)

        snapshots_list = Snapshot.list(self.apiclient,
                                       id=self.snapshots_created[2].id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Check in Secondary Storage - Snapshots: S2, S3 are deleted
        self.assertFalse(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                self.snapshots_created[2].id),
            "Check: Snapshot 2 is still on Secondary Storage. Not Deleted.")

        self.assertFalse(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                self.snapshots_created[1].id),
            "Check: Snapshot 3 is still on Secondary Storage. Not Deleted.")

        # Restore Snapshots for S1
        checkIntegrityOfSnapshot(
            self,
            self.snapshots_created[0],
            checksum_created[0],
            disk_type=DATA)

        # Step 6
        # Delete S1

        Snapshot.delete(self.snapshots_created[0], self.apiclient)

        snapshots_list = Snapshot.list(self.apiclient,
                                       id=self.snapshots_created[0].id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Check in Secondary Storage - Snapshots: All - S1, S2, S3 are deleted

        self.assertFalse(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                self.snapshots_created[2].id),
            "Check: Snapshot 3 is still on Secondary Storage. Not Deleted.")

        self.assertFalse(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                self.snapshots_created[1].id),
            "Check: Snapshot 2 is still on Secondary Storage. Not Deleted.")

        self.assertFalse(
            is_snapshot_on_nfs(
                self.apiclient,
                self.dbclient,
                self.config,
                self.zone.id,
                self.snapshots_created[0].id),
            "Check: Snapshot 1 is still on Secondary Storage. Not Deleted.")

        return
Пример #26
0
    def test_02_check_size_snapshotTemplate(self):
        """TS_BUG_010-Test check size of snapshot and template
        """


        # Validate the following
        # 1. Deploy VM using default template, small service offering
        #    and small data disk offering.
        # 2. Perform snapshot on the root disk of this VM.
        # 3. Create a template from snapshot.
        # 4. Check the size of snapshot and template

        # Create a snapshot from the ROOTDISK
        snapshot = Snapshot.create(
                                   self.apiclient,
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid
                                   )
        self.debug("Created snapshot with ID: %s" % snapshot.id)
        snapshots = Snapshot.list(
                                   self.apiclient,
                                   id=snapshot.id
                                   )
        self.assertEqual(
                            isinstance(snapshots, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            snapshots,
                            None,
                            "Check if result exists in list snapshots call"
                            )
        self.assertEqual(
                            snapshots[0].id,
                            snapshot.id,
                            "Check snapshot id in list resources call"
                        )

        # Generate template from the snapshot
        template = Template.create_from_snapshot(
                                    self.apiclient,
                                    snapshot,
                                    self.services["template"]
                                    )
        self.cleanup.append(template)

        self.debug("Created template from snapshot with ID: %s" % template.id)
        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(
                            isinstance(templates, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            templates,
                            None,
                            "Check if result exists in list item call"
                            )

        self.assertEqual(
                            templates[0].isready,
                            True,
                            "Check new template state in list templates call"
                        )
        # check size of template with that of snapshot
        self.assertEqual(
                            templates[0].size,
                            self.volume.size,
                            "Derived template size (%s) does not match snapshot size (%s)" % (templates[0].size, self.volume.size)
                        )
        return
    def test_01_multiple_snapshot_in_zwps(self):
        """ Test multiple volume snapshot in zwps

        # 1. Verify if setup has a ZWPS and 2 CWPS
        # 2. Deploy a VM with data disk in ZWPS
        # 1. Verify ROOT and DATA Disk of the VM is in ZWPS.
        # 2. Take a snapshot of VM.
        # 3. Create Multiple Snapshots till operation fails.
        """
        try:
            self.pools = StoragePool.list(self.apiclient, zoneid=self.zone.id)
            status = validateList(self.pools)

            self.assertEqual(
                status[0],
                PASS,
                "Check: Failed to list storage pools due to %s" %
                status[2])

            zonepoolList = list(storagePool for storagePool in self.pools
                                if storagePool.scope == "ZONE")

            if len(zonepoolList) < 1:
                self.skipTest("There must be at least one zone wide\
                storage pools available in the setup")
            if len(list(storagePool for storagePool in self.pools
                        if storagePool.scope == "CLUSTER")) < 2:
                self.skipTest("There must be at atleast two cluster wide\
                storage pools available in the setup")
        except Exception as e:
            self.skipTest(e)

        # Adding tags to Storage Pools
        zone_no = 1
        StoragePool.update(
            self.apiclient,
            id=zonepoolList[0].id,
            tags=[ZONETAG1[:-1] + repr(zone_no)])

        self.vm_zwps = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_zwps.id,
            diskofferingid=self.disk_offering_zwps.id,
            zoneid=self.zone.id,
        )

        self.cleanup.append(self.vm_zwps)

        # Step 1
        volumes_root_list = list_volumes(
            self.apiclient,
            virtualmachineid=self.vm_zwps.id,
            type=ROOT,
            listall=True
        )
        status = validateList(volumes_root_list)

        self.assertEqual(
            status[0],
            PASS,
            "Check: Failed to list root vloume due to %s" %
            status[2])

        root_volume = volumes_root_list[0]

        if root_volume.storage != zonepoolList[0].name:
            self.fail("Root Volume not in Zone-Wide Storage Pool !")

        volumes_data_list = list_volumes(
            self.apiclient,
            virtualmachineid=self.vm_zwps.id,
            type=DATA,
            listall=True
        )
        status = validateList(volumes_data_list)

        self.assertEqual(
            status[0],
            PASS,
            "Check: Failed to list data vloume due to %s" %
            status[2])

        data_volume = volumes_data_list[0]

        if data_volume.storage != zonepoolList[0].name:
            self.fail("Data Volume not in Zone-Wide Storage Pool !")

        # Step 2
        self.vm_zwps.stop(self.apiclient)

        self.debug(
            "Creation of Snapshot of Data Volume after VM is stopped.....")

        Snapshot.create(
            self.apiclient,
            data_volume.id)

        snapshots_list = Snapshot.list(
            self.apiclient,
            volumeid=data_volume.id,
            listall=True)

        snap_list_validation_result = validateList(snapshots_list)

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

        snap_count = len(snapshots_list)

        # Step 3
        self.debug(
            "Creating Multiple Snapshots(Should create more than 10).....")
        try:
            while snap_count <= 12:
                Snapshot.create(
                    self.apiclient,
                    data_volume.id)

                snapshots_list = Snapshot.list(
                    self.apiclient,
                    volumeid=data_volume.id,
                    listall=True)

                snap_list_validation_result = validateList(snapshots_list)

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

                snap_count = len(snapshots_list)
        except Exception as e:
            snapshots_list = Snapshot.list(
                self.apiclient,
                volumeid=data_volume.id,
                listall=True)

            snap_list_validation_result = validateList(snapshots_list)

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

            assert len(snapshots_list) >= 10,\
                "Less than 10 snapshots created...."
            raise Exception("Snapshot creation failed !: %s" % e)

        return
    def test_01_storage_snapshots_limits(self):
        """ Storage and Snapshot Limit
            1.   Create Snapshot of ROOT disk.
            2.   Verify the Secondary Storage value
                 is increased by the size of snapshot.
            3.   Delete Snaphshot.
            4.   Verify the Secondary
                 Storage value is decreased by the size of snapshot.
            5.   Set the Snapshot limit of Account.
            6.   Create Snasphots till limit is reached.
            7.   Create Snapshot of ROOT Volume.
                 Creation should fail.
            8.   Delete few Snapshots.
            9.   Create Snapshot again.
                 Creation should succeed.
        """

        # Get ROOT Volume
        root_volumes_list = Volume.list(
            self.userapiclient,
            virtualmachineid=self.vm.id,
            type='ROOT'
        )

        status = validateList(root_volumes_list)
        self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed")

        root_volume = root_volumes_list[0]

        self.data_volume_created = Volume.create(
            self.userapiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id
        )

        self.cleanup.append(self.data_volume_created)

        data_volumes_list = Volume.list(
            self.userapiclient,
            id=self.data_volume_created.id
        )

        status = validateList(data_volumes_list)
        self.assertEqual(status[0], PASS, "DATA Volume List Validation Failed")

        self.data_volume = data_volumes_list[0]

        self.vm.attach_volume(
            self.userapiclient,
            self.data_volume
        )

        # Get Secondary Storage Value from Database
        qryresult_before_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_before_snapshot)
        self.assertEqual(
            status[0],
            PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageBeforeSnapshot = qryresult_before_snapshot[0][2]

        # Step 1
        snapshot = Snapshot.create(
            self.userapiclient,
            root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ],
            True,
            "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state
        )

        # Step 2
        qryresult_after_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_after_snapshot)
        self.assertEqual(
            status[0],
            PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageAfterSnapshotCreated = qryresult_after_snapshot[0][2]

        snapshot_size = snapshots_list[0].physicalsize
        secStorageIncreased = secStorageBeforeSnapshot + \
            snapshot_size

        self.assertEqual(
            secStorageIncreased,
            secStorageAfterSnapshotCreated,
            "Secondary storage Total after Snapshot\
                        should be incremented by size of snapshot.")

        # Step 3
        snapshot.delete(self.apiclient)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Step 4
        qryresult_after_snapshot_deleted = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_after_snapshot_deleted)
        self.assertEqual(
            status[0],
            PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageAfterSnapshotDeleted = qryresult_after_snapshot_deleted[0][2]

        secStorageDecreased = secStorageAfterSnapshotCreated - \
            snapshot_size

        self.assertEqual(
            secStorageDecreased,
            secStorageAfterSnapshotDeleted,
            "Secondary storage Total after Snapshot\
                        should be incremented by size of snapshot.")

        # Step 5
        # Set Snapshot Limit for account
        Resources.updateLimit(self.apiclient, resourcetype=3,
                              max=1, account=self.account.name,
                              domainid=self.account.domainid)

        # Step 6
        snapshot = Snapshot.create(
            self.userapiclient,
            root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ],
            True,
            "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state
        )

        # Step 7
        with self.assertRaises(Exception):
            Snapshot.create(
                self.userapiclient,
                self.data_volume.id)

        # Step 8
        snapshot.delete(self.userapiclient)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Step 9
        snapshot = Snapshot.create(
            self.userapiclient,
            root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ],
            True,
            "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state
        )

        return
    def test_01_concurrent_snapshot_global_limit(self):
        """ Test if global value concurrent.snapshots.threshold.perhost
            value respected
            This is positive test cases and tests if we are able to create
            as many snapshots mentioned in global value
        # 1. Create an account and a VM in it
        # 2. Read the global value for concurrent.snapshots.threshold.perhost
        # 3. If the value is Null, create at least 10 concurrent snapshots
             and verify they are created successfully
        # 4. Else, create as many snapshots specified in the global value, and
             verify they are created successfully
        """

        # Create an account
        account = Account.create(
            self.apiclient,
            self.testdata["account"],
            domainid=self.domain.id
        )

        self.cleanup.append(account)
        # Create user api client of the account
        userapiclient = self.testClient.getUserApiClient(
            UserName=account.name,
            DomainName=account.domain
        )

        # Create VM
        virtual_machine = VirtualMachine.create(
            userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=account.name,
            domainid=account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id
        )

        # Create 10 concurrent snapshots by default
        # We can have any value, so keeping it 10 as it
        # seems good enough to test
        concurrentSnapshots = 10

        # Step 1
        # Get ROOT Volume Id
        volumes = Volume.list(
            self.apiclient,
            virtualmachineid=virtual_machine.id,
            type='ROOT',
            listall=True
        )

        self.assertEqual(validateList(volumes)[0], PASS,
                         "Volumes list validation failed")

        root_volume = volumes[0]

        config = Configurations.list(
            self.apiclient,
            name="concurrent.snapshots.threshold.perhost"
        )
        self.assertEqual(
            isinstance(
                config,
                list),
            True,
            "concurrent.snapshots.threshold.perhost should be present\
                    in global config")
        if config[0].value:
            concurrentSnapshots = int(config[0].value)
        self.debug("concurrent Snapshots: %s" % concurrentSnapshots)

        threads = []
        for i in range(0, (concurrentSnapshots)):
            thread = Thread(
                target=Snapshot.create,
                args=(
                    self.apiclient,
                    root_volume.id
                ))
            threads.append(thread)
            thread.start()
        for thread in threads:
            thread.join()

        snapshots = Snapshot.list(self.apiclient,
                                  volumeid=root_volume.id,
                                  listall=True)

        self.assertEqual(validateList(snapshots)[0], PASS,
                         "Snapshots list validation failed")
        self.assertEqual(
            len(snapshots),
            concurrentSnapshots,
            "There should be exactly %s snapshots present" %
            concurrentSnapshots)

        for snapshot in snapshots:
            self.assertEqual(str(snapshot.state).lower(), BACKED_UP,
                             "Snapshot state should be backedUp but it is\
                            %s" % snapshot.state)
        return
    def test_04_reoccuring_snapshot_rules(self):
        """
        1) Create a VM using the Service offering IsVolatile enabled
        2) Apply a recurring snapshot rule on the  Volume.
        3) After a couple of snapshots are taken reboot the VM.

        Verify the following conditions
        1) New root disk should be formed
        2) The recurring snapshot rule should be deleted
        """
        self.hypervisor = self.testClient.getHypervisorInfo()
        vms = VirtualMachine.list(
                                  self.apiclient,
                                  id=self.vm_with_reset.id,
                                  listall=True
                                  )

        vm_list_validation_result = validateList(vms)

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

        vm_with_reset = vm_list_validation_result[1]
        vm_with_reset_root_disk_id = self.get_root_device_uuid_for_vm(
                                            vm_with_reset.id,
                                            vm_with_reset.rootdeviceid
                                        )

        self.debug("Creating recurring snapshot policy for root disk on vm created with IsVolatile=True")
        self.debug("Snapshot Policy - Type : %s Scheduled Hours : %s" %(
            self.services["recurring_snapshot"]["intervaltype"],
            self.services["recurring_snapshot"]["schedule"]))

        recurring_snapshot = SnapshotPolicy.create(
                                           self.apiclient,
                                           vm_with_reset_root_disk_id,
                                           self.services["recurring_snapshot"]
                                        )

        #ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = SnapshotPolicy.list(
                                                     self.apiclient,
                                                     id=recurring_snapshot.id,
                                                     volumeid=vm_with_reset_root_disk_id
                                                     )

        snapshot_list_validation_result = validateList(list_snapshots_policy)

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

        snapshots_policy = snapshot_list_validation_result[1]

        self.assertEqual(
                        snapshots_policy.id,
                        recurring_snapshot.id,
                        "Check recurring snapshot id in list resources call"
                        )
        self.assertEqual(
                        snapshots_policy.maxsnaps,
                        self.services["recurring_snapshot"]["maxsnaps"],
                        "Check interval type in list resources call"
                        )
        sleep_seconds = (self.services["recurring_snapshot"]["schedule"]) * 3600 + 600
        sleep_minutes = sleep_seconds/60
        self.debug("Sleeping for %s minutes till the volume is snapshoted" %sleep_minutes)
        time.sleep(sleep_seconds)

        retriesCount = self.services["retriesCount"]
        while True:
            snapshots = Snapshot.list(
                        self.apiclient,
                        volumeid=vm_with_reset_root_disk_id,
                        intervaltype=\
                        self.services["recurring_snapshot"]["intervaltype"],
                        snapshottype=RECURRING,
                        listall=True
                        )

            snapshot_list_validation_result = validateList(snapshots)

            if snapshot_list_validation_result[0] == PASS:
                break

            elif retriesCount == 0:
                self.fail("Failed to get snapshots list")

            time.sleep(60)
            retriesCount = retriesCount - 1

        # rebooting the vm with isVolatile = True
        try:
            self.vm_with_reset.reboot(self.apiclient)
        except Exception as e:
            self.fail("Failed to reboot the virtual machine. Error: %s" % e)

        # Check if the the root disk was destroyed and recreated for isVolatile=True
        self.debug("Checking whether root disk of VM with isVolatile=True was destroyed")
        vms = VirtualMachine.list(
                                  self.apiclient,
                                  id=self.vm_with_reset.id,
                                  listall=True
                                  )

        vm_list_validation_result = validateList(vms)

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

        vm_with_reset_after_reboot = vm_list_validation_result[1]

        vm_with_reset_root_disk_id_after_reboot = self.get_root_device_uuid_for_vm(
                                                        vm_with_reset_after_reboot.id,
                                                        vm_with_reset_after_reboot.rootdeviceid
                                                    )

        self.assertNotEqual(vm_with_reset_root_disk_id,
                            vm_with_reset_root_disk_id_after_reboot,
                            "VM created with IsVolatile=True has same rootdeviceid : %s after reboot" %vm_with_reset_root_disk_id_after_reboot
                        )
        # Make sure it has the same IP after reboot
        self.assertEqual(vm_with_reset.nic[0].ipaddress,
                            vm_with_reset_after_reboot.nic[0].ipaddress,
                            "VM created with IsVolatile=True doesn't have same ip after reboot. Got : %s Expected : %s"
                            %(vm_with_reset_after_reboot.nic[0].ipaddress, vm_with_reset.nic[0].ipaddress)
                        )

        # Check whether the recurring policy has been deleted from the database
        self.debug("Checking whether snapshot rule for VM with isVolatile=True was destroyed \
                   Here we are passing root disk id of vm before reboot which does not exist hence\
                   listing should fail")

        with self.assertRaises(Exception):
            listSnapshotPolicies = SnapshotPolicy.list(
                                        self.apiclient,
                                        volumeid=vm_with_reset_root_disk_id)
            self.assertEqual(
                    validateList(listSnapshotPolicies)[0],
                    PASS,
                    "snapshot policies list validation failed"
                    )
        return
Пример #31
0
    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
    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_02_snapshot_size_check(self):
        """ Check Snapshots size in database
            1. Create file on ROOT disk of deployed VM.
            2. Create Snapshot of ROOT disk.
            3. Check if physiacal_size parameter of snapshot_store_ref table
               has physical size of snapshot
        """
        if self.hypervisor.lower() not in ["xenserver", "vmware"]:
            self.skipTest("Test not to be run on %s" % self.hypervisor)

        root_volumes_list = list_volumes(self.apiclient,
                                         virtualmachineid=self.vm.id,
                                         type=ROOT,
                                         listall=True)

        status = validateList(root_volumes_list)
        self.assertEqual(status[0], PASS,
                         "Check listVolumes response for ROOT Disk")

        root_volume = root_volumes_list[0]

        # Get Secondary Storage Value from Database
        qryresult_before_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)

        self.assertNotEqual(
            len(qryresult_before_snapshot), 0,
            "Check sql query to return SecondaryStorageTotal of account")

        storage_qry_result_old = qryresult_before_snapshot[0]
        secondary_storage_old = storage_qry_result_old[2]

        createChecksum(self.testdata, self.vm, root_volume, "rootdiskdevice")

        time.sleep(30)

        root_vol_snapshot = Snapshot.create(self.apiclient, root_volume.id)

        snapshots_list = Snapshot.list(self.apiclient, id=root_vol_snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Check listSnapshots response")
        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ], True, "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state)

        self.assertEqual(
            snapshots_list[0].volumeid, root_volume.id,
            "Snapshot volume id is not matching with the vm's volume id")

        qryresult_snp_id = self.dbclient.execute("select id\
                        from snapshots where uuid = '%s';" %
                                                 snapshots_list[0].id)

        self.assertNotEqual(
            len(qryresult_snp_id), 0,
            "Check sql query to return physical size of the snapshot")

        snp_id_result = qryresult_snp_id[0]
        snp_id = snp_id_result[0]

        qryresult_physical_size = self.dbclient.execute(
            " select id, store_id, physical_size\
                        from snapshot_store_ref where snapshot_id = '%s' \
                        and store_role='Image';" % snp_id)

        self.assertNotEqual(
            len(qryresult_physical_size), 0,
            "Check sql query to return SecondaryStorageTotal of account")

        snapshot_physical_size_result = qryresult_physical_size[0]
        snapshot_physical_size = snapshot_physical_size_result[2]

        # Step 3
        qryresult_after_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)
        self.assertNotEqual(
            len(qryresult_after_snapshot), 0,
            "Check sql query to return SecondaryStorageTotal of account")

        storage_qry_result_from_database = qryresult_after_snapshot[0]
        secondary_storage_new = storage_qry_result_from_database[2]

        secondary_storage_after_snapshot = secondary_storage_new - \
            secondary_storage_old

        self.assertEqual(
            snapshot_physical_size, secondary_storage_after_snapshot,
            "Check if physical_size attribute of snapshot_store_ref table \
                stores correct value")

        return
    def test_04_reoccuring_snapshot_rules(self):
        """
        1) Create a VM using the Service offering IsVolatile enabled
        2) Apply a recurring snapshot rule on the  Volume.
        3) After a couple of snapshots are taken reboot the VM.

        Verify the following conditions
        1) New root disk should be formed
        2) The recurring snapshot rule should be deleted
        """
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ['lxc']:
            raise self.SkipTest(
                "Template creation from root volume is not supported in LXC")
        vms = VirtualMachine.list(self.apiclient,
                                  id=self.vm_with_reset.id,
                                  listall=True)

        vm_list_validation_result = validateList(vms)

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

        vm_with_reset = vm_list_validation_result[1]
        vm_with_reset_root_disk_id = self.get_root_device_uuid_for_vm(
            vm_with_reset.id, vm_with_reset.rootdeviceid)

        self.debug(
            "Creating recurring snapshot policy for root disk on vm created with IsVolatile=True"
        )
        self.debug("Snapshot Policy - Type : %s Scheduled Hours : %s" %
                   (self.services["recurring_snapshot"]["intervaltype"],
                    self.services["recurring_snapshot"]["schedule"]))

        recurring_snapshot = SnapshotPolicy.create(
            self.apiclient, vm_with_reset_root_disk_id,
            self.services["recurring_snapshot"])

        #ListSnapshotPolicy should return newly created policy
        list_snapshots_policy = SnapshotPolicy.list(
            self.apiclient,
            id=recurring_snapshot.id,
            volumeid=vm_with_reset_root_disk_id)

        snapshot_list_validation_result = validateList(list_snapshots_policy)

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

        snapshots_policy = snapshot_list_validation_result[1]

        self.assertEqual(snapshots_policy.id, recurring_snapshot.id,
                         "Check recurring snapshot id in list resources call")
        self.assertEqual(snapshots_policy.maxsnaps,
                         self.services["recurring_snapshot"]["maxsnaps"],
                         "Check interval type in list resources call")
        sleep_seconds = (
            self.services["recurring_snapshot"]["schedule"]) * 3600 + 600
        sleep_minutes = sleep_seconds / 60
        self.debug("Sleeping for %s minutes till the volume is snapshoted" %
                   sleep_minutes)
        time.sleep(sleep_seconds)

        retriesCount = self.services["retriesCount"]
        while True:
            snapshots = Snapshot.list(
                        self.apiclient,
                        volumeid=vm_with_reset_root_disk_id,
                        intervaltype=\
                        self.services["recurring_snapshot"]["intervaltype"],
                        snapshottype=RECURRING,
                        listall=True
                        )

            snapshot_list_validation_result = validateList(snapshots)

            if snapshot_list_validation_result[0] == PASS:
                break

            elif retriesCount == 0:
                self.fail("Failed to get snapshots list")

            time.sleep(60)
            retriesCount = retriesCount - 1

        # rebooting the vm with isVolatile = True
        try:
            self.vm_with_reset.reboot(self.apiclient)
        except Exception as e:
            self.fail("Failed to reboot the virtual machine. Error: %s" % e)

        # Check if the the root disk was destroyed and recreated for isVolatile=True
        self.debug(
            "Checking whether root disk of VM with isVolatile=True was destroyed"
        )
        vms = VirtualMachine.list(self.apiclient,
                                  id=self.vm_with_reset.id,
                                  listall=True)

        vm_list_validation_result = validateList(vms)

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

        vm_with_reset_after_reboot = vm_list_validation_result[1]

        vm_with_reset_root_disk_id_after_reboot = self.get_root_device_uuid_for_vm(
            vm_with_reset_after_reboot.id,
            vm_with_reset_after_reboot.rootdeviceid)

        self.assertNotEqual(
            vm_with_reset_root_disk_id,
            vm_with_reset_root_disk_id_after_reboot,
            "VM created with IsVolatile=True has same rootdeviceid : %s after reboot"
            % vm_with_reset_root_disk_id_after_reboot)
        # Make sure it has the same IP after reboot
        self.assertEqual(
            vm_with_reset.nic[0].ipaddress,
            vm_with_reset_after_reboot.nic[0].ipaddress,
            "VM created with IsVolatile=True doesn't have same ip after reboot. Got : %s Expected : %s"
            % (vm_with_reset_after_reboot.nic[0].ipaddress,
               vm_with_reset.nic[0].ipaddress))

        # Check whether the recurring policy has been deleted from the database
        self.debug(
            "Checking whether snapshot rule for VM with isVolatile=True was destroyed \
                   Here we are passing root disk id of vm before reboot which does not exist hence\
                   listing should fail")

        with self.assertRaises(Exception):
            listSnapshotPolicies = SnapshotPolicy.list(
                self.apiclient, volumeid=vm_with_reset_root_disk_id)
            self.assertEqual(
                validateList(listSnapshotPolicies)[0], PASS,
                "snapshot policies list validation failed")
        return
Пример #35
0
    def test_01_delta_snapshots(self):
        """ Delta Snapshots
            1. Create file on ROOT disk of deployed VM.
            2. Create Snapshot of ROOT disk.
            3. Verify secondary storage count.
            4. Check integrity of Full Snapshot.
            5. Delete delta snaphshot and check integrity of\
               remaining snapshots.
            6. Delete full snapshot and verify it is deleted from\
               secondary storage.
        """
        checksum_created = []
        full_snapshot_count = 0
        delta_snapshot_count = 0

        # Mulitply delta max value by 2 to set loop counter
        # to create 2 Snapshot chains
        snapshot_loop_count = int(self.delta_max) * 2

        # Get ROOT Volume
        root_volumes_list = list_volumes(self.apiclient,
                                         virtualmachineid=self.vm.id,
                                         type=ROOT,
                                         listall=True)

        status = validateList(root_volumes_list)
        self.assertEqual(status[0], PASS,
                         "Check listVolumes response for ROOT Disk")

        root_volume = root_volumes_list[0]

        # Get Secondary Storage Value from Database
        qryresult_before_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)

        self.assertNotEqual(
            len(qryresult_before_snapshot), 0,
            "Check sql query to return SecondaryStorageTotal of account")

        storage_qry_result_old = qryresult_before_snapshot[0]
        secondary_storage_old = storage_qry_result_old[2]

        # Create Snapshots

        for i in range(snapshot_loop_count):

            # Step 1
            checksum_root = createChecksum(self.testdata, self.vm, root_volume,
                                           "rootdiskdevice")

            time.sleep(30)
            checksum_created.append(checksum_root)

            # Step 2
            root_vol_snapshot = Snapshot.create(self.apiclient, root_volume.id)

            self.snapshots_created.append(root_vol_snapshot)

            snapshots_list = Snapshot.list(self.apiclient,
                                           id=root_vol_snapshot.id)

            status = validateList(snapshots_list)
            self.assertEqual(status[0], PASS, "Check listSnapshots response")

            # Verify Snapshot state
            self.assertEqual(
                snapshots_list[0].state.lower() in [
                    BACKED_UP,
                ], True, "Snapshot state is not as expected. It is %s" %
                snapshots_list[0].state)

            self.assertEqual(
                snapshots_list[0].volumeid, root_volume.id,
                "Snapshot volume id is not matching with the vm's volume id")

            # Step 3
            qryresult_after_snapshot = self.dbclient.execute(
                " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
                self.account.name)

            self.assertNotEqual(
                len(qryresult_after_snapshot), 0,
                "Check sql query to return SecondaryStorageTotal of account")

            storage_qry_result_from_database = qryresult_after_snapshot[0]
            secondary_storage_from_database = storage_qry_result_from_database[
                2]

            snapshot_size = snapshots_list[0].physicalsize
            secondary_storage_after_snapshot = secondary_storage_old + \
                snapshot_size

            # Reset full_snapshot_count to 0 before start of new snapshot chain
            if delta_snapshot_count == (int(self.delta_max) - 1):
                full_snapshot_count = 0
                delta_snapshot_count = 0

            # Full Snapshot of each Snapshot chain
            if full_snapshot_count == 0:

                full_snapshot_count += 1
                full_snapshot_size = snapshot_size

                # Check secondary storage count for Full Snapshots
                self.assertEqual(
                    secondary_storage_from_database,
                    secondary_storage_after_snapshot,
                    "Secondary storage count after full snapshot\
                                should be incremented by size of snapshot.")
                # Step 4
                checkIntegrityOfSnapshot(self,
                                         snapshots_list[0],
                                         checksum_root,
                                         disk_type=DATA)

            else:

                # Delta Snapshot of each Snapshot chain
                delta_snapshot_count += 1
                delta_snapshot_size = snapshot_size

                # Check secondary storage count for Delta Snapshots
                self.assertTrue(
                    delta_snapshot_size < full_snapshot_size,
                    "Delta Snapshot size should be less than\
                                Full Snapshot.")

                self.assertEqual(
                    secondary_storage_from_database,
                    secondary_storage_after_snapshot,
                    "Secondary storage count after delta snapshot\
                                should be incremented by size of snapshot.")

            secondary_storage_old = secondary_storage_from_database

        # Step 5

        # Check in Secondary Storage- Snapshots: S1, S2, S3 are present
        for i in range(int(self.delta_max)):
            self.assertTrue(
                is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                                   self.zone.id, self.snapshots_created[i].id),
                "Check: Snapshot is not on Secondary Storage.")

        # Delete S2

        Snapshot.delete(self.snapshots_created[1], self.apiclient)

        snapshots_list = Snapshot.list(self.apiclient,
                                       id=self.snapshots_created[1].id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Check integrity of Snapshots for S1 and S3
        checkIntegrityOfSnapshot(self,
                                 self.snapshots_created[0],
                                 checksum_created[0],
                                 disk_type=DATA)

        checkIntegrityOfSnapshot(self,
                                 self.snapshots_created[2],
                                 checksum_created[2],
                                 disk_type=DATA)

        # Delete S3

        Snapshot.delete(self.snapshots_created[2], self.apiclient)

        snapshots_list = Snapshot.list(self.apiclient,
                                       id=self.snapshots_created[2].id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Check in Secondary Storage - Snapshots: S2, S3 are deleted
        self.assertFalse(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, self.snapshots_created[2].id),
            "Check: Snapshot 2 is still on Secondary Storage. Not Deleted.")

        self.assertFalse(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, self.snapshots_created[1].id),
            "Check: Snapshot 3 is still on Secondary Storage. Not Deleted.")

        # Restore Snapshots for S1
        checkIntegrityOfSnapshot(self,
                                 self.snapshots_created[0],
                                 checksum_created[0],
                                 disk_type=DATA)

        # Step 6
        # Delete S1

        Snapshot.delete(self.snapshots_created[0], self.apiclient)

        snapshots_list = Snapshot.list(self.apiclient,
                                       id=self.snapshots_created[0].id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Check in Secondary Storage - Snapshots: All - S1, S2, S3 are deleted

        self.assertFalse(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, self.snapshots_created[2].id),
            "Check: Snapshot 3 is still on Secondary Storage. Not Deleted.")

        self.assertFalse(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, self.snapshots_created[1].id),
            "Check: Snapshot 2 is still on Secondary Storage. Not Deleted.")

        self.assertFalse(
            is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config,
                               self.zone.id, self.snapshots_created[0].id),
            "Check: Snapshot 1 is still on Secondary Storage. Not Deleted.")

        return