Blame SOURCES/bz1476401-3-add-sync_set_power-to-fence_action.patch

4822a5
--- a/fence/agents/lib/fencing.py.py.orig	2017-10-16 13:51:44.994248524 +0200
4822a5
+++ b/fence/agents/lib/fencing.py.py	2017-10-16 14:09:05.576468918 +0200
4822a5
@@ -938,7 +938,7 @@
4822a5
 
4822a5
 	return status
4822a5
 
4822a5
-def set_multi_power_fn(tn, options, set_power_fn, get_power_fn, retry_attempts = 1):
4822a5
+def async_set_multi_power_fn(tn, options, set_power_fn, get_power_fn, retry_attempts):
4822a5
 	plugs = options["--plugs"] if options.has_key("--plugs") else [""]
4822a5
 
4822a5
 	for _ in range(retry_attempts):
4822a5
@@ -961,6 +961,39 @@
4822a5
 				return True
4822a5
 	return False
4822a5
 
4822a5
+def sync_set_multi_power_fn(tn, options, sync_set_power_fn, retry_attempts):
4822a5
+	success = True
4822a5
+	plugs = options["--plugs"] if options.has_key("--plugs") else [""]
4822a5
+
4822a5
+	for plug in plugs:
4822a5
+		try:
4822a5
+			options["--uuid"] = str(uuid.UUID(plug))
4822a5
+		except ValueError:
4822a5
+			pass
4822a5
+		except KeyError:
4822a5
+			pass
4822a5
+
4822a5
+		options["--plug"] = plug
4822a5
+		for retry in range(retry_attempts):
4822a5
+			if sync_set_power_fn(tn, options):
4822a5
+				break
4822a5
+			if retry == retry_attempts-1:
4822a5
+				success = False
4822a5
+		time.sleep(int(options["--power-wait"]))
4822a5
+
4822a5
+	return success
4822a5
+
4822a5
+def set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn, retry_attempts=1):
4822a5
+
4822a5
+	if set_power_fn != None:
4822a5
+		if get_power_fn != None:
4822a5
+			return async_set_multi_power_fn(tn, options, set_power_fn, get_power_fn, retry_attempts)
4822a5
+	elif sync_set_power_fn != None:
4822a5
+		return sync_set_multi_power_fn(tn, options, sync_set_power_fn, retry_attempts)
4822a5
+
4822a5
+	return False
4822a5
+
4822a5
+
4822a5
 def show_docs(options, docs=None):
4822a5
 	device_opt = options["device_opt"]
4822a5
 
4822a5
@@ -986,7 +1019,7 @@
4822a5
 		print __main__.REDHAT_COPYRIGHT
4822a5
 		sys.exit(0)
4822a5
 
4822a5
-def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list=None, reboot_cycle_fn=None):
4822a5
+def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list=None, reboot_cycle_fn=None, sync_set_power_fn=None):
4822a5
 	result = 0
4822a5
 
4822a5
 	try:
4822a5
@@ -1042,12 +1075,12 @@
4822a5
 				return 0
4822a5
 
4822a5
 		if options["--action"] == "on":
4822a5
-			if set_multi_power_fn(tn, options, set_power_fn, get_power_fn, 1 + int(options["--retry-on"])):
4822a5
+			if set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn, 1 + int(options["--retry-on"])):
4822a5
 				print "Success: Powered ON"
4822a5
 			else:
4822a5
 				fail(EC_WAITING_ON)
4822a5
 		elif options["--action"] == "off":
4822a5
-			if set_multi_power_fn(tn, options, set_power_fn, get_power_fn):
4822a5
+			if set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn):
4822a5
 				print "Success: Powered OFF"
4822a5
 			else:
4822a5
 				fail(EC_WAITING_OFF)
4822a5
@@ -1065,13 +1098,13 @@
4822a5
 			else:
4822a5
 				if status != "off":
4822a5
 					options["--action"] = "off"
4822a5
-					if not set_multi_power_fn(tn, options, set_power_fn, get_power_fn):
4822a5
+					if not set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn):
4822a5
 						fail(EC_WAITING_OFF)
4822a5
 
4822a5
 				options["--action"] = "on"
4822a5
 
4822a5
 				try:
4822a5
-					power_on = set_multi_power_fn(tn, options, set_power_fn, get_power_fn, int(options["--retry-on"]))
4822a5
+					power_on = set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn, int(options["--retry-on"]))
4822a5
 				except Exception, ex:
4822a5
 					# an error occured during power ON phase in reboot
4822a5
 					# fence action was completed succesfully even in that case