def test_12_move_across_subdomain_vm_volumes(self): """Test as domain admin, stop a VM from subdomain1 and attempt to move it to subdomain2 """ # Validate the following: # 1. deploy VM in sub subdomain1 with volumes. # 3. assignVirtualMachine to subdomain2 userapiclient = self.testClient.getUserApiClient( account=self.sdomain_account_user1['account'].name, domain=self.sdomain_account_user1['domain'].name, type=2) self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'], volume=self.sdomain_account_user1['volume']) self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, userapiclient, self.sdomain_account_user2['account'].name, self.sdomain_account_user2['domain'].id) # Check all volumes attached to same VM list_volume_response = list_volumes( self.apiclient, virtualmachineid=self.virtual_machine.id, type='DATADISK', listall=True) self.assertEqual(isinstance(list_volume_response, list), True, "Check list volumes response for valid list") self.assertNotEqual(list_volume_response[0].domainid, self.sdomain_account_user2['domain'].id, "Volume ownership not changed.") self.virtual_machine.detach_volume( self.apiclient, self.sdomain_account_user1['volume'])
def test_12_move_across_subdomain_vm_volumes(self): """Test as domain admin, stop a VM from subdomain1 and attempt to move it to subdomain2 """ # Validate the following: # 1. deploy VM in sub subdomain1 with volumes. # 3. assignVirtualMachine to subdomain2 self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'],volume=self.sdomain_account_user1['volume']) self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, self.apiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id) # Check all volumes attached to same VM list_volume_response = list_volumes(self.apiclient, virtualmachineid=self.virtual_machine.id, type='DATADISK', listall=True) self.assertEqual(isinstance(list_volume_response, list), True, "Check list volumes response for valid list") self.assertNotEqual(list_volume_response[0].domainid, self.sdomain_account_user2['domain'].id, "Volume ownership not changed.")
def create_vm(self, account, domain, isRunning=False, project =None, limit =None, pfrule =False, lbrule =None, natrule =None, volume =None, snapshot =False): #TODO: Implemnt pfrule/lbrule/natrule self.debug("Deploying instance in the account: %s" % account.name) self.virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], accountid=account.name, domainid=domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype if pfrule else 'basic', projectid=project.id if project else None) self.debug("Deployed instance in account: %s" % account.name) list_virtual_machines(self.apiclient, id=self.virtual_machine.id) if snapshot: volumes = list_volumes(self.apiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall=True) self.snapshot = Snapshot.create(self.apiclient, volumes[0].id, account=account.name, domainid=account.domainid) if volume: self.virtual_machine.attach_volume(self.apiclient, volume) if not isRunning: self.virtual_machine.stop(self.apiclient) self.cleanup.append(self.virtual_machine)
def create_vm(self, account, domain, isRunning=False, project=None, limit=None, pfrule=False, lbrule=None, natrule=None, volume=None, snapshot=False): #TODO: Implemnt pfrule/lbrule/natrule self.debug("Deploying instance in the account: %s" % account.name) self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=account.name, domainid=domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype if pfrule else 'basic', projectid=project.id if project else None) self.debug("Deployed instance in account: %s" % account.name) list_virtual_machines(self.apiclient, id=self.virtual_machine.id) if snapshot: volumes = list_volumes(self.apiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall=True) self.snapshot = Snapshot.create(self.apiclient, volumes[0].id, account=account.name, domainid=account.domainid) if volume: self.virtual_machine.attach_volume(self.apiclient, volume) if not isRunning: self.virtual_machine.stop(self.apiclient) self.cleanup.append(self.virtual_machine)
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 """ if(self.apiclient.hypervisor == 'kvm'): newrootsize = (self.template.size >> 30) + 2 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 ) list_vms = VirtualMachine.list(self.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.assertNotEqual( len(list_vms), 0, "List VM response was empty" ) 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 ) 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" ) else: self.debug("hypervisor %s unsupported for test 00, verifying it errors properly" % self.apiclient.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 "Hypervisor XenServer does not support rootdisksize override" in 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.apiclient.hypervisor)