Пример #1
0
 def updateVmwareCreateFullCloneSetting(self, tearDown):
     if not tearDown:
         Configurations.update(self.apiclient,
                               "vmware.create.full.clone",
                               "true")
         allStoragePools = StoragePool.list(
             self.apiclient
         )
         for pool in allStoragePools:
             Configurations.update(self.apiclient,
                                   storageid=pool.id,
                                   name="vmware.create.full.clone",
                                   value="true")
     else:
         Configurations.update(self.apiclient,
                               "vmware.create.full.clone",
                               self.fullClone[0].value.lower())
         allStoragePools = StoragePool.list(
             self.apiclient
         )
         for pool in allStoragePools:
             Configurations.update(self.apiclient,
                                   storageid=pool.id,
                                   name="vmware.create.full.clone",
                                   value=self.storeCloneValues[pool.id])
    def setUpClass(cls):
        testClient = super(TestAttachDataDiskOnCWPS, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.testdata = testClient.getParsedTestDataConfig()
        cls.hypervisor = cls.testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls._cleanup = []
        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.testdata["ostype"])
        cls.skiptest = False

        try:
            cls.pools = StoragePool.list(
                cls.apiclient,
                zoneid=cls.zone.id,
                scope="CLUSTER")
        except Exception as e:
            cls.skiptest = True
            return
        try:

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

            # Create user api client of the account
            cls.userapiclient = testClient.getUserApiClient(
                UserName=cls.account.name,
                DomainName=cls.account.domain
            )
            # Create Service offering
            cls.service_offering = ServiceOffering.create(
                cls.apiclient,
                cls.testdata["service_offering"],
            )
            cls._cleanup.append(cls.service_offering)

            # Create Disk offering
            cls.disk_offering = DiskOffering.create(
                cls.apiclient,
                cls.testdata["disk_offering"],
                custom=True,
                tags=CLUSTERTAG1,
            )

            cls._cleanup.append(cls.disk_offering)

        except Exception as e:
            cls.tearDownClass()
            raise e
        return
Пример #3
0
    def setUpClass(cls):
        testClient = super(TestVolumes, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls._cleanup = []
        # 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.hypervisor = testClient.getHypervisorInfo()
        cls.invalidStoragePoolType = False
        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"]["tiny"])
        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"])
        pools = StoragePool.list(cls.apiclient)
        # cls.assertEqual(
        #         validateList(pools)[0],
        #         PASS,
        #         "storage pool list validation failed")

        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
        ]
Пример #4
0
    def setUpClass(cls):
        try:
            cls._cleanup = []
            cls.testClient = super(testHaPoolMaintenance,
                                   cls).getClsTestClient()
            cls.api_client = cls.testClient.getApiClient()
            cls.services = cls.testClient.getParsedTestDataConfig()
            # Get Domain, Zone, Template
            cls.domain = get_domain(cls.api_client)
            cls.zone = get_zone(cls.api_client,
                                cls.testClient.getZoneForTests())
            cls.template = get_template(cls.api_client, cls.zone.id,
                                        cls.services["ostype"])
            cls.hypervisor = cls.testClient.getHypervisorInfo()
            cls.services['mode'] = cls.zone.networktype
            cls.hypervisor = cls.testClient.getHypervisorInfo()
            cls.services["virtual_machine"]["zoneid"] = cls.zone.id
            cls.services["virtual_machine"]["template"] = cls.template.id
            cls.clusterWithSufficientPool = None
            cls.listResponse = None
            clusters = Cluster.list(cls.api_client, zoneid=cls.zone.id)

            if not validateList(clusters)[0]:

                cls.debug("check list cluster response for zone id %s" %
                          cls.zone.id)
                cls.listResponse = True
                return

            for cluster in clusters:
                cls.pool = StoragePool.list(cls.api_client,
                                            clusterid=cluster.id,
                                            keyword="NetworkFilesystem")

                if not validateList(cls.pool)[0]:

                    cls.debug("check list cluster response for zone id %s" %
                              cls.zone.id)
                    cls.listResponse = True
                    return

                if len(cls.pool) >= 2:
                    cls.clusterWithSufficientPool = cluster
                    break
            if not cls.clusterWithSufficientPool:
                return

            cls.services["service_offerings"]["tiny"]["offerha"] = "True"

            cls.services_off = ServiceOffering.create(
                cls.api_client, cls.services["service_offerings"]["tiny"])
            cls._cleanup.append(cls.services_off)

        except Exception as e:
            cls.tearDownClass()
            raise Exception("Warning: Exception in setup : %s" % e)
        return
Пример #5
0
    def setUpClass(cls):
        testClient = super(TestAttachDataDisk, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.testdata = testClient.getParsedTestDataConfig()
        cls.hypervisor = cls.testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls._cleanup = []
        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.testdata["ostype"])
        cls.skiptest = False

        try:
            cls.pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id)
        except Exception as e:
            cls.skiptest = True
            return
        try:

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

            # Create user api client of the account
            cls.userapiclient = testClient.getUserApiClient(
                UserName=cls.account.name,
                DomainName=cls.account.domain
            )
            # Create Service offering
            cls.service_offering_zone1 = ServiceOffering.create(
                cls.apiclient,
                cls.testdata["service_offering"],
                tags=ZONETAG1
            )
            cls._cleanup.append(cls.service_offering_zone1)

            # Create Disk offering
            cls.disk_offering = DiskOffering.create(
                cls.apiclient,
                cls.testdata["disk_offering"]
            )

            cls._cleanup.append(cls.disk_offering)

        except Exception as e:
            cls.tearDownClass()
            raise e
        return
    def setUpClass(cls):
        testClient = super(TestVolumes, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls._cleanup = []
        # 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.hypervisor = testClient.getHypervisorInfo()
        cls.invalidStoragePoolType = False
        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"]["tiny"])
        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"],
        )
        pools = StoragePool.list(cls.apiclient)
        # cls.assertEqual(
        #         validateList(pools)[0],
        #         PASS,
        #         "storage pool list validation failed")

        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,
        ]
Пример #7
0
 def updateVmwareSettings(cls, tearDown):
     value = "false"
     if not tearDown:
         value = "true"
     if cls.hypervisor.lower() == 'vmware':
         Configurations.update(cls.apiclient, "vmware.create.full.clone",
                               value)
         allStoragePools = StoragePool.list(cls.apiclient)
         for pool in allStoragePools:
             Configurations.update(cls.apiclient,
                                   storageid=pool.id,
                                   name="vmware.create.full.clone",
                                   value=value)
Пример #8
0
 def check_storage_pools(self, virtualmachineid):
     """
     list storage pools available to the VM
     """
     vm = VirtualMachine.list(self.apiClient, id=virtualmachineid)[0]
     hostid = vm.histid
     host = Host.list(self.apiClient, id=hostid)[0]
     clusterid = host.clusterid
     storage_pools = StoragePool.list(self.apiClient, clusterid=clusterid)
     if len(storage_pools) < 2:
         self.skipTest(
             "at least two accesible primary storage pools needed for the vm to perform this test"
         )
     return storage_pools
Пример #9
0
    def test_05_storage_pools(self):
        """Check the status of Storage pools"""

        # Validate the following
        # 1. List storage pools for the zone
        # 2. Check state is "enabled" or not

        storage_pools = StoragePool.list(self.apiclient,
                                         zoneid=self.zone.id,
                                         listall=True)
        self.assertEqual(isinstance(storage_pools, list), True,
                         "Check if listStoragePools returns a valid response")
        for storage_pool in storage_pools:
            self.assertEqual(storage_pool.state, 'Up',
                             "storage pool should be in Up state and running")
        return
    def test_05_storage_pools(self):
        """Check the status of Storage pools"""

        # Validate the following
        # 1. List storage pools for the zone
        # 2. Check state is "enabled" or not

        storage_pools = StoragePool.list(
                          self.apiclient,
                          zoneid=self.zone.id,
              listall=True
                          )
        self.assertEqual(
                         isinstance(storage_pools, list),
                         True,
                         "Check if listStoragePools returns a valid response"
                         )
        for storage_pool in storage_pools:
            self.assertEqual(
                             storage_pool.state,
                             'Up',
                             "storage pool should be in Up state and running"
                             )
        return
Пример #11
0
          print "Disable zone"
          zoneCmd = updateZone.updateZoneCmd()
          zoneCmd.id = zone.id
          zoneCmd.allocationstate = 'Disabled'
          apiClient.updateZone(zoneCmd)

    ssvms = list_ssvms(apiClient)
    if ssvms:
      for ssvm in ssvms:
        print "ssvm name={}, id={}".format(ssvm.name, ssvm.id)
        print "Destroy SSVM"
        cmd = destroySystemVm.destroySystemVmCmd()
        cmd.id = ssvm.id
        apiClient.destroySystemVm(cmd)

    storages = StoragePool.list(apiClient)
    if storages:
      for storage in storages:
        print "storage name={}, id={}".format(storage.name, storage.id)
        if storage.state == 'Maintenance':
          print "delete StoragePool"
          cmd = deleteStoragePool.deleteStoragePoolCmd()
          cmd.id = storage.id
          cmd.forced = 'True'
          apiClient.deleteStoragePool(cmd)
        else:
          print "Delete StoragePool"
          s = StoragePool(tmp_dict)
          s.id = storage.id
          s.forced = 'True'
          s.delete(apiClient)
Пример #12
0
    def setUpClass(cls):
        testClient = super(TestVmSnapshot, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls._cleanup = []
        cls.unsupportedHypervisor = False
        cls.hypervisor = testClient.getHypervisorInfo()
        if cls.hypervisor.lower() != "kvm":
            cls.unsupportedHypervisor = True
            return

        cls.services = testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())

        hosts = Host.list(cls.apiclient,
                          zoneid=cls.zone.id,
                          type='Routing',
                          hypervisor='KVM')

        pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id)

        for pool in pools:
            if pool.type == "NetworkFilesystem" or pool.type == "Filesystem":
                raise unittest.SkipTest(
                    "Storage-based snapshots functionality is not supported for NFS/Local primary storage"
                )

        for host in hosts:
            if host.details['Host.OS'] in ['CentOS']:
                raise unittest.SkipTest(
                    "The standard `qemu-kvm` which is the default for CentOS does not support the new functionality. It has to be installed `qemu-kvm-ev`"
                )

        Configurations.update(cls.apiclient,
                              name="kvm.vmstoragesnapshot.enabled",
                              value="true")
        #The version of CentOS has to be supported
        templ = {
            "name": "CentOS8",
            "displaytext": "CentOS 8",
            "format": "QCOW2",
            "url":
            "http://download.cloudstack.org/releases/4.14/default-tmpl-centos8.0.qcow2.bz2",
            "ispublic": "True",
            "isextractable": "True",
            "hypervisor": cls.hypervisor,
            "zoneid": cls.zone.id,
            "ostype": "CentOS 8",
            "directdownload": True,
        }

        template = Template.register(cls.apiclient,
                                     templ,
                                     zoneid=cls.zone.id,
                                     hypervisor=cls.hypervisor)
        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["small"]["zoneid"] = cls.zone.id
        cls.services["templates"]["ostypeid"] = template.ostypeid
        cls.services["zoneid"] = cls.zone.id

        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     domainid=cls.domain.id)
        cls._cleanup.append(cls.account)

        service_offerings_nfs = {
            "name": "nfs",
            "displaytext": "nfs",
            "cpunumber": 1,
            "cpuspeed": 500,
            "memory": 512,
            "storagetype": "shared",
            "customizediops": False,
        }

        cls.service_offering = ServiceOffering.create(
            cls.apiclient,
            service_offerings_nfs,
        )

        cls._cleanup.append(cls.service_offering)

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services,
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.zone.networktype,
            hypervisor=cls.hypervisor,
            rootdisksize=20,
        )
        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"
        return
    def setUpClass(cls):
        try:
            cls._cleanup = []
            cls.testClient = super(
                testHaPoolMaintenance,
                cls).getClsTestClient()
            cls.api_client = cls.testClient.getApiClient()
            cls.services = cls.testClient.getParsedTestDataConfig()
            # Get Domain, Zone, Template
            cls.domain = get_domain(cls.api_client)
            cls.zone = get_zone(
                cls.api_client,
                cls.testClient.getZoneForTests())
            cls.template = get_template(
                cls.api_client,
                cls.zone.id,
                cls.services["ostype"]
            )
            cls.hypervisor = cls.testClient.getHypervisorInfo()
            cls.services['mode'] = cls.zone.networktype
            cls.hypervisor = cls.testClient.getHypervisorInfo()
            cls.services["virtual_machine"]["zoneid"] = cls.zone.id
            cls.services["virtual_machine"]["template"] = cls.template.id
            cls.clusterWithSufficientPool = None
            cls.listResponse = None
            clusters = Cluster.list(cls.api_client, zoneid=cls.zone.id)

            if not validateList(clusters)[0]:

                cls.debug(
                    "check list cluster response for zone id %s" %
                    cls.zone.id)
                cls.listResponse = True
                return

            for cluster in clusters:
                cls.pool = StoragePool.list(cls.api_client,
                                            clusterid=cluster.id,
                                            keyword="NetworkFilesystem"
                                            )

                if not validateList(cls.pool)[0]:

                    cls.debug(
                        "check list cluster response for zone id %s" %
                        cls.zone.id)
                    cls.listResponse = True
                    return

                if len(cls.pool) >= 2:
                    cls.clusterWithSufficientPool = cluster
                    break
            if not cls.clusterWithSufficientPool:
                return

            cls.services["service_offerings"][
                "tiny"]["offerha"] = "True"

            cls.services_off = ServiceOffering.create(
                cls.api_client,
                cls.services["service_offerings"]["tiny"])
            cls._cleanup.append(cls.services_off)

        except Exception as e:
            cls.tearDownClass()
            raise Exception("Warning: Exception in setup : %s" % e)
        return
Пример #14
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", "hyperv"):
            self.skipTest("Resize Volume is unsupported on VmWare and Hyper-V")

        # 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
Пример #15
0
 def setUpClass(cls):
     testClient = super(TestPathVolume, cls).getClsTestClient()
     cls.apiclient = testClient.getApiClient()
     cls.testdata = testClient.getParsedTestDataConfig()
     #Get Zone,Domain and templates
     cls.domain = get_domain(cls.apiclient)
     cls.zone = get_zone(cls.apiclient)
     cls.testdata["mode"] = cls.zone.networktype
     cls.template = get_template(cls.apiclient, cls.zone.id, cls.testdata["ostype"])
     cls.testdata["template"]["ostypeid"] = cls.template.ostypeid
     if cls.template == FAILED:
             cls.fail("get_template() failed to return template with description %s" % cls.testdata["ostype"])
     cls._cleanup = []
     try:
         cls.account = Account.create(cls.apiclient,
                                      cls.testdata["account"],
                                      domainid=cls.domain.id
                                      )
         cls._cleanup.append(cls.account)
         #createa two service offerings
         cls.service_offering_1 = ServiceOffering.create(cls.apiclient, cls.testdata["service_offerings"]["small"])
         cls._cleanup.append(cls.service_offering_1)
         # Create Disk offerings
         cls.disk_offering_1 = DiskOffering.create(cls.apiclient, cls.testdata["disk_offering"])
         cls._cleanup.append(cls.disk_offering_1)
         #check if zone wide storage is enable
         cls.list_storage = StoragePool.list(cls.apiclient,
                                             scope="ZONE"
                                             )
         if cls.list_storage:
             cls.zone_wide_storage = cls.list_storage[0]
             cls.debug("zone wide storage id is %s" % cls.zone_wide_storage.id)
             cls.testdata["tags"] = "zp"
             update1 = StoragePool.update(cls.apiclient,
                                          id=cls.zone_wide_storage.id,
                                          tags=cls.testdata["tags"]
                                          )
             cls.debug("Storage %s pool tag%s" % (cls.zone_wide_storage.id, update1.tags))
             cls.testdata["service_offerings"]["tags"] = "zp"
             cls.tagged_so = ServiceOffering.create(cls.apiclient, cls.testdata["service_offerings"])
             cls.testdata["service_offerings"]["tags"] = " "
             cls._cleanup.append(cls.tagged_so)
             #create tagged disk offerings
             cls.testdata["disk_offering"]["tags"] = "zp"
             cls.disk_offering_tagged = DiskOffering.create(cls.apiclient, cls.testdata["disk_offering"])
             cls._cleanup.append(cls.disk_offering_tagged)
         else:
             cls.debug("No zone wide storage found")
         #check if local storage is enable
         if cls.zone.localstorageenabled:
             cls.testdata["disk_offering"]["tags"] = " "
             cls.testdata["service_offerings"]["storagetype"] = 'local'
             cls.service_offering_2 = ServiceOffering.create(cls.apiclient, cls.testdata["service_offerings"])
             cls._cleanup.append(cls.service_offering_2)
             #craete a compute offering with local storage
             cls.testdata["disk_offering"]["storagetype"] = 'local'
             cls.disk_offering_local = DiskOffering.create(cls.apiclient, cls.testdata["disk_offering"])
             cls._cleanup.append(cls.disk_offering_local)
             cls.testdata["disk_offering"]["storagetype"] = ' '
         else:
             cls.debug("No local storage found")
         cls.userapiclient = testClient.getUserApiClient(UserName=cls.account.name,
                                                         DomainName=cls.account.domain
                                                         )
         #Check if login is successful with new account
         response = User.login(cls.userapiclient,
                               username=cls.account.name,
                               password=cls.testdata["account"]["password"]
                               )
         assert response.sessionkey is not None
         #response should have non null value
     except Exception as e:
             cls.tearDownClass()
             raise e
     return
Пример #16
0
    def test_01_multiple_snapshot_in_zwps(self):
        """ Test multiple volume snapshot in zwps

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

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

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

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

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

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

        self.cleanup.append(self.vm_zwps)

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

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

        root_volume = volumes_root_list[0]

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

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

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

        data_volume = volumes_data_list[0]

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

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

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

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

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

        snap_list_validation_result = validateList(snapshots_list)

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

        snap_count = len(snapshots_list)

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

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

                snap_list_validation_result = validateList(snapshots_list)

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

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

            snap_list_validation_result = validateList(snapshots_list)

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

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

        return
Пример #17
0
    def test_local_storage_data_disk_tag(self):
        """
        @Desc: Test whether tags are honoured while creating
        data disks on local storage
        @Steps:
        This test needs multiple local storages
        Step1: create a tag 'loc' on the local storage
        Step2: create a disk offering with this storage tag 'loc'
        Step3: create a VM and create disk by selecting the disk offering
         created in step2
        step4: check whether the data disk created in step3 is created on
        local storage with tag 'loc'
        """
        if not self.zone.localstorageenabled:
            self.skipTest('Local storage is not enable for this '
                          'zone. skipping')

        local_storages = StoragePool.list(self.apiClient,
                                          zoneid=self.zone.id,
                                          scope='HOST')
        self.assertEqual(
            isinstance(local_storages, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            local_storages,
            None,
            "Check if local storage pools exists in ListStoragePools"
        )

        cmd = updateStoragePool.updateStoragePoolCmd()
        cmd.zoneid = self.zone.id
        cmd.tags = 'loc'
        cmd.id = local_storages[0].id
        self.apiClient.updateStoragePool(cmd)

        self.services["disk_offering"]["storagetype"] = 'local'
        self.services["disk_offering"]["tags"] = 'loc'
        disk_offering = DiskOffering.create(
            self.apiClient,
            self.services["disk_offering"]
        )
        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,
            mode=self.services["mode"]
        )
        self.cleanup.append(virtual_machine)
        self.cleanup.append(disk_offering)
        # Verify VM state
        self.assertEqual(
            virtual_machine.state,
            'Running',
            "Check VM state is Running or not"
        )
        self.volume = Volume.create(
            self.apiClient,
            self.services["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=disk_offering.id
        )
        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"
        )

        storage_pool = StoragePool.list(self.apiClient, id=volume.storageid)

        self.assertEqual(
            volume.storagetype,
            'local',
            "Check list storage pool response has local as storage type"
        )

        self.assertEqual(
            storage_pool[0].tags,
            'loc',
            "Check list storage pool response has tag"
        )
        return
    def test_01_multiple_snapshot_in_zwps(self):
        """ Test multiple volume snapshot in zwps

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

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

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

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

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

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

        self.cleanup.append(self.vm_zwps)

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

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

        root_volume = volumes_root_list[0]

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

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

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

        data_volume = volumes_data_list[0]

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

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

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

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

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

        snap_list_validation_result = validateList(snapshots_list)

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

        snap_count = len(snapshots_list)

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

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

                snap_list_validation_result = validateList(snapshots_list)

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

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

            snap_list_validation_result = validateList(snapshots_list)

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

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

        return
Пример #19
0
    def test_01_recover_VM(self):
        """ Test Restore VM on VMWare
            1. Deploy a VM without datadisk
            2. Restore the VM
            3. Verify that VM comes up in Running state
        """
        try:
            self.pools = StoragePool.list(self.apiclient,
                                          zoneid=self.zone.id,
                                          scope="CLUSTER")

            status = validateList(self.pools)

            # Step 3
            self.assertEqual(
                status[0], PASS,
                "Check: Failed to list  cluster wide storage pools")

            if len(self.pools) < 2:
                self.skipTest("There must be at atleast two cluster wide\
                storage pools available in the setup")

        except Exception as e:
            self.skipTest(e)

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

        self.vm = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            accountid=self.account.name,
            templateid=self.template.id,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_cwps.id,
            zoneid=self.zone.id,
        )
        # Step 2

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

        root_volume = volumes_root_list[0]

        # Restore VM till its ROOT disk is recreated on onother Primary Storage
        while True:
            self.vm.restore(self.apiclient)
            volumes_root_list = list_volumes(self.apiclient,
                                             virtualmachineid=self.vm.id,
                                             type=ROOT,
                                             listall=True)

            root_volume = volumes_root_list[0]

            if root_volume.storage != self.pools[0].name:
                break

        # Step 3
        vm_list = list_virtual_machines(self.apiclient, id=self.vm.id)

        state = vm_list[0].state
        i = 0
        while (state != "Running"):
            vm_list = list_virtual_machines(self.apiclient, id=self.vm.id)

            time.sleep(10)
            i = i + 1
            state = vm_list[0].state
            if i >= 10:
                self.fail("Restore VM Failed")
                break

        return
Пример #20
0
    def test_04_test_settings_for_storage(self):
        """
        1. Get the default value for the setting in storage scope
        2. Change the default value to new value
        3. Make sure updated value is same as new value
        4. Reset the config value
        5. Make sure that current value is same as default value
        :return:
        """
        storage = StoragePool.list(
            self.apiclient
        )

        self.assertIsNotNone(storage[0],
                             "There should be atleast 1 primary storage pool in the zone")

        config_name = "vmware.create.full.clone"
        configs = Configurations.list(
            self.apiclient,
            name=config_name,
            storageid=storage[0].id
        )
        self.assertIsNotNone(configs, "Fail to get storage pool setting %s " % config_name)

        orig_value = str(configs[0].value)
        new_value = 'false'

        Configurations.update(
            self.apiclient,
            name=config_name,
            value=new_value,
            storageid=storage[0].id
        )

        configs = Configurations.list(
            self.apiclient,
            name=config_name,
            storageid=storage[0].id
        )
        self.assertIsNotNone(configs, "Fail to get storage pool setting %s " % config_name)

        self.assertEqual(new_value,
                         (configs[0].value),
                         "Failed to set new config value")

        Configurations.reset(
            self.apiclient,
            name=config_name,
            storageid=storage[0].id
        )

        configs = Configurations.list(
            self.apiclient,
            name=config_name,
            storage=storage[0].id
        )
        self.assertIsNotNone(configs, "Fail to get storage pool setting %s " % config_name)

        self.assertEqual(orig_value,
                         (configs[0].value),
                         "Failed to reset the value for storage pool")
Пример #21
0
    def test_01_positive_test_1(self):
        """
        positive test for volume life cycle
        # 1. Deploy a vm [vm1] with shared storage and data disk
        # 2. Deploy a vm [vm2]with shared storage without data disk
        # 3.
        # 4. Create a new volume and attache to vm2
        # 5. Detach data disk from vm1 and download it
        #  Variance(1-9)
        # 6. Upload volume by providing url of downloaded volume in step 5
        # 7. Attach the volume to a different vm - vm2
        # 8. Try to delete an attached volume
        # 9. Create template from root volume of VM1
        # 10. Create new VM using the template created in step 9
        # 11. Delete the template
        # 12. Detach the disk from VM2 and re-attach the disk to VM1
        # 13.
        # 14.
        # 15.Migrate volume(detached) and then attach to a vm and live-migrate
        # 16.Upload volume of size smaller  than storage.max.volume.upload.size(leaving the negative case)
        # 17.NA
        # 18.
        # 19.NA
        # 20.Detach data disks from VM2 and delete volume

        """
        # 1. Deploy a vm [vm1] with shared storage and data disk
        self.virtual_machine_1 = VirtualMachine.create(self.userapiclient,
                                                       self.testdata["small"],
                                                       templateid=self.template.id,
                                                       accountid=self.account.name,
                                                       domainid=self.account.domainid,
                                                       serviceofferingid=self.service_offering_1.id,
                                                       zoneid=self.zone.id,
                                                       diskofferingid=self.disk_offering_1.id,
                                                       mode=self.testdata["mode"]
                                                       )
        verify_vm(self, self.virtual_machine_1.id)
        # List data volume for vm1
        list_volume = Volume.list(self.userapiclient,
                                  virtualmachineid=self.virtual_machine_1.id,
                                  type='DATADISK'
                                  )
        self.assertEqual(validateList(list_volume)[0], PASS, "Check List volume response for vm id  %s" % self.virtual_machine_1.id)
        list_data_volume_for_vm1 = list_volume[0]
        self.assertEqual(len(list_volume), 1, "There is no data disk attached to vm id:%s" % self.virtual_machine_1.id)
        self.assertEqual(list_data_volume_for_vm1.virtualmachineid, str(self.virtual_machine_1.id), "Check if volume state (attached) is reflected")
        # 2. Deploy a vm [vm2]with shared storage without data disk
        self.virtual_machine_2 = VirtualMachine.create(self.userapiclient,
                                                       self.testdata["small"],
                                                       templateid=self.template.id,
                                                       accountid=self.account.name,
                                                       domainid=self.account.domainid,
                                                       serviceofferingid=self.service_offering_1.id,
                                                       zoneid=self.zone.id,
                                                       mode=self.testdata["mode"]
                                                       )
        verify_vm(self, self.virtual_machine_2.id)

        #4. Create a new volume and attache to vm2
        self.volume = Volume.create(self.userapiclient,
                                    services=self.testdata["volume"],
                                    diskofferingid=self.disk_offering_1.id,
                                    zoneid=self.zone.id
                                    )

        list_data_volume = Volume.list(self.userapiclient,
                                       id=self.volume.id
                                       )
        self.assertEqual(validateList(list_data_volume)[0], PASS, "Check List volume response for volume %s" % self.volume.id)
        self.assertEqual(list_data_volume[0].id, self.volume.id, "check list volume response for volume id:  %s" % self.volume.id)
        self.debug("volume id %s got created successfully" % list_data_volume[0].id)
        # Attach volume to vm2
        self.virtual_machine_2.attach_volume(self.userapiclient,
                                             self.volume
                                             )
        verify_attach_volume(self, self.virtual_machine_2.id, self.volume.id)

        #Variance
        if self.zone.localstorageenabled:
            # V1.Create vm3 with local storage offering
            self.virtual_machine_local_3=VirtualMachine.create(self.userapiclient,
                                                               self.testdata["small"],
                                                               templateid=self.template.id,
                                                               accountid=self.account.name,
                                                               domainid=self.account.domainid,
                                                               serviceofferingid=self.service_offering_2.id,
                                                               zoneid=self.zone.id,
                                                               mode=self.testdata["mode"]
                                                               )
            verify_vm(self, self.virtual_machine_local_3.id)

            # V2.create two data disk on local storage
            self.local_volumes = []
            for i in range(2):

                    local_volume = Volume.create(self.userapiclient,
                                                 services=self.testdata["volume"],
                                                 diskofferingid=self.disk_offering_local.id,
                                                 zoneid=self.zone.id
                                                 )

                    list_local_data_volume = Volume.list(self.userapiclient,
                                                         id=local_volume.id
                                                         )
                    self.assertEqual(validateList(list_local_data_volume)[0], PASS, "Check List volume response for volume %s" % local_volume.id)
                    self.assertEqual(list_local_data_volume[0].id, local_volume.id, "check list volume response for volume id:  %s" % local_volume.id)
                    self.debug("volume id %s got created successfully" % list_local_data_volume[0].id)
                    self.local_volumes.append(local_volume)
            # V3.Attach local disk to vm1
            self.virtual_machine_1.attach_volume(self.userapiclient,
                                                 self.local_volumes[0]
                                                 )
            verify_attach_volume(self, self.virtual_machine_1.id, self.local_volumes[0].id)
        if self.list_storage:
            # V4.create vm4 with zone wide storage
            self.virtual_machine_zone_4 = VirtualMachine.create(self.userapiclient,
                                                                self.testdata["small"],
                                                                templateid=self.template.id,
                                                                accountid=self.account.name,
                                                                domainid=self.account.domainid,
                                                                serviceofferingid=self.tagged_so.id,
                                                                zoneid=self.zone.id,
                                                                mode=self.testdata["mode"]
                                                                )
            verify_vm(self, self.virtual_machine_zone_4.id)

            # V5.Create two data disk on zone  wide storage
            self.zone_volumes = []
            for i in range(2):

                    zone_volume = Volume.create(self.userapiclient,
                                                services=self.testdata["volume"],
                                                diskofferingid=self.disk_offering_tagged.id,
                                                zoneid=self.zone.id
                                                )

                    list_zone_data_volume = Volume.list(self.userapiclient,
                                                        id=zone_volume.id
                                                        )
                    self.assertEqual(validateList(list_zone_data_volume)[0], PASS, "Check List volume response for volume %s" % zone_volume.id)
                    self.assertEqual(list_zone_data_volume[0].id, zone_volume.id, "check list volume response for volume id:  %s" % zone_volume.id)
                    self.debug("volume id:%s got created successfully" % list_zone_data_volume[0].id)
                    self.zone_volumes.append(zone_volume)

            # V6.Attach data disk running on ZWPS to VM1 (root disk on shared)
            self.virtual_machine_1.attach_volume(self.userapiclient,
                                                 self.zone_volumes[0]
                                                 )
            verify_attach_volume(self, self.virtual_machine_1.id, self.zone_volumes[0].id)
            # V7. Create a cluster wide volume and attach to vm running on zone wide storage
            self.cluster_volume = Volume.create(self.userapiclient,
                                                services=self.testdata["volume"],
                                                diskofferingid=self.disk_offering_1.id,
                                                zoneid=self.zone.id
                                                )
            list_cluster_volume = Volume.list(self.userapiclient,
                                              id=self.cluster_volume.id
                                              )
            self.assertEqual(validateList(list_cluster_volume)[0], PASS, "Check List volume response for volume %s" % self.cluster_volume.id)
            self.assertEqual(list_cluster_volume[0].id, str(self.cluster_volume.id), "volume does not exist %s" % self.cluster_volume.id)
            self.debug("volume id %s got created successfuly" % list_cluster_volume[0].id)
            self.virtual_machine_zone_4.attach_volume(self.userapiclient,
                                                      self.cluster_volume
                                                      )
            verify_attach_volume(self, self.virtual_machine_zone_4.id, self.cluster_volume.id)
        if self.list_storage and self.zone.localstorageenabled:
            #V8.Attach zone wide volume to vm running on local storage
            self.virtual_machine_local_3.attach_volume(self.userapiclient,
                                                       self.zone_volumes[1]
                                                       )
            verify_attach_volume(self, self.virtual_machine_local_3.id, self.zone_volumes[1].id)
            # V9.Attach local volume to a vm running on zone wide storage
            self.virtual_machine_zone_4.attach_volume(self.userapiclient,
                                                      self.local_volumes[1]
                                                      )
            verify_attach_volume(self, self.virtual_machine_zone_4.id, self.local_volumes[1].id)
        # 5. Detach data disk from vm1 and download it
        self.virtual_machine_1.detach_volume(self.userapiclient,
                                             volume=list_data_volume_for_vm1
                                             )
        verify_detach_volume(self, self.virtual_machine_1.id, list_data_volume_for_vm1.id)
        # download detached volume
        self.extract_volume = Volume.extract(self.userapiclient,
                                             volume_id=list_data_volume_for_vm1.id,
                                             zoneid=self.zone.id,
                                             mode='HTTP_DOWNLOAD'
                                             )

        self.debug("extracted url is%s  :" % self.extract_volume.url)
        try:

            formatted_url = urllib.unquote_plus(self.extract_volume.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" % (list_data_volume_for_vm1.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)" % (self.extract_volume, list_data_volume_for_vm1.id))
        #Need to get format for downloaded volume ,for now using default format VHD
        if "OVA" in self.extract_volume.url.upper():
            self.testdata["upload_volume"]["format"] = "OVA"
        if "QCOW2" in self.extract_volume.url.upper():
            self.testdata["upload_volume"]["format"] = "QCOW2"
        # 6. Upload volume by providing url of downloaded volume in step 5
        self.upload_response = Volume.upload(self.userapiclient,
                                             zoneid=self.zone.id,
                                             url=self.extract_volume.url,
                                             services=self.testdata["upload_volume"]
                                             )
        self.upload_response.wait_for_upload(self.userapiclient
                                             )
        self.debug("uploaded volume id is %s" % self.upload_response.id)
        # 7. Attach the volume to a different vm - vm2
        self.virtual_machine_2.attach_volume(self.userapiclient,
                                             volume=self.upload_response
                                             )
        verify_attach_volume(self, self.virtual_machine_2.id, self.upload_response.id)
        # 8. Try to delete an attached volume
        try:
            self.volume.delete(self.userapiclient
                               )
            self.fail("Volume got deleted in attached state %s " % self.volume.id)
        except Exception as e:
            self.debug("Attached volume deletion failed because  %s" % e)
        #9. Create template from root volume of VM1(stop VM->create template -> start vm)

        self.virtual_machine_1.stop(self.userapiclient
                                    )

        self.list_root_disk_for_vm1 = Volume.list(self.userapiclient,
                                                  virtualmachineid=self.virtual_machine_1.id,
                                                  type='ROOT'
                                                  )
        self.assertEqual(validateList(self.list_root_disk_for_vm1)[0], PASS, "Check List volume response for vm %s" % self.virtual_machine_1.id)
        self.assertEqual(len(self.list_root_disk_for_vm1), 1, "list root disk for vm1 is empty : %s" % self.virtual_machine_1.id)
        self.template_from_vm1_root_disk = Template.create(self.userapiclient,
                                                           self.testdata["template"],
                                                           self.list_root_disk_for_vm1[0].id,
                                                           account=self.account.name,
                                                           domainid=self.account.domainid
                                                           )
        list_template = Template.list(self.userapiclient,
                                      templatefilter=self.testdata["templatefilter"],
                                      id=self.template_from_vm1_root_disk.id
                                      )
        self.assertEqual(validateList(list_template)[0], PASS, "Check List template response for template id %s" % self.template_from_vm1_root_disk.id)
        self.assertEqual(len(list_template), 1, "list template response is empty for template id  : %s" % list_template[0].id)
        self.assertEqual(list_template[0].id, self.template_from_vm1_root_disk.id, "list template id is not same as created template")
        self.debug("Template id:%s got created successfully" % self.template_from_vm1_root_disk.id)
        self.virtual_machine_1.start(self.userapiclient
                                     )
        # 10. Deploy a vm using template ,created  from vm1's root disk

        self.virtual_machine_3 = VirtualMachine.create(self.userapiclient,
                                                       self.testdata["small"],
                                                       templateid=self.template_from_vm1_root_disk.id,
                                                       accountid=self.account.name,
                                                       domainid=self.account.domainid,
                                                       serviceofferingid=self.service_offering_1.id,
                                                       zoneid=self.zone.id,
                                                       mode=self.testdata["mode"]
                                                       )
        verify_vm(self, self.virtual_machine_3.id)

        # 11.delete the template created from root disk of vm1
        try:
            self.template_from_vm1_root_disk.delete(self.userapiclient
                                                    )
            self.debug("Template id: %s got deleted successfuly" % self.template_from_vm1_root_disk.id)
        except Exception as e:
            raise Exception("Template deletion failed with error %s" % e)
        list_template = Template.list(self.userapiclient,
                                      templatefilter=self.testdata["templatefilter"],
                                      id=self.template_from_vm1_root_disk.id
                                      )
        self.assertEqual(list_template, None, "Template is not deleted, id %s:" % self.template_from_vm1_root_disk.id)
        self.debug("Template id%s got deleted successfully" % self.template_from_vm1_root_disk.id)

        # List vm and check the state of vm
        verify_vm(self, self.virtual_machine_3.id)

        #12.Detach the disk from VM2 and re-attach the disk to VM1
        self.virtual_machine_2.detach_volume(self.userapiclient,
                                             volume=self.upload_response
                                             )
        verify_detach_volume(self, self.virtual_machine_2.id, self.upload_response.id)

        self.virtual_machine_1.attach_volume(self.userapiclient,
                                             volume=self.upload_response
                                             )

        verify_attach_volume(self, self.virtual_machine_1.id, self.upload_response.id)

        # 15.Migrate volume(detached) and then attach to a vm and live-migrate
        self.migrate_volume = Volume.create(self.userapiclient,
                                            services=self.testdata["volume"],
                                            diskofferingid=self.disk_offering_1.id,
                                            zoneid=self.zone.id
                                            )
        list_volume = Volume.list(self.apiclient,
                                  id=self.migrate_volume.id
                                  )
        self.assertEqual(validateList(list_volume)[0], PASS, "Check List volume response for volume %s" % self.migrate_volume.id)
        self.assertEqual(list_volume[0].id, str(self.migrate_volume.id), "volume does not exist %s" % self.migrate_volume.id)
        self.debug("volume id %s got created successfuly" % list_volume[0].id)

        self.virtual_machine_1.attach_volume(self.userapiclient,
                                             self.migrate_volume
                                             )
        verify_attach_volume(self, self.virtual_machine_1.id, self.migrate_volume.id)

        self.virtual_machine_1.detach_volume(self.userapiclient,
                                             volume=self.migrate_volume
                                             )
        verify_detach_volume(self, self.virtual_machine_1.id, self.migrate_volume.id)

        list_volume = Volume.list(self.apiclient,
                                  id=self.migrate_volume.id
                                  )
        self.assertEqual(validateList(list_volume)[0], PASS, "Check List volume response for volume %s" % self.migrate_volume.id)
        self.assertEqual(list_volume[0].id, str(self.migrate_volume.id), "volume does not exist %s" % self.migrate_volume.id)
        self.debug("volume id %s got created successfuly" % list_volume[0].id)
        list_pool = StoragePool.list(self.apiclient,
                                     id=list_volume[0].storageid
                                     )
        self.assertEqual(validateList(list_pool)[0], PASS, "Check List pool response for storage id %s" % list_volume[0].storageid)
        self.assertGreater(len(list_pool), 0, "Check the list list storagepoolresponse for vm id:  %s" % list_volume[0].storageid)
        list_pools = StoragePool.list(self.apiclient,
                                      scope=list_pool[0].scope
                                      )
        self.assertEqual(validateList(list_pools)[0], PASS, "Check List pool response for scope %s" % list_pool[0].scope)
        self.assertGreater(len(list_pools), 0, "Check the list vm response for scope :%s" % list_volume[0].scope)
        storagepoolid = None
        for i in range(len(list_pools)):
            if list_volume[0].storageid != list_pools[i].id:
                storagepoolid = list_pools[i].id
                break
            else:
                self.debug("No pool available for volume migration ")

        if storagepoolid is not None:
            try:
                volume_migrate = Volume.migrate(self.apiclient,
                                                storageid=storagepoolid,
                                                volumeid=self.migrate_volume.id
                                                )
            except Exception as e:
                raise Exception("Volume migration failed with error %s" % e)

            self.virtual_machine_2.attach_volume(self.userapiclient,
                                                 self.migrate_volume
                                                 )
            verify_attach_volume(self, self.virtual_machine_2.id, self.migrate_volume.id)

            pool_for_migration = StoragePool.listForMigration(self.apiclient,
                                                              id=self.migrate_volume.id
                                                              )
            self.assertEqual(validateList(pool_for_migration)[0], PASS, "Check list pool For Migration response for volume %s" % self.migrate_volume.id)
            self.assertGreater(len(pool_for_migration), 0, "Check the listForMigration response for volume :%s" % self.migrate_volume.id)
            try:
                volume_migrate = Volume.migrate(self.apiclient,
                                                storageid=pool_for_migration[0].id,
                                                volumeid=self.migrate_volume.id,
                                                livemigrate=True
                                                )
            except Exception as e:
                raise Exception("Volume migration failed with error %s" % e)
        else:
            try:
                self.migrate_volume.delete(self.userapiclient
                                           )
                self.debug("volume id:%s got deleted successfully " % self.migrate_volume.id)
            except Exception as e:
                raise Exception("Volume deletion failed with error %s" % e)
        # 16.Upload volume of size smaller  than storage.max.volume.upload.size(leaving the negative case)
        self.testdata["upload_volume"]["format"] = "VHD"
        volume_upload = Volume.upload(self.userapiclient,
                                      self.testdata["upload_volume"],
                                      zoneid=self.zone.id
                                      )
        volume_upload.wait_for_upload(self.userapiclient
                                      )
        self.debug("volume id :%s got uploaded successfully is " % volume_upload.id)

        # 20.Detach data disk from vm 2 and delete the volume
        self.virtual_machine_2.detach_volume(self.userapiclient,
                                             volume=self.volume
                                             )
        verify_detach_volume(self, self.virtual_machine_2.id, self.volume.id)

        try:
            self.volume.delete(self.userapiclient
                               )
            self.debug("volume id:%s got deleted successfully " % self.volume.id)
        except Exception as e:
            raise Exception("Volume deletion failed with error %s" % e)
Пример #22
0
    def test_06_disk_offering_strictness_false(self):
        """Test to see change service offering is possible when disk offering strictness is set to false
        """
        # Validate the following
        # 1. Create service offering linked a disk offering and disk offering strictness is false
        # 2. Create a VM with that service offering
        # 3. Create another service offering with a different disk offering and disk offering strictness is false
        # 4. Try change service offering for VM should succeed

        if self.hypervisor.lower() == "lxc":
            self.skipTest("Skipping this test for {} due to bug CS-38153".format(self.hypervisor))
        self.storeCloneValues = {}
        if self.hypervisor.lower() == "vmware":
            self.fullClone = Configurations.list(self.apiclient, name="vmware.create.full.clone")
            assert isinstance(self.fullClone, list), "Config list not retrieved for vmware.create.full.clone"
            allStoragePools = StoragePool.list(
                self.apiclient
            )
            for pool in allStoragePools:
                self.storeCloneValues[pool.id] = Configurations.list(self.apiclient, name="vmware.create.full.clone", storageid=pool.id)[0].value.lower()
            self.updateVmwareCreateFullCloneSetting(False)

        offering_data = {
            'displaytext': 'TestDiskOfferingStrictnessFalse',
            'cpuspeed': 512,
            'cpunumber': 2,
            'name': 'TestDiskOfferingStrictnessFalse',
            'memory': 1024,
            'diskofferingstrictness': False
        }

        self.serviceOfferingWithDiskOfferingStrictnessFalse = ServiceOffering.create(
            self.apiclient,
            offering_data,
        )
        self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse)

        self.virtual_machine_with_diskoffering_strictness_false = VirtualMachine.create(
            self.apiclient,
            self.services["small"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.serviceOfferingWithDiskOfferingStrictnessFalse.id,
            mode=self.services["mode"]
        )

        try:
            self.virtual_machine_with_diskoffering_strictness_false.stop(self.apiclient)

            timeout = self.services["timeout"]

            while True:
                time.sleep(self.services["sleep"])

                # Ensure that VM is in stopped state
                list_vm_response = list_virtual_machines(
                    self.apiclient,
                    id=self.virtual_machine_with_diskoffering_strictness_false.id
                )

                if isinstance(list_vm_response, list):
                    vm = list_vm_response[0]
                    if vm.state == 'Stopped':
                        self.debug("VM state: %s" % vm.state)
                        break

                if timeout == 0:
                    raise Exception(
                        "Failed to stop VM (ID: %s) in change service offering" % vm.id)

                timeout = timeout - 1
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        self.disk_offering2 = DiskOffering.create(
                                    self.apiclient,
                                    self.services["disk_offering"],
                                    )
        self._cleanup.append(self.disk_offering2)
        offering_data = {
            'displaytext': 'TestDiskOfferingStrictnessFalse2',
            'cpuspeed': 1000,
            'cpunumber': 2,
            'name': 'TestDiskOfferingStrictnessFalse2',
            'memory': 1024,
            'diskofferingstrictness': False,
            'diskofferingid': self.disk_offering2.id
        }

        self.serviceOfferingWithDiskOfferingStrictnessFalse2 = ServiceOffering.create(
            self.apiclient,
            offering_data,
        )
        self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse2)
        cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd()
        cmd.id = self.virtual_machine_with_diskoffering_strictness_false.id
        cmd.serviceofferingid = self.serviceOfferingWithDiskOfferingStrictnessFalse2.id
        self.apiclient.changeServiceForVirtualMachine(cmd)

        list_vm_response = VirtualMachine.list(
            self.apiclient,
            id=self.virtual_machine_with_diskoffering_strictness_false.id
        )

        vm_response = list_vm_response[0]
        self.assertEqual(
            vm_response.id,
            self.virtual_machine_with_diskoffering_strictness_false.id,
            "Check virtual machine ID of upgraded VM"
        )

        self.assertEqual(
            vm_response.serviceofferingid,
            self.serviceOfferingWithDiskOfferingStrictnessFalse2.id,
            "Check service offering of the VM"
        )

        if self.hypervisor.lower() == "vmware":
            self.updateVmwareCreateFullCloneSetting(True)

        return
Пример #23
0
    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.hypervisor = testClient.getHypervisorInfo()
        #for LXC if the storage pool of type 'rbd' ex: ceph is not available, skip the test
        if cls.hypervisor.lower() == 'lxc':
            if not find_storage_pool_type(cls.apiclient, storagetype='rbd'):
                raise unittest.SkipTest("RBD storage type is required for data volumes for LXC")
        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"]
                                )
        pools = StoragePool.list(cls.apiclient)
        # cls.assertEqual(
        #         validateList(pools)[0],
        #         PASS,
        #         "storage pool list validation failed")



        if cls.hypervisor.lower() == 'lxc' and cls.storage_pools.type.lower() != 'rbd':
            raise unittest.SkipTest("Snapshots not supported on Hyper-V or LXC")
        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
                        ]
Пример #24
0
    def setUpCloudStack(cls):
        super(TestRenameObjectsWithUuids, cls).setUpClass()

        cls.spapi = spapi.Api.fromConfig(multiCluster=True)
        cls.helper = HelperUtil(cls)

        cls._cleanup = []
        testClient = super(TestRenameObjectsWithUuids, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.unsupportedHypervisor = False
        cls.hypervisor = testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ("hyperv", "lxc"):
            cls.unsupportedHypervisor = True
            return

        cls.services = testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = None


        zones = list_zones(cls.apiclient)

        for z in zones:
            if z.internaldns1 == cls.getClsConfig().mgtSvr[0].mgtSvrIp:
                cls.zone = z

        storpool_primary_storage = {
            "name" : "ssd",
            "zoneid": cls.zone.id,
            "url": "ssd",
            "scope": "zone",
            "capacitybytes": 4500000,
            "capacityiops": 155466464221111121,
            "hypervisor": "kvm",
            "provider": "StorPool",
            "tags": "ssd"
            }

        storpool_service_offerings = {
            "name": "ssd",
                "displaytext": "SP_CO_2 (Min IOPS = 10,000; Max IOPS = 15,000)",
                "cpunumber": 1,
                "cpuspeed": 500,
                "memory": 512,
                "storagetype": "shared",
                "customizediops": False,
                "hypervisorsnapshotreserve": 200,
                "tags": "ssd"
            }

        storage_pool = list_storage_pools(
            cls.apiclient,
            name='ssd'
            )

        service_offerings = list_service_offering(
            cls.apiclient,
            name='ssd'
            )

        disk_offerings = list_disk_offering(
            cls.apiclient,
            name="Small"
            )

        disk_offering_20 = list_disk_offering(
            cls.apiclient,
            name="Medium"
            )

        disk_offering_100 = list_disk_offering(
            cls.apiclient,
            name="Large"
            )

        cls.disk_offering = disk_offerings[0]
        cls.disk_offering_20 = disk_offering_20[0]
        cls.disk_offering_100 = disk_offering_100[0]
        cls.debug(pprint.pformat(storage_pool))
        if storage_pool is None:
            storage_pool = StoragePool.create(cls.apiclient, storpool_primary_storage)
        else:
            storage_pool = storage_pool[0]
        cls.storage_pool = storage_pool
        cls.debug(pprint.pformat(storage_pool))
        if service_offerings is None:
            service_offerings = ServiceOffering.create(cls.apiclient, storpool_service_offerings)
        else:
            service_offerings = service_offerings[0]
        #The version of CentOS has to be supported
        template = get_template(
             cls.apiclient,
            cls.zone.id,
            account = "system"
        )

        cls.pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id)
        cls.debug(pprint.pformat(template))
        cls.debug(pprint.pformat(cls.hypervisor))

        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["small"]["zoneid"] = cls.zone.id
        cls.services["templates"]["ostypeid"] = template.ostypeid
        cls.services["zoneid"] = cls.zone.id


        cls.service_offering = service_offerings
        cls.debug(pprint.pformat(cls.service_offering))

        cls.local_cluster = cls.get_local_cluster(zoneid = cls.zone.id)
        cls.host = cls.list_hosts_by_cluster_id(cls.local_cluster.id)

        assert len(cls.host) > 1, "Hosts list is less than 1"
        cls.host_on_local_1 = cls.host[0]
        cls.host_on_local_2 = cls.host[1]

        cls.remote_cluster = cls.get_remote_cluster(zoneid = cls.zone.id)
        cls.host_remote = cls.list_hosts_by_cluster_id(cls.remote_cluster.id)
        assert len(cls.host_remote) > 1, "Hosts list is less than 1"

        cls.host_on_remote1 = cls.host_remote[0]
        cls.host_on_remote2 = cls.host_remote[1]

        cls.volume_1 = Volume.create(
            cls.apiclient,
            {"diskname":"StorPoolDisk-1" },
            zoneid=cls.zone.id,
            diskofferingid=cls.disk_offering.id,
        )
        cls._cleanup.append(cls.volume_1)

        cls.volume = Volume.create(
            cls.apiclient,
            {"diskname":"StorPoolDisk-3" },
            zoneid=cls.zone.id,
            diskofferingid=cls.disk_offering.id,
        )
        cls._cleanup.append(cls.volume)

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid=cls.zone.id,
            templateid=template.id,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            hostid = cls.host_on_local_1.id,
            rootdisksize=10
        )

        cls.volume_on_remote = Volume.create(
            cls.apiclient,
            {"diskname":"StorPoolDisk-3" },
            zoneid=cls.zone.id,
            diskofferingid=cls.disk_offering.id,
        )
        cls._cleanup.append(cls.volume_on_remote)

        cls.virtual_machine_on_remote = VirtualMachine.create(
            cls.apiclient,
            {"name":"StorPool-%s" % uuid.uuid4() },
            zoneid=cls.zone.id,
            templateid=template.id,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            hostid = cls.host_on_remote1.id,
            rootdisksize=10
        )

        cls.template = template
        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"
        return
    def setUpClass(cls):
        cls.testClient = super(TestDirectDownloadTemplates, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        cls.dbclient = cls.testClient.getDbConnection()
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.pod = get_pod(cls.apiclient, cls.zone.id)
        cls.services = cls.testClient.getParsedTestDataConfig()

        cls._cleanup = []
        cls.hypervisorSupported = False
        cls.nfsStorageFound = False
        cls.localStorageFound = False
        cls.sharedMountPointFound = False

        if cls.hypervisor.lower() in ['kvm', 'lxc']:
            cls.hypervisorSupported = True

        if cls.hypervisorSupported:
            cls.services["test_templates"]["kvm"]["directdownload"] = "true"
            cls.template = Template.register(cls.apiclient, cls.services["test_templates"]["kvm"],
                              zoneid=cls.zone.id, hypervisor=cls.hypervisor)
            cls._cleanup.append(cls.template)

            cls.services["virtual_machine"]["zoneid"] = cls.zone.id
            cls.services["virtual_machine"]["template"] = cls.template.id
            cls.services["virtual_machine"]["hypervisor"] = cls.hypervisor
            cls.service_offering = ServiceOffering.create(
                cls.apiclient,
                cls.services["service_offerings"]["tiny"]
            )
            cls._cleanup.append(cls.service_offering)
            cls.network_offering = NetworkOffering.create(
                cls.apiclient,
                cls.services["l2-network_offering"],
            )
            cls.network_offering.update(cls.apiclient, state='Enabled')
            cls.services["network"]["networkoffering"] = cls.network_offering.id
            cls.l2_network = Network.create(
                cls.apiclient,
                cls.services["l2-network"],
                zoneid=cls.zone.id,
                networkofferingid=cls.network_offering.id
            )
            cls._cleanup.append(cls.l2_network)
            cls._cleanup.append(cls.network_offering)

            storage_pools = StoragePool.list(
                cls.apiclient,
                zoneid=cls.zone.id
            )
            for pool in storage_pools:
                if not cls.nfsStorageFound and pool.type == "NetworkFilesystem":
                    cls.nfsStorageFound = True
                    cls.nfsPoolId = pool.id
                elif not cls.localStorageFound and pool.type == "Filesystem":
                    cls.localStorageFound = True
                    cls.localPoolId = pool.id
                elif not cls.sharedMountPointFound and pool.type == "SharedMountPoint":
                    cls.sharedMountPointFound = True
                    cls.sharedPoolId = pool.id

        cls.nfsKvmNotAvailable = not cls.hypervisorSupported or not cls.nfsStorageFound
        cls.localStorageKvmNotAvailable = not cls.hypervisorSupported or not cls.localStorageFound
        cls.sharedMountPointKvmNotAvailable = not cls.hypervisorSupported or not cls.sharedMountPointFound
        return
Пример #26
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
Пример #27
0
    def setUpClass(cls):
        testClient = super(TestVolumes, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls._cleanup = []
        # 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.hypervisor = testClient.getHypervisorInfo()
        cls.invalidStoragePoolType = False
        #for LXC if the storage pool of type 'rbd' ex: ceph is not available, skip the test
        if cls.hypervisor.lower() == 'lxc':
            if not find_storage_pool_type(cls.apiclient, storagetype='rbd'):
                # RBD storage type is required for data volumes for LXC
                cls.invalidStoragePoolType = True
                return
        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
                                    )

        cls.template = get_suitable_test_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"],
            cls.hypervisor
        )
        if cls.template == FAILED:
            assert False, "get_suitable_test_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"] = cls.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"]["tiny"]
                                        )
        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"]
                                )
        pools = StoragePool.list(cls.apiclient)
        # cls.assertEqual(
        #         validateList(pools)[0],
        #         PASS,
        #         "storage pool list validation failed")



        if cls.hypervisor.lower() == 'lxc' and cls.storage_pools.type.lower() != 'rbd':
            raise unittest.SkipTest("Snapshots not supported on Hyper-V or LXC")
        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
                        ]
    def setUpCloudStack(cls):
        super(TestLiveMigration, cls).setUpClass()

        cls._cleanup = []
        testClient = super(TestLiveMigration, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.unsupportedHypervisor = False
        cls.hypervisor = testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ("hyperv", "lxc"):
            cls.unsupportedHypervisor = True
            return

        cls.services = testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = None

        zones = list_zones(cls.apiclient)

        for z in zones:
            if z.internaldns1 == cls.getClsConfig().mgtSvr[0].mgtSvrIp:
                cls.zone = z

        td = TestData()
        cls.testdata = td.testdata
        cls.helper = StorPoolHelper()

        cls.template_name = cls.testdata[TestData.primaryStorage].get("name")

        storage_pool = list_storage_pools(cls.apiclient,
                                          name=cls.template_name)

        service_offerings = list_service_offering(cls.apiclient,
                                                  name=cls.template_name)

        disk_offerings = list_disk_offering(cls.apiclient, name="Small")

        disk_offering_20 = list_disk_offering(cls.apiclient, name="Medium")

        disk_offering_100 = list_disk_offering(cls.apiclient, name="Large")

        cls.disk_offerings = disk_offerings[0]
        cls.disk_offering_20 = disk_offering_20[0]
        cls.disk_offering_100 = disk_offering_100[0]
        cls.debug(pprint.pformat(storage_pool))
        if storage_pool is None:
            storage_pool = cls.helper.create_sp_template_and_storage_pool(
                cls.apiclient, cls.template_name,
                cls.testdata[TestData.primaryStorage], cls.zone.id)
        else:
            storage_pool = storage_pool[0]
        cls.storage_pool = storage_pool
        cls.debug(pprint.pformat(storage_pool))
        if service_offerings is None:
            service_offerings = ServiceOffering.create(
                cls.apiclient, cls.testdata[TestData.serviceOffering])
        else:
            service_offerings = service_offerings[0]
        #The version of CentOS has to be supported
        template = get_template(cls.apiclient, cls.zone.id, account="system")

        cls.pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id)
        cls.debug(pprint.pformat(template))
        cls.debug(pprint.pformat(cls.hypervisor))

        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["small"]["zoneid"] = cls.zone.id
        cls.services["templates"]["ostypeid"] = template.ostypeid
        cls.services["zoneid"] = cls.zone.id

        cls.service_offering = service_offerings
        cls.debug(pprint.pformat(cls.service_offering))

        cls.local_cluster = cls.helper.get_local_cluster(cls.apiclient,
                                                         zoneid=cls.zone.id)
        cls.host = cls.helper.list_hosts_by_cluster_id(cls.apiclient,
                                                       cls.local_cluster.id)

        assert len(cls.host) > 1, "Hosts list is less than 1"
        cls.host_on_local_1 = cls.host[0]
        cls.host_on_local_2 = cls.host[1]

        cls.remote_cluster = cls.helper.get_remote_cluster(cls.apiclient,
                                                           zoneid=cls.zone.id)
        cls.host_remote = cls.helper.list_hosts_by_cluster_id(
            cls.apiclient, cls.remote_cluster.id)
        assert len(cls.host_remote) > 1, "Hosts list is less than 1"

        cls.host_on_remote1 = cls.host_remote[0]
        cls.host_on_remote2 = cls.host_remote[1]

        cls.services["domainid"] = cls.domain.id
        cls.services["zoneid"] = cls.zone.id
        cls.services["template"] = template.id
        cls.services["diskofferingid"] = disk_offerings[0].id

        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     domainid=cls.domain.id)
        cls._cleanup.append(cls.account)

        securitygroup = SecurityGroup.list(cls.apiclient,
                                           account=cls.account.name,
                                           domainid=cls.account.domainid)[0]
        cls.helper.set_securityGroups(cls.apiclient,
                                      account=cls.account.name,
                                      domainid=cls.account.domainid,
                                      id=securitygroup.id)

        cls.volume_1 = Volume.create(cls.apiclient,
                                     cls.services,
                                     account=cls.account.name,
                                     domainid=cls.account.domainid)

        cls.volume = Volume.create(cls.apiclient,
                                   cls.services,
                                   account=cls.account.name,
                                   domainid=cls.account.domainid)

        cls.volume_on_remote = Volume.create(cls.apiclient,
                                             cls.services,
                                             account=cls.account.name,
                                             domainid=cls.account.domainid)

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            hostid=cls.host_on_local_1.id,
            rootdisksize=10)

        cls.virtual_machine_on_remote = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            hostid=cls.host_on_remote1.id,
            rootdisksize=10)

        cls.virtual_machine_migr_btw_cl = VirtualMachine.create(
            cls.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=cls.zone.id,
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            hypervisor=cls.hypervisor,
            hostid=cls.host_on_local_1.id,
            rootdisksize=10)

        cls.template = template
        cls.random_data_0 = random_gen(size=100)
        cls.test_dir = "/tmp"
        cls.random_data = "random.data"
        return
    def setUpClass(cls):
        testClient = super(TestConcurrentSnapshots, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.testdata = testClient.getParsedTestDataConfig()
        cls.hypervisor = cls.testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())

        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.testdata["ostype"])

        cls._cleanup = []
        cls.vm_pool = []
        cls.snapshotSupported = True

        if cls.hypervisor.lower() in ["hyperv", "lxc"]:
            cls.snapshotSupported = False
            return

        # Set sleep time as per Snapshot Recurring Policy - HOURLY
        cls.sleep_time_for_hourly_policy = 60 * 60 * 1

        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__

        try:

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

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

            # Create Service offering
            cls.service_offering = ServiceOffering.create(
                cls.apiclient,
                cls.testdata["service_offering"],
            )
            cls._cleanup.append(cls.service_offering)

            for i in range(4):
                cls.vm = VirtualMachine.create(
                    cls.apiclient,
                    cls.testdata["small"],
                    templateid=cls.template.id,
                    accountid=cls.account.name,
                    domainid=cls.account.domainid,
                    serviceofferingid=cls.service_offering.id,
                    zoneid=cls.zone.id,
                    mode=cls.zone.networktype
                )

                cls.vm_pool.append(cls.vm)
                cls._cleanup.append(cls.vm)

            cls.checksum_pool = []
            cls.root_pool = []
            cls.snapshot_pool = []
            cls.rec_policy_pool = []
            for vm in cls.vm_pool:
                root_volumes = list_volumes(
                    cls.apiclient,
                    virtualmachineid=vm.id,
                    type='ROOT',
                    listall=True
                )

                checksum_root = createChecksum(
                    cls.testdata,
                    vm,
                    root_volumes[0],
                    "rootdiskdevice")

                cls.checksum_pool.append(checksum_root)
                cls.root_pool.append(root_volumes[0])
            try:
                cls.pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id)
            except Exception as e:
                raise unittest.SkipTest(e)

        except Exception as e:
            cls.tearDownClass()
            raise e
        return
Пример #30
0
    def test_local_storage_data_disk_tag(self):
        """
        @Desc: Test whether tags are honoured while creating
        data disks on local storage
        @Steps:
        This test needs multiple local storages
        Step1: create a tag 'loc' on the local storage
        Step2: create a disk offering with this storage tag 'loc'
        Step3: create a VM and create disk by selecting the disk offering
         created in step2
        step4: check whether the data disk created in step3 is created on
        local storage with tag 'loc'
        """
        if not self.zone.localstorageenabled:
            self.skipTest('Local storage is not enable for this '
                          'zone. skipping')

        local_storages = StoragePool.list(self.apiClient,
                                          zoneid=self.zone.id,
                                          scope='HOST')
        self.assertEqual(isinstance(local_storages, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(
            local_storages, None,
            "Check if local storage pools exists in ListStoragePools")

        cmd = updateStoragePool.updateStoragePoolCmd()
        cmd.zoneid = self.zone.id
        cmd.tags = 'loc'
        cmd.id = local_storages[0].id
        self.apiClient.updateStoragePool(cmd)

        self.services["disk_offering"]["storagetype"] = 'local'
        self.services["disk_offering"]["tags"] = 'loc'
        disk_offering = DiskOffering.create(self.apiClient,
                                            self.services["disk_offering"])
        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,
            mode=self.services["mode"])
        self.cleanup.append(virtual_machine)
        self.cleanup.append(disk_offering)
        # Verify VM state
        self.assertEqual(virtual_machine.state, 'Running',
                         "Check VM state is Running or not")
        self.volume = Volume.create(self.apiClient,
                                    self.services["volume"],
                                    zoneid=self.zone.id,
                                    account=self.account.name,
                                    domainid=self.account.domainid,
                                    diskofferingid=disk_offering.id)
        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")

        storage_pool = StoragePool.list(self.apiClient, id=volume.storageid)

        self.assertEqual(
            volume.storagetype, 'local',
            "Check list storage pool response has local as storage type")

        self.assertEqual(storage_pool[0].tags, 'loc',
                         "Check list storage pool response has tag")
        return
 def getCurrentStoragePoolTags(self, poolId):
     local_pool = StoragePool.list(
         self.apiclient,
         id=poolId
     )
     return local_pool[0].tags
Пример #32
0
    def test_09_stop_vm_migrate_vol(self):
        """Test Stopped Virtual Machine's ROOT volume migration
        """

        # Validate the following:
        # 1. deploy Vm with startvm=true
        # 2. Should not be able to login to the VM.
        # 3. listVM command should return the deployed VM.State of this VM
        #    should be "Running".
        # 4. Stop the vm
        # 5.list primary storages in the cluster , should be more than one
        # 6.Migrate voluem to another available primary storage
        clusters = Cluster.list(self.apiclient, zoneid=self.zone.id)
        self.assertEqual(isinstance(clusters, list), True, "Check list response returns a valid list")
        i = 0
        for cluster in clusters:
            storage_pools = StoragePool.list(self.apiclient, clusterid=cluster.id)
            if len(storage_pools) > 1:
                self.cluster_id = cluster.id
                i += 1
                break
        if i == 0:
            self.skipTest("No cluster with more than one primary storage pool to perform migrate volume test")

        hosts = Host.list(self.apiclient, clusterid=self.cluster_id)
        self.assertEqual(isinstance(hosts, list), True, "Check list response returns a valid list")
        host = hosts[0]
        self.debug("Deploying instance on host: %s" % host.id)
        self.debug("Deploying instance in the account: %s" % self.account.name)
        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            diskofferingid=self.disk_offering.id,
            hostid=host.id,
            mode=self.zone.networktype,
        )

        response = self.virtual_machine.getState(self.apiclient, VirtualMachine.RUNNING)
        self.assertEqual(response[0], PASS, response[1])
        try:
            self.virtual_machine.stop(self.apiclient)
        except Exception as e:
            self.fail("failed to stop instance: %s" % e)
        volumes = Volume.list(self.apiclient, virtualmachineid=self.virtual_machine.id, type="ROOT", listall=True)
        self.assertEqual(isinstance(volumes, list), True, "Check volume list response returns a valid list")
        vol_response = volumes[0]
        # get the storage name in which volume is stored
        storage_name = vol_response.storage
        storage_pools = StoragePool.list(self.apiclient, clusterid=self.cluster_id)
        # Get storage pool to migrate volume
        for spool in storage_pools:
            if spool.name == storage_name:
                continue
            else:
                self.storage_id = spool.id
                self.storage_name = spool.name
                break
        self.debug("Migrating volume to storage pool: %s" % self.storage_name)
        Volume.migrate(self.apiclient, storageid=self.storage_id, volumeid=vol_response.id)
        volume = Volume.list(self.apiclient, virtualmachineid=self.virtual_machine.id, type="ROOT", listall=True)
        self.assertEqual(volume[0].storage, self.storage_name, "Check volume migration response")

        return
Пример #33
0
    def test_01_recover_VM(self):
        """ Test Restore VM on VMWare
            1. Deploy a VM without datadisk
            2. Restore the VM
            3. Verify that VM comes up in Running state
        """
        try:
            self.pools = StoragePool.list(
                self.apiclient,
                zoneid=self.zone.id,
                scope="CLUSTER")

            status = validateList(self.pools)

            # Step 3
            self.assertEqual(
                status[0],
                PASS,
                "Check: Failed to list  cluster wide storage pools")

            if len(self.pools) < 2:
                self.skipTest("There must be at atleast two cluster wide\
                storage pools available in the setup")

        except Exception as e:
            self.skipTest(e)

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

        self.vm = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            accountid=self.account.name,
            templateid=self.template.id,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_cwps.id,
            zoneid=self.zone.id,
        )
        # Step 2

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

        root_volume = volumes_root_list[0]

        # Restore VM till its ROOT disk is recreated on onother Primary Storage
        while True:
            self.vm.restore(self.apiclient)
            volumes_root_list = list_volumes(
                self.apiclient,
                virtualmachineid=self.vm.id,
                type=ROOT,
                listall=True
            )

            root_volume = volumes_root_list[0]

            if root_volume.storage != self.pools[0].name:
                break

        # Step 3
        vm_list = list_virtual_machines(
            self.apiclient,
            id=self.vm.id)

        state = vm_list[0].state
        i = 0
        while(state != "Running"):
            vm_list = list_virtual_machines(
                self.apiclient,
                id=self.vm.id)

            time.sleep(10)
            i = i + 1
            state = vm_list[0].state
            if i >= 10:
                self.fail("Restore VM Failed")
                break

        return
    def setUpClass(cls):
        testClient = super(TestConcurrentSnapshots, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.testdata = testClient.getParsedTestDataConfig()
        cls.hypervisor = cls.testClient.getHypervisorInfo()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())

        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.testdata["ostype"])

        cls._cleanup = []
        cls.vm_pool = []
        cls.snapshotSupported = True

        if cls.hypervisor.lower() in ["hyperv", "lxc"]:
            cls.snapshotSupported = False
            return

        # Set sleep time as per Snapshot Recurring Policy - HOURLY
        cls.sleep_time_for_hourly_policy = 60 * 60 * 1

        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__

        try:

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

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

            # Create Service offering
            cls.service_offering = ServiceOffering.create(
                cls.apiclient,
                cls.testdata["service_offering"],
            )
            cls._cleanup.append(cls.service_offering)

            for i in range(4):
                cls.vm = VirtualMachine.create(
                    cls.apiclient,
                    cls.testdata["small"],
                    templateid=cls.template.id,
                    accountid=cls.account.name,
                    domainid=cls.account.domainid,
                    serviceofferingid=cls.service_offering.id,
                    zoneid=cls.zone.id,
                    mode=cls.zone.networktype
                )

                cls.vm_pool.append(cls.vm)
                cls._cleanup.append(cls.vm)

            cls.checksum_pool = []
            cls.root_pool = []
            cls.snapshot_pool = []
            cls.rec_policy_pool = []
            for vm in cls.vm_pool:
                root_volumes = list_volumes(
                    cls.apiclient,
                    virtualmachineid=vm.id,
                    type='ROOT',
                    listall=True
                )

                checksum_root = createChecksum(
                    cls.testdata,
                    vm,
                    root_volumes[0],
                    "rootdiskdevice")

                cls.checksum_pool.append(checksum_root)
                cls.root_pool.append(root_volumes[0])
            try:
                cls.pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id)
            except Exception as e:
                raise unittest.SkipTest(e)

        except Exception as e:
            cls.tearDownClass()
            raise e
        return