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 <[email protected]>
---
  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 = ""):
      """
      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)
+    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:
+        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)


  def virsh_version(uri = ""):
--
1.7.1


_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to