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 setupAccounts(self, account_limit=2, domain_limit=2, project_limit=2): self.debug("Creating a domain under: %s" % self.domain.name) self.child_domain = Domain.create(self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id) self.debug("domain crated with domain id %s" % self.child_domain.id) self.child_do_admin = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.child_domain.id) self.debug("domain admin created for domain id %s" % self.child_do_admin.domainid) # Create project as a domain admin self.project = Project.create(self.apiclient, self.services["project"], account=self.child_do_admin.name, domainid=self.child_do_admin.domainid) # Cleanup created project at end of test self.cleanup.append(self.project) # Cleanup accounts created self.cleanup.append(self.child_do_admin) self.cleanup.append(self.child_domain) self.debug("Updating the CPU resource count for domain: %s" % self.child_domain.name) # Update resource limits for account 1 responses = Resources.updateLimit(self.apiclient, resourcetype=8, max=account_limit, account=self.child_do_admin.name, domainid=self.child_do_admin.domainid) self.debug("CPU Resource count for child domain admin account is now: %s" % responses.max) self.debug("Updating the CPU limit for project") responses = Resources.updateLimit(self.apiclient, resourcetype=8, max=project_limit, projectid=self.project.id) self.debug("CPU Resource count for project is now") self.debug(responses.max) self.debug("Updating the CPU limit for domain only") responses = Resources.updateLimit(self.apiclient, resourcetype=8, max=domain_limit, domainid=self.child_domain.id) self.debug("CPU Resource count for domain %s with id %s is now %s" % (responses.domain, responses.domainid, responses.max)) return
def setupAccounts(self): self.debug("Creating a domain under: %s" % self.domain.name) self.parent_domain = Domain.create( self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id ) self.parentd_admin = Account.create( self.apiclient, self.services["account"], admin=True, domainid=self.domain.id ) self.debug("Updating the Memory resource count for domain: %s" % self.domain.name) Resources.updateLimit( self.apiclient, resourcetype=9, max=4096, account=self.parentd_admin.name, domainid=self.parentd_admin.domainid, ) self.debug("Creating a sub-domain under: %s" % self.parent_domain.name) self.cdomain_1 = Domain.create( self.apiclient, services=self.services["domain"], parentdomainid=self.parent_domain.id ) self.debug("Creating a sub-domain under: %s" % self.parent_domain.name) self.cdomain_2 = Domain.create( self.apiclient, services=self.services["domain"], parentdomainid=self.parent_domain.id ) self.cadmin_1 = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.cdomain_1.id) self.debug("Updating the Memory resource count for domain: %s" % self.cdomain_1.name) Resources.updateLimit(self.apiclient, resourcetype=9, max=2048, domainid=self.cadmin_1.domainid) self.debug("Updating the Memory resource count for account: %s" % self.cadmin_1.name) Resources.updateLimit( self.apiclient, resourcetype=9, max=2048, account=self.cadmin_1.name, domainid=self.cadmin_1.domainid ) self.cadmin_2 = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.cdomain_2.id) self.debug("Updating the Memory resource count for domain: %s" % self.cdomain_2.name) Resources.updateLimit(self.apiclient, resourcetype=9, max=2048, domainid=self.cadmin_2.domainid) self.debug("Updating the Memory resource count for domain: %s" % self.cadmin_2.name) Resources.updateLimit( self.apiclient, resourcetype=9, max=2048, account=self.cadmin_2.name, domainid=self.cadmin_2.domainid ) # Cleanup the resources created at end of test self.cleanup.append(self.cadmin_1) self.cleanup.append(self.cadmin_2) self.cleanup.append(self.cdomain_1) self.cleanup.append(self.cdomain_2) self.cleanup.append(self.parentd_admin) self.cleanup.append(self.parent_domain) users = {self.parent_domain: self.parentd_admin, self.cdomain_1: self.cadmin_1, self.cdomain_2: self.cadmin_2} return users
def setupAccounts(self): self.debug("Creating a sub-domain under: %s" % self.domain.name) self.child_domain = Domain.create( self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id ) self.child_do_admin = Account.create( self.apiclient, self.services["account"], admin=True, domainid=self.child_domain.id ) # Cleanup the resources created at end of test self.cleanup.append(self.child_do_admin) self.cleanup.append(self.child_domain) Resources.updateLimit( self.apiclient, resourcetype=8, max=16, account=self.child_do_admin.name, domainid=self.child_do_admin.domainid ) self.domain = Domain.create( self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id ) self.admin = Account.create( self.apiclient, self.services["account"], admin=True, domainid=self.domain.id ) # Cleanup the resources created at end of test self.cleanup.append(self.admin) self.cleanup.append(self.domain) Resources.updateLimit( self.apiclient, resourcetype=8, max=16, account=self.admin.name, domainid=self.admin.domainid ) return
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_04_deploy_multiple_vm_with_multiple_cpus(self): """Test Deploy multiple VM with 4 core CPU & verify the usage""" #keep the configuration value - max.account.cpus number = 16 # Validate the following # 1. Create compute offering with 4 core CPU # 2. Deploy multiple VMs with this service offering # 3. List Resource count for the root admin CPU usage # 4. CPU usage should list properly self.debug("Creating service offering with 4 CPU cores") self.service_offering = ServiceOffering.create( self.apiclient, self.services["service_offering"] ) # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = {self.child_domain_1: self.child_do_admin_1, self.child_domain_2: self.child_do_admin_2 } for domain, admin in users.items(): self.account = admin self.domain = domain cpu_account_gc = Resources.list(self.apiclient, resourcetype = 8, #CPU account = self.account.name, domainid = self.domain.id ) if cpu_account_gc[0].max != 16: self.skipTest("This test case requires configuration value max.account.cpus to be 16") api_client = self.testClient.createUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client) vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.debug("Deploying instance - CPU capacity is fully utilized") with self.assertRaises(Exception): self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count = account_list[0].cputotal expected_resource_count = int(self.services["service_offering"]["cpunumber"]) * 4 #Total 4 vms self.assertEqual(resource_count, expected_resource_count, "Initial resource count should with the expected resource count") self.debug("Destroying instance: %s" % vm_1.name) try: vm_1.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_delete = account_list[0].cputotal expected_resource_count -= int(self.services["service_offering"]["cpunumber"]) self.assertEqual(resource_count_after_delete, expected_resource_count, "Resource count should be less than before after deleting the instance") host = findSuitableHostForMigration(self.apiclient, vm_2.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm_2.name, host.name)) try: vm_2.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].cputotal self.debug(resource_count_after_migrate) self.assertEqual(resource_count_after_delete, resource_count_after_migrate, "Resource count should be same after migrating the instance")
def test_04_deploy_multiple_vm_with_multiple_cpus(self): """Test Deploy multiple VM with 4 core CPU & verify the usage""" #keep the configuration value - max.account.cpus number = 16 # Validate the following # 1. Create compute offering with 4 core CPU # 2. Deploy multiple VMs with this service offering # 3. List Resource count for the root admin CPU usage # 4. CPU usage should list properly self.debug("Creating service offering with 4 CPU cores") self.service_offering = ServiceOffering.create( self.apiclient, self.services["service_offering"]) # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = { self.child_domain_1: self.child_do_admin_1, self.child_domain_2: self.child_do_admin_2 } for domain, admin in users.items(): self.account = admin self.domain = domain cpu_account_gc = Resources.list( self.apiclient, resourcetype=8, #CPU account=self.account.name, domainid=self.domain.id) if cpu_account_gc[0].max != 16: self.skipTest( "This test case requires configuration value max.account.cpus to be 16" ) api_client = self.testClient.createUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client) vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.debug("Deploying instance - CPU capacity is fully utilized") with self.assertRaises(Exception): self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count = account_list[0].cputotal expected_resource_count = int(self.services["service_offering"] ["cpunumber"]) * 4 #Total 4 vms self.assertEqual( resource_count, expected_resource_count, "Initial resource count should with the expected resource count" ) self.debug("Destroying instance: %s" % vm_1.name) try: vm_1.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count_after_delete = account_list[0].cputotal expected_resource_count -= int( self.services["service_offering"]["cpunumber"]) self.assertEqual( resource_count_after_delete, expected_resource_count, "Resource count should be less than before after deleting the instance" ) host = find_suitable_host(self.apiclient, vm_2) self.debug("Migrating instance: %s to host: %s" % (vm_2.name, host.name)) try: vm_2.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count_after_migrate = account_list[0].cputotal self.debug(resource_count_after_migrate) self.assertEqual( resource_count_after_delete, resource_count_after_migrate, "Resource count should be same after migrating the instance")
def setupAccounts(self): self.debug("Creating a domain under: %s" % self.domain.name) self.parent_domain = Domain.create(self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id) self.parentd_admin = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.domain.id) self.debug("Updating the Memory resource limit for domain: %s" % self.domain.name) Resources.updateLimit(self.apiclient, resourcetype=8, max=10, domainid=self.parentd_admin.domainid, account=self.parentd_admin.name) self.debug("Creating a sub-domain under: %s" % self.parent_domain.name) self.cdomain_1 = Domain.create(self.apiclient, services=self.services["domain"], parentdomainid=self.parent_domain.id) self.debug("Creating a sub-domain under: %s" % self.parent_domain.name) self.cdomain_2 = Domain.create(self.apiclient, services=self.services["domain"], parentdomainid=self.parent_domain.id) self.cadmin_1 = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.cdomain_1.id) self.debug("Updating the Memory resource count for domain: %s" % self.cdomain_1.name) Resources.updateLimit(self.apiclient, resourcetype=8, max=4, domainid=self.cadmin_1.domainid) self.debug("Updating the Memory resource count for account: %s" % self.cadmin_1.name) Resources.updateLimit(self.apiclient, resourcetype=8, max=2, account=self.cadmin_1.name, domainid=self.cadmin_1.domainid) self.cadmin_2 = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.cdomain_2.id) self.debug("Updating the Memory resource count for domain: %s" % self.cdomain_2.name) Resources.updateLimit(self.apiclient, resourcetype=8, max=5, domainid=self.cadmin_2.domainid) self.debug("Updating the Memory resource count for account: %s" % self.cadmin_2.name) Resources.updateLimit(self.apiclient, resourcetype=8, max=3, account=self.cadmin_2.name, domainid=self.cadmin_2.domainid) # Cleanup the resources created at end of test self.cleanup.append(self.cadmin_1) self.cleanup.append(self.cadmin_2) self.cleanup.append(self.cdomain_1) self.cleanup.append(self.cdomain_2) self.cleanup.append(self.parentd_admin) self.cleanup.append(self.parent_domain) users = { self.parent_domain: self.parentd_admin, self.cdomain_1: self.cadmin_1, self.cdomain_2: self.cadmin_2 } return users
def setupAccounts(self, account_limit=2, domain_limit=2, project_limit=2): self.debug("Creating a domain under: %s" % self.domain.name) self.child_domain = Domain.create(self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id) self.debug("domain crated with domain id %s" % self.child_domain.id) self.child_do_admin = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.child_domain.id) self.debug("domain admin created for domain id %s" % self.child_do_admin.domainid) # Create project as a domain admin self.project = Project.create(self.apiclient, self.services["project"], account=self.child_do_admin.name, domainid=self.child_do_admin.domainid) # Cleanup created project at end of test self.cleanup.append(self.project) # Cleanup accounts created self.cleanup.append(self.child_do_admin) self.cleanup.append(self.child_domain) self.debug("Updating the Memory resource count for domain: %s" % self.child_domain.name) # Update resource limits for account 1 responses = Resources.updateLimit( self.apiclient, resourcetype=9, max=(account_limit * 1024), account=self.child_do_admin.name, domainid=self.child_do_admin.domainid) self.debug( "Memory Resource count for child domain admin account is now: %s" % responses.max) # Update resource limits for project responses = Resources.updateLimit(self.apiclient, resourcetype=9, max=(project_limit * 1024), projectid=self.project.id) self.debug("Memory Resource count for project is now") self.debug(responses.max) # TODO: Update the Memory limit for domain only responses = Resources.updateLimit(self.apiclient, resourcetype=9, max=(domain_limit * 1024), domainid=self.child_domain.id) self.debug("Memory Resource count for domain %s with id %s is now %s" % (responses.domain, responses.domainid, responses.max)) return
def test_04_deploy_multiple_vm(self): """Test Deploy multiple VM with 2 GB memory & verify the usage""" #keep the configuration value - max.account.memory = 8192 (maximum 4 instances per account with 2 GB RAM) # Validate the following # 1. Create compute offering with 2 GB RAM # 2. Deploy multiple VMs with this service offering in child domains of root domain # 3. List Resource count for the root admin Memory usage # 4. Memory usage should list properly self.debug("Creating service offering with 2 GB RAM") self.service_offering = ServiceOffering.create( self.apiclient, self.services["service_offering"] ) # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = {self.child_domain_1: self.child_do_admin_1, self.child_domain_2: self.child_do_admin_2 } for domain, admin in users.items(): self.account = admin self.domain = domain memory_account_gc = Resources.list(self.apiclient, resourcetype = 9, #Memory account = self.account.name, domainid = self.domain.id ) if memory_account_gc[0].max != 8192: self.skipTest("This test case requires configuration value max.account.memory to be 8192") api_client = self.testClient.createUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client) vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.debug("Deploying instance - memory capacity is fully utilized") with self.assertRaises(Exception): self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count = account_list[0].memorytotal expected_resource_count = int(self.services["service_offering"]["memory"]) * 4 #Total 4 vms self.assertEqual(resource_count, expected_resource_count, "Initial resource count should with the expected resource count") self.debug("Destroying instance: %s" % vm_1.name) try: vm_1.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_delete = account_list[0].memorytotal expected_resource_count -= int(self.services["service_offering"]["memory"]) self.assertEqual(resource_count_after_delete, expected_resource_count, "Resource count should match with the expected resource count") host = find_suitable_host(self.apiclient, vm_2) self.debug("Migrating instance: %s to host: %s" % (vm_2.name, host.name)) try: vm_2.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].memorytotal self.debug(resource_count_after_migrate) self.assertEqual(resource_count_after_delete, resource_count_after_migrate, "Resource count should be same after migrating the instance") return