Message ID | 788a7179006d8edbc1f2a31c5110e0fdbc0e8092.1248102188.git.mgoldish@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Mon, Jul 20, 2009 at 12:07 PM, Michael Goldish<mgoldish@redhat.com> wrote: > Make some small style changes to handling of pre- and post-commands. > These changes are not required, but they make the code slightly shorter and > more consistent with the rest of the code (IMO). > Also, do not print "Adding ... to environment" for each parameter in the > dict because in some cases there are too many parameters and this generates > a lot of output. Nice cleanup, thanks. Applied. > Signed-off-by: Michael Goldish <mgoldish@redhat.com> > --- > Â client/tests/kvm/kvm_preprocessing.py | Â 38 +++++++++++++-------------------- > Â 1 files changed, 15 insertions(+), 23 deletions(-) > > diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py > index 71f7a6b..d118826 100644 > --- a/client/tests/kvm/kvm_preprocessing.py > +++ b/client/tests/kvm/kvm_preprocessing.py > @@ -141,30 +141,22 @@ def process_command(test, params, env, command, command_timeout, > Â Â @param test: An Autotest test object. > Â Â @param params: A dict containing all VM and image parameters. > Â Â @param env: The environment (a dict-like object). > - Â Â @param command: Script containing the command to be run. > - Â Â @param commmand_timeout: Timeout for command execution. > - Â Â @param command_noncritical: if 'yes' test will not fail if command fails. > + Â Â @param command: Command to be run. > + Â Â @param command_timeout: Timeout for command execution. > + Â Â @param command_noncritical: If True test will not fail if command fails. > Â Â """ > - Â Â if command_timeout is None: > - Â Â Â Â command_timeout = "600" > - > - Â Â if command_noncritical is None: > - Â Â Â Â command_noncritical = "no" > - > - Â Â # export environment vars > + Â Â # Export environment vars > Â Â for k in params.keys(): > - Â Â Â Â logging.info("Adding KVM_TEST_%s to Environment" % (k)) > - Â Â Â Â os.putenv("KVM_TEST_%s" % (k), str(params[k])) > - Â Â # execute command > + Â Â Â Â os.putenv("KVM_TEST_%s" % k, str(params[k])) > + Â Â # Execute command > Â Â logging.info("Executing command '%s'..." % command) > - Â Â timeout = int(command_timeout) > Â Â (status, output) = kvm_subprocess.run_fg("cd %s; %s" % (test.bindir, > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â command), > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â logging.debug, "(command) ", > - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â timeout=timeout) > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â timeout=command_timeout) > Â Â if status != 0: > - Â Â Â Â logging.warn("Custom processing command failed: '%s'..." % command) > - Â Â Â Â if command_noncritical != "yes": > + Â Â Â Â logging.warn("Custom processing command failed: '%s'" % command) > + Â Â Â Â if not command_noncritical: > Â Â Â Â Â Â raise error.TestError("Custom processing command failed") > > > @@ -214,11 +206,11 @@ def preprocess(test, params, env): > Â Â Â Â Â Â vm.destroy() > Â Â Â Â Â Â del env[key] > > - Â Â #execute any pre_commands > + Â Â # Execute any pre_commands > Â Â if params.get("pre_command"): > Â Â Â Â process_command(test, params, env, params.get("pre_command"), > - Â Â Â Â Â Â Â Â Â Â Â Â params.get("pre_command_timeout"), > - Â Â Â Â Â Â Â Â Â Â Â Â params.get("pre_command_noncritical")) > + Â Â Â Â Â Â Â Â Â Â Â Â int(params.get("pre_command_timeout", "600")), > + Â Â Â Â Â Â Â Â Â Â Â Â params.get("pre_command_noncritical") == "yes") > > Â Â # Preprocess all VMs and images > Â Â process(test, params, env, preprocess_image, preprocess_vm) > @@ -280,11 +272,11 @@ def postprocess(test, params, env): > Â Â Â Â rm_cmd = "rm -vf %s" % os.path.join(test.debugdir, "*.ppm") > Â Â Â Â kvm_subprocess.run_fg(rm_cmd, logging.debug, "(rm) ", timeout=5.0) > > - Â Â #execute any post_commands > + Â Â # Execute any post_commands > Â Â if params.get("post_command"): > Â Â Â Â process_command(test, params, env, params.get("post_command"), > - Â Â Â Â Â Â Â Â Â Â Â Â params.get("post_command_timeout"), > - Â Â Â Â Â Â Â Â Â Â Â Â params.get("post_command_noncritical")) > + Â Â Â Â Â Â Â Â Â Â Â Â int(params.get("post_command_timeout", "600")), > + Â Â Â Â Â Â Â Â Â Â Â Â params.get("post_command_noncritical") == "yes") > > > Â def postprocess_on_error(test, params, env): > -- > 1.5.4.1 > > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest >
diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py index 71f7a6b..d118826 100644 --- a/client/tests/kvm/kvm_preprocessing.py +++ b/client/tests/kvm/kvm_preprocessing.py @@ -141,30 +141,22 @@ def process_command(test, params, env, command, command_timeout, @param test: An Autotest test object. @param params: A dict containing all VM and image parameters. @param env: The environment (a dict-like object). - @param command: Script containing the command to be run. - @param commmand_timeout: Timeout for command execution. - @param command_noncritical: if 'yes' test will not fail if command fails. + @param command: Command to be run. + @param command_timeout: Timeout for command execution. + @param command_noncritical: If True test will not fail if command fails. """ - if command_timeout is None: - command_timeout = "600" - - if command_noncritical is None: - command_noncritical = "no" - - # export environment vars + # Export environment vars for k in params.keys(): - logging.info("Adding KVM_TEST_%s to Environment" % (k)) - os.putenv("KVM_TEST_%s" % (k), str(params[k])) - # execute command + os.putenv("KVM_TEST_%s" % k, str(params[k])) + # Execute command logging.info("Executing command '%s'..." % command) - timeout = int(command_timeout) (status, output) = kvm_subprocess.run_fg("cd %s; %s" % (test.bindir, command), logging.debug, "(command) ", - timeout=timeout) + timeout=command_timeout) if status != 0: - logging.warn("Custom processing command failed: '%s'..." % command) - if command_noncritical != "yes": + logging.warn("Custom processing command failed: '%s'" % command) + if not command_noncritical: raise error.TestError("Custom processing command failed") @@ -214,11 +206,11 @@ def preprocess(test, params, env): vm.destroy() del env[key] - #execute any pre_commands + # Execute any pre_commands if params.get("pre_command"): process_command(test, params, env, params.get("pre_command"), - params.get("pre_command_timeout"), - params.get("pre_command_noncritical")) + int(params.get("pre_command_timeout", "600")), + params.get("pre_command_noncritical") == "yes") # Preprocess all VMs and images process(test, params, env, preprocess_image, preprocess_vm) @@ -280,11 +272,11 @@ def postprocess(test, params, env): rm_cmd = "rm -vf %s" % os.path.join(test.debugdir, "*.ppm") kvm_subprocess.run_fg(rm_cmd, logging.debug, "(rm) ", timeout=5.0) - #execute any post_commands + # Execute any post_commands if params.get("post_command"): process_command(test, params, env, params.get("post_command"), - params.get("post_command_timeout"), - params.get("post_command_noncritical")) + int(params.get("post_command_timeout", "600")), + params.get("post_command_noncritical") == "yes") def postprocess_on_error(test, params, env):
Make some small style changes to handling of pre- and post-commands. These changes are not required, but they make the code slightly shorter and more consistent with the rest of the code (IMO). Also, do not print "Adding ... to environment" for each parameter in the dict because in some cases there are too many parameters and this generates a lot of output. Signed-off-by: Michael Goldish <mgoldish@redhat.com> --- client/tests/kvm/kvm_preprocessing.py | 38 +++++++++++++-------------------- 1 files changed, 15 insertions(+), 23 deletions(-)