Example #1
0
    def test_22_volume_from_snapshot_bypassed(self):
        '''Create volume from snapshot (with uuid) on secondary, which volume was deleted
            and snapshot does not exists on StorPool or snapshot_details DB table
        '''
        #check that the snapshot exists on StorPool
        globalIdName = self.snapshot_uuid4.id
        try:
            sp_snapshot = self.spapi.snapshotList(
                snapshotName=self.snapshot_uuid4.id)
        except spapi.ApiError as err:
            raise Exception(err)

        volume = self.helper.create_volume(snapshotid=self.snapshot_uuid4.id)
        flag = False
        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = self.snapshot_uuid4.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            cfg.logger.info("Snapshot details %s", snapshot_details)
            cfg.logger.info("Snapshot with uuid %s", self.snapshot_uuid4.id)
            for s in snapshot_details:
                if s["snapshotDetailsName"] == self.snapshot_uuid4.id:
                    name = s["snapshotDetailsValue"].split("/")[3]
                    sp_snapshot = self.spapi.snapshotList(snapshotName="~" +
                                                          name)
                    flag = True
        except spapi.ApiError as err:
            raise Exception(err)
        if flag == False:
            raise Exception("Could not find snapshot in snapshot details")
        self._cleanup.append(volume)
Example #2
0
 def test_04_snapshot_volume_bypass_secondary(self):
     '''
         Test snapshot bypassing secondary
     '''
     Configurations.update(self.apiclient,
         name = "sp.bypass.secondary.storage",
         value = "true")
     volume = list_volumes(
                     self.apiclient,
                     virtualmachineid = self.virtual_machine.id,
                     type = "ROOT",
                     listall = True,
                     )
     snapshot = Snapshot.create(
        self.apiclient,
         volume_id = volume[0].id,
         account=self.account.name,
         domainid=self.account.domainid,
         )
     try:
         cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
         cmd.snapshotid = snapshot.id
         snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
         flag = False
         for s in snapshot_details:
             if s["snapshotDetailsName"] == snapshot.id:
                 name = s["snapshotDetailsValue"].split("/")[3]
                 sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                 flag = True
                 self.debug('################ %s' % sp_snapshot)
         if flag == False:
             raise Exception("Could not find snapshot in snapshot details")
     except spapi.ApiError as err:
         raise Exception(err)
     self.assertIsNotNone(snapshot, "Could not create snapshot")
Example #3
0
    def test_21_volume_from_snapshot_secondary(self):
        '''Create volume from snapshot(with uuid) on secondary, which volume was deleted
            and snapshot does not exists on StorPool or snapshot_details DB table
        '''
        #check that snapshot exists on StorPool
        try:
            sp_snapshot = self.spapi.snapshotList(
                snapshotName=self.snapshot_uuid3.id)
        except spapi.ApiError as err:
            raise Exception(err)

        #remove the snapshot from StorPool so it has to be downloaded from secondary
        self.spapi.snapshotDelete(snapshotName=self.snapshot_uuid3.id)
        volume = self.helper.create_volume(snapshotid=self.snapshot_uuid3.id)
        flag = False
        #new snapshot has to be added to snapshot_details and created new snapshot in StorPool
        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = self.snapshot_uuid3.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            cfg.logger.info("Snapshot details %s", snapshot_details)
            cfg.logger.info("Snapshot with uuid %s", self.snapshot_uuid3.id)
            for s in snapshot_details:
                if s["snapshotDetailsName"] == self.snapshot_uuid3.id:
                    name = s["snapshotDetailsValue"].split("/")[3]
                    sp_snapshot = self.spapi.snapshotList(snapshotName="~" +
                                                          name)
                    flag = True
        except spapi.ApiError as err:
            raise Exception(err)
        if flag == False:
            raise Exception("Could not find snapshot in snapshot details")
        self._cleanup.append(volume)
Example #4
0
    def test_08_snapshot_detached_volume(self):
        ''' Test Snapshot Detached Volume
        '''
        self.virtual_machine.stop(
            self.apiclient,
            forced = True
            )
        self.volume = self.virtual_machine.attach_volume(
            self.apiclient,
            self.volume
            )
        self.assertIsNotNone(self.volume, "Attach: Is none")
        self.volume = self.virtual_machine.detach_volume(
            self.apiclient,
            self.volume
            )

        self.assertIsNotNone(self.volume, "Detach: Is none")
 
        snapshot = Snapshot.create(
            self.apiclient,
            self.volume.id,
            account=self.account.name,
            domainid=self.account.domainid,
            )

        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            flag = False
            for s in snapshot_details:
                if s["snapshotDetailsName"] == snapshot.id:
                    name = s["snapshotDetailsValue"].split("/")[3]
                    sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                    self.debug('################ %s' % sp_snapshot)
                    flag = True
            if flag == False:
                raise Exception("Could not find snapshot in snapshot details")
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertIsNotNone(snapshot, "Snapshot is None")

        self.assertIsInstance(snapshot, Snapshot, "Snapshot is not Instance of Snappshot")

        snapshot = Snapshot.delete(
            snapshot,
            self.apiclient
            )

        self.assertIsNone(snapshot, "Snapshot was not deleted")
Example #5
0
    def test_07_snapshot_to_volume(self):
        ''' Create volume from snapshot
        '''
        snapshot = Snapshot.create(
            self.apiclient,
            volume_id = self.volume_2.id,
            account=self.account.name,
            domainid=self.account.domainid,
            )

        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            flag = False
            for s in snapshot_details:
                if s["snapshotDetailsName"] == snapshot.id:
                    name = s["snapshotDetailsValue"].split("/")[3]
                    sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                    self.debug('################ %s' % sp_snapshot)
                    flag = True
            if flag == False:
                raise Exception("Could not find snapshot in snapshot details")
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertIsNotNone(snapshot, "Could not create snapshot")
        self.assertIsInstance(snapshot, Snapshot, "Snapshot is not an instance of Snapshot")

        volume = self.helper.create_custom_disk(
            self.apiclient,
            {"diskname":"StorPoolDisk" },
            account=self.account.name,
            domainid=self.account.domainid,
            zoneid = self.zone.id,
            snapshotid = snapshot.id
            )

        listvol = Volume.list(
            self.apiclient,
            id=volume.id,
            listall= True
            )
        name = listvol[0].path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertIsNotNone(volume, "Could not create volume from snapshot")
        self.assertIsInstance(volume, Volume, "Volume is not instance of Volume")
Example #6
0
    def get_snapshot_template_id(self, apiclient, snapshot, storage_pool_id):
        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = apiclient.getVolumeSnapshotDetails(cmd)
            logging.debug("Snapshot details %s" % snapshot_details)
            logging.debug("Snapshot with uuid %s" % snapshot.id)
            for s in snapshot_details:
                if s["snapshotDetailsName"] == storage_pool_id:
                    return s["snapshotDetailsValue"]
        except Exception as err:
            raise Exception(err)

        return None
Example #7
0
    def test_09_snapshot_root_disk(self):
        ''' Test ROOT Disk Snapshot 
        '''
        vm = VirtualMachine.create(self.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid = self.zone.id,
            templateid = self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid = self.service_offering.id,
            hypervisor = self.hypervisor,
            hostid = self.host[0].id,
            rootdisksize = 10
            )
        list_volumes_of_vm = list_volumes(
            self.apiclient,
            virtualmachineid = vm.id,
            listall = True
            )
        self.assertIs(len(list_volumes_of_vm), 1, "VM has more disk than 1")

        snapshot = Snapshot.create(
            self.apiclient,
            list_volumes_of_vm[0].id,
            account=self.account.name,
            domainid=self.account.domainid,
            )

        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            flag = False
            for s in snapshot_details:
                if s["snapshotDetailsName"] == snapshot.id:
                    name = s["snapshotDetailsValue"].split("/")[3]
                    sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                    self.debug('################ %s' % sp_snapshot)
                    flag = True
            if flag == False:
                raise Exception("Could not find snapshot in snapshot details")
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertIsNotNone(snapshot, "Snapshot is None")

        self.assertEqual(list_volumes_of_vm[0].id, snapshot.volumeid, "Snapshot is not for the same volume")
Example #8
0
 def getSnapshotName(cls, snapshot):
     try:
         cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
         cmd.snapshotid = snapshot.id
         snapshot_details = cls.apiclient.getVolumeSnapshotDetails(cmd)
         flag = False
         for s in snapshot_details:
             if s["snapshotDetailsName"] == snapshot.id:
                 name = s["snapshotDetailsValue"].split("/")[3]
                 sp_snapshot = cls.spapi.snapshotList(snapshotName = "~" + name)
                 flag = True
                 cls.debug('################ %s' % sp_snapshot)
                 return "~" + name
         if flag == False:
             raise Exception("Could not find snapshot in snapshot details")
     except spapi.ApiError as err:
        raise Exception(err)
Example #9
0
    def test_10_snapshot_to_template_bypass_secondary(self):
        ''' Test Create Template bypassing secondary storage from snapshot on secondary storage
        '''
        ##cls.virtual_machine
        volume = list_volumes(
                        self.apiclient,
                        virtualmachineid = self.virtual_machine.id,
                        type = "ROOT",
                        listall = True,
                        )
        try:
            name = volume[0].path.split("/")[3]
            sp_volume = self.spapi.volumeList(volumeName = "~" + name)
            self.debug('################ %s' % sp_volume)
        except spapi.ApiError as err:
            raise Exception(err)

        Configurations.update(self.apiclient,
            name = "sp.bypass.secondary.storage",
            value = "false")

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

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

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


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

        snapshot = Snapshot.create(
           self.apiclient,
            volume_id = volume[0].id,
            account=self.account.name,
            domainid=self.account.domainid,
            )
        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            flag = False
            for s in snapshot_details:
                if s["snapshotDetailsName"] == snapshot.id:
                    name = s["snapshotDetailsValue"].split("/")[3]
                    sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                    flag = True
                    self.debug('################ %s' % sp_snapshot)
            if flag == False:
                raise Exception("Could not find snasphot in snapshot_details")
        except spapi.ApiError as err:
               raise Exception(err)

        self.assertIsNotNone(snapshot, "Could not create snapshot")
        self.assertIsInstance(snapshot, Snapshot, "Snapshot is not an instance of Snapshot")

        Configurations.update(self.apiclient,
            name = "sp.bypass.secondary.storage",
            value = "true")

        template = self.helper.create_template_from_snapshot(
            self.apiclient,
            self.services,
            snapshotid = snapshot.id
            )

        flag = False
        sp_snapshots = self.spapi.snapshotsList()
        for snap in sp_snapshots:
            tags = snap.tags
            for t in tags:
                if tags[t] == template.id:
                    flag = True
                    break
            else:
                continue
            break

        if flag is False:
            raise Exception("Template does not exists in Storpool")
        virtual_machine = VirtualMachine.create(self.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid=self.zone.id,
            templateid=template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            hypervisor=self.hypervisor,
            rootdisksize=10
            )

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

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

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

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

        self.assertEqual(
            self.random_data_0,
            result[0],
            "Check the random data is equal with the ramdom file!"
        )
        self.assertIsNotNone(template, "Template is None")
        self.assertIsInstance(template, Template, "Template is instance of template")
        self._cleanup.append(template)
Example #10
0
    def test_09_vm_from_bypassed_template(self):
        '''Create virtual machine with sp.bypass.secondary.storage=false
        from template created on StorPool and Secondary Storage'''

        volume = list_volumes(
                        self.apiclient,
                        virtualmachineid = self.virtual_machine.id,
                        type = "ROOT",
                        listall = True,
                        )

        name = volume[0].path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
        except spapi.ApiError as err:
           raise Exception(err)

        Configurations.update(self.apiclient,
            name = "sp.bypass.secondary.storage",
            value = "true")

        snapshot = Snapshot.create(
           self.apiclient,
            volume_id = volume[0].id,
            account=self.account.name,
            domainid=self.account.domainid,
            )

        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            flag = False
            for s in snapshot_details:
                if s["snapshotDetailsName"] == snapshot.id:
                    name = s["snapshotDetailsValue"].split("/")[3]
                    try:
                        sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                        self.debug('################ %s' % sp_snapshot)
                        flag = True
                    except spapi.ApiError as err:
                       raise Exception(err)
            if flag == False:
                raise Exception("Could not find snapshot in snapshot details")
        except Exception as err:
            raise Exception(err)

        self.assertIsNotNone(snapshot, "Could not create snapshot")
        self.assertIsInstance(snapshot, Snapshot, "Snapshot is not an instance of Snapshot")

        template = self.helper.create_template_from_snapshot(
            self.apiclient,
            self.services,
            snapshotid = snapshot.id
            )
        self._cleanup.append(template)

        flag = False
        sp_snapshots = self.spapi.snapshotsList()
        for snap in sp_snapshots:
            tags = snap.tags
            for t in tags:
                if tags[t] == template.id:
                    flag = True
                    break
            else:
                continue
            break

        if flag is False:
            raise Exception("Template does not exists in Storpool")


        self.assertIsNotNone(template, "Template is None")
        self.assertIsInstance(template, Template, "Template is instance of template")

        Configurations.update(self.apiclient,
            name = "sp.bypass.secondary.storage",
            value = "false")  

        vm = VirtualMachine.create(
            self.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid=self.zone.id,
            templateid = template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            hypervisor=self.hypervisor,
            hostid = self.host[0].id,
            rootdisksize=10,
            )

        ssh_client = vm.get_ssh_client(reconnect=True)
Example #11
0
    def test_08_delete_snapshot_of_deleted_volume(self):
        ''' Delete snapshot and template if volume is already deleted, bypassing secondary
        '''

        Configurations.update(self.apiclient,
        name = "sp.bypass.secondary.storage",
        value = "true")

        volume = Volume.create(
            self.apiclient,
            {"diskname":"StorPoolDisk-Delete" },
            zoneid = self.zone.id,
            diskofferingid = self.disk_offerings.id,
            account=self.account.name,
            domainid=self.account.domainid,
            )
        delete = volume
        self.virtual_machine2.attach_volume(
            self.apiclient,
            volume
            )
        self.virtual_machine2.detach_volume(
            self.apiclient,
            volume
            )

        volume = list_volumes(self.apiclient, id = volume.id, listall = True,)

        name = volume[0].path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
        except spapi.ApiError as err:
           raise Exception(err)

        snapshot = Snapshot.create(
            self.apiclient,
             volume_id = volume[0].id
            )

        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            if snapshot_details is not None:
                flag = False
                for s in snapshot_details:
                    if s["snapshotDetailsName"] == snapshot.id:
                        name = s["snapshotDetailsValue"].split("/")[3]
                        try:
                            sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                            self.debug('################ %s' % sp_snapshot)
                            flag = True
                        except spapi.ApiError as err:
                           raise Exception(err)
                if flag == False:
                    raise Exception("Could not find snapshot in snapshot details")
        except Exception as err:
            raise Exception(err)  

        template = self.helper.create_template_from_snapshot(self.apiclient, self.services, snapshotid = snapshot.id)

        Volume.delete(delete, self.apiclient, )
        Snapshot.delete(snapshot, self.apiclient)

        flag = False
        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            if snapshot_details is not None:
                try:
                    for s in snapshot_details:
                        if s["snapshotDetailsName"] == snapshot.id:
                            name = s["snapshotDetailsValue"].split("/")[3]
                            sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                            self.debug('################ The snapshot had to be deleted %s' % sp_snapshot)
                            flag = True
                except spapi.ApiError as err:
                    flag = False
    
            if flag is True:
                raise Exception("Snapshot was not deleted")
        except Exception as err:
            self.debug('Snapshot was deleted %s' % err)
            

        Template.delete(template, self.apiclient, zoneid = self.zone.id)
Example #12
0
    def test_06_template_from_snapshot(self):
        ''' Test create template bypassing secondary from snapshot which is backed up on secondary storage
        '''
        ##cls.virtual_machine
        volume = list_volumes(
                        self.apiclient,
                        virtualmachineid = self.virtual_machine.id,
                        type = "ROOT",
                        listall = True,
                        )
        try:
            name = volume[0].path.split("/")[3]
            sp_volume = self.spapi.volumeList(volumeName = "~" + name)
            self.debug('################ %s' % sp_volume)
        except spapi.ApiError as err:
            raise Exception(err)

        Configurations.update(self.apiclient,
            name = "sp.bypass.secondary.storage",
            value = "false")

        snapshot = Snapshot.create(
           self.apiclient,
            volume_id = volume[0].id,
            account=self.account.name,
            domainid=self.account.domainid,
            )
        try:
            cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd()
            cmd.snapshotid = snapshot.id
            snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd)
            flag = False
            for s in snapshot_details:
                if s["snapshotDetailsName"] == snapshot.id:
                    name = s["snapshotDetailsValue"].split("/")[3]
                    sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name)
                    flag = True
                    self.debug('################ %s' % sp_snapshot)
            if flag == False:
                raise Exception("Could not find snapshot in snapshot details")
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertIsNotNone(snapshot, "Could not create snapshot")
        self.assertIsInstance(snapshot, Snapshot, "Snapshot is not an instance of Snapshot")

        Configurations.update(self.apiclient,
            name = "sp.bypass.secondary.storage",
            value = "true")

        template = self.helper.create_template_from_snapshot(
            self.apiclient,
            self.services,
            snapshotid = snapshot.id
            )

        flag = False
        globalId = None
        sp_snapshots = self.spapi.snapshotsList()
        for snap in sp_snapshots:
            tags = snap.tags
            for t in tags:
                if tags[t] == template.id:
                    flag = True
                    globalId = snap.globalId
                    break
            else:
                continue
            break

        if flag is False:
            raise Exception("Template does not exists in Storpool")


        self.assertIsNotNone(template, "Template is None")
        self.assertIsInstance(template, Template, "Template is instance of template")
        temp = Template.delete(template, self.apiclient, self.zone.id)
        self.assertIsNone(temp, "Template was not deleted")

        if globalId is not None:
            try:
                sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + globalId)
                if sp_snapshot is not None:
                    raise Exception("Snapshot does not exists on Storpool name" + globalId)
            except spapi.ApiError as err:
                self.debug("Do nothing the template has to be deleted")
        else:
            flag = False
            sp_snapshots = self.spapi.snapshotsList()
            for snap in sp_snapshots:
                tags = snap.tags
                for t in tags:
                    if tags[t] == template.id:
                        flag = True
                        break
                else:
                    continue
                break

            if flag is True:
                raise Exception("Template should not exists in Storpool")