Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=3d9e3cf41... Commit: 3d9e3cf41f11da188e3f927ceb4b9f39435bc0a9 Parent: d7378e8c4b986fa490b31d53526edf24c6b0c9e1 Author: Marek 'marx' Grac mgrac@redhat.com AuthorDate: Fri Jun 7 13:01:43 2013 +0200 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Fri Jun 7 13:01:43 2013 +0200
fence_dummy: Add a 'fail' test dummy agent
--- fence/agents/dummy/fence_dummy.py | 77 ++++++++++++++++++++++++++++++++++--- 1 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/fence/agents/dummy/fence_dummy.py b/fence/agents/dummy/fence_dummy.py index ccf7f20..e24a0cc 100644 --- a/fence/agents/dummy/fence_dummy.py +++ b/fence/agents/dummy/fence_dummy.py @@ -10,7 +10,9 @@ REDHAT_COPYRIGHT="" BUILD_DATE="" #END_VERSION_GENERATION
-def get_power_status(conn, options): +plug_status="on" + +def get_power_status_file(conn, options): try: status_file = open(options["--status-file"], 'r') except: @@ -21,7 +23,7 @@ def get_power_status(conn, options):
return status.lower()
-def set_power_status(conn, options): +def set_power_status_file(conn, options): if not (options["--action"] in [ "on", "off" ]): return
@@ -29,21 +31,80 @@ def set_power_status(conn, options): status_file.write(options["--action"]) status_file.close()
+def get_power_status_fail(conn, options): + outlets = get_outlets_fail(conn,options) + + if len(outlets) == 0 or options.has_key("--plug") == 0: + fail_usage("Failed: You have to enter existing machine!") + else: + return outlets[options["--plug"]][0] + +def set_power_status_fail(conn, options): + global plug_status + + plug_status = "unknown" + if options["--action"] == "on": + plug_status = "off" + +def get_outlets_fail(conn, options): + result = {} + global plug_status + + if options["--action"] == "on": + plug_status = "off" + + # This fake agent has no port data to list, so we have to make + # something up for the list action. + if options.has_key("--action") and options["--action"] == "list": + result["fake_port_1"] = [plug_status, "fake"] + result["fake_port_2"] = [plug_status, "fake"] + elif (options.has_key("--plug") == 0): + fail_usage("Failed: You have to enter existing machine!") + else: + port = options["--plug"] + result[port] = [plug_status, "fake"] + + return result + def main(): - device_opt = [ "no_password", "status_file" ] + device_opt = [ "no_password", "status_file", "random_sleep_range", "type", "port" ]
atexit.register(atexit_handler)
all_opt["status_file"] = { "getopt" : "s:", "longopt" : "status-file", - "help":"--status-file=<file> Name of file that holds current status", + "help":"--status-file=[file] Name of file that holds current status", "required" : "0", "shortdesc" : "File with status", "default" : "/tmp/fence_dummy.status", "order": 1 }
+ all_opt["random_sleep_range"] = { + "getopt" : "R:", + "longopt" : "random_sleep_range", + "help":"--random_sleep_range=[seconds] Issue a sleep between 1 and [seconds]", + "required" : "0", + "shortdesc" : "Issue a sleep between 1 and X seconds. Used for testing.", + "order": 1 + } + + all_opt["type"] = { + "getopt" : "t:", + "longopt" : "type", + "help":"--type=[type] Possible types are: file and fail", + "required" : "0", + "shortdesc" : "Type of the dummy fence agent", + "default" : "file", + "order": 1 + } + + pinput = process_input(device_opt) + if (pinput.has_key("--type") and pinput["--type"] == "file") or (pinput.has_key("--type") == False): + # hack to have fence agents that require ports 'fail' and one that do not 'file' + device_opt.remove("port") + options = check_input(device_opt, process_input(device_opt))
docs = { } @@ -51,8 +112,12 @@ def main(): docs["longdesc"] = "fence_dummy" docs["vendorurl"] = "http://www.example.com" show_docs(options, docs) - - result = fence_action(None, options, set_power_status, get_power_status, None) + + if options["--type"] == "fail": + result = fence_action(None, options, set_power_status_fail, get_power_status_fail, get_outlets_fail) + else: + result = fence_action(None, options, set_power_status_file, get_power_status_file, None) + sys.exit(result)
if __name__ == "__main__":