* [Autotest PATCH] KVM-test: Add a subtest image_copy
@ 2010-01-04 9:30 Yolkfull Chow
2010-01-04 14:52 ` [Autotest] " Amos Kong
0 siblings, 1 reply; 4+ messages in thread
From: Yolkfull Chow @ 2010-01-04 9:30 UTC (permalink / raw)
To: autotest; +Cc: kvm, Yolkfull Chow
Add image_copy subtest for convenient KVM functional testing.
The target image will be copied into the linked directory if link 'images'
is created, and copied to the directory specified in config file otherwise.
Signed-off-by: Yolkfull Chow <yzhou@redhat.com>
---
client/tests/kvm/kvm_utils.py | 64 ++++++++++++++++++++++++++++++++
client/tests/kvm/tests/image_copy.py | 42 +++++++++++++++++++++
client/tests/kvm/tests_base.cfg.sample | 6 +++
3 files changed, 112 insertions(+), 0 deletions(-)
create mode 100644 client/tests/kvm/tests/image_copy.py
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 2bbbe22..1e11441 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -924,3 +924,67 @@ def create_report(report_dir, results_dir):
reporter = os.path.join(report_dir, 'html_report.py')
html_file = os.path.join(results_dir, 'results.html')
os.system('%s -r %s -f %s -R' % (reporter, results_dir, html_file))
+
+
+def is_dir_mounted(source, dest, type, perm):
+ """
+ Check whether `source' is mounted on `dest' with right permission.
+
+ @source: mount source
+ @dest: mount point
+ @type: file system type
+ """
+ match_string = "%s %s %s %s" % (source, dest, type, perm)
+ try:
+ f = open("/etc/mtab", "r")
+ except IOError:
+ pass
+ mounted = f.read()
+ f.close()
+ if match_string in mounted:
+ return True
+ return False
+
+
+def umount(mount_point):
+ """
+ Umount `mount_point'.
+
+ @mount_point: mount point
+ """
+ cmd = "umount %s" % mount_point
+ s, o = commands.getstatusoutput(cmd)
+ if s != 0:
+ logging.error("Fail to umount: %s" % o)
+ return False
+ return True
+
+
+def mount(src, mount_point, type, perm = "rw"):
+ """
+ Mount the src into mount_point of the host.
+
+ @src: mount source
+ @mount_point: mount point
+ @type: file system type
+ @perm: mount permission
+ """
+ if is_dir_mounted(src, mount_point, type, perm):
+ return True
+
+ umount(mount_point)
+
+ cmd = "mount -t %s %s %s -o %s" % (type, src, mount_point, perm)
+ logging.debug("Issue mount command: %s" % cmd)
+ s, o = commands.getstatusoutput(cmd)
+ if s != 0:
+ logging.error("Fail to mount: %s " % o)
+ return False
+
+ if is_dir_mounted(src, mount_point, type, perm):
+ logging.info("Successfully mounted %s" % src)
+ return True
+ else:
+ logging.error("Mount verification failed; currently mounted: %s" %
+ file('/etc/mtab').read())
+ return False
diff --git a/client/tests/kvm/tests/image_copy.py b/client/tests/kvm/tests/image_copy.py
new file mode 100644
index 0000000..800fb90
--- /dev/null
+++ b/client/tests/kvm/tests/image_copy.py
@@ -0,0 +1,42 @@
+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')
+ if not os.path.exists(mount_dest_dir):
+ os.mkdir(mount_dest_dir)
+
+ src_dir = params.get('nfs_images_dir')
+ image_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm/images')
+ if not os.path.exists(image_dir):
+ image_dir = os.path.dirname(params.get("image_name"))
+
+ 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(image_dir, image)
+
+ if not kvm_utils.mount(src_dir, mount_dest_dir, "nfs", "ro"):
+ raise error.TestError("Fail to mount the %s to %s" %
+ (src_dir, 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.info("Copying image '%s'..." % image)
+ cmd = "cp %s %s" % (src_path, dst_path)
+ s, o = commands.getstatusoutput(cmd)
+ if s != 0:
+ raise error.TestFail("Failed to copy image %s: %s" % (cmd, o))
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index b8f25f4..bdeac19 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -61,6 +61,12 @@ variants:
floppy = "images/floppy.img"
extra_params += " -boot d"
+ - image_copy:
+ type = image_copy
+ vms = ''
+ # Here specify the NFS directory that contains all images
+ nfs_images_dir =
+
- setup: install unattended_install
type = steps
fail_if_stuck_for = 300
--
1.6.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Autotest] [Autotest PATCH] KVM-test: Add a subtest image_copy
2010-01-04 9:30 [Autotest PATCH] KVM-test: Add a subtest image_copy Yolkfull Chow
@ 2010-01-04 14:52 ` Amos Kong
2010-01-05 2:53 ` Yolkfull Chow
0 siblings, 1 reply; 4+ messages in thread
From: Amos Kong @ 2010-01-04 14:52 UTC (permalink / raw)
To: Yolkfull Chow; +Cc: autotest, kvm
On Mon, Jan 04, 2010 at 05:30:21PM +0800, Yolkfull Chow wrote:
> Add image_copy subtest for convenient KVM functional testing.
>
> The target image will be copied into the linked directory if link 'images'
> is created, and copied to the directory specified in config file otherwise.
>
> Signed-off-by: Yolkfull Chow <yzhou@redhat.com>
> ---
> client/tests/kvm/kvm_utils.py | 64 ++++++++++++++++++++++++++++++++
> client/tests/kvm/tests/image_copy.py | 42 +++++++++++++++++++++
> client/tests/kvm/tests_base.cfg.sample | 6 +++
> 3 files changed, 112 insertions(+), 0 deletions(-)
> create mode 100644 client/tests/kvm/tests/image_copy.py
>
> diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
> index 2bbbe22..1e11441 100644
> --- a/client/tests/kvm/kvm_utils.py
> +++ b/client/tests/kvm/kvm_utils.py
> @@ -924,3 +924,67 @@ def create_report(report_dir, results_dir):
> reporter = os.path.join(report_dir, 'html_report.py')
> html_file = os.path.join(results_dir, 'results.html')
> os.system('%s -r %s -f %s -R' % (reporter, results_dir, html_file))
> +
> +
> +def is_dir_mounted(source, dest, type, perm):
> + """
> + Check whether `source' is mounted on `dest' with right permission.
> +
> + @source: mount source
> + @dest: mount point
> + @type: file system type
@perm: mount permission
> + """
> + match_string = "%s %s %s %s" % (source, dest, type, perm)
> + try:
> + f = open("/etc/mtab", "r")
> + except IOError:
> + pass
When calling open(), if raise an IOError exception, 'f' was not assigned.
Then we could not call 'f.read()' or 'f.close()'
We need 'return False', not 'pass'
> + mounted = f.read()
> + f.close()
> + if match_string in mounted:
> + return True
> + return False
> +
> +
> +def umount(mount_point):
> + """
> + Umount `mount_point'.
> +
> + @mount_point: mount point
> + """
> + cmd = "umount %s" % mount_point
> + s, o = commands.getstatusoutput(cmd)
> + if s != 0:
> + logging.error("Fail to umount: %s" % o)
> + return False
> + return True
> +
> +
> +def mount(src, mount_point, type, perm = "rw"):
> + """
> + Mount the src into mount_point of the host.
> +
> + @src: mount source
> + @mount_point: mount point
> + @type: file system type
> + @perm: mount permission
> + """
> + if is_dir_mounted(src, mount_point, type, perm):
> + return True
> +
> + umount(mount_point)
> +
> + cmd = "mount -t %s %s %s -o %s" % (type, src, mount_point, perm)
> + logging.debug("Issue mount command: %s" % cmd)
> + s, o = commands.getstatusoutput(cmd)
> + if s != 0:
> + logging.error("Fail to mount: %s " % o)
> + return False
> +
> + if is_dir_mounted(src, mount_point, type, perm):
> + logging.info("Successfully mounted %s" % src)
> + return True
> + else:
> + logging.error("Mount verification failed; currently mounted: %s" %
> + file('/etc/mtab').read())
> + return False
> diff --git a/client/tests/kvm/tests/image_copy.py b/client/tests/kvm/tests/image_copy.py
> new file mode 100644
> index 0000000..800fb90
> --- /dev/null
> +++ b/client/tests/kvm/tests/image_copy.py
> @@ -0,0 +1,42 @@
> +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')
> + if not os.path.exists(mount_dest_dir):
> + os.mkdir(mount_dest_dir)
> +
> + src_dir = params.get('nfs_images_dir')
> + image_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm/images')
> + if not os.path.exists(image_dir):
> + image_dir = os.path.dirname(params.get("image_name"))
> +
> + 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(image_dir, image)
> +
> + if not kvm_utils.mount(src_dir, mount_dest_dir, "nfs", "ro"):
> + raise error.TestError("Fail to mount the %s to %s" %
> + (src_dir, 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.info("Copying image '%s'..." % image)
> + cmd = "cp %s %s" % (src_path, dst_path)
> + s, o = commands.getstatusoutput(cmd)
> + if s != 0:
> + raise error.TestFail("Failed to copy image %s: %s" % (cmd, o))
> diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
> index b8f25f4..bdeac19 100644
> --- a/client/tests/kvm/tests_base.cfg.sample
> +++ b/client/tests/kvm/tests_base.cfg.sample
> @@ -61,6 +61,12 @@ variants:
> floppy = "images/floppy.img"
> extra_params += " -boot d"
>
> + - image_copy:
> + type = image_copy
> + vms = ''
> + # Here specify the NFS directory that contains all images
> + nfs_images_dir =
> +
> - setup: install unattended_install
> type = steps
> fail_if_stuck_for = 300
> --
> 1.6.6
>
> _______________________________________________
> Autotest mailing list
> Autotest@test.kernel.org
> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
--
Amos Kong
Quality Engineer
Raycom Office(Beijing), Red Hat Inc.
Phone: +86-10-62608183
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Autotest PATCH] KVM-test: Add a subtest image_copy
2010-01-04 14:52 ` [Autotest] " Amos Kong
@ 2010-01-05 2:53 ` Yolkfull Chow
0 siblings, 0 replies; 4+ messages in thread
From: Yolkfull Chow @ 2010-01-05 2:53 UTC (permalink / raw)
To: Amos Kong; +Cc: autotest, kvm
On Mon, Jan 04, 2010 at 10:52:13PM +0800, Amos Kong wrote:
> On Mon, Jan 04, 2010 at 05:30:21PM +0800, Yolkfull Chow wrote:
> > Add image_copy subtest for convenient KVM functional testing.
> >
> > The target image will be copied into the linked directory if link 'images'
> > is created, and copied to the directory specified in config file otherwise.
> >
> > Signed-off-by: Yolkfull Chow <yzhou@redhat.com>
> > ---
> > client/tests/kvm/kvm_utils.py | 64 ++++++++++++++++++++++++++++++++
> > client/tests/kvm/tests/image_copy.py | 42 +++++++++++++++++++++
> > client/tests/kvm/tests_base.cfg.sample | 6 +++
> > 3 files changed, 112 insertions(+), 0 deletions(-)
> > create mode 100644 client/tests/kvm/tests/image_copy.py
> >
> > diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
> > index 2bbbe22..1e11441 100644
> > --- a/client/tests/kvm/kvm_utils.py
> > +++ b/client/tests/kvm/kvm_utils.py
> > @@ -924,3 +924,67 @@ def create_report(report_dir, results_dir):
> > reporter = os.path.join(report_dir, 'html_report.py')
> > html_file = os.path.join(results_dir, 'results.html')
> > os.system('%s -r %s -f %s -R' % (reporter, results_dir, html_file))
> > +
> > +
> > +def is_dir_mounted(source, dest, type, perm):
> > + """
> > + Check whether `source' is mounted on `dest' with right permission.
> > +
> > + @source: mount source
> > + @dest: mount point
> > + @type: file system type
>
> @perm: mount permission
>
> > + """
> > + match_string = "%s %s %s %s" % (source, dest, type, perm)
> > + try:
> > + f = open("/etc/mtab", "r")
> > + except IOError:
> > + pass
>
> When calling open(), if raise an IOError exception, 'f' was not assigned.
> Then we could not call 'f.read()' or 'f.close()'
Ah..yes, thanks for pointing this out.
>
> We need 'return False', not 'pass'
>
> > + mounted = f.read()
> > + f.close()
> > + if match_string in mounted:
> > + return True
> > + return False
> > +
> > +
> > +def umount(mount_point):
> > + """
> > + Umount `mount_point'.
> > +
> > + @mount_point: mount point
> > + """
> > + cmd = "umount %s" % mount_point
> > + s, o = commands.getstatusoutput(cmd)
> > + if s != 0:
> > + logging.error("Fail to umount: %s" % o)
> > + return False
> > + return True
> > +
> > +
> > +def mount(src, mount_point, type, perm = "rw"):
> > + """
> > + Mount the src into mount_point of the host.
> > +
> > + @src: mount source
> > + @mount_point: mount point
> > + @type: file system type
> > + @perm: mount permission
> > + """
> > + if is_dir_mounted(src, mount_point, type, perm):
> > + return True
> > +
> > + umount(mount_point)
> > +
> > + cmd = "mount -t %s %s %s -o %s" % (type, src, mount_point, perm)
> > + logging.debug("Issue mount command: %s" % cmd)
> > + s, o = commands.getstatusoutput(cmd)
> > + if s != 0:
> > + logging.error("Fail to mount: %s " % o)
> > + return False
> > +
> > + if is_dir_mounted(src, mount_point, type, perm):
> > + logging.info("Successfully mounted %s" % src)
> > + return True
> > + else:
> > + logging.error("Mount verification failed; currently mounted: %s" %
> > + file('/etc/mtab').read())
> > + return False
> > diff --git a/client/tests/kvm/tests/image_copy.py b/client/tests/kvm/tests/image_copy.py
> > new file mode 100644
> > index 0000000..800fb90
> > --- /dev/null
> > +++ b/client/tests/kvm/tests/image_copy.py
> > @@ -0,0 +1,42 @@
> > +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')
> > + if not os.path.exists(mount_dest_dir):
> > + os.mkdir(mount_dest_dir)
> > +
> > + src_dir = params.get('nfs_images_dir')
> > + image_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm/images')
> > + if not os.path.exists(image_dir):
> > + image_dir = os.path.dirname(params.get("image_name"))
> > +
> > + 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(image_dir, image)
> > +
> > + if not kvm_utils.mount(src_dir, mount_dest_dir, "nfs", "ro"):
> > + raise error.TestError("Fail to mount the %s to %s" %
> > + (src_dir, 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.info("Copying image '%s'..." % image)
> > + cmd = "cp %s %s" % (src_path, dst_path)
> > + s, o = commands.getstatusoutput(cmd)
> > + if s != 0:
> > + raise error.TestFail("Failed to copy image %s: %s" % (cmd, o))
> > diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
> > index b8f25f4..bdeac19 100644
> > --- a/client/tests/kvm/tests_base.cfg.sample
> > +++ b/client/tests/kvm/tests_base.cfg.sample
> > @@ -61,6 +61,12 @@ variants:
> > floppy = "images/floppy.img"
> > extra_params += " -boot d"
> >
> > + - image_copy:
> > + type = image_copy
> > + vms = ''
> > + # Here specify the NFS directory that contains all images
> > + nfs_images_dir =
> > +
> > - setup: install unattended_install
> > type = steps
> > fail_if_stuck_for = 300
> > --
> > 1.6.6
> >
> > _______________________________________________
> > Autotest mailing list
> > Autotest@test.kernel.org
> > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
>
> --
> Amos Kong
> Quality Engineer
> Raycom Office(Beijing), Red Hat Inc.
> Phone: +86-10-62608183
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Autotest] [Autotest PATCH] KVM-test: Add a subtest image_copy
2010-01-27 3:43 ` Yolkfull Chow
@ 2010-01-27 11:11 ` Lucas Meneghel Rodrigues
0 siblings, 0 replies; 4+ messages in thread
From: Lucas Meneghel Rodrigues @ 2010-01-27 11:11 UTC (permalink / raw)
To: Yolkfull Chow; +Cc: autotest, kvm, Lawrence Lim, Michael Goldish
On Wed, 2010-01-27 at 11:43 +0800, Yolkfull Chow wrote:
> On Tue, Jan 26, 2010 at 02:04:09PM -0200, Lucas Meneghel Rodrigues wrote:
> > Yolkfull, I am copying Michael and Lawrence on the e-mail so they can
> > comment on the points I am going to present.
>
> Lucas, firstly thank you very much for addressing your viewpoints and the
> coding/logical suggestions. Most of them are reasonable and appreciated
> except that I also have an improvidence about point 3):
>
> Your idea on executing image_copy as a backup of unattended_install is good.
> But I think we could also seperate 'unattended_install' from test set of
> "functional testing" and encapsulate it into "Installation testing" set.
> In this way the following functional test cases will not be affected by
> failed installation tests.
>
> What do you think about this?
I believe this could be implemented by simply removing the dependency.
However, if *no* install test succeed whatsoever, then we don't have any
way to perform the subsequent tests. So I don't know how to implement
this idea.
Please explain me how that encapsulation would work.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-01-27 11:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-04 9:30 [Autotest PATCH] KVM-test: Add a subtest image_copy Yolkfull Chow
2010-01-04 14:52 ` [Autotest] " Amos Kong
2010-01-05 2:53 ` Yolkfull Chow
-- strict thread matches above, loose matches on Subject: below --
2010-01-06 3:32 Yolkfull Chow
2010-01-26 16:04 ` Lucas Meneghel Rodrigues
2010-01-27 3:43 ` Yolkfull Chow
2010-01-27 11:11 ` [Autotest] " Lucas Meneghel Rodrigues
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).