예제 #1
0
 def test_02_resize_iops_detached_volume(self):
     ''' Test resize iops of detached StorPool's disk
     '''
     self.virtual_machine.stop(self.apiclient, forced=True)
     self.virtual_machine.detach_volume(
         self.apiclient,
         self.volume_1
         )
     Volume.resize(self.volume_1, self.apiclient, maxiops = 10000)
     self.volume_1 = Volume.list(self.apiclient, id = self.volume_1.id)[0]
     self.helper.check_storpool_volume_iops(self.spapi, self.volume_1)
예제 #2
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)
예제 #3
0
    def test_01_resize_iops_attached_volume(self):
        ''' Test resize iops of attached StorPool's disk
        '''
        volume_attached = self.virtual_machine.attach_volume(
            self.apiclient,
            self.volume_1
            )

        volumes = list_volumes(
            self.apiclient,
            virtualmachineid = self.virtual_machine.id, listall = True
            )

        for v in volumes:
            self.helper.check_storpool_volume_iops(self.spapi, v)

        Volume.resize(self.volume_1, self.apiclient, maxiops = 4000)
        self.volume_1 = Volume.list(self.apiclient, id = self.volume_1.id)[0]
        self.helper.check_storpool_volume_iops(self.spapi, self.volume_1)
예제 #4
0
    def test_01_resize_volume_to_qos_offering(self):

        Volume.resize(self.volume_1,
                      self.apiclient,
                      diskofferingid=self.disk_offering_qos.id)

        volume = Volume.list(self.apiclient,
                             virtualmachineid=self.virtual_machine.id,
                             id=self.volume_1.id,
                             listall=True)[0]

        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            self.debug("#################### volumes %s" % spvolume)
            if spvolume[0].templateName != "qos":
                raise Exception(
                    "StorPool volume was not migrated to the QoS template")
            else:
                self.debug("Volume was migrate to the new qos template")
        except spapi.ApiError as err:
            raise Exception(err)
    def test_7_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" or
                            vm.hypervisor.lower() == "vmware"):
                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.assertEquals(
                        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)
    def test_6_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" or
                            vm.hypervisor.lower() == "vmware"):
                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:
                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)
    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" or \
                             vm.hypervisor.lower() == "vmware"):
            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" or \
                                vm.hypervisor.lower() == "vmware":
                    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_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" or
                             vm.hypervisor.lower() == "vmware"):
                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
예제 #9
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
예제 #10
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)
예제 #11
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)
예제 #12
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