This patch adds service_libvirtd_control API to libvirt_vm.py file.
Signed-off-by: Gu Yanhua <[email protected]>
---
client/virt/libvirt_vm.py | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index 74dbad2..c9345e0 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -55,6 +55,35 @@ def libvirtd_start():
logging.error("Failed to start libvirtd:\n%s", detail)
return False
+def service_libvirtd_control(action):
+ """
+ Libvirtd control by action, if cmd executes successfully,
+ return True, otherwise return False.
+ If the action is status, return True when it's running,
+ otherwise return False.
+ @ param action: start|stop|status|restart|condrestart|
+ reload|force-reload|try-restart
+ """
+ actions = ['start','stop','restart','condrestart','reload',\
+ 'force-reload','try-restart']
+ if action in actions:
+ try:
+ utils.run("service libvirtd %s" % action)
+ logging.debug("%s libvirtd successfuly", action)
+ return True
+ except error.CmdError, detail:
+ logging.error("Failed to %s libvirtd:\n%s", (action, detail))
+ return False
+ elif action == "status":
+ cmd_result = utils.run("service libvirtd status")
+ if re.search("pid", cmd_result.stdout.strip()):
+ logging.info("Libvirtd service is running")
+ return True
+ else:
+ return False
+ else:
+ raise error.TestError("Unknown action: %s" % action)
+
def virsh_cmd(cmd, uri = ""):
"""
--
1.7.1
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest