def getAdminKeys(self, apiClient): domains = Domain.list(apiClient, name="ROOT") listuser = listUsers.listUsersCmd() listuser.username = "******" listuser.domainid = domains[0].id listuser.listall = True listuserRes = apiClient.listUsers(listuser) userId = listuserRes[0].id apiKey = listuserRes[0].apikey securityKey = listuserRes[0].secretkey return [apiKey, securityKey]
def deploy_domain(self, domain_data): if domain_data['name'] == 'ROOT': domain_list = Domain.list(api_client=self.api_client, name=domain_data['name']) domain = domain_list[0] else: self.logger.debug('>>> DOMAIN => Creating "%s"...', domain_data['name']) domain = Domain.create( api_client=self.api_client, name=domain_data['name'] + ('-' + random_gen() if self.randomizeNames else '')) self.logger.debug( '>>> DOMAIN => ID: %s => Name: %s => Path: %s => State: %s', domain.id, domain.name, domain.path, domain.state) self.deploy_accounts(domain_data['accounts'], domain)
def deploy_domain(self, domain_data): if domain_data['name'] == 'ROOT': domain_list = Domain.list( api_client=self.api_client, name=domain_data['name'] ) domain = domain_list[0] else: self.logger.debug('>>> DOMAIN => Creating "%s"...', domain_data['name']) domain = Domain.create( api_client=self.api_client, name=domain_data['name'] + ('-' + random_gen() if self.randomizeNames else '') ) self.logger.debug('>>> DOMAIN => ID: %s => Name: %s => Path: %s => State: %s', domain.id, domain.name, domain.path, domain.state) self.deploy_accounts(domain_data['accounts'], domain)
def test_forceDeleteDomain(self): """ Test delete domain with force option""" # Steps for validations # 1. create a domain DOM # 2. create 2 users under this domain # 3. deploy 1 VM into each of these user accounts # 4. create PF / FW rules for port 22 on these VMs for their # respective accounts # 5. delete the domain with force=true option # Validate the following # 1. listDomains should list the created domain # 2. listAccounts should list the created accounts # 3. listvirtualmachines should show the Running VMs # 4. PF and FW rules should be shown in listFirewallRules # 5. domain should delete successfully and above three list calls # should show all the resources now deleted. listRouters should # not return any routers in the deleted accounts/domains self.debug("Creating a domain for login with API domain test") domain = Domain.create( self.apiclient, self.services["domain"], parentdomainid=self.domain.id ) self.debug("Domain is created succesfully.") self.debug( "Checking if the created domain is listed in list domains API") domains = Domain.list(self.apiclient, id=domain.id, listall=True) self.assertEqual( isinstance(domains, list), True, "List domains shall return a valid response" ) self.debug("Creating 2 user accounts in domain: %s" % domain.name) self.account_1 = Account.create( self.apiclient, self.services["account"], domainid=domain.id ) self.account_2 = Account.create( self.apiclient, self.services["account"], domainid=domain.id ) try: self.debug("Creating a tiny service offering for VM deployment") self.service_offering = ServiceOffering.create( self.apiclient, self.services["service_offering"], domainid=self.domain.id ) self.debug("Deploying virtual machine in account 1: %s" % self.account_1.name) vm_1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account_1.name, domainid=self.account_1.domainid, serviceofferingid=self.service_offering.id ) self.debug("Deploying virtual machine in account 2: %s" % self.account_2.name) VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account_2.name, domainid=self.account_2.domainid, serviceofferingid=self.service_offering.id ) networks = Network.list( self.apiclient, account=self.account_1.name, domainid=self.account_1.domainid, listall=True ) self.assertEqual( isinstance(networks, list), True, "List networks should return a valid response" ) network_1 = networks[0] self.debug("Default network in account 1: %s is %s" % ( self.account_1.name, network_1.name)) src_nat_list = PublicIPAddress.list( self.apiclient, associatednetworkid=network_1.id, account=self.account_1.name, domainid=self.account_1.domainid, listall=True, issourcenat=True, ) self.assertEqual( isinstance(src_nat_list, list), True, "List Public IP should return a valid source NAT" ) self.assertNotEqual( len(src_nat_list), 0, "Length of response from listPublicIp should not be 0" ) src_nat = src_nat_list[0] self.debug( "Trying to create a port forwarding rule in source NAT: %s" % src_nat.ipaddress) #Create NAT rule nat_rule = NATRule.create( self.apiclient, vm_1, self.services["natrule"], ipaddressid=src_nat.id ) self.debug("Created PF rule on source NAT: %s" % src_nat.ipaddress) nat_rules = NATRule.list(self.apiclient, id=nat_rule.id) self.assertEqual( isinstance(nat_rules, list), True, "List NAT should return a valid port forwarding rules" ) self.assertNotEqual( len(nat_rules), 0, "Length of response from listLbRules should not be 0" ) except Exception as e: self._cleanup.append(self.account_1) self._cleanup.append(self.account_2) self.fail(e) self.debug("Deleting domain with force option") try: domain.delete(self.apiclient, cleanup=True) except Exception as e: self.debug("Waiting for account.cleanup.interval" + " to cleanup any remaining resouces") # Sleep 3*account.gc to ensure that all resources are deleted wait_for_cleanup(self.apiclient, ["account.cleanup.interval"]*3) with self.assertRaises(CloudstackAPIException): Domain.list( self.apiclient, id=domain.id, listall=True ) self.debug("Checking if the resources in domain are deleted") with self.assertRaises(CloudstackAPIException): Account.list( self.apiclient, name=self.account_1.name, domainid=self.account_1.domainid, listall=True ) return
def test_LoginApiDomain(self): """Test login API with domain """ # Steps for test scenario # 1. create a domain # 2. create user in the domain # 3. login to the user account above using UUID domain/user # 4. delete the user account # Validate the following # 1. listDomains returns created domain # 2. listAccounts returns created user # 3. loginResponse should have UUID only in responses # Login also succeeds with non NULL sessionId in response self.debug("Creating a domain for login with API domain test") domain = Domain.create( self.apiclient, self.services["domain"], parentdomainid=self.domain.id ) self.debug("Domain: %s is created succesfully." % domain.name) self.debug( "Checking if the created domain is listed in list domains API") domains = Domain.list(self.apiclient, id=domain.id, listall=True) self.assertEqual( isinstance(domains, list), True, "List domains shall return a valid response" ) self.debug("Creating an user account in domain: %s" % domain.name) self.account = Account.create( self.apiclient, self.services["account"], domainid=domain.id ) self._cleanup.append(self.account) accounts = Account.list( self.apiclient, name=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(accounts, list), True, "List accounts should return a valid response" ) self.debug("Logging into the cloudstack with login API") respose = User.login( self.apiclient, username=self.account.name, password=self.services["account"]["password"], domainid=domain.id) self.debug("Login API response: %s" % respose) self.assertNotEqual( respose.sessionkey, None, "Login to the CloudStack should be successful" + "response shall have non Null key" ) return
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)