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

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