def test_08_migrate_vm(self): """Test migrate VM """ # Validate the following # 1. Environment has enough hosts for migration # 2. DeployVM on suitable host (with another host in the cluster) # 3. Migrate the VM and assert migration successful suitable_hosts = None hosts = Host.list(self.apiclient, zoneid=self.zone.id, type='Routing') self.assertEqual( validateList(hosts)[0], PASS, "hosts list validation failed") if len(hosts) < 2: self.skipTest( "At least two hosts should be present in the zone for migration" ) hypervisor = str(get_hypervisor_type(self.apiclient)).lower() # For KVM, two hosts used for migration should be present in same cluster # For XenServer and VMware, migration is possible between hosts belonging to different clusters # with the help of XenMotion and Vmotion respectively. if hypervisor == "kvm": #identify suitable host clusters = [h.clusterid for h in hosts] #find hosts withe same clusterid clusters = [ cluster for index, cluster in enumerate(clusters) if clusters.count(cluster) > 1 ] if len(clusters) <= 1: self.skipTest( "In KVM, Live Migration needs two hosts within same cluster" ) suitable_hosts = [ host for host in hosts if host.clusterid == clusters[0] ] else: suitable_hosts = hosts target_host = suitable_hosts[0] migrate_host = suitable_hosts[1] #deploy VM on target host self.vm_to_migrate = VirtualMachine.create( self.api_client, self.services["small"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.small_offering.id, mode=self.services["mode"], hostid=target_host.id) self.debug("Migrating VM-ID: %s to Host: %s" % (self.vm_to_migrate.id, migrate_host.id)) self.vm_to_migrate.migrate(self.api_client, migrate_host.id) list_vm_response = list_virtual_machines(self.apiclient, id=self.vm_to_migrate.id) self.assertNotEqual(list_vm_response, None, "Check virtual machine is listed") vm_response = list_vm_response[0] self.assertEqual(vm_response.id, self.vm_to_migrate.id, "Check virtual machine ID of migrated VM") self.assertEqual(vm_response.hostid, migrate_host.id, "Check destination hostID of migrated VM") return
def test_08_migrate_vm(self): """Test migrate VM """ # Validate the following # 1. Environment has enough hosts for migration # 2. DeployVM on suitable host (with another host in the cluster) # 3. Migrate the VM and assert migration successful suitable_hosts = None hosts = Host.list( self.apiclient, zoneid=self.zone.id, type='Routing' ) self.assertEqual(validateList(hosts)[0], PASS, "hosts list validation failed") if len(hosts) < 2: self.skipTest("At least two hosts should be present in the zone for migration") hypervisor = str(get_hypervisor_type(self.apiclient)).lower() # For KVM, two hosts used for migration should be present in same cluster # For XenServer and VMware, migration is possible between hosts belonging to different clusters # with the help of XenMotion and Vmotion respectively. if hypervisor == "kvm": #identify suitable host clusters = [h.clusterid for h in hosts] #find hosts withe same clusterid clusters = [cluster for index, cluster in enumerate(clusters) if clusters.count(cluster) > 1] if len(clusters) <= 1: self.skipTest("In KVM, Live Migration needs two hosts within same cluster") suitable_hosts = [host for host in hosts if host.clusterid == clusters[0]] else: suitable_hosts = hosts target_host = suitable_hosts[0] migrate_host = suitable_hosts[1] #deploy VM on target host self.vm_to_migrate = VirtualMachine.create( self.api_client, self.services["small"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.small_offering.id, mode=self.services["mode"], hostid=target_host.id ) self.debug("Migrating VM-ID: %s to Host: %s" % ( self.vm_to_migrate.id, migrate_host.id )) self.vm_to_migrate.migrate(self.api_client, migrate_host.id) list_vm_response = list_virtual_machines( self.apiclient, id=self.vm_to_migrate.id ) self.assertNotEqual( list_vm_response, None, "Check virtual machine is listed" ) vm_response = list_vm_response[0] self.assertEqual( vm_response.id, self.vm_to_migrate.id, "Check virtual machine ID of migrated VM" ) self.assertEqual( vm_response.hostid, migrate_host.id, "Check destination hostID of migrated VM" ) return