Blame SOURCES/bz1111599-1-fence_cisco_and_soap_logout.patch

3340af
commit 91399dd3e884c50e2317ab738eea1569faa8d55a
3340af
Author: Marek 'marx' Grac <mgrac@redhat.com>
3340af
Date:   Mon Sep 8 15:10:05 2014 +0200
3340af
3340af
    fence_cisco_ucs & fence_vmware_soap: Logout has to be performed even when fencing fails
3340af
    
3340af
    Previously, logout was not performed in the case when fence agent was aborted e.g. timeout. What could
3340af
    lead to a situation when connections were not closed correctly. In the extreme case, it was not possible
3340af
    to log into device at all
3340af
    
3340af
    Resolves: rhbz#1111599
3340af
3340af
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py
3340af
index 888d689..f411433 100644
3340af
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
3340af
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
3340af
@@ -19,6 +19,8 @@ RE_STATUS = re.compile("
3340af
 RE_GET_DN = re.compile(" dn=\"(.*?)\"", re.IGNORECASE)
3340af
 RE_GET_DESC = re.compile(" descr=\"(.*?)\"", re.IGNORECASE)
3340af
 
3340af
+options_global = None
3340af
+
3340af
 def get_power_status(conn, options):
3340af
 	del conn
3340af
 
3340af
@@ -115,27 +117,37 @@ def define_new_opts():
3340af
 		"default" : "",
3340af
 		"order" : 1}
3340af
 
3340af
+def logout():
3340af
+	### Logout; we do not care about result as we will end in any case
3340af
+	try:
3340af
+		send_command(options_global, "<aaaLogout inCookie=\"" + options_global["cookie"] + "\" />",
3340af
+				int(options_global["--shell-timeout"]))
3340af
+	except Exception:
3340af
+		pass
3340af
+
3340af
 def main():
3340af
+	global options_global
3340af
 	device_opt = ["ipaddr", "login", "passwd", "ssl", "notls", "port", "web", "suborg"]
3340af
 
3340af
 	atexit.register(atexit_handler)
3340af
+	atexit.register(logout)
3340af
 
3340af
 	define_new_opts()
3340af
 
3340af
-	options = check_input(device_opt, process_input(device_opt))
3340af
+	options_global = check_input(device_opt, process_input(device_opt))
3340af
 
3340af
 	docs = {}
3340af
 	docs["shortdesc"] = "Fence agent for Cisco UCS"
3340af
 	docs["longdesc"] = "fence_cisco_ucs is an I/O Fencing agent which can be \
3340af
 used with Cisco UCS to fence machines."
3340af
 	docs["vendorurl"] = "http://www.cisco.com"
3340af
-	show_docs(options, docs)
3340af
+	show_docs(options_global, docs)
3340af
 
3340af
-	run_delay(options)
3340af
+	run_delay(options_global)
3340af
 	### Login
3340af
 	try:
3340af
-		res = send_command(options, "
3340af
-				"\" inPassword=\"" + options["--password"] + "\" />", int(options["--login-timeout"]))
3340af
+		res = send_command(options_global, "
3340af
+				"\" inPassword=\"" + options_global["--password"] + "\" />", int(options_global["--login-timeout"]))
3340af
 		result = RE_COOKIE.search(res)
3340af
 		if result == None:
3340af
 			## Cookie is absenting in response
3340af
@@ -143,22 +155,19 @@ used with Cisco UCS to fence machines."
3340af
 	except Exception:
3340af
 		fail(EC_LOGIN_DENIED)
3340af
 
3340af
-	options["cookie"] = result.group(1)
3340af
+	options_global["cookie"] = result.group(1)
3340af
 
3340af
 	##
3340af
 	## Modify suborg to format /suborg
3340af
-	if options["--suborg"] != "":
3340af
-		options["--suborg"] = "/" + options["--suborg"].lstrip("/").rstrip("/")
3340af
+	if options_global["--suborg"] != "":
3340af
+		options_global["--suborg"] = "/" + options_global["--suborg"].lstrip("/").rstrip("/")
3340af
 
3340af
 	##
3340af
 	## Fence operations
3340af
 	####
3340af
-	result = fence_action(None, options, set_power_status, get_power_status, get_list)
3340af
-
3340af
-	### Logout; we do not care about result as we will end in any case
3340af
-	send_command(options, "<aaaLogout inCookie=\"" + options["cookie"] + "\" />",
3340af
-			int(options["--shell-timeout"]))
3340af
+	result = fence_action(None, options_global, set_power_status, get_power_status, get_list)
3340af
 
3340af
+	## Logout is done every time at atexit phase
3340af
 	sys.exit(result)
3340af
 
3340af
 if __name__ == "__main__":
3340af
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py
3340af
index 3217c6b..2cea105 100644
3340af
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
3340af
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
3340af
@@ -20,6 +20,9 @@ REDHAT_COPYRIGHT=""
3340af
 BUILD_DATE="April, 2011"
3340af
 #END_VERSION_GENERATION
3340af
 
3340af
+options_global = None
3340af
+conn_global = None
3340af
+
3340af
 class RequestsTransport(HttpAuthenticated):
3340af
 	def __init__(self, **kwargs):
3340af
 		self.cert = kwargs.pop('cert', None)
3340af
@@ -203,12 +206,21 @@ def set_power_status(conn, options):
3340af
 def remove_tmp_dir(tmp_dir):
3340af
 	shutil.rmtree(tmp_dir)
3340af
 
3340af
+def logout():
3340af
+	try:
3340af
+		conn_global.service.Logout(options_global["mo_SessionManager"])
3340af
+	except Exception:
3340af
+		pass
3340af
+
3340af
 def main():
3340af
+	global options_global
3340af
+	global conn_global
3340af
 	device_opt = ["ipaddr", "login", "passwd", "web", "ssl", "notls", "port"]
3340af
 
3340af
 	atexit.register(atexit_handler)
3340af
+	atexit.register(logout)
3340af
 
3340af
-	options = check_input(device_opt, process_input(device_opt))
3340af
+	options_global = check_input(device_opt, process_input(device_opt))
3340af
 
3340af
 	##
3340af
 	## Fence agent specific defaults
3340af
@@ -224,7 +236,7 @@ format (e.g. /datacenter/vm/Discovered virtual machine/myMachine). \
3340af
 In the cases when name of yours VM is unique you can use it instead. \
3340af
 Alternatively you can always use UUID to access virtual machine."
3340af
 	docs["vendorurl"] = "http://www.vmware.com"
3340af
-	show_docs(options, docs)
3340af
+	show_docs(options_global, docs)
3340af
 
3340af
 	logging.basicConfig(level=logging.INFO)
3340af
 	logging.getLogger('suds.client').setLevel(logging.CRITICAL)
3340af
@@ -234,18 +246,11 @@ Alternatively you can always use UUID to access virtual machine."
3340af
 	##
3340af
 	## Operate the fencing device
3340af
 	####
3340af
-	conn = soap_login(options)
3340af
-
3340af
-	result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
3340af
+	conn_global = soap_login(options_global)
3340af
 
3340af
-	##
3340af
-	## Logout from system
3340af
-	#####
3340af
-	try:
3340af
-		conn.service.Logout(options["mo_SessionManager"])
3340af
-	except Exception:
3340af
-		pass
3340af
+	result = fence_action(conn_global, options_global, set_power_status, get_power_status, get_power_status)
3340af
 
3340af
+	## Logout from system is done automatically via atexit()
3340af
 	sys.exit(result)
3340af
 
3340af
 if __name__ == "__main__":