def test_04_deploy_multiple_vm(self):
        """Test Deploy multiple VM with 2 GB memory & verify the usage"""
	    #keep the configuration value - max.account.memory = 8192 (maximum 4 instances per account with 2 GB RAM)

        # Validate the following
        # 1. Create compute offering with 2 GB RAM
        # 2. Deploy multiple VMs with this service offering in child domains of root domain
        # 3. List Resource count for the root admin Memory usage
        # 4. Memory usage should list properly

        self.debug("Creating service offering with 2 GB RAM")
        self.service_offering = ServiceOffering.create(
                                            self.apiclient,
                                            self.services["service_offering"]
                                            )
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.child_domain_1: self.child_do_admin_1,
                 self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            memory_account_gc = Resources.list(self.apiclient,
                                resourcetype = 9, #Memory
                                account = self.account.name,
                                domainid = self.domain.id
                                )

            if memory_account_gc[0].max != 8192:
                self.skipTest("This test case requires configuration value max.account.memory to be 8192")

	        api_client = self.testClient.getUserApiClient(
                             UserName=self.account.name,
                             DomainName=self.account.domain)

            self.debug("Creating an instance with service offering: %s" %
                                                    self.service_offering.name)
            vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client)
            self.createInstance(service_off=self.service_offering, api_client=api_client)
            self.createInstance(service_off=self.service_offering, api_client=api_client)

            self.debug("Deploying instance - memory capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"]) * 4 #Total 4 vms

            self.assertEqual(resource_count, expected_resource_count,
                         "Initial resource count should with the expected resource count")

            self.debug("Destroying instance: %s" % vm_1.name)
            try:
                vm_1.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count_after_delete = account_list[0].memorytotal

            expected_resource_count -= int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count_after_delete, expected_resource_count,
                         "Resource count should match with the expected resource count")

            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
                                                               host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count_after_migrate = account_list[0].memorytotal

            self.debug(resource_count_after_migrate)
            self.assertEqual(resource_count_after_delete, resource_count_after_migrate,
                         "Resource count should be same after migrating the instance")
        return
예제 #2
0
    def test_02_negative_path(self):
        """
        negative test for volume life cycle
        # 1. Deploy a vm [vm1] with shared storage and  data disk
        #v1. Create VM2 with local storage offering disk offerings
        # 2.TBD
        # 3. Detach the data disk from VM1 and Download the volume
        # 4.TBD
        # 5. Attach volume with deviceid = 0
        # 6. Attach volume, specify a VM which is destroyed
        # 7.TBD
        # 8.TBD
        # 9.TBD
        # 10.TBD
        # 11.Upload the volume from T3 by providing the URL of the downloaded
             volume, but specify a wrong format (not supported by the
             hypervisor)
        # 12.Upload the same volume from T4 by providing a wrong URL
        # 13.Upload volume, provide wrong checksum
        # 14.Upload a volume when maximum limit for the account is reached
        # 15.TBD
        # 16.Upload volume with all correct parameters
             (covered in positive test path)
        # 17.TBD
        # 18.TBD
        # 19.Now attach the volume with all correct parameters
            (covered in positive test path)
        # 20.Destroy and expunge all VMs

        """

        # 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")
        # Variance
        if self.zone.localstorageenabled:
            # V1.Create vm3 with local storage offering
            self.virtual_machine_local_2 = 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_2.id)

        # 3. Detach the data disk from VM1 and Download the volume
        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))

        # 6. Attach volume, specify a VM which is destroyed
        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)
        try:
            self.virtual_machine_2.delete(self.apiclient)
        except Exception as e:
            raise Exception("Vm deletion failed with error %s" % e)
        # Create a new volume
        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)
        # try  Attach volume to vm2
        try:
            self.virtual_machine_2.attach_volume(self.userapiclient,
                                                 self.volume)
            self.fail("Volume got attached to a destroyed vm ")
        except Exception:
            self.debug("Volume cant not be attached to a destroyed vm ")

        # 11.Upload the volume  by providing the URL of the downloaded
        # volume, but specify a wrong format (not supported by the hypervisor)
        if "OVA" in self.extract_volume.url.upper():
            self.testdata["upload_volume"]["format"] = "VHD"
        else:
            self.testdata["upload_volume"]["format"] = "OVA"
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["upload_volume"])
            self.fail("Volume got uploaded with invalid format")
        except Exception as e:
            self.debug("upload volume failed due %s" % e)
        # 12. Upload the same volume from T4 by providing a wrong URL
        self.testdata["upload_volume"]["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"
        u1 = self.extract_volume.url.split('.')
        u1[-2] = "wrong"
        wrong_url = ".".join(u1)
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=wrong_url,
                services=self.testdata["upload_volume"])
            self.upload_response.wait_for_upload(self.userapiclient)
            self.fail("volume got uploaded with wrong url")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)
        # 13.Upload volume, provide wrong checksum
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["upload_volume"],
                checksome="123456")
            self.upload_response.wait_for_upload(self.userapiclient)
            self.fail("volume got uploaded with wrong checksome")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)

        # 14.Upload a volume when maximum limit for the account is reached
        account_update = Resources.updateLimit(self.apiclient,
                                               resourcetype=2,
                                               account=self.account.name,
                                               domainid=self.account.domainid,
                                               max=1)
        list_resource = Resources.list(self.apiclient,
                                       account=self.account.name,
                                       domainid=self.account.domainid,
                                       resourcetype=2)
        self.assertEqual(
            validateList(list_resource)[0], PASS,
            "Check List resource response for volume %s" % self.account.name)
        self.assertEqual(
            str(list_resource[0].max), '1',
            "check list List resource response for account id:  %s" %
            self.account.name)
        self.debug("Max resources got updated successfully for account %s" %
                   self.account.name)
        try:
            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.fail("volume got uploaded after account reached max limit for\
                      volumes ")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)
예제 #3
0
    def test_02_negative_path(self):
        """
        negative test for volume life cycle
        # 1. Deploy a vm [vm1] with shared storage and  data disk
        #v1. Create VM2 with local storage offering disk offerings
        # 2.TBD
        # 3. Detach the data disk from VM1 and Download the volume
        # 4.TBD
        # 5. Attach volume with deviceid = 0
        # 6. Attach volume, specify a VM which is destroyed
        # 7.TBD
        # 8.TBD
        # 9.TBD
        # 10.TBD
        # 11.Upload the volume from T3 by providing the URL of the downloaded
             volume, but specify a wrong format (not supported by the
             hypervisor)
        # 12.Upload the same volume from T4 by providing a wrong URL
        # 13.Upload volume, provide wrong checksum
        # 14.Upload a volume when maximum limit for the account is reached
        # 15.TBD
        # 16.Upload volume with all correct parameters
             (covered in positive test path)
        # 17.TBD
        # 18.TBD
        # 19.Now attach the volume with all correct parameters
            (covered in positive test path)
        # 20.Destroy and expunge all VMs

        """

        # 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")
        # Variance
        if self.zone.localstorageenabled:
            # V1.Create vm3 with local storage offering
            self.virtual_machine_local_2 = 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_2.id)

        # 3. Detach the data disk from VM1 and Download the volume
        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))

        # 6. Attach volume, specify a VM which is destroyed
        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)
        try:
            self.virtual_machine_2.delete(self.apiclient)
        except Exception as e:
            raise Exception("Vm deletion failed with error %s" % e)
        # Create a new volume
        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)
        # try  Attach volume to vm2
        try:
            self.virtual_machine_2.attach_volume(self.userapiclient,
                                                 self.volume
                                                 )
            self.fail("Volume got attached to a destroyed vm ")
        except Exception:
            self.debug("Volume cant not be attached to a destroyed vm ")

        # 11.Upload the volume  by providing the URL of the downloaded
        # volume, but specify a wrong format (not supported by the hypervisor)
        if "OVA" in self.extract_volume.url.upper():
            self.testdata["configurableData"]["upload_volume"]["format"] = "VHD"
        else:
            self.testdata["configurableData"]["upload_volume"]["format"] = "OVA"
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["configurableData"]["upload_volume"])
            self.fail("Volume got uploaded with invalid format")
        except Exception as e:
            self.debug("upload volume failed due %s" % e)
        # 12. Upload the same volume from T4 by providing a wrong URL
        self.testdata["configurableData"]["upload_volume"]["format"] = "VHD"
        if "OVA" in self.extract_volume.url.upper():
            self.testdata["configurableData"]["upload_volume"]["format"] = "OVA"
        if "QCOW2" in self.extract_volume.url.upper():
            self.testdata["configurableData"]["upload_volume"]["format"] = "QCOW2"
        u1 = self.extract_volume.url.split('.')
        u1[-2] = "wrong"
        wrong_url = ".".join(u1)
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=wrong_url,
                services=self.testdata["configurableData"]["upload_volume"])
            self.upload_response.wait_for_upload(self.userapiclient
                                                 )
            self.fail("volume got uploaded with wrong url")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)
        # 13.Upload volume, provide wrong checksum
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["configurableData"]["upload_volume"],
                checksome="123456")
            self.upload_response.wait_for_upload(self.userapiclient
                                                 )
            self.fail("volume got uploaded with wrong checksome")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)

        # 14.Upload a volume when maximum limit for the account is reached
        account_update = Resources.updateLimit(self.apiclient,
                                               resourcetype=2,
                                               account=self.account.name,
                                               domainid=self.account.domainid,
                                               max=1
                                               )
        list_resource = Resources.list(self.apiclient,
                                       account=self.account.name,
                                       domainid=self.account.domainid,
                                       resourcetype=2
                                       )
        self.assertEqual(
            validateList(list_resource)[0],
            PASS,
            "Check List resource response for volume %s" %
            self.account.name)
        self.assertEqual(
            str(
                list_resource[0].max),
            '1',
            "check list List resource response for account id:  %s" %
            self.account.name)
        self.debug(
            "Max resources got updated successfully for account %s" %
            self.account.name)
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["configurableData"]["upload_volume"])
            self.upload_response.wait_for_upload(self.userapiclient
                                                 )
            self.fail("volume got uploaded after account reached max limit for\
                      volumes ")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)
예제 #4
0
    def test_04_deploy_multiple_vm(self):
        """Test Deploy multiple VM with 2 GB memory & verify the usage"""
        #keep the configuration value - max.account.memory = 8192 (maximum 4 instances per account with 2 GB RAM)

        # Validate the following
        # 1. Create compute offering with 2 GB RAM
        # 2. Deploy multiple VMs with this service offering in child domains of root domain
        # 3. List Resource count for the root admin Memory usage
        # 4. Memory usage should list properly

        self.debug("Creating service offering with 2 GB RAM")
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.child_domain_1: self.child_do_admin_1,
            self.child_domain_2: self.child_do_admin_2
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            memory_account_gc = Resources.list(
                self.apiclient,
                resourcetype=9,  #Memory
                account=self.account.name,
                domainid=self.domain.id)

            if memory_account_gc[0].max != 8192:
                self.skipTest(
                    "This test case requires configuration value max.account.memory to be 8192"
                )

                api_client = self.testClient.getUserApiClient(
                    UserName=self.account.name, DomainName=self.account.domain)

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm_1 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)

            self.debug(
                "Deploying instance - memory capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering,
                                    api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(
                self.services["service_offering"]["memory"]) * 4  #Total 4 vms

            self.assertEqual(
                resource_count, expected_resource_count,
                "Initial resource count should with the expected resource count"
            )

            self.debug("Destroying instance: %s" % vm_1.name)
            try:
                vm_1.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_delete = account_list[0].memorytotal

            expected_resource_count -= int(
                self.services["service_offering"]["memory"])

            self.assertEqual(
                resource_count_after_delete, expected_resource_count,
                "Resource count should match with the expected resource count")

            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm_2.name, host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_migrate = account_list[0].memorytotal

            self.debug(resource_count_after_migrate)
            self.assertEqual(
                resource_count_after_delete, resource_count_after_migrate,
                "Resource count should be same after migrating the instance")
        return