def test_02_project_counts_migrate_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Migrate VM of an accounts added to the project to a new host # 4. Resource count should list properly. project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].cputotal expected_resource_count = int(self.services["service_offering"]["cpunumber"]) self.assertEqual( resource_count, expected_resource_count, "Resource count should match with the expected resource count" ) host = find_suitable_host(self.apiclient, self.vm) self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name)) try: self.vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_migrate = project_list[0].cputotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same after migrating the instance" ) return
def test_03_project_vmlifecycle_delete_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Destroy VM of an accounts added to the project # 4. Resource count should list as 0 after destroying the instance self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].memorytotal self.debug(resource_count) self.debug("Destroying instance: %s" % self.vm.name) try: self.vm.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) # Wait for expunge interval to cleanup Memory wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"]) self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_delete = project_list[0].memorytotal self.assertEqual( resource_count_after_delete, 0, "Resource count for %s should be 0" % get_resource_type(resource_id=9) ) # RAM return
def setupProjectAccounts(self): self.debug("Creating a domain under: %s" % self.domain.name) 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 ) # Create project as a domain admin self.project = Project.create(self.apiclient, self.services["project"], account=self.admin.name, domainid=self.admin.domainid) # Cleanup created project at end of test self.cleanup.append(self.project) self.cleanup.append(self.admin) self.cleanup.append(self.domain) self.debug("Created project with domain admin with name: %s" % self.project.name) projects = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertEqual(isinstance(projects, list), True, "Check for a valid list projects response") project = projects[0] self.assertEqual(project.name, self.project.name, "Check project name from list response") return
def test_03_project_counts_delete_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Destroy VM of an accounts added to the project to a new host # 4. Resource count should list properly. project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response" ) resource_count = project_list[0].cputotal expected_resource_count = int(self.services["service_offering"]["cpunumber"]) self.assertEqual(resource_count, expected_resource_count, "Resource count should match with the expected resource count") self.debug("Destroying instance: %s" % self.vm.name) try: self.vm.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response" ) resource_count_after_delete = project_list[0].cputotal self.assertEqual(resource_count_after_delete, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU return
def test_01_project_vmlifecycle_start_stop_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Stop VM of an accounts added to the project to a new host # 4. Resource count should list properly # 5. Start VM of an accounts added to the project to a new host # 6. Resource count should list properly self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].memorytotal self.debug(resource_count) self.debug("Stopping instance: %s" % self.vm.name) try: self.vm.stop(self.apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_stop = project_list[0].memorytotal self.assertEqual( resource_count, resource_count_after_stop, "Resource count should be same after stopping the instance") self.debug("Starting instance: %s" % self.vm.name) try: self.vm.start(self.apiclient) except Exception as e: self.fail("Failed to start instance: %s" % e) self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_start = project_list[0].memorytotal self.assertEqual( resource_count, resource_count_after_start, "Resource count should be same after starting the instance") return
def setupProjectAccounts(self): self.debug("Creating a domain under: %s" % self.domain.name) 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) # Create project as a domain admin self.project = Project.create(self.apiclient, self.services["project"], account=self.admin.name, domainid=self.admin.domainid) # Cleanup created project at end of test self.cleanup.append(self.project) self.cleanup.append(self.admin) self.cleanup.append(self.domain) self.debug("Created project with domain admin with name: %s" % self.project.name) projects = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertEqual(isinstance(projects, list), True, "Check for a valid list projects response") project = projects[0] self.assertEqual(project.name, self.project.name, "Check project name from list response") return
def test_02_project_vmlifecycle_migrate_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Migrate VM of an accounts added to the project to a new host # 4. Resource count should list properly. self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].memorytotal self.debug(resource_count) host = findSuitableHostForMigration(self.apiclient, self.vm.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name)) try: self.vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_migrate = project_list[0].memorytotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same after migrating the instance" ) return
def test_01_project_counts_start_stop_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Stop VM of an accounts added to the project. # 4. Resource count should list properly. project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].cputotal expected_resource_count = int( self.services["service_offering"]["cpunumber"]) self.assertEqual( resource_count, expected_resource_count, "Resource count should match with the expected resource count") self.debug("Stopping instance: %s" % self.vm.name) try: self.vm.stop(self.apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_stop = project_list[0].cputotal self.assertEqual( resource_count, resource_count_after_stop, "Resource count should be same after stopping the instance") self.debug("Starting instance: %s" % self.vm.name) try: self.vm.start(self.apiclient) except Exception as e: self.fail("Failed to start instance: %s" % e) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_start = project_list[0].cputotal self.assertEqual( resource_count, resource_count_after_start, "Resource count should be same after starting the instance") return
def test_01_project_vmlifecycle_start_stop_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Stop VM of an accounts added to the project to a new host # 4. Resource count should list properly # 5. Start VM of an accounts added to the project to a new host # 6. Resource count should list properly self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response" ) resource_count = project_list[0].memorytotal self.debug(resource_count) self.debug("Stopping instance: %s" % self.vm.name) try: self.vm.stop(self.apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response" ) resource_count_after_stop = project_list[0].memorytotal self.assertEqual(resource_count, resource_count_after_stop, "Resource count should be same after stopping the instance") self.debug("Starting instance: %s" % self.vm.name) try: self.vm.start(self.apiclient) except Exception as e: self.fail("Failed to start instance: %s" % e) self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response" ) resource_count_after_start = project_list[0].memorytotal self.assertEqual(resource_count, resource_count_after_start, "Resource count should be same after starting the instance") return
def test_01_project_counts_start_stop_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Stop VM of an accounts added to the project. # 4. Resource count should list properly. project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response" ) resource_count = project_list[0].cputotal expected_resource_count = int(self.services["service_offering"]["cpunumber"]) self.assertEqual(resource_count, expected_resource_count, "Resource count should match with the expected resource count") self.debug("Stopping instance: %s" % self.vm.name) try: self.vm.stop(self.apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response" ) resource_count_after_stop = project_list[0].cputotal self.assertEqual(resource_count, resource_count_after_stop, "Resource count should be same after stopping the instance") self.debug("Starting instance: %s" % self.vm.name) try: self.vm.start(self.apiclient) except Exception as e: self.fail("Failed to start instance: %s" % e) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response" ) resource_count_after_start = project_list[0].cputotal self.assertEqual(resource_count, resource_count_after_start, "Resource count should be same after starting the instance") return
def create_domain_account_user(parentDomain=None): domain = Domain.create(cls.api_client, cls.services["domain"], parentdomainid=parentDomain.id if parentDomain else None) cls._cleanup.append(domain) # Create an Account associated with domain account = Account.create(cls.api_client, cls.services["account"], domainid=domain.id) cls._cleanup.append(account) # Create an User, Project, Volume associated with account user = User.create(cls.api_client, cls.services["user"], account=account.name, domainid=account.domainid) cls._cleanup.append(user) project = Project.create(cls.api_client, cls.services["project"], account=account.name, domainid=account.domainid) cls._cleanup.append(project) volume = Volume.create(cls.api_client, cls.services["volume"], zoneid=cls.zone.id, account=account.name, domainid=account.domainid, diskofferingid=cls.disk_offering.id) cls._cleanup.append(volume) return {'domain':domain, 'account':account, 'user':user, 'project':project, 'volume':volume}
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 test_02_project_counts_migrate_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Migrate VM of an accounts added to the project to a new host # 4. Resource count should list properly. project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].cputotal expected_resource_count = int( self.services["service_offering"]["cpunumber"]) self.assertEqual( resource_count, expected_resource_count, "Resource count should match with the expected resource count") host = find_suitable_host(self.apiclient, self.vm) self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name)) try: self.vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_migrate = project_list[0].cputotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same after migrating the instance") return
def test_02_project_vmlifecycle_migrate_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Migrate VM of an accounts added to the project to a new host # 4. Resource count should list properly. self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].memorytotal self.debug(resource_count) host = find_suitable_host(self.apiclient, self.vm) self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name)) try: self.vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_migrate = project_list[0].memorytotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same after migrating the instance") return
def test_03_project_vmlifecycle_delete_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Destroy VM of an accounts added to the project # 4. Resource count should list as 0 after destroying the instance self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].memorytotal self.debug(resource_count) self.debug("Destroying instance: %s" % self.vm.name) try: self.vm.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) # Wait for expunge interval to cleanup Memory wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"]) self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_delete = project_list[0].memorytotal self.assertEqual(resource_count_after_delete, 0, "Resource count for %s should be 0" % get_resource_type(resource_id=9)) #RAM return
def test_03_project_counts_delete_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Destroy VM of an accounts added to the project to a new host # 4. Resource count should list properly. project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].cputotal expected_resource_count = int( self.services["service_offering"]["cpunumber"]) self.assertEqual( resource_count, expected_resource_count, "Resource count should match with the expected resource count") self.debug("Destroying instance: %s" % self.vm.name) try: self.vm.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count_after_delete = project_list[0].cputotal self.assertEqual(resource_count_after_delete, 0, "Resource count for %s should be 0" % get_resource_type(resource_id=8)) #CPU return
def create_domain_account_user(parentDomain=None): domain = Domain.create( cls.api_client, cls.services["domain"], parentdomainid=parentDomain.id if parentDomain else None) cls._cleanup.append(domain) # Create an Account associated with domain account = Account.create(cls.api_client, cls.services["account"], domainid=domain.id) cls._cleanup.append(account) # Create an User, Project, Volume associated with account user = User.create(cls.api_client, cls.services["user"], account=account.name, domainid=account.domainid) cls._cleanup.append(user) project = Project.create(cls.api_client, cls.services["project"], account=account.name, domainid=account.domainid) cls._cleanup.append(project) volume = Volume.create(cls.api_client, cls.services["volume"], zoneid=cls.zone.id, account=account.name, domainid=account.domainid, diskofferingid=cls.disk_offering.id) cls._cleanup.append(volume) return { 'domain': domain, 'account': account, 'user': user, 'project': project, 'volume': volume }
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