Gitweb:
http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=ff21e9...
Commit: ff21e947b5aed25bc1842f43deecf4d3c2230725
Parent: af5da579e90acb9c70ad0f97eff42cd14fd708b5
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Thu Nov 8 10:29:14 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Nov 8 10:39:30 2012 +0100
fence_hds_cb: Push exception handling to fencing library
Exception handling of network failures should be handled in fencing library. Old fence
agents are already
ported to this new behaviour.
---
fence/agents/hds_cb/fence_hds_cb.py | 150 ++++++++++++++++-------------------
1 files changed, 67 insertions(+), 83 deletions(-)
diff --git a/fence/agents/hds_cb/fence_hds_cb.py b/fence/agents/hds_cb/fence_hds_cb.py
index 1f944b3..ab44e2f 100755
--- a/fence/agents/hds_cb/fence_hds_cb.py
+++ b/fence/agents/hds_cb/fence_hds_cb.py
@@ -23,39 +23,34 @@ BUILD_DATE="November, 2012"
RE_STATUS_LINE = "^([0-9]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$"
def get_power_status(conn, options):
- try:
- #### Maybe should put a conn.log_expect here to make sure
- #### we have properly entered into the main menu
- conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
- conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- result = {}
- # Status can now be obtained from the output of the PC
- # command. Line looks like the following:
- # "P Power Condition LID lamp Mode Auto power on"
- # "0 On Normal Off Basic Synchronized"
- # "1 On Normal Off Basic Synchronized"
- for line in conn.before.splitlines():
- # populate the relevant fields based on regex
- partition = re.search(RE_STATUS_LINE, line)
- if( partition != None):
- # find the blade number defined in args
- if( partition.group(1) == options["--plug"] ):
- result = partition.group(2).lower()
- # We must make sure we go back to the main menu as the
- # status is checked before any fencing operations are
- # executed. We could in theory save some time by staying in
- # the partition control, but the logic is a little cleaner
- # this way.
- conn.sendline("Q") # Back to system command mode
- conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
- conn.sendline("EX") # Back to system console main menu
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ #### Maybe should put a conn.log_expect here to make sure
+ #### we have properly entered into the main menu
+ conn.sendline("S") # Enter System Command Mode
+ conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
+ conn.sendline("PC") # Enter partition control
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
+ result = {}
+ # Status can now be obtained from the output of the PC
+ # command. Line looks like the following:
+ # "P Power Condition LID lamp Mode Auto power on"
+ # "0 On Normal Off Basic Synchronized"
+ # "1 On Normal Off Basic Synchronized"
+ for line in conn.before.splitlines():
+ # populate the relevant fields based on regex
+ partition = re.search(RE_STATUS_LINE, line)
+ if( partition != None):
+ # find the blade number defined in args
+ if( partition.group(1) == options["--plug"] ):
+ result = partition.group(2).lower()
+ # We must make sure we go back to the main menu as the
+ # status is checked before any fencing operations are
+ # executed. We could in theory save some time by staying in
+ # the partition control, but the logic is a little cleaner
+ # this way.
+ conn.sendline("Q") # Back to system command mode
+ conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
+ conn.sendline("EX") # Back to system console main menu
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
return result
@@ -67,56 +62,47 @@ def set_power_status(conn, options):
}[options["--action"]]
- try:
- conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
- conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- conn.sendline("P") # Enter power control menu
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- conn.sendline(action) # Execute action from array above
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- conn.sendline(options["--plug"]) # Select blade number from args
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- conn.sendline("Y") # Confirm action
- conn.log_expect(options, "Hit enter key.",
int(options["--shell-timeout"]))
- conn.sendline("") # Press the any key
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- conn.sendline("Q") # Quit back to partition control
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- conn.sendline("Q") # Quit back to system command mode
- conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
- conn.sendline("EX") # Quit back to system console menu
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.sendline("S") # Enter System Command Mode
+ conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
+ conn.sendline("PC") # Enter partition control
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
+ conn.sendline("P") # Enter power control menu
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
+ conn.sendline(action) # Execute action from array above
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
+ conn.sendline(options["--plug"]) # Select blade number from args
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
+ conn.sendline("Y") # Confirm action
+ conn.log_expect(options, "Hit enter key.",
int(options["--shell-timeout"]))
+ conn.sendline("") # Press the any key
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
+ conn.sendline("Q") # Quit back to partition control
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
+ conn.sendline("Q") # Quit back to system command mode
+ conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
+ conn.sendline("EX") # Quit back to system console menu
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
def get_blades_list(conn, options):
outlets = { }
- try:
- conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
- conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- # Status can now be obtained from the output of the PC
- # command. Line looks like the following:
- # "P Power Condition LID lamp Mode Auto power on"
- # "0 On Normal Off Basic Synchronized"
- # "1 On Normal Off Basic Synchronized"
- for line in conn.before.splitlines():
- partition = re.search(RE_STATUS_LINE, line)
- if( partition != None):
- outlets[partition.group(1)] = (partition.group(2), "")
- conn.sendline("Q") # Quit back to system command mode
- conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
- conn.sendline("EX") # Quit back to system console menu
- conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+
+ conn.sendline("S") # Enter System Command Mode
+ conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
+ conn.sendline("PC") # Enter partition control
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
+ # Status can now be obtained from the output of the PC
+ # command. Line looks like the following:
+ # "P Power Condition LID lamp Mode Auto power on"
+ # "0 On Normal Off Basic Synchronized"
+ # "1 On Normal Off Basic Synchronized"
+ for line in conn.before.splitlines():
+ partition = re.search(RE_STATUS_LINE, line)
+ if( partition != None):
+ outlets[partition.group(1)] = (partition.group(2), "")
+ conn.sendline("Q") # Quit back to system command mode
+ conn.log_expect(options, "SVP>",
int(options["--shell-timeout"]))
+ conn.sendline("EX") # Quit back to system console menu
+ conn.log_expect(options, options["--command-prompt"],
int(options["--shell-timeout"]))
return outlets
@@ -152,9 +138,7 @@ includes telnet support."
try:
conn.sendline("X")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)