On Fri, Jun 1, 2012 at 3:39 AM, guyanhua <guyanhua-f...@cn.fujitsu.com> wrote:
>
>  Adding two params (default raise_error = True, extra_param = "")in virsh_cmd 
> function,
>  which can satisfy the basic use and test the virsh command through diff 
> params.
>  Besides, I modified the virsh_hostname function to satisfy more requirements.
>
> Signed-off-by: Gu Yanhua <guyanhua-f...@cn.fujitsu.com>
> ---
>  client/virt/libvirt_vm.py |   19 ++++++++++++-------
>  1 files changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
> index eda5e8e..2734a6c 100644
> --- a/client/virt/libvirt_vm.py
> +++ b/client/virt/libvirt_vm.py
> @@ -86,7 +86,7 @@ def service_libvirtd_control(action):
>          raise error.TestError("Unknown action: %s" % action)
>
>
> -def virsh_cmd(cmd, uri = ""):
> +def virsh_cmd(cmd, uri = "",raise_error = True, extra_param = ""):

here you can pass ignore_status=False, to match the structure of utils.run.

>      """
>      Append cmd to 'virsh' and execute, optionally return full results.
>
> @@ -100,10 +100,15 @@ def virsh_cmd(cmd, uri = ""):
>      uri_arg = ""
>      if uri:
>          uri_arg = "-c " + uri
> -    cmd = "%s %s %s" % (VIRSH_EXEC, uri_arg, cmd)
> -    cmd_result = utils.run(cmd, verbose=DEBUG)
> -    return cmd_result.stdout.strip()
> -
> +    cmd = "%s %s %s %s" % (VIRSH_EXEC, uri_arg, cmd, extra_param)
> +    cmd_result = utils.run(cmd, verbose=DEBUG, raise_error=raise_error)

Here, just pass ignore_status value

> +    logging.info("command:%s", cmd)
> +    logging.debug("stdout: %s", cmd_result.stdout.strip())
> +    logging.debug("exit_status: %s", cmd_result.exit_status)
> +    if raise_error:

this if can be reversed

if ignore_status:
    return cmd_result.exit_status, cmd_result.stdout.strip()
else:
    return cmd_result.stdout.strip()

To be honest, I'm not a huge fan of functions that return different
things depending on input, really. I'd return the tuple (exit status,
stdout) anyway in both cases, even it being 0, it's less of a surprise
for the API users.

> +        return cmd_result.stdout.strip()
> +    else:
> +        return cmd_result.exit_status, cmd_result.stdout.strip()
>
>  def virsh_uri(uri = ""):
>      """
> @@ -112,11 +117,11 @@ def virsh_uri(uri = ""):
>      return virsh_cmd("uri", uri)
>
>
> -def virsh_hostname(uri = ""):
> +def virsh_hostname(uri = "", raise_error = True, extra_param = ""):
>      """
>      Return the hypervisor hostname.
>      """
> -    return virsh_cmd("hostname", uri)
> +    return virsh_cmd("hostname", uri, raise_error, extra_param)

return virsh_cmd("hostname", uri, ignore_status, extra_param)
_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to