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

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