Blame SOURCES/bz1188750-fence_zvmip-improve_usage_of_resources.patch

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