예제 #1
0
    def create_custom_disk(cls, apiclient, services, size = None, miniops = None, maxiops =None, diskofferingid=None, zoneid=None, account=None, domainid=None, snapshotid=None):
        """Create Volume from Custom disk offering"""
        cmd = createVolume.createVolumeCmd()
        cmd.name = services["diskname"]

        if diskofferingid:
            cmd.diskofferingid = diskofferingid

        if size:
            cmd.size = size

        if miniops:
            cmd.miniops = miniops

        if maxiops:
            cmd.maxiops = maxiops

        if account:
            cmd.account = account

        if domainid:
            cmd.domainid = domainid

        if snapshotid:
            cmd.snapshotid = snapshotid

        cmd.zoneid = zoneid

        return Volume(apiclient.createVolume(cmd).__dict__)
예제 #2
0
    def create_volume(self, apiclient, zoneid=None, snapshotid=None):
        """Create Volume"""
        cmd = createVolume.createVolumeCmd()
        cmd.name = "Test"

        if zoneid:
            cmd.zoneid = zoneid

        if snapshotid:
            cmd.snapshotid = snapshotid
        return Volume(apiclient.createVolume(cmd).__dict__)
예제 #3
0
    def runner(self, provisioning_type):
        self.services["disk_offering"]['provisioningtype'] = provisioning_type
        self.services["small"]['size'] = "1"
        disk_offering = DiskOffering.create(
            self.apiclient,
            self.services["disk_offering"],
            custom=True,
        )
        self.cleanup.append(disk_offering)

        self.debug("Created Disk offering with ID: %s" % disk_offering.id)

        self.services["service_offerings"]["small"][
            "provisioningtype"] = provisioning_type
        small_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offerings"]["small"])

        self.cleanup.append(small_offering)

        self.debug("Created service offering with ID: %s" % small_offering.id)

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

        self.debug("Created virtual machine with ID: %s" % virtual_machine.id)

        volumes = Volume.list(self.apiclient,
                              virtualMachineId=virtual_machine.id,
                              listAll='true')

        for volume in volumes:
            if volume["type"] == "DATADISK":
                VirtualMachine.detach_volume(virtual_machine, self.apiclient,
                                             volume)
                currentVolume = Volume({})
                currentVolume.id = volume.id
                Volume.resize(currentVolume, self.apiclient, size='2')
                VirtualMachine.attach_volume(virtual_machine, self.apiclient,
                                             volume)
 def create_from_snapshot(cls, apiclient, snapshot_id, services,
                          account=None, domainid=None):
         """Create volume from snapshot"""
         cmd = createVolume.createVolumeCmd()
         cmd.isAsync = "false"
         cmd.name = "-".join([services["diskname"], random_gen()])
         cmd.snapshotid = snapshot_id
         cmd.zoneid = services["zoneid"]
         if "size" in services:
             cmd.size = services["size"]
         if services["ispublic"]:
             cmd.ispublic = services["ispublic"]
         else:
             cmd.ispublic = False
         if account:
             cmd.account = account
         else:
             cmd.account = services["account"]
         if domainid:
             cmd.domainid = domainid
         else:
             cmd.domainid = services["domainid"]
         return Volume(apiclient.createVolume(cmd).__dict__)
예제 #5
0
    def test_06_create_volume_from_non_native_snapshot(self):

        old_supports_resign = self.supports_resign
        self._set_supports_resign(False)

        primary_storage_db_id = self._get_cs_storage_pool_db_id(
            self.primary_storage)

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

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

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

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

        vm_1_root_volume = list_volumes_response[0]

        dt_volume_1 = self._get_dt_volume_for_cs_volume(vm_1_root_volume)

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

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

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

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

        dt_snapshot_volume = self._get_dt_volume_for_cs_volume(
            volume_created_from_snapshot)

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

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

        self._delete_and_test_non_native_snapshot(vol_snap_a)

        virtual_machine.delete(self.apiClient, True)

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

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

        data_volume = list_volumes_response[0]

        data_volume_2 = Volume(data_volume.__dict__)

        data_volume_2.delete(self.apiClient)

        self._get_dt_volume_for_cs_volume(data_volume, should_exist=False)

        self._set_supports_resign(old_supports_resign)
예제 #6
0
    def test_08_increase_volume_size_within_account_limit(self):
        """Test increasing volume size within the account limit and verify
           primary storage usage

        # Validate the following
        # 1. Create a domain and its admin account
        # 2. Set account primary storage limit well beyond (20 GB volume +
        #    template size of VM)
        # 3. Deploy a VM without any disk offering (only root disk)
        #
        # 4. Increase (resize) the volume to 20 GB
        # 6. Resize operation should be successful and primary storage count
        #    for account should be updated successfully"""

        # Setting up account and domain hierarchy

        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])
        apiclient = self.testClient.getUserApiClient(
            UserName=self.parentd_admin.name,
            DomainName=self.parentd_admin.domain)
        self.assertNotEqual(
            apiclient, FAILED, "Failed to get api client\
                            of account: %s" % self.parentd_admin.name)

        templateSize = (self.template.size / (1024**3))
        accountLimit = (templateSize + 20)
        response = self.updateResourceLimits(accountLimit=accountLimit)
        self.assertEqual(response[0], PASS, response[1])

        try:

            if self.updateclone:

                self.virtual_machine = VirtualMachine.create(
                    apiclient,
                    self.services["virtual_machine"],
                    accountid=self.parentd_admin.name,
                    domainid=self.parent_domain.id,
                    serviceofferingid=self.services_offering_vmware.id)
            else:
                self.virtual_machine = VirtualMachine.create(
                    apiclient,
                    self.services["virtual_machine"],
                    accountid=self.parentd_admin.name,
                    domainid=self.parent_domain.id,
                    serviceofferingid=self.service_offering.id)
            list_vms = VirtualMachine.list(apiclient,
                                           id=self.virtual_machine.id)
            self.debug(
                "Verify listVirtualMachines response for virtual machine: %s" \
                % self.virtual_machine.id
            )
            self.assertEqual(isinstance(list_vms, list), True,
                             "List VM response was not a valid list")
            self.cleanup.append(self.virtual_machine)
            self.cleanup.reverse()
            vm = list_vms[0]
            list_volume_response = Volume.list(
                apiclient,
                virtualmachineid=self.virtual_machine.id,
                type='ROOT',
                listall='True')
            res = validateList(list_volume_response)
            self.assertNotEqual(
                res[2], INVALID_INPUT,
                "listVolumes returned invalid object in response")
            if vm.state == "Running" and vm.hypervisor.lower() == "xenserver":
                self.virtual_machine.stop(self.apiclient)
                time.sleep(self.services["sleep"])
            rootvolume = list_volume_response[0]
            # converting json response to Volume  Object
            rootvol = Volume(rootvolume.__dict__)
            newsize = (rootvolume.size >> 30) + 20
            if rootvolume is not None:
                try:
                    rootvol.resize(apiclient, size=newsize)
                    response = matchResourceCount(
                        self.apiclient,
                        newsize,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.parentd_admin.id)
                    if response[0] == FAIL:
                        raise Exception(response[1])
                except Exception as e:
                    self.fail("Failed with exception: %s" % e)

        except Exception as e:
            raise Exception("Warning: Exception while checking primary"
                            " storage capacity after root "
                            "volume resize  : %s" % e)

        return
예제 #7
0
    def test_07_usage_events_after_rootvolume_resized_(self):
        """Test check usage events after root volume resize

        # Validate the following

        # 1. Deploy a VM without any disk offering (only root disk)
        # 2. Perform(resize)  of the root  volume
        # 3. Check the corresponding usage events
        """

        # deploy a vm
        try:
            if self.updateclone:

                self.virtual_machine = VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.parentd_admin.name,
                    domainid=self.parent_domain.id,
                    serviceofferingid=self.services_offering_vmware.id,
                    mode=self.zone.networktype)
            else:
                self.virtual_machine = VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.parentd_admin.name,
                    domainid=self.parent_domain.id,
                    serviceofferingid=self.service_offering.id,
                    mode=self.zone.networktype)
            # listVirtual macine
            time.sleep(self.services["sleep"])
            list_vms = VirtualMachine.list(self.apiclient,
                                           id=self.virtual_machine.id)
            self.debug(
                "Verify listVirtualMachines response for virtual machine: %s" %
                self.virtual_machine.id)
            res = validateList(list_vms)
            self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
            self.cleanup.append(self.virtual_machine)
            vm = list_vms[0]
            self.assertEqual(vm.id, self.virtual_machine.id,
                             "Virtual Machine ids do not match")
            # get root vol from created vm, verify it is correct size
            list_volume_response = Volume.list(
                self.apiclient,
                virtualmachineid=self.virtual_machine.id,
                type='ROOT',
                listall='True')
            res = validateList(list_volume_response)
            self.assertNotEqual(
                res[2], INVALID_INPUT,
                "listVolumes returned invalid object in response")
            if vm.state == "Running" and vm.hypervisor.lower() == "xenserver":
                self.virtual_machine.stop(self.apiclient)
                time.sleep(self.services["sleep"])
            rootvolume = list_volume_response[0]
            # converting json response to Volume  Object
            rootvol = Volume(rootvolume.__dict__)
            newsize = (rootvolume.size >> 30) + 2
            success = False
            if rootvolume is not None:
                try:
                    rootvol.resize(self.apiclient, size=newsize)
                    qresultset = self.dbclient.execute(
                        "select id from account where uuid = '%s';" %
                        self.parentd_admin.id)

                    res = validateList(qresultset)
                    self.assertNotEqual(res[2], INVALID_INPUT,
                                        "Check DB Query result set")
                    qresult = qresultset[0]
                    account_id = qresult[0]
                    self.debug("select type,size from usage_event"
                               " where account_id = '%s';" % account_id)
                    qresultsize = self.dbclient.execute(
                        "select size from usage_event where account_id = '%s' "
                        "and type='VOLUME.RESIZE' ORDER BY ID  DESC LIMIT 1;" %
                        account_id)
                    res = validateList(qresultsize)
                    self.assertNotEqual(res[2], INVALID_INPUT,
                                        "Check DB Query result set")
                    qresult = int(qresultsize[0][0])
                    self.debug("Query result: %s" % qresult)
                    self.assertEqual(
                        qresult, (newsize * 1024 * 1024 * 1024),
                        "Usage event not logged properly with right volume"
                        " size please check ")
                except Exception as e:
                    raise Exception("Warning: Exception while checking usage "
                                    "event for the root volume resize : %s" %
                                    e)
        except Exception as e:
            raise Exception(
                "Warning: Exception performing "
                "usage_events_after_rootvolume_resized Test  : %s" % e)
예제 #8
0
    def test_06_resized_rootvolume_with_lessvalue(self):
        """Test resize root volume with less than original volume size

        # Validate the following

        # 1. Deploy a VM without any disk offering (only root disk)
        # 2. Perform(resize)  of the root  volume with less
         than current root volume
        # 3. Check for proper error message

        """

        # deploy a vm
        try:
            if self.updateclone:

                self.virtual_machine = VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.parentd_admin.name,
                    domainid=self.parent_domain.id,
                    serviceofferingid=self.services_offering_vmware.id,
                    mode=self.zone.networktype)
            else:
                self.virtual_machine = VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.parentd_admin.name,
                    domainid=self.parent_domain.id,
                    serviceofferingid=self.service_offering.id,
                    mode=self.zone.networktype)

            # listVirtual macine
            time.sleep(self.services["sleep"])
            list_vms = VirtualMachine.list(self.apiclient,
                                           id=self.virtual_machine.id)
            self.debug(
                "Verify listVirtualMachines response for virtual machine: %s" \
                % self.virtual_machine.id
            )
            res = validateList(list_vms)
            self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
            self.cleanup.append(self.virtual_machine)
            vm = list_vms[0]
            self.assertEqual(vm.id, self.virtual_machine.id,
                             "Virtual Machine ids do not match")
            # get root vol from created vm, verify it is correct size
            list_volume_response = Volume.list(
                self.apiclient,
                virtualmachineid=self.virtual_machine.id,
                type='ROOT',
                listall='True')
            res = validateList(list_volume_response)
            self.assertNotEqual(
                res[2], INVALID_INPUT,
                "listVolumes returned invalid object in response")
            if vm.state == "Running" and vm.hypervisor.lower() == "xenserver":
                self.virtual_machine.stop(self.apiclient)
                time.sleep(self.services["sleep"])

            rootvolume = list_volume_response[0]
            # converting json response to Volume  Object
            rootvol = Volume(rootvolume.__dict__)
            newsize = (rootvolume.size >> 30) - 1
            success = False
            if rootvolume is not None and 'vmware' in vm.hypervisor.lower():
                try:
                    rootvol.resize(self.apiclient, size=newsize)
                except Exception as e:
                    assert "Shrink operation on ROOT volume not supported" \
                           in e.message, \
                        "TestCase Failed,able to resize root volume  or error message is not matched"
        except Exception as e:
            raise Exception("Warning: Exception "
                            "during executing test resize"
                            " volume with less value : %s" % e)
            if rootvol is not None and 'kvm' or 'xenserver' in vm.hypervisor.lower(
            ):
                rootvol.resize(self.apiclient, size=newsize)
예제 #9
0
    def chk_volume_resize(self, apiclient, vm):

        self.assertEqual(vm.state, "Running", msg="VM is not in Running state")
        # get root vol from created vm, verify its size
        list_volume_response = Volume.list(apiclient,
                                           virtualmachineid=vm.id,
                                           type='ROOT',
                                           listall='True')
        rootvolume = list_volume_response[0]
        if vm.state == "Running" and vm.hypervisor.lower() == "xenserver":
            self.virtual_machine.stop(apiclient)
            time.sleep(self.services["sleep"])
        if vm.hypervisor.lower() == "vmware":
            rootdiskcontroller = self.getDiskController(vm)
            if rootdiskcontroller != "scsi":
                raise Exception(
                    "root volume resize only supported on scsi disk ,"
                    "please check rootdiskcontroller type")

        rootvolobj = Volume(rootvolume.__dict__)
        newsize = (rootvolume.size >> 30) + 2
        success = False
        if rootvolume is not None:
            try:
                rootvolobj.resize(apiclient, size=newsize)
                if vm.hypervisor.lower() == "xenserver":
                    self.virtual_machine.start(apiclient)
                    time.sleep(self.services["sleep"])
                ssh = SshClient(self.virtual_machine.ssh_ip, 22, "root",
                                "password")
                newsizeinbytes = newsize * 1024 * 1024 * 1024

                if vm.hypervisor.lower() == "xenserver":
                    volume_name = "/dev/xvd" + \
                                  chr(ord('a') +
                                      int(
                                          list_volume_response[0].deviceid))
                    self.debug(" Using XenServer"
                               " volume_name: %s" % volume_name)
                    ret = checkVolumeSize(ssh_handle=ssh,
                                          volume_name=volume_name,
                                          size_to_verify=newsizeinbytes)
                    success = True
                elif vm.hypervisor.lower() == "kvm":
                    volume_name = "/dev/vd" + chr(
                        ord('a') + int(list_volume_response[0].deviceid))
                    self.debug(" Using KVM volume_name:" " %s" % volume_name)
                    ret = checkVolumeSize(ssh_handle=ssh,
                                          volume_name=volume_name,
                                          size_to_verify=newsizeinbytes)
                    success = True
                elif vm.hypervisor.lower() == "vmware":
                    ret = checkVolumeSize(ssh_handle=ssh,
                                          volume_name="/dev/sdb",
                                          size_to_verify=newsizeinbytes)
                    success = True
                self.debug(" Volume Size Expected %s "
                           " Actual :%s" % (newsizeinbytes, ret[1]))
            except Exception as e:
                # need to write the rootdisk controller  code.
                if vm.hypervisor == "vmware" and rootdiskcontroller == "ide":
                    assert "Found unsupported root disk " \
                           "controller :ide" in e.message, \
                        "able to resize ide root volume Testcase failed"
                else:
                    raise Exception("fail to resize the volume: %s" % e)
        else:
            self.debug("hypervisor %s unsupported for test "
                       ", verifying it errors properly" % self.hypervisor)
            success = False
        return success
    def test_01_upload_and_download_snapshot(self):
        list_volumes_response = list_volumes(
            self.apiClient,
            virtualmachineid=self.virtual_machine.id,
            listall=True)

        sf_util.check_list(list_volumes_response, 1, self,
                           "There should only be one volume in this list.")

        vm_root_volume = list_volumes_response[0]

        ### Perform tests related to uploading a QCOW2 file to secondary storage and then moving it to managed storage

        volume_name = "Volume-A"
        services = {"format": TestData.file_type, "diskname": volume_name}

        uploaded_volume = Volume.upload(self.apiClient,
                                        services,
                                        self.zone.id,
                                        account=self.account.name,
                                        domainid=self.account.domainid,
                                        url=TestData.volume_url,
                                        diskofferingid=self.disk_offering.id)

        self._wait_for_volume_state(uploaded_volume.id, "Uploaded")

        uploaded_volume_id = sf_util.get_cs_volume_db_id(
            self.dbConnection, uploaded_volume)

        result = self._get_volume_store_ref_row(uploaded_volume_id)

        self.assertEqual(len(result), 1, TestUploadDownload.assertText)

        install_path = self._get_install_path(
            result[0][TestData.install_path_index])

        self._verify_uploaded_volume_present(install_path)

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

        uploaded_volume = sf_util.check_and_get_cs_volume(
            self, uploaded_volume.id, volume_name, self)

        sf_account_id = sf_util.get_sf_account_id(
            self.cs_api, self.account.id, self.primary_storage.id, self,
            "The SolidFire account ID should be a non-zero integer.")

        sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id)

        self.assertNotEqual(
            len(sf_volumes), 0,
            "The length of the response for the SolidFire-volume query should not be zero."
        )

        sf_volume = sf_util.check_and_get_sf_volume(sf_volumes,
                                                    uploaded_volume.name, self)

        sf_volume_size = sf_util.get_volume_size_with_hsr(
            self.cs_api, uploaded_volume, self)

        sf_util.check_size_and_iops(sf_volume, uploaded_volume, sf_volume_size,
                                    self)

        sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id,
                                       self.primary_storage.id, self)

        sf_util.check_vag(sf_volume, sf_vag_id, self)

        result = self._get_volume_store_ref_row(uploaded_volume_id)

        self.assertEqual(len(result), 0, TestUploadDownload.assertText2)

        self._verify_uploaded_volume_not_present(install_path)

        ### Perform tests related to extracting the contents of a volume on managed storage to a QCOW2 file
        ### and downloading the file

        try:
            # for data disk
            Volume.extract(self.apiClient, uploaded_volume.id, self.zone.id,
                           TestData.download_mode)

            raise Exception(
                "The volume extraction (for the data disk) did not fail (as expected)."
            )
        except Exception as e:
            if TestUploadDownload.errorText in str(e):
                pass
            else:
                raise

        vm_root_volume_id = sf_util.get_cs_volume_db_id(
            self.dbConnection, vm_root_volume)

        try:
            # for root disk
            Volume.extract(self.apiClient, vm_root_volume.id, self.zone.id,
                           TestData.download_mode)

            raise Exception(
                "The volume extraction (for the root disk) did not fail (as expected)."
            )
        except Exception as e:
            if TestUploadDownload.errorText in str(e):
                pass
            else:
                raise

        self.virtual_machine.stop(self.apiClient)

        self._extract_volume_and_verify(
            uploaded_volume_id,
            "Unable to locate the extracted file for the data disk (attached)")

        result = self._get_volume_store_ref_row(vm_root_volume_id)

        self.assertEqual(len(result), 0, TestUploadDownload.assertText2)

        self._extract_volume_and_verify(
            vm_root_volume_id,
            "Unable to locate the extracted file for the root disk")

        uploaded_volume = self.virtual_machine.detach_volume(
            self.apiClient, uploaded_volume)

        self._extract_volume_and_verify(
            uploaded_volume_id,
            "Unable to locate the extracted file for the data disk (detached)")

        uploaded_volume = Volume(uploaded_volume.__dict__)

        uploaded_volume.delete(self.apiClient)