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 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_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_add_user_to_project_with_project_role(self): """ 1. Create a User Account 2. Add user of an account with 'Regular' project account role associate it with a Project role; The role defines what APIs are allowed/disallowed for the user: here, 'listPublicIpAddresses' is denied for the user account 3. Execute the 'listPublicIpAddresses' API and verify/confirm that the API isn't allowed to be executed by the user """ self.useraccount = Account.create(self.apiclient, self.testdata["account"], roleid=4) self.cleanup.append(self.useraccount) # Add account to the project self.project.addUser(self.apiclient, username=self.useraccount.user[0].username, projectroleid=self.projectrole.id) Project.listAccounts(self.apiclient, projectid=self.project.id) self.userapiclient = self.testClient.getUserApiClient( UserName=self.useraccount.name, DomainName=self.useraccount.domain, type=0) try: PublicIPAddress.list(self.userapiclient, projectid=self.project.id) self.fail( "API call succeeded which is denied for the project role") except CloudstackAPIException: pass
def setupProjectAccounts(self): self.debug("Creating a domain under: %s" % self.domain.name) self.domain = Domain.create(self.apiclient, services=self.testdata["domain"], parentdomainid=self.domain.id) self.admin = Account.create( self.apiclient, self.testdata["account"], admin=True, domainid=self.domain.id ) # Create project as a domain admin self.project = Project.create(self.apiclient, self.testdata["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 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.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_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 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.testdata["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.testdata["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.testdata["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 setUpClass(cls): cls.testClient = super(TestResourceLimitsProject, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) cls.services["server"]["zoneid"] = cls.zone.id # Create Domains, Account etc cls.domain = Domain.create(cls.api_client, cls.services["domain"]) cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id) cls.userapiclient = cls.testClient.getUserApiClient(UserName=cls.account.name, DomainName=cls.account.domain) # Create project as a domain admin cls.project = Project.create( cls.api_client, cls.services["project"], account=cls.account.name, domainid=cls.account.domainid ) cls.services["account"] = cls.account.name # Create Service offering and disk offerings etc cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"]) cls.disk_offering = DiskOffering.create(cls.api_client, cls.services["disk_offering"]) cls._cleanup = [cls.project, cls.service_offering, cls.disk_offering, cls.account, cls.domain] return
def matchResourceCount(apiclient, expectedCount, resourceType, accountid=None, projectid=None): """Match the resource count of account/project with the expected resource count""" try: resourceholderlist = None if accountid: resourceholderlist = Account.list(apiclient, id=accountid) elif projectid: resourceholderlist = Project.list(apiclient, id=projectid, listall=True) validationresult = validateList(resourceholderlist) assert validationresult[0] == PASS,\ "accounts list validation failed" if resourceType == RESOURCE_PRIMARY_STORAGE: resourceCount = resourceholderlist[0].primarystoragetotal elif resourceType == RESOURCE_SECONDARY_STORAGE: resourceCount = resourceholderlist[0].secondarystoragetotal elif resourceType == RESOURCE_CPU: resourceCount = resourceholderlist[0].cputotal elif resourceType == RESOURCE_MEMORY: resourceCount = resourceholderlist[0].memorytotal assert str(resourceCount) == str(expectedCount),\ "Resource count %s should match with the expected resource count %s" %\ (resourceCount, expectedCount) except Exception as e: return [FAIL, e] return [PASS, None]
def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] response = self.setupProjectAccounts() self.assertEqual(response[0], PASS, response[1]) try: self.vm = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, projectid=self.project.id, serviceofferingid=self.service_offering.id) projects = Project.list(self.apiclient, id=self.project.id, listall=True) self.assertEqual(validateList(projects)[0], PASS,\ "projects list validation failed") self.initialResourceCount = projects[0].primarystoragetotal except Exception as e: self.tearDown() self.skipTest("Exception occured in setup: %s" % e) return
def test_01_service_offerings(self): """ Test service offerings in a project """ # Validate the following # 1. Create a project. # 2. List service offerings for the project. All SO available in the # domain can be used for project resource creation. # Create project as a domain admin project = Project.create( self.apiclient, self.services["project"], account=self.account.name, domainid=self.account.domainid ) # Cleanup created project at end of test self.cleanup.append(project) self.debug("Created project with domain admin with ID: %s" % project.id) self.debug( "Deploying VM instance for project: %s & service offering: %s" % (project.id, self.service_offering.id) ) virtual_machine = VirtualMachine.create( self.apiclient, self.services["server"], templateid=self.template.id, serviceofferingid=self.service_offering.id, projectid=project.id, ) # Verify VM state self.assertEqual(virtual_machine.state, "Running", "Check VM state is Running or not") 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): try: 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) # 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) except Exception as e: return [FAIL, e] return [PASS, None]
def setupAccounts(self): try: self.child_domain = Domain.create(self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id) self.cleanup.append(self.child_domain) self.child_do_admin = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.child_domain.id) self.cleanup.append(self.child_do_admin) self.userapiclient = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) # 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) self.cleanup.append(self.project) except Exception as e: return [FAIL, e] return [PASS, None]
def setUpClass(cls): cls.testClient = super(TestPublicIpAddress, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) cls.services["server"]["zoneid"] = cls.zone.id # Create Domains, Account etc cls.domain = Domain.create(cls.api_client, cls.services["domain"]) cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id) # Create project as a domain admin cls.project = Project.create( cls.api_client, cls.services["project"], account=cls.account.name, domainid=cls.account.domainid ) cls.services["account"] = cls.account.name # Create Service offering and disk offerings etc cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"]) cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["server"], templateid=cls.template.id, serviceofferingid=cls.service_offering.id, projectid=cls.project.id, ) cls._cleanup = [cls.project, cls.service_offering, cls.account, cls.domain] return
def setupAccounts(self): try: 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) self.userapiclient = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) # 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) except Exception as e: return [FAIL, e] return [PASS, None]
def matchResourceCount(apiclient, expectedCount, resourceType, accountid=None, projectid=None): """Match the resource count of account/project with the expected resource count""" try: resourceholderlist = None if accountid: resourceholderlist = Account.list(apiclient, id=accountid) elif projectid: resourceholderlist = Project.list(apiclient, id=projectid, listall=True) validationresult = validateList(resourceholderlist) assert validationresult[0] == PASS, "accounts list validation failed" if resourceType == RESOURCE_PRIMARY_STORAGE: resourceCount = resourceholderlist[0].primarystoragetotal elif resourceType == RESOURCE_SECONDARY_STORAGE: resourceCount = resourceholderlist[0].secondarystoragetotal elif resourceType == RESOURCE_CPU: resourceCount = resourceholderlist[0].cputotal elif resourceType == RESOURCE_MEMORY: resourceCount = resourceholderlist[0].memorytotal assert str(resourceCount) == str( expectedCount ), "Resource count %s should match with the expected resource count %s" % (resourceCount, expectedCount) except Exception as e: return [FAIL, e] return [PASS, None]
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. if self.hypervisor.lower() in ['lxc']: self.skipTest("vm migrate feature is not supported on %s" % self.hypervisor.lower()) 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_06_volumes_per_project(self): """Test Volumes limit per project """ # Validate the following # 1. set max no of volume per project to 1. # 2. Create 1 VM in this project # 4. Try to Create another VM in the project. It should give the user # an appropriate error that Volume limit is exhausted and an alert # should be generated. if self.hypervisor.lower() == 'lxc': if not find_storage_pool_type(self.apiclient, storagetype='rbd'): self.skipTest("RBD storage type is required for data volumes for LXC") self.project_1 = Project.create( self.api_client, self.services["project"], account=self.account.name, domainid=self.account.domainid ) self.cleanup.append(self.project_1) self.debug( "Updating volume resource limits for project: %s" % self.project_1.id) # Set usage_vm=1 for Account 1 update_resource_limit( self.apiclient, 2, # Volume max=1, projectid=self.project_1.id ) self.debug("Deploying VM for project: %s" % self.project_1.id) virtual_machine_1 = VirtualMachine.create( self.apiclient, self.services["server"], templateid=self.template.id, serviceofferingid=self.service_offering.id, projectid=self.project_1.id ) # Verify VM state self.assertEqual( virtual_machine_1.state, 'Running', "Check VM state is Running or not" ) # Exception should be raised for second volume with self.assertRaises(Exception): Volume.create( self.apiclient, self.services["volume"], zoneid=self.zone.id, diskofferingid=self.disk_offering.id, projectid=self.project_1.id ) return
def setUpClass(cls): cls.testClient = super(TestResourceLimitsProject, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) cls.services["server"]["zoneid"] = cls.zone.id # Create Domains, Account etc cls.domain = Domain.create( cls.api_client, cls.services["domain"] ) cls.account = Account.create( cls.api_client, cls.services["account"], domainid=cls.domain.id ) cls.userapiclient = cls.testClient.getUserApiClient( UserName=cls.account.name, DomainName=cls.account.domain) # Create project as a domain admin cls.project = Project.create( cls.api_client, cls.services["project"], account=cls.account.name, domainid=cls.account.domainid ) cls.services["account"] = cls.account.name # Create Service offering and disk offerings etc cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"] ) cls.disk_offering = DiskOffering.create( cls.api_client, cls.services["disk_offering"] ) cls._cleanup = [ cls.project, cls.service_offering, cls.disk_offering, cls.account, cls.domain ] 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. self.hypervisor = self.testClient.getHypervisorInfo() 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 = 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) 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_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. self.hypervisor = self.testClient.getHypervisorInfo() if self.hypervisor.lower() in ['lxc']: self.skipTest("vm migrate feature is not supported on %s" % self.hypervisor.lower()) 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 = 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) 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_deploy_vm_project_limit_reached(self): """Test TTry to deploy VM with admin account where account has not used the resources but @ project they are not available # Validate the following # 1. Try to deploy VM with admin account where account has not used the # resources but @ project they are not available # 2. Deploy VM should error out saying ResourceAllocationException # with "resource limit exceeds""" self.virtualMachine = VirtualMachine.create( self.api_client, self.services["virtual_machine"], projectid=self.project.id, serviceofferingid=self.service_offering.id) try: projects = Project.list(self.apiclient, id=self.project.id, listall=True) except Exception as e: self.fail("failed to get projects list: %s" % e) self.assertEqual( validateList(projects)[0], PASS, "projects list validation failed") self.initialResourceCount = int(projects[0].primarystoragetotal) projectLimit = self.initialResourceCount + 3 self.debug("Setting up account and domain hierarchy") response = self.updatePrimaryStorageLimits(projectLimit=projectLimit) self.assertEqual(response[0], PASS, response[1]) self.services["volume"]["size"] = self.services["disk_offering"][ "disksize"] = 2 try: disk_offering = DiskOffering.create( self.apiclient, services=self.services["disk_offering"]) self.cleanup.append(disk_offering) Volume.create(self.apiclient, self.services["volume"], zoneid=self.zone.id, projectid=self.project.id, diskofferingid=disk_offering.id) except Exception as e: self.fail("Exception occurred: %s" % e) with self.assertRaises(Exception): Volume.create(self.apiclient, self.services["volume"], zoneid=self.zone.id, projectid=self.project.id, diskofferingid=disk_offering.id) return
def test_maxAccountNetworks(self): """Test Limit number of guest account specific networks """ # Steps for validation # 1. Fetch max.account.networks from configurations # 2. Create an account. Create account more that max.accout.network # 3. Create network should fail self.debug("Creating project with '%s' as admin" % self.account.name) # Create project as a domain admin project = Project.create(self.apiclient, self.services["project"], account=self.account.name, domainid=self.account.domainid) # Cleanup created project at end of test self.cleanup.append(project) self.debug("Created project with domain admin with ID: %s" % project.id) config = Configurations.list(self.apiclient, name='max.project.networks', listall=True) self.assertEqual( isinstance(config, list), True, "List configurations hsould have max.project.networks") config_value = int(config[0].value) self.debug("max.project.networks: %s" % config_value) for ctr in range(config_value): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % self.network_offering.id) network = Network.create( self.apiclient, self.services["network"], projectid=project.id, networkofferingid=self.network_offering.id, zoneid=self.zone.id) self.cleanup.append(network) self.debug("Created network with ID: %s" % network.id) self.debug("Creating network in account already having networks : %s" % config_value) with self.assertRaises(Exception): network = Network.create( self.apiclient, self.services["network"], projectid=project.id, networkofferingid=self.network_offering.id, zoneid=self.zone.id) self.cleanup.append(network) self.debug('Create network failed (as expected)') 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_deploy_vm_project_limit_reached(self): """Test TTry to deploy VM with admin account where account has not used the resources but @ project they are not available # Validate the following # 1. Try to deploy VM with admin account where account has not used the # resources but @ project they are not available # 2. Deploy VM should error out saying ResourceAllocationException # with "resource limit exceeds""" self.virtualMachine = VirtualMachine.create(self.api_client, self.services["virtual_machine"], projectid=self.project.id, diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id) try: projects = Project.list(self.apiclient, id=self.project.id, listall=True) except Exception as e: self.fail("failed to get projects list: %s" % e) self.assertEqual(validateList(projects)[0], PASS, "projects list validation failed") self.initialResourceCount = int(projects[0].primarystoragetotal) projectLimit = self.initialResourceCount + 3 self.debug("Setting up account and domain hierarchy") response = self.updatePrimaryStorageLimits(projectLimit=projectLimit) self.assertEqual(response[0], PASS, response[1]) self.services["volume"]["size"] = self.services["disk_offering"]["disksize"] = 2 try: disk_offering = DiskOffering.create(self.apiclient, services=self.services["disk_offering"]) self.cleanup.append(disk_offering) Volume.create(self.apiclient, self.services["volume"], zoneid=self.zone.id, projectid=self.project.id, diskofferingid=disk_offering.id) except Exception as e: self.fail("Exception occured: %s" % e) with self.assertRaises(Exception): Volume.create(self.apiclient, self.services["volume"], zoneid=self.zone.id, projectid=self.project.id, diskofferingid=disk_offering.id) return
def test_02_project_disk_offerings(self): """ Test project disk offerings """ # Validate the following # 1. Create a project. # 2. List service offerings for the project. All disk offerings # available in the domain can be used for project resource creation # Create project as a domain admin project = Project.create( self.apiclient, self.services["project"], account=self.account.name, domainid=self.account.domainid ) # Cleanup created project at end of test self.cleanup.append(project) self.debug("Created project with domain admin with ID: %s" % project.id) list_projects_reponse = Project.list(self.apiclient, id=project.id, listall=True) self.assertEqual(isinstance(list_projects_reponse, list), True, "Check for a valid list projects response") list_project = list_projects_reponse[0] self.assertNotEqual(len(list_projects_reponse), 0, "Check list project response returns a valid project") self.assertEqual(project.name, list_project.name, "Check project name from list response") self.debug("Create a data volume for project: %s" % project.id) # Create a volume for project volume = Volume.create( self.apiclient, self.services["volume"], zoneid=self.zone.id, diskofferingid=self.disk_offering.id, projectid=project.id, ) self.cleanup.append(volume) # Verify Volume state self.assertEqual(volume.state in ["Allocated", "Ready"], True, "Check Volume state is Ready or not") return
def test_maxAccountNetworks(self): """Test Limit number of guest account specific networks """ # Steps for validation # 1. Fetch max.account.networks from configurations # 2. Create an account. Create account more that max.accout.network # 3. Create network should fail self.debug("Creating project with '%s' as admin" % self.account.name) # Create project as a domain admin project = Project.create( self.apiclient, self.services["project"], account=self.account.name, domainid=self.account.domainid ) # Cleanup created project at end of test self.cleanup.append(project) self.debug("Created project with domain admin with ID: %s" % project.id) config = Configurations.list(self.apiclient, name="max.project.networks", listall=True) self.assertEqual(isinstance(config, list), True, "List configurations hsould have max.project.networks") config_value = int(config[0].value) self.debug("max.project.networks: %s" % config_value) for ctr in range(config_value): # Creating network using the network offering created self.debug("Creating network with network offering: %s" % self.network_offering.id) network = Network.create( self.apiclient, self.services["network"], projectid=project.id, networkofferingid=self.network_offering.id, zoneid=self.zone.id, ) self.debug("Created network with ID: %s" % network.id) self.debug("Creating network in account already having networks : %s" % config_value) with self.assertRaises(Exception): Network.create( self.apiclient, self.services["network"], projectid=project.id, networkofferingid=self.network_offering.id, zoneid=self.zone.id, ) self.debug("Create network failed (as expected)") return
def test_03_deploy_vm_project_limit_reached(self): """Test TTry to deploy VM with admin account where account has not used the resources but @ project they are not available # Validate the following # 1. Try to register template with admin account where account has not used the # resources but @ project they are not available # 2. Template registration should error out saying ResourceAllocationException # with "resource limit exceeds""" response = self.setupAccounts() self.assertEqual(response[0], PASS, response[1]) response = self.registerTemplate(inProject=True) self.assertEqual(response[0], PASS, response[1]) try: projects = Project.list(self.userapiclient, id=self.project.id, listall=True) except Exception as e: self.fail("failed to get projects list: %s" % e) self.assertEqual( validateList(projects)[0], PASS, "projects list validation failed") self.assertEqual( self.templateSize, projects[0].secondarystoragetotal, "Resource count %s\ not matching with the expcted count: %s" % (projects[0].secondarystoragetotal, self.templateSize)) projectLimit = self.templateSize response = self.updateSecondaryStorageLimits(projectLimit=projectLimit) self.assertEqual(response[0], PASS, response[1]) with self.assertRaises(Exception): template = Template.register(self.userapiclient, self.services["template_2"], zoneid=self.zone.id, projectid=self.project.id) template.delete(self.userapiclient) return
def setupProjectAccounts(self): try: 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) except Exception as e: return [FAIL, e] return [PASS, None]
def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] response = self.setupProjectAccounts() self.assertEqual(response[0], PASS, response[1]) try: self.vm = VirtualMachine.create( self.apiclient,self.services["virtual_machine"], templateid=self.template.id,projectid=self.project.id, serviceofferingid=self.service_offering.id) projects = Project.list(self.apiclient,id=self.project.id, listall=True) self.assertEqual(validateList(projects)[0], PASS,\ "projects list validation failed") self.initialResourceCount = projects[0].primarystoragetotal except Exception as e: self.tearDown() self.skipTest("Exception occured in setup: %s" % e) return
def test_03_deploy_vm_project_limit_reached(self): """Test TTry to deploy VM with admin account where account has not used the resources but @ project they are not available # Validate the following # 1. Try to register template with admin account where account has not used the # resources but @ project they are not available # 2. Template registration should error out saying ResourceAllocationException # with "resource limit exceeds""" response = self.setupAccounts() self.assertEqual(response[0], PASS, response[1]) response = self.registerTemplate(inProject=True) self.assertEqual(response[0], PASS, response[1]) try: projects = Project.list(self.userapiclient, id=self.project.id, listall=True) except Exception as e: self.fail("failed to get projects list: %s" % e) self.assertEqual(validateList(projects)[0], PASS, "projects list validation failed") self.assertEqual(self.templateSize, projects[0].secondarystoragetotal, "Resource count %s\ not matching with the expcted count: %s" % (projects[0].secondarystoragetotal, self.templateSize)) projectLimit = self.templateSize response = self.updateSecondaryStorageLimits(projectLimit=projectLimit) self.assertEqual(response[0], PASS, response[1]) with self.assertRaises(Exception): template = Template.register(self.userapiclient, self.services["template_2"], zoneid=self.zone.id, projectid=self.project.id) template.delete(self.userapiclient) return
def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.testdata = TestData().testdata feature_enabled = self.apiclient.listCapabilities( listCapabilities.listCapabilitiesCmd()).dynamicrolesenabled if not feature_enabled: self.skipTest( "Dynamic Role-Based API checker not enabled, skipping test") self.testdata["projectrole"]["name"] += self.getRandomString() self.project = Project.create(self.apiclient, self.testdata["project"]) self.projectrole = ProjectRole.create(self.apiclient, self.testdata["projectrole"], self.project.id) self.testdata["projectrolepermission"][ "projectroleid"] = self.projectrole.id self.projectrolepermission = ProjectRolePermission.create( self.apiclient, self.testdata["projectrolepermission"], self.project.id) self.cleanup = [self.project]
def setUpClass(cls): cls.testClient = super(TestSecurityGroup, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.domain = get_domain(cls.api_client) cls.services["mode"] = cls.zone.networktype template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) cls.services["domainid"] = cls.domain.id cls.services["server"]["zoneid"] = cls.zone.id cls.services["server"]["template"] = template.id cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"]) cls.account = Account.create(cls.api_client, cls.services["account"], admin=True, domainid=cls.domain.id) # Create project as a domain admin cls.project = Project.create( cls.api_client, cls.services["project"], account=cls.account.name, domainid=cls.account.domainid ) cls.services["account"] = cls.account.name cls._cleanup = [cls.project, cls.account, cls.service_offering] return
def test_01_project_limits(self): """ Test project limits for domain admin """ # Validate the following # 1. Create a Project. Verify once projects are created, they inherit # a default set of resource limits as configured by the Cloud Stack # ROOT admin. # 2. Reduce Project resources limits. Verify limits can be reduced by # the Project Owner of each project and project limit applies to # number of virtual instances, disk volumes, snapshots, IP address. # Also, verify resource limits for the project are independent of # account resource limits # 3. Increase Projects Resources limits above domains limit. Verify # project can't have more resources than domain level limit allows. # 4. Create Resource more than its set limit for the parent domain. # Verify resource allocation should fail giving proper message # Create project as a domain admin 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(project) self.debug("Created project with domain admin with ID: %s" % project.id) list_projects_reponse = Project.list( self.apiclient, id=project.id, listall=True ) self.assertEqual( isinstance(list_projects_reponse, list), True, "Check for a valid list projects response" ) list_project = list_projects_reponse[0] self.assertNotEqual( len(list_projects_reponse), 0, "Check list project response returns a valid project" ) self.assertEqual( project.name, list_project.name, "Check project name from list response" ) # Get the resource limits for ROOT domain resource_limits = list_resource_limits(self.apiclient) self.assertEqual( isinstance(resource_limits, list), True, "List resource API should return a valid list" ) self.assertNotEqual( len(resource_limits), 0, "List resource API response should not be empty" ) # Reduce resource limits for project # Resource: 0 - Instance. Number of instances a user can create. # Resource: 1 - IP. Number of public IP addresses a user can own. # Resource: 2 - Volume. Number of disk volumes a user can create. # Resource: 3 - Snapshot. Number of snapshots a user can create. # Resource: 4 - Template. Number of templates that a user can # register/create for resource in resource_limits: update_resource_limit( self.apiclient, resource.resourcetype, max=1, projectid=project.id ) self.debug( "Updating resource (ID: %s) limit for project: %s" % ( resource, project.id )) resource_limits = list_resource_limits( self.apiclient, projectid=project.id ) self.assertEqual( isinstance(resource_limits, list), True, "List resource API should return a valid list" ) self.assertNotEqual( len(resource_limits), 0, "List resource API response should not be empty" ) for resource in resource_limits: self.assertEqual( resource.max, 1, "Resource limit should be updated to 1" ) # Get the resource limits for domain resource_limits = list_resource_limits( self.apiclient, domainid=self.domain.id ) self.assertEqual( isinstance(resource_limits, list), True, "List resource API should return a valid list" ) self.assertNotEqual( len(resource_limits), 0, "List resource API response should not be empty" ) for resource in resource_limits: # Update domain resource limits to 2 update_resource_limit( self.apiclient, resource.resourcetype, domainid=self.domain.id, max=1 ) max_value = 2 self.debug( "Attempting to update project: %s resource limit to: %s" % ( project.id, max_value )) # Update project resource limits to 3 update_resource_limit( self.apiclient, resource.resourcetype, max=max_value, projectid=project.id ) # Verify project can't have more resources then limit set for domain by adding volumes. volume = Volume.create( self.apiclient, self.services["volume"], zoneid=self.zone.id, diskofferingid=self.disk_offering.id, projectid=project.id ) # Exception should be raised for second volume with self.assertRaises(Exception): Volume.create( self.apiclient, self.services["volume"], zoneid=self.zone.id, diskofferingid=self.disk_offering.id, projectid=project.id ) volume.delete(self.apiclient); return
def setUpClass(cls): cls.testClient = super(TestNetworkPermissions, cls).getClsTestClient() cls.apiclient = cls.testClient.getApiClient() cls.services = cls.testClient.getParsedTestDataConfig() zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.zone = Zone(zone.__dict__) cls.template = get_template(cls.apiclient, cls.zone.id) cls._cleanup = [] cls.logger = logging.getLogger("TestNetworkPermissions") cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) cls.domain = get_domain(cls.apiclient) # Create small service offering cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"]) cls._cleanup.append(cls.service_offering) # Create network offering for isolated networks cls.network_offering_isolated = NetworkOffering.create( cls.apiclient, cls.services["isolated_network_offering"]) cls.network_offering_isolated.update(cls.apiclient, state='Enabled') cls._cleanup.append(cls.network_offering_isolated) # Create sub-domain cls.sub_domain = Domain.create(cls.apiclient, cls.services["acl"]["domain1"]) cls._cleanup.append(cls.sub_domain) # Create domain admin and normal user cls.domain_admin = Account.create(cls.apiclient, cls.services["acl"]["accountD1A"], admin=True, domainid=cls.sub_domain.id) cls._cleanup.append(cls.domain_admin) cls.network_owner = Account.create(cls.apiclient, cls.services["acl"]["accountD11A"], domainid=cls.sub_domain.id) cls._cleanup.append(cls.network_owner) cls.other_user = Account.create(cls.apiclient, cls.services["acl"]["accountD11B"], domainid=cls.sub_domain.id) cls._cleanup.append(cls.other_user) # Create project cls.project = Project.create(cls.apiclient, cls.services["project"], account=cls.domain_admin.name, domainid=cls.domain_admin.domainid) cls._cleanup.append(cls.project) # Create api clients for domain admin and normal user cls.domainadmin_user = cls.domain_admin.user[0] cls.domainadmin_apiclient = cls.testClient.getUserApiClient( cls.domainadmin_user.username, cls.sub_domain.name) cls.networkowner_user = cls.network_owner.user[0] cls.user_apiclient = cls.testClient.getUserApiClient( cls.networkowner_user.username, cls.sub_domain.name) cls.otheruser_user = cls.other_user.user[0] cls.otheruser_apiclient = cls.testClient.getUserApiClient( cls.otheruser_user.username, cls.sub_domain.name) # Create networks for domain admin, normal user and project cls.services["network"]["name"] = "Test Network Isolated - Project" cls.project_network = Network.create( cls.apiclient, cls.services["network"], networkofferingid=cls.network_offering_isolated.id, domainid=cls.sub_domain.id, projectid=cls.project.id, zoneid=cls.zone.id) cls._cleanup.append(cls.project_network) cls.services["network"][ "name"] = "Test Network Isolated - Domain admin" cls.domainadmin_network = Network.create( cls.apiclient, cls.services["network"], networkofferingid=cls.network_offering_isolated.id, domainid=cls.sub_domain.id, accountid=cls.domain_admin.name, zoneid=cls.zone.id) cls._cleanup.append(cls.domainadmin_network) cls.services["network"]["name"] = "Test Network Isolated - Normal user" cls.user_network = Network.create( cls.apiclient, cls.services["network"], networkofferingid=cls.network_offering_isolated.id, domainid=cls.sub_domain.id, accountid=cls.network_owner.name, zoneid=cls.zone.id) cls._cleanup.append(cls.user_network)
def setUpClass(cls): cls.testClient = super(TestDeployVMAffinityGroups, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services #Get Zone, Domain and templates cls.rootdomain = get_domain(cls.api_client) cls.domain = Domain.create(cls.api_client, cls.services["domain"]) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["template"] = cls.template.id cls.services["zoneid"] = cls.zone.id cls._cleanup = [] cls.domain_admin_account = Account.create( cls.api_client, cls.services["domain_admin_account"], domainid=cls.domain.id, admin=True) cls._cleanup.append(cls.domain_admin_account) cls.domain_api_client = cls.testClient.getUserApiClient( cls.domain_admin_account.name, cls.domain.name, 2) cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id) cls._cleanup.append(cls.account) cls.account_api_client = cls.testClient.getUserApiClient( cls.account.name, cls.domain.name, 0) cls.account_not_in_project = Account.create( cls.api_client, cls.services["account_not_in_project"], domainid=cls.domain.id) cls._cleanup.append(cls.account_not_in_project) cls.account_not_in_project_api_client = cls.testClient.getUserApiClient( cls.account_not_in_project.name, cls.domain.name, 0) cls._proj_toclean = [] cls.project = Project.create( cls.api_client, cls.services["project"], account=cls.domain_admin_account.name, domainid=cls.domain_admin_account.domainid) cls._proj_toclean.append(cls.project) cls.project2 = Project.create( cls.api_client, cls.services["project2"], account=cls.domain_admin_account.name, domainid=cls.domain_admin_account.domainid) cls._proj_toclean.append(cls.project2) cls.debug("Created project with ID: %s" % cls.project.id) cls.debug("Created project2 with ID: %s" % cls.project2.id) # Add user to the project cls.project.addAccount(cls.api_client, cls.account.name) cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"], domainid=cls.account.domainid) return
def test_03_network_create(self): """ Test create network in project """ # Validate the following # 1. Create a project. # 2. Add virtual/direct network resource to the project. User shared # network resource for the project # 3. Verify any number of Project level Virtual/Direct networks can be # created and used for vm deployment within the project. # 4. Verify shared networks (zone and domain wide) from outside the # project can also be used in a project. # Create project as a domain admin project = Project.create( self.apiclient, self.services["project"], account=self.account.name, domainid=self.account.domainid ) # Cleanup created project at end of test self.cleanup.append(project) self.debug("Created project with domain admin with ID: %s" % project.id) network_offerings = list_network_offerings( self.apiclient, projectid=project.id, supportedServices="SourceNat", type="isolated", state="Enabled" ) self.assertEqual(isinstance(network_offerings, list), True, "Check for the valid network offerings") network_offering = network_offerings[0] self.debug("creating a network with network offering ID: %s" % network_offering.id) self.services["network"]["zoneid"] = self.zone.id network = Network.create( self.apiclient, self.services["network"], networkofferingid=network_offering.id, projectid=project.id ) self.debug("Created network with ID: %s" % network.id) networks = Network.list(self.apiclient, projectid=project.id, listall=True) self.assertEqual(isinstance(networks, list), True, "Check for the valid network list response") self.debug("Deploying VM with network: %s" % network.id) virtual_machine = VirtualMachine.create( self.apiclient, self.services["server"], templateid=self.template.id, networkids=[str(network.id)], serviceofferingid=self.service_offering.id, projectid=project.id, ) self.debug("Deployed VM with ID: %s" % virtual_machine.id) # Verify VM state self.assertEqual(virtual_machine.state, "Running", "Check VM state is Running or not") network_offerings = list_network_offerings( self.apiclient, state="Enabled", guestiptype="Shared", name="DefaultSharedNetworkOffering", displaytext="Offering for Shared networks", ) self.assertEqual(isinstance(network_offerings, list), True, "Check for the valid network offerings") network_offering = network_offerings[0] self.debug("creating a shared network in domain: %s" % self.domain.id) # Getting physical network and free vlan in it physical_network, vlan = get_free_vlan(self.apiclient, self.zone.id) self.services["domain_network"]["vlan"] = vlan self.services["domain_network"]["physicalnetworkid"] = physical_network.id # Generating random subnet number for shared network creation shared_network_subnet_number = random.randrange(1, 254) self.services["domain_network"]["gateway"] = "172.16." + str(shared_network_subnet_number) + ".1" self.services["domain_network"]["startip"] = "172.16." + str(shared_network_subnet_number) + ".2" self.services["domain_network"]["endip"] = "172.16." + str(shared_network_subnet_number) + ".20" domain_network = Network.create( self.apiclient, self.services["domain_network"], domainid=self.domain.id, networkofferingid=network_offering.id, zoneid=self.zone.id, ) self.cleanup.append(domain_network) self.debug("Created network with ID: %s" % domain_network.id) virtual_machine = VirtualMachine.create( self.apiclient, self.services["server"], templateid=self.template.id, networkids=[str(domain_network.id)], serviceofferingid=self.service_offering.id, projectid=project.id, ) self.debug("Deployed VM with ID: %s" % virtual_machine.id) # Verify VM state self.assertEqual(virtual_machine.state, "Running", "Check VM state is Running or not") # Delete VM before network gets deleted in cleanup virtual_machine.delete(self.apiclient, expunge=True) return
def test_add_multiple_admins_in_project(self): """ 1. Create a User Account 2. Add user account with 'Admin' project account role and associate it with a Project role; The role defines what APIs are allowed/disallowed for the user: here, 'listPublicIpAddresses' is denied for the user account 3. Execute the 'listPublicIpAddresses' API and verify/confirm that the user/account can execute the API as it is a project admin """ self.useraccount = Account.create(self.apiclient, self.testdata["account"], roleid=4) self.cleanup.append(self.useraccount) self.useraccount1 = Account.create(self.apiclient, self.testdata["useracc"], roleid=4) self.cleanup.append(self.useraccount1) self.project.addAccount(self.apiclient, account=self.useraccount.name, projectroleid=self.projectrole.id, roletype='Admin') self.project.addAccount(self.apiclient, account=self.useraccount1.name, projectroleid=self.projectrole.id) project_accounts = Project.listAccounts(self.apiclient, projectid=self.project.id, role='Admin') self.assertEqual(len(project_accounts), 2, "account not added with admin Role") self.userapiclientAdminRole = self.testClient.getUserApiClient( UserName=self.useraccount.name, DomainName=self.useraccount.domain, type=0) self.userapiclientRegularRole = self.testClient.getUserApiClient( UserName=self.useraccount1.name, DomainName=self.useraccount1.domain, type=0) try: PublicIPAddress.list(self.userapiclientAdminRole, projectid=self.project.id) self.debug( "User added to the project could execute the listPublicIpAddresses API despite the project " "role as it is the Admin") pass except CloudstackAPIException: self.fail( "User is an Admin, should be able to execute the command despite Project role" ) try: self.project.suspend(self.userapiclientAdminRole, ) self.debug( "The user can perform Project administrative operations as it is added as " "an Admin to the project") pass except CloudstackAPIException: self.fail( "User should be allowed to execute project administrative operations" "as it is the Project Admin") try: self.project.suspend(self.userapiclientRegularRole, ) except Exception as e: pass
def test_01_create_list_domain_account_project(self): """ Verify list domain, account and project return expected response """ # Validate the following # 1. Create domain # 2. list domain, 'cpulimit' should be included in response # 3. list domain with details=min, 'cpulimit' should not be included in response. # 4. create account in the domain # 5. list account, 'cpulimit' should be included in response # 6. list account with details=min, 'cpulimit' should not be included in response. # 7. create project in the domain # 8. list project, 'cpulimit' should be included in response # 9. list project with details=min, 'cpulimit' should not be included in response. # Create new domain self.user_domain = Domain.create(self.apiclient, self.services["domain"], parentdomainid=self.domain.id) list_domain_response = Domain.list(self.apiclient, id=self.user_domain.id) self.assertEqual(isinstance(list_domain_response, list), True, "Check list response returns a valid list") self.assertIsNotNone(list_domain_response[0].cpulimit, "'cpulimit' should be included in response") list_domain_response = Domain.list(self.apiclient, details="min", id=self.user_domain.id) self.assertEqual(isinstance(list_domain_response, list), True, "Check list response returns a valid list") self.assertIsNone(list_domain_response[0].cpulimit, "'cpulimit' should not be included in response") # Create account self.account = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.user_domain.id) list_account_response = Account.list(self.apiclient, id=self.account.id) self.assertEqual(isinstance(list_account_response, list), True, "Check list response returns a valid list") self.assertIsNotNone(list_account_response[0].cpulimit, "'cpulimit' should be included in response") list_account_response = Account.list(self.apiclient, details="min", id=self.account.id) self.assertEqual(isinstance(list_account_response, list), True, "Check list response returns a valid list") self.assertIsNone(list_account_response[0].cpulimit, "'cpulimit' should not be included in response") # Create project self.project = Project.create(self.apiclient, self.services["project"], account=self.account.name, domainid=self.account.domainid) list_project_response = Project.list(self.apiclient, listall="true", id=self.project.id) self.assertEqual(isinstance(list_project_response, list), True, "Check list response returns a valid list") self.assertIsNotNone(list_project_response[0].cpulimit, "'cpulimit' should be included in response") list_project_response = Project.list(self.apiclient, details="min", listall="true", id=self.project.id) self.assertEqual(isinstance(list_project_response, list), True, "Check list response returns a valid list") self.assertIsNone(list_project_response[0].cpulimit, "'cpulimit' should not be included in response") self.cleanup.append(self.project) self.cleanup.append(self.account) self.cleanup.append(self.user_domain)
def setUpClass(cls): cls.testClient = super(TestUserPrivateGateways, cls).getClsTestClient() cls.apiclient = cls.testClient.getApiClient() cls.apiclient = cls.testClient.getApiClient() cls.services = cls.testClient.getParsedTestDataConfig() zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.zone = Zone(zone.__dict__) cls.template = get_template(cls.apiclient, cls.zone.id) cls._cleanup = [] cls.logger = logging.getLogger("TestUserPrivateGateways") cls.stream_handler = logging.StreamHandler() cls.logger.setLevel(logging.DEBUG) cls.logger.addHandler(cls.stream_handler) cls.domain = get_domain(cls.apiclient) # Create small service offering cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"]) cls._cleanup.append(cls.service_offering) # Create network offering for isolated networks cls.network_offering_isolated = NetworkOffering.create( cls.apiclient, cls.services["network_offering"]) cls.network_offering_isolated.update(cls.apiclient, state='Enabled') cls._cleanup.append(cls.network_offering_isolated) # Create vpc offering cls.vpc_offering = VpcOffering.create( cls.apiclient, cls.services["vpc_offering_multi_lb"]) cls.vpc_offering.update(cls.apiclient, state='Enabled') cls._cleanup.append(cls.vpc_offering) # Create network offering for vpc tiers cls.network_offering_vpc = NetworkOffering.create( cls.apiclient, cls.services["nw_offering_isolated_vpc"], conservemode=False) cls.network_offering_vpc.update(cls.apiclient, state='Enabled') cls._cleanup.append(cls.network_offering_vpc) # Create sub-domain cls.sub_domain = Domain.create(cls.apiclient, cls.services["acl"]["domain1"]) cls._cleanup.append(cls.sub_domain) # Create domain admin and normal user cls.domain_admin = Account.create(cls.apiclient, cls.services["acl"]["accountD1A"], admin=True, domainid=cls.sub_domain.id) cls._cleanup.append(cls.domain_admin) cls.normal_user = Account.create(cls.apiclient, cls.services["acl"]["accountD1B"], domainid=cls.sub_domain.id) cls._cleanup.append(cls.normal_user) # Create project cls.project = Project.create(cls.apiclient, cls.services["project"], account=cls.domain_admin.name, domainid=cls.domain_admin.domainid) cls._cleanup.append(cls.project) # Create api clients for domain admin and normal user cls.domainadmin_user = cls.domain_admin.user[0] cls.domainapiclient = cls.testClient.getUserApiClient( cls.domainadmin_user.username, cls.sub_domain.name) cls.normaluser_user = cls.normal_user.user[0] cls.normaluser_apiclient = cls.testClient.getUserApiClient( cls.normaluser_user.username, cls.sub_domain.name)
def test_02_project_limits_normal_user(self): """ Test project limits for normal user """ # Validate the following # 1. Create a Project # 2. Reduce the projects limits as a domain admin. Verify resource # count is updated # 3. Reduce the projects limits as a project user owner who is not a # domain admin. Resource count should fail # Create project as a domain admin 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(project) self.debug("Created project with domain admin with ID: %s" % project.id) list_projects_reponse = Project.list( self.apiclient, id=project.id, listall=True ) self.assertEqual( isinstance(list_projects_reponse, list), True, "Check for a valid list projects response" ) list_project = list_projects_reponse[0] self.assertNotEqual( len(list_projects_reponse), 0, "Check list project response returns a valid project" ) self.assertEqual( project.name, list_project.name, "Check project name from list response" ) # Get the resource limits for ROOT domain resource_limits = list_resource_limits(self.apiclient) self.assertEqual( isinstance(resource_limits, list), True, "List resource API should return a valid list" ) self.assertNotEqual( len(resource_limits), 0, "List resource API response should not be empty" ) # Reduce resource limits for project # Resource: 0 - Instance. Number of instances a user can create. # Resource: 1 - IP. Number of public IP addresses a user can own. # Resource: 2 - Volume. Number of disk volumes a user can create. # Resource: 3 - Snapshot. Number of snapshots a user can create. # Resource: 4 - Template. Number of templates that a user can # register/create for resource in resource_limits: update_resource_limit( self.apiclient, resource.resourcetype, max=1, projectid=project.id ) self.debug( "Updating resource (ID: %s) limit for project: %s" % ( resource, project.id )) resource_limits = list_resource_limits( self.apiclient, projectid=project.id ) self.assertEqual( isinstance(resource_limits, list), True, "List resource API should return a valid list" ) self.assertNotEqual( len(resource_limits), 0, "List resource API response should not be empty" ) for resource in resource_limits: self.assertEqual( resource.max, 1, "Resource limit should be updated to 1" ) self.debug("Adding %s user to project: %s" % ( self.user.name, project.name )) # Add user to the project project.addAccount( self.apiclient, self.user.name, ) # Get the resource limits for domain resource_limits = list_resource_limits( self.apiclient, domainid=self.domain.id ) self.assertEqual( isinstance(resource_limits, list), True, "List resource API should return a valid list" ) self.assertNotEqual( len(resource_limits), 0, "List resource API response should not be empty" ) for resource in resource_limits: #with self.assertRaises(Exception): self.debug( "Attempting to update resource limit by user: %s" % ( self.user.name )) # Update project resource limits to 3 update_resource_limit( self.apiclient, resource.resourcetype, account=self.user.name, domainid=self.user.domainid, max=3, projectid=project.id ) return
def setUpClass(cls): cls.testClient = super(TestCreateAffinityGroup, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services #Get Zone, Domain and templates cls.rootdomain = get_domain(cls.api_client) cls.domain = Domain.create(cls.api_client, cls.services["domain"]) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["template"] = cls.template.id cls.services["zoneid"] = cls.zone.id cls.domain_admin_account = Account.create( cls.api_client, cls.services["domain_admin_account"], domainid=cls.domain.id, admin=True ) cls.domain_api_client = cls.testClient.getUserApiClient(cls.domain_admin_account.name, cls.domain.name, 2) cls.account = Account.create( cls.api_client, cls.services["account"], domainid=cls.domain.id ) cls.account_api_client = cls.testClient.getUserApiClient(cls.account.name, cls.domain.name, 0) cls.account_not_in_project = Account.create( cls.api_client, cls.services["account_not_in_project"], domainid=cls.domain.id ) cls.account_not_in_project_api_client = cls.testClient.getUserApiClient(cls.account_not_in_project.name, cls.domain.name, 0) cls.project = Project.create( cls.api_client, cls.services["project"], account=cls.domain_admin_account.name, domainid=cls.domain_admin_account.domainid ) cls.project2 = Project.create( cls.api_client, cls.services["project2"], account=cls.domain_admin_account.name, domainid=cls.domain_admin_account.domainid ) cls.debug("Created project with ID: %s" % cls.project.id) cls.debug("Created project2 with ID: %s" % cls.project2.id) # Add user to the project cls.project.addAccount( cls.api_client, cls.account.name ) cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"], domainid=cls.account.domainid ) cls._cleanup = [] return