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

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