Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=dfff684d5... Commit: dfff684d59a6c427c9bb680f9a26b9b960005486 Parent: f0969886c13feae734547d4cb9241f9f6eae0d9f Author: Marek 'marx' Grac mgrac@redhat.com AuthorDate: Mon Feb 11 19:07:36 2013 +0100 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Mon Feb 11 19:07:36 2013 +0100
fence_apc: Add support for firmware 5.x
New major version of firmware is now supported.
Resolves: rhbz#886614 --- fence/agents/apc/fence_apc.py | 51 ++++++++++++++++++++++++++++++++++++--- fence/agents/lib/fencing.py.py | 14 +++++++++- tests/actions.d/list.cfg | 2 + tests/test-apc2.py | 17 +++++++++++++ tests/test-apc5.py | 17 +++++++++++++ 5 files changed, 95 insertions(+), 6 deletions(-)
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py index 1d82957..13b1e69 100644 --- a/fence/agents/apc/fence_apc.py +++ b/fence/agents/apc/fence_apc.py @@ -68,7 +68,7 @@ def get_power_status(conn, options): conn.send_eol(options["--switch"]) while True: - exp_result = conn.log_expect(options, [ options["--command-prompt"], "Press <ENTER>" ], int(options["--shell-timeout"])) + exp_result = conn.log_expect(options, options["--command-prompt"] + [ "Press <ENTER>" ], int(options["--shell-timeout"])) lines = conn.before.split("\n") show_re = re.compile('(^|\x0D)\s*(\d+)- (.*?)\s+(ON|OFF)\s*') for x in lines: @@ -146,7 +146,7 @@ def set_power_status(conn, options): else: conn.send_eol(options["--switch"])
- while 1 == conn.log_expect(options, [ options["--command-prompt"], "Press <ENTER>" ], int(options["--shell-timeout"])): + while 1 == conn.log_expect(options, options["--command-prompt"] + [ "Press <ENTER>" ], int(options["--shell-timeout"])): conn.send_eol("")
conn.send_eol(options["--plug"]+"") @@ -173,13 +173,47 @@ def set_power_status(conn, options): conn.log_expect(options, "- Logout", int(options["--shell-timeout"])) conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+def get_power_status5(conn, options): + exp_result = 0 + outlets = {} + + conn.send_eol("olStatus all") + + exp_result = conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) + lines = conn.before.split("\n") + + show_re = re.compile('^\s*(\d+): (.*): (On|Off)\s*$', re.IGNORECASE) + + for x in lines: + res = show_re.search(x) + if (res != None): + outlets[res.group(1)] = (res.group(2), res.group(3)) + + if ["list", "monitor"].count(options["--action"]) == 1: + return outlets + else: + try: + (_, status) = outlets[options["--plug"]] + return status.lower().strip() + except KeyError: + fail(EC_STATUS) + +def set_power_status5(conn, options): + action = { + 'on' : "olOn", + 'off': "olOff" + }[options["--action"]] + + conn.send_eol(action + " " + options["--plug"]) + conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"])) + def main(): device_opt = [ "ipaddr", "login", "passwd", "cmd_prompt", "secure", \ "port", "switch" ]
atexit.register(atexit_handler)
- all_opt["cmd_prompt"]["default"] = "\n>" + all_opt["cmd_prompt"]["default"] = [ "\n>", "\napc>" ] all_opt["ssh_options"]["default"] = "-1 -c blowfish"
options = check_input(device_opt, process_input(device_opt)) @@ -204,7 +238,16 @@ will block any necessary fencing actions." ## Operate the fencing device #### conn = fence_login(options) - result = fence_action(conn, options, set_power_status, get_power_status, get_power_status) + + ## Detect firmware version (ASCII menu vs command-line interface) + ## and continue with proper action + #### + result = -1 + firmware_version = re.compile('\s*v(\d)*.').search(conn.before) + if (firmware_version != None) and (firmware_version.group(1) == "5"): + result = fence_action(conn, options, set_power_status5, get_power_status5, get_power_status5) + else: + result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
## ## Logout from system diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 37be50e..188ee1f 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -862,7 +862,8 @@ def fence_login(options): time.sleep(int(options["--delay"]))
try: - re_login = re.compile("(login\s*: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE) + re_login_string = "(login\s*: )|(Login Name: )|(username: )|(User Name :)" + re_login = re.compile(re_login_string, re.IGNORECASE) re_pass = re.compile("(password)|(pass phrase)", re.IGNORECASE)
if options.has_key("--ssl"): @@ -955,7 +956,16 @@ def fence_login(options):
try: conn.send_eol(options["--password"]) - conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"])) + valid_password = conn.log_expect(options, [ re_login_string ] + options["--command-prompt"], int(options["--shell-timeout"])) + if valid_password == 0: + ## password is invalid or we have to change EOL separator + options["eol"] = "\r" + conn.send_eol("") + conn.send_eol("") + conn.send_eol(options["--username"]) + conn.log_expect(options, re_pass, int(options["--login-timeout"])) + conn.send_eol(options["--password"]) + conn.log_expect(options, options["--command-prompt"], int(options["--login-timeout"])) except KeyError: fail(EC_PASSWORD_MISSING) except pexpect.EOF: diff --git a/tests/actions.d/list.cfg b/tests/actions.d/list.cfg new file mode 100644 index 0000000..b7ed552 --- /dev/null +++ b/tests/actions.d/list.cfg @@ -0,0 +1,2 @@ +name = "List plugs and check port 6" +actions = [ { "command" : "list", "return_code" : "^0$" } ] diff --git a/tests/test-apc2.py b/tests/test-apc2.py new file mode 100755 index 0000000..bb5aefd --- /dev/null +++ b/tests/test-apc2.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +from fence_testing import test_action + +def main(): + DEVICE = "devices.d/apc-v2.cfg" + + ACT_STATUS = "actions.d/status.cfg" + ACT_ONOFF = "actions.d/power-on-off.cfg" + ACT_LIST = "actions.d/list.cfg" + + test_action(DEVICE, ACT_STATUS, "getopt") + test_action(DEVICE, ACT_ONOFF, "stdin") + test_action(DEVICE, ACT_LIST, "getopt") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/test-apc5.py b/tests/test-apc5.py new file mode 100755 index 0000000..7e86a91 --- /dev/null +++ b/tests/test-apc5.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +from fence_testing import test_action + +def main(): + DEVICE = "devices.d/apc-v5.cfg" + + ACT_STATUS = "actions.d/status.cfg" + ACT_ONOFF = "actions.d/power-on-off.cfg" + ACT_LIST = "actions.d/list.cfg" + + test_action(DEVICE, ACT_STATUS, "getopt") + test_action(DEVICE, ACT_ONOFF, "stdin") + test_action(DEVICE, ACT_LIST, "getopt") + +if __name__ == "__main__": + main() \ No newline at end of file
cluster-commits@lists.fedorahosted.org