From b4af058c555b52ab6e4fcab41400f16c31468d48 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Fri, 2 Nov 2018 12:14:30 -0700 Subject: [PATCH] Fixes unit tests and token cleanup (#48005) The unit tests in 2.8 were broken. this fixes them and adds a token cleanup to the bigip_tunnel module --- .../modules/network/f5/bigip_tunnel.py | 2 ++ .../modules/network/f5/test_bigip_tunnel.py | 22 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigip_tunnel.py b/lib/ansible/modules/network/f5/bigip_tunnel.py index 4433ef82b4..c4fd87f435 100644 --- a/lib/ansible/modules/network/f5/bigip_tunnel.py +++ b/lib/ansible/modules/network/f5/bigip_tunnel.py @@ -603,8 +603,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/test/units/modules/network/f5/test_bigip_tunnel.py b/test/units/modules/network/f5/test_bigip_tunnel.py index cb6facc277..7eeefde3f0 100644 --- a/test/units/modules/network/f5/test_bigip_tunnel.py +++ b/test/units/modules/network/f5/test_bigip_tunnel.py @@ -8,16 +8,12 @@ __metaclass__ = type import os import json -import pytest import sys from nose.plugins.skip import SkipTest if sys.version_info < (2, 7): raise SkipTest("F5 Ansible modules require Python >= 2.7") -from units.compat import unittest -from units.compat.mock import Mock -from units.compat.mock import patch from ansible.module_utils.basic import AnsibleModule try: @@ -25,17 +21,25 @@ try: from library.modules.bigip_tunnel import ModuleParameters from library.modules.bigip_tunnel import ModuleManager from library.modules.bigip_tunnel import ArgumentSpec - from library.module_utils.network.f5.common import F5ModuleError - from library.module_utils.network.f5.common import iControlUnexpectedHTTPError - from test.unit.modules.utils import set_module_args + + # In Ansible 2.8, Ansible changed import paths. + from test.units.compat import unittest + from test.units.compat.mock import Mock + from test.units.compat.mock import patch + + from test.units.modules.utils import set_module_args except ImportError: try: from ansible.modules.network.f5.bigip_tunnel import ApiParameters from ansible.modules.network.f5.bigip_tunnel import ModuleParameters from ansible.modules.network.f5.bigip_tunnel import ModuleManager from ansible.modules.network.f5.bigip_tunnel import ArgumentSpec - from ansible.module_utils.network.f5.common import F5ModuleError - from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError + + # Ansible 2.8 imports + from units.compat import unittest + from units.compat.mock import Mock + from units.compat.mock import patch + from units.modules.utils import set_module_args except ImportError: raise SkipTest("F5 Ansible modules require the f5-sdk Python library")