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