def test_05_assign_virtual_machine_different_domain(self):
        """Test assign virtual machine to account belonging to different domain

        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        2. Deploy VM in child domain 1
        3. Check if the resource count for domain 1 is updated correctly
        4. Assign this virtual machine to account 2 in domain 2
        5. Verify that primaru storage resource count of domain 1 is now 0 and
           primary storage resource count of domain 2 is increased by equivalent number
        """

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])

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

        try:
            vm_1 = VirtualMachine.create(
                apiclient,
                self.services["virtual_machine"],
                accountid=self.cadmin_1.name,
                domainid=self.cadmin_1.domainid,
                diskofferingid=self.disk_offering.id,
                serviceofferingid=self.service_offering.id)

            templatesize = (self.template.size / (1024**3))

            expectedCount = templatesize + self.disk_offering.disksize
            result = isDomainResourceCountEqualToExpectedCount(
                self.apiclient, self.cadmin_1.domainid, expectedCount,
                RESOURCE_PRIMARY_STORAGE)
            self.assertFalse(result[0], result[1])
            self.assertTrue(result[2], "Resource count does not match")

            vm_1.stop(apiclient)
            vm_1.assign_virtual_machine(self.apiclient,
                                        account=self.cadmin_2.name,
                                        domainid=self.cadmin_2.domainid)

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

            expectedCount = 0
            result = isDomainResourceCountEqualToExpectedCount(
                self.apiclient, self.cadmin_1.domainid, expectedCount,
                RESOURCE_PRIMARY_STORAGE)
            self.assertFalse(result[0], result[1])
            self.assertTrue(result[2], "Resource count does not match")
        except Exception as e:
            self.fail("Failed with exception: %s" % e)
        return
    def test_06_destroy_recover_vm(self):
        """Test primary storage counts while destroying and recovering VM
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Deploy VM in child domain
        3. Check if the resource count for domain is updated correctly
        4. Destroy the VM
        5. Verify that the primary storage resource count remains the same
        6. Recover the VM
        7. Verify that the primary storage resource count remains the same
        """

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain
            try:
                vm_1 = VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=self.disk_offering.id,
                    serviceofferingid=self.service_offering.id,
                )

                templatesize = self.template.size / (1024 ** 3)

                expectedCount = templatesize + self.disk_offering.disksize
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.account.domainid, expectedCount, RESOURCE_PRIMARY_STORAGE
                )
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                vm_1.delete(self.apiclient, expunge=False)

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

                vm_1.recover(self.apiclient)

                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.account.domainid, expectedCount, RESOURCE_PRIMARY_STORAGE
                )
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed with exception: %s" % e)
        return
Ejemplo n.º 3
0
    def test_05_assign_virtual_machine_different_domain(self):
	"""Test assign virtual machine to account belonging to different domain

        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        2. Deploy VM in child domain 1
        3. Check if the resource count for domain 1 is updated correctly
        4. Assign this virtual machine to account 2 in domain 2
        5. Verify that primaru storage resource count of domain 1 is now 0 and
           primary storage resource count of domain 2 is increased by equivalent number
        """

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])

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

        try:
            vm_1 = VirtualMachine.create(
                    apiclient, self.services["virtual_machine"],
                    accountid=self.cadmin_1.name, domainid=self.cadmin_1.domainid,
                    diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id
                    )

            templatesize = (self.template.size / (1024**3))

            expectedCount = templatesize + self.disk_offering.disksize
            result = isDomainResourceCountEqualToExpectedCount(
                            self.apiclient, self.cadmin_1.domainid,
                            expectedCount, RESOURCE_PRIMARY_STORAGE)
            self.assertFalse(result[0], result[1])
            self.assertTrue(result[2], "Resource count does not match")

            vm_1.stop(apiclient)
            vm_1.assign_virtual_machine(self.apiclient, account=self.cadmin_2.name,
				    domainid=self.cadmin_2.domainid)

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

            expectedCount = 0
            result = isDomainResourceCountEqualToExpectedCount(
                            self.apiclient, self.cadmin_1.domainid,
                            expectedCount, RESOURCE_PRIMARY_STORAGE)
            self.assertFalse(result[0], result[1])
            self.assertTrue(result[2], "Resource count does not match")
        except Exception as e:
            self.fail("Failed with exception: %s" % e)
        return
Ejemplo n.º 4
0
    def test_06_destroy_recover_vm(self):
        """Test primary storage counts while destroying and recovering VM
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Deploy VM in child domain
        3. Check if the resource count for domain is updated correctly
        4. Destroy the VM
        5. Verify that the primary storage resource count remains the same
        6. Recover the VM
        7. Verify that the primary storage resource count remains the same
        """

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain
            try:
                vm_1 = VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=self.disk_offering.id,
                    serviceofferingid=self.service_offering.id)

                templatesize = (self.template.size / (1024**3))

                expectedCount = templatesize + self.disk_offering.disksize
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.account.domainid, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                vm_1.delete(self.apiclient, expunge=False)

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

                vm_1.recover(self.apiclient)

                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.account.domainid, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed with exception: %s" % e)
        return
Ejemplo n.º 5
0
    def test_03_increase_volume_size_above_domain_limit(self):
        """Test increasing volume size above the domain limit

        # Validate the following
        # 1. Create a domain and its admin account
        # 2. Set domain primary storage limit more than (5 GB volume + template size of VM)
        #    and less than (20 GB volume+ template size of VM)
        # 3. Deploy a VM without any disk offering (only root disk)
        # 4. Create a volume of 5 GB in the account and attach it to the VM
        # 5. Try to (resize) the volume to 20 GB
        # 6. Resize opearation should fail"""

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])

        templateSize = (self.template.size / (1024**3))
        domainLimit = ((templateSize + self.disk_offering_20_GB.disksize) - 1)
        response = self.updateResourceLimits(domainLimit=domainLimit)
        self.assertEqual(response[0], PASS, response[1])

        apiclient = self.testClient.getUserApiClient(
            UserName=self.parentd_admin.name,
            DomainName=self.parentd_admin.domain)
        self.assertNotEqual(
            apiclient, FAILED, "Failed to get api client\
                            of account: %s" % self.parentd_admin.name)

        try:
            virtualMachine = VirtualMachine.create(
                apiclient,
                self.services["virtual_machine"],
                accountid=self.parentd_admin.name,
                domainid=self.parent_domain.id,
                serviceofferingid=self.service_offering.id)

            volume = Volume.create(apiclient,
                                   self.services["volume"],
                                   zoneid=self.zone.id,
                                   account=self.parentd_admin.name,
                                   domainid=self.parent_domain.id,
                                   diskofferingid=self.disk_offering_5_GB.id)

            virtualMachine.attach_volume(apiclient, volume=volume)

            expectedCount = (templateSize + self.disk_offering_5_GB.disksize)
            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")
        except Exception as e:
            self.fail("Failed with exception: %s" % e)

        if self.hypervisor == str(XEN_SERVER).lower():
            virtualMachine.stop(self.apiclient)
        with self.assertRaises(Exception):
            volume.resize(apiclient,
                          diskofferingid=self.disk_offering_20_GB.id)
        return
Ejemplo n.º 6
0
    def test_03_increase_volume_size_above_domain_limit(self):
	"""Test increasing volume size above the domain limit

        # Validate the following
        # 1. Create a domain and its admin account
        # 2. Set domain primary storage limit more than (5 GB volume + template size of VM)
        #    and less than (20 GB volume+ template size of VM)
        # 3. Deploy a VM without any disk offering (only root disk)
        # 4. Create a volume of 5 GB in the account and attach it to the VM
        # 5. Try to (resize) the volume to 20 GB
        # 6. Resize opearation should fail"""

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])

        templateSize = (self.template.size / (1024**3))
        domainLimit = ((templateSize + self.disk_offering_20_GB.disksize) - 1)
        response = self.updateResourceLimits(domainLimit=domainLimit)
        self.assertEqual(response[0], PASS, response[1])

        apiclient = self.testClient.getUserApiClient(
                        UserName=self.parentd_admin.name,
                        DomainName=self.parentd_admin.domain)
        self.assertNotEqual(apiclient, FAILED, "Failed to get api client\
                            of account: %s" % self.parentd_admin.name)

        try:
            virtualMachine = VirtualMachine.create(
                    apiclient, self.services["virtual_machine"],
                    accountid=self.parentd_admin.name, domainid=self.parent_domain.id,
                    serviceofferingid=self.service_offering.id
                    )

            volume = Volume.create(
                    apiclient,self.services["volume"],zoneid=self.zone.id,
                    account=self.parentd_admin.name,domainid=self.parent_domain.id,
                    diskofferingid=self.disk_offering_5_GB.id)

            virtualMachine.attach_volume(apiclient, volume=volume)

            expectedCount = (templateSize + self.disk_offering_5_GB.disksize)
            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")
        except Exception as e:
            self.fail("Failed with exception: %s" % e)

        if self.hypervisor == str(XEN_SERVER).lower():
            virtualMachine.stop(self.apiclient)
        with self.assertRaises(Exception):
            volume.resize(apiclient, diskofferingid=self.disk_offering_20_GB.id)
        return
Ejemplo n.º 7
0
    def test_02_multiple_domains_primary_storage_limits(self):
        """Test primary storage counts in multiple child domains
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Deploy VM in child domain
        3. Check if the resource count for domain is updated correctly
        4. Create a volume and attach it to the VM
        5. Check if the primary storage resource count is updated correctly

        """

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

        templatesize = (self.template.size / (1024**3))

        for domain, admin in list(users.items()):
            self.account = admin
            self.domain = domain

            apiclient = self.testClient.getUserApiClient(
                UserName=self.account.name, DomainName=self.account.domain)
            self.assertNotEqual(
                apiclient, FAILED,
                "Failed to create api client for account: %s" %
                self.account.name)
            try:
                vm = VirtualMachine.create(
                    apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=self.disk_offering.id,
                    serviceofferingid=self.service_offering.id)
                self.cleanup.append(vm)

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

                # Creating service offering with 10 GB volume
                self.services["disk_offering"]["disksize"] = 10
                disk_offering_10_GB = DiskOffering.create(
                    self.apiclient, services=self.services["disk_offering"])
                self.cleanup.append(disk_offering_10_GB)

                volume = Volume.create(apiclient,
                                       self.services["volume"],
                                       zoneid=self.zone.id,
                                       account=self.account.name,
                                       domainid=self.account.domainid,
                                       diskofferingid=disk_offering_10_GB.id)
                self.cleanup.append(
                    volume)  # we get an exception in the next few lines

                volumeSize = (volume.size / (1024**3))
                expectedCount += volumeSize

                vm.attach_volume(apiclient, volume=volume)
                self.cleanup.remove(
                    volume)  # we can't cleanup an attached volume
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failure: %s" % e)
            return
Ejemplo n.º 8
0
    def test_04_create_template_snapshot(self):
        """Test create snapshot and templates from volume

        # Validate the following
        1. Create parent domain with two child sub-domains (and their admin accounts)
        Follow these steps for both the domains
        # 1. Create template from snapshot and verify secondary storage resource count
        # 2. Create Volume from Snapshot and verify primary storage resource count
        # 3. Attach volume to instance which was created from snapshot and
        #    verify primary storage resource count
        # 4. Detach volume from instance which was created from snapshot and
        #    verify the primary storage resource count
        # 5. Delete volume which was created from snapshot and verify primary storage
             resource count"""

        result = self.setupAccounts()
        if result[0] == FAIL:
            self.fail(
                "Failure while setting up accounts and domains: %s" %
                result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

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

                templatesize = (self.template.size / (1024 ** 3))

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

                vm.stop(self.apiclient)

                response = createSnapshotFromVirtualMachineVolume(
                    apiclient,
                    self.account,
                    vm.id)
                self.assertEqual(response[0], PASS, response[1])
                snapshot = response[1]

                response = snapshot.validateState(
                    apiclient,
                    Snapshot.BACKED_UP)
                self.assertEqual(response[0], PASS, response[1])

                self.services["volume"]["size"] = self.services[
                    "disk_offering"]["disksize"]
                volume = Volume.create_from_snapshot(
                    apiclient,
                    snapshot_id=snapshot.id,
                    services=self.services["volume"],
                    account=self.account.name,
                    domainid=self.account.domainid)
                volumeSize = (volume.size / (1024 ** 3))
                vm.attach_volume(apiclient, volume)
                expectedCount = initialResourceCount + (volumeSize)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    expectedCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                expectedCount -= volumeSize
                vm.detach_volume(apiclient, volume)
                volume.delete(apiclient)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    expectedCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed with exception : %s" % e)
        return
Ejemplo n.º 9
0
    def test_03_multiple_domains_multiple_volumes(self):
        """Test primary storage counts in multiple child domains
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Deploy VM in child domain
        3. Check if the resource count for domain is updated correctly
        4. Create multiple volumes and attach it to the VM
        5. Check if the primary storage resource count is updated correctly
        6. Delete one of the volumes and check if the primary storage resource count
           reduced by equivalent number
        7. Detach other volume and check primary storage resource count remains the same

        """
        # Setting up account and domain hierarchy

        result = self.setupAccounts()
        if result[0] == FAIL:
            self.fail(
                "Failure while setting up accounts and domains: %s" %
                result[1])
        else:
            users = result[2]

        templatesize = (self.template.size / (1024 ** 3))

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            try:
                vm = VirtualMachine.create(
                    apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=self.disk_offering.id,
                    serviceofferingid=self.service_offering.id)

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

                volume1size = self.services["disk_offering"]["disksize"] = 15
                disk_offering_15_GB = DiskOffering.create(
                    self.apiclient,
                    services=self.services["disk_offering"])

                self.cleanup.append(disk_offering_15_GB)

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

                self.cleanup.append(disk_offering_20_GB)

                volume_1 = Volume.create(
                    apiclient,
                    self.services["volume"],
                    zoneid=self.zone.id,
                    account=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=disk_offering_15_GB.id)

                volume_2 = Volume.create(
                    apiclient,
                    self.services["volume"],
                    zoneid=self.zone.id,
                    account=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=disk_offering_20_GB.id)

                vm.attach_volume(apiclient, volume=volume_1)
                vm.attach_volume(apiclient, volume=volume_2)

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

                vm.detach_volume(apiclient, volume=volume_1)
                volume_1.delete(apiclient)

                expectedCount -= volume1size
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    expectedCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failure: %s" % e)
        return
Ejemplo n.º 10
0
    def test_02_multiple_domains_primary_storage_limits(self):
        """Test primary storage counts in multiple child domains
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Deploy VM in child domain
        3. Check if the resource count for domain is updated correctly
        4. Create a volume and attach it to the VM
        5. Check if the primary storage resource count is updated correctly

        """

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

        templatesize = (self.template.size / (1024 ** 3))

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            apiclient = self.testClient.getUserApiClient(
                UserName=self.account.name,
                DomainName=self.account.domain)
            self.assertNotEqual(
                apiclient,
                FAILED,
                "Failed to create api client for account: %s" %
                self.account.name)
            try:
                vm = VirtualMachine.create(
                    apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=self.disk_offering.id,
                    serviceofferingid=self.service_offering.id)

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

                # Creating service offering with 10 GB volume
                self.services["disk_offering"]["disksize"] = 10
                disk_offering_10_GB = DiskOffering.create(
                    self.apiclient,
                    services=self.services["disk_offering"])

                self.cleanup.append(disk_offering_10_GB)

                volume = Volume.create(
                    apiclient,
                    self.services["volume"],
                    zoneid=self.zone.id,
                    account=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=disk_offering_10_GB.id)

                volumeSize = (volume.size / (1024 ** 3))
                expectedCount += volumeSize

                vm.attach_volume(apiclient, volume=volume)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    expectedCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failure: %s" % e)
            return
Ejemplo n.º 11
0
    def test_03_copy_template(self):
        """Test secondary storage counts in multiple child domains
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Register template in child domain
        3. Check if the resource count for domain is updated correctly
        4. Copy template to other zone
        5. Verify that secondary storage count for the domain is doubled
           as there are two templates now
        """

        zones = list_zones(self.apiclient)
        self.assertEqual(
            validateList(zones)[0], PASS, "zones list validation faield")

        if len(zones) < 2:
            self.skipTest(
                "At least 2 zones should be present for this test case")

        users = None
        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            try:
                builtin_info = get_builtin_template_info(
                    self.apiclient, self.zone.id)
                self.services["template_2"]["url"] = builtin_info[0]
                self.services["template_2"]["hypervisor"] = builtin_info[1]
                self.services["template_2"]["format"] = builtin_info[2]

                template = Template.register(self.apiclient,
                                             self.services["template_2"],
                                             zoneid=self.zone.id,
                                             account=self.account.name,
                                             domainid=self.account.domainid)

                template.download(self.apiclient)

                templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
                if validateList(templates)[0] == FAIL:
                    raise Exception("templates list validation failed")

                templateSize = int(int(templates[0].size) / (1024**3))
                expectedCount = templateSize
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_SECONDARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                templateDestinationZoneId = None
                for zone in zones:
                    if template.zoneid != zone.id:
                        templateDestinationZoneId = zone.id
                        break

                template.copy(self.apiclient,
                              destzoneid=templateDestinationZoneId,
                              sourcezoneid=template.zoneid)

                expectedCount *= 2
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_SECONDARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed to get zone list: %s" % e)
            return
Ejemplo n.º 12
0
    def test_04_create_template_snapshot(self):
        """Test create snapshot and templates from volume

        # Validate the following
        1. Create parent domain with two child sub-domains (and their admin accounts)
        Follow these steps for both the domains
        # 1. Create template from snapshot and verify secondary storage resource count
        # 2. Create Volume from Snapshot and verify primary storage resource count
        # 3. Attach volume to instance which was created from snapshot and
        #    verify primary storage resource count
        # 4. Detach volume from instance which was created from snapshot and
        #    verify the primary storage resource count
        # 5. Delete volume which was created from snapshot and verify primary storage
             resource count"""

        if self.hypervisor.lower() in ['hyperv']:
            self.skipTest("Snapshots feature is not supported on Hyper-V")

        result = self.setupAccounts()
        if result[0] == FAIL:
            self.fail("Failure while setting up accounts and domains: %s" %
                      result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

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

                templatesize = (self.template.size / (1024**3))

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

                vm.stop(self.apiclient)

                response = createSnapshotFromVirtualMachineVolume(
                    apiclient, self.account, vm.id)
                self.assertEqual(response[0], PASS, response[1])
                snapshot = response[1]

                response = snapshot.validateState(apiclient,
                                                  Snapshot.BACKED_UP)
                self.assertEqual(response[0], PASS, response[1])

                self.services["volume"]["size"] = self.services[
                    "disk_offering"]["disksize"]
                volume = Volume.create_from_snapshot(
                    apiclient,
                    snapshot_id=snapshot.id,
                    services=self.services["volume"],
                    account=self.account.name,
                    domainid=self.account.domainid)
                volumeSize = (volume.size / (1024**3))
                vm.attach_volume(apiclient, volume)
                expectedCount = initialResourceCount + (volumeSize)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                expectedCount -= volumeSize
                vm.detach_volume(apiclient, volume)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                volume.delete(apiclient)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed with exception : %s" % e)
        return
Ejemplo n.º 13
0
    def test_04_create_template_delete_account(self):
        """Test secondary 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. Register template in child domain 1
        3. Verify that the secondary storage count for child domain 1 equals
           the template size
        4. Register template in child domain 2
        5. Vreify that the seconday storage count for child domain 2 equals
           the template size
        6. Verify that the secondary storage count for parent domain equals
           double of template size
        7. Delete child domain 1 admin account
        8. Verify that secondary storage count for parent domain now equals
           to only 1 template size
        """

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])

        try:
            builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
            self.services["template_2"]["url"] = builtin_info[0]
            self.services["template_2"]["hypervisor"] = builtin_info[1]
            self.services["template_2"]["format"] = builtin_info[2]

            template = Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.cadmin_1.name,
                                     domainid=self.cadmin_1.domainid)

            template.download(self.apiclient)

            templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
            if validateList(templates)[0] == FAIL:
                raise Exception("templates list validation failed")

            self.templateSize = int(int(templates[0].size) / (1024**3))
        except Exception as e:
            self.fail("Failed with exception as ee: %s" % e)

        # Checking Primary Storage count of Parent domain admin before deleting child domain user account
        expectedCount = self.templateSize
        result = isDomainResourceCountEqualToExpectedCount(
                                    self.apiclient, self.cadmin_1.domainid,
                                    expectedCount, RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        try:
            template = Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.cadmin_2.name,
                                     domainid=self.cadmin_2.domainid)

            template.download(self.apiclient)
        except Exception as e:
            self.fail("Failed while registering/downloading template: %s" % e)

        result = isDomainResourceCountEqualToExpectedCount(
                                    self.apiclient, self.cadmin_2.domainid,
                                    expectedCount, RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

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

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

        expectedCount /= 2
        result = isDomainResourceCountEqualToExpectedCount(
                                    self.apiclient, self.parent_domain.id,
                                    expectedCount, RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")
        return
Ejemplo n.º 14
0
    def test_03_copy_template(self):
        """Test secondary storage counts in multiple child domains
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Register template in child domain
        3. Check if the resource count for domain is updated correctly
        4. Copy template to other zone
        5. Verify that secondary storage count for the domain is doubled
           as there are two templates now
        """

        zones = list_zones(self.apiclient)
        self.assertEqual(validateList(zones)[0], PASS, "zones list validation faield")

        if len(zones) < 2:
            self.skipTest("At least 2 zones should be present for this test case")

        users = None
        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            try:
                builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
                self.services["template_2"]["url"] = builtin_info[0]
                self.services["template_2"]["hypervisor"] = builtin_info[1]
                self.services["template_2"]["format"] = builtin_info[2]

                template = Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.account.name,
                                     domainid=self.account.domainid)

                template.download(self.apiclient)

                templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
                if validateList(templates)[0] == FAIL:
                    raise Exception("templates list validation failed")

                templateSize = int(int(templates[0].size) / (1024**3))
                expectedCount = templateSize
                result = isDomainResourceCountEqualToExpectedCount(
                                    self.apiclient, self.domain.id,
                                    expectedCount, RESOURCE_SECONDARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                templateDestinationZoneId = None
                for zone in zones:
                    if template.zoneid != zone.id :
                        templateDestinationZoneId = zone.id
                        break

                template.copy(self.apiclient, destzoneid=templateDestinationZoneId,
                              sourcezoneid = template.zoneid)

                expectedCount *= 2
                result = isDomainResourceCountEqualToExpectedCount(
                                    self.apiclient, self.domain.id,
                                    expectedCount, RESOURCE_SECONDARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed to get zone list: %s" % e)
	    return
Ejemplo n.º 15
0
    def test_02_multiple_domains_secondary_storage_counts(self):
        """Test secondary storage counts in multiple child domains
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Register template in child domain
        3. Check if the resource count for domain is updated correctly
        4. Delete the template
        5. Verify that the resource count for the domain is 0

        """
        users = None
        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            try:
                builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
                self.services["template_2"]["url"] = builtin_info[0]
                self.services["template_2"]["hypervisor"] = builtin_info[1]
                self.services["template_2"]["format"] = builtin_info[2]

                template = Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.account.name,
                                     domainid=self.account.domainid)

                template.download(self.apiclient)

                templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
                if validateList(templates)[0] == FAIL:
                    raise Exception("templates list validation failed")

                templateSize = int(int(templates[0].size) / (1024**3))
                expectedCount = templateSize
                result = isDomainResourceCountEqualToExpectedCount(
                                    self.apiclient, self.domain.id,
                                    expectedCount, RESOURCE_SECONDARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                template.delete(self.apiclient)

                expectedCount = 0
                result = isDomainResourceCountEqualToExpectedCount(
                                    self.apiclient, self.domain.id,
                                    expectedCount, RESOURCE_SECONDARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed to get zone list: %s" % e)
	    return
Ejemplo n.º 16
0
    def test_01_multiple_domains_secondary_storage_limits(self):
        """Test secondary 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. Register template in child domain 1 so that total secondary storage
           is less than the limit of child domain
        3. Set the child domain limit equal to template size and parent domain
           domain limit as double of the template size
        4. Repeat step 2 for child domain 2
        5. Try to register template in parent domain now so that the total secondary storage in
           parent domain (including that in sub-domains is more than the secondary
           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 template in account 2 and check secondary storage count
           of parent domain

        # Validations:
        1. Step 2 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, result[1])

        try:
            builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
            self.services["template_2"]["url"] = builtin_info[0]
            self.services["template_2"]["hypervisor"] = builtin_info[1]
            self.services["template_2"]["format"] = builtin_info[2]

            templateChildAccount1 = Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.cadmin_1.name,
                                     domainid=self.cadmin_1.domainid)

            templateChildAccount1.download(self.apiclient)

            templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=templateChildAccount1.id)
            if validateList(templates)[0] == FAIL:
                raise Exception("templates list validation failed")

            self.templateSize = int(int(templates[0].size) / (1024**3))
        except Exception as e:
            self.fail("Failed with exception as ee: %s" % e)

        subdomainlimit = (self.templateSize)

        result = self.updateDomainResourceLimits(((subdomainlimit*2)), subdomainlimit)
        self.assertEqual(result[0], PASS, result[1])

        # Checking Primary Storage count of Parent domain admin before deleting child domain user account
        result = isDomainResourceCountEqualToExpectedCount(
                        self.apiclient, self.cadmin_1.domainid,
                        self.templateSize, RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        try:
            templateChildAccount2 = Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.cadmin_2.name,
                                     domainid=self.cadmin_2.domainid)

            templateChildAccount2.download(self.apiclient)
        except Exception as e:
            self.fail("Failed while registering/downloading template: %s" % e)

        result = isDomainResourceCountEqualToExpectedCount(
                        self.apiclient, self.cadmin_2.domainid,
                        self.templateSize, RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        with self.assertRaises(Exception):
            Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.parentd_admin.name,
                                     domainid=self.parentd_admin.domainid)

        self.cadmin_1.delete(self.apiclient)
        self.cleanup.remove(self.cadmin_1)

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

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

        result = isDomainResourceCountEqualToExpectedCount(
                        self.apiclient, self.parent_domain.id,
                        0, RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")
        return
Ejemplo n.º 17
0
    def test_04_create_template_delete_account(self):
        """Test secondary 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. Register template in child domain 1
        3. Verify that the secondary storage count for child domain 1 equals
           the template size
        4. Register template in child domain 2
        5. Vreify that the seconday storage count for child domain 2 equals
           the template size
        6. Verify that the secondary storage count for parent domain equals
           double of template size
        7. Delete child domain 1 admin account
        8. Verify that secondary storage count for parent domain now equals
           to only 1 template size
        """

        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])

        try:
            builtin_info = get_builtin_template_info(self.apiclient,
                                                     self.zone.id)
            self.services["template_2"]["url"] = builtin_info[0]
            self.services["template_2"]["hypervisor"] = builtin_info[1]
            self.services["template_2"]["format"] = builtin_info[2]

            template = Template.register(self.apiclient,
                                         self.services["template_2"],
                                         zoneid=self.zone.id,
                                         account=self.cadmin_1.name,
                                         domainid=self.cadmin_1.domainid)

            template.download(self.apiclient)

            templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
            if validateList(templates)[0] == FAIL:
                raise Exception("templates list validation failed")

            self.templateSize = int(int(templates[0].size) / (1024**3))
        except Exception as e:
            self.fail("Failed with exception as ee: %s" % e)

        # Checking Primary Storage count of Parent domain admin before deleting child domain user account
        expectedCount = self.templateSize
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.cadmin_1.domainid, expectedCount,
            RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        try:
            template = Template.register(self.apiclient,
                                         self.services["template_2"],
                                         zoneid=self.zone.id,
                                         account=self.cadmin_2.name,
                                         domainid=self.cadmin_2.domainid)

            template.download(self.apiclient)
        except Exception as e:
            self.fail("Failed while registering/downloading template: %s" % e)

        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.cadmin_2.domainid, expectedCount,
            RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

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

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

        expectedCount /= 2
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.parent_domain.id, expectedCount,
            RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")
        return
Ejemplo n.º 18
0
    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
Ejemplo n.º 19
0
    def test_03_multiple_domains_multiple_volumes(self):
        """Test primary storage counts in multiple child domains
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Deploy VM in child domain
        3. Check if the resource count for domain is updated correctly
        4. Create multiple volumes and attach it to the VM
        5. Check if the primary storage resource count is updated correctly
        6. Delete one of the volumes and check if the primary storage resource count
           reduced by equivalent number
        7. Detach other volume and check primary storage resource count remains the same

        """
        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        if result[0] == FAIL:
            self.fail("Failure while setting up accounts and domains: %s" %
                      result[1])
        else:
            users = result[2]

        templatesize = (self.template.size / (1024**3))

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            try:
                vm = VirtualMachine.create(
                    apiclient,
                    self.services["virtual_machine"],
                    accountid=self.account.name,
                    domainid=self.account.domainid,
                    diskofferingid=self.disk_offering.id,
                    serviceofferingid=self.service_offering.id)

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

                volume1size = self.services["disk_offering"]["disksize"] = 15
                disk_offering_15_GB = DiskOffering.create(
                    self.apiclient, services=self.services["disk_offering"])

                self.cleanup.append(disk_offering_15_GB)

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

                self.cleanup.append(disk_offering_20_GB)

                volume_1 = Volume.create(apiclient,
                                         self.services["volume"],
                                         zoneid=self.zone.id,
                                         account=self.account.name,
                                         domainid=self.account.domainid,
                                         diskofferingid=disk_offering_15_GB.id)

                volume_2 = Volume.create(apiclient,
                                         self.services["volume"],
                                         zoneid=self.zone.id,
                                         account=self.account.name,
                                         domainid=self.account.domainid,
                                         diskofferingid=disk_offering_20_GB.id)

                vm.attach_volume(apiclient, volume=volume_1)
                vm.attach_volume(apiclient, volume=volume_2)

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

                vm.detach_volume(apiclient, volume=volume_1)
                volume_1.delete(apiclient)

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

                expectedCount -= volume2size
                vm.detach_volume(apiclient, volume=volume_2)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failure: %s" % e)
        return
Ejemplo n.º 20
0
    def test_01_multiple_domains_secondary_storage_limits(self):
        """Test secondary 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. Register template in child domain 1 so that total secondary storage
           is less than the limit of child domain
        3. Set the child domain limit equal to template size and parent domain
           domain limit as double of the template size
        4. Repeat step 2 for child domain 2
        5. Try to register template in parent domain now so that the total secondary storage in
           parent domain (including that in sub-domains is more than the secondary
           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 template in account 2 and check secondary storage count
           of parent domain

        # Validations:
        1. Step 2 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, result[1])

        try:
            builtin_info = get_builtin_template_info(self.apiclient,
                                                     self.zone.id)
            self.services["template_2"]["url"] = builtin_info[0]
            self.services["template_2"]["hypervisor"] = builtin_info[1]
            self.services["template_2"]["format"] = builtin_info[2]

            templateChildAccount1 = Template.register(
                self.apiclient,
                self.services["template_2"],
                zoneid=self.zone.id,
                account=self.cadmin_1.name,
                domainid=self.cadmin_1.domainid)

            templateChildAccount1.download(self.apiclient)

            templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=templateChildAccount1.id)
            if validateList(templates)[0] == FAIL:
                raise Exception("templates list validation failed")

            self.templateSize = int(int(templates[0].size) / (1024**3))
        except Exception as e:
            self.fail("Failed with exception as ee: %s" % e)

        subdomainlimit = (self.templateSize)

        result = self.updateDomainResourceLimits(((subdomainlimit * 2)),
                                                 subdomainlimit)
        self.assertEqual(result[0], PASS, result[1])

        # Checking Primary Storage count of Parent domain admin before deleting child domain user account
        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.cadmin_1.domainid, self.templateSize,
            RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        try:
            templateChildAccount2 = Template.register(
                self.apiclient,
                self.services["template_2"],
                zoneid=self.zone.id,
                account=self.cadmin_2.name,
                domainid=self.cadmin_2.domainid)

            templateChildAccount2.download(self.apiclient)
        except Exception as e:
            self.fail("Failed while registering/downloading template: %s" % e)

        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.cadmin_2.domainid, self.templateSize,
            RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")

        with self.assertRaises(Exception):
            Template.register(self.apiclient,
                              self.services["template_2"],
                              zoneid=self.zone.id,
                              account=self.parentd_admin.name,
                              domainid=self.parentd_admin.domainid)

        self.cadmin_1.delete(self.apiclient)
        self.cleanup.remove(self.cadmin_1)

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

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

        result = isDomainResourceCountEqualToExpectedCount(
            self.apiclient, self.parent_domain.id, 0,
            RESOURCE_SECONDARY_STORAGE)
        self.assertFalse(result[0], result[1])
        self.assertTrue(result[2], "Resource count does not match")
        return
Ejemplo n.º 21
0
    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
Ejemplo n.º 22
0
    def test_02_multiple_domains_secondary_storage_counts(self):
        """Test secondary storage counts in multiple child domains
        # Steps
        1. Create a parent domain and two sub-domains in it (also admin accounts
           of each domain)
        Repeat following steps for both the child domains
        2. Register template in child domain
        3. Check if the resource count for domain is updated correctly
        4. Delete the template
        5. Verify that the resource count for the domain is 0

        """
        users = None
        # Setting up account and domain hierarchy
        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            try:
                builtin_info = get_builtin_template_info(
                    self.apiclient, self.zone.id)
                self.services["template_2"]["url"] = builtin_info[0]
                self.services["template_2"]["hypervisor"] = builtin_info[1]
                self.services["template_2"]["format"] = builtin_info[2]

                template = Template.register(self.apiclient,
                                             self.services["template_2"],
                                             zoneid=self.zone.id,
                                             account=self.account.name,
                                             domainid=self.account.domainid)

                template.download(self.apiclient)

                templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
                if validateList(templates)[0] == FAIL:
                    raise Exception("templates list validation failed")

                templateSize = int(int(templates[0].size) / (1024**3))
                expectedCount = templateSize
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_SECONDARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                template.delete(self.apiclient)

                expectedCount = 0
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_SECONDARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed to get zone list: %s" % e)
            return