mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
migrate only when hosts are available
Identify the hosts that are suitable for migration before proceeding with migrateVM Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
parent
92e6352287
commit
e1ad36bccb
@ -135,35 +135,34 @@ class TestDeployVM(cloudstackTestCase):
|
|||||||
cls.apiclient = super(TestDeployVM, cls).getClsTestClient().getApiClient()
|
cls.apiclient = super(TestDeployVM, cls).getClsTestClient().getApiClient()
|
||||||
# Get Zone, Domain and templates
|
# Get Zone, Domain and templates
|
||||||
domain = get_domain(cls.apiclient, cls.services)
|
domain = get_domain(cls.apiclient, cls.services)
|
||||||
zone = get_zone(cls.apiclient, cls.services)
|
cls.zone = get_zone(cls.apiclient, cls.services)
|
||||||
cls.services['mode'] = zone.networktype
|
cls.services['mode'] = cls.zone.networktype
|
||||||
|
|
||||||
#If local storage is enabled, alter the offerings to use localstorage
|
#If local storage is enabled, alter the offerings to use localstorage
|
||||||
#this step is needed for devcloud
|
#this step is needed for devcloud
|
||||||
if zone.localstorageenabled == True:
|
if cls.zone.localstorageenabled == True:
|
||||||
cls.services["service_offerings"]["tiny"]["storagetype"] = 'local'
|
cls.services["service_offerings"]["tiny"]["storagetype"] = 'local'
|
||||||
cls.services["service_offerings"]["small"]["storagetype"] = 'local'
|
cls.services["service_offerings"]["small"]["storagetype"] = 'local'
|
||||||
cls.services["service_offerings"]["medium"]["storagetype"] = 'local'
|
cls.services["service_offerings"]["medium"]["storagetype"] = 'local'
|
||||||
|
|
||||||
template = get_template(
|
template = get_template(
|
||||||
cls.apiclient,
|
cls.apiclient,
|
||||||
zone.id,
|
cls.zone.id,
|
||||||
cls.services["ostype"]
|
cls.services["ostype"]
|
||||||
)
|
)
|
||||||
# Set Zones and disk offerings
|
# Set Zones and disk offerings
|
||||||
cls.services["small"]["zoneid"] = zone.id
|
cls.services["small"]["zoneid"] = cls.zone.id
|
||||||
cls.services["small"]["template"] = template.id
|
cls.services["small"]["template"] = template.id
|
||||||
|
|
||||||
cls.services["medium"]["zoneid"] = zone.id
|
cls.services["medium"]["zoneid"] = cls.zone.id
|
||||||
cls.services["medium"]["template"] = template.id
|
cls.services["medium"]["template"] = template.id
|
||||||
cls.services["iso"]["zoneid"] = zone.id
|
cls.services["iso"]["zoneid"] = cls.zone.id
|
||||||
|
|
||||||
cls.account = Account.create(
|
cls.account = Account.create(
|
||||||
cls.apiclient,
|
cls.apiclient,
|
||||||
cls.services["account"],
|
cls.services["account"],
|
||||||
domainid=domain.id
|
domainid=domain.id
|
||||||
)
|
)
|
||||||
cls.debug(str("============" ))
|
|
||||||
cls.debug(cls.account.id)
|
cls.debug(cls.account.id)
|
||||||
|
|
||||||
cls.service_offering = ServiceOffering.create(
|
cls.service_offering = ServiceOffering.create(
|
||||||
@ -811,17 +810,15 @@ class TestVMLifeCycle(cloudstackTestCase):
|
|||||||
"""Test migrate VM
|
"""Test migrate VM
|
||||||
"""
|
"""
|
||||||
# Validate the following
|
# Validate the following
|
||||||
# 1. Should be able to login to the VM.
|
# 1. Environment has enough hosts for migration
|
||||||
# 2. listVM command should return this VM.State of this VM
|
# 2. DeployVM on suitable host (with another host in the cluster)
|
||||||
# should be "Running" and the host should be the host
|
# 3. Migrate the VM and assert migration successful
|
||||||
# to which the VM was migrated to
|
|
||||||
|
|
||||||
hosts = Host.list(
|
hosts = Host.list(
|
||||||
self.apiclient,
|
self.apiclient,
|
||||||
zoneid=self.medium_virtual_machine.zoneid,
|
zoneid=self.zone.id,
|
||||||
type='Routing'
|
type='Routing'
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
isinstance(hosts, list),
|
isinstance(hosts, list),
|
||||||
True,
|
True,
|
||||||
@ -830,49 +827,59 @@ class TestVMLifeCycle(cloudstackTestCase):
|
|||||||
self.assertGreaterEqual(
|
self.assertGreaterEqual(
|
||||||
len(hosts),
|
len(hosts),
|
||||||
2,
|
2,
|
||||||
"Atleast 2 hosts should be present in a zone for VM migration"
|
"Atleast 2 hosts should be present for VM migration"
|
||||||
)
|
)
|
||||||
# Remove the host of current VM from the hosts list
|
|
||||||
hosts[:] = [host for host in hosts if host.id != self.medium_virtual_machine.hostid]
|
|
||||||
|
|
||||||
host = hosts[0]
|
#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("Migration needs a cluster with at least two hosts")
|
||||||
|
|
||||||
|
suitable_hosts = [host for host in hosts if host.clusterid == clusters[0]]
|
||||||
|
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.debug("Migrating VM-ID: %s to Host: %s" % (
|
||||||
self.medium_virtual_machine.id,
|
self.vm_to_migrate.id,
|
||||||
host.id
|
migrate_host.id
|
||||||
))
|
))
|
||||||
|
|
||||||
cmd = migrateVirtualMachine.migrateVirtualMachineCmd()
|
self.vm_to_migrate.migrate(self.api_client, migrate_host.id)
|
||||||
cmd.hostid = host.id
|
|
||||||
cmd.virtualmachineid = self.medium_virtual_machine.id
|
|
||||||
self.apiclient.migrateVirtualMachine(cmd)
|
|
||||||
|
|
||||||
list_vm_response = list_virtual_machines(
|
list_vm_response = list_virtual_machines(
|
||||||
self.apiclient,
|
self.apiclient,
|
||||||
id=self.medium_virtual_machine.id
|
id=self.vm_to_migrate.id
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
|
||||||
isinstance(list_vm_response, list),
|
|
||||||
True,
|
|
||||||
"Check list response returns a valid list"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
list_vm_response,
|
list_vm_response,
|
||||||
None,
|
None,
|
||||||
"Check virtual machine is listVirtualMachines"
|
"Check virtual machine is listed"
|
||||||
)
|
)
|
||||||
|
|
||||||
vm_response = list_vm_response[0]
|
vm_response = list_vm_response[0]
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
vm_response.id,
|
vm_response.id,
|
||||||
self.medium_virtual_machine.id,
|
self.vm_to_migrate.id,
|
||||||
"Check virtual machine ID of migrated VM"
|
"Check virtual machine ID of migrated VM"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
vm_response.hostid,
|
vm_response.hostid,
|
||||||
host.id,
|
migrate_host.id,
|
||||||
"Check destination hostID of migrated VM"
|
"Check destination hostID of migrated VM"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@ -964,6 +971,9 @@ class TestVMLifeCycle(cloudstackTestCase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ssh_client = self.virtual_machine.get_ssh_client()
|
ssh_client = self.virtual_machine.get_ssh_client()
|
||||||
|
except Exception as e:
|
||||||
|
self.fail("SSH failed for virtual machine: %s - %s" %
|
||||||
|
(self.virtual_machine.ipaddress, e))
|
||||||
|
|
||||||
cmds = [
|
cmds = [
|
||||||
"mkdir -p %s" % self.services["mount_dir"],
|
"mkdir -p %s" % self.services["mount_dir"],
|
||||||
@ -973,20 +983,13 @@ class TestVMLifeCycle(cloudstackTestCase):
|
|||||||
self.services["mount_dir"]
|
self.services["mount_dir"]
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
for c in cmds:
|
for c in cmds:
|
||||||
res = ssh_client.execute(c)
|
res = ssh_client.execute(c)
|
||||||
|
|
||||||
self.assertEqual(res, [], "Check mount is successful or not")
|
self.assertEqual(res, [], "Check mount is successful or not")
|
||||||
|
|
||||||
c = "fdisk -l|grep %s|head -1" % self.services["diskdevice"]
|
c = "fdisk -l|grep %s|head -1" % self.services["diskdevice"]
|
||||||
res = ssh_client.execute(c)
|
res = ssh_client.execute(c)
|
||||||
#Disk /dev/xvdd: 4393 MB, 4393723904 bytes
|
#Disk /dev/xvdd: 4393 MB, 4393723904 bytes
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
self.fail("SSH failed for virtual machine: %s - %s" %
|
|
||||||
(self.virtual_machine.ipaddress, e))
|
|
||||||
|
|
||||||
# Res may contain more than one strings depending on environment
|
# Res may contain more than one strings depending on environment
|
||||||
# Split strings to form new list which is used for assertion on ISO size
|
# Split strings to form new list which is used for assertion on ISO size
|
||||||
result = []
|
result = []
|
||||||
@ -1015,7 +1018,6 @@ class TestVMLifeCycle(cloudstackTestCase):
|
|||||||
#Unmount ISO
|
#Unmount ISO
|
||||||
command = "umount %s" % self.services["mount_dir"]
|
command = "umount %s" % self.services["mount_dir"]
|
||||||
ssh_client.execute(command)
|
ssh_client.execute(command)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail("SSH failed for virtual machine: %s - %s" %
|
self.fail("SSH failed for virtual machine: %s - %s" %
|
||||||
(self.virtual_machine.ipaddress, e))
|
(self.virtual_machine.ipaddress, e))
|
||||||
@ -1027,7 +1029,6 @@ class TestVMLifeCycle(cloudstackTestCase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
res = ssh_client.execute(c)
|
res = ssh_client.execute(c)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail("SSH failed for virtual machine: %s - %s" %
|
self.fail("SSH failed for virtual machine: %s - %s" %
|
||||||
(self.virtual_machine.ipaddress, e))
|
(self.virtual_machine.ipaddress, e))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user