summaryrefslogtreecommitdiff
path: root/bz2065114-fence_lpar-refactor.patch
blob: 599a22cfaf2b24e498165928171cf917540066b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From e3dff8570b70f0c19eca84cf02f0aadd68e16599 Mon Sep 17 00:00:00 2001
From: Thomas Renninger <trenn@suse.com>
Date: Fri, 25 Feb 2022 14:05:42 +0100
Subject: [PATCH] fence_lpar: fix missing import logging, use fail_usage

and slightly re-factor code to avoid duplicate code lines.
Should be cleanup only, no functional change.
---
 agents/lpar/fence_lpar.py | 39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/agents/lpar/fence_lpar.py b/agents/lpar/fence_lpar.py
index ad18c6191..2046b0e4e 100644
--- a/agents/lpar/fence_lpar.py
+++ b/agents/lpar/fence_lpar.py
@@ -28,31 +28,28 @@ def _normalize_status(status):
 
 def get_power_status(conn, options):
 	if options["--hmc-version"] == "3":
-		conn.send("lssyscfg -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + " -F name,state\n")
-
-		# First line (command) may cause parsing issues if long
-		conn.readline()
-		conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
-
-		try:
-			status = re.compile("^" + options["--plug"] + ",(.*?),.*$",
-					re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
-		except AttributeError as e:
-			logging.error("Failed: {}".format(str(e)))
-			fail(EC_STATUS_HMC)
+		command = "lssyscfg -r lpar -m " + options["--managed"] + " -n " + options["--plug"] + " -F name,state\n"
 	elif options["--hmc-version"] in ["4", "IVM"]:
-		conn.send("lssyscfg -r lpar -m "+ options["--managed"] +
-				" --filter 'lpar_names=" + options["--plug"] + "'\n")
+		command = "lssyscfg -r lpar -m "+ options["--managed"] + \
+			" --filter 'lpar_names=" + options["--plug"] + "'\n"
+	else:
+		# Bad HMC Version cannot be reached
+		fail(EC_STATUS_HMC)
 
-		# First line (command) may cause parsing issues if long
-		conn.readline()
-		conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
+	conn.send(command)
+	# First line (command) may cause parsing issues if long
+	conn.readline()
+	conn.log_expect(options["--command-prompt"], int(options["--power-timeout"]))
 
-		try:
+	try:
+		if options["--hmc-version"] == "3":
+			status = re.compile("^" + options["--plug"] + ",(.*?),.*$",
+					    re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
+		elif options["--hmc-version"] in ["4", "IVM"]:
 			status = re.compile(",state=(.*?),", re.IGNORECASE).search(conn.before).group(1)
-		except AttributeError as e:
-			logging.error("Failed: {}".format(str(e)))
-			fail(EC_STATUS_HMC)
+	except AttributeError as e:
+		fail_usage("Command on HMC failed: {}\n{}".format(command, str(e)), False)
+		fail(EC_STATUS_HMC)
 
 	return _normalize_status(status)