fence-agents: master - [cleanup] Remove warning logging-not-lazy
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=c84df1...
Commit: c84df1578d288fb23e2cd72e1704f7c4234b7fd4
Parent: 364de00cdd7619ad65f5eabdab2d8499d448045d
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Wed Apr 16 17:18:04 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Wed Apr 23 17:38:41 2014 +0200
[cleanup] Remove warning logging-not-lazy
---
fence/agents/cisco_ucs/fence_cisco_ucs.py | 4 +-
fence/agents/dummy/fence_dummy.py | 2 +-
fence/agents/eps/fence_eps.py | 8 +++---
fence/agents/lib/XenAPI.py.py | 2 +-
fence/agents/lib/fencing.py.py | 30 ++++++++++++++--------------
fence/agents/lib/fencing_snmp.py.py | 2 +-
fence/agents/ovh/fence_ovh.py | 8 +++---
fence/agents/rhevm/fence_rhevm.py | 4 +-
fence/agents/vmware/fence_vmware.py | 6 ++--
9 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py
index 0a4bff7..afe2c0d 100644
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -96,8 +96,8 @@ def send_command(opt, command, timeout):
conn.perform()
result = web_buffer.getvalue()
- logging.debug("%s\n" % command)
- logging.debug("%s\n" % result)
+ logging.debug("%s\n", command)
+ logging.debug("%s\n", result)
return result
diff --git a/fence/agents/dummy/fence_dummy.py b/fence/agents/dummy/fence_dummy.py
index 9f0e950..f460746 100644
--- a/fence/agents/dummy/fence_dummy.py
+++ b/fence/agents/dummy/fence_dummy.py
@@ -128,7 +128,7 @@ def main():
if options.has_key("--random_sleep_range"):
val = int(options["--random_sleep_range"])
ran = random.randint(1, val)
- logging.info("Random sleep for %d seconds\n" % ran)
+ logging.info("Random sleep for %d seconds\n", ran)
time.sleep(ran)
if options["--type"] == "fail":
diff --git a/fence/agents/eps/fence_eps.py b/fence/agents/eps/fence_eps.py
index 68a0991..740a9e5 100644
--- a/fence/agents/eps/fence_eps.py
+++ b/fence/agents/eps/fence_eps.py
@@ -30,7 +30,7 @@ def eps_run_command(options, params):
if params != "":
request_str += "?"+params
- logging.debug("GET %s\n" % request_str)
+ logging.debug("GET %s\n", request_str)
conn.putrequest('GET', request_str)
if options.has_key("--username"):
@@ -39,21 +39,21 @@ def eps_run_command(options, params):
# String for Authorization header
auth_str = 'Basic ' + string.strip(base64.encodestring(options["--username"]+':'+options["--password"]))
- logging.debug("Authorization: %s\n" % auth_str)
+ logging.debug("Authorization: %s\n", auth_str)
conn.putheader('Authorization', auth_str)
conn.endheaders()
response = conn.getresponse()
- logging.debug("%d %s\n"%(response.status, response.reason))
+ logging.debug("%d %s\n", response.status, response.reason)
#Response != OK -> couldn't login
if response.status != 200:
fail(EC_LOGIN_DENIED)
result = response.read()
- logging.debug("%s \n" % result)
+ logging.debug("%s \n", result)
conn.close()
except socket.timeout:
fail(EC_TIMED_OUT)
diff --git a/fence/agents/lib/XenAPI.py.py b/fence/agents/lib/XenAPI.py.py
index 9928bba..f9b7687 100644
--- a/fence/agents/lib/XenAPI.py.py
+++ b/fence/agents/lib/XenAPI.py.py
@@ -73,7 +73,7 @@ class Failure(Exception):
return "Message database broken: %s.\nXen-API failure: %s" % \
(exn, str(self.details))
except Exception, exn:
- logging.error("%s\n" % str(exn))
+ logging.error("%s\n", str(exn))
return "Xen-API failure: %s" % str(self.details)
def _details_map(self):
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 63c046d..b4ecea7 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -382,17 +382,17 @@ DEPENDENCY_OPT = {
class fspawn(pexpect.spawn):
def __init__(self, options, command):
- logging.info("Running command: %s" % command)
+ logging.info("Running command: %s", command)
pexpect.spawn.__init__(self, command)
self.opt = options
def log_expect(self, options, pattern, timeout):
result = self.expect(pattern, timeout)
- logging.debug("Received: %s" % (self.before + self.after))
+ logging.debug("Received: %s", self.before + self.after)
return result
def send(self, message):
- logging.debug("Sent: %s" % message)
+ logging.debug("Sent: %s", message)
return pexpect.spawn.send(self, message)
# send EOL according to what was detected in login process (telnet)
@@ -404,7 +404,7 @@ def atexit_handler():
sys.stdout.close()
os.close(1)
except IOError:
- logging.error("%s failed to close standard output\n" % (sys.argv[0]))
+ logging.error("%s failed to close standard output\n", sys.argv[0])
syslog.syslog(syslog.LOG_ERR, "Failed to close standard output")
sys.exit(EC_GENERIC_ERROR)
@@ -418,7 +418,7 @@ def add_dependency_options(options):
def fail_usage(message = ""):
if len(message) > 0:
- logging.error("%s\n" % message)
+ logging.error("%s\n", message)
logging.error("Please use '-h' for usage\n")
sys.exit(EC_GENERIC_ERROR)
@@ -435,7 +435,7 @@ def fail(error_code):
EC_PASSWORD_MISSING : "Failed: You have to set login password",
EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to do the requested action."
}[error_code] + "\n"
- logging.error("%s\n" % message)
+ logging.error("%s\n", message)
syslog.syslog(syslog.LOG_ERR, message)
sys.exit(EC_GENERIC_ERROR)
@@ -603,8 +603,8 @@ def process_input(avail_opt):
value = value[:-1]
if avail_opt.count(name) == 0:
- logging.warning("Parse error: Ignoring unknown option '%s'\n" % line)
- syslog.syslog(syslog.LOG_WARNING, "Parse error: Ignoring unknown option '"+line)
+ logging.warning("Parse error: Ignoring unknown option '%s'\n", line)
+ syslog.syslog(syslog.LOG_WARNING, "Parse error: Ignoring unknown option '" + line)
continue
if all_opt[name]["getopt"].endswith(":"):
@@ -741,7 +741,7 @@ def check_input(device_opt, opt):
fh.setLevel(logging.DEBUG)
logging.getLogger().addHandler(fh)
except IOError:
- logging.error("Unable to create file %s" % options["--debug-file"])
+ logging.error("Unable to create file %s", options["--debug-file"])
fail_usage("Failed: Unable to create file " + options["--debug-file"])
if options.has_key("--snmp-priv-passwd-script"):
@@ -932,7 +932,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
except Exception, ex:
# an error occured during power ON phase in reboot
# fence action was completed succesfully even in that case
- logging.error("%s\n", str(ex))
+ logging.error("%s", str(ex))
syslog.syslog(syslog.LOG_NOTICE, str(ex))
if power_on == False:
@@ -952,7 +952,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
except pycurl.error, ex:
- logging.error("%s\n" % str(ex))
+ logging.error("%s\n", str(ex))
syslog.syslog(syslog.LOG_ERR, ex[1])
fail(EC_TIMED_OUT)
@@ -976,7 +976,7 @@ def fence_login(options, re_login_string = r"(login\s*: )|(Login Name: )|(usern
## Do the delay of the fence device before logging in
## Delay is important for two-node clusters fencing but we do not need to delay 'status' operations
if options["--action"] in ["off", "reboot"]:
- logging.info("Delay %s second(s) before logging in to the fence device" % options["--delay"])
+ logging.info("Delay %s second(s) before logging in to the fence device", options["--delay"])
time.sleep(int(options["--delay"]))
try:
@@ -993,7 +993,7 @@ def fence_login(options, re_login_string = r"(login\s*: )|(Login Name: )|(usern
try:
conn = fspawn(options, command)
except pexpect.ExceptionPexpect, ex:
- logging.error("%s\n" % str(ex))
+ logging.error("%s\n", str(ex))
syslog.syslog(syslog.LOG_ERR, str(ex))
sys.exit(EC_GENERIC_ERROR)
elif options.has_key("--ssh") and 0 == options.has_key("--identity-file"):
@@ -1103,7 +1103,7 @@ def run_command(options, command, timeout = None, env = None):
if timeout is not None:
timeout = float(timeout)
- logging.info("Executing: %s\n" % command)
+ logging.info("Executing: %s\n", command)
try:
process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
@@ -1123,6 +1123,6 @@ def run_command(options, command, timeout = None, env = None):
process.stdout.close()
process.stderr.close()
- logging.debug("%s %s %s\n" % (str(status), str(pipe_stdout), str(pipe_stderr)))
+ logging.debug("%s %s %s\n", str(status), str(pipe_stdout), str(pipe_stderr))
return (status, pipe_stdout, pipe_stderr)
diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py
index 24ad171..997e2da 100644
--- a/fence/agents/lib/fencing_snmp.py.py
+++ b/fence/agents/lib/fencing_snmp.py.py
@@ -22,7 +22,7 @@ class FencingSnmp:
# Log message if user set verbose option
def log_command(self, message):
- logging.debug("%s\n" % message)
+ logging.debug("%s\n", message)
def quote_for_run(self, string):
return string.replace(r"'", "'\\''")
diff --git a/fence/agents/ovh/fence_ovh.py b/fence/agents/ovh/fence_ovh.py
index f4e9caf..0f460df 100644
--- a/fence/agents/ovh/fence_ovh.py
+++ b/fence/agents/ovh/fence_ovh.py
@@ -126,13 +126,13 @@ Poweroff is simulated with a reboot into rescue-pro mode."
# Verify that action was completed sucesfully
reboot_t = reboot_time(options)
- logging.debug("reboot_start_end.start: %s\n" %
+ logging.debug("reboot_start_end.start: %s\n",
reboot_t.start.strftime('%Y-%m-%d %H:%M:%S'))
- logging.debug("before_netboot_reboot: %s\n" %
+ logging.debug("before_netboot_reboot: %s\n",
before_netboot_reboot.strftime('%Y-%m-%d %H:%M:%S'))
- logging.debug("reboot_start_end.end: %s\n" %
+ logging.debug("reboot_start_end.end: %s\n",
reboot_t.end.strftime('%Y-%m-%d %H:%M:%S'))
- logging.debug("after_netboot_reboot: %s\n" %
+ logging.debug("after_netboot_reboot: %s\n",
after_netboot_reboot.strftime('%Y-%m-%d %H:%M:%S'))
if reboot_t.start < after_netboot_reboot < reboot_t.end:
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
index 8ff5ee9..cd75c3b 100644
--- a/fence/agents/rhevm/fence_rhevm.py
+++ b/fence/agents/rhevm/fence_rhevm.py
@@ -101,8 +101,8 @@ def send_command(opt, command, method = "GET"):
conn.perform()
result = web_buffer.getvalue()
- logging.debug("%s\n" % command)
- logging.debug("%s\n" % result)
+ logging.debug("%s\n", command)
+ logging.debug("%s\n", result)
return result
diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py
index 00e7632..63e809a 100644
--- a/fence/agents/vmware/fence_vmware.py
+++ b/fence/agents/vmware/fence_vmware.py
@@ -144,7 +144,7 @@ def vmware_run_command(options, add_login_params, additional_params, additional_
command = vmware_prepare_command(options, add_login_params, additional_params)
try:
- logging.debug("%s\n" % command)
+ logging.debug("%s\n", command)
(res_output, res_code) = pexpect.run(command,
int(options["--shell-timeout"]) + int(options["--login-timeout"]) + additional_timeout, True)
@@ -152,10 +152,10 @@ def vmware_run_command(options, add_login_params, additional_params, additional_
if res_code == None:
fail(EC_TIMED_OUT)
if res_code != 0 and add_login_params:
- logging.debug("%s\n" % res_output)
+ logging.debug("%s\n", res_output)
fail_usage("%s returned %s"% (options["--exec"], res_output))
else:
- logging.debug("%s\n" % res_output)
+ logging.debug("%s\n", res_output)
except pexpect.ExceptionPexpect:
fail_usage("Cannot run command %s"% (options["--exec"]))
10 years, 2 months
cluster: RHEL510 - libgfs2: Fix up remove_mtab_entry
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=2626fb3ca90...
Commit: 2626fb3ca90e285ab703f0da96955e3d0f5190c7
Parent: 6bb05a0862875033268faceddc764c2b2c313510
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Feb 4 00:00:05 2014 -0600
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 23 14:44:22 2014 +0100
libgfs2: Fix up remove_mtab_entry
mkstemp was creating the temporary mtab file with overly tight
permissions causing /etc/mtab to end up with an 0600 mode instead of the
regular 0644. This patch resets the mode to 0644 by calling fchmod on
the file descriptor returned by mkstemp.
It also removes a superfluous close() call and sets the temp filename
char array on initialisation instead of using strcpy().
Resolves: rhbz#1086861
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/misc.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 6a1f07f..838209e 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -227,7 +227,7 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
{
FILE *mtab, *mtabnew;
struct mntent *mountent;
- char mtab_tmpfn[PATH_MAX];
+ char mtab_tmpfn[] = "/etc/mtab.XXXXXX";
int error, fd;
mode_t mask;
@@ -235,7 +235,7 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
if (mtab == NULL)
die("Couldn't open /etc/mtab for writing: %s\n",
strerror(errno));
- strcpy(mtab_tmpfn, "/etc/mtab.XXXXXX");
+
mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
fd = mkstemp(mtab_tmpfn);
umask(mask);
@@ -243,6 +243,9 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
die("Couldn't open temporary mtab file for writing: %s\n",
strerror(errno));
+ if (fchmod(fd, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH))
+ die("Couldn't change mode of temporary mtab: %s\n", strerror(errno));
+
mtabnew = fdopen(fd, "wt");
if (mtabnew == NULL)
die("Couldn't open %s for writing : %s\n", mtab_tmpfn,
@@ -257,8 +260,7 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
}
endmntent(mtab);
- fclose(mtabnew);
- close(fd);
+ fclose(mtabnew); /* Closes underlying fd */
if (rename(mtab_tmpfn, "/etc/mtab"))
fprintf(stderr, "Unable to remove mount entry from mtab.\n");
}
10 years, 2 months
fence-agents: master - fencing: Pexpect problems - missing return statement
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=364de0...
Commit: 364de00cdd7619ad65f5eabdab2d8499d448045d
Parent: a61329c3e6611f0b49fe3d0eef25b35080651ebe
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Wed Apr 16 16:09:47 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Wed Apr 16 16:09:47 2014 +0200
fencing: Pexpect problems - missing return statement
Previusly pexpect.send() returned value which was not used anywhere, with new version this is no
longer true and our inherited class fspawn has to return proper values (length of the written string)
---
fence/agents/lib/fencing.py.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 6a30ef8..63c046d 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -393,11 +393,11 @@ class fspawn(pexpect.spawn):
def send(self, message):
logging.debug("Sent: %s" % message)
- pexpect.spawn.send(self, message)
+ return pexpect.spawn.send(self, message)
# send EOL according to what was detected in login process (telnet)
def send_eol(self, message):
- self.send(message + self.opt["eol"])
+ return self.send(message + self.opt["eol"])
def atexit_handler():
try:
10 years, 2 months
fence-agents: master - fencing: Fix invalid parsing in XML metadata
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=a61329...
Commit: a61329c3e6611f0b49fe3d0eef25b35080651ebe
Parent: 90ce5ac64762f54eada6cc6f4623a98e2eb493f7
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Wed Apr 16 15:01:11 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Wed Apr 16 15:01:11 2014 +0200
fencing: Fix invalid parsing in XML metadata
This error has no functional impact on fence agents integration.
---
fence/agents/lib/fencing.py.py | 2 +-
tests/data/metadata/fence_apc.xml | 3 +--
tests/data/metadata/fence_bladecenter.xml | 3 +--
tests/data/metadata/fence_brocade.xml | 3 +--
tests/data/metadata/fence_cisco_ucs.xml | 3 +--
tests/data/metadata/fence_drac5.xml | 3 +--
tests/data/metadata/fence_hds_cb.xml | 3 +--
tests/data/metadata/fence_hpblade.xml | 3 +--
tests/data/metadata/fence_ilo_mp.xml | 3 +--
tests/data/metadata/fence_rhevm.xml | 3 +--
tests/data/metadata/fence_rsa.xml | 3 +--
tests/data/metadata/fence_vmware_soap.xml | 3 +--
tests/data/metadata/fence_wti.xml | 3 +--
13 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index c84476f..6a30ef8 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -494,7 +494,7 @@ def metadata(avail_opt, options, docs):
mixed = all_opt[option]["help"]
## split it between option and help text
- res = re.compile(r"^(.*--\S+)\s+", re.IGNORECASE | re.S).search(mixed)
+ res = re.compile(r"^(.*?--\S+)\s+", re.IGNORECASE | re.S).search(mixed)
if None != res:
mixed = res.group(1)
mixed = mixed.replace("<", "<").replace(">", ">")
diff --git a/tests/data/metadata/fence_apc.xml b/tests/data/metadata/fence_apc.xml
index 0e6b265..441de61 100644
--- a/tests/data/metadata/fence_apc.xml
+++ b/tests/data/metadata/fence_apc.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.apc.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_bladecenter.xml b/tests/data/metadata/fence_bladecenter.xml
index 8ab7939..ec1b011 100644
--- a/tests/data/metadata/fence_bladecenter.xml
+++ b/tests/data/metadata/fence_bladecenter.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.ibm.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_brocade.xml b/tests/data/metadata/fence_brocade.xml
index 4670da8..5373d0e 100644
--- a/tests/data/metadata/fence_brocade.xml
+++ b/tests/data/metadata/fence_brocade.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.brocade.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_cisco_ucs.xml b/tests/data/metadata/fence_cisco_ucs.xml
index c5b6b37..30a3cb4 100644
--- a/tests/data/metadata/fence_cisco_ucs.xml
+++ b/tests/data/metadata/fence_cisco_ucs.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.cisco.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 80, 443 if --ssl" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="80" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_drac5.xml b/tests/data/metadata/fence_drac5.xml
index a461cb6..d96484c 100644
--- a/tests/data/metadata/fence_drac5.xml
+++ b/tests/data/metadata/fence_drac5.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.dell.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_hds_cb.xml b/tests/data/metadata/fence_hds_cb.xml
index c1bb5b9..8f5279a 100644
--- a/tests/data/metadata/fence_hds_cb.xml
+++ b/tests/data/metadata/fence_hds_cb.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.hds.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_hpblade.xml b/tests/data/metadata/fence_hpblade.xml
index 255f7f3..4f0976b 100644
--- a/tests/data/metadata/fence_hpblade.xml
+++ b/tests/data/metadata/fence_hpblade.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.hp.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_ilo_mp.xml b/tests/data/metadata/fence_ilo_mp.xml
index 8960349..93503a0 100644
--- a/tests/data/metadata/fence_ilo_mp.xml
+++ b/tests/data/metadata/fence_ilo_mp.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.hp.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_rhevm.xml b/tests/data/metadata/fence_rhevm.xml
index 1324839..a47f025 100644
--- a/tests/data/metadata/fence_rhevm.xml
+++ b/tests/data/metadata/fence_rhevm.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.redhat.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 80, 443 if --ssl" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="80" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_rsa.xml b/tests/data/metadata/fence_rsa.xml
index ee0421a..749b21d 100644
--- a/tests/data/metadata/fence_rsa.xml
+++ b/tests/data/metadata/fence_rsa.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.ibm.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_vmware_soap.xml b/tests/data/metadata/fence_vmware_soap.xml
index 52dedfa..97d8fc6 100644
--- a/tests/data/metadata/fence_vmware_soap.xml
+++ b/tests/data/metadata/fence_vmware_soap.xml
@@ -6,8 +6,7 @@ Name of virtual machine (-n / port) has to be used in inventory path format (e.g
<vendor-url>http://www.vmware.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 80, 443 if --ssl" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="80" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
diff --git a/tests/data/metadata/fence_wti.xml b/tests/data/metadata/fence_wti.xml
index 0c05620..c7cb9d1 100644
--- a/tests/data/metadata/fence_wti.xml
+++ b/tests/data/metadata/fence_wti.xml
@@ -4,8 +4,7 @@
<vendor-url>http://www.wti.com</vendor-url>
<parameters>
<parameter name="ipport" unique="0" required="0">
- <getopt mixed="-u, --ipport=[port] TCP/UDP port to use
- (default 23, 22 if --ssh" />
+ <getopt mixed="-u, --ipport=[port]" />
<content type="string" default="23" />
<shortdesc lang="en">TCP/UDP port to use for connection with device</shortdesc>
</parameter>
10 years, 2 months
fence-agents: master - fencing: ipport defaults was set after defaults were used
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=90ce5a...
Commit: 90ce5ac64762f54eada6cc6f4623a98e2eb493f7
Parent: 6687842cd2bd608555efd2bc624c68c0250c6ef4
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Wed Apr 16 14:54:05 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Wed Apr 16 14:54:05 2014 +0200
fencing: ipport defaults was set after defaults were used
SNMP fence agents were influenced - introduced in 91dcb051959c5e70094cbb3c5b5243e4a328d8bc
---
fence/agents/lib/fencing.py.py | 24 +++++++++++++-----------
1 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 56a8a1a..c84476f 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -636,25 +636,20 @@ def check_input(device_opt, opt):
all_opt["action"]["default"] = "off"
all_opt["action"]["help"] = "-o, --action=[action] Action: status, off (default) or on"
- ## Set default values
- #####
- for opt in device_opt:
- if all_opt[opt].has_key("default"):
- getopt_long = "--" + all_opt[opt]["longopt"]
- if 0 == options.has_key(getopt_long):
- options[getopt_long] = all_opt[opt]["default"]
-
if device_opt.count("ipport"):
if options.has_key("--ipport"):
all_opt["ipport"]["help"] = "-u, --ipport=[port] " + \
"TCP/UDP port to use (default " + options["--ipport"] +")"
+ elif all_opt.has_key("ipport") and all_opt["ipport"].has_key("default"):
+ all_opt["ipport"]["help"] = "-u, --ipport=[port] " + \
+ "TCP/UDP port to use (default " + all_opt["ipport"]["default"] +")"
elif device_opt.count("snmp_version"):
all_opt["ipport"]["default"] = "161"
all_opt["ipport"]["help"] = "-u, --ipport=[port] TCP/UDP port to use (default 161)"
- elif options.has_key("--ssh"):
+ elif options.has_key("--ssh") or (all_opt["secure"].has_key("default") and all_opt["secure"]["default"] == '1'):
all_opt["ipport"]["default"] = 22
all_opt["ipport"]["help"] = "-u, --ipport=[port] TCP/UDP port to use (default 22)"
- elif options.has_key("--ssl"):
+ elif options.has_key("--ssl") or (all_opt["ssl"].has_key("default") and all_opt["ssl"]["default"] == '1'):
all_opt["ipport"]["default"] = 443
all_opt["ipport"]["help"] = "-u, --ipport=[port] TCP/UDP port to use (default 443)"
elif device_opt.count("web"):
@@ -670,8 +665,15 @@ def check_input(device_opt, opt):
all_opt["ipport"]["help"] = "-u, --ipport=[port] TCP/UDP port to use (default 23)"
else:
all_opt["ipport"]["help"] = "-u, --ipport=[port] TCP/UDP port to use\n\
- (default 23, 22 if --ssh option is used)"
+ (default 23, 22 if --ssh option is used)"
+ ## Set default values
+ #####
+ for opt in device_opt:
+ if all_opt[opt].has_key("default"):
+ getopt_long = "--" + all_opt[opt]["longopt"]
+ if 0 == options.has_key(getopt_long):
+ options[getopt_long] = all_opt[opt]["default"]
## In special cases (show help, metadata or version) we don't need to check anything
#####
10 years, 2 months
fence-agents: master - [cleanup] Replace vmware_log() with direct call of logging
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=668784...
Commit: 6687842cd2bd608555efd2bc624c68c0250c6ef4
Parent: 40083240dfc96073905b7a42222111c7637a0feb
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Apr 14 15:46:24 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Wed Apr 16 14:50:46 2014 +0200
[cleanup] Replace vmware_log() with direct call of logging
---
fence/agents/vmware/fence_vmware.py | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py
index 4576f40..00e7632 100644
--- a/fence/agents/vmware/fence_vmware.py
+++ b/fence/agents/vmware/fence_vmware.py
@@ -137,10 +137,6 @@ def vmware_prepare_command(options, add_login_params, additional_params):
return res
-# Log message if user set verbose option
-def vmware_log(options, message):
- logging.debug("%s\n" % message)
-
# Run command with timeout and parameters. Internaly uses vmware_prepare_command. Returns string
# with output from vmrun command. If something fails (command not found, exit code is not 0), fail_usage
# function is called (and never return).
@@ -148,7 +144,7 @@ def vmware_run_command(options, add_login_params, additional_params, additional_
command = vmware_prepare_command(options, add_login_params, additional_params)
try:
- vmware_log(options, command)
+ logging.debug("%s\n" % command)
(res_output, res_code) = pexpect.run(command,
int(options["--shell-timeout"]) + int(options["--login-timeout"]) + additional_timeout, True)
@@ -156,10 +152,10 @@ def vmware_run_command(options, add_login_params, additional_params, additional_
if res_code == None:
fail(EC_TIMED_OUT)
if res_code != 0 and add_login_params:
- vmware_log(options, res_output)
+ logging.debug("%s\n" % res_output)
fail_usage("%s returned %s"% (options["--exec"], res_output))
else:
- vmware_log(options, res_output)
+ logging.debug("%s\n" % res_output)
except pexpect.ExceptionPexpect:
fail_usage("Cannot run command %s"% (options["--exec"]))
10 years, 2 months
fence-agents: master - [cleanup] Remove additional parentheses
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=400832...
Commit: 40083240dfc96073905b7a42222111c7637a0feb
Parent: 756796d3ab7a9a9933a7ebca2c6b0259a7a7ab9c
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Apr 14 15:44:22 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Wed Apr 16 14:50:40 2014 +0200
[cleanup] Remove additional parentheses
---
fence/agents/amt/fence_amt.py | 4 +-
fence/agents/apc/fence_apc.py | 30 ++++----
fence/agents/apc_snmp/fence_apc_snmp.py | 28 ++++----
fence/agents/brocade/fence_brocade.py | 2 +-
fence/agents/cisco_mds/fence_cisco_mds.py | 6 +-
fence/agents/cisco_ucs/fence_cisco_ucs.py | 6 +-
fence/agents/drac/fence_drac.py | 2 +-
fence/agents/drac5/fence_drac5.py | 4 +-
fence/agents/dummy/fence_dummy.py | 2 +-
fence/agents/eaton_snmp/fence_eaton_snmp.py | 40 +++++-----
fence/agents/eps/fence_eps.py | 12 ++--
fence/agents/hds_cb/fence_hds_cb.py | 6 +-
fence/agents/ibmblade/fence_ibmblade.py | 2 +-
fence/agents/ifmib/fence_ifmib.py | 12 ++--
fence/agents/intelmodular/fence_intelmodular.py | 2 +-
fence/agents/ipdu/fence_ipdu.py | 22 +++---
fence/agents/ldom/fence_ldom.py | 10 ++--
fence/agents/lib/fencing.py.py | 24 +++---
fence/agents/lib/fencing_snmp.py.py | 16 ++--
fence/agents/ovh/fence_ovh.py | 6 +-
fence/agents/rhevm/fence_rhevm.py | 8 +-
fence/agents/rsa/fence_rsa.py | 2 +-
fence/agents/rsb/fence_rsb.py | 2 +-
fence/agents/sanbox2/fence_sanbox2.py | 4 +-
fence/agents/virsh/fence_virsh.py | 6 +-
fence/agents/vmware/fence_vmware.py | 86 +++++++++++-----------
fence/agents/vmware_soap/fence_vmware_soap.py | 4 +-
fence/agents/wti/fence_wti.py | 8 +-
fence/agents/xenapi/fence_xenapi.py | 14 ++--
29 files changed, 185 insertions(+), 185 deletions(-)
diff --git a/fence/agents/amt/fence_amt.py b/fence/agents/amt/fence_amt.py
index edab61a..4a3f0e2 100644
--- a/fence/agents/amt/fence_amt.py
+++ b/fence/agents/amt/fence_amt.py
@@ -18,9 +18,9 @@ def get_power_status(_, options):
match = re.search('Powerstate:[\\s]*(..)', str(output))
status = match.group(1) if match else None
- if (status == None):
+ if status == None:
return "fail"
- elif (status == "S0"): # SO = on; S3 = sleep; S5 = off
+ elif status == "S0": # SO = on; S3 = sleep; S5 = off
return "on"
else:
return "off"
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index f744583..4b4c2bc 100644
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -37,21 +37,21 @@ def get_power_status(conn, options):
admin = 0
switch = 0
- if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before)):
+ if None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before):
switch = 1
- if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before)):
- if (0 == options.has_key("--switch")):
+ if None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before):
+ if 0 == options.has_key("--switch"):
fail_usage("Failed: You have to enter physical switch number")
else:
- if (0 == options.has_key("--switch")):
+ if 0 == options.has_key("--switch"):
options["--switch"] = "1"
- if (None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before)):
+ if None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before):
version = 2
else:
version = 3
- if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before)):
+ if None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before):
admin = 0
else:
admin = 1
@@ -76,7 +76,7 @@ def get_power_status(conn, options):
show_re = re.compile(r'(^|\x0D)\s*(\d+)- (.*?)\s+(ON|OFF)\s*')
for line in lines:
res = show_re.search(line)
- if (res != None):
+ if res != None:
outlets[res.group(2)] = (res.group(3), res.group(4))
conn.send_eol("")
if exp_result != 0:
@@ -108,26 +108,26 @@ def set_power_status(conn, options):
admin3 = 0
switch = 0
- if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before)):
+ if None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before):
switch = 1
## MasterSwitch has different schema for on/off actions
action = {
'on' : "1",
'off': "3"
}[options["--action"]]
- if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before)):
- if (0 == options.has_key("--switch")):
+ if None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before):
+ if 0 == options.has_key("--switch"):
fail_usage("Failed: You have to enter physical switch number")
else:
- if (0 == options.has_key("--switch")):
+ if 0 == options.has_key("--switch"):
options["--switch"] = 1
- if (None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before)):
+ if None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before):
version = 2
else:
version = 3
- if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before)):
+ if None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before):
admin2 = 0
else:
admin2 = 1
@@ -141,7 +141,7 @@ def set_power_status(conn, options):
else:
conn.send_eol("2")
conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- if (None == re.compile('.*2- Outlet Restriction.*', re.IGNORECASE | re.S).match(conn.before)):
+ if None == re.compile('.*2- Outlet Restriction.*', re.IGNORECASE | re.S).match(conn.before):
admin3 = 0
else:
admin3 = 1
@@ -189,7 +189,7 @@ def get_power_status5(conn, options):
for line in lines:
res = show_re.search(line)
- if (res != None):
+ if res != None:
outlets[res.group(1)] = (res.group(2), res.group(3))
if ["list", "monitor"].count(options["--action"]) == 1:
diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
index 0a0d409..33f152e 100644
--- a/fence/agents/apc_snmp/fence_apc_snmp.py
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -99,7 +99,7 @@ def apc_set_device(conn):
# First resolve type of APC
apc_type = conn.walk(OID_SYS_OBJECT_ID)
- if (not ((len(apc_type)==1) and (agents_dir.has_key(apc_type[0][1])))):
+ if not ((len(apc_type)==1) and (agents_dir.has_key(apc_type[0][1]))):
apc_type = [[None, None]]
device = agents_dir[apc_type[0][1]]
@@ -109,41 +109,41 @@ def apc_set_device(conn):
def apc_resolv_port_id(conn, options):
global port_id, switch_id
- if (device == None):
+ if device == None:
apc_set_device(conn)
# Now we resolv port_id/switch_id
- if ((options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit()))):
+ if (options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit())):
port_id = int(options["--plug"])
- if (device.has_switches):
+ if device.has_switches:
switch_id = int(options["--switch"])
else:
table = conn.walk(device.outlet_table_oid, 30)
for x in table:
- if (x[1].strip('"') == options["--plug"]):
+ if x[1].strip('"') == options["--plug"]:
t = x[0].split('.')
- if (device.has_switches):
+ if device.has_switches:
port_id = int(t[len(t)-1])
switch_id = int(t[len(t)-3])
else:
port_id = int(t[len(t)-1])
- if (port_id == None):
+ if port_id == None:
fail_usage("Can't find port with name %s!"%(options["--plug"]))
def get_power_status(conn, options):
- if (port_id == None):
+ if port_id == None:
apc_resolv_port_id(conn, options)
oid = ((device.has_switches) and device.status_oid%(switch_id, port_id) or device.status_oid%(port_id))
(oid, status) = conn.get(oid)
- return (status==str(device.state_on) and "on" or "off")
+ return status == str(device.state_on) and "on" or "off"
def set_power_status(conn, options):
- if (port_id == None):
+ if port_id == None:
apc_resolv_port_id(conn, options)
oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id))
@@ -154,7 +154,7 @@ def set_power_status(conn, options):
def get_outlets_status(conn, options):
result = {}
- if (device == None):
+ if device == None:
apc_set_device(conn)
res_ports = conn.walk(device.outlet_table_oid, 30)
@@ -183,13 +183,13 @@ def main():
options = check_input(device_opt, process_input(device_opt))
## Support for -n [switch]:[plug] notation that was used before
- if ((options.has_key("--plug")) and (-1 != options["--plug"].find(":"))):
+ if (options.has_key("--plug")) and (-1 != options["--plug"].find(":")):
(switch, plug) = options["--plug"].split(":", 1)
- if ((switch.isdigit()) and (plug.isdigit())):
+ if switch.isdigit() and plug.isdigit():
options["--switch"] = switch
options["--plug"] = plug
- if (not (options.has_key("--switch"))):
+ if not options.has_key("--switch"):
options["--switch"] = "1"
docs = { }
diff --git a/fence/agents/brocade/fence_brocade.py b/fence/agents/brocade/fence_brocade.py
index 35082ee..3bbb74c 100644
--- a/fence/agents/brocade/fence_brocade.py
+++ b/fence/agents/brocade/fence_brocade.py
@@ -22,7 +22,7 @@ def get_power_status(conn, options):
for line in lines:
res = show_re.search(line)
- if (res != None):
+ if res != None:
# We queried if it is disabled, so we have to negate answer
if res.group(1) == "ON":
return "off"
diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py
index 0508f90..82b28a0 100644
--- a/fence/agents/cisco_mds/fence_cisco_mds.py
+++ b/fence/agents/cisco_mds/fence_cisco_mds.py
@@ -39,14 +39,14 @@ def cisco_port2oid(port):
nums = re.match(r'^fc(\d+)/(\d+)$', port)
- if ((nums) and (len(nums.groups()))==2):
+ if nums and len(nums.groups()) == 2:
return "%s.%d.%d"% (PORT_ADMIN_STATUS_OID, int(nums.group(1))+21, int(nums.group(2))-1)
else:
fail_usage("Mangled port number: %s"%(port))
def get_power_status(conn, options):
(_, status) = conn.get(PORT_OID)
- return (status=="1" and "on" or "off")
+ return status == "1" and "on" or "off"
def set_power_status(conn, options):
conn.set(PORT_OID, (options["--action"]=="on" and 1 or 2))
@@ -93,7 +93,7 @@ which can be used with any Cisco MDS 9000 series with SNMP enabled device."
docs["vendorurl"] = "http://www.cisco.com"
show_docs(options, docs)
- if (not (options["--action"] in ["list","monitor"])):
+ if not options["--action"] in ["list","monitor"]:
PORT_OID = cisco_port2oid(options["--plug"])
# Operate the fencing device
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py
index 2d4eaa8..0a4bff7 100644
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -28,12 +28,12 @@ def get_power_status(conn, options):
options["--plug"] + "/power\"/>", int(options["--shell-timeout"]))
result = RE_STATUS.search(res)
- if (result == None):
+ if result == None:
fail(EC_STATUS)
else:
status = result.group(1)
- if (status == "up"):
+ if status == "up":
return "on"
else:
return "off"
@@ -137,7 +137,7 @@ used with Cisco UCS to fence machines."
res = send_command(options, "<aaaLogin inName=\"" + options["--username"] +
"\" inPassword=\"" + options["--password"] + "\" />", int(options["--login-timeout"]))
result = RE_COOKIE.search(res)
- if (result == None):
+ if result == None:
## Cookie is absenting in response
fail(EC_LOGIN_DENIED)
except:
diff --git a/fence/agents/drac/fence_drac.py b/fence/agents/drac/fence_drac.py
index b858d62..3cd7653 100644
--- a/fence/agents/drac/fence_drac.py
+++ b/fence/agents/drac/fence_drac.py
@@ -15,7 +15,7 @@ def get_power_status(conn, options):
conn.send_eol("getmodinfo")
conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
status = re.compile(r"\s+(on|off)\s+", re.IGNORECASE).search(conn.before).group(1)
- return (status.lower().strip())
+ return status.lower().strip()
def set_power_status(conn, options):
action = {
diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py
index 7d8fe9a..6f70dad 100644
--- a/fence/agents/drac5/fence_drac5.py
+++ b/fence/agents/drac5/fence_drac5.py
@@ -73,7 +73,7 @@ def get_list_devices(conn, options):
list_re = re.compile(r"^([^\s]*?)\s+Present\s*(ON|OFF)\s*.*$")
conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
for line in conn.before.splitlines():
- if (list_re.search(line)):
+ if list_re.search(line):
outlets[list_re.search(line).group(1)] = ("", list_re.search(line).group(2))
elif options["--drac-version"] == "DRAC MC":
conn.send_eol("getmodinfo")
@@ -81,7 +81,7 @@ def get_list_devices(conn, options):
list_re = re.compile(r"^\s*([^\s]*)\s*---->\s*(.*?)\s+Present\s*(ON|OFF)\s*.*$")
conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
for line in conn.before.splitlines():
- if (list_re.search(line)):
+ if list_re.search(line):
outlets[list_re.search(line).group(2)] = ("", list_re.search(line).group(3))
elif options["--drac-version"] == "DRAC 5":
## DRAC 5 can be used only for one computer
diff --git a/fence/agents/dummy/fence_dummy.py b/fence/agents/dummy/fence_dummy.py
index aa1e5c2..9f0e950 100644
--- a/fence/agents/dummy/fence_dummy.py
+++ b/fence/agents/dummy/fence_dummy.py
@@ -69,7 +69,7 @@ def get_outlets_fail(conn, options):
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):
+ elif options.has_key("--plug") == 0:
fail_usage("Failed: You have to enter existing machine!")
else:
port = options["--plug"]
diff --git a/fence/agents/eaton_snmp/fence_eaton_snmp.py b/fence/agents/eaton_snmp/fence_eaton_snmp.py
index 24dfd9e..884fd6d 100644
--- a/fence/agents/eaton_snmp/fence_eaton_snmp.py
+++ b/fence/agents/eaton_snmp/fence_eaton_snmp.py
@@ -76,7 +76,7 @@ def eaton_set_device(conn):
# First resolve type of Eaton
eaton_type = conn.walk(OID_SYS_OBJECT_ID)
- if (not ((len(eaton_type)==1) and (agents_dir.has_key(eaton_type[0][1])))):
+ if not ((len(eaton_type)==1) and (agents_dir.has_key(eaton_type[0][1]))):
eaton_type = [[None, None]]
device = agents_dir[eaton_type[0][1]]
@@ -86,48 +86,48 @@ def eaton_set_device(conn):
def eaton_resolv_port_id(conn, options):
global port_id, switch_id
- if (device==None):
+ if device == None:
eaton_set_device(conn)
# Restore the increment, that was removed in main for ePDU Managed
- if (device.ident_str == "Eaton Switched ePDU"):
+ if device.ident_str == "Eaton Switched ePDU":
options["--plug"] = str(int(options["--plug"]) + 1)
# Now we resolv port_id/switch_id
- if ((options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit()))):
+ if options["--plug"].isdigit() and ((not device.has_switches) or (options["--switch"].isdigit())):
port_id = int(options["--plug"])
- if (device.has_switches):
+ if device.has_switches:
switch_id = int(options["--switch"])
else:
table = conn.walk(device.outlet_table_oid, 30)
for x in table:
- if (x[1].strip('"')==options["--plug"]):
+ if x[1].strip('"') == options["--plug"]:
t = x[0].split('.')
- if (device.has_switches):
+ if device.has_switches:
port_id = int(t[len(t)-1])
switch_id = int(t[len(t)-3])
else:
- if (device.ident_str == "Eaton Switched ePDU"):
+ if device.ident_str == "Eaton Switched ePDU":
port_id = int(t[len(t)-3])
else:
port_id = int(t[len(t)-1])
- if (port_id==None):
+ if port_id == None:
# Restore index offset, to provide a valid error output on Managed ePDU
- if (device.ident_str != "Eaton Switched ePDU"):
+ if device.ident_str != "Eaton Switched ePDU":
options["--plug"] = str(int(options["--plug"]) + 1)
fail_usage("Can't find port with name %s!"%(options["--plug"]))
def get_power_status(conn, options):
global port_id, after_set
- if (port_id==None):
+ if port_id == None:
eaton_resolv_port_id(conn, options)
# Ajust OID for Switched ePDU when the get is after a set
- if ((after_set == True) and (device.ident_str == "Eaton Switched ePDU")):
+ if after_set and device.ident_str == "Eaton Switched ePDU":
port_id -= 1
after_set = False
@@ -135,9 +135,9 @@ def get_power_status(conn, options):
try:
(oid, status)=conn.get(oid)
- if (status==str(device.state_on)):
+ if status == str(device.state_on):
return "on"
- elif (status==str(device.state_off)):
+ elif status == str(device.state_off):
return "off"
else:
return None
@@ -149,11 +149,11 @@ def set_power_status(conn, options):
after_set = True
- if (port_id==None):
+ if port_id == None:
eaton_resolv_port_id(conn, options)
# Controls start at #2 on Switched ePDU, since #1 is the global command
- if (device.ident_str == "Eaton Switched ePDU"):
+ if device.ident_str == "Eaton Switched ePDU":
port_id = int(port_id)+1
oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id))
@@ -165,7 +165,7 @@ def get_outlets_status(conn, options):
outletCount = 0
result = {}
- if (device==None):
+ if device == None:
eaton_set_device(conn)
res_ports = conn.walk(device.outlet_table_oid, 30)
@@ -177,7 +177,7 @@ def get_outlets_status(conn, options):
# Plug indexing start from zero, so we substract '1' from the
# user's given plug number
- if (device.ident_str == "Eaton Managed ePDU"):
+ if device.ident_str == "Eaton Managed ePDU":
port_num = str(int(((device.has_switches) and
"%s:%s"%(t[len(t)-3], t[len(t)-1]) or "%s"%(t[len(t)-1]))) + 1)
@@ -193,7 +193,7 @@ def get_outlets_status(conn, options):
port_num = str(outletCount)
port_name = str(outletCount)
port_status = ""
- if (status != '0'):
+ if status != '0':
result[port_num] = (port_name, port_status)
return result
@@ -214,7 +214,7 @@ def main():
# Plug indexing start from zero on ePDU Managed, so we substract '1' from
# the user's given plug number.
# For Switched ePDU, we will add this back again later.
- if ((options.has_key("--plug")) and (options["--plug"].isdigit())):
+ if options.has_key("--plug") and options["--plug"].isdigit():
options["--plug"] = str(int(options["--plug"]) - 1)
docs = { }
diff --git a/fence/agents/eps/fence_eps.py b/fence/agents/eps/fence_eps.py
index 5efc8df..68a0991 100644
--- a/fence/agents/eps/fence_eps.py
+++ b/fence/agents/eps/fence_eps.py
@@ -27,14 +27,14 @@ def eps_run_command(options, params):
request_str = "/"+options["--page"]
- if (params!=""):
+ if params != "":
request_str += "?"+params
logging.debug("GET %s\n" % request_str)
conn.putrequest('GET', request_str)
- if (options.has_key("--username")):
- if (not options.has_key("--password")):
+ if options.has_key("--username"):
+ if not options.has_key("--password"):
options["--password"] = "" # Default is empty password
# String for Authorization header
@@ -49,7 +49,7 @@ def eps_run_command(options, params):
logging.debug("%d %s\n"%(response.status, response.reason))
#Response != OK -> couldn't login
- if (response.status!=200):
+ if response.status != 200:
fail(EC_LOGIN_DENIED)
result = response.read()
@@ -71,8 +71,8 @@ def get_power_status(conn, options):
for out_num, out_stat in status:
result[out_num] = ("",(out_stat=="1" and "on" or "off"))
- if (not (options["--action"] in ['monitor','list'])):
- if (not (options["--plug"] in result)):
+ if not options["--action"] in ['monitor','list']:
+ if not options["--plug"] in result:
fail_usage("Failed: You have to enter existing physical plug!")
else:
return result[options["--plug"]][1]
diff --git a/fence/agents/hds_cb/fence_hds_cb.py b/fence/agents/hds_cb/fence_hds_cb.py
index f895fd3..6caee7f 100755
--- a/fence/agents/hds_cb/fence_hds_cb.py
+++ b/fence/agents/hds_cb/fence_hds_cb.py
@@ -39,9 +39,9 @@ def get_power_status(conn, options):
for line in conn.before.splitlines():
# populate the relevant fields based on regex
partition = re.search(RE_STATUS_LINE, line)
- if( partition != None):
+ if partition != None:
# find the blade number defined in args
- if( partition.group(1) == options["--plug"] ):
+ 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
@@ -97,7 +97,7 @@ def get_blades_list(conn, options):
# "1 On Normal Off Basic Synchronized"
for line in conn.before.splitlines():
partition = re.search(RE_STATUS_LINE, line)
- if( partition != None):
+ 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"]))
diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py
index d1bb065..f3c810e 100644
--- a/fence/agents/ibmblade/fence_ibmblade.py
+++ b/fence/agents/ibmblade/fence_ibmblade.py
@@ -29,7 +29,7 @@ STATUS_SET_ON = 1
def get_power_status(conn, options):
(_, status) = conn.get("%s.%s"% (STATUSES_OID, options["--plug"]))
- return (status == str(STATUS_UP) and "on" or "off")
+ return status == str(STATUS_UP) and "on" or "off"
def set_power_status(conn, options):
conn.set("%s.%s"%(CONTROL_OID, options["--plug"]),
diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py
index c477ba2..04edbf9 100644
--- a/fence/agents/ifmib/fence_ifmib.py
+++ b/fence/agents/ifmib/fence_ifmib.py
@@ -42,17 +42,17 @@ port_num = None
def port2index(conn, port):
res = None
- if (port.isdigit()):
+ if port.isdigit():
res = int(port)
else:
ports = conn.walk(PORTS_OID, 30)
for x in ports:
- if (x[1].strip('"')==port):
+ if x[1].strip('"') == port:
res = int(x[0].split('.')[-1])
break
- if (res==None):
+ if res == None:
fail_usage("Can't find port with name %s!"%(port))
return res
@@ -60,16 +60,16 @@ def port2index(conn, port):
def get_power_status(conn, options):
global port_num
- if (port_num==None):
+ if port_num == None:
port_num = port2index(conn, options["--plug"])
(_, status) = conn.get("%s.%d"%(STATUSES_OID, port_num))
- return (status==str(STATUS_UP) and "on" or "off")
+ return status == str(STATUS_UP) and "on" or "off"
def set_power_status(conn, options):
global port_num
- if (port_num==None):
+ if port_num == None:
port_num = port2index(conn, options["--plug"])
conn.set("%s.%d"%(STATUSES_OID, port_num), (options["--action"]=="on" and STATUS_UP or STATUS_DOWN))
diff --git a/fence/agents/intelmodular/fence_intelmodular.py b/fence/agents/intelmodular/fence_intelmodular.py
index e9ef43c..bdb45b5 100644
--- a/fence/agents/intelmodular/fence_intelmodular.py
+++ b/fence/agents/intelmodular/fence_intelmodular.py
@@ -40,7 +40,7 @@ STATUS_SET_OFF = 3
def get_power_status(conn, options):
(_, status) = conn.get("%s.%s"% (STATUSES_OID, options["--plug"]))
- return (status==str(STATUS_UP) and "on" or "off")
+ return status == str(STATUS_UP) and "on" or "off"
def set_power_status(conn, options):
conn.set("%s.%s" % (STATUSES_OID, options["--plug"]),
diff --git a/fence/agents/ipdu/fence_ipdu.py b/fence/agents/ipdu/fence_ipdu.py
index 913322d..e17d837 100644
--- a/fence/agents/ipdu/fence_ipdu.py
+++ b/fence/agents/ipdu/fence_ipdu.py
@@ -54,7 +54,7 @@ def ipdu_set_device(conn, options):
# First resolve type of PDU device
pdu_type = conn.walk(OID_SYS_OBJECT_ID)
- if (not ((len(pdu_type)==1) and (agents_dir.has_key(pdu_type[0][1])))):
+ if not ((len(pdu_type)==1) and (agents_dir.has_key(pdu_type[0][1]))):
pdu_type = [[None, None]]
device = agents_dir[pdu_type[0][1]]
@@ -64,41 +64,41 @@ def ipdu_set_device(conn, options):
def ipdu_resolv_port_id(conn, options):
global port_id, switch_id
- if (device==None):
+ if device == None:
ipdu_set_device(conn, options)
# Now we resolv port_id/switch_id
- if ((options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit()))):
+ if options["--plug"].isdigit() and ((not device.has_switches) or (options["--switch"].isdigit())):
port_id = int(options["--plug"])
- if (device.has_switches):
+ if device.has_switches:
switch_id = int(options["--switch"])
else:
table = conn.walk(device.outlet_table_oid, 30)
for x in table:
- if (x[1].strip('"')==options["--plug"]):
+ if x[1].strip('"') == options["--plug"]:
t = x[0].split('.')
- if (device.has_switches):
+ if device.has_switches:
port_id = int(t[len(t)-1])
switch_id = int(t[len(t)-3])
else:
port_id = int(t[len(t)-1])
- if (port_id==None):
+ if port_id == None:
fail_usage("Can't find port with name %s!"%(options["--plug"]))
def get_power_status(conn, options):
- if (port_id==None):
+ if port_id == None:
ipdu_resolv_port_id(conn, options)
oid = ((device.has_switches) and device.status_oid%(switch_id, port_id) or device.status_oid%(port_id))
(oid, status) = conn.get(oid)
- return (status==str(device.state_on) and "on" or "off")
+ return status == str(device.state_on) and "on" or "off"
def set_power_status(conn, options):
- if (port_id==None):
+ if port_id == None:
ipdu_resolv_port_id(conn, options)
oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id))
@@ -109,7 +109,7 @@ def set_power_status(conn, options):
def get_outlets_status(conn, options):
result = {}
- if (device == None):
+ if device == None:
ipdu_set_device(conn, options)
res_ports = conn.walk(device.outlet_table_oid, 30)
diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py
index 65c810b..5e046df 100644
--- a/fence/agents/ldom/fence_ldom.py
+++ b/fence/agents/ldom/fence_ldom.py
@@ -46,14 +46,14 @@ def get_power_status(conn, options):
for line in conn.before.splitlines():
domain = re.search(r"^(\S+)\s+(\S+)\s+.*$", line)
- if (domain!=None):
- if ((fa_status==0) and (domain.group(1)=="NAME") and (domain.group(2)=="STATE")):
+ if domain != None:
+ if fa_status == 0 and domain.group(1) == "NAME" and domain.group(2) == "STATE":
fa_status = 1
- elif (fa_status==1):
+ elif fa_status == 1:
result[domain.group(1)] = ("", (domain.group(2).lower()=="bound" and "off" or "on"))
- if (not (options["--action"] in ['monitor','list'])):
- if (not (options["--plug"] in result)):
+ if not options["--action"] in ['monitor','list']:
+ if not options["--plug"] in result:
fail_usage("Failed: You have to enter existing logical domain!")
else:
return result[options["--plug"]][1]
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index a37cd0d..56a8a1a 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -495,7 +495,7 @@ def metadata(avail_opt, options, docs):
mixed = all_opt[option]["help"]
## split it between option and help text
res = re.compile(r"^(.*--\S+)\s+", re.IGNORECASE | re.S).search(mixed)
- if (None != res):
+ if None != res:
mixed = res.group(1)
mixed = mixed.replace("<", "<").replace(">", ">")
print "\t\t<getopt mixed=\"" + mixed + "\" />"
@@ -596,7 +596,7 @@ def process_input(avail_opt):
name = ""
for line in sys.stdin.readlines():
line = line.strip()
- if ((line.startswith("#")) or (len(line) == 0)):
+ if (line.startswith("#")) or (len(line) == 0):
continue
(name, value) = (line + "=").split("=", 1)
@@ -710,7 +710,7 @@ def check_input(device_opt, opt):
if device_opt.count("ipaddr") and 0 == options.has_key("--ip") and 0 == options.has_key("--managed"):
fail_usage("Failed: You have to enter fence address")
- if (device_opt.count("no_password") == 0):
+ if device_opt.count("no_password") == 0:
if 0 == device_opt.count("identity_file"):
if 0 == (options.has_key("--password") or options.has_key("--password-script")):
fail_usage("Failed: You have to enter password or password script")
@@ -850,10 +850,10 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
## Process options that manipulate fencing device
#####
- if (options["--action"] == "list") and 0 == options["device_opt"].count("port"):
+ if options["--action"] == "list" and 0 == options["device_opt"].count("port"):
print "N/A"
return
- elif (options["--action"] == "list" and get_outlet_list == None):
+ elif options["--action"] == "list" and get_outlet_list == None:
## @todo: exception?
## This is just temporal solution, we will remove default value
## None as soon as all existing agent will support this operation
@@ -959,13 +959,13 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
def fence_login(options, re_login_string = r"(login\s*: )|(Login Name: )|(username: )|(User Name :)"):
force_ipvx = ""
- if (options.has_key("--inet6-only")):
+ if options.has_key("--inet6-only"):
force_ipvx = "-6 "
- if (options.has_key("--inet4-only")):
+ if options.has_key("--inet4-only"):
force_ipvx = "-4 "
- if (options.has_key("eol") == False):
+ if not options.has_key("eol"):
options["eol"] = "\r\n"
if options.has_key("--command-prompt") and type(options["--command-prompt"]) is not list:
@@ -1057,11 +1057,11 @@ def fence_login(options, re_login_string = r"(login\s*: )|(Login Name: )|(usern
## automatically change end of line separator
screen = conn.read_nonblocking(size=100, timeout=int(options["--shell-timeout"]))
- if (re_login.search(screen) != None):
+ if re_login.search(screen) != None:
options["eol"] = "\n"
conn.send_eol(options["--username"])
result = conn.log_expect(options, re_pass, int(options["--login-timeout"]))
- elif (re_pass.search(screen) == None):
+ elif re_pass.search(screen) != None:
conn.log_expect(options, re_pass, int(options["--shell-timeout"]))
try:
@@ -1074,7 +1074,7 @@ def fence_login(options, re_login_string = r"(login\s*: )|(Login Name: )|(usern
conn.send_eol("")
screen = conn.read_nonblocking(size=100, timeout=int(options["--shell-timeout"]))
## after sending EOL the fence device can either show 'Login' or 'Password'
- if (re_login.search(screen) != None):
+ if re_login.search(screen) != None:
conn.send_eol("")
conn.send_eol(options["--username"])
conn.log_expect(options, re_pass, int(options["--login-timeout"]))
@@ -1111,7 +1111,7 @@ def run_command(options, command, timeout = None, env = None):
thread = threading.Thread(target = process.wait)
thread.start()
thread.join(timeout)
- if (thread.is_alive()):
+ if thread.is_alive():
process.kill()
fail(EC_TIMED_OUT)
diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py
index 055c8f2..24ad171 100644
--- a/fence/agents/lib/fencing_snmp.py.py
+++ b/fence/agents/lib/fencing_snmp.py.py
@@ -42,11 +42,11 @@ class FencingSnmp:
res = True
for item in e:
- if ((item[0]=='!') and (self.options.has_key("--"+item[1:]))):
+ if item[0] == '!' and self.options.has_key("--" + item[1:]):
res = False
break
- if ((item[0]!='!') and (not self.options.has_key("--"+item[0:]))):
+ if item[0] != '!' and not self.options.has_key("--" + item[0:]):
res = False
break
@@ -62,7 +62,7 @@ class FencingSnmp:
mapping = (('snmp-version', 'v'),('community', 'c'))
for item in mapping:
- if (self.options.has_key("--" + item[0])):
+ if self.options.has_key("--" + item[0]):
cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["--" + item[0]]))
# Some options make sense only for v3 (and for v1/2c can cause "problems")
@@ -71,15 +71,15 @@ class FencingSnmp:
mapping_v3 = (('snmp-auth-prot','a'), ('snmp-sec-level','l'), ('snmp-priv-prot','x'), \
('snmp-priv-passwd','X'),('password','A'),('username','u'))
for item in mapping_v3:
- if (self.options.has_key("--"+item[0])):
+ if self.options.has_key("--"+item[0]):
cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["--" + item[0]]))
force_ipvx = ""
- if (self.options.has_key("--inet6-only")):
+ if self.options.has_key("--inet6-only"):
force_ipvx = "udp6:"
- if (self.options.has_key("--inet4-only")):
+ if self.options.has_key("--inet4-only"):
force_ipvx = "udp:"
cmd += " '%s%s%s'"% (force_ipvx, self.quote_for_run(self.options["--ip"]),
@@ -95,7 +95,7 @@ class FencingSnmp:
int(self.options["--login-timeout"]) +
additional_timemout, True)
- if (res_code==None):
+ if res_code == None:
fail(EC_TIMED_OUT)
self.log_command(res_output)
@@ -120,7 +120,7 @@ class FencingSnmp:
type_of_value = ''
for item in mapping:
- if (isinstance(value, item[0])):
+ if isinstance(value, item[0]):
type_of_value = item[1]
break
diff --git a/fence/agents/ovh/fence_ovh.py b/fence/agents/ovh/fence_ovh.py
index 24c3972..f4e9caf 100644
--- a/fence/agents/ovh/fence_ovh.py
+++ b/fence/agents/ovh/fence_ovh.py
@@ -40,7 +40,7 @@ def netboot_reboot(options, mode):
# dedicatedNetbootModifyById changes the mode of the next reboot
conn.service.dedicatedNetbootModifyById(options["session"], options["--plug"], mode, '', options["--email"])
-
+
# dedicatedHardRebootDo initiates a hard reboot on the given node
conn.service.dedicatedHardRebootDo(options["session"],
options["--plug"], 'Fencing initiated by cluster', '', 'en')
@@ -81,7 +81,7 @@ def soap_login(options):
def remove_tmp_dir(tmp_dir):
shutil.rmtree(tmp_dir)
-
+
def main():
device_opt = [ "login", "passwd", "port", "email" ]
@@ -134,7 +134,7 @@ Poweroff is simulated with a reboot into rescue-pro mode."
reboot_t.end.strftime('%Y-%m-%d %H:%M:%S'))
logging.debug("after_netboot_reboot: %s\n" %
after_netboot_reboot.strftime('%Y-%m-%d %H:%M:%S'))
-
+
if reboot_t.start < after_netboot_reboot < reboot_t.end:
result = 0
logging.debug("Netboot reboot went OK.\n")
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
index 54af81b..8ff5ee9 100644
--- a/fence/agents/rhevm/fence_rhevm.py
+++ b/fence/agents/rhevm/fence_rhevm.py
@@ -26,14 +26,14 @@ def get_power_status(conn, options):
res = send_command(options, "vms/?search=name%3D" + options["--plug"])
result = RE_GET_ID.search(res)
- if (result == None):
+ if result == None:
# Unable to obtain ID needed to access virtual machine
fail(EC_STATUS)
options["id"] = result.group(2)
result = RE_STATUS.search(res)
- if (result == None):
+ if result == None:
# We were able to parse ID so output is correct
# in some cases it is possible that RHEV-M output does not
# contain <status> line. We can assume machine is OFF then
@@ -41,7 +41,7 @@ def get_power_status(conn, options):
else:
status = result.group(1)
- if (status.lower() == "down"):
+ if status.lower() == "down":
return "off"
else:
return "on"
@@ -94,7 +94,7 @@ def send_command(opt, command, method = "GET"):
conn.setopt(pycurl.SSL_VERIFYPEER, 0)
conn.setopt(pycurl.SSL_VERIFYHOST, 0)
- if (method == "POST"):
+ if method == "POST":
conn.setopt(pycurl.POSTFIELDS, "<action />")
conn.setopt(pycurl.WRITEFUNCTION, web_buffer.write)
diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py
index ba93709..e163397 100644
--- a/fence/agents/rsa/fence_rsa.py
+++ b/fence/agents/rsa/fence_rsa.py
@@ -23,7 +23,7 @@ def get_power_status(conn, options):
conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
match = re.compile("Power: (.*)", re.IGNORECASE).search(conn.before)
- if (match != None):
+ if match != None:
status = match.group(1)
else:
status = "undefined"
diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py
index b72d295..e9e37de 100755
--- a/fence/agents/rsb/fence_rsb.py
+++ b/fence/agents/rsb/fence_rsb.py
@@ -18,7 +18,7 @@ def get_power_status(conn, options):
conn.send("0")
conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- return (status.lower().strip())
+ return status.lower().strip()
def set_power_status(conn, options):
action = {
diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py
index 161e002..c53f1ef 100644
--- a/fence/agents/sanbox2/fence_sanbox2.py
+++ b/fence/agents/sanbox2/fence_sanbox2.py
@@ -85,7 +85,7 @@ def get_list_devices(conn, options):
list_re = re.compile(r"^\s+(\d+?)\s+(Online|Offline)\s+", re.IGNORECASE)
for line in conn.before.splitlines():
- if (list_re.search(line)):
+ if list_re.search(line):
status = {
'online' : "ON",
'offline' : "OFF"
@@ -130,7 +130,7 @@ because the connection will block any necessary fencing actions."
conn.send_eol("admin start")
conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- if (re.search(r"\(admin\)", conn.before, re.MULTILINE) == None):
+ if re.search(r"\(admin\)", conn.before, re.MULTILINE) == None:
## Someone else is in admin section, we can't enable/disable
## ports so we will rather exit
logging.error("Failed: Unable to switch to admin section\n")
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index cbdb399..9f94f58 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -38,10 +38,10 @@ def get_outlets_status(conn, options):
for line in conn.before.splitlines():
domain = re.search(r"^\s*(\S+)\s+(\S+)\s+(\S+).*$", line)
- if (domain!=None):
- if ((fa_status==0) and (domain.group(1).lower()=="id") and (domain.group(2).lower()=="name")):
+ if domain != None:
+ if fa_status == 0 and domain.group(1).lower() == "id" and domain.group(2).lower() == "name":
fa_status = 1
- elif (fa_status==1):
+ elif fa_status == 1:
result[domain.group(2)] = ("",
(domain.group(3).lower() in ["running", "blocked", "idle", "no state", "paused"] and "on" or "off"))
return result
diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py
index 80dc122..4576f40 100644
--- a/fence/agents/vmware/fence_vmware.py
+++ b/fence/agents/vmware/fence_vmware.py
@@ -72,24 +72,24 @@ def dsv_split(dsv_str):
tmp_str = ""
for x in dsv_str:
- if (status==0):
- if (x==delimiter_c):
+ if status == 0:
+ if x == delimiter_c:
res.append(tmp_str)
tmp_str = ""
- elif (x==escape_c):
+ elif x == escape_c:
status = 1
else:
tmp_str += x
- elif (status==1):
- if (x==delimiter_c):
+ elif status == 1:
+ if x == delimiter_c:
tmp_str += delimiter_c
- elif (x==escape_c):
+ elif x == escape_c:
tmp_str += escape_c
else:
tmp_str += escape_c+x
status = 0
- if (tmp_str != ""):
+ if tmp_str != "":
res.append(tmp_str)
return res
@@ -111,28 +111,28 @@ def quote_for_run(text):
def vmware_prepare_command(options, add_login_params, additional_params):
res = options["--exec"]
- if (add_login_params):
- if (vmware_internal_type==VMWARE_TYPE_ESX):
+ if add_login_params:
+ if vmware_internal_type==VMWARE_TYPE_ESX:
res += " --server '%s' --username '%s' --password '%s' "% (quote_for_run(options["--ip"]),
quote_for_run(options["--username"]),
quote_for_run(options["--password"]))
- elif (vmware_internal_type==VMWARE_TYPE_SERVER2):
+ elif vmware_internal_type==VMWARE_TYPE_SERVER2:
res += " -h 'https://%s/sdk' -u '%s' -p '%s' -T server "% (quote_for_run(options["--ip"]),
quote_for_run(options["--username"]),
quote_for_run(options["--password"]))
- elif (vmware_internal_type==VMWARE_TYPE_SERVER1):
+ elif vmware_internal_type==VMWARE_TYPE_SERVER1:
host_name_array = options["--ip"].split(':')
res += " -h '%s' -u '%s' -p '%s' -T server1 "% (quote_for_run(host_name_array[0]),
quote_for_run(options["--username"]),
quote_for_run(options["--password"]))
- if (len(host_name_array)>1):
+ if len(host_name_array) > 1:
res += "-P '%s' "% (quote_for_run(host_name_array[1]))
- if ((options.has_key("--vmware-datacenter")) and (vmware_internal_type==VMWARE_TYPE_ESX)):
+ if options.has_key("--vmware-datacenter") and vmware_internal_type == VMWARE_TYPE_ESX:
res += "--datacenter '%s' "% (quote_for_run(options["--vmware-datacenter"]))
- if (additional_params != ""):
+ if additional_params != "":
res += additional_params
return res
@@ -153,9 +153,9 @@ def vmware_run_command(options, add_login_params, additional_params, additional_
(res_output, res_code) = pexpect.run(command,
int(options["--shell-timeout"]) + int(options["--login-timeout"]) + additional_timeout, True)
- if (res_code==None):
+ if res_code == None:
fail(EC_TIMED_OUT)
- if ((res_code!=0) and (add_login_params)):
+ if res_code != 0 and add_login_params:
vmware_log(options, res_output)
fail_usage("%s returned %s"% (options["--exec"], res_output))
else:
@@ -171,7 +171,7 @@ def vmware_run_command(options, add_login_params, additional_params, additional_
def vmware_get_outlets_vi(options, add_vm_name):
outlets = {}
- if (add_vm_name):
+ if add_vm_name:
all_machines = vmware_run_command(options, True,
("--operation status --vmname '%s'"% (quote_for_run(options["--plug"]))), 0)
else:
@@ -181,11 +181,11 @@ def vmware_get_outlets_vi(options, add_vm_name):
for machine in all_machines_array:
machine_array = dsv_split(machine)
- if (len(machine_array) == 4):
- if (machine_array[0] in outlets):
+ if len(machine_array) == 4:
+ if machine_array[0] in outlets:
fail_usage("Failed. More machines with same name %s found!"%(machine_array[0]))
- if (vmware_disconnected_hack):
+ if vmware_disconnected_hack:
outlets[machine_array[0]] = ("", (
((machine_array[2].lower() in ["poweredon"]) and
(machine_array[3].lower()=="connected"))
@@ -201,14 +201,14 @@ def vmware_get_outlets_vix(options):
running_machines = vmware_run_command(options, True, "list", 0)
running_machines_array = running_machines.splitlines()[1:]
- if (vmware_internal_type==VMWARE_TYPE_SERVER2):
+ if vmware_internal_type == VMWARE_TYPE_SERVER2:
all_machines = vmware_run_command(options, True, "listRegisteredVM", 0)
all_machines_array = all_machines.splitlines()[1:]
- elif (vmware_internal_type==VMWARE_TYPE_SERVER1):
+ elif vmware_internal_type == VMWARE_TYPE_SERVER1:
all_machines_array = running_machines_array
for machine in all_machines_array:
- if (machine!=""):
+ if machine != "":
outlets[machine] = ("", ((machine in running_machines_array) and "on" or "off"))
return outlets
@@ -216,35 +216,35 @@ def vmware_get_outlets_vix(options):
def get_outlets_status(conn, options):
del conn
- if (vmware_internal_type==VMWARE_TYPE_ESX):
+ if vmware_internal_type == VMWARE_TYPE_ESX:
return vmware_get_outlets_vi(options, False)
- if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)):
+ if vmware_internal_type == VMWARE_TYPE_SERVER1 or vmware_internal_type == VMWARE_TYPE_SERVER2:
return vmware_get_outlets_vix(options)
def get_power_status(conn, options):
- if (vmware_internal_type==VMWARE_TYPE_ESX):
+ if vmware_internal_type == VMWARE_TYPE_ESX:
outlets = vmware_get_outlets_vi(options, True)
else:
outlets = get_outlets_status(conn, options)
- if ((vmware_internal_type==VMWARE_TYPE_SERVER2) or (vmware_internal_type==VMWARE_TYPE_ESX)):
- if (not (options["--plug"] in outlets)):
+ if vmware_internal_type == VMWARE_TYPE_SERVER2 or vmware_internal_type == VMWARE_TYPE_ESX:
+ if not options["--plug"] in outlets:
fail_usage("Failed: You have to enter existing name of virtual machine!")
else:
return outlets[options["--plug"]][1]
- elif (vmware_internal_type==VMWARE_TYPE_SERVER1):
- return ((options["--plug"] in outlets) and "on" or "off")
+ elif vmware_internal_type == VMWARE_TYPE_SERVER1:
+ return (options["--plug"] in outlets) and "on" or "off"
def set_power_status(conn, options):
del conn
- if (vmware_internal_type==VMWARE_TYPE_ESX):
+ if vmware_internal_type == VMWARE_TYPE_ESX:
additional_params = "--operation %s --vmname '%s'" % \
((options["--action"]=="on" and "on" or "off"), quote_for_run(options["--plug"]))
- elif ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)):
+ elif vmware_internal_type == VMWARE_TYPE_SERVER1 or vmware_internal_type == VMWARE_TYPE_SERVER2:
additional_params = "%s '%s'" % \
((options["--action"]=="on" and "start" or "stop"), quote_for_run(options["--plug"]))
- if (options["--action"]=="off"):
+ if options["--action"] == "off":
additional_params += " hard"
vmware_run_command(options, True, additional_params, int(options["--power-timeout"]))
@@ -253,13 +253,13 @@ def set_power_status(conn, options):
def vmware_is_supported_vmrun_version(options):
vmware_help_str = vmware_run_command(options, False, "", 0)
version_re = re.search(r"vmrun version (\d\.(\d[\.]*)*)", vmware_help_str.lower())
- if (version_re==None):
+ if version_re == None:
return False # Looks like this "vmrun" is not real vmrun
version_array = version_re.group(1).split(".")
try:
- if (int(version_array[0]) < VMRUN_MINIMUM_REQUIRED_VERSION):
+ if int(version_array[0]) < VMRUN_MINIMUM_REQUIRED_VERSION:
return False
except Exception:
return False
@@ -273,17 +273,17 @@ def vmware_check_vmware_type(options):
options["--vmware_type"] = options["--vmware_type"].lower()
- if (options["--vmware_type"]=="esx"):
+ if options["--vmware_type"] == "esx":
vmware_internal_type = VMWARE_TYPE_ESX
- if (not options.has_key("--exec")):
+ if not options.has_key("--exec"):
options["--exec"] = VMHELPER_COMMAND
- elif (options["--vmware_type"]=="server2"):
+ elif options["--vmware_type"] == "server2":
vmware_internal_type = VMWARE_TYPE_SERVER2
- if (not options.has_key("--exec")):
+ if not options.has_key("--exec"):
options["--exec"] = VMRUN_COMMAND
- elif (options["--vmware_type"]=="server1"):
+ elif options["--vmware_type"] == "server1":
vmware_internal_type = VMWARE_TYPE_SERVER1
- if (not options.has_key("--exec")):
+ if not options.has_key("--exec"):
options["--exec"] = VMRUN_COMMAND
else:
fail_usage("vmware_type can be esx,server2 or server1!")
@@ -330,8 +330,8 @@ This agent supports only vmrun from version 2.0.0 (VIX API 1.6.0)."
vmware_check_vmware_type(options)
# Test user vmrun command version
- if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)):
- if (not (vmware_is_supported_vmrun_version(options))):
+ if vmware_internal_type == VMWARE_TYPE_SERVER1 or vmware_internal_type == VMWARE_TYPE_SERVER2:
+ if not vmware_is_supported_vmrun_version(options):
fail_usage("Unsupported version of vmrun command! You must use at least version %d!" %
(VMRUN_MINIMUM_REQUIRED_VERSION))
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py
index ccdbac1..feba447 100644
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
@@ -107,7 +107,7 @@ def get_power_status(conn, options):
(machines, uuid, mappingToUUID) = process_results(raw_machines, {}, {}, {})
# Probably need to loop over the ContinueRetreive if there are more results after 1 iteration.
- while (hasattr(raw_machines, 'token') == True):
+ while hasattr(raw_machines, 'token'):
try:
raw_machines = conn.service.ContinueRetrievePropertiesEx(mo_PropertyCollector, raw_machines.token)
except Exception:
@@ -169,7 +169,7 @@ def set_power_status(conn, options):
else:
conn.service.PowerOffVM_Task(mo_machine)
except suds.WebFault, ex:
- if ((str(ex).find("Permission to perform this operation was denied")) >= 0):
+ if (str(ex).find("Permission to perform this operation was denied")) >= 0:
fail(EC_INVALID_PRIVILEGES)
else:
if options["--action"] == "on":
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index d502a0e..a7e1c8f 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -67,9 +67,9 @@ def get_plug_status(conn, options):
## We already believe that first column contains plug number
if len(plug_line[0]) != 0:
outlets[plug_line[0]] = (plug_line[name_index], plug_line[status_index])
- elif (plug_section == 1):
+ elif plug_section == 1:
plug_section = 2
- elif (line.upper().startswith("PLUG")):
+ elif line.upper().startswith("PLUG"):
plug_section = 1
plug_header = [x.strip().lower() for x in line.split("|")]
plug_index = plug_header.index("plug")
@@ -99,7 +99,7 @@ def get_plug_group_status(conn, options):
lines = listing.splitlines()
while line_index < len(lines) and line_index >= 0:
line = lines[line_index]
- if (line.find("|") >= 0 and line.lstrip().startswith("GROUP NAME") == False):
+ if line.find("|") >= 0 and line.lstrip().startswith("GROUP NAME") == False:
plug_line = [x.strip().lower() for x in line.split("|")]
if ["list", "monitor"].count(options["--action"]) == 0 and \
options["--plug"].lower() == plug_line[name_index]:
@@ -137,7 +137,7 @@ def get_plug_group_status(conn, options):
outlets[group_name] = (group_name, get_plug_group_status_from_list(plug_status))
line_index += 1
- elif (line.upper().lstrip().startswith("GROUP NAME")):
+ elif line.upper().lstrip().startswith("GROUP NAME"):
plug_header = [x.strip().lower() for x in line.split("|")]
name_index = plug_header.index("group name")
plug_index = plug_header.index("plug")
diff --git a/fence/agents/xenapi/fence_xenapi.py b/fence/agents/xenapi/fence_xenapi.py
index 2a52c98..0a4f838 100644
--- a/fence/agents/xenapi/fence_xenapi.py
+++ b/fence/agents/xenapi/fence_xenapi.py
@@ -58,7 +58,7 @@ def get_power_fn(session, options):
record = session.xenapi.VM.get_record(vm)
# Check that we are not trying to manipulate a template or a control
# domain as they show up as VM's with specific properties.
- if not(record["is_a_template"]) and not(record["is_control_domain"]):
+ if not record["is_a_template"] and not record["is_control_domain"]:
status = record["power_state"]
if verbose:
print "UUID:", record["uuid"], "NAME:", record["name_label"], "POWER STATUS:", record["power_state"]
@@ -70,7 +70,7 @@ def get_power_fn(session, options):
# We want to make sure that we only return the status "off" if the machine is actually halted as the status
# is checked before a fencing action. Only when the machine is Halted is it not consuming resources which
# may include whatever you are trying to protect with this fencing action.
- return (status=="Halted" and "off" or "on")
+ return status == "Halted" and "off" or "on"
except Exception, exn:
print str(exn)
@@ -87,14 +87,14 @@ def set_power_fn(session, options):
record = session.xenapi.VM.get_record(vm)
# Check that we are not trying to manipulate a template or a control
# domain as they show up as VM's with specific properties.
- if not(record["is_a_template"]) and not(record["is_control_domain"]):
- if( action == "on" ):
+ if not record["is_a_template"] and not record["is_control_domain"]:
+ if action == "on":
# Start the VM
session.xenapi.VM.start(vm, False, True)
- elif( action == "off" ):
+ elif action == "off":
# Force shutdown the VM
session.xenapi.VM.hard_shutdown(vm)
- elif( action == "reboot" ):
+ elif action == "reboot":
# Force reboot the VM
session.xenapi.VM.hard_reboot(vm)
except Exception, exn:
@@ -116,7 +116,7 @@ def get_outlet_list(session, options):
record = session.xenapi.VM.get_record(vm)
# Check that we are not trying to manipulate a template or a control
# domain as they show up as VM's with specific properties.
- if not(record["is_a_template"]) and not(record["is_control_domain"]):
+ if not record["is_a_template"] and not record["is_control_domain"]:
name = record["name_label"]
uuid = record["uuid"]
status = record["power_state"]
10 years, 2 months
fence-agents: master - [cleanup] Replace map/filter by list comprehensions
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=756796...
Commit: 756796d3ab7a9a9933a7ebca2c6b0259a7a7ab9c
Parent: 92928f5fd7f90805df98d46311a6e99e17ae0fd9
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Wed Apr 16 14:50:24 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Wed Apr 16 14:50:24 2014 +0200
[cleanup] Replace map/filter by list comprehensions
---
fence/agents/cisco_mds/fence_cisco_mds.py | 2 +-
fence/agents/ifmib/fence_ifmib.py | 2 +-
fence/agents/lib/fencing.py.py | 2 +-
fence/agents/lib/fencing_snmp.py.py | 4 ++--
fence/agents/wti/fence_wti.py | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py
index 84adee2..0508f90 100644
--- a/fence/agents/cisco_mds/fence_cisco_mds.py
+++ b/fence/agents/cisco_mds/fence_cisco_mds.py
@@ -54,7 +54,7 @@ def set_power_status(conn, options):
# Convert array of format [[key1, value1], [key2, value2], ... [keyN, valueN]] to dict, where key is
# in format a.b.c.d...z and returned dict has key only z
def array_to_dict(ar):
- return dict(map(lambda y:[y[0].split('.')[-1], y[1]], ar))
+ return dict([[x[0].split(".")[-1], x[1]] for x in ar])
def get_outlets_status(conn, options):
result = {}
diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py
index f8beaa5..c477ba2 100644
--- a/fence/agents/ifmib/fence_ifmib.py
+++ b/fence/agents/ifmib/fence_ifmib.py
@@ -77,7 +77,7 @@ def set_power_status(conn, options):
# Convert array of format [[key1, value1], [key2, value2], ... [keyN, valueN]] to dict, where key is
# in format a.b.c.d...z and returned dict has key only z
def array_to_dict(ar):
- return dict(map(lambda y:[y[0].split('.')[-1], y[1]], ar))
+ return dict([[x[0].split(".")[-1], x[1]] for x in ar])
def get_outlets_status(conn, options):
result = {}
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 31155ac..a37cd0d 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -762,7 +762,7 @@ def check_input(device_opt, opt):
for opt in device_opt:
if all_opt[opt].has_key("choices"):
longopt = "--" + all_opt[opt]["longopt"]
- possible_values_upper = map (lambda y : y.upper(), all_opt[opt]["choices"])
+ possible_values_upper = [y.upper() for y in all_opt[opt]["choices"]]
if options.has_key(longopt):
options[longopt] = options[longopt].upper()
if not options["--" + all_opt[opt]["longopt"]] in possible_values_upper:
diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py
index 9ebdcbc..055c8f2 100644
--- a/fence/agents/lib/fencing_snmp.py.py
+++ b/fence/agents/lib/fencing_snmp.py.py
@@ -25,7 +25,7 @@ class FencingSnmp:
logging.debug("%s\n" % message)
def quote_for_run(self, string):
- return ''.join(map(lambda x:x==r"'" and "'\\''" or x, string))
+ return string.replace(r"'", "'\\''")
def complete_missed_params(self):
mapping = [[
@@ -134,4 +134,4 @@ class FencingSnmp:
output = self.run_command(cmd, additional_timemout).splitlines()
- return map(lambda x:x.split(None, 1), filter(lambda y:len(y)>0 and y[0]=='.', output))
+ return [ x.split(None,1) for x in output if x.startswith(".") ]
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 9d49854..d502a0e 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -212,7 +212,7 @@ is running because the connection will block any necessary fencing actions."
conn.send("open %s -%s\n"%(options["--ip"], options["--ipport"]))
re_login = re.compile("(login: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE)
- re_prompt = re.compile("|".join(map (lambda x: "(" + x + ")", options["--command-prompt"])), re.IGNORECASE)
+ re_prompt = re.compile("|".join(["(" + x + ")" for x in options["--command-prompt"]]), re.IGNORECASE)
result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["--shell-timeout"]))
if result == 0:
10 years, 2 months
cluster: RHEL511 - gfs2-utils: check and fix bad dinode pointers in gfs1 sb
by Abhijith Das
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=b5eb3050608...
Commit: b5eb3050608dbf3dae895f9d5ef3bade5669ffb1
Parent: 34ec3fa0784072b323aa46e23d1193a90b3cd59d
Author: Abhi Das <adas(a)redhat.com>
AuthorDate: Mon Apr 14 14:59:09 2014 -0500
Committer: Abhi Das <adas(a)redhat.com>
CommitterDate: Mon Apr 14 14:59:09 2014 -0500
gfs2-utils: check and fix bad dinode pointers in gfs1 sb
This patch makes gfs2_convert check for bad values of sb_seg_size,
sb_quota_di and sb_license_di.
In fsck.gfs2, attempts are made to correct these erroneous values.
This is a port of the following two upstream patches:
https://git.fedorahosted.org/cgit/gfs2-utils.git/commit/?id=d394637d9c658...
https://git.fedorahosted.org/cgit/gfs2-utils.git/commit/?id=c6d2155f68d45...
Resolves: rhbz#1084140
Signed-off-by: Abhi Das <adas(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 30 +++++++++++
gfs2/fsck/initialize.c | 114 +++++++++++++++++++++++++++++++++++++++++--
2 files changed, 140 insertions(+), 4 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 1b3f44b..d5e2ec9 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1485,6 +1485,24 @@ static int read_gfs1_jiindex(struct gfs2_sbd *sdp)
return -1;
}
+static int sanity_check(struct gfs2_sbd *sdp)
+{
+ int error = 0;
+ if (!raw_gfs1_ondisk_sb.sb_quota_di.no_addr) {
+ log_crit("Error: Superblock Quota inode address is NULL\n");
+ error = 1;
+ }
+ if (!raw_gfs1_ondisk_sb.sb_license_di.no_addr) {
+ log_crit("Error: Superblock Statfs inode address is NULL\n");
+ error = 1;
+ }
+ if (!raw_gfs1_ondisk_sb.sb_seg_size) {
+ log_crit("Error: Superblock segment size is zero\n");
+ error = 1;
+ }
+ return error;
+}
+
/* ------------------------------------------------------------------------- */
/* init - initialization code */
/* Returns: 0 on success, -1 on failure */
@@ -2067,6 +2085,18 @@ int main(int argc, char **argv)
process_parameters(argc, argv, &opts);
error = init(&sb2);
+ /*
+ * Check for some common fs errors
+ */
+ if (!error) {
+ if (sanity_check(&sb2)) {
+ log_crit("%s is not a clean gfs filesytem. Please use the"
+ " fsck.gfs2 utility to correct these errors and"
+ " try again.\n", device);
+ exit(0);
+ }
+ }
+
/* ---------------------------------------------- */
/* Make them seal their fate. */
/* ---------------------------------------------- */
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 789af2c..2842a18 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -718,9 +718,26 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
sdp->md.next_inum = be64_to_cpu(inumbuf);
}
- if (sdp->gfs1)
+ if (sdp->gfs1) {
+ /* In gfs1, the license_di is always 3 blocks after the jindex_di */
+ if ((sbd1->sb_license_di.no_addr != sbd1->sb_jindex_di.no_addr + 3) ||
+ (sbd1->sb_license_di.no_formal_ino != sbd1->sb_jindex_di.no_addr + 3)) {
+ if (!query( _("The gfs system statfs inode pointer is incorrect. "
+ "Okay to correct? (y/n) "))) {
+ log_err( _("fsck.gfs2 cannot continue without a valid "
+ "statfs file; aborting.\n"));
+ goto fail;
+ }
+ sbd1->sb_license_di.no_addr = sbd1->sb_license_di.no_formal_ino
+ = sbd1->sb_jindex_di.no_addr + 3;
+ }
+
sdp->md.statfs = inode_read(sdp, sbd1->sb_license_di.no_addr);
- else
+ if (sdp->md.statfs == NULL) {
+ log_crit(_("Error reading statfs inode: %s\n"), strerror(errno));
+ goto fail;
+ }
+ } else
gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
if (!sdp->gfs1 && !sdp->md.statfs) {
if (!query( _("The gfs2 system statfs inode is missing. "
@@ -760,9 +777,27 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
}
}
- if (sdp->gfs1)
+ if (sdp->gfs1) {
+ /* In gfs1, the quota_di is always 2 blocks after the jindex_di */
+ if ((sbd1->sb_quota_di.no_addr != sbd1->sb_jindex_di.no_addr + 2) ||
+ (sbd1->sb_quota_di.no_formal_ino != sbd1->sb_jindex_di.no_addr + 2)) {
+ if (!query( _("The gfs system quota inode pointer is incorrect. "
+ " Okay to correct? (y/n) "))) {
+ log_err( _("fsck.gfs2 cannot continue without a valid "
+ "quota file; aborting.\n"));
+ goto fail;
+ }
+ sbd1->sb_quota_di.no_addr = sbd1->sb_quota_di.no_formal_ino
+ = sbd1->sb_jindex_di.no_addr + 2;
+ }
+
sdp->md.qinode = inode_read(sdp, sbd1->sb_quota_di.no_addr);
- else
+ if (sdp->md.qinode == NULL) {
+ log_crit(_("Error reading quota inode: %s\n"), strerror(errno));
+ goto fail;
+ }
+
+ } else
gfs2_lookupi(sdp->master_dir, "quota", 5, &sdp->md.qinode);
if (!sdp->gfs1 && !sdp->md.qinode) {
if (!query( _("The gfs2 system quota inode is missing. "
@@ -1322,6 +1357,71 @@ static int reconstruct_single_journal(struct gfs2_sbd *sdp, int jnum,
return 0;
}
+static int reset_journal_seg_size(unsigned int jsize, unsigned int nsegs,
+ unsigned int bsize)
+{
+ unsigned int seg_size = jsize / (nsegs * bsize);
+ if (!seg_size)
+ seg_size = 16; /* The default with 128MB journal and 4K bsize */
+ if (seg_size != sbd1->sb_seg_size) {
+ sbd1->sb_seg_size = seg_size;
+ if (!query(_("Computed correct journal segment size to %u."
+ " Reset it? (y/n) "), seg_size)) {
+ log_crit(_("Error: Cannot proceed without a valid journal"
+ " segment size value.\n"));
+ return -1;
+ }
+ log_err(_("Resetting journal segment size to %u\n"), sbd1->sb_seg_size);
+ }
+ return 0;
+}
+
+static int correct_journal_seg_size(struct gfs2_sbd *sdp)
+{
+ int count;
+ struct gfs_jindex ji_0, ji_1;
+ char buf[sizeof(struct gfs_jindex)];
+ unsigned int jsize = GFS2_DEFAULT_JSIZE * 1024 * 1024;
+
+ count = gfs2_readi(sdp->md.jiinode, buf, 0, sizeof(struct gfs_jindex));
+ if (count != sizeof(struct gfs_jindex)) {
+ log_crit(_("Error %d reading system journal index inode. "
+ "Aborting\n"), count);
+ return -1;
+ }
+ gfs_jindex_in(&ji_0, buf);
+
+ if (sdp->md.journals == 1) {
+ if (sbd1->sb_seg_size == 0) {
+ if (!query(_("The gfs2 journal segment size is 0 and a"
+ " correct value cannot be determined in a"
+ " single-journal filesystem.\n"
+ "Continue with default? (y/n) "))) {
+ log_crit(_("Error: Cannot proceed without a valid"
+ "sb_seg_size value.\n"));
+ return -1;
+ }
+ goto out;
+ }
+ /* Don't mess with sb_seg_size because we don't know what
+ * it needs to be
+ */
+ return 0;
+ }
+
+ count = gfs2_readi(sdp->md.jiinode, buf, sizeof(struct gfs_jindex),
+ sizeof(struct gfs_jindex));
+ if (count != sizeof(struct gfs_jindex)) {
+ log_crit(_("Error %d reading system journal index inode. "
+ "Aborting\n"), count);
+ return -1;
+ }
+ gfs_jindex_in(&ji_1, buf);
+
+ jsize = (ji_1.ji_addr - ji_0.ji_addr) * sbd1->sb_bsize;
+out:
+ return reset_journal_seg_size(jsize, ji_0.ji_nsegment, sbd1->sb_bsize);
+}
/*
* reconstruct_journals - write fresh journals for GFS1 only
@@ -1335,6 +1435,12 @@ static int reconstruct_journals(struct gfs2_sbd *sdp)
struct gfs_jindex ji;
char buf[sizeof(struct gfs_jindex)];
+ /* Ensure that sb_seg_size is valid */
+ if (correct_journal_seg_size(sdp)) {
+ log_crit(_("Failed to set correct journal segment size. Cannot continue\n"));
+ return -1;
+ }
+
log_err("Clearing GFS journals (this may take a while)\n");
for (i = 0; i < sdp->md.journals; i++) {
count = gfs2_readi(sdp->md.jiinode, buf,
10 years, 2 months
cluster: RHEL511 - gfs2-utils: patch to update gfs1 superblock correctly
by Abhijith Das
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=34ec3fa0784...
Commit: 34ec3fa0784072b323aa46e23d1193a90b3cd59d
Parent: 700ec50c22d2135d2cdbd93eaa90c4b6983dc7ca
Author: Abhi Das <adas(a)redhat.com>
AuthorDate: Mon Apr 14 14:58:06 2014 -0500
Committer: Abhi Das <adas(a)redhat.com>
CommitterDate: Mon Apr 14 14:58:06 2014 -0500
gfs2-utils: patch to update gfs1 superblock correctly
gfs2-utils uses the gfs2_sb structure as a template to operate on
both gfs1 and gfs2 superblocks. Some fields of the gfs1 superblock
are not in gfs2 and are replaced by padded fields. These padded
fields were not being written out after modification and were
instead being zeroed out, thereby causing corruption.
This patch fixes gfs2_sb_out() to write out the padded fields.
This is a port of the upstream patch here:
https://git.fedorahosted.org/cgit/gfs2-utils.git/commit/?id=f8d4e5711ab54...
Resolves: rhbz#1084140
Signed-off-by: Abhi Das <adas(a)redhat.com>
---
gfs2/fsck/ondisk.c | 5 +++++
gfs2/libgfs2/ondisk.c | 5 +++++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/gfs2/fsck/ondisk.c b/gfs2/fsck/ondisk.c
index e43cd26..028c035 100644
--- a/gfs2/fsck/ondisk.c
+++ b/gfs2/fsck/ondisk.c
@@ -125,15 +125,20 @@ void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)
CPOUT_32(sb, str, sb_fs_format);
CPOUT_32(sb, str, sb_multihost_format);
+ CPOUT_32(sb, str, __pad0);
CPOUT_32(sb, str, sb_bsize);
CPOUT_32(sb, str, sb_bsize_shift);
+ CPOUT_32(sb, str, __pad1);
gfs2_inum_out(&sb->sb_master_dir, (char *)&str->sb_master_dir);
gfs2_inum_out(&sb->sb_root_dir, (char *)&str->sb_root_dir);
CPOUT_08(sb, str, sb_lockproto, GFS2_LOCKNAME_LEN);
CPOUT_08(sb, str, sb_locktable, GFS2_LOCKNAME_LEN);
+ gfs2_inum_out(&sb->__pad2, (char *)&str->__pad2); /* gfs rindex */
+ gfs2_inum_out(&sb->__pad3, (char *)&str->__pad3); /* gfs quota */
+ gfs2_inum_out(&sb->__pad4, (char *)&str->__pad4); /* gfs license */
#ifdef GFS2_HAS_UUID
memcpy(str->sb_uuid, sb->sb_uuid, 16);
#endif
diff --git a/gfs2/libgfs2/ondisk.c b/gfs2/libgfs2/ondisk.c
index 8a2868b..197c428 100644
--- a/gfs2/libgfs2/ondisk.c
+++ b/gfs2/libgfs2/ondisk.c
@@ -134,15 +134,20 @@ void gfs2_sb_out(struct gfs2_sb *sb, struct gfs2_buffer_head *bh)
CPOUT_32(sb, str, sb_fs_format);
CPOUT_32(sb, str, sb_multihost_format);
+ CPOUT_32(sb, str, __pad0);
CPOUT_32(sb, str, sb_bsize);
CPOUT_32(sb, str, sb_bsize_shift);
+ CPOUT_32(sb, str, __pad1);
gfs2_inum_out(&sb->sb_master_dir, (char *)&str->sb_master_dir);
gfs2_inum_out(&sb->sb_root_dir, (char *)&str->sb_root_dir);
CPOUT_08(sb, str, sb_lockproto, GFS2_LOCKNAME_LEN);
CPOUT_08(sb, str, sb_locktable, GFS2_LOCKNAME_LEN);
+ gfs2_inum_out(&sb->__pad2, (char *)&str->__pad2); /* gfs rindex */
+ gfs2_inum_out(&sb->__pad3, (char *)&str->__pad3); /* gfs quota */
+ gfs2_inum_out(&sb->__pad4, (char *)&str->__pad4); /* gfs license */
#ifdef GFS2_HAS_UUID
CPOUT_08(sb, str, sb_uuid, sizeof(sb->sb_uuid));
#endif
10 years, 2 months