Blame SOURCES/bz2080729-2-fence_lpar-fix-import-fail_usage.patch

eab3e9
From e3dff8570b70f0c19eca84cf02f0aadd68e16599 Mon Sep 17 00:00:00 2001
eab3e9
From: Thomas Renninger <trenn@suse.com>
eab3e9
Date: Fri, 25 Feb 2022 14:05:42 +0100
eab3e9
Subject: [PATCH] fence_lpar: fix missing import logging, use fail_usage
eab3e9
eab3e9
and slightly re-factor code to avoid duplicate code lines.
eab3e9
Should be cleanup only, no functional change.
eab3e9
---
eab3e9
 agents/lpar/fence_lpar.py | 39 ++++++++++++++++++---------------------
eab3e9
 1 file changed, 18 insertions(+), 21 deletions(-)
eab3e9
eab3e9
diff --git a/agents/lpar/fence_lpar.py b/agents/lpar/fence_lpar.py
eab3e9
index ad18c6191..2046b0e4e 100644
eab3e9
--- a/agents/lpar/fence_lpar.py
eab3e9
+++ b/agents/lpar/fence_lpar.py
eab3e9
@@ -28,31 +28,28 @@ def _normalize_status(status):
eab3e9
 
eab3e9
 def get_power_status(conn, options):
eab3e9
 	if options["--hmc-version"] == "3":
eab3e9
-		conn.send("lssyscfg -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + " -F name,state\n")
eab3e9
-
eab3e9
-		# First line (command) may cause parsing issues if long
eab3e9
-		conn.readline()
eab3e9
-		conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
eab3e9
-
eab3e9
-		try:
eab3e9
-			status = re.compile("^" + options["--plug"] + ",(.*?),.*$",
eab3e9
-					re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
eab3e9
-		except AttributeError as e:
eab3e9
-			logging.error("Failed: {}".format(str(e)))
eab3e9
-			fail(EC_STATUS_HMC)
eab3e9
+		command = "lssyscfg -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + " -F name,state\n"
eab3e9
 	elif options["--hmc-version"] in ["4", "IVM"]:
eab3e9
-		conn.send("lssyscfg -r lpar -m "+ options["--managed"] +
eab3e9
-				" --filter 'lpar_names=" + options["--plug"] + "'\n")
eab3e9
+		command = "lssyscfg -r lpar -m "+ options["--managed"] + \
eab3e9
+			" --filter 'lpar_names=" + options["--plug"] + "'\n"
eab3e9
+	else:
eab3e9
+		# Bad HMC Version cannot be reached
eab3e9
+		fail(EC_STATUS_HMC)
eab3e9
 
eab3e9
-		# First line (command) may cause parsing issues if long
eab3e9
-		conn.readline()
eab3e9
-		conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
eab3e9
+	conn.send(command)
eab3e9
+	# First line (command) may cause parsing issues if long
eab3e9
+	conn.readline()
eab3e9
+	conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
eab3e9
 
eab3e9
-		try:
eab3e9
+	try:
eab3e9
+		if options["--hmc-version"] == "3":
eab3e9
+			status = re.compile("^" + options["--plug"] + ",(.*?),.*$",
eab3e9
+					    re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
eab3e9
+		elif options["--hmc-version"] in ["4", "IVM"]:
eab3e9
 			status = re.compile(",state=(.*?),", re.IGNORECASE).search(conn.before).group(1)
eab3e9
-		except AttributeError as e:
eab3e9
-			logging.error("Failed: {}".format(str(e)))
eab3e9
-			fail(EC_STATUS_HMC)
eab3e9
+	except AttributeError as e:
eab3e9
+		fail_usage("Command on HMC failed: {}\n{}".format(command, str(e)), False)
eab3e9
+		fail(EC_STATUS_HMC)
eab3e9
 
eab3e9
 	return _normalize_status(status)
eab3e9