def tearDown(self): try: if self.egressruleid: self.debug('remove egress rule id=%s' % self.egressruleid) self.deleteEgressRule() self.debug("Cleaning up the resources") self.virtual_machine.delete(self.apiclient) wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"]) retriesCount = 5 while True: vms = list_virtual_machines(self.apiclient, id=self.virtual_machine.id) if vms is None: break elif retriesCount == 0: self.fail("Failed to delete/expunge VM") time.sleep(10) retriesCount -= 1 self.network.delete(self.apiclient) self.debug("Sleep for Network cleanup to complete.") wait_for_cleanup(self.apiclient, ["network.gc.wait", "network.gc.interval"]) cleanup_resources(self.apiclient, reversed(self.cleanup)) self.debug("Cleanup complete!") except Exception as e: self.fail("Warning! Cleanup failed: %s" % e)
def tearDown(self): try: if self.egressruleid: self.debug('remove egress rule id=%s' % self.egressruleid) self.deleteEgressRule() self.debug("Cleaning up the resources") self.virtual_machine.delete(self.apiclient) wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"]) retriesCount = 5 while True: vms = list_virtual_machines(self.apiclient, id=self.virtual_machine.id) if vms is None: break elif retriesCount == 0: self.fail("Failed to delete/expunge VM") time.sleep(10) retriesCount -= 1 self.network.delete(self.apiclient) self.debug("Sleep for Network cleanup to complete.") wait_for_cleanup(self.apiclient, ["network.gc.wait", "network.gc.interval"]) cleanup_resources(self.apiclient, reversed(self.cleanup)) self.debug("Cleanup complete!") except Exception as e: self.debug("Warning! Exception in tearDown: %s" % e)
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_delete_vm(self): """Test Deploy VM with 5 GB RAM & verify the usage""" # Validate the following # 1. Create compute offering with 5 GB RAM & Deploy VM in the created domain # 2. List Resource count for the root admin Memory usage # 3. Delete vm, resource count should list as 0 after delete operation. self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = { self.domain: self.admin, self.child_domain: self.child_do_admin } for domain, admin in users.items(): self.account = admin self.domain = domain self.debug("Creating an instance with service offering: %s" % self.service_offering.name) api_client = self.testClient.createUserApiClient( UserName=self.account.name, DomainName=self.account.domain) vm = self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count = account_list[0].memorytotal expected_resource_count = int( self.services["service_offering"]["memory"]) self.assertEqual( resource_count, expected_resource_count, "Resource count should match with the expected resource count") self.debug("Destroying instance: %s" % vm.name) try: 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"]) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count_after_delete = account_list[0].memorytotal 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_delete_vm(self): """Test Deploy VM with specified RAM & verify the usage""" # Validate the following # 1. Create compute offering with specified RAM & Deploy VM in the created domain # 2. List Resource count for the root admin Memory usage # 3. Delete vm, resource count should list as 0 after delete operation. # Resetting the memory count of service offering self.services["service_offering"]["memory"] = 2048 self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = { self.child_domain_1: self.child_do_admin_1, self.child_domain_2: self.child_do_admin_2 } for domain, admin in users.items(): self.account = admin self.domain = domain self.debug("Creating an instance with service offering: %s" % self.service_offering.name) api_client = self.testClient.createUserApiClient( UserName=self.account.name, DomainName=self.account.domain) vm = self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count = account_list[0].memorytotal expected_resource_count = int(self.services["service_offering"]["memory"]) self.assertEqual(resource_count, expected_resource_count, "Resource count should match with the expected resource count") self.debug("Destroying instance: %s" % vm.name) try: 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"]) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_delete = account_list[0].memorytotal self.assertEqual(resource_count_after_delete, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM return
def tearDown(self): try: # Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self._cleanup) wait_for_cleanup(self.apiclient, ["network.gc.interval", "network.gc.wait"]) except Exception as e: self.debug("Warning: Exception during cleanup : %s" % e) # raise Exception("Warning: Exception during cleanup : %s" % e) return
def tearDown(self): try: #Clean up, terminate the created network offerings cleanup_resources(self.apiclient, self._cleanup) wait_for_cleanup(self.apiclient, ["network.gc.interval", "network.gc.wait"]) except Exception as e: self.debug("Warning: Exception during cleanup : %s" % e) #raise Exception("Warning: Exception during cleanup : %s" % e) return
def tearDown(self): try: if self.egressruleid: self.debug("remove egress rule id=%s" % self.egressruleid) self.deleteEgressRule() self.debug("Cleaning up the resources") self.virtual_machine.delete(self.apiclient) wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"]) self.debug("Sleep for VM cleanup to complete.") time.sleep(self.services["sleep"]) self.network.delete(self.apiclient) wait_for_cleanup(self.apiclient, ["network.gc.wait", "network.gc.interval"]) self.debug("Sleep for Network cleanup to complete.") time.sleep(self.services["sleep"]) cleanup_resources(self.apiclient, reversed(self.cleanup)) self.debug("Cleanup complete!") except Exception as e: self.debug("Warning! Exception in tearDown: %s" % e)
def tearDown(self): try: if self.egressruleid: self.debug('remove egress rule id=%s' % self.egressruleid) self.deleteEgressRule() self.debug("Cleaning up the resources") self.virtual_machine.delete(self.apiclient) wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"]) self.debug("Sleep for VM cleanup to complete.") time.sleep(self.services['sleep']) self.network.delete(self.apiclient) wait_for_cleanup(self.apiclient, ["network.gc.wait", "network.gc.interval"]) self.debug("Sleep for Network cleanup to complete.") time.sleep(self.services['sleep']) cleanup_resources(self.apiclient, reversed(self.cleanup)) self.debug("Cleanup complete!") except Exception as e: self.debug("Warning! Exception in tearDown: %s" % e)
def tearDown(self): try: if self.egressruleid: self.debug('remove egress rule id=%s' % self.egressruleid) self.deleteEgressRule() self.debug("Cleaning up the resources") #below components is not a part of cleanup because to mandate the order and to cleanup network try: for vm in self.cleanup_vms: if str(vm.state).lower() != "error": vm.delete(self.api_client) except Exception as e: self.fail("Warning: Exception during virtual machines cleanup : %s" % e) # Wait for VMs to expunge wait_for_cleanup(self.api_client, ["expunge.delay", "expunge.interval"]) if len(self.cleanup_vms) > 0: retriesCount = 10 while True: vms = list_virtual_machines(self.api_client, id=self.virtual_machine.id) if vms is None: break elif retriesCount == 0: self.fail("Failed to expunge vm even after 10 minutes") time.sleep(60) retriesCount -= 1 try: for network in self.cleanup_networks: network.delete(self.api_client) except Exception as e: self.fail("Warning: Exception during networks cleanup : %s" % e) self.debug("Sleep for Network cleanup to complete.") wait_for_cleanup(self.apiclient, ["network.gc.wait", "network.gc.interval"]) cleanup_resources(self.apiclient, reversed(self.cleanup)) self.debug("Cleanup complete!") except Exception as e: self.fail("Warning! Cleanup failed: %s" % e)
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_delete_instance(self): """Test Deploy VM with specified GB RAM & verify the usage""" # Validate the following # 1. Create compute offering with specified RAM & Deploy VM as root admin # 2. List Resource count for the root admin Memory usage # 3. Delete instance, resource count should be 0 after delete operation. account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response") resource_count = account_list[0].memorytotal expected_resource_count = int( self.services["service_offering"]["memory"]) 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) # Wait for expunge interval to cleanup Memory wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"]) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response") resource_count_after_delete = account_list[0].memorytotal 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_delete_instance(self): """Test Deploy VM with specified GB RAM & verify the usage""" # Validate the following # 1. Create compute offering with specified RAM & Deploy VM as root admin # 2. List Resource count for the root admin Memory usage # 3. Delete instance, resource count should be 0 after delete operation. account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count = account_list[0].memorytotal expected_resource_count = int(self.services["service_offering"]["memory"]) 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) # Wait for expunge interval to cleanup Memory wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"]) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_delete = account_list[0].memorytotal self.assertEqual(resource_count_after_delete, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM return