Skip to content

Commit

Permalink
qemu_storage: Stop ignoring failures creating VM images
Browse files Browse the repository at this point in the history
By default, the qemu_storage code is ignoring failures
when qemu-img fails to create a disk image. This happens
because the failure is actually considered only if the
(terribly undocumented) param 'check_output' is set to
yes.

Since there's no 'check_output' on any .cfg file
in the virt-test repo, the failures will never be
considered and virt-tests will happily proceed, even
though a world of pain and suffering will follow.

Since there are future tests that might require the
output of the creation command, we'll fix the problem
by:

1) Introducing a ignore_errors boolean parameter to
the .create() method, when set to true it'll make
the method to not raise an error on failure.

2) Making the method return a fixed tuple
(path to the image created, object with the result
of the command). With the result object, it is easy
to get outputs as they are attributes of the said
object.

This also has the nice side effect of not requiring
the check_output parameter anymore.

Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
  • Loading branch information
lmr committed May 8, 2013
1 parent bcd4ff0 commit c390b3a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion qemu/tests/qemu_io_blkdebug.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run_qemu_io_blkdebug(test, params, env):

error.context("Create image", logging.info)
image_io = QemuImg(params.object_params(image), test.bindir, image)
image_name = image_io.create(params.object_params(image))
image_name, _ = image_io.create(params.object_params(image))

template_name = utils_misc.get_path(test.virtdir, blkdebug_default)
template = ConfigParser.ConfigParser()
Expand Down
4 changes: 2 additions & 2 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def preprocess_image(test, params, image_name):

if create_image:
image = qemu_storage.QemuImg(params, base_dir, image_name)
if not image.create(params):
raise error.TestError("Could not create image")
image.create(params)


def preprocess_vm(test, params, env, name):
"""
Expand Down
26 changes: 11 additions & 15 deletions virttest/qemu_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ def __init__(self, params, root_dir, tag):
params.get("qemu_img_binary","qemu-img"))


def create(self, params):
def create(self, params, ignore_errors=False):
"""
Create an image using qemu_img or dd.
@param params: Dictionary containing the test parameters.
@param ignore_errors: Whether to ignore errors on the image creation
cmd.
@note: params should contain:
image_name -- the name of the image file, without extension
Expand All @@ -51,6 +53,9 @@ def create(self, params):
values: on and off. Default is "off"
preallocated(optional) -- if preallocation when create image,
allowed values: off, metadata. Default is "off"
@return: tuple (path to the image created, utils.CmdResult object
containing the result of the creation command).
"""
if params.get("create_with_dd") == "yes" and self.image_format == "raw":
# maps K,M,G,T => (count, bs)
Expand Down Expand Up @@ -95,21 +100,12 @@ def create(self, params):

qemu_img_cmd += " %s" % self.size

check_output = params.get("check_output") == "yes"
try:
result = utils.run(qemu_img_cmd, verbose=False)
except error.CmdError, e:
logging.error("Could not create image, failed with error message:"
"%s", str(e))
if not check_output:
result = None
else:
result = str(e)
if not check_output:
result = self.image_filename

return result
cmd_result = utils.run(qemu_img_cmd, verbose=False, ignore_status=True)
if cmd_result.exit_status != 0 and not ignore_errors:
raise error.TestError("Failed to create image %s" %
self.image_filename)

return self.image_filename, cmd_result


def convert(self, params, root_dir):
Expand Down

0 comments on commit c390b3a

Please sign in to comment.