From 929a1df91d3c189335daff40a7aca1461b11a62d Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Fri, 1 Dec 2017 19:57:02 -0800 Subject: [PATCH] Adds fixes to various bigip tests (#33471) upstream changes broke downstream code. this rectifies that --- .../f5/test_bigip_configsync_action.py | 6 ++++-- .../f5/test_bigip_device_connectivity.py | 19 +++++++++++-------- .../network/f5/test_bigip_device_dns.py | 6 ++++-- .../network/f5/test_bigip_device_trust.py | 6 ++++-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/test/units/modules/network/f5/test_bigip_configsync_action.py b/test/units/modules/network/f5/test_bigip_configsync_action.py index 4ffc8cd6ea4..4a79b9c8c10 100644 --- a/test/units/modules/network/f5/test_bigip_configsync_action.py +++ b/test/units/modules/network/f5/test_bigip_configsync_action.py @@ -15,21 +15,23 @@ if sys.version_info < (2, 7): raise SkipTest("F5 Ansible modules require Python >= 2.7") from ansible.compat.tests import unittest -from ansible.compat.tests.mock import patch, Mock +from ansible.compat.tests.mock import Mock +from ansible.compat.tests.mock import patch from ansible.module_utils.f5_utils import AnsibleF5Client -from units.modules.utils import set_module_args try: from library.bigip_configsync_actions import Parameters from library.bigip_configsync_actions import ModuleManager from library.bigip_configsync_actions import ArgumentSpec from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError + from test.unit.modules.utils import set_module_args except ImportError: try: from ansible.modules.network.f5.bigip_configsync_actions import Parameters from ansible.modules.network.f5.bigip_configsync_actions import ModuleManager from ansible.modules.network.f5.bigip_configsync_actions import ArgumentSpec from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError + from units.modules.utils import set_module_args except ImportError: raise SkipTest("F5 Ansible modules require the f5-sdk Python library") diff --git a/test/units/modules/network/f5/test_bigip_device_connectivity.py b/test/units/modules/network/f5/test_bigip_device_connectivity.py index 55271070046..13e28ec1523 100644 --- a/test/units/modules/network/f5/test_bigip_device_connectivity.py +++ b/test/units/modules/network/f5/test_bigip_device_connectivity.py @@ -16,9 +16,8 @@ if sys.version_info < (2, 7): raise SkipTest("F5 Ansible modules require Python >= 2.7") from ansible.compat.tests import unittest -from ansible.compat.tests.mock import patch, Mock -from ansible.module_utils import basic -from ansible.module_utils._text import to_bytes +from ansible.compat.tests.mock import Mock +from ansible.compat.tests.mock import patch from ansible.module_utils.f5_utils import AnsibleF5Client from ansible.module_utils.f5_utils import F5ModuleError @@ -27,12 +26,14 @@ try: from library.bigip_device_connectivity import ModuleManager from library.bigip_device_connectivity import ArgumentSpec from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError + from test.unit.modules.utils import set_module_args except ImportError: try: from ansible.modules.network.f5.bigip_device_connectivity import Parameters from ansible.modules.network.f5.bigip_device_connectivity import ModuleManager from ansible.modules.network.f5.bigip_device_connectivity import ArgumentSpec from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError + from units.modules.utils import set_module_args except ImportError: raise SkipTest("F5 Ansible modules require the f5-sdk Python library") @@ -40,19 +41,21 @@ fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') fixture_data = {} -def set_module_args(args): - args = json.dumps({'ANSIBLE_MODULE_ARGS': args}) - basic._ANSIBLE_ARGS = to_bytes(args) - - def load_fixture(name): path = os.path.join(fixture_path, name) + + if path in fixture_data: + return fixture_data[path] + with open(path) as f: data = f.read() + try: data = json.loads(data) except Exception: pass + + fixture_data[path] = data return data diff --git a/test/units/modules/network/f5/test_bigip_device_dns.py b/test/units/modules/network/f5/test_bigip_device_dns.py index 4cc44223a73..97f32cc822c 100644 --- a/test/units/modules/network/f5/test_bigip_device_dns.py +++ b/test/units/modules/network/f5/test_bigip_device_dns.py @@ -16,22 +16,24 @@ if sys.version_info < (2, 7): raise SkipTest("F5 Ansible modules require Python >= 2.7") from ansible.compat.tests import unittest -from ansible.compat.tests.mock import patch, Mock +from ansible.compat.tests.mock import Mock +from ansible.compat.tests.mock import patch from ansible.module_utils.f5_utils import AnsibleF5Client from ansible.module_utils.f5_utils import F5ModuleError -from units.modules.utils import set_module_args try: from library.bigip_device_dns import Parameters from library.bigip_device_dns import ModuleManager from library.bigip_device_dns import ArgumentSpec from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError + from test.unit.modules.utils import set_module_args except ImportError: try: from ansible.modules.network.f5.bigip_device_dns import Parameters from ansible.modules.network.f5.bigip_device_dns import ModuleManager from ansible.modules.network.f5.bigip_device_dns import ArgumentSpec from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError + from units.modules.utils import set_module_args except ImportError: raise SkipTest("F5 Ansible modules require the f5-sdk Python library") diff --git a/test/units/modules/network/f5/test_bigip_device_trust.py b/test/units/modules/network/f5/test_bigip_device_trust.py index b440753051f..678e3531cdc 100644 --- a/test/units/modules/network/f5/test_bigip_device_trust.py +++ b/test/units/modules/network/f5/test_bigip_device_trust.py @@ -15,9 +15,9 @@ if sys.version_info < (2, 7): raise SkipTest("F5 Ansible modules require Python >= 2.7") from ansible.compat.tests import unittest -from ansible.compat.tests.mock import patch, Mock +from ansible.compat.tests.mock import Mock +from ansible.compat.tests.mock import patch from ansible.module_utils.f5_utils import AnsibleF5Client -from units.modules.utils import set_module_args try: from library.bigip_device_trust import Parameters @@ -26,6 +26,7 @@ try: from library.bigip_device_trust import HAS_F5SDK from library.bigip_device_trust import HAS_NETADDR from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError + from test.unit.modules.utils import set_module_args except ImportError: try: from ansible.modules.network.f5.bigip_device_trust import Parameters @@ -34,6 +35,7 @@ except ImportError: from ansible.modules.network.f5.bigip_device_trust import HAS_F5SDK from ansible.modules.network.f5.bigip_device_trust import HAS_NETADDR from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError + from units.modules.utils import set_module_args except ImportError: raise SkipTest("F5 Ansible modules require the f5-sdk Python library")