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