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

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