# HG changeset patch
# User Deepti B. Kalakeri<deeptik(a)linux.vnet.ibm.com>
# Date 1238772223 25200
# Node ID 8923fbe5cb2a4321feff81be63a6c458ebdae52d
# Parent bfd8818c151aec7e9fa8a675fe29e03e4e07824e
[TEST] Adding remote_copy_guest_image() to vsmigration.py.
This is needed to make sure that we have the required image files
on the destination for the remote migration tests to be successful.
Tested for KVM and Xen with current sources.
Signed-off-by: Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
diff -r bfd8818c151a -r 8923fbe5cb2a suites/libvirt-cim/lib/XenKvmLib/vsmigrations.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vsmigrations.py Sun Mar 29 16:04:03 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vsmigrations.py Fri Apr 03 08:23:43 2009 -0700
@@ -21,16 +21,19 @@
#
#
+import random
from time import sleep
+from VirtLib import utils
from pywbem import WBEMConnection, CIMInstanceName
from CimTest.CimExt import CIMMethodClass, CIMClassMOF
from CimTest.ReturnCodes import PASS, FAIL
-from XenKvmLib import enumclass
+from XenKvmLib.enumclass import EnumInstances
from XenKvmLib.classes import get_typed_class, virt_types
from XenKvmLib.xm_virt_util import domain_list
from XenKvmLib.const import get_provider_version
from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS, \
CIM_ERROR_ENUMERATE
+
# Migration constants
CIM_MIGRATE_OFFLINE=1
CIM_MIGRATE_LIVE=2
@@ -129,6 +132,41 @@
return msd.mof()
+def remote_copy_guest_image(virt, s_sysname, t_sysname, test_dom):
+ cn_name = get_typed_class(virt, 'DiskResourceAllocationSettingData')
+ req_image = backup_image = None
+ try:
+ d_rasds = EnumInstances(s_sysname, cn_name, ret_cim_inst=True)
+ for d_rasd in d_rasds:
+ if test_dom in d_rasd["InstanceID"]:
+ req_image = d_rasd["Address"]
+ break
+
+ if req_image == None:
+ logger.error("Failed to get Disk RASD info for '%s'",
test_dom)
+ return FAIL, req_image, backup_image
+
+ # Check if the image file with the same name already exist on the machine.
+ # Back it up. Copy the required working image to the destination.
+ cmd = "/bin/ls -l %s" % req_image
+ rc, out = utils.run_remote(t_sysname, cmd)
+ if rc == 0:
+ backup_image = req_image + "." + str(random.randint(1, 100))
+ cmd = 'mv %s %s' % (req_image, backup_image)
+ rc, out = utils.run_remote(t_sysname, cmd)
+
+ s, o = utils.copy_remote(t_sysname, req_image, remote=req_image)
+ if s != 0:
+ logger.error("Failed to copy the image file '%s' for
migration"\
+ " to '%s'", req_image, t_sysname)
+ return FAIL, req_image, backup_image
+ except Exception, details:
+ logger.error("Exception in remote_copy_guest_image()")
+ logger.error("Exception details %s", details)
+ return FAIL, req_image, backup_image
+
+ return PASS, req_image, backup_image
+
def check_possible_host_migration(service, cs_ref, ip, msd=None):
res = None
try:
@@ -181,7 +219,7 @@
mig_job_cn = get_typed_class(virt, 'MigrationJob')
try:
- job = enumclass.EnumInstances(src_ip, mig_job_cn)
+ job = EnumInstances(src_ip, mig_job_cn)
if len(job) < 1:
logger.error("'%s' returned empty list", mig_job_cn)
return FAIL, None
@@ -285,6 +323,14 @@
logger.error("Guest to be migrated not specified.")
return FAIL
+ if remote_migrate == 1:
+ status, req_image, backup_image = remote_copy_guest_image(virt,
+ s_sysname,
+ t_sysname,
+ guest_name)
+ if status != PASS:
+ return status
+
# Get the guest ref
guest_ref = get_guest_ref(guest_name, virt)
if guest_ref == None or guest_ref['Name'] != guest_name:
@@ -320,4 +366,15 @@
status = check_migration_job(s_sysname, id, t_sysname, guest_name,
remote_migrate, virt, timeout=time_out)
+ # Make sure we do not remove the images on the local machine
+ if remote_migrate == 1:
+ # Cleanup the images that is copied on the remote machine
+ cmd = "rm -rf %s" % req_image
+ rc, out = utils.run_remote(t_sysname, cmd)
+
+ # Copy the backed up image if any on the remote machine
+ if backup_image != None:
+ cmd = 'mv %s %s' % (backup_image, req_image)
+ rc, out = utils.run_remote(t_sysname, cmd)
+
return status