fence-agents/SOURCES/bz1861926-fence_lpar-fix-list-status-action.patch
2021-09-09 16:34:56 +00:00

146 lines
5.0 KiB
Diff

From 6d0b2cb598135b697ee583e3514aa427fc0e4cf8 Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Wed, 29 Jul 2020 18:33:17 -0700
Subject: [PATCH 1/2] fence_lpar: Fix list-status action
The `list-status` action prints "UNKNOWN" status for all LPARs when
`--hmc-version` is `"4"` or `"IVM"`.
This commit fixes that by mapping the statuses returned by the HMC
(e.g., "Running") to the statuses that the fencing library expects
(e.g., "on").
Resolves: RHBZ#1861926
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
agents/lpar/fence_lpar.py | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/agents/lpar/fence_lpar.py b/agents/lpar/fence_lpar.py
index 9dfabc43..03068466 100644
--- a/agents/lpar/fence_lpar.py
+++ b/agents/lpar/fence_lpar.py
@@ -16,6 +16,16 @@
from fencing import *
from fencing import fail, fail_usage, EC_STATUS_HMC
+##
+## Transformation to standard ON/OFF status if possible
+def _normalize_status(status):
+ if status in ["Running", "Open Firmware", "Shutting Down", "Starting"]:
+ status = "on"
+ else:
+ status = "off"
+
+ return status
+
def get_power_status(conn, options):
if options["--hmc-version"] == "3":
conn.send("lssyscfg -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + " -F name,state\n")
@@ -42,14 +52,7 @@ def get_power_status(conn, options):
except AttributeError:
fail(EC_STATUS_HMC)
- ##
- ## Transformation to standard ON/OFF status if possible
- if status in ["Running", "Open Firmware", "Shutting Down", "Starting"]:
- status = "on"
- else:
- status = "off"
-
- return status
+ return _normalize_status(status)
def set_power_status(conn, options):
if options["--hmc-version"] == "3":
@@ -111,10 +114,10 @@ def get_lpar_list(conn, options):
lines = res.group(1).split("\n")
for outlet_line in lines:
try:
- (port, status) = outlet_line.split(":")
+ (port, status) = outlet_line.rstrip().split(":")
except ValueError:
fail_usage('Output does not match expected HMC version, try different one');
- outlets[port] = ("", status)
+ outlets[port] = ("", _normalize_status(status))
elif options["--hmc-version"] == "IVM":
conn.send("lssyscfg -r lpar -m " + options["--managed"] +
" -F name,state\n")
@@ -133,10 +136,10 @@ def get_lpar_list(conn, options):
lines = res.group(1).split("\n")
for outlet_line in lines:
try:
- (port, status) = outlet_line.split(",")
+ (port, status) = outlet_line.rstrip().split(",")
except ValueError:
fail_usage('Output does not match expected HMC version, try different one');
- outlets[port] = ("", status)
+ outlets[port] = ("", _normalize_status(status))
return outlets
From 4f7b40c0cde896f2f5b09e796ba34450e90aee6c Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Wed, 29 Jul 2020 18:43:47 -0700
Subject: [PATCH 2/2] fence_lpar: Reduce code duplication in get_lpar_list
The logic for HMC version 4 and HMC version IVM are the same except for
the use of a different separator character. This commit condenses them
into one block.
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
agents/lpar/fence_lpar.py | 28 ++++------------------------
1 file changed, 4 insertions(+), 24 deletions(-)
diff --git a/agents/lpar/fence_lpar.py b/agents/lpar/fence_lpar.py
index 03068466..7560a82c 100644
--- a/agents/lpar/fence_lpar.py
+++ b/agents/lpar/fence_lpar.py
@@ -96,31 +96,11 @@ def get_lpar_list(conn, options):
lines = res.group(2).split("\n")
for outlet_line in lines:
outlets[outlet_line.rstrip()] = ("", "")
- elif options["--hmc-version"] == "4":
- conn.send("lssyscfg -r lpar -m " + options["--managed"] +
- " -F name:state\n")
-
- ## We have to remove first line (command)
- conn.readline()
- conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
-
- ## We have to remove last line (part of new prompt)
- ####
- res = re.search("^(.*)\n.*$", conn.before, re.S)
-
- if res == None:
- fail_usage("Unable to parse output of list command")
+ elif options["--hmc-version"] in ["4", "IVM"]:
+ sep = ":" if options["--hmc-version"] == "4" else ","
- lines = res.group(1).split("\n")
- for outlet_line in lines:
- try:
- (port, status) = outlet_line.rstrip().split(":")
- except ValueError:
- fail_usage('Output does not match expected HMC version, try different one');
- outlets[port] = ("", _normalize_status(status))
- elif options["--hmc-version"] == "IVM":
conn.send("lssyscfg -r lpar -m " + options["--managed"] +
- " -F name,state\n")
+ " -F name" + sep + "state\n")
## We have to remove first line (command)
conn.readline()
@@ -136,7 +116,7 @@ def get_lpar_list(conn, options):
lines = res.group(1).split("\n")
for outlet_line in lines:
try:
- (port, status) = outlet_line.rstrip().split(",")
+ (port, status) = outlet_line.rstrip().split(sep)
except ValueError:
fail_usage('Output does not match expected HMC version, try different one');
outlets[port] = ("", _normalize_status(status))