예제 #1
0
def update_resource_count(apiclient,
                          domainid,
                          accountid=None,
                          projectid=None,
                          rtype=None):
    """updates the resource count
        0     - VM
        1     - Public IP
        2     - Volume
        3     - Snapshot
        4     - Template
        5     - Projects
        6     - Network
        7     - VPC
        8     - CPUs
        9     - RAM
        10    - Primary (shared) storage (Volumes)
        11    - Secondary storage (Snapshots, Templates & ISOs)
    """

    Resources.updateCount(apiclient,
                          domainid=domainid,
                          account=accountid if accountid else None,
                          projectid=projectid if projectid else None,
                          resourcetype=rtype if rtype else None)
    return
    def test_01_updateResourceCount(self):
        """Test update resource count for an account using a custom service offering to deploy a VM.
        """

        # This test will execute the following steps to assure resource count update is working properly
        # 1. Create an account.
        # 2. Start 2 VMs; one with normal service offering and other with a custom service offering
        # 3. Call the update resource count method and check the CPU and memory values.
        #    The two VMs will add up to 3 CPUs and 1024Mb of RAM.
        # 4. If the return of updateResourceCount method matches with the expected one, the test passes; otherwise, it fails.
        # 5. Remove everything created by deleting the account

        vm_1 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_custom.id,
            customcpunumber=1,
            customcpuspeed=1000,
            custommemory=512)

        self.debug("Deployed VM 1 in account: %s, ID: %s" %
                   (self.account.name, vm_1.id))

        vm_2 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_normal.id)
        self.debug("Deployed VM 2 in account: %s, ID: %s" %
                   (self.account.name, vm_2.id))

        resourceCountCpu = Resources.updateCount(
            self.apiclient,
            resourcetype=8,
            account=self.account.name,
            domainid=self.account.domainid)

        self.debug("ResourceCount for CPU: %s" %
                   (resourceCountCpu[0].resourcecount))
        self.assertEqual(resourceCountCpu[0].resourcecount, 3,
                         "The number of CPU cores does not seem to be right.")
        resourceCountMemory = Resources.updateCount(
            self.apiclient,
            resourcetype=9,
            account=self.account.name,
            domainid=self.account.domainid)

        self.debug("ResourceCount for memory: %s" %
                   (resourceCountMemory[0].resourcecount))
        self.assertEqual(resourceCountMemory[0].resourcecount, 1024,
                         "The memory amount does not seem to be right.")
        return
예제 #3
0
def update_resource_count(apiclient, domainid, accountid=None, projectid=None, rtype=None):
    """updates the resource count
        0     - VM
        1     - Public IP
        2     - Volume
        3     - Snapshot
        4     - Template
        5     - Projects
        6     - Network
        7     - VPC
        8     - CPUs
        9     - RAM
        10    - Primary (shared) storage (Volumes)
        11    - Secondary storage (Snapshots, Templates & ISOs)
    """

    Resources.updateCount(
        apiclient,
        domainid=domainid,
        account=accountid if accountid else None,
        projectid=projectid if projectid else None,
        resourcetype=rtype if rtype else None,
    )
    return
예제 #4
0
def isDomainResourceCountEqualToExpectedCount(apiclient, domainid, expectedcount, resourcetype):
    """Get the resource count of specific domain and match
    it with the expected count
    Return list [isExceptionOccured, reasonForException, isResourceCountEqual]"""
    isResourceCountEqual = False
    isExceptionOccured = False
    reasonForException = None
    try:
        response = Resources.updateCount(apiclient, domainid=domainid, resourcetype=resourcetype)
    except Exception as e:
        reasonForException = "Failed while updating resource count: %s" % e
        isExceptionOccured = True
        return [isExceptionOccured, reasonForException, isResourceCountEqual]

    resourcecount = response[0].resourcecount / (1024 ** 3)
    if resourcecount == expectedcount:
        isResourceCountEqual = True
    return [isExceptionOccured, reasonForException, isResourceCountEqual]
예제 #5
0
def isDomainResourceCountEqualToExpectedCount(apiclient, domainid, expectedcount,
                                              resourcetype):
    """Get the resource count of specific domain and match
    it with the expected count
    Return list [isExceptionOccured, reasonForException, isResourceCountEqual]"""
    isResourceCountEqual = False
    isExceptionOccured = False
    reasonForException = None
    try:
        response = Resources.updateCount(apiclient, domainid=domainid,
                                         resourcetype=resourcetype)
    except Exception as e:
        reasonForException = "Failed while updating resource count: %s" % e
        isExceptionOccured = True
        return [isExceptionOccured, reasonForException, isResourceCountEqual]

    resourcecount = (response[0].resourcecount / (1024**3))
    if resourcecount == expectedcount:
        isResourceCountEqual = True
    return [isExceptionOccured, reasonForException, isResourceCountEqual]
    def test_01_updateResourceCount(self):
        """Test update resource count for an account using a custom service offering to deploy a VM.
        """
        
        # This test will execute the following steps to assure resource count update is working properly
        # 1. Create an account.
        # 2. Start 2 VMs; one with normal service offering and other with a custom service offering
        # 3. Call the update resource count method and check the CPU and memory values.
        #    The two VMs will add up to 3 CPUs and 1024Mb of RAM.
        # 4. If the return of updateResourceCount method matches with the expected one, the test passes; otherwise, it fails.
        # 5. Remove everything created by deleting the account
        
        vm_1 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_custom.id,
            customcpunumber = 1,
            customcpuspeed = 1000,
            custommemory = 512
        )
        
        self.debug("Deployed VM 1 in account: %s, ID: %s" % (
            self.account.name,
            vm_1.id
        ))
        
        vm_2 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_normal.id
        )
        self.debug("Deployed VM 2 in account: %s, ID: %s" % (
            self.account.name,
            vm_2.id
        ))

        resourceCountCpu = Resources.updateCount(
            self.apiclient,
            resourcetype=8,
            account=self.account.name,
            domainid=self.account.domainid
        ) 
            
        self.debug("ResourceCount for CPU: %s" % (
            resourceCountCpu[0].resourcecount
        ))
        self.assertEqual(
            resourceCountCpu[0].resourcecount,
            3,
            "The number of CPU cores does not seem to be right."
        )
        resourceCountMemory = Resources.updateCount(
            self.apiclient,
            resourcetype=9,
            account=self.account.name,
            domainid=self.account.domainid
        ) 
            
        self.debug("ResourceCount for memory: %s" % (
            resourceCountMemory[0].resourcecount
        ))
        self.assertEqual(
            resourceCountMemory[0].resourcecount,
            1024,
            "The memory amount does not seem to be right."
        )
        return