Blame SOURCES/bz1753228-fence_mpath-1-add-plug-parameter-support.patch

91f48e
From d866e11213ebeab8da280b41371a968ae12410bd Mon Sep 17 00:00:00 2001
91f48e
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
91f48e
Date: Fri, 13 Sep 2019 12:48:46 +0200
91f48e
Subject: [PATCH] fence_mpath: use -n/--plug/port parameter to be able to use
91f48e
 pcmk_host_map
91f48e
91f48e
---
91f48e
 agents/mpath/fence_mpath.py         | 63 +++++++++++++++++------------
91f48e
 tests/data/metadata/fence_mpath.xml | 12 +++++-
91f48e
 2 files changed, 49 insertions(+), 26 deletions(-)
91f48e
91f48e
diff --git a/agents/mpath/fence_mpath.py b/agents/mpath/fence_mpath.py
91f48e
index e4f59836..dfc5657b 100644
91f48e
--- a/agents/mpath/fence_mpath.py
91f48e
+++ b/agents/mpath/fence_mpath.py
91f48e
@@ -16,11 +16,11 @@ def get_status(conn, options):
91f48e
 	status = "off"
91f48e
 	for dev in options["devices"]:
91f48e
 		is_block_device(dev)
91f48e
-		if options["--key"] in get_registration_keys(options, dev):
91f48e
+		if options["--plug"] in get_registration_keys(options, dev):
91f48e
 			status = "on"
91f48e
 		else:
91f48e
 			logging.debug("No registration for key "\
91f48e
-				+ options["--key"] + " on device " + dev + "\n")
91f48e
+				+ options["--plug"] + " on device " + dev + "\n")
91f48e
 
91f48e
 	if options["--action"] == "monitor":
91f48e
 		dev_read(options)
91f48e
@@ -36,10 +36,10 @@ def set_status(conn, options):
91f48e
 			is_block_device(dev)
91f48e
 
91f48e
 			register_dev(options, dev)
91f48e
-			if options["--key"] not in get_registration_keys(options, dev):
91f48e
+			if options["--plug"] not in get_registration_keys(options, dev):
91f48e
 				count += 1
91f48e
 				logging.debug("Failed to register key "\
91f48e
-					+ options["--key"] + "on device " + dev + "\n")
91f48e
+					+ options["--plug"] + "on device " + dev + "\n")
91f48e
 				continue
91f48e
 			dev_write(options, dev)
91f48e
 
91f48e
@@ -48,7 +48,7 @@ def set_status(conn, options):
91f48e
 			and get_reservation_key(options, dev) is None:
91f48e
 				count += 1
91f48e
 				logging.debug("Failed to create reservation (key="\
91f48e
-					+ options["--key"] + ", device=" + dev + ")\n")
91f48e
+					+ options["--plug"] + ", device=" + dev + ")\n")
91f48e
 
91f48e
 	else:
91f48e
 		dev_keys = dev_read(options)
91f48e
@@ -56,14 +56,14 @@ def set_status(conn, options):
91f48e
 		for dev in options["devices"]:
91f48e
 			is_block_device(dev)
91f48e
 
91f48e
-			if options["--key"] in get_registration_keys(options, dev):
91f48e
+			if options["--plug"] in get_registration_keys(options, dev):
91f48e
 				preempt_abort(options, dev_keys[dev], dev)
91f48e
 
91f48e
 		for dev in options["devices"]:
91f48e
-			if options["--key"] in get_registration_keys(options, dev):
91f48e
+			if options["--plug"] in get_registration_keys(options, dev):
91f48e
 				count += 1
91f48e
 				logging.debug("Failed to remove key "\
91f48e
-					+ options["--key"] + " on device " + dev + "\n")
91f48e
+					+ options["--plug"] + " on device " + dev + "\n")
91f48e
 				continue
91f48e
 
91f48e
 			if not get_reservation_key(options, dev):
91f48e
@@ -97,16 +97,16 @@ def is_block_device(dev):
91f48e
 
91f48e
 # cancel registration
91f48e
 def preempt_abort(options, host, dev):
91f48e
-	cmd = options["--mpathpersist-path"] + " -o --preempt-abort --prout-type=5 --param-rk=" + host +" --param-sark=" + options["--key"] +" -d " + dev
91f48e
+	cmd = options["--mpathpersist-path"] + " -o --preempt-abort --prout-type=5 --param-rk=" + host +" --param-sark=" + options["--plug"] +" -d " + dev
91f48e
 	return not bool(run_cmd(options, cmd)["err"])
91f48e
 
91f48e
 def register_dev(options, dev):
91f48e
-	cmd = options["--mpathpersist-path"] + " -o --register --param-sark=" + options["--key"] + " -d " + dev
91f48e
+	cmd = options["--mpathpersist-path"] + " -o --register --param-sark=" + options["--plug"] + " -d " + dev
91f48e
 	#cmd return code != 0 but registration can be successful
91f48e
 	return not bool(run_cmd(options, cmd)["err"])
91f48e
 
91f48e
 def reserve_dev(options, dev):
91f48e
-	cmd = options["--mpathpersist-path"] + " -o --reserv --prout-type=5 --param-rk=" + options["--key"] + " -d " + dev
91f48e
+	cmd = options["--mpathpersist-path"] + " -o --reserv --prout-type=5 --param-rk=" + options["--plug"] + " -d " + dev
91f48e
 	return not bool(run_cmd(options, cmd)["err"])
91f48e
 
91f48e
 def get_reservation_key(options, dev):
91f48e
@@ -141,7 +141,7 @@ def dev_write(options, dev):
91f48e
 		fail_usage("Failed: Cannot open file \""+ file_path + "\"")
91f48e
 	out = store_fh.read()
91f48e
 	if not re.search(r"^" + dev + r"\s+", out):
91f48e
-		store_fh.write(dev + "\t" + options["--key"] + "\n")
91f48e
+		store_fh.write(dev + "\t" + options["--plug"] + "\n")
91f48e
 	store_fh.close()
91f48e
 
91f48e
 def dev_read(options, fail=True):
91f48e
@@ -209,12 +209,9 @@ def define_new_opts():
91f48e
 	all_opt["key"] = {
91f48e
 		"getopt" : "k:",
91f48e
 		"longopt" : "key",
91f48e
-		"help" : "-k, --key=[key]                Key to use for the current operation",
91f48e
-		"required" : "1",
91f48e
-		"shortdesc" : "Key to use for the current operation. This key should be \
91f48e
-unique to a node and have to be written in /etc/multipath.conf. For the \"on\" action, the key specifies the key use to \
91f48e
-register the local node. For the \"off\" action, this key specifies the key to \
91f48e
-be removed from the device(s).",
91f48e
+		"help" : "-k, --key=[key]                Replaced by -n, --plug",
91f48e
+		"required" : "0",
91f48e
+		"shortdesc" : "Replaced by -n, --plug",
91f48e
 		"order": 1
91f48e
 	}
91f48e
 	all_opt["mpathpersist_path"] = {
91f48e
@@ -240,10 +237,18 @@ def main():
91f48e
 	atexit.register(atexit_handler)
91f48e
 
91f48e
 	device_opt = ["no_login", "no_password", "devices", "key", "sudo", \
91f48e
-	        "fabric_fencing", "on_target", "store_path", "mpathpersist_path", "force_on"]
91f48e
+	        "fabric_fencing", "on_target", "store_path", \
91f48e
+		"mpathpersist_path", "force_on", "port", "no_port"]
91f48e
 
91f48e
 	define_new_opts()
91f48e
 
91f48e
+	all_opt["port"]["help"] = "Key to use for the current operation"
91f48e
+	all_opt["port"]["shortdesc"] = "Key to use for the current operation. \
91f48e
+This key should be unique to a node and have to be written in \
91f48e
+/etc/multipath.conf. For the \"on\" action, the key specifies the key use to \
91f48e
+register the local node. For the \"off\" action, this key specifies the key to \
91f48e
+be removed from the device(s)."
91f48e
+
91f48e
 	# fence_mpath_check
91f48e
 	if os.path.basename(sys.argv[0]) == "fence_mpath_check":
91f48e
 		sys.exit(mpath_check())
91f48e
@@ -252,6 +257,17 @@ def main():
91f48e
 
91f48e
 	options = check_input(device_opt, process_input(device_opt), other_conditions=True)
91f48e
 
91f48e
+	# hack to remove list/list-status actions which are not supported
91f48e
+	options["device_opt"] = [ o for o in options["device_opt"] if o != "separator" ]
91f48e
+
91f48e
+	# workaround to avoid regressions
91f48e
+	if "--key" in options:
91f48e
+		options["--plug"] = options["--key"]
91f48e
+		del options["--key"]
91f48e
+	elif options["--action"] in ["off", "on", "reboot", "status"] \
91f48e
+	     and "--plug" not in options:
91f48e
+		fail_usage("Failed: You have to enter plug number or machine identification", stop)
91f48e
+
91f48e
 	docs = {}
91f48e
 	docs["shortdesc"] = "Fence agent for multipath persistent reservation"
91f48e
 	docs["longdesc"] = "fence_mpath is an I/O fencing agent that uses SCSI-3 \
91f48e
@@ -271,16 +287,13 @@ def main():
91f48e
 	run_delay(options)
91f48e
 
91f48e
 	# Input control BEGIN
91f48e
-	if not "--key" in options:
91f48e
-		fail_usage("Failed: key is required")
91f48e
-
91f48e
 	if options["--action"] == "validate-all":
91f48e
 		sys.exit(0)
91f48e
 
91f48e
-	options["devices"] = options["--devices"].split(",")
91f48e
-
91f48e
-	if not options["devices"]:
91f48e
+	if not ("--devices" in options and options["--devices"]):
91f48e
 		fail_usage("Failed: No devices found")
91f48e
+
91f48e
+	options["devices"] = options["--devices"].split(",")
91f48e
 	# Input control END
91f48e
 
91f48e
 	result = fence_action(None, options, set_status, get_status)
91f48e
diff --git a/tests/data/metadata/fence_mpath.xml b/tests/data/metadata/fence_mpath.xml
91f48e
index bbe9ad2b..fe9378df 100644
91f48e
--- a/tests/data/metadata/fence_mpath.xml
91f48e
+++ b/tests/data/metadata/fence_mpath.xml
91f48e
@@ -14,9 +14,19 @@ The fence_mpath agent works by having a unique key for each node that has to be
91f48e
 		<content type="string"  />
91f48e
 		<shortdesc lang="en">List of devices to use for current operation. Devices can be comma-separated list of device-mapper multipath devices (eg. /dev/mapper/3600508b400105df70000e00000ac0000 or /dev/mapper/mpath1). Each device must support SCSI-3 persistent reservations.</shortdesc>
91f48e
 	</parameter>
91f48e
-	<parameter name="key" unique="0" required="1">
91f48e
+	<parameter name="key" unique="0" required="0">
91f48e
 		<getopt mixed="-k, --key=[key]" />
91f48e
 		<content type="string"  />
91f48e
+		<shortdesc lang="en">Replaced by -n, --plug</shortdesc>
91f48e
+	</parameter>
91f48e
+	<parameter name="plug" unique="0" required="1" obsoletes="port">
91f48e
+		<getopt mixed="Key to use for the current operation" />
91f48e
+		<content type="string"  />
91f48e
+		<shortdesc lang="en">Key to use for the current operation. This key should be unique to a node and have to be written in /etc/multipath.conf. For the "on" action, the key specifies the key use to register the local node. For the "off" action, this key specifies the key to be removed from the device(s).</shortdesc>
91f48e
+	</parameter>
91f48e
+	<parameter name="port" unique="0" required="1" deprecated="1">
91f48e
+		<getopt mixed="Key to use for the current operation" />
91f48e
+		<content type="string"  />
91f48e
 		<shortdesc lang="en">Key to use for the current operation. This key should be unique to a node and have to be written in /etc/multipath.conf. For the "on" action, the key specifies the key use to register the local node. For the "off" action, this key specifies the key to be removed from the device(s).</shortdesc>
91f48e
 	</parameter>
91f48e
 	<parameter name="quiet" unique="0" required="0">