def test_deploy_multiple_vm(self, value):
        """Test Deploy multiple VMs with & verify the usage
        # Validate the following
        # 1. Deploy multiple VMs with this service offering
        # 2. Update Resource count for the root admin Primary Storage usage
        # 3. Primary Storage usage should list properly
        # 4. Destroy one VM among multiple VM's and verify that primary storage count
        #  decreases by equivalent amount
        """

        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

        self.virtualMachine_2 = VirtualMachine.create(
            self.api_client,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id,
            serviceofferingid=self.service_offering.id)

        expectedCount = (self.initialResourceCount * 2)  #Total 2 vms
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        self.virtualMachine_3 = VirtualMachine.create(
            self.api_client,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id,
            serviceofferingid=self.service_offering.id)

        expectedCount = (self.initialResourceCount * 3)  #Total 3 vms
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

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

        self.assertTrue(isVmExpunged(self.apiclient, self.virtualMachine_2.id),
                        "VM not expunged \
                in allotted time")

        expectedCount = (self.initialResourceCount * 2)  #Total 2 vms
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_03_delete_vm(self):
        """Test delete VM belonging to project

        # Validate the following
        # 1. Create VM with custom disk offering in a project and check
        #    initial primary storage count
        # 2. Delete VM and verify that it's expunged
        # 3. Verify that primary storage count of project equals 0"""

        try:
            self.vm.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to detroy VM: %s" % e)

        self.assertTrue(isVmExpunged(self.apiclient, self.vm.id, self.project.id),\
                "VM not expunged")

        totalallottedtime = timeout = 600
        while timeout >= 0:
            volumes = Volume.list(self.apiclient, projectid=self.project.id, listall=True)
            if volumes is None:
                break
            if timeout == 0:
                self.fail("Volume attached to VM not cleaned up even\
                        after %s seconds" % totalallottedtime)
            timeout -= 60
            time.sleep(60)

        expectedCount = 0
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        projectid=self.project.id)
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_03_delete_vm(self):
        """Test delete VM belonging to project

        # Validate the following
        # 1. Create VM with custom disk offering in a project and check
        #    initial primary storage count
        # 2. Delete VM and verify that it's expunged
        # 3. Verify that primary storage count of project equals 0"""

        try:
            self.vm.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to detroy VM: %s" % e)

        self.assertTrue(isVmExpunged(self.apiclient, self.vm.id, self.project.id),\
                "VM not expunged")

        totalallottedtime = timeout = 600
        while timeout >= 0:
            volumes = Volume.list(self.apiclient, projectid=self.project.id, listall=True)
            if volumes is None:
                break
            if timeout == 0:
                self.fail("Volume attached to VM not cleaned up even\
                        after %s seconds" % totalallottedtime)
            timeout -= 60
            time.sleep(60)

        expectedCount = 0
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        projectid=self.project.id)
        self.assertEqual(response[0], PASS, response[1])
        return
Example #4
0
    def test_deploy_multiple_vm(self, value):
        """Test Deploy multiple VMs with & verify the usage
        # Validate the following
        # 1. Deploy multiple VMs with this service offering
        # 2. Update Resource count for the root admin Primary Storage usage
        # 3. Primary Storage usage should list properly
        # 4. Destroy one VM among multiple VM's and verify that primary storage count
        #  decreases by equivalent amount
        """

        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

        self.virtualMachine_2 = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
                            accountid=self.account.name, domainid=self.account.domainid,
                            diskofferingid=self.disk_offering.id,
                            serviceofferingid=self.service_offering.id)

        expectedCount = (self.initialResourceCount * 2) #Total 2 vms
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        self.virtualMachine_3 = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
                            accountid=self.account.name, domainid=self.account.domainid,
                            diskofferingid=self.disk_offering.id,
                            serviceofferingid=self.service_offering.id)

        expectedCount = (self.initialResourceCount * 3) #Total 3 vms
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

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

        self.assertTrue(isVmExpunged(self.apiclient, self.virtualMachine_2.id), "VM not expunged \
                in allotted time")

        expectedCount -= (self.template.size / (1024 ** 3))
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
	return
    def test_01_multiple_domains_primary_storage_limits(self):
        """Test primary storage limit of domain and its sub-domains

        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        2. Update primary storage limits of the parent domain and child domains
        3. Deploy VM in child domain 1 so that total primary storage
           is less than the limit of child domain
        4. Repeat step 3 for child domain 2
        5. Try to deploy VM in parent domain now so that the total primary storage in
           parent domain (including that in sub-domains is more than the primary
           storage limit of the parent domain
        6. Delete the admin account of child domain 1 and check resource count
           of the parent domain
        7.  Delete VM deployed in account 2 and check primary storage count
           of parent domain

        # Validations:
        1. Step 3 and 4 should succeed
        2. Step 5 should fail as the resource limit exceeds in parent domain
        3. After step 6, resource count in parent domain should decrease by equivalent
           quantity
        4. After step 7, resource count in parent domain should be 0"""

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(
            result[0], PASS,
            "Failure while setting up accounts and domains: %s" % result[1])

        templatesize = (self.template.size / (1024**3))
        disksize = 10
        subdomainlimit = (templatesize + disksize)

        result = self.updateDomainResourceLimits(((subdomainlimit * 3) - 1),
                                                 subdomainlimit)
        self.assertEqual(
            result[0], PASS,
            "Failure while updating resource limits: %s" % result[1])

        try:
            self.services["disk_offering"]["disksize"] = disksize
            disk_offering_custom = DiskOffering.create(
                self.apiclient, services=self.services["disk_offering"])
            self.cleanup.append(disk_offering_custom)
        except Exception as e:
            self.fail("Failed to create disk offering")

        # Get API clients of parent and child domain admin accounts
        api_client_admin = self.testClient.getUserApiClient(
            UserName=self.parentd_admin.name,
            DomainName=self.parentd_admin.domain)
        self.assertNotEqual(
            api_client_admin, FAILED,
            "Failed to create api client for account: %s" %
            self.parentd_admin.name)

        api_client_cadmin_1 = self.testClient.getUserApiClient(
            UserName=self.cadmin_1.name, DomainName=self.cadmin_1.domain)
        self.assertNotEqual(
            api_client_cadmin_1, FAILED,
            "Failed to create api client for account: %s" % self.cadmin_1.name)

        api_client_cadmin_2 = self.testClient.getUserApiClient(
            UserName=self.cadmin_2.name, DomainName=self.cadmin_2.domain)
        self.assertNotEqual(
            api_client_cadmin_2, FAILED,
            "Failed to create api client for account: %s" % self.cadmin_2.name)

        VirtualMachine.create(api_client_cadmin_1,
                              self.services["virtual_machine"],
                              accountid=self.cadmin_1.name,
                              domainid=self.cadmin_1.domainid,
                              diskofferingid=disk_offering_custom.id,
                              serviceofferingid=self.service_offering.id)

        self.initialResourceCount = (templatesize + disksize)
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.parent_domain.id, self.initialResourceCount,
            RESOURCE_PRIMARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        # Create VM in second child domain
        vm_2 = VirtualMachine.create(
            api_client_cadmin_2,
            self.services["virtual_machine"],
            accountid=self.cadmin_2.name,
            domainid=self.cadmin_2.domainid,
            diskofferingid=disk_offering_custom.id,
            serviceofferingid=self.service_offering.id)

        # Now the VMs in two child domains have exhausted the primary storage limit
        # of parent domain, hence VM creation in parent domain with custom disk offering
        # should fail
        with self.assertRaises(Exception):
            VirtualMachine.create(api_client_admin,
                                  self.services["virtual_machine"],
                                  accountid=self.parentd_admin.name,
                                  domainid=self.parentd_admin.domainid,
                                  diskofferingid=disk_offering_custom.id,
                                  serviceofferingid=self.service_offering.id)

        # Deleting user account
        self.cadmin_1.delete(self.apiclient)
        self.cleanup.remove(self.cadmin_1)

        expectedCount = self.initialResourceCount
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.parent_domain.id, expectedCount,
            RESOURCE_PRIMARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        try:
            vm_2.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        self.assertTrue(isVmExpunged(self.apiclient, vm_2.id),
                        "VM not expunged \
                in allotted time")

        expectedCount = 0
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.parent_domain.id, expectedCount,
            RESOURCE_PRIMARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")
        return
    def test_01_multiple_domains_primary_storage_limits(self):
        """Test primary storage limit of domain and its sub-domains

        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        2. Update primary storage limits of the parent domain and child domains
        3. Deploy VM in child domain 1 so that total primary storage
           is less than the limit of child domain
        4. Repeat step 3 for child domain 2
        5. Try to deploy VM in parent domain now so that the total primary storage in
           parent domain (including that in sub-domains is more than the primary
           storage limit of the parent domain
        6. Delete the admin account of child domain 1 and check resource count
           of the parent domain
        7.  Delete VM deployed in account 2 and check primary storage count
           of parent domain

        # Validations:
        1. Step 3 and 4 should succeed
        2. Step 5 should fail as the resource limit exceeds in parent domain
        3. After step 6, resource count in parent domain should decrease by equivalent
           quantity
        4. After step 7, resource count in parent domain should be 0"""

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(
            result[0],
            PASS,
            "Failure while setting up accounts and domains: %s" %
            result[1])

        templatesize = (self.template.size / (1024 ** 3))
        disksize = 10
        subdomainlimit = (templatesize + disksize)

        result = self.updateDomainResourceLimits(
            ((subdomainlimit * 3) - 1),
            subdomainlimit)
        self.assertEqual(
            result[0],
            PASS,
            "Failure while updating resource limits: %s" %
            result[1])

        try:
            self.services["disk_offering"]["disksize"] = disksize
            disk_offering_custom = DiskOffering.create(
                self.apiclient,
                services=self.services["disk_offering"])
            self.cleanup.append(disk_offering_custom)
        except Exception as e:
            self.fail("Failed to create disk offering")

        # Get API clients of parent and child domain admin accounts
        api_client_admin = self.testClient.getUserApiClient(
            UserName=self.parentd_admin.name,
            DomainName=self.parentd_admin.domain)
        self.assertNotEqual(
            api_client_admin,
            FAILED,
            "Failed to create api client for account: %s" %
            self.parentd_admin.name)

        api_client_cadmin_1 = self.testClient.getUserApiClient(
            UserName=self.cadmin_1.name,
            DomainName=self.cadmin_1.domain)
        self.assertNotEqual(
            api_client_cadmin_1,
            FAILED,
            "Failed to create api client for account: %s" %
            self.cadmin_1.name)

        api_client_cadmin_2 = self.testClient.getUserApiClient(
            UserName=self.cadmin_2.name,
            DomainName=self.cadmin_2.domain)
        self.assertNotEqual(
            api_client_cadmin_2,
            FAILED,
            "Failed to create api client for account: %s" %
            self.cadmin_2.name)

        VirtualMachine.create(
            api_client_cadmin_1,
            self.services["virtual_machine"],
            accountid=self.cadmin_1.name,
            domainid=self.cadmin_1.domainid,
            diskofferingid=disk_offering_custom.id,
            serviceofferingid=self.service_offering.id)

        self.initialResourceCount = (templatesize + disksize)
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.parent_domain.id,
            self.initialResourceCount, RESOURCE_PRIMARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        # Create VM in second child domain
        vm_2 = VirtualMachine.create(
            api_client_cadmin_2,
            self.services["virtual_machine"],
            accountid=self.cadmin_2.name,
            domainid=self.cadmin_2.domainid,
            diskofferingid=disk_offering_custom.id,
            serviceofferingid=self.service_offering.id)

        # Now the VMs in two child domains have exhausted the primary storage limit
        # of parent domain, hence VM creation in parent domain with custom disk offering
        # should fail
        with self.assertRaises(Exception):
            VirtualMachine.create(
                api_client_admin,
                self.services["virtual_machine"],
                accountid=self.parentd_admin.name,
                domainid=self.parentd_admin.domainid,
                diskofferingid=disk_offering_custom.id,
                serviceofferingid=self.service_offering.id)

        # Deleting user account
        self.cadmin_1.delete(self.apiclient)
        self.cleanup.remove(self.cadmin_1)

        expectedCount = self.initialResourceCount
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.parent_domain.id,
            expectedCount, RESOURCE_PRIMARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        try:
            vm_2.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        self.assertTrue(isVmExpunged(self.apiclient, vm_2.id), "VM not expunged \
                in allotted time")

        expectedCount -= templatesize
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.parent_domain.id,
            expectedCount, RESOURCE_PRIMARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")
        return