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