image_copy is used to copy guests' images from NFS server to test machines. It takes too much time for installing guests everytime. You can config NFS server directory in tests_base.cfg. Signed-off-by: Amos Kong <akong@xxxxxxxxxx> --- client/tests/kvm/tests/image_copy.py | 45 ++++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 9 ++++++ 2 files changed, 54 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/image_copy.py diff --git a/client/tests/kvm/tests/image_copy.py b/client/tests/kvm/tests/image_copy.py new file mode 100644 index 0000000..61f0bb5 --- /dev/null +++ b/client/tests/kvm/tests/image_copy.py @@ -0,0 +1,45 @@ +import os, logging, commands +from autotest_lib.client.common_lib import error +import kvm_utils + +def run_image_copy(test, params, env): + """ + Copy guest images from nfs server. + 1) Mount the NFS directory + 2) Check the existence of source image + 3) If existence copy the image from NFS + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + mount_dest_dir = params.get("dst_dir",'/mnt/images') + try: + os.makedirs(mount_dest_dir) + except OSError, err: + logging.warn("mkdir %s error:\n%s" % (mount_dest_dir, err)) + + if not os.path.exists(mount_dest_dir): + raise error.TestError("Failed to mkdir %s" % mount_dest_dir) + logging.debug("Dir %s exists." % mount_dest_dir) + + src = params.get('images_good') + mnt_cmd = "mount %s %s -o ro" % (src, mount_dest_dir) + pwd = os.path.join(os.environ['AUTODIR'],'tests/kvm/images') + image = os.path.split(params['image_name'])[1]+'.'+params['image_format'] + src_path = os.path.join(mount_dest_dir, image) + dst_path = os.path.join(pwd, image) + cmd = "cp %s %s" % (src_path, dst_path) + + if kvm_utils.mount(src, mount_dest_dir, "nfs", "ro") is not True: + raise error.TestError("Fail to mount the %s to %s" % \ + (src, mount_dest_dir)) + + # Check the existence of source image + if not os.path.exists(src_path): + raise error.TestError("Could not found %s in src directory" % src_path) + + logging.debug("Copying image %s..." % image) + s, o = commands.getstatusoutput(cmd) + if s != 0: + raise error.TestFail("Failed to copy image:%s; Reason: %s" % (cmd, o)) diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 4075bfc..5c40ac3 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -63,6 +63,9 @@ profilers = kvm_stat login_timeout = 360 image_raw_device = no +# NFS directory of guests' images +images_good = 0.0.0.0:/autotest/images_good + # Tests variants: - install: @@ -75,6 +78,12 @@ variants: kill_vm_timeout = 60 kill_vm_timeout_on_error = 0 + - image_copy: + type = image_copy + vms = '' + parallel = no + profilers = + - setup: install type = steps fail_if_stuck_for = 300 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html