Blame SOURCES/bz1476401-2-enhance-run_delay.patch

035a21
--- a/fence/agents/lib/fencing.py.py	2017-09-28 13:45:20.920463487 +0200
035a21
+++ b/fence/agents/lib/fencing.py.py	2017-09-28 13:47:56.844961761 +0200
035a21
@@ -1075,6 +1075,9 @@
035a21
 					# fence action was completed succesfully even in that case
035a21
 					logging.warning("%s", str(ex))
035a21
 
035a21
+				# switch back to original action for the case it is used lateron
035a21
+				options["--action"] = "reboot"
035a21
+
035a21
 			if power_on == False:
035a21
 				# this should not fail as node was fenced succesfully
035a21
 				logging.error('Timed out waiting to power ON\n')
035a21
@@ -1278,11 +1281,21 @@
035a21
 
035a21
 	return (status, pipe_stdout, pipe_stderr)
035a21
 
035a21
-def run_delay(options):
035a21
-	## Delay is important for two-node clusters fencing but we do not need to delay 'status' operations
035a21
-	if options["--action"] in ["off", "reboot"]:
035a21
-		logging.info("Delay %s second(s) before logging in to the fence device", options["--delay"])
035a21
-		time.sleep(int(options["--delay"]))
035a21
+def run_delay(options, reserve=0, result=0):
035a21
+	## Delay is important for two-node clusters fencing
035a21
+	## but we do not need to delay 'status' operations
035a21
+	## and get us out quickly if we already know that we are gonna fail
035a21
+	## still wanna do something right before fencing? - reserve some time
035a21
+	if options["--action"] in ["off", "reboot"] \
035a21
+		and options["--delay"] != "0" \
035a21
+		and result == 0 \
035a21
+		and reserve >= 0:
035a21
+		time_left = 1 + int(options["--delay"]) - (time.time() - run_delay.time_start) - reserve
035a21
+		if time_left > 0:
035a21
+			logging.info("Delay %d second(s) before logging in to the fence device", time_left)
035a21
+			time.sleep(time_left)
035a21
+# mark time when fence-agent is started
035a21
+run_delay.time_start = time.time()
035a21
 
035a21
 def fence_logout(conn, logout_string, sleep=0):
035a21
 	# Logout is not required part of fencing but we should attempt to do it properly