def test_01_VM_start_stop(self): """Test project primary storage count with VM stop/start operation # Validate the following # 1. Create VM with custom disk offering in a project and check # initial primary storage count # 2. Stop the VM and verify primary storage count remains the same # 3. Start the VM and verify priamay storage count remains the same """ try: self.vm.stop(self.apiclient) except Exception as e: self.fail("Faield to stop VM: %s" % e) expectedCount = self.initialResourceCount response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, projectid=self.project.id) self.assertEqual(response[0], PASS, response[1]) try: self.vm.start(self.apiclient) except Exception as e: self.fail("Failed to start VM: %s" % e) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, projectid=self.project.id) self.assertEqual(response[0], PASS, response[1]) return
def test_stop_start_vm(self, value): """Test Deploy VM with 5 GB volume & verify the usage # Validate the following # 1. Create a VM with custom disk offering and check the primary storage count # 2. Stop VM and verify the resource count remains same # 3. Start VM and verify resource count remains same""" response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) expectedCount = self.initialResourceCount # Stopping instance try: self.virtualMachine.stop(self.apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) # Starting instance try: self.virtualMachine.start(self.apiclient) except Exception as e: self.fail("Failed to start instance: %s" % e) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_deploy_multiple_vm(self, value): """Test Deploy multiple VMs with & verify the usage # Validate the following # 1. Deploy multiple VMs with this service offering # 2. Update Resource count for the root admin Primary Storage usage # 3. Primary Storage usage should list properly # 4. Destroy one VM among multiple VM's and verify that primary storage count # decreases by equivalent amount """ response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) self.virtualMachine_2 = VirtualMachine.create( self.api_client, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id) expectedCount = (self.initialResourceCount * 2) #Total 2 vms response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) self.virtualMachine_3 = VirtualMachine.create( self.api_client, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id) expectedCount = (self.initialResourceCount * 3) #Total 3 vms response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) self.debug("Destroying instance: %s" % self.virtualMachine_2.name) try: self.virtualMachine_2.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) self.assertTrue(isVmExpunged(self.apiclient, self.virtualMachine_2.id), "VM not expunged \ in allotted time") expectedCount = (self.initialResourceCount * 2) #Total 2 vms response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_stop_start_vm(self, value): """Test Deploy VM with 5 GB volume & verify the usage # Validate the following # 1. Create a VM with custom disk offering and check the primary storage count # 2. Stop VM and verify the resource count remains same # 3. Start VM and verify resource count remains same""" response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) expectedCount = self.initialResourceCount # Stopping instance try: self.virtualMachine.stop(self.apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) # Starting instance try: self.virtualMachine.start(self.apiclient) except Exception as e: self.fail("Failed to start instance: %s" % e) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def verify_resource_count_primary_storage(self, expectedCount, volumeTotal): response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) result = isAccountResourceCountEqualToExpectedCount( self.apiclient, self.account.domainid, self.account.name, expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count of primary storage does not match") response = matchResourceCount(self.apiclient, volumeTotal, RESOURCE_VOLUME, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) result = isAccountResourceCountEqualToExpectedCount( self.apiclient, self.account.domainid, self.account.name, volumeTotal, RESOURCE_VOLUME) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count of volume does not match")
def test_attach_volume_exceeding_primary_limits(self): """ # do # 1. create a normal user account and update primary store limits to the current resource count # 2. Upload a volume of any size # 3. Verify that upload volume succeeds # 4. Verify that primary storage count doesnt change # 6. Try attaching volume to VM and verify that the attach fails (as the resource limits exceed) # 7. Verify that primary storage count doesnt change # done """ # create an account, launch a vm with default template and custom disk offering, update the primary store limits to the current primary store resource count response = self.setupNormalAccount() self.assertEqual(response[0], PASS, response[1]) # upload volume and verify that the volume is uploaded volume = Volume.upload( self.apiclient, self.services["configurableData"]["upload_volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, url="http://people.apache.org/~sanjeev/rajani-thin-volume.vhd", ) volume.wait_for_upload(self.apiclient) volumes = Volume.list(self.apiclient, id=volume.id, zoneid=self.zone.id, listall=True) validationresult = validateList(volumes) assert validationresult[0] == PASS, "volumes list validation failed: %s" % validationresult[2] assert str(volumes[0].state).lower() == "uploaded", ( "Volume state should be 'uploaded' but it is %s" % volumes[0].state ) # verify that the resource count didnt change due to upload volume response = matchResourceCount( self.apiclient, self.initialResourceCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id ) self.assertEqual(response[0], PASS, response[1]) # attach the above volume to the vm try: self.virtualMachine.attach_volume(self.apiclient, volume=volume) except Exception as e: if ( "Maximum number of resources of type 'primary_storage' for account name=" + self.account.name in e.message ): self.assertTrue(True, "there should be primary store resource limit reached exception") else: self.fail( "only resource limit reached exception is expected. some other exception occurred. Failing the test case." ) # resource count should match as the attach should fail due to reaching resource limits response = matchResourceCount( self.apiclient, self.initialResourceCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id ) self.assertEqual(response[0], PASS, response[1]) return
def verify_resource_count_cpu_memory(self, expectedCpu, expectedMemory, account=None): if account is None: account = self.account response = matchResourceCount(self.apiclient, expectedCpu, RESOURCE_CPU, accountid=account.id) self.assertEqual(response[0], PASS, response[1]) response = matchResourceCount(self.apiclient, expectedMemory, RESOURCE_MEMORY, accountid=account.id) self.assertEqual(response[0], PASS, response[1]) result = isAccountResourceCountEqualToExpectedCount( self.apiclient, account.domainid, account.name, expectedCpu, RESOURCE_CPU) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count of cpu does not match") result = isAccountResourceCountEqualToExpectedCount( self.apiclient, account.domainid, account.name, expectedMemory, RESOURCE_MEMORY) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count of memory does not match")
def test_destroy_recover_vm(self, value): """Test delete and recover instance # Validate the following # 1. Create a VM with custom disk offering and check the primary storage count # 2. Destroy VM and verify the resource count remains same # 3. Recover VM and verify resource count remains same""" response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) expectedCount = self.initialResourceCount # Stopping instance try: self.virtualMachine.delete(self.apiclient, expunge=False) except Exception as e: self.fail("Failed to destroy instance: %s" % e) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) # Recovering instance try: self.virtualMachine.recover(self.apiclient) except Exception as e: self.fail("Failed to start instance: %s" % e) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_destroy_recover_vm(self, value): """Test delete and recover instance # Validate the following # 1. Create a VM with custom disk offering and check the primary storage count # 2. Destroy VM and verify the resource count remains same # 3. Recover VM and verify resource count remains same""" response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) expectedCount = self.initialResourceCount # Stopping instance try: self.virtualMachine.delete(self.apiclient, expunge=False) except Exception as e: self.fail("Failed to destroy instance: %s" % e) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) # Recovering instance try: self.virtualMachine.recover(self.apiclient) except Exception as e: self.fail("Failed to start instance: %s" % e) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_03_register_iso(self, value): """Test register iso Steps and validations: 1. Create a root domain/child domain admin account 2. Register a test iso in the account 3. Wait till the iso is downloaded and is in ready state 3. Verify that secondary storage resource count of the account equals the iso size 4. Delete the iso 5. Verify that the secondary storage count of the account equals 0 """ response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) self.services["iso"]["zoneid"] = self.zone.id try: iso = Iso.create( self.apiclient, self.services["iso"], account=self.account.name, domainid=self.account.domainid ) except Exception as e: self.fail("Failed to create Iso: %s" % e) timeout = 600 isoList = None while timeout >= 0: isoList = Iso.list(self.apiclient, isofilter="self", id=iso.id) self.assertEqual(validateList(isoList)[0],PASS,\ "iso list validation failed") if isoList[0].isready: break time.sleep(60) timeout -= 60 self.assertNotEqual(timeout, 0,\ "template not downloaded completely") isoSize = (isoList[0].size / (1024**3)) expectedCount = isoSize response = matchResourceCount(self.apiclient, expectedCount, resourceType=RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: iso.delete(self.apiclient) except Exception as e: self.fail("Failed to delete Iso") expectedCount = 0 response = matchResourceCount(self.apiclient, expectedCount, resourceType=RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_01_register_template(self, value): """Test register template # Validate the following: 1. Create a root domain admin/ child domain admin account 2. Register and download a template according to hypervisor type 3. Verify that the template is listed 4. Verify that the secondary storage count for the account equals the size of the template 5. Delete the template 6. Verify that the secondary storage resource count of the account equals 0 """ response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["format"] = builtin_info[2] try: template = Template.register(self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor) template.download(self.apiclient) except Exception as e: self.fail("Failed to register template: %s" % e) templates = Template.list(self.apiclient, templatefilter=\ self.services["template_2"]["templatefilter"], id=template.id) self.assertEqual(validateList(templates)[0],PASS,\ "templates list validation failed") templateSize = (templates[0].size / (1024**3)) expectedCount = templateSize response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: template.delete(self.apiclient) except Exception as e: self.fail("Failed to delete template: %s" % e) expectedCount = 0 response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_assign_vm_different_account(self, value): """Test assign Vm to different account # Validate the following # 1. Deploy VM in account and check the primary storage resource count # 2. Assign VM to another account # 3. Resource count for first account should now equal to 0 # 4. Resource count for the account to which VM is assigned should # increase to that of initial resource count of first account """ response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) try: account_2 = Account.create(self.apiclient, self.services["account"], domainid=self.domain.id, admin=True) self.cleanup.append(account_2) except Exception as e: self.fail("Failed to create account: %s" % e) expectedCount = self.initialResourceCount response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.virtualMachine.stop(self.apiclient) self.virtualMachine.assign_virtual_machine(self.apiclient, account_2.name, account_2.domainid) self.cleanup.remove( self.virtualMachine) # should now be cleaned with account_2 self.cleanup.append(self.virtualMachine) # or before to be neat except Exception as e: self.fail("Failed to assign virtual machine to account %s: %s" % (account_2.name, e)) # Checking resource count for account 2 response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=account_2.id) self.assertEqual(response[0], PASS, response[1]) expectedCount = 0 # Checking resource count for original account response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_deploy_multiple_vm(self, value): """Test Deploy multiple VMs with & verify the usage # Validate the following # 1. Deploy multiple VMs with this service offering # 2. Update Resource count for the root admin Primary Storage usage # 3. Primary Storage usage should list properly # 4. Destroy one VM among multiple VM's and verify that primary storage count # decreases by equivalent amount """ response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) self.virtualMachine_2 = VirtualMachine.create(self.api_client, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id) expectedCount = (self.initialResourceCount * 2) #Total 2 vms response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) self.virtualMachine_3 = VirtualMachine.create(self.api_client, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id) expectedCount = (self.initialResourceCount * 3) #Total 3 vms response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) self.debug("Destroying instance: %s" % self.virtualMachine_2.name) try: self.virtualMachine_2.delete(self.apiclient) except Exception as e: self.fail("Failed to delete instance: %s" % e) self.assertTrue(isVmExpunged(self.apiclient, self.virtualMachine_2.id), "VM not expunged \ in allotted time") expectedCount -= (self.template.size / (1024 ** 3)) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_attach_volume_exceeding_primary_limits(self): """ # do # 1. create a normal user account and update primary store limits to the current resource count # 2. Upload a volume of any size # 3. Verify that upload volume succeeds # 4. Verify that primary storage count doesnt change # 6. Try attaching volume to VM and verify that the attach fails (as the resource limits exceed) # 7. Verify that primary storage count doesnt change # done """ # create an account, launch a vm with default template and custom disk offering, update the primary store limits to the current primary store resource count response = self.setupNormalAccount() self.assertEqual(response[0], PASS, response[1]) # upload volume and verify that the volume is uploaded volume = Volume.upload(self.apiclient, self.services["configurableData"]["upload_volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, url="http://people.apache.org/~sanjeev/rajani-thin-volume.vhd") volume.wait_for_upload(self.apiclient) volumes = Volume.list(self.apiclient, id=volume.id, zoneid=self.zone.id, listall=True) validationresult = validateList(volumes) assert validationresult[0] == PASS, "volumes list validation failed: %s" % validationresult[2] assert str(volumes[0].state).lower() == "uploaded", "Volume state should be 'uploaded' but it is %s" % volumes[0].state # verify that the resource count didnt change due to upload volume response = matchResourceCount( self.apiclient, self.initialResourceCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) # attach the above volume to the vm try: self.virtualMachine.attach_volume(self.apiclient, volume=volume) except Exception as e: if "Maximum number of resources of type \'primary_storage\' for account name="+self.account.name in e.message: self.assertTrue(True, "there should be primary store resource limit reached exception") else: self.fail("only resource limit reached exception is expected. some other exception occurred. Failing the test case.") # resource count should match as the attach should fail due to reaching resource limits response = matchResourceCount( self.apiclient, self.initialResourceCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_assign_vm_different_account(self, value): """Test assign Vm to different account # Validate the following # 1. Deploy VM in account and check the primary storage resource count # 2. Assign VM to another account # 3. Resource count for first account should now equal to 0 # 4. Resource count for the account to which VM is assigned should # increase to that of initial resource count of first account """ response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) try: account_2 = Account.create(self.apiclient, self.services["account"], domainid=self.domain.id, admin=True) self.cleanup.insert(0, account_2) except Exception as e: self.fail("Failed to create account: %s" % e) expectedCount = self.initialResourceCount response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.virtualMachine.stop(self.apiclient) self.virtualMachine.assign_virtual_machine(self.apiclient, account_2.name ,account_2.domainid) except Exception as e: self.fail("Failed to assign virtual machine to account %s: %s" % (account_2.name,e)) # Checking resource count for account 2 response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=account_2.id) self.assertEqual(response[0], PASS, response[1]) expectedCount = 0 # Checking resource count for original account response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_03_delete_vm(self): """Test delete VM belonging to project # Validate the following # 1. Create VM with custom disk offering in a project and check # initial primary storage count # 2. Delete VM and verify that it's expunged # 3. Verify that primary storage count of project equals 0""" try: self.vm.delete(self.apiclient) except Exception as e: self.fail("Failed to detroy VM: %s" % e) self.assertTrue(isVmExpunged(self.apiclient, self.vm.id, self.project.id),\ "VM not expunged") totalallottedtime = timeout = 600 while timeout >= 0: volumes = Volume.list(self.apiclient, projectid=self.project.id, listall=True) if volumes is None: break if timeout == 0: self.fail("Volume attached to VM not cleaned up even\ after %s seconds" % totalallottedtime) timeout -= 60 time.sleep(60) expectedCount = 0 response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, projectid=self.project.id) self.assertEqual(response[0], PASS, response[1]) return
def test_02_migrate_vm(self): """Test migrate VM in project # Validate the following # 1. Create VM with custom disk offering in a project and check # initial primary storage count # 2. List the hosts suitable for migrating the VM # 3. Migrate the VM and verify that primary storage count of project remains same""" try: hosts = Host.list(self.apiclient,virtualmachineid=self.vm.id, listall=True) self.assertEqual(validateList(hosts)[0], PASS, "hosts list validation failed") host = hosts[0] self.vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Exception occured" % e) expectedCount = self.initialResourceCount response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, projectid=self.project.id) self.assertEqual(response[0], PASS, response[1]) return
def test_02_migrate_vm(self): """Test migrate VM in project # Validate the following # 1. Create VM with custom disk offering in a project and check # initial primary storage count # 2. List the hosts suitable for migrating the VM # 3. Migrate the VM and verify that primary storage count of project remains same""" self.hypervisor = self.testClient.getHypervisorInfo() if self.hypervisor.lower() in ['lxc']: self.skipTest("vm migrate feature is not supported on %s" % self.hypervisor.lower()) try: hosts = Host.list(self.apiclient,virtualmachineid=self.vm.id, listall=True) self.assertEqual(validateList(hosts)[0], PASS, "hosts list validation failed") host = hosts[0] self.vm.migrate(self.apiclient, host.id) except Exception as e: self.fail("Exception occured: %s" % e) expectedCount = self.initialResourceCount response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, projectid=self.project.id) self.assertEqual(response[0], PASS, response[1]) return
def test_02_create_template_snapshot(self, value): """Test create snapshot and templates from volume # Validate the following 1. Create root domain/child domain admin account 2. Deploy VM in the account 3. Create snapshot from the virtual machine root volume 4. Create template from the snapshot 5. Verify that the secondary storage count of the account equals the size of the template""" response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) self.virtualMachine = VirtualMachine.create(self.api_client, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id) self.assertNotEqual(self.virtualMachine, FAILED, "VM deployment failed") apiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.assertNotEqual(apiclient, FAILED,\ "Failed to create api client for account: %s" % self.account.name) try: self.virtualMachine.stop(apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) self.debug("Creating snapshot from ROOT volume: %s" % self.virtualMachine.name) response = createSnapshotFromVirtualMachineVolume(apiclient, self.account, self.virtualMachine.id) self.assertEqual(response[0], PASS, response[1]) snapshot = response[1] snapshotSize = (snapshot.physicalsize / (1024 ** 3)) try: template = Template.create_from_snapshot(apiclient, snapshot=snapshot, services=self.services["template_2"]) except Exception as e: self.fail("Failed to create template: %s" % e) templates = Template.list(apiclient, templatefilter=\ self.services["template_2"]["templatefilter"], id=template.id) self.assertEqual(validateList(templates)[0],PASS,\ "templates list validation failed") templateSize = (templates[0].size / (1024**3)) expectedSecondaryStorageCount = int(templateSize + snapshotSize) response = matchResourceCount(self.apiclient, expectedSecondaryStorageCount, resourceType=RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_02_deploy_vm_account_limit_reached(self): """Test Try to deploy VM with admin account where account has used the resources but @ domain they are available # Validate the following # 1. Try to register template with admin account where account has used the # resources but @ domain they are available # 2. Template registration should fail""" response = self.setupAccounts() self.assertEqual(response[0], PASS, response[1]) response = self.registerTemplate() self.assertEqual(response[0], PASS, response[1]) expectedCount = self.templateSize response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.child_do_admin.id) self.assertEqual(response[0], PASS, response[1]) accountLimit = self.templateSize response = self.updateSecondaryStorageLimits(accountLimit=accountLimit) self.assertEqual(response[0], PASS, response[1]) with self.assertRaises(Exception): template = Template.register(self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.child_do_admin.name, domainid=self.child_do_admin.domainid) return
def test_02_create_template_snapshot(self, value): """Test create snapshot and templates from volume # Validate the following 1. Create root domain/child domain admin account 2. Deploy VM in the account 3. Create snapshot from the virtual machine root volume 4. Create template from the snapshot 5. Verify that the secondary storage count of the account equals the size of the template""" response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) self.virtualMachine = VirtualMachine.create( self.api_client, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, ) self.assertNotEqual(self.virtualMachine, FAILED, "VM deployment failed") apiclient = self.testClient.getUserApiClient(UserName=self.account.name, DomainName=self.account.domain) self.assertNotEqual(apiclient, FAILED, "Failed to create api client for account: %s" % self.account.name) try: self.virtualMachine.stop(apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) self.debug("Creating snapshot from ROOT volume: %s" % self.virtualMachine.name) response = createSnapshotFromVirtualMachineVolume(apiclient, self.account, self.virtualMachine.id) self.assertEqual(response[0], PASS, response[1]) snapshot = response[1] snapshotSize = snapshot.physicalsize / (1024 ** 3) try: template = Template.create_from_snapshot(apiclient, snapshot=snapshot, services=self.services["template_2"]) except Exception as e: self.fail("Failed to create template: %s" % e) templates = Template.list( apiclient, templatefilter=self.services["template_2"]["templatefilter"], id=template.id ) self.assertEqual(validateList(templates)[0], PASS, "templates list validation failed") templateSize = templates[0].size / (1024 ** 3) expectedSecondaryStorageCount = int(templateSize + snapshotSize) response = matchResourceCount( self.apiclient, expectedSecondaryStorageCount, resourceType=RESOURCE_SECONDARY_STORAGE, accountid=self.account.id, ) self.assertEqual(response[0], PASS, response[1]) return
def test_02_increase_volume_size_above_account_limit(self): """Test increasing volume size above the account limit # Validate the following # 1. Create a domain and its admin account # 2. Set account primary storage limit more than (5 GB volume + template size of VM) # and less than (20 GB volume+ template size of VM) # 3. Deploy a VM without any disk offering (only root disk) # 4. Create a volume of 5 GB in the account and attach it to the VM # 5. Try to (resize) the volume to 20 GB # 6. Resize opearation should fail""" # Setting up account and domain hierarchy result = self.setupAccounts() self.assertEqual(result[0], PASS, result[1]) templateSize = (self.template.size / (1024**3)) accountLimit = ((templateSize + self.disk_offering_20_GB.disksize) - 1) response = self.updateResourceLimits(accountLimit=accountLimit) self.assertEqual(response[0], PASS, response[1]) apiclient = self.testClient.getUserApiClient( UserName=self.parentd_admin.name, DomainName=self.parentd_admin.domain) self.assertNotEqual(apiclient, FAILED, "Failed to get api client\ of account: %s" % self.parentd_admin.name) try: virtualMachine = VirtualMachine.create( apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.service_offering.id ) volume = Volume.create( apiclient,self.services["volume"],zoneid=self.zone.id, account=self.parentd_admin.name,domainid=self.parent_domain.id, diskofferingid=self.disk_offering_5_GB.id) virtualMachine.attach_volume(apiclient, volume=volume) expectedCount = (templateSize + self.disk_offering_5_GB.disksize) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.parentd_admin.id) if response[0] == FAIL: raise Exception(response[1]) except Exception as e: self.fail("Failed with exception: %s" % e) if self.hypervisor == str(XEN_SERVER).lower(): virtualMachine.stop(self.apiclient) with self.assertRaises(Exception): volume.resize(apiclient, diskofferingid=self.disk_offering_20_GB.id) return
def test_create_multiple_volumes(self, value): """Test create multiple volumes # Validate the following # 1. Create a VM with custom disk offering and check the primary storage count # of account # 2. Create multiple volumes in account # 3. Verify that primary storage count increases by same amount # 4. Attach volumes to VM and verify resource count remains the same # 5. Detach and delete both volumes one by one and verify resource count decreases # proportionately""" # Creating service offering with 10 GB volume response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) apiclient = self.apiclient if value == CHILD_DOMAIN_ADMIN: apiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.assertNotEqual( apiclient, FAIL, "Failure while getting\ api client of account %s" % self.account.name) try: self.services["disk_offering"]["disksize"] = 5 disk_offering_5_GB = DiskOffering.create( self.apiclient, services=self.services["disk_offering"]) self.cleanup.append(disk_offering_5_GB) self.services["disk_offering"]["disksize"] = 10 disk_offering_10_GB = DiskOffering.create( self.apiclient, services=self.services["disk_offering"]) self.cleanup.append(disk_offering_10_GB) volume_1 = Volume.create(apiclient, self.services["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=disk_offering_5_GB.id) volume_2 = Volume.create(apiclient, self.services["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=disk_offering_10_GB.id) self.debug("Attaching volume %s to vm %s" % (volume_1.name, self.virtualMachine.name)) self.virtualMachine.attach_volume(apiclient, volume=volume_1) self.debug("Attaching volume %s to vm %s" % (volume_2.name, self.virtualMachine.name)) self.virtualMachine.attach_volume(apiclient, volume=volume_2) except Exception as e: self.fail("Failure: %s" % e) expectedCount = self.initialResourceCount + 15 # (5 + 10) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: # Detaching and deleting volume 1 self.virtualMachine.detach_volume(apiclient, volume=volume_1) volume_1.delete(apiclient) except Exception as e: self.fail("Failure while volume operation: %s" % e) expectedCount -= 5 #After deleting first volume response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: # Detaching and deleting volume 2 self.virtualMachine.detach_volume(apiclient, volume=volume_2) volume_2.delete(apiclient) except Exception as e: self.fail("Failure while volume operation: %s" % e) expectedCount -= 10 response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_04_copy_template(self, value): """Test copy template between zones Steps and validations: This test requires at least two zones present in the setup 1. Create a root domain/child domain admin account 2. Register and download a template in the account 3. Verify the secondary storage resource count of the account equals the size of the template 4. Copy this template to other zone 5. Verify that the secondary storage resource count is now doubled as there are two templates now in two zones under the admin account """ zones = list_zones(self.apiclient) self.assertEqual(validateList(zones)[0], PASS, "zones list validation faield") if len(zones) < 2: self.skipTest("At least 2 zones should be present for this test case") response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["format"] = builtin_info[2] try: template = Template.register( self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor, ) template.download(self.apiclient) except Exception as e: self.fail("Failed to register template: %s" % e) templates = Template.list( self.apiclient, templatefilter=self.services["template_2"]["templatefilter"], id=template.id ) self.assertEqual(validateList(templates)[0], PASS, "templates list validation failed") templateSize = templates[0].size / (1024 ** 3) expectedCount = templateSize response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id ) self.assertEqual(response[0], PASS, response[1]) templateDestinationZoneId = None for zone in zones: if template.zoneid != zone.id: templateDestinationZoneId = zone.id break template.copy(self.apiclient, destzoneid=templateDestinationZoneId, sourcezoneid=template.zoneid) expectedCount = templateSize * 2 response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id ) self.assertEqual(response[0], PASS, response[1]) return
def test_create_template_snapshot(self, value): """Test create snapshot and templates from volume # Validate the following # 1. Deploy VM with custoom disk offering and check the # primary storage resource count # 2. Stop the VM and create Snapshot from VM's volume # 3. Create volume againt from this snapshto and attach to VM # 4. Verify that primary storage count increases by the volume size # 5. Detach and delete volume, verify primary storage count decreaes by volume size""" if self.hypervisor.lower() in ['hyperv']: self.skipTest("Snapshots feature is not supported on Hyper-V") response = self.setupAccount(value) self.debug(response[0]) self.debug(response[1]) self.assertEqual(response[0], PASS, response[1]) apiclient = self.apiclient if value == CHILD_DOMAIN_ADMIN: apiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain ) self.assertNotEqual(apiclient, FAIL, "Failure while getting api\ client of account: %s" % self.account.name) try: self.virtualMachine.stop(apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) expectedCount = self.initialResourceCount response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) self.debug("Creating snapshot from ROOT volume: %s" % self.virtualMachine.name) snapshot = None response = createSnapshotFromVirtualMachineVolume(apiclient, self.account, self.virtualMachine.id) self.assertEqual(response[0], PASS, response[1]) snapshot = response[1] response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.services["volume"]["size"] = self.services["disk_offering"]["disksize"] volume = Volume.create_from_snapshot(apiclient, snapshot_id=snapshot.id, services=self.services["volume"], account=self.account.name, domainid=self.account.domainid) self.debug("Attaching the volume to vm: %s" % self.virtualMachine.name) self.virtualMachine.attach_volume(apiclient, volume) except Exception as e: self.fail("Failure in volume operation: %s" % e) expectedCount += int(self.services["volume"]["size"]) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.virtualMachine.detach_volume(apiclient, volume) except Exception as e: self.fail("Failure in detach volume operation: %s" % e) try: self.debug("deleting the volume: %s" % volume.name) volume.delete(apiclient) except Exception as e: self.fail("Failure while deleting volume: %s" % e) expectedCount -= int(self.services["volume"]["size"]) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_04_copy_template(self, value): """Test copy template between zones Steps and validations: This test requires at least two zones present in the setup 1. Create a root domain/child domain admin account 2. Register and download a template in the account 3. Verify the secondary storage resource count of the account equals the size of the template 4. Copy this template to other zone 5. Verify that the secondary storage resource count is now doubled as there are two templates now in two zones under the admin account """ zones = list_zones(self.apiclient) self.assertEqual( validateList(zones)[0], PASS, "zones list validation faield") if len(zones) < 2: self.skipTest( "At least 2 zones should be present for this test case") response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["format"] = builtin_info[2] try: template = Template.register(self.apiclient, self.services["template_2"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, hypervisor=self.hypervisor) template.download(self.apiclient) except Exception as e: self.fail("Failed to register template: %s" % e) templates = Template.list(self.apiclient, templatefilter=\ self.services["template_2"]["templatefilter"], id=template.id) self.assertEqual(validateList(templates)[0],PASS,\ "templates list validation failed") templateSize = (templates[0].size / (1024**3)) expectedCount = templateSize response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) templateDestinationZoneId = None for zone in zones: if template.zoneid != zone.id: templateDestinationZoneId = zone.id break template.copy(self.apiclient, destzoneid=templateDestinationZoneId, sourcezoneid=template.zoneid) expectedCount = (templateSize * 2) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_00_deploy_vm_root_resize(self): """Test deploy virtual machine with root resize # Validate the following: # 1. listVirtualMachines returns accurate information # 2. root disk has new size per listVolumes # 3. Rejects non-supported hypervisor types """ newrootsize = (self.template.size >> 30) + 2 if (self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() == 'xenserver' or self.hypervisor.lower() == 'vmware' or self.hypervisor.lower() == 'simulator'): accounts = Account.list(self.apiclient, id=self.account.id) self.assertEqual(validateList(accounts)[0], PASS, "accounts list validation failed") initialResourceCount = int(accounts[0].primarystoragetotal) if self.hypervisor=="vmware": self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], zoneid=self.zone.id, accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.services_offering_vmware.id, templateid=self.template.id, rootdisksize=newrootsize ) else: self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], zoneid=self.zone.id, accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.service_offering.id, templateid=self.template.id, rootdisksize=newrootsize ) list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) self.debug( "Verify listVirtualMachines response for virtual machine: %s" \ % self.virtual_machine.id ) res=validateList(list_vms) self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list VM " "response") self.cleanup.append(self.virtual_machine) vm = list_vms[0] self.assertEqual( vm.id, self.virtual_machine.id, "Virtual Machine ids do not match" ) self.assertEqual( vm.name, self.virtual_machine.name, "Virtual Machine names do not match" ) self.assertEqual( vm.state, "Running", msg="VM is not in Running state" ) # get root vol from created vm, verify it is correct size list_volume_response = list_volumes( self.apiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall=True ) res=validateList(list_volume_response) self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list VM " "response") rootvolume = list_volume_response[0] success = False if rootvolume is not None and rootvolume.size == (newrootsize << 30): success = True self.assertEqual( success, True, "Check if the root volume resized appropriately" ) response = matchResourceCount( self.apiclient, (initialResourceCount + newrootsize), RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) else: self.debug("hypervisor %s unsupported for test 00, verifying it errors properly" % self.hypervisor) newrootsize = (self.template.size >> 30) + 2 success = False try: self.virtual_machine = VirtualMachine.create( self.apiclient, self.testdata["virtual_machine"], accountid=self.account.name, zoneid=self.zone.id, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=self.template.id, rootdisksize=newrootsize ) except Exception as ex: if re.search("Hypervisor \S+ does not support rootdisksize override", str(ex)): success = True else: self.debug("Virtual machine create did not fail appropriately. Error was actually : " + str(ex)); self.assertEqual(success, True, "Check if unsupported hypervisor %s fails appropriately" % self.hypervisor)
def test_01_increase_volume_size_within_account_limit(self): """Test increasing volume size within the account limit and verify primary storage usage # Validate the following # 1. Create a domain and its admin account # 2. Set account primary storage limit well beyond (20 GB volume + # template size of VM) # 3. Deploy a VM without any disk offering (only root disk) # 4. Create a volume of 5 GB in the account and attach it to the VM # 5. Increase (resize) the volume to 20 GB # 6. Resize operation should be successful and primary storage count # for account should be updated successfully""" result = self.setupAccounts() self.assertEqual(result[0], PASS, result[1]) apiclient = self.testClient.getUserApiClient( UserName=self.parentd_admin.name, DomainName=self.parentd_admin.domain) self.assertNotEqual( apiclient, FAILED, "Failed to get api client\ of account: %s" % self.parentd_admin.name) templateSize = (self.template.size / (1024**3)) accountLimit = (templateSize + self.disk_offering_20_GB.disksize) response = self.updateResourceLimits(accountLimit=accountLimit) self.assertEqual(response[0], PASS, response[1]) try: virtualMachine = VirtualMachine.create( apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.service_offering.id) self.cleanup.append(virtualMachine) volume = Volume.create(apiclient, self.services["volume"], zoneid=self.zone.id, account=self.parentd_admin.name, domainid=self.parent_domain.id, diskofferingid=self.disk_offering_5_GB.id) virtualMachine.attach_volume(apiclient, volume=volume) expectedCount = (templateSize + self.disk_offering_5_GB.disksize) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.parentd_admin.id) if response[0] == FAIL: raise Exception(response[1]) if self.hypervisor == str(XEN_SERVER).lower(): virtualMachine.stop(self.apiclient) volume.resize(apiclient, diskofferingid=self.disk_offering_20_GB.id) expectedCount = (templateSize + self.disk_offering_20_GB.disksize) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.parentd_admin.id) if response[0] == FAIL: raise Exception(response[1]) except Exception as e: self.fail("Failed with exception: %s" % e) return
def test_attach_detach_volume(self, value): """Stop attach and detach volume from VM # Validate the following # 1. Create a VM with custom disk offering and check the primary storage count # of account # 2. Create custom volume in account # 3. Verify that primary storage count increases by same amount # 4. Attach volume to VM and verify resource count remains the same # 5. Detach volume and verify resource count remains the same""" response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) apiclient = self.apiclient if value == CHILD_DOMAIN_ADMIN: apiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain ) self.assertNotEqual(apiclient, FAIL, "Failure while getting\ api client of account: %s" % self.account.name) try: self.services["disk_offering"]["disksize"] = 4 expectedCount = self.initialResourceCount + int(self.services["disk_offering"]["disksize"]) disk_offering = DiskOffering.create(self.apiclient, services=self.services["disk_offering"]) self.cleanup.append(disk_offering) volume = Volume.create( apiclient,self.services["volume"],zoneid=self.zone.id, account=self.account.name,domainid=self.account.domainid, diskofferingid=disk_offering.id) except Exception as e: self.fail("Failure: %s" % e) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.virtualMachine.attach_volume(apiclient, volume=volume) except Exception as e: self.fail("Failed while attaching volume to VM: %s" % e) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.virtualMachine.detach_volume(apiclient, volume=volume) except Exception as e: self.fail("Failure while detaching volume: %s" % e) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_create_multiple_volumes(self, value): """Test create multiple volumes # Validate the following # 1. Create a VM with custom disk offering and check the primary storage count # of account # 2. Create multiple volumes in account # 3. Verify that primary storage count increases by same amount # 4. Attach volumes to VM and verify resource count remains the same # 5. Detach and delete both volumes one by one and verify resource count decreases # proportionately""" # Creating service offering with 10 GB volume response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) apiclient = self.apiclient if value == CHILD_DOMAIN_ADMIN: apiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain ) self.assertNotEqual(apiclient, FAIL, "Failure while getting\ api client of account %s" % self.account.name) try: self.services["disk_offering"]["disksize"] = 5 disk_offering_5_GB = DiskOffering.create(self.apiclient, services=self.services["disk_offering"]) self.cleanup.append(disk_offering_5_GB) self.services["disk_offering"]["disksize"] = 10 disk_offering_10_GB = DiskOffering.create(self.apiclient, services=self.services["disk_offering"]) self.cleanup.append(disk_offering_10_GB) volume_1 = Volume.create( apiclient,self.services["volume"],zoneid=self.zone.id, account=self.account.name,domainid=self.account.domainid, diskofferingid=disk_offering_5_GB.id) volume_2 = Volume.create( apiclient,self.services["volume"],zoneid=self.zone.id, account=self.account.name,domainid=self.account.domainid, diskofferingid=disk_offering_10_GB.id) self.debug("Attaching volume %s to vm %s" % (volume_1.name, self.virtualMachine.name)) self.virtualMachine.attach_volume(apiclient, volume=volume_1) self.debug("Attaching volume %s to vm %s" % (volume_2.name, self.virtualMachine.name)) self.virtualMachine.attach_volume(apiclient, volume=volume_2) except Exception as e: self.fail("Failure: %s" % e) expectedCount = self.initialResourceCount + 15 # (5 + 10) response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: # Detaching and deleting volume 1 self.virtualMachine.detach_volume(apiclient, volume=volume_1) volume_1.delete(apiclient) except Exception as e: self.fail("Failure while volume operation: %s" % e) expectedCount -= 5 #After deleting first volume response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: # Detaching and deleting volume 2 self.virtualMachine.detach_volume(apiclient, volume=volume_2) volume_2.delete(apiclient) except Exception as e: self.fail("Failure while volume operation: %s" % e) expectedCount -= 10 response = matchResourceCount( self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_attach_detach_volume(self, value): """Stop attach and detach volume from VM # Validate the following # 1. Create a VM with custom disk offering and check the primary storage count # of account # 2. Create custom volume in account # 3. Verify that primary storage count increases by same amount # 4. Attach volume to VM and verify resource count remains the same # 5. Detach volume and verify resource count remains the same""" response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) apiclient = self.apiclient if value == CHILD_DOMAIN_ADMIN: apiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.assertNotEqual( apiclient, FAIL, "Failure while getting\ api client of account: %s" % self.account.name) try: self.services["disk_offering"]["disksize"] = 4 expectedCount = self.initialResourceCount + int( self.services["disk_offering"]["disksize"]) disk_offering = DiskOffering.create( self.apiclient, services=self.services["disk_offering"]) self.cleanup.append(disk_offering) volume = Volume.create(apiclient, self.services["volume"], zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid, diskofferingid=disk_offering.id) except Exception as e: self.fail("Failure: %s" % e) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.virtualMachine.attach_volume(apiclient, volume=volume) except Exception as e: self.fail("Failed while attaching volume to VM: %s" % e) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.virtualMachine.detach_volume(apiclient, volume=volume) except Exception as e: self.fail("Failure while detaching volume: %s" % e) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return
def test_08_increase_volume_size_within_account_limit(self): """Test increasing volume size within the account limit and verify primary storage usage # Validate the following # 1. Create a domain and its admin account # 2. Set account primary storage limit well beyond (20 GB volume + # template size of VM) # 3. Deploy a VM without any disk offering (only root disk) # # 4. Increase (resize) the volume to 20 GB # 6. Resize operation should be successful and primary storage count # for account should be updated successfully""" # Setting up account and domain hierarchy result = self.setupAccounts() self.assertEqual(result[0], PASS, result[1]) apiclient = self.testClient.getUserApiClient( UserName=self.parentd_admin.name, DomainName=self.parentd_admin.domain) self.assertNotEqual( apiclient, FAILED, "Failed to get api client\ of account: %s" % self.parentd_admin.name) templateSize = (self.template.size / (1024**3)) accountLimit = (templateSize + 20) response = self.updateResourceLimits(accountLimit=accountLimit) self.assertEqual(response[0], PASS, response[1]) try: if self.updateclone: self.virtual_machine = VirtualMachine.create( apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.services_offering_vmware.id) else: self.virtual_machine = VirtualMachine.create( apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.service_offering.id) list_vms = VirtualMachine.list(apiclient, id=self.virtual_machine.id) self.debug( "Verify listVirtualMachines response for virtual machine: %s" \ % self.virtual_machine.id ) self.assertEqual(isinstance(list_vms, list), True, "List VM response was not a valid list") self.cleanup.append(self.virtual_machine) self.cleanup.reverse() vm = list_vms[0] list_volume_response = Volume.list( apiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall='True') res = validateList(list_volume_response) self.assertNotEqual( res[2], INVALID_INPUT, "listVolumes returned invalid object in response") if vm.state == "Running" and vm.hypervisor.lower() == "xenserver": self.virtual_machine.stop(self.apiclient) time.sleep(self.services["sleep"]) rootvolume = list_volume_response[0] # converting json response to Volume Object rootvol = Volume(rootvolume.__dict__) newsize = (rootvolume.size >> 30) + 20 if rootvolume is not None: try: rootvol.resize(apiclient, size=newsize) response = matchResourceCount( self.apiclient, newsize, RESOURCE_PRIMARY_STORAGE, accountid=self.parentd_admin.id) if response[0] == FAIL: raise Exception(response[1]) except Exception as e: self.fail("Failed with exception: %s" % e) except Exception as e: raise Exception("Warning: Exception while checking primary" " storage capacity after root " "volume resize : %s" % e) return
def test_00_deploy_vm_root_resize(self): """Test deploy virtual machine with root resize # Validate the following: # 1. listVirtualMachines returns accurate information # 2. root disk has new size per listVolumes # 3. Rejects non-supported hypervisor types """ newrootsize = (self.template.size >> 30) + 2 if (self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() == 'xenserver' or self.hypervisor.lower() == 'vmware' or self.hypervisor.lower() == 'simulator'): accounts = Account.list(self.apiclient, id=self.account.id) self.assertEqual( validateList(accounts)[0], PASS, "accounts list validation failed") initialResourceCount = int(accounts[0].primarystoragetotal) if self.hypervisor == "vmware": self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], zoneid=self.zone.id, accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.services_offering_vmware.id, templateid=self.template.id, rootdisksize=newrootsize) else: self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], zoneid=self.zone.id, accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.service_offering.id, templateid=self.template.id, rootdisksize=newrootsize) list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) self.debug( "Verify listVirtualMachines response for virtual machine: %s" \ % self.virtual_machine.id ) res = validateList(list_vms) self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list VM " "response") self.cleanup.append(self.virtual_machine) vm = list_vms[0] self.assertEqual(vm.id, self.virtual_machine.id, "Virtual Machine ids do not match") self.assertEqual(vm.name, self.virtual_machine.name, "Virtual Machine names do not match") self.assertEqual(vm.state, "Running", msg="VM is not in Running state") # get root vol from created vm, verify it is correct size list_volume_response = list_volumes( self.apiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall=True) res = validateList(list_volume_response) self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list VM " "response") rootvolume = list_volume_response[0] success = False if rootvolume is not None and rootvolume.size == ( newrootsize << 30): success = True self.assertEqual(success, True, "Check if the root volume resized appropriately") response = matchResourceCount(self.apiclient, (initialResourceCount + newrootsize), RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) else: self.debug( "hypervisor %s unsupported for test 00, verifying it errors properly" % self.hypervisor) newrootsize = (self.template.size >> 30) + 2 success = False try: self.virtual_machine = VirtualMachine.create( self.apiclient, self.testdata["virtual_machine"], accountid=self.account.name, zoneid=self.zone.id, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=self.template.id, rootdisksize=newrootsize) except Exception as ex: if re.search( "Hypervisor \S+ does not support rootdisksize override", str(ex)): success = True else: self.debug( "Virtual machine create did not fail appropriately. Error was actually : " + str(ex)) self.assertEqual( success, True, "Check if unsupported hypervisor %s fails appropriately" % self.hypervisor)
def test_08_increase_volume_size_within_account_limit(self): """Test increasing volume size within the account limit and verify primary storage usage # Validate the following # 1. Create a domain and its admin account # 2. Set account primary storage limit well beyond (20 GB volume + # template size of VM) # 3. Deploy a VM without any disk offering (only root disk) # # 4. Increase (resize) the volume to 20 GB # 6. Resize operation should be successful and primary storage count # for account should be updated successfully""" # Setting up account and domain hierarchy result = self.setupAccounts() self.assertEqual(result[0], PASS, result[1]) apiclient = self.testClient.getUserApiClient( UserName=self.parentd_admin.name, DomainName=self.parentd_admin.domain) self.assertNotEqual(apiclient, FAILED, "Failed to get api client\ of account: %s" % self.parentd_admin.name) templateSize = (self.template.size / (1024 ** 3)) accountLimit = (templateSize + 20) response = self.updateResourceLimits(accountLimit=accountLimit) self.assertEqual(response[0], PASS, response[1]) try: if self.updateclone: self.virtual_machine = VirtualMachine.create( apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.services_offering_vmware.id ) else: self.virtual_machine = VirtualMachine.create( apiclient, self.services["virtual_machine"], accountid=self.parentd_admin.name, domainid=self.parent_domain.id, serviceofferingid=self.service_offering.id ) list_vms = VirtualMachine.list(apiclient, id=self.virtual_machine.id) self.debug( "Verify listVirtualMachines response for virtual machine: %s" \ % self.virtual_machine.id ) self.assertEqual( isinstance(list_vms, list), True, "List VM response was not a valid list" ) self.cleanup.append(self.virtual_machine) self.cleanup.reverse() vm = list_vms[0] list_volume_response = Volume.list( apiclient, virtualmachineid= self.virtual_machine.id, type='ROOT', listall='True' ) res = validateList(list_volume_response) self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response") if vm.state == "Running" and \ (vm.hypervisor.lower() == "xenserver" or vm.hypervisor.lower() == "vmware"): self.virtual_machine.stop(self.apiclient) time.sleep(self.services["sleep"]) rootvolume = list_volume_response[0] # converting json response to Volume Object rootvol = Volume(rootvolume.__dict__) newsize = (rootvolume.size >> 30) + 20 if rootvolume is not None: try: rootvol.resize(apiclient, size=newsize) response = matchResourceCount( self.apiclient, newsize, RESOURCE_PRIMARY_STORAGE, accountid=self.parentd_admin.id) if response[0] == FAIL: raise Exception(response[1]) except Exception as e: self.fail("Failed with exception: %s" % e) except Exception as e: raise Exception("Warning: Exception while checking primary" " storage capacity after root " "volume resize : %s" % e) return
def test_create_template_snapshot(self, value): """Test create snapshot and templates from volume # Validate the following # 1. Deploy VM with custoom disk offering and check the # primary storage resource count # 2. Stop the VM and create Snapshot from VM's volume # 3. Create volume againt from this snapshto and attach to VM # 4. Verify that primary storage count increases by the volume size # 5. Detach and delete volume, verify primary storage count decreaes by volume size""" response = self.setupAccount(value) self.debug(response[0]) self.debug(response[1]) self.assertEqual(response[0], PASS, response[1]) apiclient = self.apiclient if value == CHILD_DOMAIN_ADMIN: apiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) self.assertNotEqual( apiclient, FAIL, "Failure while getting api\ client of account: %s" % self.account.name) try: self.virtualMachine.stop(apiclient) except Exception as e: self.fail("Failed to stop instance: %s" % e) expectedCount = self.initialResourceCount response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) self.debug("Creating snapshot from ROOT volume: %s" % self.virtualMachine.name) snapshot = None response = createSnapshotFromVirtualMachineVolume( apiclient, self.account, self.virtualMachine.id) self.assertEqual(response[0], PASS, response[1]) snapshot = response[1] response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.services["volume"]["size"] = self.services["disk_offering"][ "disksize"] volume = Volume.create_from_snapshot( apiclient, snapshot_id=snapshot.id, services=self.services["volume"], account=self.account.name, domainid=self.account.domainid) self.debug("Attaching the volume to vm: %s" % self.virtualMachine.name) self.virtualMachine.attach_volume(apiclient, volume) except Exception as e: self.fail("Failure in volume operation: %s" % e) expectedCount += int(self.services["volume"]["size"]) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.virtualMachine.detach_volume(apiclient, volume) except Exception as e: self.fail("Failure in detach volume operation: %s" % e) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) try: self.debug("deleting the volume: %s" % volume.name) volume.delete(apiclient) except Exception as e: self.fail("Failure while deleting volume: %s" % e) expectedCount -= int(self.services["volume"]["size"]) response = matchResourceCount(self.apiclient, expectedCount, RESOURCE_PRIMARY_STORAGE, accountid=self.account.id) self.assertEqual(response[0], PASS, response[1]) return