From 934190f02e5a80219c09993ec403fdadd25cea3c Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Thu, 13 Sep 2018 12:33:53 -0700 Subject: [PATCH] More bigip software fixes Fixes problems related to token timeout. Adds cleanup of tokens. (cherry picked from commit 604b95aab29b3bee8e49f8f7488e10ba0f59134b) --- .../modules/network/f5/bigip_software_image.py | 4 ++-- .../network/f5/bigip_software_install.py | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigip_software_image.py b/lib/ansible/modules/network/f5/bigip_software_image.py index 9d10098296..765b6637fa 100644 --- a/lib/ansible/modules/network/f5/bigip_software_image.py +++ b/lib/ansible/modules/network/f5/bigip_software_image.py @@ -116,7 +116,6 @@ try: from library.module_utils.network.f5.common import F5ModuleError from library.module_utils.network.f5.common import AnsibleF5Parameters from library.module_utils.network.f5.common import cleanup_tokens - from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json @@ -126,7 +125,6 @@ except ImportError: from ansible.module_utils.network.f5.common import F5ModuleError from ansible.module_utils.network.f5.common import AnsibleF5Parameters from ansible.module_utils.network.f5.common import cleanup_tokens - from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.common import exit_json from ansible.module_utils.network.f5.common import fail_json @@ -473,8 +471,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_software_install.py b/lib/ansible/modules/network/f5/bigip_software_install.py index f8fdba4a0d..0db888d022 100644 --- a/lib/ansible/modules/network/f5/bigip_software_install.py +++ b/lib/ansible/modules/network/f5/bigip_software_install.py @@ -71,26 +71,23 @@ RETURN = r''' ''' import time +import ssl from ansible.module_utils.basic import AnsibleModule try: - from library.module_utils.network.f5.bigip import HAS_F5SDK from library.module_utils.network.f5.bigip import F5RestClient from library.module_utils.network.f5.common import F5ModuleError from library.module_utils.network.f5.common import AnsibleF5Parameters from library.module_utils.network.f5.common import cleanup_tokens - from library.module_utils.network.f5.common import fq_name from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json except ImportError: - from ansible.module_utils.network.f5.bigip import HAS_F5SDK from ansible.module_utils.network.f5.bigip import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError from ansible.module_utils.network.f5.common import AnsibleF5Parameters from ansible.module_utils.network.f5.common import cleanup_tokens - from ansible.module_utils.network.f5.common import fq_name from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.common import exit_json from ansible.module_utils.network.f5.common import fail_json @@ -416,6 +413,8 @@ class ModuleManager(object): try: self.client.reconnect() volume = self.read_volume_from_device() + if volume is None: + continue if 'active' in volume and volume['active'] is True: break except F5ModuleError: @@ -437,6 +436,9 @@ class ModuleManager(object): while True: time.sleep(10) volume = self.read_volume_from_device() + if volume is None or 'status' not in volume: + self.client.reconnect() + continue if volume['status'] == 'complete': break elif volume['status'] == 'failed': @@ -448,11 +450,15 @@ class ModuleManager(object): self.client.provider['server_port'], self.want.volume ) - resp = self.client.api.get(uri) try: + resp = self.client.api.get(uri) response = resp.json() except ValueError as ex: raise F5ModuleError(str(ex)) + except ssl.SSLError: + # Suggests BIG-IP is still in the middle of restarting itself or + # restjavad is restarting. + return None if 'code' in response and response['code'] == 400: if 'message' in response: @@ -490,8 +496,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client)