summaryrefslogtreecommitdiff
path: root/test/units/modules/network
diff options
context:
space:
mode:
Diffstat (limited to 'test/units/modules/network')
-rw-r--r--test/units/modules/network/aireos/aireos_module.py39
-rw-r--r--test/units/modules/network/aireos/test_aireos_command.py5
-rw-r--r--test/units/modules/network/aireos/test_aireos_config.py8
-rw-r--r--test/units/modules/network/aruba/aruba_module.py38
-rw-r--r--test/units/modules/network/aruba/test_aruba_command.py7
-rw-r--r--test/units/modules/network/aruba/test_aruba_config.py9
-rw-r--r--test/units/modules/network/enos/enos_module.py38
-rw-r--r--test/units/modules/network/enos/test_enos_command.py5
-rw-r--r--test/units/modules/network/enos/test_enos_facts.py5
-rw-r--r--test/units/modules/network/eos/eos_module.py38
-rw-r--r--test/units/modules/network/eos/test_eos_banner.py9
-rw-r--r--test/units/modules/network/eos/test_eos_command.py5
-rw-r--r--test/units/modules/network/eos/test_eos_config.py7
-rw-r--r--test/units/modules/network/eos/test_eos_eapi.py9
-rw-r--r--test/units/modules/network/eos/test_eos_system.py9
-rw-r--r--test/units/modules/network/eos/test_eos_user.py9
-rw-r--r--test/units/modules/network/f5/test_bigip_asm_policy.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_command.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_config.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_configsync_action.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_configsync_actions.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_device_dns.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_device_trust.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_gtm_facts.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_gtm_pool.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_gtm_wide_ip.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_hostname.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_iapp_service.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_iapp_template.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_iapplx_package.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_irule.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_monitor_http.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_monitor_https.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_monitor_tcp.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_monitor_tcp_echo.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_monitor_tcp_half_open.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_partition.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_policy.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_pool.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_provision.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_qkview.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_remote_syslog.py6
-rw-r--r--test/units/modules/network/f5/test_bigip_selfip.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_snmp.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_snmp_trap.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_ssl_certificate.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_ssl_key.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_ucs.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_user.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_virtual_address.py8
-rw-r--r--test/units/modules/network/f5/test_bigip_wait.py8
-rw-r--r--test/units/modules/network/ios/ios_module.py38
-rw-r--r--test/units/modules/network/ios/test_ios_banner.py8
-rw-r--r--test/units/modules/network/ios/test_ios_command.py6
-rw-r--r--test/units/modules/network/ios/test_ios_config.py8
-rw-r--r--test/units/modules/network/ios/test_ios_logging.py7
-rw-r--r--test/units/modules/network/ios/test_ios_ping.py5
-rw-r--r--test/units/modules/network/ios/test_ios_system.py8
-rw-r--r--test/units/modules/network/ios/test_ios_user.py6
-rw-r--r--test/units/modules/network/ios/test_ios_vrf.py8
-rw-r--r--test/units/modules/network/iosxr/iosxr_module.py38
-rw-r--r--test/units/modules/network/iosxr/test_iosxr_command.py9
-rw-r--r--test/units/modules/network/iosxr/test_iosxr_config.py9
-rw-r--r--test/units/modules/network/iosxr/test_iosxr_facts.py7
-rw-r--r--test/units/modules/network/iosxr/test_iosxr_netconf.py6
-rw-r--r--test/units/modules/network/iosxr/test_iosxr_system.py9
-rw-r--r--test/units/modules/network/iosxr/test_iosxr_user.py9
-rw-r--r--test/units/modules/network/ironware/ironware_module.py37
-rw-r--r--test/units/modules/network/ironware/test_ironware_command.py7
-rw-r--r--test/units/modules/network/ironware/test_ironware_config.py6
-rw-r--r--test/units/modules/network/ironware/test_ironware_facts.py5
-rw-r--r--test/units/modules/network/junos/junos_module.py38
-rw-r--r--test/units/modules/network/junos/test_junos_command.py7
-rw-r--r--test/units/modules/network/junos/test_junos_config.py6
-rw-r--r--test/units/modules/network/junos/test_junos_facts.py6
-rw-r--r--test/units/modules/network/junos/test_junos_netconf.py6
-rw-r--r--test/units/modules/network/junos/test_junos_package.py7
-rw-r--r--test/units/modules/network/junos/test_junos_rpc.py5
-rw-r--r--test/units/modules/network/netscaler/netscaler_module.py37
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_cs_action.py7
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_cs_policy.py7
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_cs_vserver.py7
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_gslb_service.py7
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_gslb_site.py7
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_gslb_vserver.py7
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_lb_monitor.py7
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_lb_vserver.py6
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_save_config.py5
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_server.py5
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_service.py5
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_servicegroup.py5
-rw-r--r--test/units/modules/network/netscaler/test_netscaler_ssl_certkey.py5
-rw-r--r--test/units/modules/network/nso/nso_module.py39
-rw-r--r--test/units/modules/network/nso/test_nso_config.py9
-rw-r--r--test/units/modules/network/nuage/nuage_module.py56
-rw-r--r--test/units/modules/network/nuage/test_nuage_vspk.py123
-rw-r--r--test/units/modules/network/nxos/nxos_module.py38
-rw-r--r--test/units/modules/network/nxos/test_nxos_acl.py3
-rw-r--r--test/units/modules/network/nxos/test_nxos_acl_interface.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_banner.py6
-rw-r--r--test/units/modules/network/nxos/test_nxos_bgp.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_bgp_af.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_bgp_neighbor.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_command.py3
-rw-r--r--test/units/modules/network/nxos/test_nxos_config.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_evpn_global.py3
-rw-r--r--test/units/modules/network/nxos/test_nxos_evpn_vni.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_feature.py2
-rw-r--r--test/units/modules/network/nxos/test_nxos_hsrp.py6
-rw-r--r--test/units/modules/network/nxos/test_nxos_interface.py4
-rw-r--r--test/units/modules/network/nxos/test_nxos_interface_ospf.py3
-rw-r--r--test/units/modules/network/nxos/test_nxos_ip_interface.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_nxapi.py6
-rw-r--r--test/units/modules/network/nxos/test_nxos_ospf.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_ospf_vrf.py7
-rw-r--r--test/units/modules/network/nxos/test_nxos_overlay_global.py4
-rw-r--r--test/units/modules/network/nxos/test_nxos_pim.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_pim_interface.py3
-rw-r--r--test/units/modules/network/nxos/test_nxos_pim_rp_address.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_portchannel.py7
-rw-r--r--test/units/modules/network/nxos/test_nxos_static_route.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_switchport.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_system.py4
-rw-r--r--test/units/modules/network/nxos/test_nxos_vlan.py3
-rw-r--r--test/units/modules/network/nxos/test_nxos_vpc.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_vpc_interface.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_vrf.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_vrf_af.py7
-rw-r--r--test/units/modules/network/nxos/test_nxos_vxlan_vtep.py5
-rw-r--r--test/units/modules/network/nxos/test_nxos_vxlan_vtep_vni.py5
-rw-r--r--test/units/modules/network/ovs/ovs_module.py38
-rw-r--r--test/units/modules/network/ovs/test_openvswitch_bridge.py9
-rw-r--r--test/units/modules/network/ovs/test_openvswitch_db.py9
-rw-r--r--test/units/modules/network/ovs/test_openvswitch_port.py9
-rw-r--r--test/units/modules/network/vyos/test_vyos_banner.py8
-rw-r--r--test/units/modules/network/vyos/test_vyos_command.py5
-rw-r--r--test/units/modules/network/vyos/test_vyos_config.py9
-rw-r--r--test/units/modules/network/vyos/test_vyos_facts.py5
-rw-r--r--test/units/modules/network/vyos/test_vyos_static_route.py7
-rw-r--r--test/units/modules/network/vyos/test_vyos_system.py9
-rw-r--r--test/units/modules/network/vyos/test_vyos_user.py8
-rw-r--r--test/units/modules/network/vyos/vyos_module.py38
143 files changed, 595 insertions, 931 deletions
diff --git a/test/units/modules/network/aireos/aireos_module.py b/test/units/modules/network/aireos/aireos_module.py
index 3483447a6d..5fc6c93578 100644
--- a/test/units/modules/network/aireos/aireos_module.py
+++ b/test/units/modules/network/aireos/aireos_module.py
@@ -22,15 +22,7 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
-
-
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +46,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestCiscoWlcModule(unittest.TestCase):
+class TestCiscoWlcModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
@@ -84,27 +68,16 @@ class TestCiscoWlcModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/aireos/test_aireos_command.py b/test/units/modules/network/aireos/test_aireos_command.py
index e4403c171e..14d7f58e5a 100644
--- a/test/units/modules/network/aireos/test_aireos_command.py
+++ b/test/units/modules/network/aireos/test_aireos_command.py
@@ -23,7 +23,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.aireos import aireos_command
-from .aireos_module import TestCiscoWlcModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .aireos_module import TestCiscoWlcModule, load_fixture
class TestCiscoWlcCommandModule(TestCiscoWlcModule):
@@ -31,10 +32,12 @@ class TestCiscoWlcCommandModule(TestCiscoWlcModule):
module = aireos_command
def setUp(self):
+ super(TestCiscoWlcCommandModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.aireos.aireos_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestCiscoWlcCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/aireos/test_aireos_config.py b/test/units/modules/network/aireos/test_aireos_config.py
index 311d7398e3..7f15c87937 100644
--- a/test/units/modules/network/aireos/test_aireos_config.py
+++ b/test/units/modules/network/aireos/test_aireos_config.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.aireos import aireos_config
-from .aireos_module import TestCiscoWlcModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .aireos_module import TestCiscoWlcModule, load_fixture
class TestCiscoWlcConfigModule(TestCiscoWlcModule):
@@ -32,6 +31,8 @@ class TestCiscoWlcConfigModule(TestCiscoWlcModule):
module = aireos_config
def setUp(self):
+ super(TestCiscoWlcConfigModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.aireos.aireos_config.get_config')
self.get_config = self.mock_get_config.start()
@@ -42,6 +43,7 @@ class TestCiscoWlcConfigModule(TestCiscoWlcModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestCiscoWlcConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/aruba/aruba_module.py b/test/units/modules/network/aruba/aruba_module.py
index d8883e8958..d11d7d4393 100644
--- a/test/units/modules/network/aruba/aruba_module.py
+++ b/test/units/modules/network/aruba/aruba_module.py
@@ -22,16 +22,9 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +47,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestArubaModule(unittest.TestCase):
+class TestArubaModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
@@ -84,27 +69,16 @@ class TestArubaModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/aruba/test_aruba_command.py b/test/units/modules/network/aruba/test_aruba_command.py
index ca268f59b9..3d31aa426a 100644
--- a/test/units/modules/network/aruba/test_aruba_command.py
+++ b/test/units/modules/network/aruba/test_aruba_command.py
@@ -23,7 +23,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.aruba import aruba_command
-from .aruba_module import TestArubaModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .aruba_module import TestArubaModule, load_fixture
class TestArubaCommandModule(TestArubaModule):
@@ -31,10 +32,14 @@ class TestArubaCommandModule(TestArubaModule):
module = aruba_command
def setUp(self):
+ super(TestArubaCommandModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.aruba.aruba_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestArubaCommandModule, self).tearDown()
+
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/aruba/test_aruba_config.py b/test/units/modules/network/aruba/test_aruba_config.py
index 34f36881f7..7510b10398 100644
--- a/test/units/modules/network/aruba/test_aruba_config.py
+++ b/test/units/modules/network/aruba/test_aruba_config.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.aruba import aruba_config
-from .aruba_module import TestArubaModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .aruba_module import TestArubaModule, load_fixture
class TestArubaConfigModule(TestArubaModule):
@@ -32,6 +31,8 @@ class TestArubaConfigModule(TestArubaModule):
module = aruba_config
def setUp(self):
+ super(TestArubaConfigModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.aruba.aruba_config.get_config')
self.get_config = self.mock_get_config.start()
@@ -42,6 +43,8 @@ class TestArubaConfigModule(TestArubaModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestArubaConfigModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/enos/enos_module.py b/test/units/modules/network/enos/enos_module.py
index d9395f5745..5728657c61 100644
--- a/test/units/modules/network/enos/enos_module.py
+++ b/test/units/modules/network/enos/enos_module.py
@@ -22,16 +22,9 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +47,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestEnosModule(unittest.TestCase):
+class TestEnosModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
@@ -84,27 +69,16 @@ class TestEnosModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/enos/test_enos_command.py b/test/units/modules/network/enos/test_enos_command.py
index 99e7403d2b..8d9fc2c35e 100644
--- a/test/units/modules/network/enos/test_enos_command.py
+++ b/test/units/modules/network/enos/test_enos_command.py
@@ -23,7 +23,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.enos import enos_command
-from .enos_module import TestEnosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .enos_module import TestEnosModule, load_fixture
class TestEnosCommandModule(TestEnosModule):
@@ -31,10 +32,12 @@ class TestEnosCommandModule(TestEnosModule):
module = enos_command
def setUp(self):
+ super(TestEnosCommandModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.enos.enos_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestEnosCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/enos/test_enos_facts.py b/test/units/modules/network/enos/test_enos_facts.py
index 4724ab19a6..b0c4ea03c4 100644
--- a/test/units/modules/network/enos/test_enos_facts.py
+++ b/test/units/modules/network/enos/test_enos_facts.py
@@ -22,8 +22,9 @@ __metaclass__ = type
import json
from ansible.compat.tests.mock import patch
-from .enos_module import TestEnosModule, load_fixture, set_module_args
+from .enos_module import TestEnosModule, load_fixture
from ansible.modules.network.enos import enos_facts
+from units.modules.utils import set_module_args
class TestEnosFacts(TestEnosModule):
@@ -31,11 +32,13 @@ class TestEnosFacts(TestEnosModule):
module = enos_facts
def setUp(self):
+ super(TestEnosFacts, self).setUp()
self.mock_run_commands = patch(
'ansible.modules.network.enos.enos_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestEnosFacts, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/eos/eos_module.py b/test/units/modules/network/eos/eos_module.py
index 3db2d1f089..d9d5d44fa2 100644
--- a/test/units/modules/network/eos/eos_module.py
+++ b/test/units/modules/network/eos/eos_module.py
@@ -22,16 +22,9 @@ __metaclass__ = type
import json
import os
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +47,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestEosModule(unittest.TestCase):
+class TestEosModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, inputs=None, sort=True, defaults=False, transport='cli'):
@@ -98,27 +83,16 @@ class TestEosModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/eos/test_eos_banner.py b/test/units/modules/network/eos/test_eos_banner.py
index 3f501bb680..7684dc22c9 100644
--- a/test/units/modules/network/eos/test_eos_banner.py
+++ b/test/units/modules/network/eos/test_eos_banner.py
@@ -17,11 +17,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.eos import eos_banner
-from .eos_module import TestEosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .eos_module import TestEosModule, load_fixture
class TestEosBannerModule(TestEosModule):
@@ -29,6 +28,8 @@ class TestEosBannerModule(TestEosModule):
module = eos_banner
def setUp(self):
+ super(TestEosBannerModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.eos.eos_banner.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -36,6 +37,8 @@ class TestEosBannerModule(TestEosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestEosBannerModule, self).tearDown()
+
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/eos/test_eos_command.py b/test/units/modules/network/eos/test_eos_command.py
index 02865d2f7e..0734147f43 100644
--- a/test/units/modules/network/eos/test_eos_command.py
+++ b/test/units/modules/network/eos/test_eos_command.py
@@ -23,7 +23,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.eos import eos_command
-from .eos_module import TestEosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .eos_module import TestEosModule, load_fixture
class TestEosCommandModule(TestEosModule):
@@ -31,10 +32,12 @@ class TestEosCommandModule(TestEosModule):
module = eos_command
def setUp(self):
+ super(TestEosCommandModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.eos.eos_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestEosCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None, transport='cli'):
diff --git a/test/units/modules/network/eos/test_eos_config.py b/test/units/modules/network/eos/test_eos_config.py
index 54033318c2..4a244b91f2 100644
--- a/test/units/modules/network/eos/test_eos_config.py
+++ b/test/units/modules/network/eos/test_eos_config.py
@@ -19,11 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.eos import eos_config
-from .eos_module import TestEosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .eos_module import TestEosModule, load_fixture
class TestEosConfigModule(TestEosModule):
@@ -31,6 +30,7 @@ class TestEosConfigModule(TestEosModule):
module = eos_config
def setUp(self):
+ super(TestEosConfigModule, self).setUp()
self.mock_get_config = patch('ansible.modules.network.eos.eos_config.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +38,7 @@ class TestEosConfigModule(TestEosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestEosConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/eos/test_eos_eapi.py b/test/units/modules/network/eos/test_eos_eapi.py
index dfb4e83f4a..dd16ea60cc 100644
--- a/test/units/modules/network/eos/test_eos_eapi.py
+++ b/test/units/modules/network/eos/test_eos_eapi.py
@@ -19,11 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.eos import eos_eapi
-from .eos_module import TestEosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .eos_module import TestEosModule, load_fixture
class TestEosEapiModule(TestEosModule):
@@ -31,6 +30,8 @@ class TestEosEapiModule(TestEosModule):
module = eos_eapi
def setUp(self):
+ super(TestEosEapiModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.eos.eos_eapi.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -43,6 +44,8 @@ class TestEosEapiModule(TestEosModule):
self.command_fixtures = {}
def tearDown(self):
+ super(TestEosEapiModule, self).tearDown()
+
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/eos/test_eos_system.py b/test/units/modules/network/eos/test_eos_system.py
index 8cbf0335b1..f02687694a 100644
--- a/test/units/modules/network/eos/test_eos_system.py
+++ b/test/units/modules/network/eos/test_eos_system.py
@@ -19,11 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.eos import eos_system
-from .eos_module import TestEosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .eos_module import TestEosModule, load_fixture
class TestEosSystemModule(TestEosModule):
@@ -31,6 +30,8 @@ class TestEosSystemModule(TestEosModule):
module = eos_system
def setUp(self):
+ super(TestEosSystemModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.eos.eos_system.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +39,8 @@ class TestEosSystemModule(TestEosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestEosSystemModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/eos/test_eos_user.py b/test/units/modules/network/eos/test_eos_user.py
index 74cfb7bc04..ac08a2158c 100644
--- a/test/units/modules/network/eos/test_eos_user.py
+++ b/test/units/modules/network/eos/test_eos_user.py
@@ -17,11 +17,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.eos import eos_user
-from .eos_module import TestEosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .eos_module import TestEosModule, load_fixture
class TestEosUserModule(TestEosModule):
@@ -29,6 +28,8 @@ class TestEosUserModule(TestEosModule):
module = eos_user
def setUp(self):
+ super(TestEosUserModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.eos.eos_user.get_config')
self.get_config = self.mock_get_config.start()
@@ -36,6 +37,8 @@ class TestEosUserModule(TestEosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestEosUserModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/f5/test_bigip_asm_policy.py b/test/units/modules/network/f5/test_bigip_asm_policy.py
index 226eabde04..72cac746a5 100644
--- a/test/units/modules/network/f5/test_bigip_asm_policy.py
+++ b/test/units/modules/network/f5/test_bigip_asm_policy.py
@@ -17,10 +17,9 @@ if sys.version_info < (2, 7):
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, Mock, PropertyMock
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
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_asm_policy import V1Parameters
@@ -46,11 +45,6 @@ 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)
with open(path) as f:
diff --git a/test/units/modules/network/f5/test_bigip_command.py b/test/units/modules/network/f5/test_bigip_command.py
index f4ff740195..39d4c2333d 100644
--- a/test/units/modules/network/f5/test_bigip_command.py
+++ b/test/units/modules/network/f5/test_bigip_command.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_command import Parameters
@@ -38,11 +37,6 @@ 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)
with open(path) as f:
diff --git a/test/units/modules/network/f5/test_bigip_config.py b/test/units/modules/network/f5/test_bigip_config.py
index 228937d7bb..9cb02c7260 100644
--- a/test/units/modules/network/f5/test_bigip_config.py
+++ b/test/units/modules/network/f5/test_bigip_config.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_config import Parameters
@@ -38,11 +37,6 @@ 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)
with open(path) as f:
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 509eefaf8d..4ffc8cd6ea 100644
--- a/test/units/modules/network/f5/test_bigip_configsync_action.py
+++ b/test/units/modules/network/f5/test_bigip_configsync_action.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_configsync_actions import Parameters
@@ -38,11 +37,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_configsync_actions.py b/test/units/modules/network/f5/test_bigip_configsync_actions.py
index 8729b40ade..b7269f7a53 100644
--- a/test/units/modules/network/f5/test_bigip_configsync_actions.py
+++ b/test/units/modules/network/f5/test_bigip_configsync_actions.py
@@ -30,9 +30,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_configsync_actions import Parameters
@@ -50,11 +49,6 @@ 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)
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 59679c1675..4cc44223a7 100644
--- a/test/units/modules/network/f5/test_bigip_device_dns.py
+++ b/test/units/modules/network/f5/test_bigip_device_dns.py
@@ -17,10 +17,9 @@ if sys.version_info < (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.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
@@ -40,11 +39,6 @@ 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)
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 10d1139e1e..b440753051 100644
--- a/test/units/modules/network/f5/test_bigip_device_trust.py
+++ b/test/units/modules/network/f5/test_bigip_device_trust.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_device_trust import Parameters
@@ -46,11 +45,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_gtm_facts.py b/test/units/modules/network/f5/test_bigip_gtm_facts.py
index e4d2b89117..05a1c27e9d 100644
--- a/test/units/modules/network/f5/test_bigip_gtm_facts.py
+++ b/test/units/modules/network/f5/test_bigip_gtm_facts.py
@@ -16,10 +16,9 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
from ansible.module_utils.six import iteritems
+from units.modules.utils import set_module_args
try:
from library.bigip_gtm_facts import Parameters
@@ -63,11 +62,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_gtm_pool.py b/test/units/modules/network/f5/test_bigip_gtm_pool.py
index 1bfdf4aa93..be2d4bb704 100644
--- a/test/units/modules/network/f5/test_bigip_gtm_pool.py
+++ b/test/units/modules/network/f5/test_bigip_gtm_pool.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_gtm_pool import Parameters
@@ -42,11 +41,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_gtm_wide_ip.py b/test/units/modules/network/f5/test_bigip_gtm_wide_ip.py
index 46de8c03ba..908c0d12e3 100644
--- a/test/units/modules/network/f5/test_bigip_gtm_wide_ip.py
+++ b/test/units/modules/network/f5/test_bigip_gtm_wide_ip.py
@@ -17,10 +17,9 @@ if sys.version_info < (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.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_gtm_wide_ip import Parameters
@@ -44,11 +43,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_hostname.py b/test/units/modules/network/f5/test_bigip_hostname.py
index 49db8c341a..f29790c9db 100644
--- a/test/units/modules/network/f5/test_bigip_hostname.py
+++ b/test/units/modules/network/f5/test_bigip_hostname.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_hostname import Parameters
@@ -38,11 +37,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_iapp_service.py b/test/units/modules/network/f5/test_bigip_iapp_service.py
index 8f7fd425c4..592123b83e 100644
--- a/test/units/modules/network/f5/test_bigip_iapp_service.py
+++ b/test/units/modules/network/f5/test_bigip_iapp_service.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_iapp_service import Parameters
@@ -38,11 +37,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_iapp_template.py b/test/units/modules/network/f5/test_bigip_iapp_template.py
index 5378bd94f0..9d01243860 100644
--- a/test/units/modules/network/f5/test_bigip_iapp_template.py
+++ b/test/units/modules/network/f5/test_bigip_iapp_template.py
@@ -15,10 +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.module_utils import basic
from ansible.compat.tests.mock import patch, Mock
-from ansible.module_utils._text import to_bytes
from ansible.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_iapp_template import Parameters
@@ -38,11 +37,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_iapplx_package.py b/test/units/modules/network/f5/test_bigip_iapplx_package.py
index 3ddc252cf7..4d44c7b6c0 100644
--- a/test/units/modules/network/f5/test_bigip_iapplx_package.py
+++ b/test/units/modules/network/f5/test_bigip_iapplx_package.py
@@ -15,10 +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.module_utils import basic
from ansible.compat.tests.mock import patch, Mock
-from ansible.module_utils._text import to_bytes
from ansible.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_iapp_template import Parameters
@@ -38,11 +37,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_irule.py b/test/units/modules/network/f5/test_bigip_irule.py
index eb2974adb8..a6a26299b2 100644
--- a/test/units/modules/network/f5/test_bigip_irule.py
+++ b/test/units/modules/network/f5/test_bigip_irule.py
@@ -16,10 +16,9 @@ if sys.version_info < (2, 7):
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, mock_open, Mock
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
from ansible.module_utils.f5_utils import AnsibleF5Client
from ansible.module_utils.six import PY3
+from units.modules.utils import set_module_args
try:
from library.bigip_irule import Parameters
@@ -43,11 +42,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_monitor_http.py b/test/units/modules/network/f5/test_bigip_monitor_http.py
index 4ce0b28812..fc171d25ad 100644
--- a/test/units/modules/network/f5/test_bigip_monitor_http.py
+++ b/test/units/modules/network/f5/test_bigip_monitor_http.py
@@ -31,10 +31,9 @@ if sys.version_info < (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.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_monitor_http import Parameters
@@ -54,11 +53,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_monitor_https.py b/test/units/modules/network/f5/test_bigip_monitor_https.py
index 68144dae68..2b5f3bc53a 100644
--- a/test/units/modules/network/f5/test_bigip_monitor_https.py
+++ b/test/units/modules/network/f5/test_bigip_monitor_https.py
@@ -31,10 +31,9 @@ if sys.version_info < (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.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_monitor_https import Parameters
@@ -54,11 +53,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_monitor_tcp.py b/test/units/modules/network/f5/test_bigip_monitor_tcp.py
index 412f5e4736..eeac55ea56 100644
--- a/test/units/modules/network/f5/test_bigip_monitor_tcp.py
+++ b/test/units/modules/network/f5/test_bigip_monitor_tcp.py
@@ -31,10 +31,9 @@ if sys.version_info < (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.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_monitor_tcp import ParametersTcp
@@ -64,11 +63,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_monitor_tcp_echo.py b/test/units/modules/network/f5/test_bigip_monitor_tcp_echo.py
index 36baab4066..b3633c9a61 100644
--- a/test/units/modules/network/f5/test_bigip_monitor_tcp_echo.py
+++ b/test/units/modules/network/f5/test_bigip_monitor_tcp_echo.py
@@ -31,10 +31,9 @@ if sys.version_info < (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.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_monitor_tcp_echo import Parameters
@@ -53,11 +52,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_monitor_tcp_half_open.py b/test/units/modules/network/f5/test_bigip_monitor_tcp_half_open.py
index f2a4a228ac..6f67ddfdc2 100644
--- a/test/units/modules/network/f5/test_bigip_monitor_tcp_half_open.py
+++ b/test/units/modules/network/f5/test_bigip_monitor_tcp_half_open.py
@@ -31,10 +31,9 @@ if sys.version_info < (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.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_monitor_tcp_half_open import Parameters
@@ -53,11 +52,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_partition.py b/test/units/modules/network/f5/test_bigip_partition.py
index cd2ea1b019..23e9c8f0e8 100644
--- a/test/units/modules/network/f5/test_bigip_partition.py
+++ b/test/units/modules/network/f5/test_bigip_partition.py
@@ -30,9 +30,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_partition import Parameters
@@ -52,11 +51,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_policy.py b/test/units/modules/network/f5/test_bigip_policy.py
index 88b323a9c2..5f769ad4d5 100644
--- a/test/units/modules/network/f5/test_bigip_policy.py
+++ b/test/units/modules/network/f5/test_bigip_policy.py
@@ -30,9 +30,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_policy import Parameters
@@ -56,11 +55,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_pool.py b/test/units/modules/network/f5/test_bigip_pool.py
index a6b4277ba6..c34959127b 100644
--- a/test/units/modules/network/f5/test_bigip_pool.py
+++ b/test/units/modules/network/f5/test_bigip_pool.py
@@ -17,10 +17,9 @@ if sys.version_info < (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.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_pool import Parameters
@@ -40,11 +39,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_provision.py b/test/units/modules/network/f5/test_bigip_provision.py
index 35dba41099..9b575638b8 100644
--- a/test/units/modules/network/f5/test_bigip_provision.py
+++ b/test/units/modules/network/f5/test_bigip_provision.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_provision import Parameters
@@ -38,11 +37,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_qkview.py b/test/units/modules/network/f5/test_bigip_qkview.py
index 9a7830aa53..55cd5e06a8 100644
--- a/test/units/modules/network/f5/test_bigip_qkview.py
+++ b/test/units/modules/network/f5/test_bigip_qkview.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_qkview import Parameters
@@ -42,11 +41,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_remote_syslog.py b/test/units/modules/network/f5/test_bigip_remote_syslog.py
index f78c099fc0..51c0c894e1 100644
--- a/test/units/modules/network/f5/test_bigip_remote_syslog.py
+++ b/test/units/modules/network/f5/test_bigip_remote_syslog.py
@@ -19,6 +19,7 @@ from ansible.compat.tests.mock import patch, Mock
from ansible.module_utils import basic
from ansible.module_utils._text import to_bytes
from ansible.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_remote_syslog import Parameters
@@ -46,11 +47,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_selfip.py b/test/units/modules/network/f5/test_bigip_selfip.py
index 48266745e0..eb57109c84 100644
--- a/test/units/modules/network/f5/test_bigip_selfip.py
+++ b/test/units/modules/network/f5/test_bigip_selfip.py
@@ -31,10 +31,9 @@ if sys.version_info < (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.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_selfip import Parameters
@@ -56,11 +55,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_snmp.py b/test/units/modules/network/f5/test_bigip_snmp.py
index 7c86f7d62c..05fdda8a50 100644
--- a/test/units/modules/network/f5/test_bigip_snmp.py
+++ b/test/units/modules/network/f5/test_bigip_snmp.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_snmp import Parameters
@@ -38,11 +37,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_snmp_trap.py b/test/units/modules/network/f5/test_bigip_snmp_trap.py
index 1251718471..9b7a011ac2 100644
--- a/test/units/modules/network/f5/test_bigip_snmp_trap.py
+++ b/test/units/modules/network/f5/test_bigip_snmp_trap.py
@@ -16,9 +16,8 @@ if sys.version_info < (2, 7):
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, DEFAULT, Mock
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
from ansible.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_snmp_trap import NetworkedParameters
@@ -44,11 +43,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_ssl_certificate.py b/test/units/modules/network/f5/test_bigip_ssl_certificate.py
index 2eb33d9ea6..bdacfa2c99 100644
--- a/test/units/modules/network/f5/test_bigip_ssl_certificate.py
+++ b/test/units/modules/network/f5/test_bigip_ssl_certificate.py
@@ -15,10 +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.module_utils import basic
from ansible.compat.tests.mock import patch, Mock
-from ansible.module_utils._text import to_bytes
from ansible.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_ssl_certificate import ArgumentSpec
@@ -44,11 +43,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_ssl_key.py b/test/units/modules/network/f5/test_bigip_ssl_key.py
index 477ca11e37..ee575868a3 100644
--- a/test/units/modules/network/f5/test_bigip_ssl_key.py
+++ b/test/units/modules/network/f5/test_bigip_ssl_key.py
@@ -15,10 +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.module_utils import basic
from ansible.compat.tests.mock import patch, Mock
-from ansible.module_utils._text import to_bytes
from ansible.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_ssl_key import ArgumentSpec
@@ -40,11 +39,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_ucs.py b/test/units/modules/network/f5/test_bigip_ucs.py
index e4e69cc604..e819ca28c2 100644
--- a/test/units/modules/network/f5/test_bigip_ucs.py
+++ b/test/units/modules/network/f5/test_bigip_ucs.py
@@ -17,10 +17,9 @@ if sys.version_info < (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.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_ucs import Parameters
@@ -44,11 +43,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_user.py b/test/units/modules/network/f5/test_bigip_user.py
index ffbde0afa8..028c96252b 100644
--- a/test/units/modules/network/f5/test_bigip_user.py
+++ b/test/units/modules/network/f5/test_bigip_user.py
@@ -17,10 +17,9 @@ if sys.version_info < (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.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_user import Parameters
@@ -44,11 +43,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_virtual_address.py b/test/units/modules/network/f5/test_bigip_virtual_address.py
index eb75a7fb26..556878d9d2 100644
--- a/test/units/modules/network/f5/test_bigip_virtual_address.py
+++ b/test/units/modules/network/f5/test_bigip_virtual_address.py
@@ -16,9 +16,8 @@ if sys.version_info < (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.module_utils.f5_utils import AnsibleF5Client
+from units.modules.utils import set_module_args
try:
from library.bigip_virtual_address import Parameters
@@ -38,11 +37,6 @@ 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)
diff --git a/test/units/modules/network/f5/test_bigip_wait.py b/test/units/modules/network/f5/test_bigip_wait.py
index 4bac673157..7fe4d06d05 100644
--- a/test/units/modules/network/f5/test_bigip_wait.py
+++ b/test/units/modules/network/f5/test_bigip_wait.py
@@ -31,10 +31,9 @@ if sys.version_info < (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.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_wait import Parameters
@@ -56,11 +55,6 @@ 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)
diff --git a/test/units/modules/network/ios/ios_module.py b/test/units/modules/network/ios/ios_module.py
index 35d6658725..f450c4ad26 100644
--- a/test/units/modules/network/ios/ios_module.py
+++ b/test/units/modules/network/ios/ios_module.py
@@ -22,16 +22,9 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +47,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestIosModule(unittest.TestCase):
+class TestIosModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
@@ -84,27 +69,16 @@ class TestIosModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/ios/test_ios_banner.py b/test/units/modules/network/ios/test_ios_banner.py
index e464e5f74e..e4bd98109d 100644
--- a/test/units/modules/network/ios/test_ios_banner.py
+++ b/test/units/modules/network/ios/test_ios_banner.py
@@ -17,11 +17,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_banner
-from .ios_module import TestIosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ios_module import TestIosModule, load_fixture
class TestIosBannerModule(TestIosModule):
@@ -29,6 +28,8 @@ class TestIosBannerModule(TestIosModule):
module = ios_banner
def setUp(self):
+ super(TestIosBannerModule, self).setUp()
+
self.mock_exec_command = patch('ansible.modules.network.ios.ios_banner.exec_command')
self.exec_command = self.mock_exec_command.start()
@@ -36,6 +37,7 @@ class TestIosBannerModule(TestIosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestIosBannerModule, self).tearDown()
self.mock_exec_command.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/ios/test_ios_command.py b/test/units/modules/network/ios/test_ios_command.py
index d415680801..45a8ddabdd 100644
--- a/test/units/modules/network/ios/test_ios_command.py
+++ b/test/units/modules/network/ios/test_ios_command.py
@@ -23,7 +23,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_command
-from .ios_module import TestIosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ios_module import TestIosModule, load_fixture
class TestIosCommandModule(TestIosModule):
@@ -31,10 +32,13 @@ class TestIosCommandModule(TestIosModule):
module = ios_command
def setUp(self):
+ super(TestIosCommandModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.ios.ios_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestIosCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/ios/test_ios_config.py b/test/units/modules/network/ios/test_ios_config.py
index c6a5bcef46..2294bce3fe 100644
--- a/test/units/modules/network/ios/test_ios_config.py
+++ b/test/units/modules/network/ios/test_ios_config.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_config
-from .ios_module import TestIosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ios_module import TestIosModule, load_fixture
class TestIosConfigModule(TestIosModule):
@@ -32,6 +31,8 @@ class TestIosConfigModule(TestIosModule):
module = ios_config
def setUp(self):
+ super(TestIosConfigModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.ios.ios_config.get_config')
self.get_config = self.mock_get_config.start()
@@ -42,6 +43,7 @@ class TestIosConfigModule(TestIosModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestIosConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/ios/test_ios_logging.py b/test/units/modules/network/ios/test_ios_logging.py
index 7138a0cd8d..91c0006798 100644
--- a/test/units/modules/network/ios/test_ios_logging.py
+++ b/test/units/modules/network/ios/test_ios_logging.py
@@ -25,7 +25,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_logging
-from .ios_module import TestIosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ios_module import TestIosModule, load_fixture
class TestIosLoggingModule(TestIosModule):
@@ -33,6 +34,8 @@ class TestIosLoggingModule(TestIosModule):
module = ios_logging
def setUp(self):
+ super(TestIosLoggingModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.ios.ios_logging.get_config')
self.get_config = self.mock_get_config.start()
@@ -40,6 +43,8 @@ class TestIosLoggingModule(TestIosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestIosLoggingModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/ios/test_ios_ping.py b/test/units/modules/network/ios/test_ios_ping.py
index a045fcc626..8d1b2a1aee 100644
--- a/test/units/modules/network/ios/test_ios_ping.py
+++ b/test/units/modules/network/ios/test_ios_ping.py
@@ -22,7 +22,8 @@ __metaclass__ = type
from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_ping
-from .ios_module import TestIosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ios_module import TestIosModule, load_fixture
class TestIosPingModule(TestIosModule):
@@ -30,10 +31,12 @@ class TestIosPingModule(TestIosModule):
module = ios_ping
def setUp(self):
+ super(TestIosPingModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.ios.ios_ping.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestIosPingModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/ios/test_ios_system.py b/test/units/modules/network/ios/test_ios_system.py
index 4f2fa93a4a..3e37d8b3a1 100644
--- a/test/units/modules/network/ios/test_ios_system.py
+++ b/test/units/modules/network/ios/test_ios_system.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_system
-from .ios_module import TestIosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ios_module import TestIosModule, load_fixture
class TestIosSystemModule(TestIosModule):
@@ -32,6 +31,8 @@ class TestIosSystemModule(TestIosModule):
module = ios_system
def setUp(self):
+ super(TestIosSystemModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.ios.ios_system.get_config')
self.get_config = self.mock_get_config.start()
@@ -39,6 +40,7 @@ class TestIosSystemModule(TestIosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestIosSystemModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/ios/test_ios_user.py b/test/units/modules/network/ios/test_ios_user.py
index e39c3e73a7..ee185eb7db 100644
--- a/test/units/modules/network/ios/test_ios_user.py
+++ b/test/units/modules/network/ios/test_ios_user.py
@@ -23,7 +23,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_user
-from .ios_module import TestIosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ios_module import TestIosModule, load_fixture
class TestIosUserModule(TestIosModule):
@@ -31,6 +32,8 @@ class TestIosUserModule(TestIosModule):
module = ios_user
def setUp(self):
+ super(TestIosUserModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.ios.ios_user.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +41,7 @@ class TestIosUserModule(TestIosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestIosUserModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/ios/test_ios_vrf.py b/test/units/modules/network/ios/test_ios_vrf.py
index 53f634b483..c7c3bc4122 100644
--- a/test/units/modules/network/ios/test_ios_vrf.py
+++ b/test/units/modules/network/ios/test_ios_vrf.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_vrf
-from .ios_module import TestIosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ios_module import TestIosModule, load_fixture
class TestIosVrfModule(TestIosModule):
@@ -32,6 +31,8 @@ class TestIosVrfModule(TestIosModule):
module = ios_vrf
def setUp(self):
+ super(TestIosVrfModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.ios.ios_vrf.get_config')
self.get_config = self.mock_get_config.start()
@@ -42,6 +43,7 @@ class TestIosVrfModule(TestIosModule):
self.exec_command = self.mock_exec_command.start()
def tearDown(self):
+ super(TestIosVrfModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_exec_command.stop()
diff --git a/test/units/modules/network/iosxr/iosxr_module.py b/test/units/modules/network/iosxr/iosxr_module.py
index e4ecf5884a..a8229ca3df 100644
--- a/test/units/modules/network/iosxr/iosxr_module.py
+++ b/test/units/modules/network/iosxr/iosxr_module.py
@@ -22,16 +22,9 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +47,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestIosxrModule(unittest.TestCase):
+class TestIosxrModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
@@ -84,27 +69,16 @@ class TestIosxrModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/iosxr/test_iosxr_command.py b/test/units/modules/network/iosxr/test_iosxr_command.py
index fcf1efd9d3..3f1a0e6aa4 100644
--- a/test/units/modules/network/iosxr/test_iosxr_command.py
+++ b/test/units/modules/network/iosxr/test_iosxr_command.py
@@ -19,11 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.iosxr import iosxr_command
-from .iosxr_module import TestIosxrModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .iosxr_module import TestIosxrModule, load_fixture
class TestIosxrCommandModule(TestIosxrModule):
@@ -31,10 +30,14 @@ class TestIosxrCommandModule(TestIosxrModule):
module = iosxr_command
def setUp(self):
+ super(TestIosxrCommandModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.iosxr.iosxr_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestIosxrCommandModule, self).tearDown()
+
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/iosxr/test_iosxr_config.py b/test/units/modules/network/iosxr/test_iosxr_config.py
index 5e2f696e3a..5d62639929 100644
--- a/test/units/modules/network/iosxr/test_iosxr_config.py
+++ b/test/units/modules/network/iosxr/test_iosxr_config.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.iosxr import iosxr_config
-from .iosxr_module import TestIosxrModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .iosxr_module import TestIosxrModule, load_fixture
class TestIosxrConfigModule(TestIosxrModule):
@@ -32,12 +31,16 @@ class TestIosxrConfigModule(TestIosxrModule):
module = iosxr_config
def setUp(self):
+ super(TestIosxrConfigModule, self).setUp()
+
self.patcher_get_config = patch('ansible.modules.network.iosxr.iosxr_config.get_config')
self.mock_get_config = self.patcher_get_config.start()
self.patcher_exec_command = patch('ansible.modules.network.iosxr.iosxr_config.load_config')
self.mock_exec_command = self.patcher_exec_command.start()
def tearDown(self):
+ super(TestIosxrConfigModule, self).tearDown()
+
self.patcher_get_config.stop()
self.patcher_exec_command.stop()
diff --git a/test/units/modules/network/iosxr/test_iosxr_facts.py b/test/units/modules/network/iosxr/test_iosxr_facts.py
index c1433b3592..717f403009 100644
--- a/test/units/modules/network/iosxr/test_iosxr_facts.py
+++ b/test/units/modules/network/iosxr/test_iosxr_facts.py
@@ -22,7 +22,8 @@ __metaclass__ = type
import json
from ansible.compat.tests.mock import patch
-from .iosxr_module import TestIosxrModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .iosxr_module import TestIosxrModule, load_fixture
from ansible.modules.network.iosxr import iosxr_facts
@@ -31,11 +32,15 @@ class TestIosxrFacts(TestIosxrModule):
module = iosxr_facts
def setUp(self):
+ super(TestIosxrFacts, self).setUp()
+
self.mock_run_commands = patch(
'ansible.modules.network.iosxr.iosxr_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestIosxrFacts, self).tearDown()
+
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/iosxr/test_iosxr_netconf.py b/test/units/modules/network/iosxr/test_iosxr_netconf.py
index 544059d01c..7cde357718 100644
--- a/test/units/modules/network/iosxr/test_iosxr_netconf.py
+++ b/test/units/modules/network/iosxr/test_iosxr_netconf.py
@@ -21,7 +21,8 @@ __metaclass__ = type
from ansible.compat.tests.mock import patch
from ansible.modules.network.iosxr import iosxr_netconf
-from .iosxr_module import TestIosxrModule, set_module_args
+from units.modules.utils import set_module_args
+from .iosxr_module import TestIosxrModule
class TestIosxrNetconfModule(TestIosxrModule):
@@ -29,6 +30,8 @@ class TestIosxrNetconfModule(TestIosxrModule):
module = iosxr_netconf
def setUp(self):
+ super(TestIosxrNetconfModule, self).setUp()
+
self.mock_exec_command = patch('ansible.modules.network.iosxr.iosxr_netconf.exec_command')
self.exec_command = self.mock_exec_command.start()
@@ -39,6 +42,7 @@ class TestIosxrNetconfModule(TestIosxrModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestIosxrNetconfModule, self).tearDown()
self.mock_exec_command.stop()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/iosxr/test_iosxr_system.py b/test/units/modules/network/iosxr/test_iosxr_system.py
index 83d928ffbe..de5029eb8f 100644
--- a/test/units/modules/network/iosxr/test_iosxr_system.py
+++ b/test/units/modules/network/iosxr/test_iosxr_system.py
@@ -19,10 +19,9 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
-from .iosxr_module import TestIosxrModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .iosxr_module import TestIosxrModule, load_fixture
from ansible.modules.network.iosxr import iosxr_system
@@ -31,6 +30,8 @@ class TestIosxrSystemModule(TestIosxrModule):
module = iosxr_system
def setUp(self):
+ super(TestIosxrSystemModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.iosxr.iosxr_system.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +39,8 @@ class TestIosxrSystemModule(TestIosxrModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestIosxrSystemModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/iosxr/test_iosxr_user.py b/test/units/modules/network/iosxr/test_iosxr_user.py
index 7f392e7a1c..2254249498 100644
--- a/test/units/modules/network/iosxr/test_iosxr_user.py
+++ b/test/units/modules/network/iosxr/test_iosxr_user.py
@@ -19,11 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.iosxr import iosxr_user
-from .iosxr_module import TestIosxrModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .iosxr_module import TestIosxrModule, load_fixture
class TestIosxrUserModule(TestIosxrModule):
@@ -31,6 +30,8 @@ class TestIosxrUserModule(TestIosxrModule):
module = iosxr_user
def setUp(self):
+ super(TestIosxrUserModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.iosxr.iosxr_user.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +39,8 @@ class TestIosxrUserModule(TestIosxrModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestIosxrUserModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/ironware/ironware_module.py b/test/units/modules/network/ironware/ironware_module.py
index 4a68cbbc54..a66a7754b4 100644
--- a/test/units/modules/network/ironware/ironware_module.py
+++ b/test/units/modules/network/ironware/ironware_module.py
@@ -22,16 +22,10 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +48,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestIronwareModule(unittest.TestCase):
+class TestIronwareModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
@@ -84,27 +70,16 @@ class TestIronwareModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/ironware/test_ironware_command.py b/test/units/modules/network/ironware/test_ironware_command.py
index 9cb4c22acd..f7d53e0e04 100644
--- a/test/units/modules/network/ironware/test_ironware_command.py
+++ b/test/units/modules/network/ironware/test_ironware_command.py
@@ -19,11 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.ironware import ironware_command
-from .ironware_module import TestIronwareModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ironware_module import TestIronwareModule, load_fixture
class TestIronwareCommandModule(TestIronwareModule):
@@ -31,10 +30,12 @@ class TestIronwareCommandModule(TestIronwareModule):
module = ironware_command
def setUp(self):
+ super(TestIronwareCommandModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.ironware.ironware_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestIronwareCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/ironware/test_ironware_config.py b/test/units/modules/network/ironware/test_ironware_config.py
index c23c1a8b81..ad228db05a 100644
--- a/test/units/modules/network/ironware/test_ironware_config.py
+++ b/test/units/modules/network/ironware/test_ironware_config.py
@@ -24,7 +24,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.ironware import ironware_config
-from .ironware_module import TestIronwareModule, load_fixture, set_module_args
+from .ironware_module import TestIronwareModule, load_fixture
+from units.modules.utils import set_module_args
class TestIronwareConfigModule(TestIronwareModule):
@@ -32,6 +33,8 @@ class TestIronwareConfigModule(TestIronwareModule):
module = ironware_config
def setUp(self):
+ super(TestIronwareConfigModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.ironware.ironware_config.get_config')
self.get_config = self.mock_get_config.start()
@@ -42,6 +45,7 @@ class TestIronwareConfigModule(TestIronwareModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestIronwareConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/ironware/test_ironware_facts.py b/test/units/modules/network/ironware/test_ironware_facts.py
index f1e66f7bec..44792706d8 100644
--- a/test/units/modules/network/ironware/test_ironware_facts.py
+++ b/test/units/modules/network/ironware/test_ironware_facts.py
@@ -22,8 +22,9 @@ __metaclass__ = type
import json
from ansible.compat.tests.mock import patch
-from .ironware_module import TestIronwareModule, load_fixture, set_module_args
+from .ironware_module import TestIronwareModule, load_fixture
from ansible.modules.network.ironware import ironware_facts
+from units.modules.utils import set_module_args
class TestIronwareFacts(TestIronwareModule):
@@ -31,11 +32,13 @@ class TestIronwareFacts(TestIronwareModule):
module = ironware_facts
def setUp(self):
+ super(TestIronwareFacts, self).setUp()
self.mock_run_commands = patch(
'ansible.modules.network.ironware.ironware_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestIronwareFacts, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/junos/junos_module.py b/test/units/modules/network/junos/junos_module.py
index 30fb4c7fe0..b0701b1fe2 100644
--- a/test/units/modules/network/junos/junos_module.py
+++ b/test/units/modules/network/junos/junos_module.py
@@ -27,16 +27,9 @@ try:
except ImportError:
from xml.etree.ElementTree import parse
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -63,15 +56,7 @@ def load_fixture(name, content='xml'):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestJunosModule(unittest.TestCase):
+class TestJunosModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False, format='text'):
@@ -87,27 +72,16 @@ class TestJunosModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/junos/test_junos_command.py b/test/units/modules/network/junos/test_junos_command.py
index a647d669b0..fe8cc2f1ae 100644
--- a/test/units/modules/network/junos/test_junos_command.py
+++ b/test/units/modules/network/junos/test_junos_command.py
@@ -21,7 +21,8 @@ __metaclass__ = type
from ansible.compat.tests.mock import patch
from ansible.modules.network.junos import junos_command
-from .junos_module import TestJunosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .junos_module import TestJunosModule, load_fixture
RPC_CLI_MAP = {
'get-software-information': 'show version'
@@ -33,10 +34,14 @@ class TestJunosCommandModule(TestJunosModule):
module = junos_command
def setUp(self):
+ super(TestJunosCommandModule, self).setUp()
+
self.mock_send_request = patch('ansible.modules.network.junos.junos_command.send_request')
self.send_request = self.mock_send_request.start()
def tearDown(self):
+ super(TestJunosCommandModule, self).tearDown()
+
self.mock_send_request.stop()
def load_fixtures(self, commands=None, format='text', changed=False):
diff --git a/test/units/modules/network/junos/test_junos_config.py b/test/units/modules/network/junos/test_junos_config.py
index ece27ec1d8..17dcf0fe6a 100644
--- a/test/units/modules/network/junos/test_junos_config.py
+++ b/test/units/modules/network/junos/test_junos_config.py
@@ -22,7 +22,8 @@ __metaclass__ = type
from ansible.compat.tests.mock import patch
from ansible.modules.network.junos import junos_config
-from .junos_module import TestJunosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .junos_module import TestJunosModule, load_fixture
class TestJunosConfigModule(TestJunosModule):
@@ -30,6 +31,8 @@ class TestJunosConfigModule(TestJunosModule):
module = junos_config
def setUp(self):
+ super(TestJunosConfigModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.junos.junos_config.get_configuration')
self.get_config = self.mock_get_config.start()
@@ -55,6 +58,7 @@ class TestJunosConfigModule(TestJunosModule):
self.send_request = self.mock_send_request.start()
def tearDown(self):
+ super(TestJunosConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_lock_configuration.stop()
diff --git a/test/units/modules/network/junos/test_junos_facts.py b/test/units/modules/network/junos/test_junos_facts.py
index 7e7d866d1d..c1032bd9dd 100644
--- a/test/units/modules/network/junos/test_junos_facts.py
+++ b/test/units/modules/network/junos/test_junos_facts.py
@@ -21,7 +21,8 @@ __metaclass__ = type
from ansible.compat.tests.mock import patch
from ansible.modules.network.junos import junos_facts
-from .junos_module import TestJunosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .junos_module import TestJunosModule, load_fixture
RPC_CLI_MAP = {
'get-software-information': 'show version',
@@ -38,6 +39,8 @@ class TestJunosCommandModule(TestJunosModule):
module = junos_facts
def setUp(self):
+ super(TestJunosCommandModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.junos.junos_facts.get_configuration')
self.get_config = self.mock_get_config.start()
@@ -45,6 +48,7 @@ class TestJunosCommandModule(TestJunosModule):
self.send_request = self.mock_send_request.start()
def tearDown(self):
+ super(TestJunosCommandModule, self).tearDown()
self.mock_send_request.stop()
def load_fixtures(self, commands=None, format='text', changed=False):
diff --git a/test/units/modules/network/junos/test_junos_netconf.py b/test/units/modules/network/junos/test_junos_netconf.py
index 1bf7947f00..6d7abcd68f 100644
--- a/test/units/modules/network/junos/test_junos_netconf.py
+++ b/test/units/modules/network/junos/test_junos_netconf.py
@@ -21,7 +21,8 @@ __metaclass__ = type
from ansible.compat.tests.mock import patch
from ansible.modules.network.junos import junos_netconf
-from .junos_module import TestJunosModule, set_module_args
+from units.modules.utils import set_module_args
+from .junos_module import TestJunosModule
class TestJunosCommandModule(TestJunosModule):
@@ -29,6 +30,8 @@ class TestJunosCommandModule(TestJunosModule):
module = junos_netconf
def setUp(self):
+ super(TestJunosCommandModule, self).setUp()
+
self.mock_exec_command = patch('ansible.modules.network.junos.junos_netconf.exec_command')
self.exec_command = self.mock_exec_command.start()
@@ -42,6 +45,7 @@ class TestJunosCommandModule(TestJunosModule):
self.commit_configuration = self.mock_commit_configuration.start()
def tearDown(self):
+ super(TestJunosCommandModule, self).tearDown()
self.mock_exec_command.stop()
self.mock_lock_configuration.stop()
self.mock_unlock_configuration.stop()
diff --git a/test/units/modules/network/junos/test_junos_package.py b/test/units/modules/network/junos/test_junos_package.py
index 8bfc0ab197..31dd778f75 100644
--- a/test/units/modules/network/junos/test_junos_package.py
+++ b/test/units/modules/network/junos/test_junos_package.py
@@ -20,7 +20,8 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.compat.tests.mock import patch, MagicMock
-from .junos_module import TestJunosModule, set_module_args
+from units.modules.utils import set_module_args
+from .junos_module import TestJunosModule
jnpr_mock = MagicMock()
modules = {
@@ -41,10 +42,10 @@ class TestJunosCommandModule(TestJunosModule):
module = junos_package
def setUp(self):
- pass
+ super(TestJunosCommandModule, self).setUp()
def tearDown(self):
- pass
+ super(TestJunosCommandModule, self).tearDown()
def test_junos_package_src(self):
set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz'))
diff --git a/test/units/modules/network/junos/test_junos_rpc.py b/test/units/modules/network/junos/test_junos_rpc.py
index 5cd431e5e2..7ac8f89a0e 100644
--- a/test/units/modules/network/junos/test_junos_rpc.py
+++ b/test/units/modules/network/junos/test_junos_rpc.py
@@ -26,7 +26,8 @@ except ImportError:
from ansible.compat.tests.mock import patch
from ansible.modules.network.junos import junos_rpc
-from .junos_module import TestJunosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .junos_module import TestJunosModule, load_fixture
RPC_CLI_MAP = {
@@ -43,10 +44,12 @@ class TestJunosCommandModule(TestJunosModule):
module = junos_rpc
def setUp(self):
+ super(TestJunosCommandModule, self).setUp()
self.mock_send_request = patch('ansible.modules.network.junos.junos_rpc.send_request')
self.send_request = self.mock_send_request.start()
def tearDown(self):
+ super(TestJunosCommandModule, self).tearDown()
self.mock_send_request.stop()
def load_fixtures(self, commands=None, format='text', changed=False):
diff --git a/test/units/modules/network/netscaler/netscaler_module.py b/test/units/modules/network/netscaler/netscaler_module.py
index 9b2b2e83e1..f3715883de 100644
--- a/test/units/modules/network/netscaler/netscaler_module.py
+++ b/test/units/modules/network/netscaler/netscaler_module.py
@@ -1,10 +1,7 @@
import sys
from ansible.compat.tests.mock import patch, Mock
-from ansible.compat.tests import unittest
-from ansible.module_utils import basic
-import json
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
base_modules_mock = Mock()
nitro_service_mock = Mock()
@@ -30,40 +27,18 @@ base_modules_to_mock = {
nitro_base_patcher = patch.dict(sys.modules, base_modules_to_mock)
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
-
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestModule(unittest.TestCase):
+class TestModule(ModuleTestCase):
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def exited(self, changed=False):
- def exit_json(*args, **kwargs):
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
return result
diff --git a/test/units/modules/network/netscaler/test_netscaler_cs_action.py b/test/units/modules/network/netscaler/test_netscaler_cs_action.py
index bea60ca940..cf30cf43a5 100644
--- a/test/units/modules/network/netscaler/test_netscaler_cs_action.py
+++ b/test/units/modules/network/netscaler/test_netscaler_cs_action.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -53,12 +54,16 @@ class TestNetscalerCSActionModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerCSActionModule, self).setUp()
+
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerCSActionModule, self).tearDown()
+
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_cs_policy.py b/test/units/modules/network/netscaler/test_netscaler_cs_policy.py
index 42d5f2f8de..6bee0f0e1d 100644
--- a/test/units/modules/network/netscaler/test_netscaler_cs_policy.py
+++ b/test/units/modules/network/netscaler/test_netscaler_cs_policy.py
@@ -25,7 +25,8 @@ if sys.version_info[:2] != (2, 6):
import requests
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
class TestNetscalerCSPolicyModule(TestModule):
@@ -58,10 +59,14 @@ class TestNetscalerCSPolicyModule(TestModule):
))
def setUp(self):
+ super(TestNetscalerCSPolicyModule, self).setUp()
+
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
def tearDown(self):
+ super(TestNetscalerCSPolicyModule, self).tearDown()
+
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_cs_vserver.py b/test/units/modules/network/netscaler/test_netscaler_cs_vserver.py
index 45f1ac53d8..6c7927850c 100644
--- a/test/units/modules/network/netscaler/test_netscaler_cs_vserver.py
+++ b/test/units/modules/network/netscaler/test_netscaler_cs_vserver.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -58,12 +59,16 @@ class TestNetscalerCSVserverModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerCSVserverModule, self).setUp()
+
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerCSVserverModule, self).tearDown()
+
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_gslb_service.py b/test/units/modules/network/netscaler/test_netscaler_gslb_service.py
index 0f57ae7fed..8b5eaa9892 100644
--- a/test/units/modules/network/netscaler/test_netscaler_gslb_service.py
+++ b/test/units/modules/network/netscaler/test_netscaler_gslb_service.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -61,12 +62,16 @@ class TestNetscalerGSLBSiteModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerGSLBSiteModule, self).setUp()
+
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerGSLBSiteModule, self).tearDown()
+
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_gslb_site.py b/test/units/modules/network/netscaler/test_netscaler_gslb_site.py
index ba7413d879..0cec388acd 100644
--- a/test/units/modules/network/netscaler/test_netscaler_gslb_site.py
+++ b/test/units/modules/network/netscaler/test_netscaler_gslb_site.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -51,12 +52,16 @@ class TestNetscalerGSLBSiteModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerGSLBSiteModule, self).setUp()
+
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerGSLBSiteModule, self).tearDown()
+
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_gslb_vserver.py b/test/units/modules/network/netscaler/test_netscaler_gslb_vserver.py
index 5087eb7dea..fa7ca41bfc 100644
--- a/test/units/modules/network/netscaler/test_netscaler_gslb_vserver.py
+++ b/test/units/modules/network/netscaler/test_netscaler_gslb_vserver.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -55,12 +56,16 @@ class TestNetscalerGSLBVserverModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerGSLBVserverModule, self).setUp()
+
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerGSLBVserverModule, self).tearDown()
+
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_lb_monitor.py b/test/units/modules/network/netscaler/test_netscaler_lb_monitor.py
index d45ffdf7cc..e889106785 100644
--- a/test/units/modules/network/netscaler/test_netscaler_lb_monitor.py
+++ b/test/units/modules/network/netscaler/test_netscaler_lb_monitor.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -51,12 +52,16 @@ class TestNetscalerLBVServerModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerLBVServerModule, self).setUp()
+
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerLBVServerModule, self).tearDown()
+
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_lb_vserver.py b/test/units/modules/network/netscaler/test_netscaler_lb_vserver.py
index 6becb5fb1f..f943bb89b3 100644
--- a/test/units/modules/network/netscaler/test_netscaler_lb_vserver.py
+++ b/test/units/modules/network/netscaler/test_netscaler_lb_vserver.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -60,12 +61,15 @@ class TestNetscalerLBVServerModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerLBVServerModule, self).setUp()
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerLBVServerModule, self).tearDown()
+
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_save_config.py b/test/units/modules/network/netscaler/test_netscaler_save_config.py
index 98bed1a7eb..d752dc8344 100644
--- a/test/units/modules/network/netscaler/test_netscaler_save_config.py
+++ b/test/units/modules/network/netscaler/test_netscaler_save_config.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -42,9 +43,11 @@ class TestNetscalerSaveConfigModule(TestModule):
cls.nitro_base_patcher.stop()
def setUp(self):
+ super(TestNetscalerSaveConfigModule, self).setUp()
self.nitro_base_patcher.start()
def tearDown(self):
+ super(TestNetscalerSaveConfigModule, self).tearDown()
self.nitro_base_patcher.stop()
def test_graceful_nitro_error_on_login(self):
diff --git a/test/units/modules/network/netscaler/test_netscaler_server.py b/test/units/modules/network/netscaler/test_netscaler_server.py
index 7bd026ec11..32aafb4072 100644
--- a/test/units/modules/network/netscaler/test_netscaler_server.py
+++ b/test/units/modules/network/netscaler/test_netscaler_server.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -53,12 +54,14 @@ class TestNetscalerServerModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerServerModule, self).setUp()
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerServerModule, self).tearDown()
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_service.py b/test/units/modules/network/netscaler/test_netscaler_service.py
index 2921d69ca4..2804583bd6 100644
--- a/test/units/modules/network/netscaler/test_netscaler_service.py
+++ b/test/units/modules/network/netscaler/test_netscaler_service.py
@@ -25,7 +25,8 @@ if sys.version_info[:2] != (2, 6):
import requests
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
class TestNetscalerServiceModule(TestModule):
@@ -65,12 +66,14 @@ class TestNetscalerServiceModule(TestModule):
))
def setUp(self):
+ super(TestNetscalerServiceModule, self).setUp()
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerServiceModule, self).tearDown()
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_servicegroup.py b/test/units/modules/network/netscaler/test_netscaler_servicegroup.py
index 05c56acb73..4f5c9f794a 100644
--- a/test/units/modules/network/netscaler/test_netscaler_servicegroup.py
+++ b/test/units/modules/network/netscaler/test_netscaler_servicegroup.py
@@ -25,7 +25,8 @@ if sys.version_info[:2] != (2, 6):
import requests
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
class TestNetscalerServicegroupModule(TestModule):
@@ -69,12 +70,14 @@ class TestNetscalerServicegroupModule(TestModule):
))
def setUp(self):
+ super(TestNetscalerServicegroupModule, self).setUp()
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerServicegroupModule, self).tearDown()
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/netscaler/test_netscaler_ssl_certkey.py b/test/units/modules/network/netscaler/test_netscaler_ssl_certkey.py
index 311a15aa81..3fe1e045fd 100644
--- a/test/units/modules/network/netscaler/test_netscaler_ssl_certkey.py
+++ b/test/units/modules/network/netscaler/test_netscaler_ssl_certkey.py
@@ -18,7 +18,8 @@
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
-from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
+from units.modules.utils import set_module_args
+from .netscaler_module import TestModule, nitro_base_patcher
import sys
@@ -53,12 +54,14 @@ class TestNetscalerSSLCertkeyModule(TestModule):
cls.nitro_specific_patcher.stop()
def setUp(self):
+ super(TestNetscalerSSLCertkeyModule, self).setUp()
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
+ super(TestNetscalerSSLCertkeyModule, self).tearDown()
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
diff --git a/test/units/modules/network/nso/nso_module.py b/test/units/modules/network/nso/nso_module.py
index 44ce5d5049..4397490310 100644
--- a/test/units/modules/network/nso/nso_module.py
+++ b/test/units/modules/network/nso/nso_module.py
@@ -20,21 +20,13 @@ from __future__ import (absolute_import, division, print_function)
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
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 not in fixture_data:
@@ -80,15 +72,7 @@ def mock_call(calls, url, data=None, headers=None, method=None):
return result
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestNsoModule(unittest.TestCase):
+class TestNsoModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, **kwargs):
if failed:
@@ -104,27 +88,16 @@ class TestNsoModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/nso/test_nso_config.py b/test/units/modules/network/nso/test_nso_config.py
index 546688a0ce..b0eb6d66f9 100644
--- a/test/units/modules/network/nso/test_nso_config.py
+++ b/test/units/modules/network/nso/test_nso_config.py
@@ -22,6 +22,7 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.nso import nso_config
+from units.modules.utils import set_module_args, AnsibleFailJson
from . import nso_module
from .nso_module import MockResponse
@@ -46,11 +47,11 @@ class TestNsoConfig(nso_module.TestNsoModule):
open_url_mock.side_effect = lambda *args, **kwargs: nso_module.mock_call(calls, *args, **kwargs)
data = nso_module.load_fixture('config_config.json')
- nso_module.set_module_args({
+ set_module_args({
'username': 'user', 'password': 'password',
'url': 'http://localhost:8080/jsonrpc', 'data': data
})
- with self.assertRaises(SystemExit):
+ with self.assertRaises(AnsibleFailJson):
self.execute_module(changed=False, changes=[], diffs=[])
self.assertEqual(0, len(calls))
@@ -75,7 +76,7 @@ class TestNsoConfig(nso_module.TestNsoModule):
open_url_mock.side_effect = lambda *args, **kwargs: nso_module.mock_call(calls, *args, **kwargs)
data = nso_module.load_fixture('config_empty_data.json')
- nso_module.set_module_args({
+ set_module_args({
'username': 'user', 'password': 'password',
'url': 'http://localhost:8080/jsonrpc', 'data': data
})
@@ -118,7 +119,7 @@ class TestNsoConfig(nso_module.TestNsoModule):
open_url_mock.side_effect = lambda *args, **kwargs: nso_module.mock_call(calls, *args, **kwargs)
data = nso_module.load_fixture('config_config.json')
- nso_module.set_module_args({
+ set_module_args({
'username': 'user', 'password': 'password',
'url': 'http://localhost:8080/jsonrpc', 'data': data
})
diff --git a/test/units/modules/network/nuage/nuage_module.py b/test/units/modules/network/nuage/nuage_module.py
index 2a38ca3981..c27b5d3e8f 100644
--- a/test/units/modules/network/nuage/nuage_module.py
+++ b/test/units/modules/network/nuage/nuage_module.py
@@ -16,11 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-import json
-from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import set_module_args as _set_module_args, AnsibleExitJson, AnsibleFailJson, ModuleTestCase
from nose.plugins.skip import SkipTest
try:
@@ -31,27 +28,15 @@ except ImportError:
def set_module_args(args):
- set_module_args_custom_auth(args=args, auth={
- 'api_username': 'csproot',
- 'api_password': 'csproot',
- 'api_enterprise': 'csp',
- 'api_url': 'https://localhost:8443',
- 'api_version': 'v5_0'
- })
-
-
-def set_module_args_custom_auth(args, auth):
- args['auth'] = auth
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
-
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
+ if 'auth' not in args:
+ args['auth'] = {
+ 'api_username': 'csproot',
+ 'api_password': 'csproot',
+ 'api_enterprise': 'csp',
+ 'api_url': 'https://localhost:8443',
+ 'api_version': 'v5_0'
+ }
+ return _set_module_args(args)
class MockNuageResponse(object):
@@ -66,9 +51,10 @@ class MockNuageConnection(object):
self.response = MockNuageResponse(status_code, reason, errors)
-class TestNuageModule(unittest.TestCase):
+class TestNuageModule(ModuleTestCase):
def setUp(self):
+ super(TestNuageModule, self).setUp()
def session_start(self):
self._root_object = vsdk.NUMe()
@@ -79,22 +65,6 @@ class TestNuageModule(unittest.TestCase):
self.session_mock = patch('vspk.v5_0.NUVSDSession.start', new=session_start)
self.session_mock.start()
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- self.fail_json_mock = patch('ansible.module_utils.basic.AnsibleModule.fail_json', new=fail_json)
- self.fail_json_mock.start()
-
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- self.exit_json_mock = patch('ansible.module_utils.basic.AnsibleModule.exit_json', new=exit_json)
- self.exit_json_mock.start()
-
def tearDown(self):
+ super(TestNuageModule, self).tearDown()
self.session_mock.stop()
- self.fail_json_mock.stop()
- self.exit_json_mock.stop()
diff --git a/test/units/modules/network/nuage/test_nuage_vspk.py b/test/units/modules/network/nuage/test_nuage_vspk.py
index f83f611b13..29abe49e84 100644
--- a/test/units/modules/network/nuage/test_nuage_vspk.py
+++ b/test/units/modules/network/nuage/test_nuage_vspk.py
@@ -30,7 +30,8 @@ except ImportError:
raise SkipTest('Nuage Ansible modules requires the vspk and bambou python libraries')
from ansible.compat.tests.mock import patch
-from .nuage_module import AnsibleExitJson, AnsibleFailJson, MockNuageConnection, TestNuageModule, set_module_args, set_module_args_custom_auth
+from units.modules.utils import set_module_args, AnsibleExitJson, AnsibleFailJson
+from .nuage_module import MockNuageConnection, TestNuageModule
_LOOP_COUNTER = 0
@@ -173,25 +174,25 @@ class TestNuageVSPKModule(TestNuageModule):
def tearDown(self):
super(TestNuageVSPKModule, self).tearDown()
- for patch in self.patches:
- patch.stop()
+ for mock in self.patches:
+ mock.stop()
def test_certificate_auth(self):
- set_module_args_custom_auth(
+ set_module_args(
args={
'type': 'Enterprise',
'state': 'present',
'properties': {
'name': 'test-enterprise'
+ },
+ 'auth': {
+ 'api_username': 'csproot',
+ 'api_certificate': '/dummy/location/certificate.pem',
+ 'api_key': '/dummy/location/key.pem',
+ 'api_enterprise': 'csp',
+ 'api_url': 'https://localhost:8443',
+ 'api_version': 'v5_0'
}
- },
- auth={
- 'api_username': 'csproot',
- 'api_certificate': '/dummy/location/certificate.pem',
- 'api_key': '/dummy/location/key.pem',
- 'api_enterprise': 'csp',
- 'api_url': 'https://localhost:8443',
- 'api_version': 'v5_0'
}
)
@@ -874,16 +875,16 @@ class TestNuageVSPKModule(TestNuageModule):
self.assertEqual(result['msg'], "Job ended in an error")
def test_fail_auth(self):
- set_module_args_custom_auth(
+ set_module_args(
args={
'type': 'Enterprise',
- 'command': 'find'
- },
- auth={
- 'api_username': 'csproot',
- 'api_enterprise': 'csp',
- 'api_url': 'https://localhost:8443',
- 'api_version': 'v5_0'
+ 'command': 'find',
+ 'auth': {
+ 'api_username': 'csproot',
+ 'api_enterprise': 'csp',
+ 'api_url': 'https://localhost:8443',
+ 'api_version': 'v5_0'
+ }
}
)
@@ -896,17 +897,17 @@ class TestNuageVSPKModule(TestNuageModule):
self.assertEqual(result['msg'], 'Missing api_password or api_certificate and api_key parameter in auth')
def test_fail_version(self):
- set_module_args_custom_auth(
+ set_module_args(
args={
'type': 'Enterprise',
- 'command': 'find'
- },
- auth={
- 'api_username': 'csproot',
- 'api_password': 'csproot',
- 'api_enterprise': 'csp',
- 'api_url': 'https://localhost:8443',
- 'api_version': 'v1_0'
+ 'command': 'find',
+ 'auth': {
+ 'api_username': 'csproot',
+ 'api_password': 'csproot',
+ 'api_enterprise': 'csp',
+ 'api_url': 'https://localhost:8443',
+ 'api_version': 'v1_0'
+ }
}
)
@@ -1197,16 +1198,16 @@ class TestNuageVSPKModule(TestNuageModule):
self.assertEqual(result['msg'], 'Property fake is not valid for this type of entity')
def test_input_auth_username(self):
- set_module_args_custom_auth(
+ set_module_args(
args={
'type': 'Enterprise',
- 'command': 'find'
- },
- auth={
- 'api_password': 'csproot',
- 'api_enterprise': 'csp',
- 'api_url': 'https://localhost:8443',
- 'api_version': 'v5_0'
+ 'command': 'find',
+ 'auth': {
+ 'api_password': 'csproot',
+ 'api_enterprise': 'csp',
+ 'api_url': 'https://localhost:8443',
+ 'api_version': 'v5_0'
+ }
}
)
@@ -1219,16 +1220,16 @@ class TestNuageVSPKModule(TestNuageModule):
self.assertEqual(result['msg'], 'missing required arguments: api_username')
def test_input_auth_enterprise(self):
- set_module_args_custom_auth(
+ set_module_args(
args={
'type': 'Enterprise',
- 'command': 'find'
- },
- auth={
- 'api_username': 'csproot',
- 'api_password': 'csproot',
- 'api_url': 'https://localhost:8443',
- 'api_version': 'v5_0'
+ 'command': 'find',
+ 'auth': {
+ 'api_username': 'csproot',
+ 'api_password': 'csproot',
+ 'api_url': 'https://localhost:8443',
+ 'api_version': 'v5_0'
+ }
}
)
@@ -1241,16 +1242,16 @@ class TestNuageVSPKModule(TestNuageModule):
self.assertEqual(result['msg'], 'missing required arguments: api_enterprise')
def test_input_auth_url(self):
- set_module_args_custom_auth(
+ set_module_args(
args={
'type': 'Enterprise',
- 'command': 'find'
- },
- auth={
- 'api_username': 'csproot',
- 'api_password': 'csproot',
- 'api_enterprise': 'csp',
- 'api_version': 'v5_0'
+ 'command': 'find',
+ 'auth': {
+ 'api_username': 'csproot',
+ 'api_password': 'csproot',
+ 'api_enterprise': 'csp',
+ 'api_version': 'v5_0'
+ }
}
)
@@ -1263,16 +1264,16 @@ class TestNuageVSPKModule(TestNuageModule):
self.assertEqual(result['msg'], 'missing required arguments: api_url')
def test_input_auth_version(self):
- set_module_args_custom_auth(
+ set_module_args(
args={
'type': 'Enterprise',
- 'command': 'find'
- },
- auth={
- 'api_username': 'csproot',
- 'api_password': 'csproot',
- 'api_enterprise': 'csp',
- 'api_url': 'https://localhost:8443',
+ 'command': 'find',
+ 'auth': {
+ 'api_username': 'csproot',
+ 'api_password': 'csproot',
+ 'api_enterprise': 'csp',
+ 'api_url': 'https://localhost:8443',
+ }
}
)
diff --git a/test/units/modules/network/nxos/nxos_module.py b/test/units/modules/network/nxos/nxos_module.py
index a9546f8448..1948cfc0aa 100644
--- a/test/units/modules/network/nxos/nxos_module.py
+++ b/test/units/modules/network/nxos/nxos_module.py
@@ -22,18 +22,15 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
+from units.modules.utils import set_module_args as _set_module_args
def set_module_args(args):
if 'provider' not in args:
args['provider'] = {'transport': args.get('transport') or 'cli'}
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
+ return _set_module_args(args)
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -59,15 +56,7 @@ def load_fixture(module_name, name, device=''):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestNxosModule(unittest.TestCase):
+class TestNxosModule(ModuleTestCase):
def execute_module_devices(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
module_name = self.module.__name__.rsplit('.', 1)[1]
@@ -107,27 +96,16 @@ class TestNxosModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/nxos/test_nxos_acl.py b/test/units/modules/network/nxos/test_nxos_acl.py
index 6c2163fa05..fce8207ef3 100644
--- a/test/units/modules/network/nxos/test_nxos_acl.py
+++ b/test/units/modules/network/nxos/test_nxos_acl.py
@@ -31,6 +31,8 @@ class TestNxosAclModule(TestNxosModule):
module = nxos_acl
def setUp(self):
+ super(TestNxosAclModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_acl.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -38,6 +40,7 @@ class TestNxosAclModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosAclModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_acl_interface.py b/test/units/modules/network/nxos/test_nxos_acl_interface.py
index c4dc3591d6..8e71fa8c86 100644
--- a/test/units/modules/network/nxos/test_nxos_acl_interface.py
+++ b/test/units/modules/network/nxos/test_nxos_acl_interface.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metacl_interfaceass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_acl_interface
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosAclInterfaceModule(TestNxosModule):
module = nxos_acl_interface
def setUp(self):
+ super(TestNxosAclInterfaceModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_acl_interface.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -38,6 +38,7 @@ class TestNxosAclInterfaceModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosAclInterfaceModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_banner.py b/test/units/modules/network/nxos/test_nxos_banner.py
index 145b4bd57e..7c0644a38e 100644
--- a/test/units/modules/network/nxos/test_nxos_banner.py
+++ b/test/units/modules/network/nxos/test_nxos_banner.py
@@ -17,11 +17,9 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_banner
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
+from .nxos_module import TestNxosModule, set_module_args
class TestNxosBannerModule(TestNxosModule):
@@ -29,6 +27,7 @@ class TestNxosBannerModule(TestNxosModule):
module = nxos_banner
def setUp(self):
+ super(TestNxosBannerModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_banner.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -36,6 +35,7 @@ class TestNxosBannerModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosBannerModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_bgp.py b/test/units/modules/network/nxos/test_nxos_bgp.py
index 275b3bdbb2..b39508be0b 100644
--- a/test/units/modules/network/nxos/test_nxos_bgp.py
+++ b/test/units/modules/network/nxos/test_nxos_bgp.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_bgp
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosBgpModule(TestNxosModule):
module = nxos_bgp
def setUp(self):
+ super(TestNxosBgpModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_bgp.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosBgpModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosBgpModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_bgp_af.py b/test/units/modules/network/nxos/test_nxos_bgp_af.py
index b3c8bb616f..2708d59660 100644
--- a/test/units/modules/network/nxos/test_nxos_bgp_af.py
+++ b/test/units/modules/network/nxos/test_nxos_bgp_af.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_bgp_af
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosBgpAfModule(TestNxosModule):
module = nxos_bgp_af
def setUp(self):
+ super(TestNxosBgpAfModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_bgp_af.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosBgpAfModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosBgpAfModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_bgp_neighbor.py b/test/units/modules/network/nxos/test_nxos_bgp_neighbor.py
index 60b151f9f8..ffbd7b0a39 100644
--- a/test/units/modules/network/nxos/test_nxos_bgp_neighbor.py
+++ b/test/units/modules/network/nxos/test_nxos_bgp_neighbor.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_bgp_neighbor
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosBgpNeighborModule(TestNxosModule):
module = nxos_bgp_neighbor
def setUp(self):
+ super(TestNxosBgpNeighborModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_bgp_neighbor.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosBgpNeighborModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosBgpNeighborModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py b/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py
index bbaf1e4f14..7a0b1219ce 100644
--- a/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py
+++ b/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_bgp_neighbor_af
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosBgpNeighborAfModule(TestNxosModule):
module = nxos_bgp_neighbor_af
def setUp(self):
+ super(TestNxosBgpNeighborAfModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_bgp_neighbor_af.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosBgpNeighborAfModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosBgpNeighborAfModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_command.py b/test/units/modules/network/nxos/test_nxos_command.py
index ee073ac003..6f3e0e14c3 100644
--- a/test/units/modules/network/nxos/test_nxos_command.py
+++ b/test/units/modules/network/nxos/test_nxos_command.py
@@ -31,10 +31,13 @@ class TestNxosCommandModule(TestNxosModule):
module = nxos_command
def setUp(self):
+ super(TestNxosCommandModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestNxosCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None, device=''):
diff --git a/test/units/modules/network/nxos/test_nxos_config.py b/test/units/modules/network/nxos/test_nxos_config.py
index 42e178ab94..e403eced05 100644
--- a/test/units/modules/network/nxos/test_nxos_config.py
+++ b/test/units/modules/network/nxos/test_nxos_config.py
@@ -21,8 +21,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_config
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -33,6 +31,8 @@ class TestNxosConfigModule(TestNxosModule):
module = nxos_config
def setUp(self):
+ super(TestNxosConfigModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_config.get_config')
self.get_config = self.mock_get_config.start()
@@ -40,6 +40,7 @@ class TestNxosConfigModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_evpn_global.py b/test/units/modules/network/nxos/test_nxos_evpn_global.py
index 1adce68b82..48db78b5b9 100644
--- a/test/units/modules/network/nxos/test_nxos_evpn_global.py
+++ b/test/units/modules/network/nxos/test_nxos_evpn_global.py
@@ -19,7 +19,6 @@
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_evpn_global
@@ -31,6 +30,7 @@ class TestNxosEvpnGlobalModule(TestNxosModule):
module = nxos_evpn_global
def setUp(self):
+ super(TestNxosEvpnGlobalModule, self).setUp()
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_evpn_global.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +38,7 @@ class TestNxosEvpnGlobalModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosEvpnGlobalModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_evpn_vni.py b/test/units/modules/network/nxos/test_nxos_evpn_vni.py
index 8ee0aad3f5..28707fcbfc 100644
--- a/test/units/modules/network/nxos/test_nxos_evpn_vni.py
+++ b/test/units/modules/network/nxos/test_nxos_evpn_vni.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_evpn_vni
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosEvpnVniModule(TestNxosModule):
module = nxos_evpn_vni
def setUp(self):
+ super(TestNxosEvpnVniModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_evpn_vni.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -41,6 +41,7 @@ class TestNxosEvpnVniModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosEvpnVniModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_feature.py b/test/units/modules/network/nxos/test_nxos_feature.py
index 60fd4aab1f..e4194bae42 100644
--- a/test/units/modules/network/nxos/test_nxos_feature.py
+++ b/test/units/modules/network/nxos/test_nxos_feature.py
@@ -31,6 +31,7 @@ class TestNxosFeatureModule(TestNxosModule):
module = nxos_feature
def setUp(self):
+ super(TestNxosFeatureModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_feature.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -38,6 +39,7 @@ class TestNxosFeatureModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosFeatureModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_hsrp.py b/test/units/modules/network/nxos/test_nxos_hsrp.py
index d60d5e26e4..5812cdfdb9 100644
--- a/test/units/modules/network/nxos/test_nxos_hsrp.py
+++ b/test/units/modules/network/nxos/test_nxos_hsrp.py
@@ -19,11 +19,9 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_hsrp
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
+from .nxos_module import TestNxosModule, set_module_args
class TestNxosHsrpModule(TestNxosModule):
@@ -31,6 +29,7 @@ class TestNxosHsrpModule(TestNxosModule):
module = nxos_hsrp
def setUp(self):
+ super(TestNxosHsrpModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_hsrp.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -38,6 +37,7 @@ class TestNxosHsrpModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosHsrpModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_interface.py b/test/units/modules/network/nxos/test_nxos_interface.py
index b9e14f1abb..f0dc10b239 100644
--- a/test/units/modules/network/nxos/test_nxos_interface.py
+++ b/test/units/modules/network/nxos/test_nxos_interface.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_interface
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,7 @@ class TestNxosInterfaceModule(TestNxosModule):
module = nxos_interface
def setUp(self):
+ super(TestNxosInterfaceModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_interface.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -38,6 +37,7 @@ class TestNxosInterfaceModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosInterfaceModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_interface_ospf.py b/test/units/modules/network/nxos/test_nxos_interface_ospf.py
index f47d2f9cf2..78b2b41195 100644
--- a/test/units/modules/network/nxos/test_nxos_interface_ospf.py
+++ b/test/units/modules/network/nxos/test_nxos_interface_ospf.py
@@ -29,6 +29,8 @@ class TestNxosInterfaceOspfModule(TestNxosModule):
module = nxos_interface_ospf
def setUp(self):
+ super(TestNxosInterfaceOspfModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_interface_ospf.get_config')
self.get_config = self.mock_get_config.start()
@@ -36,6 +38,7 @@ class TestNxosInterfaceOspfModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosInterfaceOspfModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_ip_interface.py b/test/units/modules/network/nxos/test_nxos_ip_interface.py
index 96d95c34d4..2e1e5e1b12 100644
--- a/test/units/modules/network/nxos/test_nxos_ip_interface.py
+++ b/test/units/modules/network/nxos/test_nxos_ip_interface.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_ip_interface
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosIPInterfaceModule(TestNxosModule):
module = nxos_ip_interface
def setUp(self):
+ super(TestNxosIPInterfaceModule, self).setUp()
+
self.mock_get_interface_mode = patch(
'ansible.modules.network.nxos.nxos_ip_interface.get_interface_mode')
self.get_interface_mode = self.mock_get_interface_mode.start()
@@ -43,6 +43,7 @@ class TestNxosIPInterfaceModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosIPInterfaceModule, self).tearDown()
self.mock_get_interface_mode.stop()
self.mock_send_show_command.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_nxapi.py b/test/units/modules/network/nxos/test_nxos_nxapi.py
index 9b4e089a32..36754dc85e 100644
--- a/test/units/modules/network/nxos/test_nxos_nxapi.py
+++ b/test/units/modules/network/nxos/test_nxos_nxapi.py
@@ -19,9 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-import os
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_nxapi
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -32,6 +29,8 @@ class TestNxosNxapiModule(TestNxosModule):
module = nxos_nxapi
def setUp(self):
+ super(TestNxosNxapiModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_nxapi.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -39,6 +38,7 @@ class TestNxosNxapiModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosNxapiModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_ospf.py b/test/units/modules/network/nxos/test_nxos_ospf.py
index c2652e4b30..38374e8e70 100644
--- a/test/units/modules/network/nxos/test_nxos_ospf.py
+++ b/test/units/modules/network/nxos/test_nxos_ospf.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_ospf
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosOspfModule(TestNxosModule):
module = nxos_ospf
def setUp(self):
+ super(TestNxosOspfModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_ospf.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosOspfModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosOspfModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_ospf_vrf.py b/test/units/modules/network/nxos/test_nxos_ospf_vrf.py
index 9fac7471ca..2258d9c67d 100644
--- a/test/units/modules/network/nxos/test_nxos_ospf_vrf.py
+++ b/test/units/modules/network/nxos/test_nxos_ospf_vrf.py
@@ -19,11 +19,9 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_ospf_vrf
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
+from .nxos_module import TestNxosModule, set_module_args
class TestNxosOspfVrfModule(TestNxosModule):
@@ -31,6 +29,8 @@ class TestNxosOspfVrfModule(TestNxosModule):
module = nxos_ospf_vrf
def setUp(self):
+ super(TestNxosOspfVrfModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_ospf_vrf.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosOspfVrfModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosOspfVrfModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_overlay_global.py b/test/units/modules/network/nxos/test_nxos_overlay_global.py
index 2f05077c09..c4ef81d74c 100644
--- a/test/units/modules/network/nxos/test_nxos_overlay_global.py
+++ b/test/units/modules/network/nxos/test_nxos_overlay_global.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_overlay_global
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,7 @@ class TestNxosOverlayGlobalModule(TestNxosModule):
module = nxos_overlay_global
def setUp(self):
+ super(TestNxosOverlayGlobalModule, self).setUp()
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_overlay_global.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +37,7 @@ class TestNxosOverlayGlobalModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosOverlayGlobalModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_pim.py b/test/units/modules/network/nxos/test_nxos_pim.py
index c1326bd7db..52bf64c7d8 100644
--- a/test/units/modules/network/nxos/test_nxos_pim.py
+++ b/test/units/modules/network/nxos/test_nxos_pim.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import os
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_pim
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosPimModule(TestNxosModule):
module = nxos_pim
def setUp(self):
+ super(TestNxosPimModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_pim.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +38,7 @@ class TestNxosPimModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosPimModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_pim_interface.py b/test/units/modules/network/nxos/test_nxos_pim_interface.py
index b75c270366..0de3ea3d5d 100644
--- a/test/units/modules/network/nxos/test_nxos_pim_interface.py
+++ b/test/units/modules/network/nxos/test_nxos_pim_interface.py
@@ -29,6 +29,8 @@ class TestNxosIPInterfaceModule(TestNxosModule):
module = nxos_pim_interface
def setUp(self):
+ super(TestNxosIPInterfaceModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_pim_interface.get_config')
self.get_config = self.mock_get_config.start()
@@ -39,6 +41,7 @@ class TestNxosIPInterfaceModule(TestNxosModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestNxosIPInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_pim_rp_address.py b/test/units/modules/network/nxos/test_nxos_pim_rp_address.py
index 4af8865494..608bf06ef3 100644
--- a/test/units/modules/network/nxos/test_nxos_pim_rp_address.py
+++ b/test/units/modules/network/nxos/test_nxos_pim_rp_address.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_pim_rp_address
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosPimRpAddressModule(TestNxosModule):
module = nxos_pim_rp_address
def setUp(self):
+ super(TestNxosPimRpAddressModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_pim_rp_address.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosPimRpAddressModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosPimRpAddressModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_portchannel.py b/test/units/modules/network/nxos/test_nxos_portchannel.py
index db4defade8..32b3a04ed6 100644
--- a/test/units/modules/network/nxos/test_nxos_portchannel.py
+++ b/test/units/modules/network/nxos/test_nxos_portchannel.py
@@ -19,11 +19,9 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_portchannel
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
+from .nxos_module import TestNxosModule, set_module_args
class TestNxosPortchannelModule(TestNxosModule):
@@ -31,6 +29,8 @@ class TestNxosPortchannelModule(TestNxosModule):
module = nxos_portchannel
def setUp(self):
+ super(TestNxosPortchannelModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_portchannel.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -41,6 +41,7 @@ class TestNxosPortchannelModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosPortchannelModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_static_route.py b/test/units/modules/network/nxos/test_nxos_static_route.py
index 00abfa4db2..8d126d806c 100644
--- a/test/units/modules/network/nxos/test_nxos_static_route.py
+++ b/test/units/modules/network/nxos/test_nxos_static_route.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_static_route
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosStaticRouteModule(TestNxosModule):
module = nxos_static_route
def setUp(self):
+ super(TestNxosStaticRouteModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_static_route.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosStaticRouteModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosStaticRouteModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_switchport.py b/test/units/modules/network/nxos/test_nxos_switchport.py
index de302f3ff4..ef05f7b6e0 100644
--- a/test/units/modules/network/nxos/test_nxos_switchport.py
+++ b/test/units/modules/network/nxos/test_nxos_switchport.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import os
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_switchport
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosSwitchportModule(TestNxosModule):
module = nxos_switchport
def setUp(self):
+ super(TestNxosSwitchportModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_switchport.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -38,6 +38,7 @@ class TestNxosSwitchportModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosSwitchportModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_system.py b/test/units/modules/network/nxos/test_nxos_system.py
index 18e2042b3c..44a1b20f50 100644
--- a/test/units/modules/network/nxos/test_nxos_system.py
+++ b/test/units/modules/network/nxos/test_nxos_system.py
@@ -19,7 +19,6 @@
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_system
@@ -31,6 +30,8 @@ class TestNxosSystemModule(TestNxosModule):
module = nxos_system
def setUp(self):
+ super(TestNxosSystemModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_system.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +39,7 @@ class TestNxosSystemModule(TestNxosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestNxosSystemModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_vlan.py b/test/units/modules/network/nxos/test_nxos_vlan.py
index ab93983033..16806407f9 100644
--- a/test/units/modules/network/nxos/test_nxos_vlan.py
+++ b/test/units/modules/network/nxos/test_nxos_vlan.py
@@ -31,6 +31,8 @@ class TestNxosVlanModule(TestNxosModule):
module = nxos_vlan
def setUp(self):
+ super(TestNxosVlanModule, self).setUp()
+
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_vlan.run_commands')
self.run_commands = self.mock_run_commands.start()
@@ -41,6 +43,7 @@ class TestNxosVlanModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosVlanModule, self).tearDown()
self.mock_run_commands.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_vpc.py b/test/units/modules/network/nxos/test_nxos_vpc.py
index 4e658a22a9..e524859190 100644
--- a/test/units/modules/network/nxos/test_nxos_vpc.py
+++ b/test/units/modules/network/nxos/test_nxos_vpc.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import os
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_vpc
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosVpcModule(TestNxosModule):
module = nxos_vpc
def setUp(self):
+ super(TestNxosVpcModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_vpc.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosVpcModule(TestNxosModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestNxosVpcModule, self).tearDown()
self.mock_load_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_vpc_interface.py b/test/units/modules/network/nxos/test_nxos_vpc_interface.py
index 3e25ada534..5c85e01909 100644
--- a/test/units/modules/network/nxos/test_nxos_vpc_interface.py
+++ b/test/units/modules/network/nxos/test_nxos_vpc_interface.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import os
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_vpc_interface
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosVpcModule(TestNxosModule):
module = nxos_vpc_interface
def setUp(self):
+ super(TestNxosVpcModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_vpc_interface.load_config')
self.load_config = self.mock_load_config.start()
@@ -41,6 +41,7 @@ class TestNxosVpcModule(TestNxosModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestNxosVpcModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_vrf.py b/test/units/modules/network/nxos/test_nxos_vrf.py
index 71b072476e..036309e33e 100644
--- a/test/units/modules/network/nxos/test_nxos_vrf.py
+++ b/test/units/modules/network/nxos/test_nxos_vrf.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import os
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_vrf
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosVrfModule(TestNxosModule):
module = nxos_vrf
def setUp(self):
+ super(TestNxosVrfModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_vrf.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosVrfModule(TestNxosModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestNxosVrfModule, self).tearDown()
self.mock_load_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_vrf_af.py b/test/units/modules/network/nxos/test_nxos_vrf_af.py
index 42f985bdbf..834f75c0f3 100644
--- a/test/units/modules/network/nxos/test_nxos_vrf_af.py
+++ b/test/units/modules/network/nxos/test_nxos_vrf_af.py
@@ -19,11 +19,9 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_vrf_af
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
+from .nxos_module import TestNxosModule, set_module_args
class TestNxosVrfafModule(TestNxosModule):
@@ -31,6 +29,8 @@ class TestNxosVrfafModule(TestNxosModule):
module = nxos_vrf_af
def setUp(self):
+ super(TestNxosVrfafModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_vrf_af.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosVrfafModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosVrfafModule, self).tearDown()
self.mock_load_config.stop()
self.mock_get_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_vxlan_vtep.py b/test/units/modules/network/nxos/test_nxos_vxlan_vtep.py
index db6fa11d78..7b925c4653 100644
--- a/test/units/modules/network/nxos/test_nxos_vxlan_vtep.py
+++ b/test/units/modules/network/nxos/test_nxos_vxlan_vtep.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_vxlan_vtep
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosVxlanVtepVniModule(TestNxosModule):
module = nxos_vxlan_vtep
def setUp(self):
+ super(TestNxosVxlanVtepVniModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_vxlan_vtep.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosVxlanVtepVniModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosVxlanVtepVniModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/nxos/test_nxos_vxlan_vtep_vni.py b/test/units/modules/network/nxos/test_nxos_vxlan_vtep_vni.py
index c96e436dc9..ca445e40b1 100644
--- a/test/units/modules/network/nxos/test_nxos_vxlan_vtep_vni.py
+++ b/test/units/modules/network/nxos/test_nxos_vxlan_vtep_vni.py
@@ -19,8 +19,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.nxos import nxos_vxlan_vtep_vni
from .nxos_module import TestNxosModule, load_fixture, set_module_args
@@ -31,6 +29,8 @@ class TestNxosVxlanVtepVniModule(TestNxosModule):
module = nxos_vxlan_vtep_vni
def setUp(self):
+ super(TestNxosVxlanVtepVniModule, self).setUp()
+
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_vxlan_vtep_vni.load_config')
self.load_config = self.mock_load_config.start()
@@ -38,6 +38,7 @@ class TestNxosVxlanVtepVniModule(TestNxosModule):
self.get_config = self.mock_get_config.start()
def tearDown(self):
+ super(TestNxosVxlanVtepVniModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/ovs/ovs_module.py b/test/units/modules/network/ovs/ovs_module.py
index 5360e7a864..fe49809d50 100644
--- a/test/units/modules/network/ovs/ovs_module.py
+++ b/test/units/modules/network/ovs/ovs_module.py
@@ -22,16 +22,9 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +47,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestOpenVSwitchModule(unittest.TestCase):
+class TestOpenVSwitchModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False,
commands=None, test_name=None):
@@ -82,27 +67,16 @@ class TestOpenVSwitchModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
diff --git a/test/units/modules/network/ovs/test_openvswitch_bridge.py b/test/units/modules/network/ovs/test_openvswitch_bridge.py
index 9bef615591..0e39572bc6 100644
--- a/test/units/modules/network/ovs/test_openvswitch_bridge.py
+++ b/test/units/modules/network/ovs/test_openvswitch_bridge.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.ovs import openvswitch_bridge
-from .ovs_module import TestOpenVSwitchModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ovs_module import TestOpenVSwitchModule, load_fixture
test_name_side_effect_matrix = {
'test_openvswitch_bridge_absent_idempotent': [
@@ -86,6 +85,8 @@ class TestOpenVSwitchBridgeModule(TestOpenVSwitchModule):
module = openvswitch_bridge
def setUp(self):
+ super(TestOpenVSwitchBridgeModule, self).setUp()
+
self.mock_run_command = (
patch('ansible.module_utils.basic.AnsibleModule.run_command'))
self.run_command = self.mock_run_command.start()
@@ -94,6 +95,8 @@ class TestOpenVSwitchBridgeModule(TestOpenVSwitchModule):
self.get_bin_path = self.mock_get_bin_path.start()
def tearDown(self):
+ super(TestOpenVSwitchBridgeModule, self).tearDown()
+
self.mock_run_command.stop()
self.mock_get_bin_path.stop()
diff --git a/test/units/modules/network/ovs/test_openvswitch_db.py b/test/units/modules/network/ovs/test_openvswitch_db.py
index eb55c0cceb..b99924c4b2 100644
--- a/test/units/modules/network/ovs/test_openvswitch_db.py
+++ b/test/units/modules/network/ovs/test_openvswitch_db.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.ovs import openvswitch_db
-from .ovs_module import TestOpenVSwitchModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ovs_module import TestOpenVSwitchModule, load_fixture
test_name_side_effect_matrix = {
'test_openvswitch_db_absent_idempotent': [
@@ -50,6 +49,8 @@ class TestOpenVSwitchDBModule(TestOpenVSwitchModule):
module = openvswitch_db
def setUp(self):
+ super(TestOpenVSwitchDBModule, self).setUp()
+
self.mock_run_command = (
patch('ansible.module_utils.basic.AnsibleModule.run_command'))
self.run_command = self.mock_run_command.start()
@@ -58,6 +59,8 @@ class TestOpenVSwitchDBModule(TestOpenVSwitchModule):
self.get_bin_path = self.mock_get_bin_path.start()
def tearDown(self):
+ super(TestOpenVSwitchDBModule, self).tearDown()
+
self.mock_run_command.stop()
self.mock_get_bin_path.stop()
diff --git a/test/units/modules/network/ovs/test_openvswitch_port.py b/test/units/modules/network/ovs/test_openvswitch_port.py
index d56e480bbc..d9fc55e691 100644
--- a/test/units/modules/network/ovs/test_openvswitch_port.py
+++ b/test/units/modules/network/ovs/test_openvswitch_port.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.ovs import openvswitch_port
-from .ovs_module import TestOpenVSwitchModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .ovs_module import TestOpenVSwitchModule, load_fixture
test_name_side_effect_matrix = {
'test_openvswitch_port_absent_idempotent': [
@@ -75,6 +74,8 @@ class TestOpenVSwitchPortModule(TestOpenVSwitchModule):
module = openvswitch_port
def setUp(self):
+ super(TestOpenVSwitchPortModule, self).setUp()
+
self.mock_run_command = (
patch('ansible.module_utils.basic.AnsibleModule.run_command'))
self.run_command = self.mock_run_command.start()
@@ -83,6 +84,8 @@ class TestOpenVSwitchPortModule(TestOpenVSwitchModule):
self.get_bin_path = self.mock_get_bin_path.start()
def tearDown(self):
+ super(TestOpenVSwitchPortModule, self).tearDown()
+
self.mock_run_command.stop()
self.mock_get_bin_path.stop()
diff --git a/test/units/modules/network/vyos/test_vyos_banner.py b/test/units/modules/network/vyos/test_vyos_banner.py
index f7de5cc944..57c6f66122 100644
--- a/test/units/modules/network/vyos/test_vyos_banner.py
+++ b/test/units/modules/network/vyos/test_vyos_banner.py
@@ -17,11 +17,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.vyos import vyos_banner
-from .vyos_module import TestVyosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .vyos_module import TestVyosModule, load_fixture
class TestVyosBannerModule(TestVyosModule):
@@ -29,6 +28,8 @@ class TestVyosBannerModule(TestVyosModule):
module = vyos_banner
def setUp(self):
+ super(TestVyosBannerModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.vyos.vyos_banner.get_config')
self.get_config = self.mock_get_config.start()
@@ -36,6 +37,7 @@ class TestVyosBannerModule(TestVyosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestVyosBannerModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/vyos/test_vyos_command.py b/test/units/modules/network/vyos/test_vyos_command.py
index d3b90f847d..c64423c45b 100644
--- a/test/units/modules/network/vyos/test_vyos_command.py
+++ b/test/units/modules/network/vyos/test_vyos_command.py
@@ -23,7 +23,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.vyos import vyos_command
-from .vyos_module import TestVyosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .vyos_module import TestVyosModule, load_fixture
class TestVyosCommandModule(TestVyosModule):
@@ -31,10 +32,12 @@ class TestVyosCommandModule(TestVyosModule):
module = vyos_command
def setUp(self):
+ super(TestVyosCommandModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.vyos.vyos_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestVyosCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/vyos/test_vyos_config.py b/test/units/modules/network/vyos/test_vyos_config.py
index 09dc7a0d2f..b1bdeab6eb 100644
--- a/test/units/modules/network/vyos/test_vyos_config.py
+++ b/test/units/modules/network/vyos/test_vyos_config.py
@@ -20,11 +20,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.vyos import vyos_config
-from .vyos_module import TestVyosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .vyos_module import TestVyosModule, load_fixture
class TestVyosConfigModule(TestVyosModule):
@@ -32,6 +31,8 @@ class TestVyosConfigModule(TestVyosModule):
module = vyos_config
def setUp(self):
+ super(TestVyosConfigModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.vyos.vyos_config.get_config')
self.get_config = self.mock_get_config.start()
@@ -42,6 +43,8 @@ class TestVyosConfigModule(TestVyosModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestVyosConfigModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
diff --git a/test/units/modules/network/vyos/test_vyos_facts.py b/test/units/modules/network/vyos/test_vyos_facts.py
index b9c2aa098e..82a71fba31 100644
--- a/test/units/modules/network/vyos/test_vyos_facts.py
+++ b/test/units/modules/network/vyos/test_vyos_facts.py
@@ -23,7 +23,8 @@ import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.vyos import vyos_facts
-from .vyos_module import TestVyosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .vyos_module import TestVyosModule, load_fixture
class TestVyosFactsModule(TestVyosModule):
@@ -31,10 +32,12 @@ class TestVyosFactsModule(TestVyosModule):
module = vyos_facts
def setUp(self):
+ super(TestVyosFactsModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.vyos.vyos_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
+ super(TestVyosFactsModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
diff --git a/test/units/modules/network/vyos/test_vyos_static_route.py b/test/units/modules/network/vyos/test_vyos_static_route.py
index 2162818ce2..85a47ec8ab 100644
--- a/test/units/modules/network/vyos/test_vyos_static_route.py
+++ b/test/units/modules/network/vyos/test_vyos_static_route.py
@@ -21,7 +21,8 @@ __metaclass__ = type
from ansible.compat.tests.mock import patch
from ansible.modules.network.vyos import vyos_static_route
-from .vyos_module import TestVyosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .vyos_module import TestVyosModule, load_fixture
class TestVyosStaticRouteModule(TestVyosModule):
@@ -29,6 +30,8 @@ class TestVyosStaticRouteModule(TestVyosModule):
module = vyos_static_route
def setUp(self):
+ super(TestVyosStaticRouteModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.vyos.vyos_static_route.get_config')
self.get_config = self.mock_get_config.start()
@@ -36,6 +39,8 @@ class TestVyosStaticRouteModule(TestVyosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestVyosStaticRouteModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/vyos/test_vyos_system.py b/test/units/modules/network/vyos/test_vyos_system.py
index 2e2c2f2a7b..389538552e 100644
--- a/test/units/modules/network/vyos/test_vyos_system.py
+++ b/test/units/modules/network/vyos/test_vyos_system.py
@@ -19,11 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.vyos import vyos_system
-from .vyos_module import TestVyosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .vyos_module import TestVyosModule, load_fixture
class TestVyosSystemModule(TestVyosModule):
@@ -31,6 +30,8 @@ class TestVyosSystemModule(TestVyosModule):
module = vyos_system
def setUp(self):
+ super(TestVyosSystemModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.vyos.vyos_system.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +39,8 @@ class TestVyosSystemModule(TestVyosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestVyosSystemModule, self).tearDown()
+
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/vyos/test_vyos_user.py b/test/units/modules/network/vyos/test_vyos_user.py
index fe2e2ed83f..bdc73d7f01 100644
--- a/test/units/modules/network/vyos/test_vyos_user.py
+++ b/test/units/modules/network/vyos/test_vyos_user.py
@@ -19,11 +19,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-import json
-
from ansible.compat.tests.mock import patch
from ansible.modules.network.vyos import vyos_user
-from .vyos_module import TestVyosModule, load_fixture, set_module_args
+from units.modules.utils import set_module_args
+from .vyos_module import TestVyosModule, load_fixture
class TestVyosUserModule(TestVyosModule):
@@ -31,6 +30,8 @@ class TestVyosUserModule(TestVyosModule):
module = vyos_user
def setUp(self):
+ super(TestVyosUserModule, self).setUp()
+
self.mock_get_config = patch('ansible.modules.network.vyos.vyos_user.get_config')
self.get_config = self.mock_get_config.start()
@@ -38,6 +39,7 @@ class TestVyosUserModule(TestVyosModule):
self.load_config = self.mock_load_config.start()
def tearDown(self):
+ super(TestVyosUserModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
diff --git a/test/units/modules/network/vyos/vyos_module.py b/test/units/modules/network/vyos/vyos_module.py
index 012f7e08f7..264cd5c66e 100644
--- a/test/units/modules/network/vyos/vyos_module.py
+++ b/test/units/modules/network/vyos/vyos_module.py
@@ -22,16 +22,9 @@ __metaclass__ = type
import os
import json
-from ansible.compat.tests import unittest
-from ansible.compat.tests.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
@@ -54,15 +47,7 @@ def load_fixture(name):
return data
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-class TestVyosModule(unittest.TestCase):
+class TestVyosModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
self.load_fixtures(commands)
@@ -83,27 +68,16 @@ class TestVyosModule(unittest.TestCase):
return result
def failed(self):
- def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'fail_json', fail_json):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleFailJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
- def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
- with patch.object(basic.AnsibleModule, 'exit_json', exit_json):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
+ with self.assertRaises(AnsibleExitJson) as exc:
+ self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)