From c161ffef810942714f3dabab83f581df9a8ba495 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Fri, 9 Nov 2018 21:56:26 -0800 Subject: [PATCH] Fixes unit tests for bigip_device_auth that were broken in 2.8 (#48459) --- .../modules/network/f5/bigip_device_auth.py | 3 ++- .../network/f5/test_bigip_device_auth.py | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigip_device_auth.py b/lib/ansible/modules/network/f5/bigip_device_auth.py index 1ca31d75972..18da90a787d 100644 --- a/lib/ansible/modules/network/f5/bigip_device_auth.py +++ b/lib/ansible/modules/network/f5/bigip_device_auth.py @@ -790,8 +790,9 @@ def main(): supports_check_mode=spec.supports_check_mode, ) + client = F5RestClient(**module.params) + try: - client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() cleanup_tokens(client) diff --git a/test/units/modules/network/f5/test_bigip_device_auth.py b/test/units/modules/network/f5/test_bigip_device_auth.py index 6dbcef8d401..b470c788b92 100644 --- a/test/units/modules/network/f5/test_bigip_device_auth.py +++ b/test/units/modules/network/f5/test_bigip_device_auth.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: @@ -26,8 +22,13 @@ try: from library.modules.bigip_device_auth import TacacsManager from library.modules.bigip_device_auth import ModuleManager from library.modules.bigip_device_auth import ArgumentSpec - from library.module_utils.network.f5.common import F5ModuleError - 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_sys_auth import TacacsApiParameters @@ -35,7 +36,12 @@ except ImportError: from ansible.modules.network.f5.bigip_sys_auth import TacacsManager from ansible.modules.network.f5.bigip_sys_auth import ModuleManager from ansible.modules.network.f5.bigip_sys_auth import ArgumentSpec - from ansible.module_utils.network.f5.common import F5ModuleError + + # 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")