Blame SOURCES/bz1861926-fence_lpar-fix-list-status-action.patch

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