Blame SOURCES/bz1188750-fence_zvmip-improve_usage_of_resources.patch

e4ffb1
From 4ef3bd1bc0e7bb3fcd3c3b2a7ce20e49e37d3332 Mon Sep 17 00:00:00 2001
e4ffb1
From: Marek 'marx' Grac <mgrac@redhat.com>
e4ffb1
Date: Mon, 22 Jun 2015 16:49:27 +0200
e4ffb1
Subject: [PATCH] fence_zvmip: Add --missing-as-off and improve usage of system
e4ffb1
 resources
e4ffb1
e4ffb1
Resolves: rhbz#1188750
e4ffb1
---
e4ffb1
 fence/agents/lib/fencing.py.py      |  5 ++++
e4ffb1
 fence/agents/zvm/fence_zvmip.py     | 49 +++++++++++++++++++++++++------------
e4ffb1
 tests/data/metadata/fence_zvmip.xml |  5 ++++
e4ffb1
 3 files changed, 44 insertions(+), 15 deletions(-)
e4ffb1
e4ffb1
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
e4ffb1
index 29b3a94..db620e8 100644
e4ffb1
--- a/fence/agents/lib/fencing.py.py
e4ffb1
+++ b/fence/agents/lib/fencing.py.py
e4ffb1
@@ -902,7 +902,12 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list=None,
e4ffb1
 			return
e4ffb1
 		elif (options["--action"] == "list") or \
e4ffb1
 				((options["--action"] == "monitor") and 1 == options["device_opt"].count("port")):
e4ffb1
+			options["--original-action"] = options["--action"]
e4ffb1
+			options["--action"] = "list"
e4ffb1
 			outlets = get_outlet_list(tn, options)
e4ffb1
+			options["--action"] = options["--original-action"]
e4ffb1
+			del options["--original-action"]
e4ffb1
+
e4ffb1
 			## keys can be numbers (port numbers) or strings (names of VM)
e4ffb1
 			for outlet_id in outlets.keys():
e4ffb1
 				(alias, status) = outlets[outlet_id]
e4ffb1
diff --git a/fence/agents/zvm/fence_zvmip.py b/fence/agents/zvm/fence_zvmip.py
e4ffb1
index 63f7fa7..3fe6f24 100644
e4ffb1
--- a/fence/agents/zvm/fence_zvmip.py
e4ffb1
+++ b/fence/agents/zvm/fence_zvmip.py
e4ffb1
@@ -62,24 +62,38 @@ def prepare_smapi_command(options, smapi_function, additional_args):
e4ffb1
 def get_power_status(conn, options):
e4ffb1
 	del conn
e4ffb1
 
e4ffb1
-	# '*' = list all active images
e4ffb1
+	if options.get("--original-action", None) == "monitor":
e4ffb1
+		(return_code, reason_code, images_active) = \
e4ffb1
+			get_list_of_images(options, "Check_Authentication", None)
e4ffb1
+		logging.debug("Check_Authenticate (%d,%d)", return_code, reason_code)
e4ffb1
+		if return_code == 0:
e4ffb1
+			return {}
e4ffb1
+		else:
e4ffb1
+			fail(EC_LOGIN_DENIED)
e4ffb1
+
e4ffb1
+	if options["--action"] == "list":
e4ffb1
+		# '*' = list all active images
e4ffb1
+		options["--plug"] = "*"
e4ffb1
+
e4ffb1
 	(return_code, reason_code, images_active) = \
e4ffb1
-			get_list_of_images(options, "Image_Status_Query", "*")
e4ffb1
+			get_list_of_images(options, "Image_Status_Query", options["--plug"])
e4ffb1
 	logging.debug("Image_Status_Query results are (%d,%d)", return_code, reason_code)
e4ffb1
-	(return_code, reason_code, images_defined) = \
e4ffb1
+
e4ffb1
+	if not options["--action"] == "list":
e4ffb1
+		if (return_code == 0) and (reason_code == 0):
e4ffb1
+			return "on"
e4ffb1
+		elif (return_code == 0) and (reason_code == 12):
e4ffb1
+			# We are running always with --missing-as-off because we can not check if image
e4ffb1
+			# is defined or not (look at rhbz#1188750)
e4ffb1
+			return "off"
e4ffb1
+		else:
e4ffb1
+			return "unknown"
e4ffb1
+	else:
e4ffb1
+		(return_code, reason_code, images_defined) = \
e4ffb1
 			get_list_of_images(options, "Image_Name_Query_DM", options["--username"])
e4ffb1
-	logging.debug("Image_Name_Query_DM results are (%d,%d)", return_code, reason_code)
e4ffb1
+		logging.debug("Image_Name_Query_DM results are (%d,%d)", return_code, reason_code)
e4ffb1
 
e4ffb1
-	if ["list", "monitor"].count(options["--action"]) == 1:
e4ffb1
 		return dict([(i, ("", "on" if i in images_active else "off")) for i in images_defined])
e4ffb1
-	else:
e4ffb1
-		status = "error"
e4ffb1
-		if options["--plug"].upper() in images_defined:
e4ffb1
-			if options["--plug"].upper() in images_active:
e4ffb1
-				status = "on"
e4ffb1
-			else:
e4ffb1
-				status = "off"
e4ffb1
-		return status
e4ffb1
 
e4ffb1
 def set_power_status(conn, options):
e4ffb1
 	conn = open_socket(options)
e4ffb1
@@ -101,7 +115,11 @@ def set_power_status(conn, options):
e4ffb1
 def get_list_of_images(options, command, data_as_plug):
e4ffb1
 	conn = open_socket(options)
e4ffb1
 
e4ffb1
-	packet = prepare_smapi_command(options, command, [data_as_plug])
e4ffb1
+	if data_as_plug is None:
e4ffb1
+		packet = prepare_smapi_command(options, command, [])
e4ffb1
+	else:
e4ffb1
+		packet = prepare_smapi_command(options, command, [data_as_plug])
e4ffb1
+
e4ffb1
 	conn.send(packet)
e4ffb1
 
e4ffb1
 	request_id = struct.unpack("!i", conn.recv(INT4))[0]
e4ffb1
@@ -133,12 +151,13 @@ def get_list_of_images(options, command, data_as_plug):
e4ffb1
 	return (return_code, reason_code, images)
e4ffb1
 
e4ffb1
 def main():
e4ffb1
-	device_opt = ["ipaddr", "login", "passwd", "port", "method"]
e4ffb1
+	device_opt = ["ipaddr", "login", "passwd", "port", "method", "missing_as_off"]
e4ffb1
 
e4ffb1
 	atexit.register(atexit_handler)
e4ffb1
 
e4ffb1
 	all_opt["ipport"]["default"] = "44444"
e4ffb1
 	all_opt["shell_timeout"]["default"] = "5.0"
e4ffb1
+	all_opt["missing_as_off"]["default"] = "1"
e4ffb1
 	options = check_input(device_opt, process_input(device_opt))
e4ffb1
 
e4ffb1
 	if len(options.get("--plug", "")) > 8:
e4ffb1
diff --git a/tests/data/metadata/fence_zvmip.xml b/tests/data/metadata/fence_zvmip.xml
e4ffb1
index 03220cb..993dfb3 100644
e4ffb1
--- a/tests/data/metadata/fence_zvmip.xml
e4ffb1
+++ b/tests/data/metadata/fence_zvmip.xml
e4ffb1
@@ -120,6 +120,11 @@ Where XXXXXXX is the name of the virtual machine used in the authuser field of t
e4ffb1
 		<content type="string" default="5.0"  />
e4ffb1
 		<shortdesc lang="en">Wait X seconds for cmd prompt after issuing command</shortdesc>
e4ffb1
 	</parameter>
e4ffb1
+	<parameter name="missing_as_off" unique="0" required="0">
e4ffb1
+		<getopt mixed="--missing-as-off" />
e4ffb1
+		<content type="boolean" default="1"  />
e4ffb1
+		<shortdesc lang="en">Missing port returns OFF instead of failure</shortdesc>
e4ffb1
+	</parameter>
e4ffb1
 	<parameter name="retry_on" unique="0" required="0">
e4ffb1
 		<getopt mixed="--retry-on=[attempts]" />
e4ffb1
 		<content type="string" default="1"  />
e4ffb1
-- 
e4ffb1
1.9.3
e4ffb1