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