def test_04_resize_attached_volume_of_vm_on_remote(self):
        ''' Test Resize Volume  Attached To Running Virtual Machine on remote
        '''
        self.assertEqual(VirtualMachine.RUNNING, self.virtual_machine.state,
                         "Running")
        volume = self.virtual_machine.attach_volume(self.apiclient,
                                                    self.volume_1)
        shrinkOk = False
        if volume.size > int((self.disk_offering_20.disksize) * (1024**3)):
            shrinkOk = True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id
        cmd.diskofferingid = self.disk_offering_20.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)

        new_size = Volume.list(self.apiclient, id=volume.id, listall=True)

        self.assertTrue(
            (new_size[0].size == int(
                (self.disk_offering_20.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)")
        volume = new_size[0]
        shrinkOk = False
        if volume.size > int((self.disk_offering_100.disksize) * (1024**3)):
            shrinkOk = True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id
        cmd.diskofferingid = self.disk_offering_100.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(self.apiclient, id=volume.id, listall=True)

        self.assertTrue(
            (new_size[0].size == int(
                (self.disk_offering_100.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)")

        # return to small disk
        volume = new_size[0]
        shrinkOk = False
        if volume.size > int((self.disk_offerings.disksize) * (1024**3)):
            shrinkOk = True

        cmd.diskofferingid = self.disk_offerings.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(self.apiclient, id=volume.id, listall=True)
        self.assertTrue((new_size[0].size == int(
            (self.disk_offerings.disksize) * (1024**3))),
                        "Could not return to Small disk")
Пример #2
0
    def _resize_volume(self, volume, new_disk_offering):

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume.id
        cmd.diskofferingid = new_disk_offering.id

        self.apiClient.resizeVolume(cmd)

        do_size_bytes = int(new_disk_offering.disksize * (1024**3))
        retries = 3
        success = False

        while retries > 0:
            retries -= 1

            list_volumes_response = list_volumes(self.apiClient, id=volume.id)

            for vol in list_volumes_response:
                if vol.id == volume.id and \
                                int(vol.size) == do_size_bytes and \
                                vol.state == 'Ready':
                    success = True

            if success:
                break
            else:
                time.sleep(10)

        self.assertEqual(success, True, self._volume_resize_err)
Пример #3
0
    def resize_volume(cls,
                      apiclient,
                      volume,
                      shrinkOk=None,
                      disk_offering=None,
                      size=None,
                      maxiops=None,
                      miniops=None):

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id

        if disk_offering:
            cmd.diskofferingid = disk_offering.id
        if size:
            cmd.size = size

        if maxiops:
            cmd.maxiops = maxiops
        if miniops:
            cmd.miniops

        cmd.shrinkok = shrinkOk
        apiclient.resizeVolume(cmd)

        new_size = Volume.list(apiclient, id=volume.id)
        volume_size = new_size[0].size
        return new_size[0]
Пример #4
0
    def resize_volume(cls, volume, shrinkOk, disk_offering =None, size=None):

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id

        if disk_offering:
            cmd.diskofferingid = disk_offering.id
            disk_offering_size = int((disk_offering.disksize) * (1024**3))
        if size:
            cmd.size = size
            disk_offering_size = size << 30

        cmd.shrinkok = shrinkOk
        cfg.logger.info("resizing volume=%s to size %s" % (volume.id, disk_offering_size))
        cls.testClass.apiclient.resizeVolume(cmd)

        new_size = Volume.list(
            cls.testClass.apiclient,
            id=volume.id
            )
        volume_size = new_size[0].size

        assert_true(
            volume_size == disk_offering_size,
            "New size is not int((cls.disk_offering_20) * (1024**3)"
            )
        return new_size[0]
    def test_03_resize_root_volume_of_vm_on_remote(self):
        ''' Test Resize Root volume on Running Virtual Machine on remote
        '''
        self.assertEqual(VirtualMachine.RUNNING, self.virtual_machine2.state,
                         "Running")
        volume = list_volumes(self.apiclient,
                              virtualmachineid=self.virtual_machine2.id,
                              type="ROOT",
                              listall=True)
        volume = volume[0]
        self.assertEqual(volume.type, 'ROOT', "Volume is not of ROOT type")
        shrinkOk = False
        if volume.size > int((self.disk_offering_20.disksize) * (1024**3)):
            shrinkOk = True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id
        cmd.size = 20
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)

        new_size = Volume.list(self.apiclient, id=volume.id, listall=True)

        self.assertTrue(
            (new_size[0].size == int(
                (self.disk_offering_20.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)")
        volume = new_size[0]
        shrinkOk = False
        if volume.size > int((self.disk_offering_100.disksize) * (1024**3)):
            shrinkOk = True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id
        cmd.size = 100
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(self.apiclient, id=volume.id, listall=True)

        self.assertTrue(
            (new_size[0].size == int(
                (self.disk_offering_100.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)")
Пример #6
0
    def test_CLOUDSTACK_6181_stoppedvm_root_resize(self):
        """
        @Desc: Test root volume resize of stopped VM
        @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-6181
        @Steps:
        Step1: Deploy VM in stopped state (startvm=false),
        resize via 'resizeVolume', start VM. Root is new size.
        """
        # Check whether usage server is running or not

        if self.hypervisor.lower() != 'kvm':
            self.skipTest("Test can be run only on KVM hypervisor")
        # deploy virtual machine in stopped state
        self.services["virtual_machine"]["zoneid"] = self.zone.id
        self.services["virtual_machine"]["template"] = self.template.id

        # Step3: Verifying that VM creation is successful
        virtual_machine = VirtualMachine.create(
            self.apiClient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            startvm=False)
        self.cleanup.append(virtual_machine)
        # Verify VM state
        self.assertEqual(virtual_machine.state, 'Stopped',
                         "Check VM state is Stopped or not")
        volumes = list_volumes(self.apiClient,
                               virtualmachineid=virtual_machine.id,
                               type='ROOT',
                               listall=True)

        self.assertIsNotNone(volumes, "root volume is not returned properly")
        newrootsize = (self.template.size >> 30) + 2
        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volumes[0].id
        cmd.size = newrootsize
        self.apiClient.resizeVolume(cmd)

        virtual_machine.start(self.apiClient)

        volumes_after_resize = list_volumes(
            self.apiClient,
            virtualmachineid=virtual_machine.id,
            type='ROOT',
            listall=True)

        rootvolume = volumes_after_resize[0]
        success = False
        if rootvolume is not None and rootvolume.size == (newrootsize << 30):
            success = True

        self.assertEqual(success, True,
                         "Check if the root volume resized appropriately")
        return
Пример #7
0
    def test_12_resize_volume_with_only_size_parameter(self):
        """Test resize a volume by providing only size parameter, disk offering id is not mandatory"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Attaching volume (ID: %s) to VM (ID: %s)" %
                   (self.volume.id, self.virtual_machine.id))

        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() == "hyperv":
            self.skipTest("Resize Volume is unsupported on Hyper-V")

        # resize the data disk
        self.debug("Resize Volume ID: %s" % self.volume.id)

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume.id
        cmd.size = 20

        self.apiClient.resizeVolume(cmd)

        count = 0
        success = False
        while count < 3:
            list_volume_response = Volume.list(self.apiClient,
                                               id=self.volume.id,
                                               type='DATADISK')
            for vol in list_volume_response:
                if vol.id == self.volume.id and int(
                        vol.size) == (20 * (1024**3)) and vol.state == 'Ready':
                    success = True
            if success:
                break
            else:
                time.sleep(10)
                count += 1

        self.assertEqual(success, True,
                         "Check if the data volume resized appropriately")

        # start the vm if it is on xenserver

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.start(self.apiClient)
            time.sleep(30)
        return
Пример #8
0
    def test_07_resize_fail(self):
        """Test resize (negative) non-existent volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Fail Resize Volume ID: %s" % self.volume.id)

        # first, an invalid id
        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = "invalid id"
        cmd.diskofferingid = self.services['customresizeddiskofferingid']
        success = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            # print str(ex)
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
            success, True,
            "ResizeVolume - verify invalid id is handled appropriately")

        # Next, we'll try an invalid disk offering id
        cmd.id = self.volume.id
        cmd.diskofferingid = "invalid id"
        success = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
            success, True,
            "ResizeVolume - verify disk offering is handled appropriately")

        # try to resize a root disk with a disk offering, root can only be resized by size=
        # get root vol from created vm
        list_volume_response = Volume.list(
            self.apiClient,
            virtualmachineid=self.virtual_machine.id,
            type='ROOT',
            listall=True)

        rootvolume = list_volume_response[0]

        cmd.id = rootvolume.id
        cmd.diskofferingid = self.services['diskofferingid']
        with self.assertRaises(Exception):
            self.apiClient.resizeVolume(cmd)

        return
Пример #9
0
    def test_08_resize_volume(self):
        """Test resize a volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug(
                "Attaching volume (ID: %s) to VM (ID: %s)" % (
                                                    self.volume.id,
                                                    self.virtual_machine.id
                                                    ))

        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() == "vmware":
            self.skipTest("Resize Volume is unsupported on VmWare")

        # resize the data disk
        self.debug("Resize Volume ID: %s" % self.volume.id)

        cmd                = resizeVolume.resizeVolumeCmd()
        cmd.id             = self.volume.id
        cmd.diskofferingid = self.services['resizeddiskofferingid']

        self.apiClient.resizeVolume(cmd)

        count = 0
        success = False
        while count < 3:
            list_volume_response = Volume.list(
                                                self.apiClient,
                                                id=self.volume.id,
                                                type='DATADISK'
                                                )
            for vol in list_volume_response:
                if vol.id == self.volume.id and vol.size == 3221225472L and vol.state == 'Ready':
                    success = True
            if success:
                break
            else:
                time.sleep(10)
                count += 1
Пример #10
0
    def test_08_resize_volume(self):
        """Test resize a volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug(
                "Attaching volume (ID: %s) to VM (ID: %s)" % (
                                                    self.volume.id,
                                                    self.virtual_machine.id
                                                    ))

        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() == "vmware":
            self.skipTest("Resize Volume is unsupported on VmWare")

        # resize the data disk
        self.debug("Resize Volume ID: %s" % self.volume.id)

        cmd                = resizeVolume.resizeVolumeCmd()
        cmd.id             = self.volume.id
        cmd.diskofferingid = self.services['resizeddiskofferingid']

        self.apiClient.resizeVolume(cmd)

        count = 0
        success = False
        while count < 3:
            list_volume_response = Volume.list(
                                                self.apiClient,
                                                id=self.volume.id,
                                                type='DATADISK'
                                                )
            for vol in list_volume_response:
                if vol.id == self.volume.id and vol.size == 3221225472L and vol.state == 'Ready':
                    success = True
            if success:
                break
            else:
                time.sleep(10)
                count += 1
Пример #11
0
    def test_07_resize_fail(self):
        """Test resize (negative) non-existent volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Fail Resize Volume ID: %s" % self.volume.id)

        # first, an invalid id
        cmd                = resizeVolume.resizeVolumeCmd()
        cmd.id             = "invalid id"
        cmd.diskofferingid = self.services['resizeddiskofferingid']
        success            = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            #print str(ex)
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
                success,
                True,
                "ResizeVolume - verify invalid id is handled appropriately")

        # Next, we'll try an invalid disk offering id
        cmd.id             = self.volume.id
        cmd.diskofferingid = "invalid id"
        success            = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
                success,
                True,
                "ResizeVolume - verify disk offering is handled appropriately")

        # try to resize a root disk with a disk offering, root can only be resized by size=
        # get root vol from created vm
        list_volume_response = Volume.list(
                                            self.apiClient,
                                            virtualmachineid=self.virtual_machine.id,
                                            type='ROOT',
                                            listall=True
                                            )

        rootvolume = list_volume_response[0]

        cmd.id             = rootvolume.id
        cmd.diskofferingid = self.services['diskofferingid']
        success            = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "Can only resize Data volumes" in str(ex):
                success = True
        self.assertEqual(
                success,
                True,
                "ResizeVolume - verify root disks cannot be resized by disk offering id")

        # Ok, now let's try and resize a volume that is not custom.
        cmd.id             = self.volume.id
        cmd.diskofferingid = self.services['diskofferingid']
        cmd.size           = 4
        currentSize        = self.volume.size

        self.debug(
                "Attaching volume (ID: %s) to VM (ID: %s)" % (
                                                    self.volume.id,
                                                    self.virtual_machine.id)
                 )
        #attach the volume
        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        #stop the vm if it is on xenserver
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() == "vmware":
            self.skipTest("Resize Volume is unsupported on VmWare")

        self.apiClient.resizeVolume(cmd)
        count = 0
        success = True
        while count < 10:
            list_volume_response = Volume.list(
                                                self.apiClient,
                                                id=self.volume.id,
                                                type='DATADISK'
                                                )
            for vol in list_volume_response:
                if vol.id == self.volume.id and vol.size != currentSize and vol.state != "Resizing":
                    success = False
            if success:
                break
            else:
                time.sleep(1)
                count += 1

        self.assertEqual(
                         success,
                         True,
                         "Verify the volume did not resize"
                         )
        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.start(self.apiClient)
            time.sleep(30)
        return 
Пример #12
0
    def test_08_resize_volume(self):
        """Test resize a volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Attaching volume (ID: %s) to VM (ID: %s)" %
                   (self.volume.id, self.virtual_machine.id))

        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() in ("vmware"):
            self.skipTest("Resize Volume is unsupported on VmWare")

        # resize the data disk
        self.debug("Resize Volume ID: %s" % self.volume.id)

        self.services["disk_offering"]["disksize"] = 20
        disk_offering_20_GB = DiskOffering.create(
            self.apiclient, self.services["disk_offering"])
        self.cleanup.append(disk_offering_20_GB)

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume.id
        cmd.diskofferingid = disk_offering_20_GB.id

        self.apiClient.resizeVolume(cmd)

        count = 0
        success = False
        while count < 3:
            list_volume_response = Volume.list(self.apiClient,
                                               id=self.volume.id,
                                               type='DATADISK')
            for vol in list_volume_response:
                if vol.id == self.volume.id and int(
                        vol.size) == (int(disk_offering_20_GB.disksize) *
                                      (1024**3)) and vol.state == 'Ready':
                    success = True
            if success:
                break
            else:
                time.sleep(10)
                count += 1

        self.assertEqual(success, True,
                         "Check if the data volume resized appropriately")

        can_shrink = False

        list_volume_response = Volume.list(self.apiClient,
                                           id=self.volume.id,
                                           type='DATADISK')
        storage_pool_id = [
            x.storageid for x in list_volume_response if x.id == self.volume.id
        ][0]
        storage = StoragePool.list(self.apiclient, id=storage_pool_id)[0]
        # At present only CLVM supports shrinking volumes
        if storage.type.lower() == "clvm":
            can_shrink = True

        if can_shrink:
            self.services["disk_offering"]["disksize"] = 10
            disk_offering_10_GB = DiskOffering.create(
                self.apiclient, self.services["disk_offering"])
            self.cleanup.append(disk_offering_10_GB)

            cmd = resizeVolume.resizeVolumeCmd()
            cmd.id = self.volume.id
            cmd.diskofferingid = disk_offering_10_GB.id
            cmd.shrinkok = "true"

            self.apiClient.resizeVolume(cmd)

            count = 0
            success = False
            while count < 3:
                list_volume_response = Volume.list(self.apiClient,
                                                   id=self.volume.id)
                for vol in list_volume_response:
                    if vol.id == self.volume.id and int(
                            vol.size) == (int(disk_offering_10_GB.disksize) *
                                          (1024**3)) and vol.state == 'Ready':
                        success = True
                if success:
                    break
                else:
                    time.sleep(10)
                    count += 1

            self.assertEqual(success, True,
                             "Check if the root volume resized appropriately")

        # start the vm if it is on xenserver

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.start(self.apiClient)
            time.sleep(30)
        return
Пример #13
0
    def test_07_resize_fail(self):
        """Test resize (negative) non-existent volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Fail Resize Volume ID: %s" % self.volume.id)

        # first, an invalid id
        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = "invalid id"
        cmd.diskofferingid = self.services['customresizeddiskofferingid']
        success = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            # print str(ex)
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
            success, True,
            "ResizeVolume - verify invalid id is handled appropriately")

        # Next, we'll try an invalid disk offering id
        cmd.id = self.volume.id
        cmd.diskofferingid = "invalid id"
        success = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
            success, True,
            "ResizeVolume - verify disk offering is handled appropriately")

        # try to resize a root disk with a disk offering, root can only be resized by size=
        # get root vol from created vm
        list_volume_response = Volume.list(
            self.apiClient,
            virtualmachineid=self.virtual_machine.id,
            type='ROOT',
            listall=True)

        rootvolume = list_volume_response[0]

        cmd.id = rootvolume.id
        cmd.diskofferingid = self.services['diskofferingid']
        with self.assertRaises(Exception):
            self.apiClient.resizeVolume(cmd)

        # Ok, now let's try and resize a volume that is not custom.
        cmd.id = self.volume.id
        cmd.diskofferingid = self.services['diskofferingid']
        cmd.size = 4

        self.debug("Attaching volume (ID: %s) to VM (ID: %s)" %
                   (self.volume.id, self.virtual_machine.id))
        # attach the volume
        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        # stop the vm if it is on xenserver
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() in ("vmware"):
            self.skipTest("Resize Volume is unsupported on VmWare")

        # Attempting to resize it should throw an exception, as we're using a non
        # customisable disk offering, therefore our size parameter should be ignored
        with self.assertRaises(Exception):
            self.apiClient.resizeVolume(cmd)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.start(self.apiClient)
            time.sleep(30)
        return
Пример #14
0
    def test_03_resize_attached_volume_on_working_vm(self):
        ''' Test Resize Volume  Attached To Running Virtual Machine
        '''
        self.assertEqual(VirtualMachine.RUNNING, self.virtual_machine.state, "Running")

        volume = Volume.list(
            self.apiclient,
            id=self.volume_1.id,
            listall= True
            )[0]
        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != volume.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        shrinkOk = False
        if volume.size > int((self.disk_offering_20.disksize) * (1024**3)):
            shrinkOk= True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id
        cmd.diskofferingid = self.disk_offering_20.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)

        new_size = Volume.list(
            self.apiclient,
            id=volume.id,
            listall= True
            )

        self.assertTrue(
            (new_size[0].size == int((self.disk_offering_20.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)"
            )
        volume = new_size[0]

        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != volume.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        shrinkOk = False
        if volume.size > int((self.disk_offering_100.disksize) * (1024**3)):
            shrinkOk= True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id
        cmd.diskofferingid = self.disk_offering_100.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(
            self.apiclient,
            id=volume.id,
            listall= True
            )

        self.assertTrue(
            (new_size[0].size == int((self.disk_offering_100.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)"
            )

        # return to small disk
        volume = new_size[0]

        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != volume.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        shrinkOk = False
        if volume.size > int((self.disk_offerings.disksize)* (1024**3)):
            shrinkOk= True

        cmd.diskofferingid = self.disk_offerings.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(
            self.apiclient,
            id=volume.id,
            listall= True
            )

        volume = new_size[0]

        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != volume.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertTrue(
            (new_size[0].size == int((self.disk_offerings.disksize)*(1024**3))),
            "Could not return to Small disk"
            )
Пример #15
0
    def test_05_resize_attached_volume(self):
        ''' Test Resize Volume  Attached To Virtual Machine
        '''
        #=======================================================================
        # list_volume_response = Volume.list(
        #     self.apiclient,
        #     id = self.volume_1.id
        #     )
        # volume =list_volume_response[0]
        # self.assertIsNotNone(lvolume, "Volume response is  None")
        #=======================================================================
        shrinkOk = False
        if self.volume_1.size > int((self.disk_offering_20.disksize) * (1024**3)):
            shrinkOk= True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume_1.id
        cmd.diskofferingid = self.disk_offering_20.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)

        new_size = Volume.list(
            self.apiclient,
            id=self.volume_1.id,
            listall= True
            )

        self.assertTrue(
            (new_size[0].size == int((self.disk_offering_20.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)"
            )
        self.volume_1 = new_size[0]

        name = self.volume_1.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != self.volume_1.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        shrinkOk = False
        if self.volume_1.size > int((self.disk_offering_100.disksize) * (1024**3)):
            shrinkOk= True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume_1.id
        cmd.diskofferingid = self.disk_offering_100.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(
            self.apiclient,
            id=self.volume_1.id,
            listall= True
            )

        self.assertTrue(
            (new_size[0].size == int((self.disk_offering_100.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)"
            )

        # return to small disk
        self.volume_1 = new_size[0]

        name = self.volume_1.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != self.volume_1.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        shrinkOk = False
        if self.volume_1.size > int((self.disk_offerings.disksize)* (1024**3)):
            shrinkOk= True

        cmd.diskofferingid = self.disk_offerings.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(
            self.apiclient,
            id=self.volume_1.id,
            listall= True
            )

        name = new_size[0].path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != new_size[0].size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)
        self.assertTrue(
            (new_size[0].size == int((self.disk_offerings.disksize)*(1024**3))),
            "Could not return to Small disk"
            )
Пример #16
0
    def test_08_resize_volume(self):
        """Test resize a volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Attaching volume (ID: %s) to VM (ID: %s)" % (self.volume.id, self.virtual_machine.id))

        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() == "vmware":
            self.skipTest("Resize Volume is unsupported on VmWare")

        # resize the data disk
        self.debug("Resize Volume ID: %s" % self.volume.id)

        self.services["disk_offering"]["disksize"] = 20
        disk_offering_20_GB = DiskOffering.create(self.apiclient, self.services["disk_offering"])
        self.cleanup.append(disk_offering_20_GB)

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume.id
        cmd.diskofferingid = disk_offering_20_GB.id

        self.apiClient.resizeVolume(cmd)

        count = 0
        success = False
        while count < 3:
            list_volume_response = Volume.list(self.apiClient, id=self.volume.id, type="DATADISK")
            for vol in list_volume_response:
                if (
                    vol.id == self.volume.id
                    and int(vol.size) == (int(disk_offering_20_GB.disksize) * (1024 ** 3))
                    and vol.state == "Ready"
                ):
                    success = True
            if success:
                break
            else:
                time.sleep(10)
                count += 1

        self.assertEqual(success, True, "Check if the data volume resized appropriately")

        self.services["disk_offering"]["disksize"] = 10
        disk_offering_10_GB = DiskOffering.create(self.apiclient, self.services["disk_offering"])
        self.cleanup.append(disk_offering_10_GB)

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume.id
        cmd.diskofferingid = disk_offering_10_GB.id
        cmd.shrinkok = "true"

        self.apiClient.resizeVolume(cmd)

        count = 0
        success = False
        while count < 3:
            list_volume_response = Volume.list(self.apiClient, id=self.volume.id)
            for vol in list_volume_response:
                if (
                    vol.id == self.volume.id
                    and int(vol.size) == (int(disk_offering_10_GB.disksize) * (1024 ** 3))
                    and vol.state == "Ready"
                ):
                    success = True
            if success:
                break
            else:
                time.sleep(10)
                count += 1

        self.assertEqual(success, True, "Check if the root volume resized appropriately")

        # start the vm if it is on xenserver

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.start(self.apiClient)
            time.sleep(30)
        return
Пример #17
0
    def test_07_resize_fail(self):
        """Test resize (negative) non-existent volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Fail Resize Volume ID: %s" % self.volume.id)

        # first, an invalid id
        cmd                = resizeVolume.resizeVolumeCmd()
        cmd.id             = "invalid id"
        cmd.diskofferingid = self.services['customresizeddiskofferingid']
        success            = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            #print str(ex)
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
                success,
                True,
                "ResizeVolume - verify invalid id is handled appropriately")

        # Next, we'll try an invalid disk offering id
        cmd.id             = self.volume.id
        cmd.diskofferingid = "invalid id"
        success            = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
                success,
                True,
                "ResizeVolume - verify disk offering is handled appropriately")

        # try to resize a root disk with a disk offering, root can only be resized by size=
        # get root vol from created vm
        list_volume_response = Volume.list(
                                            self.apiClient,
                                            virtualmachineid=self.virtual_machine.id,
                                            type='ROOT',
                                            listall=True
                                            )

        rootvolume = list_volume_response[0]

        cmd.id             = rootvolume.id
        cmd.diskofferingid = self.services['diskofferingid']
        with self.assertRaises(Exception):
            self.apiClient.resizeVolume(cmd)

        # Ok, now let's try and resize a volume that is not custom.
        cmd.id             = self.volume.id
        cmd.diskofferingid = self.services['diskofferingid']
        cmd.size           = 4
        currentSize        = self.volume.size

        self.debug(
                "Attaching volume (ID: %s) to VM (ID: %s)" % (
                                                    self.volume.id,
                                                    self.virtual_machine.id)
                 )
        #attach the volume
        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        #stop the vm if it is on xenserver
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() in ("vmware", "hyperv"):
            self.skipTest("Resize Volume is unsupported on VmWare and Hyper-V")

        # Attempting to resize it should throw an exception, as we're using a non
        # customisable disk offering, therefore our size parameter should be ignored
        with self.assertRaises(Exception):
            self.apiClient.resizeVolume(cmd)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.start(self.apiClient)
            time.sleep(30)
        return 
Пример #18
0
    def test_07_resize_fail(self):
        """Test resize (negative) non-existent volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Fail Resize Volume ID: %s" % self.volume.id)

        # first, an invalid id
        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = "invalid id"
        cmd.diskofferingid = self.services['customresizeddiskofferingid']
        success = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            #print str(ex)
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
            success, True,
            "ResizeVolume - verify invalid id is handled appropriately")

        # Next, we'll try an invalid disk offering id
        cmd.id = self.volume.id
        cmd.diskofferingid = "invalid id"
        success = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
            success, True,
            "ResizeVolume - verify disk offering is handled appropriately")

        # try to resize a root disk with a disk offering, root can only be resized by size=
        # get root vol from created vm
        list_volume_response = Volume.list(
            self.apiClient,
            virtualmachineid=self.virtual_machine.id,
            type='ROOT',
            listall=True)

        rootvolume = list_volume_response[0]

        cmd.id = rootvolume.id
        cmd.diskofferingid = self.services['diskofferingid']
        success = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "Can only resize Data volumes" in str(ex):
                success = True
        self.assertEqual(
            success, True,
            "ResizeVolume - verify root disks cannot be resized by disk offering id"
        )

        # Ok, now let's try and resize a volume that is not custom.
        cmd.id = self.volume.id
        cmd.diskofferingid = self.services['diskofferingid']
        cmd.size = 4
        currentSize = self.volume.size

        self.debug("Attaching volume (ID: %s) to VM (ID: %s)" %
                   (self.volume.id, self.virtual_machine.id))
        #attach the volume
        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        #stop the vm if it is on xenserver
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() == "vmware":
            self.skipTest("Resize Volume is unsupported on VmWare")

        self.apiClient.resizeVolume(cmd)
        count = 0
        success = True
        while count < 10:
            list_volume_response = Volume.list(self.apiClient,
                                               id=self.volume.id,
                                               type='DATADISK')
            for vol in list_volume_response:
                if vol.id == self.volume.id and vol.size != currentSize and vol.state != "Resizing":
                    success = False
            if success:
                break
            else:
                time.sleep(1)
                count += 1

        self.assertEqual(success, True, "Verify the volume did not resize")
        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.start(self.apiClient)
            time.sleep(30)
        return
Пример #19
0
    def test_06_resize_detached_volume(self):
        ''' Test Resize Volume Detached To Virtual Machine
        '''
        list_vm_volumes = Volume.list(
            self.apiclient,
            virtualmachineid = self.virtual_machine.id,
            id= self.volume_2.id,
            listall= True
            )

        #check that the volume is not attached to VM
        self.assertIsNone(list_vm_volumes, "List volumes is not None")

        shrinkOk = False
        if self.volume_2.size > int((self.disk_offering_20.disksize) * (1024**3)):
            shrinkOk= True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume_2.id
        cmd.diskofferingid = self.disk_offering_20.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)

        new_size = Volume.list(
            self.apiclient,
            id=self.volume_2.id,
            listall= True
            )

        self.assertTrue(
            (new_size[0].size == int((self.disk_offering_20.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)"
            )
        self.volume_2 = new_size[0]

        name = self.volume_2.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != self.volume_2.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        shrinkOk = False
        if self.volume_2.size > int((self.disk_offering_100.disksize) * (1024**3)):
            shrinkOk= True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume_2.id
        cmd.diskofferingid = self.disk_offering_100.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(
            self.apiclient,
            id=self.volume_2.id,
            listall= True
            )

        self.assertTrue(
            (new_size[0].size == int((self.disk_offering_100.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)"
            )

        # return to small disk
        self.volume_2 = new_size[0]

        name = self.volume_2.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != self.volume_2.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        shrinkOk = False
        if self.volume_2.size > int((self.disk_offerings.disksize)* (1024**3)):
            shrinkOk= True

        cmd.diskofferingid = self.disk_offerings.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(
            self.apiclient,
            id=self.volume_2.id,
            listall= True
            )

        name = new_size[0].path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != new_size[0].size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertTrue(
            (new_size[0].size == int((self.disk_offerings.disksize)*(1024**3))),
            "Could not return to Small disk"
            )
Пример #20
0
class TestVolumes(cloudstackTestCase):

    @classmethod
    def setUpClass(cls):
        testClient = super(TestVolumes, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        cls.disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["disk_offering"]
                                    )
        cls.resized_disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["resized_disk_offering"]
                                    )
        cls.custom_resized_disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["resized_disk_offering"],
                                    custom=True
                                    )

        template = get_template(
                            cls.apiclient,
                            cls.zone.id,
                            cls.services["ostype"]
                            )
        if template == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]

        cls.services["domainid"] = cls.domain.id
        cls.services["zoneid"] = cls.zone.id
        cls.services["template"] = template.id
        cls.services["diskofferingid"] = cls.disk_offering.id
        cls.services['resizeddiskofferingid'] = cls.resized_disk_offering.id
        cls.services['customresizeddiskofferingid'] = cls.custom_resized_disk_offering.id

        # Create VMs, VMs etc
        cls.account = Account.create(
                            cls.apiclient,
                            cls.services["account"],
                            domainid=cls.domain.id
                            )
        cls.service_offering = ServiceOffering.create(
                                            cls.apiclient,
                                            cls.services["service_offerings"]
                                        )
        cls.virtual_machine = VirtualMachine.create(
                                    cls.apiclient,
                                    cls.services,
                                    accountid=cls.account.name,
                                    domainid=cls.account.domainid,
                                    serviceofferingid=cls.service_offering.id,
                                    mode=cls.services["mode"]
                                )

        cls.volume = Volume.create(
                                   cls.apiclient,
                                   cls.services,
                                   account=cls.account.name,
                                   domainid=cls.account.domainid
                                   )
        cls._cleanup = [
                        cls.resized_disk_offering,
                        cls.custom_resized_disk_offering,
                        cls.service_offering,
                        cls.disk_offering,
                        cls.volume,
                        cls.account
                        ]

    @classmethod
    def tearDownClass(cls):
        try:
            cleanup_resources(cls.apiclient, cls._cleanup)
        except Exception as e:
            raise Exception("Warning: Exception during cleanup : %s" % e)

    def setUp(self):
        self.apiClient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()
        self.attached = False
        self.cleanup = []

    def tearDown(self):
        #Clean up, terminate the created volumes
        if self.attached:
            self.virtual_machine.detach_volume(self.apiClient, self.volume)
        cleanup_resources(self.apiClient, self.cleanup)
        return

    @attr(tags = ["advanced", "advancedns", "smoke", "basic", "provisioning"])
    def test_02_attach_volume(self):
        """Attach a created Volume to a Running VM
        """
        # Validate the following
        # 1. shows list of volumes
        # 2. "Attach Disk" pop-up box will display with list of  instances
        # 3. disk should be  attached to instance successfully

        self.debug(
                "Attaching volume (ID: %s) to VM (ID: %s)" % (
                                                    self.volume.id,
                                                    self.virtual_machine.id
                                                    ))
        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        list_volume_response = Volume.list(
                                                self.apiClient,
                                                id=self.volume.id
                                                )
        self.assertEqual(
                            isinstance(list_volume_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            list_volume_response,
                            None,
                            "Check if volume exists in ListVolumes"
                            )
        volume = list_volume_response[0]
        self.assertNotEqual(
                            volume.virtualmachineid,
                            None,
                            "Check if volume state (attached) is reflected"
                            )
        try:
            #Format the attached volume to a known fs
            format_volume_to_ext3(self.virtual_machine.get_ssh_client())

        except Exception as e:

            self.fail("SSH failed for VM: %s - %s" %
                                    (self.virtual_machine.ipaddress, e))
        return

    @attr(tags = ["advanced", "advancedns", "smoke", "basic", "selfservice"])
    def test_03_download_attached_volume(self):
        """Download a Volume attached to a VM
        """
        # Validate the following
        # 1. download volume will fail with proper error message
        #    "Failed - Invalid state of the volume with ID:
        #    It should be either detached or the VM should be in stopped state

        self.debug("Extract attached Volume ID: %s" % self.volume.id)

        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        cmd = extractVolume.extractVolumeCmd()
        cmd.id = self.volume.id
        cmd.mode = "HTTP_DOWNLOAD"
        cmd.zoneid = self.services["zoneid"]
        # A proper exception should be raised;
        # downloading attach VM is not allowed
        with self.assertRaises(Exception):
            self.apiClient.extractVolume(cmd)

    @attr(tags = ["advanced", "advancedns", "smoke", "basic", "selfservice"])
    def test_04_delete_attached_volume(self):
        """Delete a Volume attached to a VM
        """

        # Validate the following
        # 1. delete volume will fail with proper error message
        #    "Failed - Invalid state of the volume with ID:
        #    It should be either detached or the VM should be in stopped state

        self.debug("Trying to delete attached Volume ID: %s" %
                                                        self.volume.id)
        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        cmd = deleteVolume.deleteVolumeCmd()
        cmd.id = self.volume.id
        #Proper exception should be raised; deleting attach VM is not allowed
        #with self.assertRaises(Exception):
        with self.assertRaises(Exception):
            self.apiClient.deleteVolume(cmd)
        
    @attr(tags = ["advanced", "advancedns", "smoke", "basic", "selfservice"])
    def test_05_detach_volume(self):
        """Detach a Volume attached to a VM
        """

        # Validate the following
        # Data disk should be detached from instance and detached data disk
        # details should be updated properly

        self.debug(
                "Detaching volume (ID: %s) from VM (ID: %s)" % (
                                                    self.volume.id,
                                                    self.virtual_machine.id
                                                    ))
        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.virtual_machine.detach_volume(self.apiClient, self.volume)
        self.attached = False
        #Sleep to ensure the current state will reflected in other calls
        time.sleep(self.services["sleep"])
        list_volume_response = Volume.list(
                                                self.apiClient,
                                                id=self.volume.id
                                                )
        self.assertEqual(
                            isinstance(list_volume_response, list),
                            True,
                            "Check list response returns a valid list"
                        )

        self.assertNotEqual(
                            list_volume_response,
                            None,
                            "Check if volume exists in ListVolumes"
                            )
        volume = list_volume_response[0]
        self.assertEqual(
                         volume.virtualmachineid,
                         None,
                         "Check if volume state (detached) is reflected"
                         )
        return

    @attr(tags = ["advanced", "advancedns", "smoke", "basic", "provisioning"])
    def test_06_download_detached_volume(self):
        """Download a Volume unattached to an VM
        """
        # Validate the following
        # 1. able to download the volume when its not attached to instance

        self.debug("Extract detached Volume ID: %s" % self.volume.id)

        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.virtual_machine.detach_volume(self.apiClient, self.volume)
        self.attached = False

        cmd = extractVolume.extractVolumeCmd()
        cmd.id = self.volume.id
        cmd.mode = "HTTP_DOWNLOAD"
        cmd.zoneid = self.services["zoneid"]
        extract_vol = self.apiClient.extractVolume(cmd)

        #Attempt to download the volume and save contents locally
        try:
            formatted_url = urllib.unquote_plus(extract_vol.url)
            self.debug("Attempting to download volume at url %s" % formatted_url)
            response = urllib.urlopen(formatted_url)
            self.debug("response from volume url %s" % response.getcode())
            fd, path = tempfile.mkstemp()
            self.debug("Saving volume %s to path %s" %(self.volume.id, path))
            os.close(fd)
            with open(path, 'wb') as fd:
                fd.write(response.read())
            self.debug("Saved volume successfully")
        except Exception:
            self.fail(
                "Extract Volume Failed with invalid URL %s (vol id: %s)" \
                % (extract_vol.url, self.volume.id)
            )

    @attr(tags = ["advanced", "advancedns", "smoke", "basic", "provisioning"])
    def test_07_resize_fail(self):
        """Test resize (negative) non-existent volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug("Fail Resize Volume ID: %s" % self.volume.id)

        # first, an invalid id
        cmd                = resizeVolume.resizeVolumeCmd()
        cmd.id             = "invalid id"
        cmd.diskofferingid = self.services['resizeddiskofferingid']
        success            = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            #print str(ex)
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
                success,
                True,
                "ResizeVolume - verify invalid id is handled appropriately")

        # Next, we'll try an invalid disk offering id
        cmd.id             = self.volume.id
        cmd.diskofferingid = "invalid id"
        success            = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "invalid" in str(ex):
                success = True
        self.assertEqual(
                success,
                True,
                "ResizeVolume - verify disk offering is handled appropriately")

        # try to resize a root disk with a disk offering, root can only be resized by size=
        # get root vol from created vm
        list_volume_response = Volume.list(
                                            self.apiClient,
                                            virtualmachineid=self.virtual_machine.id,
                                            type='ROOT',
                                            listall=True
                                            )

        rootvolume = list_volume_response[0]

        cmd.id             = rootvolume.id
        cmd.diskofferingid = self.services['diskofferingid']
        success            = False
        try:
            self.apiClient.resizeVolume(cmd)
        except Exception as ex:
            if "Can only resize Data volumes" in str(ex):
                success = True
        self.assertEqual(
                success,
                True,
                "ResizeVolume - verify root disks cannot be resized by disk offering id")

        # Ok, now let's try and resize a volume that is not custom.
        cmd.id             = self.volume.id
        cmd.diskofferingid = self.services['diskofferingid']
        cmd.size           = 4
        currentSize        = self.volume.size

        self.debug(
                "Attaching volume (ID: %s) to VM (ID: %s)" % (
                                                    self.volume.id,
                                                    self.virtual_machine.id)
                 )
        #attach the volume
        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        #stop the vm if it is on xenserver
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() == "vmware":
            self.skipTest("Resize Volume is unsupported on VmWare")

        self.apiClient.resizeVolume(cmd)
        count = 0
        success = True
        while count < 10:
            list_volume_response = Volume.list(
                                                self.apiClient,
                                                id=self.volume.id,
                                                type='DATADISK'
                                                )
            for vol in list_volume_response:
                if vol.id == self.volume.id and vol.size != currentSize and vol.state != "Resizing":
                    success = False
            if success:
                break
            else:
                time.sleep(1)
                count += 1

        self.assertEqual(
                         success,
                         True,
                         "Verify the volume did not resize"
                         )
        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.start(self.apiClient)
            time.sleep(30)
        return 


    @attr(tags = ["advanced", "advancedns", "smoke", "basic", "provisioning"])
    def test_08_resize_volume(self):
        """Test resize a volume"""
        # Verify the size is the new size is what we wanted it to be.
        self.debug(
                "Attaching volume (ID: %s) to VM (ID: %s)" % (
                                                    self.volume.id,
                                                    self.virtual_machine.id
                                                    ))

        self.virtual_machine.attach_volume(self.apiClient, self.volume)
        self.attached = True
        hosts = Host.list(self.apiClient, id=self.virtual_machine.hostid)
        self.assertTrue(isinstance(hosts, list))
        self.assertTrue(len(hosts) > 0)
        self.debug("Found %s host" % hosts[0].hypervisor)

        if hosts[0].hypervisor == "XenServer":
            self.virtual_machine.stop(self.apiClient)
        elif hosts[0].hypervisor.lower() == "vmware":
            self.skipTest("Resize Volume is unsupported on VmWare")

        # resize the data disk
        self.debug("Resize Volume ID: %s" % self.volume.id)

        cmd                = resizeVolume.resizeVolumeCmd()
        cmd.id             = self.volume.id
        cmd.diskofferingid = self.services['resizeddiskofferingid']

        self.apiClient.resizeVolume(cmd)

        count = 0
        success = False
        while count < 3:
            list_volume_response = Volume.list(
                                                self.apiClient,
                                                id=self.volume.id,
                                                type='DATADISK'
                                                )
            for vol in list_volume_response:
                if vol.id == self.volume.id and vol.size == 3221225472L and vol.state == 'Ready':
                    success = True
            if success:
                break
            else:
                time.sleep(10)
                count += 1

        self.assertEqual(
                         success,
                         True,
                         "Check if the data volume resized appropriately"
                         )

        # resize the root disk
        self.debug("Resize Root for : %s" % self.virtual_machine.id)

        # get root vol from created vm
        list_volume_response = Volume.list(
                                            self.apiClient,
                                            virtualmachineid=self.virtual_machine.id,
                                            type='ROOT',
                                            listall=True
                                            )

        rootvolume = list_volume_response[0]

        cmd                = resizeVolume.resizeVolumeCmd()
        cmd.id             = rootvolume.id
        cmd.size           = 10
        cmd.shrinkok       = "true"

        self.apiClient.resizeVolume(cmd)

        count = 0
        success = False
        while count < 3:
            list_volume_response = Volume.list(
                                                self.apiClient,
                                                id=rootvolume.id
                                                )
            for vol in list_volume_response:
                if vol.id == rootvolume.id and vol.size == 10737418240L and vol.state == 'Ready':
                    success = True
            if success:
                break
            else:
                time.sleep(10)
                count += 1
Пример #21
0
    def test_02_resize_root_volume_on_working_vm(self):
        ''' Test Resize Root volume on Running Virtual Machine
        '''
        self.assertEqual(VirtualMachine.RUNNING, self.virtual_machine2.state, "Running")
        volume = list_volumes(
            self.apiclient,
            virtualmachineid = self.virtual_machine2.id,
            type = "ROOT",
            listall = True
            )
        volume = volume[0]

        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != volume.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertEqual(volume.type, 'ROOT', "Volume is not of ROOT type")
        shrinkOk = False
        if volume.size > int((self.disk_offering_20.disksize) * (1024**3)):
            shrinkOk= True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id
        cmd.size = 20
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)

        new_size = Volume.list(
            self.apiclient,
            id=volume.id,
            listall= True
            )

        self.assertTrue(
            (new_size[0].size == int((self.disk_offering_20.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)"
            )
        volume = new_size[0]

        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != volume.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        shrinkOk = False
        if volume.size > int((self.disk_offering_100.disksize) * (1024**3)):
            shrinkOk= True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volume.id
        cmd.size = 100
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(
            self.apiclient,
            id=volume.id,
            listall= True
            )

        volume = new_size[0]

        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].size != volume.size:
                raise Exception("Storpool volume size is not the same as CloudStack db size")
        except spapi.ApiError as err:
           raise Exception(err)

        self.assertTrue(
            (new_size[0].size == int((self.disk_offering_100.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)"
            )
Пример #22
0
    def test_CLOUDSTACK_6181_vm_root_resize(self):
        """
        @Desc: Test root volume resize of running VM
        @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-6181
        @Steps:
        Step1: Deploy VM, resize root volume via 'resizeVolume'.
        """
        # Check whether usage server is running or not

        if self.hypervisor.lower() != 'kvm':
            self.skipTest("Test can be run only on KVM hypervisor")
        # deploy virtual machine in stopped state
        self.services["virtual_machine"]["zoneid"] = self.zone.id
        self.services["virtual_machine"]["template"] = self.template.id

        # Step3: Verifying that VM creation is successful
        virtual_machine = VirtualMachine.create(
            self.apiClient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(virtual_machine)
        # Verify VM state
        self.assertEqual(
            virtual_machine.state,
            'Running',
            "Check VM state is Running or not"
        )
        volumes = list_volumes(
            self.apiClient,
            virtualmachineid=virtual_machine.id,
            type='ROOT',
            listall=True
        )

        self.assertIsNotNone(volumes, "root volume is not returned properly")
        newrootsize = (self.template.size >> 30) + 2
        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = volumes[0].id
        cmd.size = newrootsize
        self.apiClient.resizeVolume(cmd)

        volumes_after_resize = list_volumes(
            self.apiClient,
            virtualmachineid=virtual_machine.id,
            type='ROOT',
            listall=True
        )

        rootvolume = volumes_after_resize[0]
        success = False
        if rootvolume is not None and rootvolume.size == (newrootsize << 30):
            success = True

        self.assertEqual(
            success,
            True,
            "Check if the root volume resized appropriately"
        )
        return
Пример #23
0
    def test_03_resize_attached_volume(self):
        ''' Test Resize Volume  Attached To Virtual Machine
        '''
        #=======================================================================
        # list_volume_response = Volume.list(
        #     self.apiclient,
        #     id = self.volume_1.id
        #     )
        # volume =list_volume_response[0]
        # self.assertIsNotNone(lvolume, "Volume response is  None")
        #=======================================================================
        shrinkOk = False
        if self.volume_1.size > int(
            (self.disk_offering_20.disksize) * (1024**3)):
            shrinkOk = True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume_1.id
        cmd.diskofferingid = self.disk_offering_20.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)

        new_size = Volume.list(self.apiclient, id=self.volume_1.id)

        self.assertTrue(
            (new_size[0].size == int(
                (self.disk_offering_20.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)")
        self.volume_1 = new_size[0]
        shrinkOk = False
        if self.volume_1.size > int(
            (self.disk_offering_100.disksize) * (1024**3)):
            shrinkOk = True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume_1.id
        cmd.diskofferingid = self.disk_offering_100.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(self.apiclient, id=self.volume_1.id)

        self.assertTrue(
            (new_size[0].size == int(
                (self.disk_offering_100.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)")

        # return to small disk
        self.volume_1 = new_size[0]
        shrinkOk = False
        if self.volume_1.size > int(
            (self.disk_offerings.disksize) * (1024**3)):
            shrinkOk = True

        cmd.diskofferingid = self.disk_offerings.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(self.apiclient, id=self.volume_1.id)
        self.assertTrue((new_size[0].size == int(
            (self.disk_offerings.disksize) * (1024**3))),
                        "Could not return to Small disk")
Пример #24
0
    def test_04_resize_detached_volume(self):
        ''' Test Resize Volume Detached To Virtual Machine
        '''
        list_vm_volumes = Volume.list(self.apiclient,
                                      virtualmachineid=self.virtual_machine.id,
                                      id=self.volume_2.id)
        #check that the volume is not attached to VM
        self.assertIsNone(list_vm_volumes, "List volumes is not None")

        shrinkOk = False
        if self.volume_2.size > int(
            (self.disk_offering_20.disksize) * (1024**3)):
            shrinkOk = True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume_2.id
        cmd.diskofferingid = self.disk_offering_20.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)

        new_size = Volume.list(self.apiclient, id=self.volume_2.id)

        self.assertTrue(
            (new_size[0].size == int(
                (self.disk_offering_20.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)")
        self.volume_2 = new_size[0]
        shrinkOk = False
        if self.volume_2.size > int(
            (self.disk_offering_100.disksize) * (1024**3)):
            shrinkOk = True

        cmd = resizeVolume.resizeVolumeCmd()
        cmd.id = self.volume_2.id
        cmd.diskofferingid = self.disk_offering_100.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(self.apiclient, id=self.volume_2.id)

        self.assertTrue(
            (new_size[0].size == int(
                (self.disk_offering_100.disksize) * (1024**3))),
            "New size is not int((self.disk_offering_20) * (1024**3)")

        # return to small disk
        self.volume_2 = new_size[0]
        shrinkOk = False
        if self.volume_2.size > int(
            (self.disk_offerings.disksize) * (1024**3)):
            shrinkOk = True

        cmd.diskofferingid = self.disk_offerings.id
        cmd.shrinkok = shrinkOk

        self.apiclient.resizeVolume(cmd)
        new_size = Volume.list(self.apiclient, id=self.volume_2.id)
        self.assertTrue((new_size[0].size == int(
            (self.disk_offerings.disksize) * (1024**3))),
                        "Could not return to Small disk")