mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Unit tests: share common code (#31456)
* move set_module_args to units.modules.utils * unit tests: reuse set_module_args * unit tests: mock exit/fail_json in module.utils.ModuleTestCase * unit tests: use module.utils.ModuleTestCase * unit tests: fix 'import shadowed by loop variable'
This commit is contained in:
parent
71a6dcdf3e
commit
a5c9726502
154 changed files with 671 additions and 1113 deletions
|
@ -23,10 +23,8 @@ from __future__ import (absolute_import, division, print_function)
|
|||
from nose.plugins.skip import SkipTest
|
||||
import pytest
|
||||
import sys
|
||||
import json
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.module_utils import basic
|
||||
from ansible.module_utils.ec2 import HAS_BOTO3
|
||||
from units.modules.utils import set_module_args
|
||||
|
||||
if not HAS_BOTO3:
|
||||
raise SkipTest("test_api_gateway.py requires the `boto3` and `botocore` modules")
|
||||
|
@ -34,11 +32,6 @@ if not HAS_BOTO3:
|
|||
import ansible.modules.cloud.amazon.aws_api_gateway as agw
|
||||
|
||||
|
||||
def set_module_args(args):
|
||||
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
|
||||
basic._ANSIBLE_ARGS = to_bytes(args)
|
||||
|
||||
|
||||
exit_return_dict = {}
|
||||
|
||||
|
||||
|
|
|
@ -20,12 +20,11 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
|
||||
import copy
|
||||
import json
|
||||
import pytest
|
||||
|
||||
from ansible.compat.tests.mock import MagicMock, Mock, patch
|
||||
from ansible.module_utils import basic
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from units.modules.utils import set_module_args
|
||||
|
||||
|
||||
boto3 = pytest.importorskip("boto3")
|
||||
|
@ -35,11 +34,6 @@ _temp = __import__("ansible.modules.cloud.amazon.lambda")
|
|||
lda = getattr(_temp.modules.cloud.amazon, "lambda")
|
||||
|
||||
|
||||
def set_module_args(args):
|
||||
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
|
||||
basic._ANSIBLE_ARGS = to_bytes(args)
|
||||
|
||||
|
||||
base_lambda_config = {
|
||||
'FunctionName': 'lambda_name',
|
||||
'Role': 'arn:aws:iam::987654321012:role/lambda_basic_execution',
|
||||
|
|
|
@ -19,13 +19,12 @@
|
|||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
|
||||
import copy
|
||||
|
||||
from nose.plugins.skip import SkipTest
|
||||
from ansible.module_utils.aws.core import HAS_BOTO3
|
||||
from ansible.module_utils import basic
|
||||
from ansible.module_utils.basic import to_bytes
|
||||
from ansible.compat.tests.mock import MagicMock
|
||||
import json
|
||||
import copy
|
||||
from units.modules.utils import set_module_args
|
||||
|
||||
if not HAS_BOTO3:
|
||||
raise SkipTest("test_api_gateway.py requires the `boto3` and `botocore` modules")
|
||||
|
@ -45,11 +44,6 @@ base_module_args = {
|
|||
}
|
||||
|
||||
|
||||
def set_module_args(mod_args):
|
||||
args = json.dumps({'ANSIBLE_MODULE_ARGS': mod_args})
|
||||
basic._ANSIBLE_ARGS = to_bytes(args)
|
||||
|
||||
|
||||
def test_module_is_created_sensibly():
|
||||
set_module_args(base_module_args)
|
||||
module = setup_module_object()
|
||||
|
|
|
@ -6,48 +6,21 @@ import re
|
|||
import uuid
|
||||
from urllib3.response import HTTPResponse
|
||||
|
||||
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 ansible.modules.monitoring import circonus_annotation
|
||||
from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def exit_json(*args, **kwargs):
|
||||
if 'changed' not in kwargs:
|
||||
kwargs['changed'] = False
|
||||
raise AnsibleExitJson(kwargs)
|
||||
|
||||
|
||||
def fail_json(*args, **kwargs):
|
||||
kwargs['failed'] = True
|
||||
raise AnsibleFailJson(kwargs)
|
||||
|
||||
|
||||
class TestCirconusAnnotation(unittest.TestCase):
|
||||
class TestCirconusAnnotation(ModuleTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCirconusAnnotation, self).setUp()
|
||||
self.module = circonus_annotation
|
||||
|
||||
self.mock_exit_fail = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
|
||||
self.mock_exit_fail.start()
|
||||
self.addCleanup(self.mock_exit_fail.stop)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
super(TestCirconusAnnotation, self).tearDown()
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
"""Failure must occurs when all parameters are missing"""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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'):
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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',
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue