On 02/27/2013 10:20 PM, Alex Jia wrote:
Signed-off-by: Alex Jia<[email protected]>
---
virttest/utils_cgroup.py | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/virttest/utils_cgroup.py b/virttest/utils_cgroup.py
index b6d3edb..d55609e 100755
--- a/virttest/utils_cgroup.py
+++ b/virttest/utils_cgroup.py
@@ -428,3 +428,32 @@ def resolve_task_cgroup_path(pid, controller):
mount_path = re.findall(r":%s:(\S*)\n" % controller, proc_cgroup_txt)
path = root_path + mount_path[0]
return path
+
+
+def service_cgconfig_control(action):
+ """
+ Cgconfig 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
+ """
+ actions = ['start', 'stop', 'restart', 'condrestart']
+ if action in actions:
+ try:
+ utils.run("service cgconfig %s" % action)
+ logging.debug("%s cgconfig successfuly", action)
+ return True
+ except error.CmdError, detail:
+ logging.error("Failed to %s cgconfig:\n%s", action, detail)
+ return False
+ elif action == "status":
+ cmd_result = utils.run("service cgconfig status", ignore_status=True)
+ if not cmd_result.exit_status and \
+ cmd_result.stdout.strip() == "Running":
+ logging.info("Cgconfig service is running")
+ return True
+ else:
+ return False
+ else:
+ raise error.TestError("Unknown action: %s" % action)
LGTM, with two optional suggestions:
1) Exceptions are also caught higher up and result in a error.TestError
being raised. However, if some other internal component wants to use
this function, having it catch a 'TestError' may be too general.
Suggest raising something more specific like ValueError instead.
2) Not sure if returning True/False is a convention for these type of
functions or not. However, one thing that's become apparent from work
on the virsh module- Sometimes it's more useful to just return the
CmdResult object and let the caller deal with it. I can see this being
easily argued both ways, so I leave it just as a suggestion.
--
Chris Evich, RHCA, RHCE, RHCDS, RHCSS
Quality Assurance Engineer
e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214
_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel