mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 04:24:00 -07:00
Refactor common network shared and platform utils code into package (#33452)
* Refactor common network shared and platform specific code into package (part-1) As per proposal #76 refactor common network shared and platform specific code into sub-package. https://github.com/ansible/proposals/issues/76 * ansible.module_utils.network.common - command shared functions * ansible.module_utils.network.{{ platform }} - where platform is platform specific shared functions * Fix review comments * Fix review comments
This commit is contained in:
parent
18aca48075
commit
11c9ad23d5
483 changed files with 871 additions and 887 deletions
0
test/units/module_utils/network/__init__.py
Normal file
0
test/units/module_utils/network/__init__.py
Normal file
0
test/units/module_utils/network/aci/__init__.py
Normal file
0
test/units/module_utils/network/aci/__init__.py
Normal file
|
@ -21,7 +21,7 @@
|
|||
import sys
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.module_utils.aci import aci_response_json, aci_response_xml
|
||||
from ansible.module_utils.network.aci.aci import aci_response_json, aci_response_xml
|
||||
from ansible.module_utils.six import PY2, PY3
|
||||
from ansible.module_utils._text import to_native
|
||||
|
0
test/units/module_utils/network/common/__init__.py
Normal file
0
test/units/module_utils/network/common/__init__.py
Normal file
|
@ -23,9 +23,9 @@ __metaclass__ = type
|
|||
|
||||
from ansible.compat.tests import unittest
|
||||
|
||||
from ansible.module_utils.network_common import to_list, sort_list
|
||||
from ansible.module_utils.network_common import dict_diff, dict_merge
|
||||
from ansible.module_utils.network_common import conditional, Template
|
||||
from ansible.module_utils.network.common.utils import to_list, sort_list
|
||||
from ansible.module_utils.network.common.utils import dict_diff, dict_merge
|
||||
from ansible.module_utils.network.common.utils import conditional, Template
|
||||
|
||||
|
||||
class TestModuleUtilsNetworkCommon(unittest.TestCase):
|
0
test/units/module_utils/network/nso/__init__.py
Normal file
0
test/units/module_utils/network/nso/__init__.py
Normal file
|
@ -22,7 +22,7 @@ import json
|
|||
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.module_utils import nso
|
||||
from ansible.module_utils.network.nso import nso
|
||||
|
||||
|
||||
MODULE_PREFIX_MAP = '''
|
||||
|
@ -195,7 +195,7 @@ def get_schema_response(path):
|
|||
|
||||
|
||||
class TestValueBuilder(unittest.TestCase):
|
||||
@patch('ansible.module_utils.nso.open_url')
|
||||
@patch('ansible.module_utils.network.nso.nso.open_url')
|
||||
def test_identityref_leaf(self, open_url_mock):
|
||||
calls = [
|
||||
MockResponse('new_trans', {}, 200, '{"result": {"th": 1}}'),
|
||||
|
@ -219,7 +219,7 @@ class TestValueBuilder(unittest.TestCase):
|
|||
|
||||
self.assertEqual(0, len(calls))
|
||||
|
||||
@patch('ansible.module_utils.nso.open_url')
|
||||
@patch('ansible.module_utils.network.nso.nso.open_url')
|
||||
def test_identityref_key(self, open_url_mock):
|
||||
calls = [
|
||||
MockResponse('new_trans', {}, 200, '{"result": {"th": 1}}'),
|
|
@ -41,16 +41,16 @@ class TestJunosCommandModule(TestJunosModule):
|
|||
def setUp(self):
|
||||
super(TestJunosCommandModule, self).setUp()
|
||||
|
||||
self.mock_conn = patch('ansible.module_utils.junos.Connection')
|
||||
self.mock_conn = patch('ansible.module_utils.network.junos.junos.Connection')
|
||||
self.conn = self.mock_conn.start()
|
||||
|
||||
self.mock_netconf = patch('ansible.module_utils.junos.NetconfConnection')
|
||||
self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection')
|
||||
self.netconf_conn = self.mock_netconf.start()
|
||||
|
||||
self.mock_exec_rpc = patch('ansible.modules.network.junos.junos_command.exec_rpc')
|
||||
self.exec_rpc = self.mock_exec_rpc.start()
|
||||
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.netconf.NetconfConnection')
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection')
|
||||
self.netconf_rpc = self.mock_netconf_rpc.start()
|
||||
|
||||
self.mock_get_connection = patch('ansible.modules.network.junos.junos_command.get_connection')
|
||||
|
|
|
@ -42,10 +42,10 @@ class TestJunosConfigModule(TestJunosModule):
|
|||
self.mock_load_configuration = patch('ansible.modules.network.junos.junos_config.load_configuration')
|
||||
self.load_configuration = self.mock_load_configuration.start()
|
||||
|
||||
self.mock_lock_configuration = patch('ansible.module_utils.junos.lock_configuration')
|
||||
self.mock_lock_configuration = patch('ansible.module_utils.network.junos.junos.lock_configuration')
|
||||
self.lock_configuration = self.mock_lock_configuration.start()
|
||||
|
||||
self.mock_unlock_configuration = patch('ansible.module_utils.junos.unlock_configuration')
|
||||
self.mock_unlock_configuration = patch('ansible.module_utils.network.junos.junos.unlock_configuration')
|
||||
self.unlock_configuration = self.mock_unlock_configuration.start()
|
||||
|
||||
self.mock_commit_configuration = patch('ansible.modules.network.junos.junos_config.commit_configuration')
|
||||
|
@ -57,13 +57,13 @@ class TestJunosConfigModule(TestJunosModule):
|
|||
self.mock_conn = patch('ansible.module_utils.connection.Connection')
|
||||
self.conn = self.mock_conn.start()
|
||||
|
||||
self.mock_netconf = patch('ansible.module_utils.junos.NetconfConnection')
|
||||
self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection')
|
||||
self.netconf_conn = self.mock_netconf.start()
|
||||
|
||||
self.mock_exec_rpc = patch('ansible.modules.network.junos.junos_config.exec_rpc')
|
||||
self.exec_rpc = self.mock_exec_rpc.start()
|
||||
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.netconf.NetconfConnection')
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection')
|
||||
self.netconf_rpc = self.mock_netconf_rpc.start()
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
@ -52,16 +52,16 @@ class TestJunosCommandModule(TestJunosModule):
|
|||
self.mock_conn = patch('ansible.module_utils.connection.Connection')
|
||||
self.conn = self.mock_conn.start()
|
||||
|
||||
self.mock_netconf = patch('ansible.module_utils.junos.NetconfConnection')
|
||||
self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection')
|
||||
self.netconf_conn = self.mock_netconf.start()
|
||||
|
||||
self.mock_exec_rpc = patch('ansible.modules.network.junos.junos_facts.exec_rpc')
|
||||
self.exec_rpc = self.mock_exec_rpc.start()
|
||||
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.netconf.NetconfConnection')
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection')
|
||||
self.netconf_rpc = self.mock_netconf_rpc.start()
|
||||
|
||||
self.mock_get_capabilities = patch('ansible.module_utils.junos.get_capabilities')
|
||||
self.mock_get_capabilities = patch('ansible.module_utils.network.junos.junos.get_capabilities')
|
||||
self.get_capabilities = self.mock_get_capabilities.start()
|
||||
self.get_capabilities.return_value = {'network_api': 'netconf'}
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ class TestJunosCommandModule(TestJunosModule):
|
|||
def setUp(self):
|
||||
super(TestJunosCommandModule, self).setUp()
|
||||
|
||||
self.mock_lock_configuration = patch('ansible.module_utils.junos.lock_configuration')
|
||||
self.mock_lock_configuration = patch('ansible.module_utils.network.junos.junos.lock_configuration')
|
||||
self.lock_configuration = self.mock_lock_configuration.start()
|
||||
|
||||
self.mock_unlock_configuration = patch('ansible.module_utils.junos.unlock_configuration')
|
||||
self.mock_unlock_configuration = patch('ansible.module_utils.network.junos.junos.unlock_configuration')
|
||||
self.unlock_configuration = self.mock_unlock_configuration.start()
|
||||
|
||||
self.mock_commit_configuration = patch('ansible.modules.network.junos.junos_netconf.commit_configuration')
|
||||
|
@ -44,13 +44,13 @@ class TestJunosCommandModule(TestJunosModule):
|
|||
self.mock_conn = patch('ansible.module_utils.connection.Connection')
|
||||
self.conn = self.mock_conn.start()
|
||||
|
||||
self.mock_netconf = patch('ansible.module_utils.junos.NetconfConnection')
|
||||
self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection')
|
||||
self.netconf_conn = self.mock_netconf.start()
|
||||
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.netconf.NetconfConnection')
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection')
|
||||
self.netconf_rpc = self.mock_netconf_rpc.start()
|
||||
|
||||
self.mock_get_capabilities = patch('ansible.module_utils.junos.get_capabilities')
|
||||
self.mock_get_capabilities = patch('ansible.module_utils.network.junos.junos.get_capabilities')
|
||||
self.get_capabilities = self.mock_get_capabilities.start()
|
||||
self.get_capabilities.return_value = {'network_api': 'netconf'}
|
||||
|
||||
|
|
|
@ -49,10 +49,10 @@ class TestJunosCommandModule(TestJunosModule):
|
|||
self.mock_conn = patch('ansible.module_utils.connection.Connection')
|
||||
self.conn = self.mock_conn.start()
|
||||
|
||||
self.mock_netconf = patch('ansible.module_utils.junos.NetconfConnection')
|
||||
self.mock_netconf = patch('ansible.module_utils.network.junos.junos.NetconfConnection')
|
||||
self.netconf_conn = self.mock_netconf.start()
|
||||
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.netconf.NetconfConnection')
|
||||
self.mock_netconf_rpc = patch('ansible.module_utils.network.common.netconf.NetconfConnection')
|
||||
self.netconf_rpc = self.mock_netconf_rpc.start()
|
||||
|
||||
self.mock_exec_rpc = patch('ansible.modules.network.junos.junos_rpc.exec_rpc')
|
||||
|
|
|
@ -21,7 +21,7 @@ from ansible.compat.tests import unittest
|
|||
from ansible.compat.tests.mock import Mock
|
||||
|
||||
|
||||
from ansible.module_utils.netscaler import ConfigProxy, get_immutables_intersection, ensure_feature_is_enabled, log, loglines
|
||||
from ansible.module_utils.network.netscaler.netscaler import ConfigProxy, get_immutables_intersection, ensure_feature_is_enabled, log, loglines
|
||||
|
||||
|
||||
class TestNetscalerConfigProxy(unittest.TestCase):
|
||||
|
|
|
@ -30,11 +30,11 @@ from .nso_module import MockResponse
|
|||
class TestNsoConfig(nso_module.TestNsoModule):
|
||||
module = nso_config
|
||||
|
||||
@patch('ansible.module_utils.nso.open_url')
|
||||
@patch('ansible.module_utils.network.nso.nso.open_url')
|
||||
def test_nso_config_invalid_version_short(self, open_url_mock):
|
||||
self._test_invalid_version(open_url_mock, '4.4')
|
||||
|
||||
@patch('ansible.module_utils.nso.open_url')
|
||||
@patch('ansible.module_utils.network.nso.nso.open_url')
|
||||
def test_nso_config_invalid_version_long(self, open_url_mock):
|
||||
self._test_invalid_version(open_url_mock, '4.4.2')
|
||||
|
||||
|
@ -56,11 +56,11 @@ class TestNsoConfig(nso_module.TestNsoModule):
|
|||
|
||||
self.assertEqual(0, len(calls))
|
||||
|
||||
@patch('ansible.module_utils.nso.open_url')
|
||||
@patch('ansible.module_utils.network.nso.nso.open_url')
|
||||
def test_nso_config_valid_version_short(self, open_url_mock):
|
||||
self._test_valid_version(open_url_mock, '4.5')
|
||||
|
||||
@patch('ansible.module_utils.nso.open_url')
|
||||
@patch('ansible.module_utils.network.nso.nso.open_url')
|
||||
def test_nso_config_valid_version_long(self, open_url_mock):
|
||||
self._test_valid_version(open_url_mock, '4.4.3')
|
||||
|
||||
|
@ -84,7 +84,7 @@ class TestNsoConfig(nso_module.TestNsoModule):
|
|||
|
||||
self.assertEqual(0, len(calls))
|
||||
|
||||
@patch('ansible.module_utils.nso.open_url')
|
||||
@patch('ansible.module_utils.network.nso.nso.open_url')
|
||||
def test_nso_config_changed(self, open_url_mock):
|
||||
vpn_schema = nso_module.load_fixture('l3vpn_schema.json')
|
||||
l3vpn_schema = nso_module.load_fixture('l3vpn_l3vpn_schema.json')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue