* [PATCH 0/3] Removing scripts/check_image.py
@ 2011-01-18 23:45 Lucas Meneghel Rodrigues
2011-01-18 23:45 ` [PATCH 1/3] KVM test: Introduce check_image postprocess directive Lucas Meneghel Rodrigues
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Lucas Meneghel Rodrigues @ 2011-01-18 23:45 UTC (permalink / raw)
To: autotest; +Cc: kvm, Lucas Meneghel Rodrigues
This patchset aims to remove the script check_image.py from
KVM autotest. The reasoning behind this is that we want to
revamp all the pre/post scripts processing, that is, making
the py scripts part of the infrastructure, where they can
share API with the rest of the framework. So we'll proceed
by parts, this being the first.
Lucas Meneghel Rodrigues (3):
KVM test: Introduce check_image postprocess directive
KVM test: Modify enospc test to not require scripts/check_image.py
KVM test: Removing scripts/check_image.py
client/tests/kvm/kvm_preprocessing.py | 3 +-
client/tests/kvm/kvm_vm.py | 62 +++++++++++++++++++
client/tests/kvm/scripts/check_image.py | 99 -------------------------------
client/tests/kvm/tests/enospc.py | 12 ++--
client/tests/kvm/tests_base.cfg.sample | 7 +-
5 files changed, 73 insertions(+), 110 deletions(-)
delete mode 100644 client/tests/kvm/scripts/check_image.py
--
1.7.3.4
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/3] KVM test: Introduce check_image postprocess directive 2011-01-18 23:45 [PATCH 0/3] Removing scripts/check_image.py Lucas Meneghel Rodrigues @ 2011-01-18 23:45 ` Lucas Meneghel Rodrigues 2011-01-18 23:58 ` Amos Kong 2011-01-19 5:56 ` Michael Goldish 2011-01-18 23:45 ` [PATCH 2/3] KVM test: Modify enospc test to not require scripts/check_image.py Lucas Meneghel Rodrigues 2011-01-18 23:45 ` [PATCH 3/3] KVM test: Removing scripts/check_image.py Lucas Meneghel Rodrigues 2 siblings, 2 replies; 7+ messages in thread From: Lucas Meneghel Rodrigues @ 2011-01-18 23:45 UTC (permalink / raw) To: autotest; +Cc: kvm, Lucas Meneghel Rodrigues With check_image_foo = yes, KVM autotest will use qemu-img to perform checks on the qcow2 image. This new functionality intends to replace the script check_image.py. The plan is to supersede most of the pre/post scripts in place throughout KVM autotest. Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> --- client/tests/kvm/kvm_preprocessing.py | 3 +- client/tests/kvm/kvm_vm.py | 62 ++++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 ++-- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py index 56acf0c..4a6e0f8 100644 --- a/client/tests/kvm/kvm_preprocessing.py +++ b/client/tests/kvm/kvm_preprocessing.py @@ -93,11 +93,12 @@ def preprocess_vm(test, params, env, name): def postprocess_image(test, params): """ Postprocess a single QEMU image according to the instructions in params. - Currently this function just removes an image if requested. @param test: An Autotest test object. @param params: A dict containing image postprocessing parameters. """ + if params.get("check_image") == "yes": + kvm_vm.check_image(params, test.bindir) if params.get("remove_image") == "yes": kvm_vm.remove_image(params, test.bindir) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 18d10ef..767c6d4 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -47,6 +47,15 @@ class VMImageMissingError(VMError): return "CD image file not found: %r" % self.filename +class VMImageCheckError(VMError): + def __init__(self, filename): + VMError.__init__(self, filename) + self.filename = filename + + def __str__(self): + return "Errors found on image: %r" % self.filename + + class VMBadPATypeError(VMError): def __init__(self, pa_type): VMError.__init__(self, pa_type) @@ -239,6 +248,59 @@ def remove_image(params, root_dir): logging.debug("Image file %s not found") +def check_image(params, root_dir): + """ + Check an image using qemu-img. + + @param params: Dictionary containing the test parameters. + @param root_dir: Base directory for relative filenames. + + @note: params should contain: + image_name -- the name of the image file, without extension + image_format -- the format of the image (qcow2, raw etc) + """ + image_filename = get_image_filename(params, root_dir) + logging.debug("Checking image file %s..." % image_filename) + qemu_img_cmd = kvm_utils.get_path(root_dir, + params.get("qemu_img_binary", "qemu-img")) + check_critical = params.get("check_image_critical") == 'yes' + image_is_qcow2 = params.get("image_format") == 'qcow2' + if os.path.exists(image_filename) and image_is_qcow2: + # Verifying if qemu-img supports 'check' + q_result = utils.run(qemu_img_cmd, ignore_status=True) + q_output = q_result.stdout + check_img = True + if not "check" in q_output: + logging.error("qemu-img does not support 'check', " + "skipping check...") + check_img = False + if not "info" in q_output: + logging.error("qemu-img does not support 'info', " + "skipping check...") + check_img = False + if check_img: + try: + utils.system("%s info %s" % (qemu_img_cmd, image_filename)) + except error.CmdError: + logging.error("Error getting info from image %s", + image_filename) + try: + utils.system("%s check %s" % (qemu_img_cmd, image_filename)) + except error.CmdError: + if check_critical: + raise VMImageCheckError(image_filename) + else: + logging.error("Error checking image %s", image_filename) + + else: + if not os.path.exists(image_filename): + logging.debug("Image file %s not found, skipping check...", + image_filename) + elif not image_is_qcow2: + logging.debug("Image file %s not qcow2, skipping check...", + image_filename) + + class VM: """ This class handles all basic VM operations. diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 28064a8..8b67256 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -2357,11 +2357,10 @@ kdump: variants: - @qcow2: image_format = qcow2 - post_command += " python scripts/check_image.py;" - post_command_timeout = 600 - post_command_noncritical = yes + check_image = yes + check_image_critical = no ioquit: - post_command_noncritical = no + check_image_critical = yes - vmdk: no ioquit only Fedora Ubuntu Windows -- 1.7.3.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] KVM test: Introduce check_image postprocess directive 2011-01-18 23:45 ` [PATCH 1/3] KVM test: Introduce check_image postprocess directive Lucas Meneghel Rodrigues @ 2011-01-18 23:58 ` Amos Kong 2011-01-19 5:56 ` Michael Goldish 1 sibling, 0 replies; 7+ messages in thread From: Amos Kong @ 2011-01-18 23:58 UTC (permalink / raw) To: Lucas Meneghel Rodrigues; +Cc: autotest, kvm ----- Original Message ----- > With check_image_foo = yes, KVM autotest will use > qemu-img to perform checks on the qcow2 image. > > This new functionality intends to replace the > script check_image.py. The plan is to supersede most > of the pre/post scripts in place throughout KVM > autotest. Good idea! Some pre/post cmd/script is very confused, this would make thing clear. > Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> I'll test patches when I go to office. > --- > client/tests/kvm/kvm_preprocessing.py | 3 +- > client/tests/kvm/kvm_vm.py | 62 ++++++++++++++++++++++++++++++++ > client/tests/kvm/tests_base.cfg.sample | 7 ++-- > 3 files changed, 67 insertions(+), 5 deletions(-) > > diff --git a/client/tests/kvm/kvm_preprocessing.py > b/client/tests/kvm/kvm_preprocessing.py > index 56acf0c..4a6e0f8 100644 > --- a/client/tests/kvm/kvm_preprocessing.py > +++ b/client/tests/kvm/kvm_preprocessing.py > @@ -93,11 +93,12 @@ def preprocess_vm(test, params, env, name): > def postprocess_image(test, params): > """ > Postprocess a single QEMU image according to the instructions in > params. > - Currently this function just removes an image if requested. > > @param test: An Autotest test object. > @param params: A dict containing image postprocessing parameters. > """ > + if params.get("check_image") == "yes": > + kvm_vm.check_image(params, test.bindir) > if params.get("remove_image") == "yes": > kvm_vm.remove_image(params, test.bindir) It will fix the problem that check_image.py try to check some removed images. > diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py > index 18d10ef..767c6d4 100755 > --- a/client/tests/kvm/kvm_vm.py > +++ b/client/tests/kvm/kvm_vm.py > @@ -47,6 +47,15 @@ class VMImageMissingError(VMError): > return "CD image file not found: %r" % self.filename > > > +class VMImageCheckError(VMError): > + def __init__(self, filename): > + VMError.__init__(self, filename) > + self.filename = filename > + > + def __str__(self): > + return "Errors found on image: %r" % self.filename > + > + > class VMBadPATypeError(VMError): > def __init__(self, pa_type): > VMError.__init__(self, pa_type) > @@ -239,6 +248,59 @@ def remove_image(params, root_dir): > logging.debug("Image file %s not found") > > > +def check_image(params, root_dir): > + """ > + Check an image using qemu-img. > + > + @param params: Dictionary containing the test parameters. > + @param root_dir: Base directory for relative filenames. > + > + @note: params should contain: > + image_name -- the name of the image file, without extension > + image_format -- the format of the image (qcow2, raw etc) > + """ > + image_filename = get_image_filename(params, root_dir) > + logging.debug("Checking image file %s..." % image_filename) > + qemu_img_cmd = kvm_utils.get_path(root_dir, > + params.get("qemu_img_binary", "qemu-img")) > + check_critical = params.get("check_image_critical") == 'yes' > + image_is_qcow2 = params.get("image_format") == 'qcow2' > + if os.path.exists(image_filename) and image_is_qcow2: > + # Verifying if qemu-img supports 'check' > + q_result = utils.run(qemu_img_cmd, ignore_status=True) > + q_output = q_result.stdout > + check_img = True > + if not "check" in q_output: > + logging.error("qemu-img does not support 'check', " > + "skipping check...") > + check_img = False > + if not "info" in q_output: > + logging.error("qemu-img does not support 'info', " > + "skipping check...") > + check_img = False > + if check_img: > + try: > + utils.system("%s info %s" % (qemu_img_cmd, image_filename)) > + except error.CmdError: > + logging.error("Error getting info from image %s", > + image_filename) > + try: > + utils.system("%s check %s" % (qemu_img_cmd, image_filename)) > + except error.CmdError: > + if check_critical: > + raise VMImageCheckError(image_filename) > + else: > + logging.error("Error checking image %s", image_filename) > + > + else: > + if not os.path.exists(image_filename): > + logging.debug("Image file %s not found, skipping check...", > + image_filename) > + elif not image_is_qcow2: > + logging.debug("Image file %s not qcow2, skipping check...", > + image_filename) > + > + > class VM: > """ > This class handles all basic VM operations. > diff --git a/client/tests/kvm/tests_base.cfg.sample > b/client/tests/kvm/tests_base.cfg.sample > index 28064a8..8b67256 100644 > --- a/client/tests/kvm/tests_base.cfg.sample > +++ b/client/tests/kvm/tests_base.cfg.sample > @@ -2357,11 +2357,10 @@ kdump: > variants: > - @qcow2: > image_format = qcow2 > - post_command += " python scripts/check_image.py;" > - post_command_timeout = 600 > - post_command_noncritical = yes > + check_image = yes > + check_image_critical = no > ioquit: > - post_command_noncritical = no > + check_image_critical = yes > - vmdk: > no ioquit > only Fedora Ubuntu Windows > -- > 1.7.3.4 > > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] KVM test: Introduce check_image postprocess directive 2011-01-18 23:45 ` [PATCH 1/3] KVM test: Introduce check_image postprocess directive Lucas Meneghel Rodrigues 2011-01-18 23:58 ` Amos Kong @ 2011-01-19 5:56 ` Michael Goldish 1 sibling, 0 replies; 7+ messages in thread From: Michael Goldish @ 2011-01-19 5:56 UTC (permalink / raw) To: Lucas Meneghel Rodrigues; +Cc: autotest, kvm On 01/19/2011 01:45 AM, Lucas Meneghel Rodrigues wrote: > With check_image_foo = yes, KVM autotest will use > qemu-img to perform checks on the qcow2 image. > > This new functionality intends to replace the > script check_image.py. The plan is to supersede most > of the pre/post scripts in place throughout KVM > autotest. > > Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> > --- > client/tests/kvm/kvm_preprocessing.py | 3 +- > client/tests/kvm/kvm_vm.py | 62 ++++++++++++++++++++++++++++++++ > client/tests/kvm/tests_base.cfg.sample | 7 ++-- > 3 files changed, 67 insertions(+), 5 deletions(-) > > diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py > index 56acf0c..4a6e0f8 100644 > --- a/client/tests/kvm/kvm_preprocessing.py > +++ b/client/tests/kvm/kvm_preprocessing.py > @@ -93,11 +93,12 @@ def preprocess_vm(test, params, env, name): > def postprocess_image(test, params): > """ > Postprocess a single QEMU image according to the instructions in params. > - Currently this function just removes an image if requested. > > @param test: An Autotest test object. > @param params: A dict containing image postprocessing parameters. > """ > + if params.get("check_image") == "yes": > + kvm_vm.check_image(params, test.bindir) > if params.get("remove_image") == "yes": > kvm_vm.remove_image(params, test.bindir) > > diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py > index 18d10ef..767c6d4 100755 > --- a/client/tests/kvm/kvm_vm.py > +++ b/client/tests/kvm/kvm_vm.py > @@ -47,6 +47,15 @@ class VMImageMissingError(VMError): > return "CD image file not found: %r" % self.filename > > > +class VMImageCheckError(VMError): > + def __init__(self, filename): > + VMError.__init__(self, filename) > + self.filename = filename > + > + def __str__(self): > + return "Errors found on image: %r" % self.filename > + > + > class VMBadPATypeError(VMError): > def __init__(self, pa_type): > VMError.__init__(self, pa_type) > @@ -239,6 +248,59 @@ def remove_image(params, root_dir): > logging.debug("Image file %s not found") > > > +def check_image(params, root_dir): > + """ > + Check an image using qemu-img. > + > + @param params: Dictionary containing the test parameters. > + @param root_dir: Base directory for relative filenames. > + > + @note: params should contain: > + image_name -- the name of the image file, without extension > + image_format -- the format of the image (qcow2, raw etc) > + """ > + image_filename = get_image_filename(params, root_dir) > + logging.debug("Checking image file %s..." % image_filename) > + qemu_img_cmd = kvm_utils.get_path(root_dir, > + params.get("qemu_img_binary", "qemu-img")) > + check_critical = params.get("check_image_critical") == 'yes' > + image_is_qcow2 = params.get("image_format") == 'qcow2' > + if os.path.exists(image_filename) and image_is_qcow2: > + # Verifying if qemu-img supports 'check' > + q_result = utils.run(qemu_img_cmd, ignore_status=True) > + q_output = q_result.stdout > + check_img = True > + if not "check" in q_output: > + logging.error("qemu-img does not support 'check', " > + "skipping check...") > + check_img = False > + if not "info" in q_output: > + logging.error("qemu-img does not support 'info', " > + "skipping check...") > + check_img = False > + if check_img: > + try: > + utils.system("%s info %s" % (qemu_img_cmd, image_filename)) > + except error.CmdError: > + logging.error("Error getting info from image %s", > + image_filename) > + try: > + utils.system("%s check %s" % (qemu_img_cmd, image_filename)) > + except error.CmdError: > + if check_critical: > + raise VMImageCheckError(image_filename) > + else: > + logging.error("Error checking image %s", image_filename) > + > + else: > + if not os.path.exists(image_filename): > + logging.debug("Image file %s not found, skipping check...", > + image_filename) > + elif not image_is_qcow2: > + logging.debug("Image file %s not qcow2, skipping check...", > + image_filename) > + > + > class VM: > """ > This class handles all basic VM operations. > diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample > index 28064a8..8b67256 100644 > --- a/client/tests/kvm/tests_base.cfg.sample > +++ b/client/tests/kvm/tests_base.cfg.sample > @@ -2357,11 +2357,10 @@ kdump: > variants: > - @qcow2: > image_format = qcow2 > - post_command += " python scripts/check_image.py;" > - post_command_timeout = 600 > - post_command_noncritical = yes > + check_image = yes > + check_image_critical = no > ioquit: > - post_command_noncritical = no > + check_image_critical = yes > - vmdk: > no ioquit > only Fedora Ubuntu Windows I know it's always been this way, but why is image_check noncritical? If we just don't want the image_check exception to override the test's failure exception, we can either set image_check_critical = yes image_check_critical_on_error = no or, better yet, we can ignore all exceptions raised during postprocessing after test failure (in kvm.py). ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] KVM test: Modify enospc test to not require scripts/check_image.py 2011-01-18 23:45 [PATCH 0/3] Removing scripts/check_image.py Lucas Meneghel Rodrigues 2011-01-18 23:45 ` [PATCH 1/3] KVM test: Introduce check_image postprocess directive Lucas Meneghel Rodrigues @ 2011-01-18 23:45 ` Lucas Meneghel Rodrigues 2011-01-19 6:05 ` [Autotest] " Michael Goldish 2011-01-18 23:45 ` [PATCH 3/3] KVM test: Removing scripts/check_image.py Lucas Meneghel Rodrigues 2 siblings, 1 reply; 7+ messages in thread From: Lucas Meneghel Rodrigues @ 2011-01-18 23:45 UTC (permalink / raw) To: autotest; +Cc: kvm With this we prepare to remove the aforementioned script. Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> --- client/tests/kvm/tests/enospc.py | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/tests/kvm/tests/enospc.py b/client/tests/kvm/tests/enospc.py index 2d8b628..4dd694f 100644 --- a/client/tests/kvm/tests/enospc.py +++ b/client/tests/kvm/tests/enospc.py @@ -1,7 +1,7 @@ import logging, commands, time, os, re from autotest_lib.client.common_lib import error from autotest_lib.client.bin import utils -import kvm_test_utils +import kvm_test_utils, kvm_vm def run_enospc(test, params, env): @@ -46,11 +46,11 @@ def run_enospc(test, params, env): if "paused" in status: pause_n += 1 logging.info("Checking all images in use by the VM") - script_path = os.path.join(test.bindir, "scripts/check_image.py") - try: - cmd_result = utils.run('python %s' % script_path) - except error.CmdError, e: - logging.debug(e.result_obj.stdout) + for image_name in vm.params.objects("images"): + image_params = vm.params.object_params(image_name) + # Just to make sure the image check won't throw exceptions + image_params["check_image_critical"] = 'no' + kvm_vm.check_image(image_params, test.bindir) logging.info("Guest paused, extending Logical Volume size") try: cmd_result = utils.run("lvextend -L +200M /dev/vgtest/lvtest") -- 1.7.3.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Autotest] [PATCH 2/3] KVM test: Modify enospc test to not require scripts/check_image.py 2011-01-18 23:45 ` [PATCH 2/3] KVM test: Modify enospc test to not require scripts/check_image.py Lucas Meneghel Rodrigues @ 2011-01-19 6:05 ` Michael Goldish 0 siblings, 0 replies; 7+ messages in thread From: Michael Goldish @ 2011-01-19 6:05 UTC (permalink / raw) To: Lucas Meneghel Rodrigues; +Cc: autotest, kvm On 01/19/2011 01:45 AM, Lucas Meneghel Rodrigues wrote: > With this we prepare to remove the aforementioned script. > > Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> > --- > client/tests/kvm/tests/enospc.py | 12 ++++++------ > 1 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/client/tests/kvm/tests/enospc.py b/client/tests/kvm/tests/enospc.py > index 2d8b628..4dd694f 100644 > --- a/client/tests/kvm/tests/enospc.py > +++ b/client/tests/kvm/tests/enospc.py > @@ -1,7 +1,7 @@ > import logging, commands, time, os, re > from autotest_lib.client.common_lib import error > from autotest_lib.client.bin import utils > -import kvm_test_utils > +import kvm_test_utils, kvm_vm > > > def run_enospc(test, params, env): > @@ -46,11 +46,11 @@ def run_enospc(test, params, env): > if "paused" in status: > pause_n += 1 > logging.info("Checking all images in use by the VM") > - script_path = os.path.join(test.bindir, "scripts/check_image.py") > - try: > - cmd_result = utils.run('python %s' % script_path) > - except error.CmdError, e: > - logging.debug(e.result_obj.stdout) > + for image_name in vm.params.objects("images"): > + image_params = vm.params.object_params(image_name) > + # Just to make sure the image check won't throw exceptions > + image_params["check_image_critical"] = 'no' I think this would be nicer: try: ... except VMError, e: logging.warn(e) > + kvm_vm.check_image(image_params, test.bindir) > logging.info("Guest paused, extending Logical Volume size") > try: > cmd_result = utils.run("lvextend -L +200M /dev/vgtest/lvtest") ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] KVM test: Removing scripts/check_image.py 2011-01-18 23:45 [PATCH 0/3] Removing scripts/check_image.py Lucas Meneghel Rodrigues 2011-01-18 23:45 ` [PATCH 1/3] KVM test: Introduce check_image postprocess directive Lucas Meneghel Rodrigues 2011-01-18 23:45 ` [PATCH 2/3] KVM test: Modify enospc test to not require scripts/check_image.py Lucas Meneghel Rodrigues @ 2011-01-18 23:45 ` Lucas Meneghel Rodrigues 2 siblings, 0 replies; 7+ messages in thread From: Lucas Meneghel Rodrigues @ 2011-01-18 23:45 UTC (permalink / raw) To: autotest; +Cc: kvm As its functionality was implemented as part of the framework on previous patches. Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> --- client/tests/kvm/scripts/check_image.py | 99 ------------------------------- 1 files changed, 0 insertions(+), 99 deletions(-) delete mode 100644 client/tests/kvm/scripts/check_image.py diff --git a/client/tests/kvm/scripts/check_image.py b/client/tests/kvm/scripts/check_image.py deleted file mode 100644 index 2b5c227..0000000 --- a/client/tests/kvm/scripts/check_image.py +++ /dev/null @@ -1,99 +0,0 @@ -import os, sys, commands - - -class ImageCheckError(Exception): - """ - Simple wrapper for the builtin Exception class. - """ - pass - - -class ImageCheck(object): - """ - Check qcow2 image by qemu-img info/check command. - """ - def __init__(self): - """ - Gets params from environment variables and sets class attributes. - """ - self.image_path_list = [] - client_dir = os.environ['AUTODIR'] - self.kvm_dir = os.path.join(client_dir, 'tests/kvm') - img_to_check = os.environ['KVM_TEST_images'].split() - - for img in img_to_check: - img_name_str = "KVM_TEST_image_name_%s" % img - if not os.environ.has_key(img_name_str): - img_name_str = "KVM_TEST_image_name" - img_format_str = "KVM_TEST_image_format_%s" % img - if os.environ.has_key(img_format_str): - image_format = os.environ[img_format_str] - else: - image_format = os.environ['KVM_TEST_image_format'] - if image_format != "qcow2": - continue - image_name = os.environ[img_name_str] - image_filename = "%s.%s" % (image_name, image_format) - image_filename = os.path.join(self.kvm_dir, image_filename) - self.image_path_list.append(image_filename) - if os.environ.has_key('KVM_TEST_qemu_img_binary'): - self.qemu_img_path = os.environ['KVM_TEST_qemu_img_binary'] - else: - self.qemu_img_path = os.path.join(self.kvm_dir, 'qemu-img') - self.qemu_img_check = True - cmd = "%s |grep check" % self.qemu_img_path - (s1, output) = commands.getstatusoutput(cmd) - if s1: - self.qemu_img_check = False - print "Command qemu-img check not available, not checking..." - cmd = "%s |grep info" % self.qemu_img_path - (s2, output) = commands.getstatusoutput(cmd) - if s2: - self.qemu_img_check = False - print "Command qemu-img info not available, not checking..." - - def exec_img_cmd(self, cmd_type, image_path): - """ - Run qemu-img info/check on given image. - - @param cmd_type: Sub command used together with qemu. - @param image_path: Real path of the image. - """ - cmd = ' '.join([self.qemu_img_path, cmd_type, image_path]) - print "Checking image with command %s" % cmd - (status, output) = commands.getstatusoutput(cmd) - print output - if status or (cmd_type == "check" and not "No errors" in output): - msg = "Command %s failed" % cmd - return False, msg - else: - return True, '' - - - def check_image(self): - """ - Run qemu-img info/check to check the image in list. - - If the image checking is failed, raise an exception. - """ - # Check all the image in list. - errmsg = [] - for image_path in self.image_path_list: - if not os.path.exists(image_path): - print "Image %s does not exist!" % image_path - continue - s, o = self.exec_img_cmd('info', image_path) - if not s: - errmsg.append(o) - s, o = self.exec_img_cmd('check', image_path) - if not s: - errmsg.append(o) - - if len(errmsg) > 0: - raise ImageCheckError('Errors were found, please check log!') - - -if __name__ == "__main__": - image_check = ImageCheck() - if image_check.qemu_img_check: - image_check.check_image() -- 1.7.3.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-01-19 6:04 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-01-18 23:45 [PATCH 0/3] Removing scripts/check_image.py Lucas Meneghel Rodrigues 2011-01-18 23:45 ` [PATCH 1/3] KVM test: Introduce check_image postprocess directive Lucas Meneghel Rodrigues 2011-01-18 23:58 ` Amos Kong 2011-01-19 5:56 ` Michael Goldish 2011-01-18 23:45 ` [PATCH 2/3] KVM test: Modify enospc test to not require scripts/check_image.py Lucas Meneghel Rodrigues 2011-01-19 6:05 ` [Autotest] " Michael Goldish 2011-01-18 23:45 ` [PATCH 3/3] KVM test: Removing scripts/check_image.py 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