def test_02_migrate_instance(self): """Test Deploy VM with 4 core CPU & verify the usage""" # Validate the following # 1. Create compute offering with 4 core CPU & Deploy VM # 2. List Resource count # 3. Migrate instance to another host # 4. Resource count should list properly. self.hypervisor = self.testClient.getHypervisorInfo() if self.hypervisor.lower() in ['lxc']: self.skipTest("vm migrate is not supported in %s" % self.hypervisor) 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 api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) 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].cputotal expected_resource_count = int(self.service_offering.cpunumber) self.assertEqual( resource_count, expected_resource_count, "Initial resource count should with the expected resource count") host = findSuitableHostForMigration(self.apiclient, vm.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name)) try: vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response") resource_count_after_migrate = account_list[0].cputotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same after starting the instance") return
def test_02_project_vmlifecycle_migrate_instance(self): # Validate the following # 1. Assign account to projects and verify the resource updates # 2. Deploy VM with the accounts added to the project # 3. Migrate VM of an accounts added to the project to a new host # 4. Resource count should list properly. self.debug("Checking memory resource count for project: %s" % self.project.name) project_list = Project.list(self.apiclient, id=self.project.id, listall=True) self.debug(project_list) self.assertIsInstance(project_list, list, "List Projects should return a valid response") resource_count = project_list[0].memorytotal self.debug(resource_count) host = 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_02_migrate_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. Migrate vm to another host, resource count should list properly. # Resetting memory count in service offering self.hypervisor = self.testClient.getHypervisorInfo() 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.getUserApiClient( 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") host = findSuitableHostForMigration(self.apiclient, vm.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name)) try: vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].memorytotal self.assertTrue(resource_count_after_migrate == resource_count, "Resource count should be same after migrating the instance") return
def test_02_multiple_core_vm_migrate_instance(self): """Test Deploy VM with 4 core CPU & verify the usage""" # Validate the following # 1. Create two domains and set specific resource (cpu) limit for them # 2. Create compute offering with 4 core CPU & deploy vm # 3. Update Resource count for the domains # 4. Migrate instance to new host and check resource count # 5. Resource count should list properly. self.hypervisor = self.testClient.getHypervisorInfo() 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 api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) 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].cputotal expected_resource_count = int(self.services["service_offering"]["cpunumber"]) self.assertEqual(resource_count, expected_resource_count, "Initial resource count should match with the expected resource count") host = findSuitableHostForMigration(self.apiclient, vm.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name)) try: vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].cputotal self.assertEqual(resource_count, resource_count_after_migrate, "Resource count should be same as before, after migrating the instance") return
def test_02_migrate_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. Migrate vm to another host, resource count should list properly. #Resetting memory count in 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.getUserApiClient( 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") host = findSuitableHostForMigration(self.apiclient, vm.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name)) try: vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].memorytotal self.assertTrue(resource_count_after_migrate == resource_count, "Resource count should be same after migrating the instance") return
def test_02_migrate_instance(self): """Test Deploy VM with specified memory & verify the usage""" # Validate the following # 1. Create compute offering with specified memory in child domains of root domain & Deploy VM # 2. List Resource count # 3. Migrate instance to another 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()) 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 api_client = self.testClient.getUserApiClient(UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) 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, "Initial resource count should with the expected resource count", ) host = findSuitableHostForMigration(self.apiclient, vm.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name)) try: vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response") resource_count_after_migrate = account_list[0].memorytotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same after starting the instance", ) return
def distribute_vm_and_routers_by_hosts(self, virtual_machine, routers): if len(routers) > 1: router = self.get_router(routers) self.logger.debug('Master Router VM is %s' % router) else: router = routers[0] if router.hostid == virtual_machine.hostid: self.logger.debug('Master Router VM is on the same host as VM') host = findSuitableHostForMigration(self.api_client, router.id) if host is not None: router.migrate(self.api_client, host) self.logger.debug('Migrated Master Router VM to host %s' % host) else: self.fail('No suitable host to migrate Master Router VM to') else: self.logger.debug('Master Router VM is not on the same host as VM: %s, %s' % (router.hostid, virtual_machine.hostid))
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_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_02_multiplecore_migrate_instance(self): """Test Deploy VM with multiple core CPU & verify the usage""" # Validate the following # 1. Deploy VM with multiple core CPU & verify the usage # 2. Migrate VM & verify updated resource count of Root Admin Account # 3. Resource count should list properly. self.hypervisor = self.testClient.getHypervisorInfo() if self.hypervisor.lower() in ['lxc']: self.skipTest("vm migrate is not supported in %s" % self.hypervisor) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response") resource_count = account_list[0].cputotal expected_resource_count = int( self.services["service_offering"]["cpunumber"]) 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) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response") resource_count_after_migrate = account_list[0].cputotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same after migrating the instance") return
def test_02_migrate_instance(self): """Test Deploy VM with specified 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. Migrate vm, 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()) 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") 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) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response") resource_count_after_migrate = account_list[0].memorytotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same after stopping the instance") return
def test_02_multiplecore_migrate_instance(self): """Test Deploy VM with multiple core CPU & verify the usage""" # Validate the following # 1. Deploy VM with multiple core CPU & verify the usage # 2. Migrate VM & verify updated resource count of Root Admin Account # 3. Resource count should list properly. self.hypervisor = self.testClient.getHypervisorInfo() if self.hypervisor.lower() in ['lxc']: self.skipTest("vm migrate is not supported in %s" % self.hypervisor) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count = account_list[0].cputotal expected_resource_count = int(self.services["service_offering"]["cpunumber"]) 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) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].cputotal self.assertEqual(resource_count, resource_count_after_migrate, "Resource count should be same after migrating the instance") return
def distribute_vm_and_routers_by_hosts(self, virtual_machine, routers): if len(routers) > 1: router = self.get_router(routers) self.logger.debug('Master Router VM is %s' % router) else: router = routers[0] if router.hostid == virtual_machine.hostid: self.logger.debug('Master Router VM is on the same host as VM') host = findSuitableHostForMigration(self.api_client, router.id) if host is not None: router.migrate(self.api_client, host) self.logger.debug('Migrated Master Router VM to host %s' % host) else: self.fail('No suitable host to migrate Master Router VM to') else: self.logger.debug( 'Master Router VM is not on the same host as VM: %s, %s' % (router.hostid, virtual_machine.hostid))
def distribute_vm_and_routers_by_hosts(self, virtual_machine, routers): if len(routers) > 1: router = self.get_router(routers) self.logger.debug("Primary Router VM is %s" % router) else: router = routers[0] if router.hostid == virtual_machine.hostid: self.logger.debug("Primary Router VM is on the same host as VM") host = findSuitableHostForMigration(self.api_client, router.id) if host is not None: migrate_router(self.api_client, router.id, host.id) self.logger.debug("Migrated Primary Router VM to host %s" % host.name) else: self.fail('No suitable host to migrate Primary Router VM to') else: self.logger.debug( "Primary Router VM is not on the same host as VM: %s, %s" % (router.hostid, virtual_machine.hostid))
def test_02_migrate_instance(self): """Test Deploy VM with specified 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. Migrate vm, resource count should list properly. self.hypervisor = self.testClient.getHypervisorInfo() 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") 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) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].memorytotal self.assertEqual(resource_count, resource_count_after_migrate, "Resource count should be same after stopping the instance") return
def test_04_deploy_multiple_vm_with_multiple_core(self): """Test Deploy multiple VM with 4 core CPU & verify the usage""" # Validate the following # 1. Create compute offering with 4 core CPU # 2. Deploy multiple VMs within domain with this service offering # 3. Update Resource count for the domain # 4. CPU usage should list properly self.debug("Creating service offering with 4 CPU cores") self.service_offering = ServiceOffering.create( self.apiclient, self.services["service_offering"] ) # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = {self.domain: self.admin, self.child_domain: self.child_do_admin } for domain, admin in users.items(): self.account = admin self.domain = domain api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client) vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.debug("Deploying instance - CPU capacity is fully utilized") with self.assertRaises(Exception): self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count = account_list[0].cputotal expected_resource_count = int(self.services["service_offering"]["cpunumber"]) * 4 #Total 4 VMs self.assertEqual(resource_count, expected_resource_count, "Initial resource count should be 4") self.debug("Destroying instance: %s" % vm_1.name) try: vm_1.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_delete = account_list[0].cputotal expected_resource_count -= int(self.services["service_offering"]["cpunumber"]) self.assertEqual(resource_count_after_delete, expected_resource_count, "Resource count should match with the expected count") host = findSuitableHostForMigration(self.apiclient, vm_2.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm_2.name, host.name)) try: vm_2.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].cputotal self.assertEqual(resource_count_after_migrate, resource_count_after_delete, "Resource count should not change after migrating the instance") return
def test_01_positive_tests_vm_operations_advanced_zone(self, value): """ Positive tests for VMLC test path - Advanced Zone # 1. List created service offering in setUpClass by name # 2. List registered template with name # 3. Create VM in account # 4. Enable networking for reaching to VM thorugh SSH # 5. Check VM accessibility through SSH # 6. Stop vm and verify vm is not accessible # 7. Start vm and verify vm is not accessible # 8. Reboot vm and verify vm is not accessible # 9. Destroy and recover VM # 10. Change service offering of VM to a different service offering # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to # as specified in new service offering # 12. Start VM and verify VM accessibility # 13. Find suitable host for VM to migrate and migrate the VM # 14. Verify VM accessibility on new host """ if self.hypervisor.lower() == 'hyperv' and value == VPC_NETWORK: self.skipTest("cann't be run for {} hypervisor".format( self.hypervisor)) # List created service offering in setUpClass by name listServiceOfferings = ServiceOffering.list( self.apiclient, name=self.service_offering_1.name, listall=True) self.assertEqual( validateList(listServiceOfferings)[0], PASS, "List validation failed for service offerings list") self.assertEqual( listServiceOfferings[0].name, self.service_offering_1.name, "Names of created service offering\ and listed service offering not matching") # List registered template with name listTemplates = Template.list(self.userapiclient, templatefilter="self", name=self.template.name, listall=True, zone=self.zone.id) self.assertEqual( validateList(listTemplates)[0], PASS, "List validation failed for templates list") self.assertEqual( listTemplates[0].name, self.template.name, "Names of created template and listed template\ not matching") network = CreateNetwork(self, value) # Create VM in account self.virtual_machine = VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering_1.id, networkids=[ network.id, ], zoneid=self.zone.id) publicip = PublicIPAddress.create(self.userapiclient, accountid=self.account.name, zoneid=self.zone.id, domainid=self.account.domainid, networkid=network.id, vpcid=self.vpcid) if value == VPC_NETWORK: lb_rule = LoadBalancerRule.create( self.apiclient, self.testdata["vpclbrule"], ipaddressid=publicip.ipaddress.id, accountid=self.account.name, domainid=self.account.domainid, networkid=network.id, vpcid=self.vpcid) lb_rule.assign(self.apiclient, [self.virtual_machine]) # Opening up the ports in VPC NetworkACL.create(self.apiclient, networkid=network.id, services=self.testdata["natrule"], traffictype='Ingress') elif value == ISOLATED_NETWORK: FireWallRule.create(self.userapiclient, ipaddressid=publicip.ipaddress.id, protocol='TCP', cidrlist=[self.testdata["fwrule"]["cidr"]], startport=self.testdata["fwrule"]["startport"], endport=self.testdata["fwrule"]["endport"]) NATRule.create(self.userapiclient, self.virtual_machine, self.testdata["natrule"], ipaddressid=publicip.ipaddress.id, networkid=network.id) # Check VM accessibility try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Stop VM and verify VM is not accessible self.virtual_machine.stop(self.userapiclient) with self.assertRaises(Exception): SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password, retries=0) # Start VM and verify that it is accessible self.virtual_machine.start(self.userapiclient) try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Reboot VM and verify that it is accessible self.virtual_machine.reboot(self.userapiclient) try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Destroy and recover VM self.virtual_machine.delete(self.apiclient, expunge=False) self.virtual_machine.recover(self.apiclient) # Change service offering of VM and verify that it is changed self.virtual_machine.change_service_offering( self.userapiclient, serviceOfferingId=self.service_offering_2.id) VerifyChangeInServiceOffering(self, self.virtual_machine, self.service_offering_2) # Start VM and verify that it is accessible self.virtual_machine.start(self.userapiclient) try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Find suitable host for VM to migrate and migrate the VM # Verify that it is accessible on the new host host = findSuitableHostForMigration(self.apiclient, self.virtual_machine.id) if host is None: self.fail(ERROR_NO_HOST_FOR_MIGRATION) self.virtual_machine.migrate(self.apiclient, host.id) try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) return
def test_01_positive_tests_vm_operations_basic_zone(self): """ Positive tests for VMLC test path - Basic Zone # 1. List created service offering in setUpClass by name # 2. List registered template with name # 3. Create VM in account # 4. Enable networking for reaching to VM thorugh SSH # 5. Check VM accessibility through SSH # 6. Stop vm and verify vm is not accessible # 7. Start vm and verify vm is not accessible # 8. Reboot vm and verify vm is not accessible # 9. Destroy and recover VM # 10. Change service offering of VM to a different service offering # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to # as specified in new service offering # 12. Start VM and verify VM accessibility # 13. Find suitable host for VM to migrate and migrate the VM # 14. Verify VM accessibility on new host """ # List created service offering in setUpClass by name listServiceOfferings = ServiceOffering.list( self.apiclient, name=self.service_offering_1.name, listall=True ) self.assertEqual(validateList(listServiceOfferings)[0], PASS, "List validation failed for service offerings list") self.assertEqual(listServiceOfferings[0].name, self.service_offering_1.name, "Names of created service offering and\ listed service offering not matching") # List registered template with name listTemplates = Template.list(self.userapiclient, templatefilter="self", name=self.template.name, listall=True, zone=self.zone.id ) self.assertEqual(validateList(listTemplates)[0], PASS, "List validation failed for\ templates list") self.assertEqual(listTemplates[0].name, self.template.name, "Names of created template and listed template\ not matching") # Enable networking for reaching to VM thorugh SSH security_group = SecurityGroup.create( self.apiclient, self.testdata["security_group"], account=self.account.name, domainid=self.account.domainid ) self.cleanup.append(security_group) # Authorize Security group to SSH to VM security_group.authorize( self.apiclient, self.testdata["ingress_rule"], account=self.account.name, domainid=self.account.domainid ) # Create VM in account self.virtual_machine = VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering_1.id, zoneid=self.zone.id, securitygroupids=[security_group.id, ] ) # Check VM accessibility try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Stop VM and verify VM is not accessible self.virtual_machine.stop(self.userapiclient) with self.assertRaises(Exception): SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password, retries=0 ) # Start VM and verify that it is accessible self.virtual_machine.start(self.userapiclient) try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Reboot VM and verify that it is accessible self.virtual_machine.reboot(self.userapiclient) try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Destroy and recover VM self.virtual_machine.delete(self.userapiclient, expunge=False) self.virtual_machine.recover(self.apiclient) # Change service offering of VM and verify that it is changed self.virtual_machine.change_service_offering( self.userapiclient, serviceOfferingId=self.service_offering_2.id ) VerifyChangeInServiceOffering(self, self.virtual_machine, self.service_offering_2) # Start VM and verify that it is accessible self.virtual_machine.start(self.userapiclient) try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Find suitable host for VM to migrate and migrate the VM # Verify that it is accessible on the new host host = findSuitableHostForMigration(self.apiclient, self.virtual_machine.id) if host is None: self.fail(ERROR_NO_HOST_FOR_MIGRATION) self.virtual_machine.migrate(self.apiclient, host.id) try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) return
def test_01_positive_tests_vm_operations_advanced_zone(self, value): """ Positive tests for VMLC test path - Advanced Zone # 1. List created service offering in setUpClass by name # 2. List registered template with name # 3. Create VM in account # 4. Enable networking for reaching to VM thorugh SSH # 5. Check VM accessibility through SSH # 6. Stop vm and verify vm is not accessible # 7. Start vm and verify vm is not accessible # 8. Reboot vm and verify vm is not accessible # 9. Destroy and recover VM # 10. Change service offering of VM to a different service offering # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to # as specified in new service offering # 12. Start VM and verify VM accessibility # 13. Find suitable host for VM to migrate and migrate the VM # 14. Verify VM accessibility on new host """ if self.hypervisor.lower() == 'hyperv' and value == VPC_NETWORK: self.skipTest("cann't be run for {} hypervisor".format(self.hypervisor)) # List created service offering in setUpClass by name listServiceOfferings = ServiceOffering.list( self.apiclient, name=self.service_offering_1.name, listall=True ) self.assertEqual(validateList(listServiceOfferings)[0], PASS, "List validation failed for service offerings list") self.assertEqual(listServiceOfferings[0].name, self.service_offering_1.name, "Names of created service offering\ and listed service offering not matching") # List registered template with name listTemplates = Template.list( self.userapiclient, templatefilter="self", name=self.template.name, listall=True, zone=self.zone.id) self.assertEqual(validateList(listTemplates)[0], PASS, "List validation failed for templates list") self.assertEqual(listTemplates[0].name, self.template.name, "Names of created template and listed template\ not matching") network = CreateNetwork(self, value) # Create VM in account self.virtual_machine = VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering_1.id, networkids=[network.id, ], zoneid=self.zone.id ) publicip = PublicIPAddress.create( self.userapiclient, accountid=self.account.name, zoneid=self.zone.id, domainid=self.account.domainid, networkid=network.id, vpcid=self.vpcid ) if value == VPC_NETWORK: lb_rule = LoadBalancerRule.create( self.apiclient, self.testdata["vpclbrule"], ipaddressid=publicip.ipaddress.id, accountid=self.account.name, domainid=self.account.domainid, networkid=network.id, vpcid=self.vpcid ) lb_rule.assign(self.apiclient, [self.virtual_machine]) # Opening up the ports in VPC NetworkACL.create( self.apiclient, networkid=network.id, services=self.testdata["natrule"], traffictype='Ingress' ) elif value == ISOLATED_NETWORK: FireWallRule.create( self.userapiclient, ipaddressid=publicip.ipaddress.id, protocol='TCP', cidrlist=[self.testdata["fwrule"]["cidr"]], startport=self.testdata["fwrule"]["startport"], endport=self.testdata["fwrule"]["endport"] ) NATRule.create( self.userapiclient, self.virtual_machine, self.testdata["natrule"], ipaddressid=publicip.ipaddress.id, networkid=network.id ) # Check VM accessibility try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Stop VM and verify VM is not accessible self.virtual_machine.stop(self.userapiclient) with self.assertRaises(Exception): SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password, retries=0) # Start VM and verify that it is accessible self.virtual_machine.start(self.userapiclient) try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Reboot VM and verify that it is accessible self.virtual_machine.reboot(self.userapiclient) try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Destroy and recover VM self.virtual_machine.delete(self.apiclient, expunge=False) self.virtual_machine.recover(self.apiclient) # Change service offering of VM and verify that it is changed self.virtual_machine.change_service_offering( self.userapiclient, serviceOfferingId=self.service_offering_2.id ) VerifyChangeInServiceOffering(self, self.virtual_machine, self.service_offering_2) # Start VM and verify that it is accessible self.virtual_machine.start(self.userapiclient) try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Find suitable host for VM to migrate and migrate the VM # Verify that it is accessible on the new host host = findSuitableHostForMigration(self.apiclient, self.virtual_machine.id) if host is None: self.fail(ERROR_NO_HOST_FOR_MIGRATION) self.virtual_machine.migrate(self.apiclient, host.id) try: SshClient(host=publicip.ipaddress.ipaddress, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) return
def test_01_positive_tests_vm_operations_basic_zone(self): """ Positive tests for VMLC test path - Basic Zone # 1. List created service offering in setUpClass by name # 2. List registered template with name # 3. Create VM in account # 4. Enable networking for reaching to VM thorugh SSH # 5. Check VM accessibility through SSH # 6. Stop vm and verify vm is not accessible # 7. Start vm and verify vm is not accessible # 8. Reboot vm and verify vm is not accessible # 9. Destroy and recover VM # 10. Change service offering of VM to a different service offering # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to # as specified in new service offering # 12. Start VM and verify VM accessibility # 13. Find suitable host for VM to migrate and migrate the VM # 14. Verify VM accessibility on new host """ # List created service offering in setUpClass by name listServiceOfferings = ServiceOffering.list( self.apiclient, name=self.service_offering_1.name, listall=True) self.assertEqual( validateList(listServiceOfferings)[0], PASS, "List validation failed for service offerings list") self.assertEqual( listServiceOfferings[0].name, self.service_offering_1.name, "Names of created service offering and\ listed service offering not matching") # List registered template with name listTemplates = Template.list(self.userapiclient, templatefilter="self", name=self.template.name, listall=True, zone=self.zone.id) self.assertEqual( validateList(listTemplates)[0], PASS, "List validation failed for\ templates list") self.assertEqual( listTemplates[0].name, self.template.name, "Names of created template and listed template\ not matching") # Enable networking for reaching to VM thorugh SSH security_group = SecurityGroup.create(self.apiclient, self.testdata["security_group"], account=self.account.name, domainid=self.account.domainid) self.cleanup.append(security_group) # Authorize Security group to SSH to VM security_group.authorize(self.apiclient, self.testdata["ingress_rule"], account=self.account.name, domainid=self.account.domainid) # Create VM in account self.virtual_machine = VirtualMachine.create( self.userapiclient, self.testdata["small"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering_1.id, zoneid=self.zone.id, securitygroupids=[ security_group.id, ]) # Check VM accessibility try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Stop VM and verify VM is not accessible self.virtual_machine.stop(self.userapiclient) with self.assertRaises(Exception): SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password, retries=0) # Start VM and verify that it is accessible self.virtual_machine.start(self.userapiclient) try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Reboot VM and verify that it is accessible self.virtual_machine.reboot(self.userapiclient) try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Destroy and recover VM self.virtual_machine.delete(self.userapiclient, expunge=False) self.virtual_machine.recover(self.apiclient) # Change service offering of VM and verify that it is changed self.virtual_machine.change_service_offering( self.userapiclient, serviceOfferingId=self.service_offering_2.id) VerifyChangeInServiceOffering(self, self.virtual_machine, self.service_offering_2) # Start VM and verify that it is accessible self.virtual_machine.start(self.userapiclient) try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) # Find suitable host for VM to migrate and migrate the VM # Verify that it is accessible on the new host host = findSuitableHostForMigration(self.apiclient, self.virtual_machine.id) if host is None: self.fail(ERROR_NO_HOST_FOR_MIGRATION) self.virtual_machine.migrate(self.apiclient, host.id) try: SshClient(host=self.virtual_machine.ssh_ip, port=22, user=self.virtual_machine.username, passwd=self.virtual_machine.password) except Exception as e: self.fail("Exception while SSHing to VM: %s" % e) return
def test_02_multiple_core_vm_migrate_instance(self): """Test Deploy VM with 4 core CPU & verify the usage""" # Validate the following # 1. Create two domains and set specific resource (cpu) limit for them # 2. Create compute offering with 4 core CPU & deploy vm # 3. Update Resource count for the domains # 4. Migrate instance to new host and check resource count # 5. Resource count should list properly. 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 api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) 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].cputotal expected_resource_count = int( self.services["service_offering"]["cpunumber"]) self.assertEqual( resource_count, expected_resource_count, "Initial resource count should match with the expected resource count" ) host = findSuitableHostForMigration(self.apiclient, vm.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name)) try: vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count_after_migrate = account_list[0].cputotal self.assertEqual( resource_count, resource_count_after_migrate, "Resource count should be same as before, after migrating the instance" ) return
def test_04_deploy_multiple_vm_with_multiple_core(self): """Test Deploy multiple VM with 4 core CPU & verify the usage""" # Validate the following # 1. Create compute offering with 4 core CPU # 2. Deploy multiple VMs within domain with this service offering # 3. Update Resource count for the domain # 4. CPU usage should list properly self.debug("Creating service offering with 4 CPU cores") self.service_offering = ServiceOffering.create( self.apiclient, self.services["service_offering"]) # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = { self.domain: self.admin, self.child_domain: self.child_do_admin } for domain, admin in users.items(): self.account = admin self.domain = domain api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client) vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.debug("Deploying instance - CPU capacity is fully utilized") with self.assertRaises(Exception): self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count = account_list[0].cputotal expected_resource_count = int(self.services["service_offering"] ["cpunumber"]) * 4 #Total 4 VMs self.assertEqual(resource_count, expected_resource_count, "Initial resource count should be 4") self.debug("Destroying instance: %s" % vm_1.name) try: vm_1.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count_after_delete = account_list[0].cputotal expected_resource_count -= int( self.services["service_offering"]["cpunumber"]) self.assertEqual( resource_count_after_delete, expected_resource_count, "Resource count should match with the expected count") #vm migration is not supported in LXC. So don't need to execute below vm migration code if self.hypervisor.lower() in ['lxc']: continue host = findSuitableHostForMigration(self.apiclient, vm_2.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm_2.name, host.name)) try: vm_2.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count_after_migrate = account_list[0].cputotal self.assertEqual( resource_count_after_migrate, resource_count_after_delete, "Resource count should not change after migrating the instance" ) return
def test_04_deploy_multiple_vm(self): """Test Deploy multiple VM with 2 GB memory & verify the usage""" #keep the configuration value - max.account.memory = 8192 (maximum 4 instances per account with 2 GB RAM) # Validate the following # 1. Create compute offering with 2 GB RAM # 2. Deploy multiple VMs with this service offering in child domains of root domain # 3. List Resource count for the root admin Memory usage # 4. Memory usage should list properly self.debug("Creating service offering with 2 GB RAM") self.service_offering = ServiceOffering.create( self.apiclient, self.services["service_offering"] ) # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = {self.child_domain_1: self.child_do_admin_1, self.child_domain_2: self.child_do_admin_2 } for domain, admin in users.items(): self.account = admin self.domain = domain memory_account_gc = Resources.list(self.apiclient, resourcetype = 9, #Memory account = self.account.name, domainid = self.domain.id ) if memory_account_gc[0].max != 8192: self.skipTest("This test case requires configuration value max.account.memory to be 8192") api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client) vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.debug("Deploying instance - memory capacity is fully utilized") with self.assertRaises(Exception): self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count = account_list[0].memorytotal expected_resource_count = int(self.services["service_offering"]["memory"]) * 4 #Total 4 vms self.assertEqual(resource_count, expected_resource_count, "Initial resource count should with the expected resource count") self.debug("Destroying instance: %s" % vm_1.name) try: vm_1.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_delete = account_list[0].memorytotal expected_resource_count -= int(self.services["service_offering"]["memory"]) self.assertEqual(resource_count_after_delete, expected_resource_count, "Resource count should match with the expected resource count") host = findSuitableHostForMigration(self.apiclient, vm_2.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm_2.name, host.name)) try: vm_2.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance(account_list, list, "List Accounts should return a valid response" ) resource_count_after_migrate = account_list[0].memorytotal self.debug(resource_count_after_migrate) self.assertEqual(resource_count_after_delete, resource_count_after_migrate, "Resource count should be same after migrating the instance") return
def test_04_deploy_multiple_vm(self): """Test Deploy multiple VM with 2 GB memory & verify the usage""" #keep the configuration value - max.account.memory = 8192 (maximum 4 instances per account with 2 GB RAM) # Validate the following # 1. Create compute offering with 2 GB RAM # 2. Deploy multiple VMs with this service offering in child domains of root domain # 3. List Resource count for the root admin Memory usage # 4. Memory usage should list properly self.debug("Creating service offering with 2 GB RAM") self.service_offering = ServiceOffering.create( self.apiclient, self.services["service_offering"]) # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") self.setupAccounts() users = { self.child_domain_1: self.child_do_admin_1, self.child_domain_2: self.child_do_admin_2 } for domain, admin in users.items(): self.account = admin self.domain = domain memory_account_gc = Resources.list( self.apiclient, resourcetype=9, #Memory account=self.account.name, domainid=self.domain.id) if memory_account_gc[0].max != 8192: self.skipTest( "This test case requires configuration value max.account.memory to be 8192" ) api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.debug("Creating an instance with service offering: %s" % self.service_offering.name) vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client) vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.createInstance(service_off=self.service_offering, api_client=api_client) self.debug( "Deploying instance - memory capacity is fully utilized") with self.assertRaises(Exception): self.createInstance(service_off=self.service_offering, api_client=api_client) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count = account_list[0].memorytotal expected_resource_count = int( self.services["service_offering"]["memory"]) * 4 #Total 4 vms self.assertEqual( resource_count, expected_resource_count, "Initial resource count should with the expected resource count" ) self.debug("Destroying instance: %s" % vm_1.name) try: vm_1.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count_after_delete = account_list[0].memorytotal expected_resource_count -= int( self.services["service_offering"]["memory"]) self.assertEqual( resource_count_after_delete, expected_resource_count, "Resource count should match with the expected resource count") host = findSuitableHostForMigration(self.apiclient, vm_2.id) if host is None: self.skipTest(ERROR_NO_HOST_FOR_MIGRATION) self.debug("Migrating instance: %s to host: %s" % (vm_2.name, host.name)) try: vm_2.migrate(self.apiclient, host.id) except Exception as e: self.fail("Failed to migrate instance: %s" % e) account_list = Account.list(self.apiclient, id=self.account.id) self.assertIsInstance( account_list, list, "List Accounts should return a valid response") resource_count_after_migrate = account_list[0].memorytotal self.debug(resource_count_after_migrate) self.assertEqual( resource_count_after_delete, resource_count_after_migrate, "Resource count should be same after migrating the instance") return