From 7fec0b69a082aaeec72fee0612766aa42f6b1b4d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 18 Apr 2024 07:52:35 +0200 Subject: Merging upstream version 9.4.0+dfsg. Signed-off-by: Daniel Baumann --- .../junos/tests/unit/compat/builtins.py | 35 - .../junos/tests/unit/compat/mock.py | 1 - .../junos/tests/unit/mock/loader.py | 12 +- .../junos/fixtures/junos_l2_interfaces_config.cfg | 53 + .../network/junos/fixtures/junos_ospfv2_config.cfg | 242 ++++- .../unit/modules/network/junos/junos_module.py | 1 - .../modules/network/junos/test_junos_command.py | 1 - .../modules/network/junos/test_junos_config.py | 11 +- .../unit/modules/network/junos/test_junos_facts.py | 1 - .../modules/network/junos/test_junos_interfaces.py | 13 +- .../network/junos/test_junos_l2_interfaces.py | 230 +++-- .../modules/network/junos/test_junos_netconf.py | 1 - .../modules/network/junos/test_junos_ospfv2.py | 1023 +++++++++++--------- .../modules/network/junos/test_junos_ospfv3.py | 1 - .../modules/network/junos/test_junos_package.py | 12 +- .../unit/modules/network/junos/test_junos_rpc.py | 1 - .../unit/modules/network/junos/test_junos_scp.py | 1 - .../network/junos/test_junos_security_policies.py | 1 - .../network/junos/test_junos_security_zones.py | 250 +++++ .../network/junos/test_junos_snmp_server.py | 193 ++++ 20 files changed, 1472 insertions(+), 611 deletions(-) delete mode 100644 ansible_collections/junipernetworks/junos/tests/unit/compat/builtins.py create mode 100644 ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l2_interfaces_config.cfg (limited to 'ansible_collections/junipernetworks/junos/tests/unit') diff --git a/ansible_collections/junipernetworks/junos/tests/unit/compat/builtins.py b/ansible_collections/junipernetworks/junos/tests/unit/compat/builtins.py deleted file mode 100644 index e898a081e..000000000 --- a/ansible_collections/junipernetworks/junos/tests/unit/compat/builtins.py +++ /dev/null @@ -1,35 +0,0 @@ -# (c) 2014, Toshio Kuratomi -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -# -# Compat for python2.7 -# - -# One unittest needs to import builtins via __import__() so we need to have -# the string that represents it -try: - import __builtin__ -except ImportError: - BUILTINS = "builtins" -else: - BUILTINS = "__builtin__" diff --git a/ansible_collections/junipernetworks/junos/tests/unit/compat/mock.py b/ansible_collections/junipernetworks/junos/tests/unit/compat/mock.py index 1d51d36e8..860a9e84b 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/compat/mock.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/compat/mock.py @@ -105,7 +105,6 @@ if sys.version_info >= (3,) and sys.version_info < (3, 4, 4): global file_spec if file_spec is None: - file_spec = list( set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))), ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/mock/loader.py b/ansible_collections/junipernetworks/junos/tests/unit/mock/loader.py index 2b5eb36a1..0fc53edcd 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/mock/loader.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/mock/loader.py @@ -31,7 +31,7 @@ from ansible.parsing.dataloader import DataLoader class DictDataLoader(DataLoader): def __init__(self, file_mapping=None): file_mapping = {} if file_mapping is None else file_mapping - assert type(file_mapping) == dict + assert isinstance(file_mapping, dict) super(DictDataLoader, self).__init__() @@ -47,12 +47,12 @@ class DictDataLoader(DataLoader): # TODO: the real _get_file_contents returns a bytestring, so we actually convert the # unicode/text it's created with to utf-8 - def _get_file_contents(self, path): - path = to_text(path) - if path in self._file_mapping: - return (to_bytes(self._file_mapping[path]), False) + def _get_file_contents(self, file_name): + file_name = to_text(file_name) + if file_name in self._file_mapping: + return (to_bytes(self._file_mapping[file_name]), False) else: - raise AnsibleParserError("file not found: %s" % path) + raise AnsibleParserError("file not found: %s" % file_name) def path_exists(self, path): path = to_text(path) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l2_interfaces_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l2_interfaces_config.cfg new file mode 100644 index 000000000..26d323fcc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l2_interfaces_config.cfg @@ -0,0 +1,53 @@ + + + + + + ge-0/0/1 + Configured by Ansible + + 100m + 1024 + + 2000 + 2200 + + full-duplex + + 0 + + + access + + vlan100 + + + + + + + ge-0/0/2 + Configured by Ansible + 400 + 10m + 2048 + + 3000 + 3200 + + + 0 + + + trunk + + vlan200 + vlan300 + + + + + + + + diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2_config.cfg index 67b18028c..94784b875 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2_config.cfg +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2_config.cfg @@ -1,34 +1,214 @@ - - - - - 0.0.0.10 - - 200 - - - so-0/0/0.0 - - 5 - 3 - - - - - 0.0.0.20 - - ge-1/1/0.0 - - - ge-2/2/0.0 - - - - - - 10.200.16.77 - - + + + + + 3000 + 4000 + 9 + + + 20000 + + 1200 + + + + + 10g + + + 0.0.0.100 + + 100 + + + 10.200.17.0/24 + + + 2000 + + + 10.200.15.0/24 + + + 2000 + + + so-0/0/0.0 + + + + + 1g + 5 + + + 10g + 40 + + + 5 + 3 + 2 + 2 + 4 + 2 + + + + 0.0.0.200 + + 100 + + + 10.400.17.0/24 + + + 2000 + + + so-0/0/1.0 + + + + + 1g + 5 + + + + + 20 + $9$.fz6pu1crvEc-w2gDjz36 + 2023-7-12.03:00:00 +0000 + + + 10 + $9$m5F/u0ISlMhSdsg4jiFn/ + 2023-7-12.03:00:00 +0000 + + + + + so-0/0/2.0 + + + 20 + $9$.fz6pu1crvEc-w2gDjz36 + 2023-7-12.03:00:00 +0000 + + + + + so-0/0/3.0 + + + 20 + $9$.fz6pu1crvEc-w2gDjz36 + 2023-7-12.03:00:00 +0000 + + + + + + + + + + 9.9.9.9 + + + + + + 4 + + + + + + + + + + + + + + 20 + + 99 + + 2000 + + + + + + + 23000 + 32000 + + + 20 + 32000 + + + + 2 + + + from-fib + + + + + 20 + + 99 + + + + + + + 3 + + + + + + + + + + + + + + + + + + + 20 + + 98 + + 2001 + + + + + + 2 + + + + + + + diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/junos_module.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/junos_module.py index fe4c37b33..b847e3eef 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/junos_module.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/junos_module.py @@ -73,7 +73,6 @@ class TestJunosModule(ModuleTestCase): defaults=False, format="text", ): - self.load_fixtures(commands, format, changed=changed) if failed: diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py index 9494eb2b2..720b32981 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py @@ -37,7 +37,6 @@ RPC_CLI_MAP = {"get-software-information": "show version"} class TestJunosCommandModule(TestJunosModule): - module = junos_command def setUp(self): diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py index a8e134050..f3adb4767 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py @@ -32,7 +32,6 @@ from .junos_module import TestJunosModule, load_fixture class TestJunosConfigModule(TestJunosModule): - module = junos_config def setUp(self): @@ -169,6 +168,16 @@ class TestJunosConfigModule(TestJunosModule): load_configuration_args = self.load_configuration.call_args self.assertEqual(rollback, load_configuration_args[1].get("rollback")) + def test_junos_config_rollback_0(self): + rollback = 0 + set_module_args(dict(rollback=rollback)) + self.execute_module(changed=True) + self.assertEqual(self.get_diff.call_count, 1) + self.assertEqual(self.load_configuration.call_count, 1) + self.assertEqual(self.commit_configuration.call_count, 1) + load_configuration_args = self.load_configuration.call_args + self.assertEqual(rollback, load_configuration_args[1].get("rollback")) + def test_junos_config_src_text(self): src = load_fixture("junos_config.text", content="str") set_module_args(dict(src=src)) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py index 0b5b7890c..1e6bc12d3 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py @@ -44,7 +44,6 @@ RPC_CLI_MAP = { class TestJunosCommandModule(TestJunosModule): - module = junos_facts def setUp(self): diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py index ad4efe9ef..55ee8c766 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py @@ -103,12 +103,10 @@ class TestJunosInterfacesModule(TestJunosModule): ) commands = [ '' - "ge-0/0/1" - "This is configured with ansible resource module" - "100m" - "1024" - "", + "ge-0/0/1This is configured with ansible resource module" + "100m1024", ] + result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) @@ -146,12 +144,11 @@ class TestJunosInterfacesModule(TestJunosModule): ), ) result = self.execute_module(changed=True) - commands = [ '' "ge-0/0/2" "This is configured with ansible" - "100m1024", + "100m1024", ] self.assertEqual(sorted(result["commands"]), commands) @@ -194,7 +191,7 @@ class TestJunosInterfacesModule(TestJunosModule): '' "ge-0/0/2" "This is configured with ansible" - "100m1024", + "100m1024", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), commands) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py index d2dd5c687..1524047f5 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py @@ -50,49 +50,45 @@ class TestJunosL2InterfacesModule(TestJunosModule): "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces.load_config", ) self.load_config = self.mock_load_config.start() - - self.mock_validate_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils.validate_config", - ) - self.validate_config = self.mock_validate_config.start() - self.mock_commit_configuration = patch( "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces.commit_configuration", ) self.mock_commit_configuration = self.mock_commit_configuration.start() - - self.mock_get_config = patch( + self.mock_execute_show_command = patch( "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l2_interfaces.l2_interfaces." - "L2_interfacesFacts.get_config", + "L2_interfacesFacts.get_device_data", ) - self.get_config = self.mock_get_config.start() - self.mock_get_res_config = patch( "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces." "L2_interfaces.get_res_config", ) self.get_res_config = self.mock_get_res_config.start() + self.execute_show_command = self.mock_execute_show_command.start() def tearDown(self): super(TestJunosL2InterfacesModule, self).tearDown() - self.mock_get_config.stop() - self.mock_get_res_config.stop() self.mock_load_config.stop() - self.mock_validate_config.stop() + self.mock_get_res_config.stop() self.mock_lock_configuration.stop() self.mock_unlock_configuration.stop() self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() - def load_fixtures(self, commands=None, format="text", changed=False): - self.get_config.return_value = load_fixture( - "junos_interfaces_config.xml", - ) - if changed: - self.load_config.return_value = load_fixture( - "get_configuration_rpc_reply_diff.txt", - ) - else: - self.load_config.return_value = None + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + if filename: + output = load_fixture(filename) + else: + output = load_fixture("junos_l2_interfaces_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file def test_junos_l2_interfaces_merged(self): set_module_args( @@ -112,91 +108,113 @@ class TestJunosL2InterfacesModule(TestJunosModule): result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) + def test_junos_l2_interfaces_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + with open("gathered_outout.py", "w") as file: + file.write(str(result["gathered"])) + gather_list = [ + {"access": {"vlan": "vlan100"}, "name": "ge-0/0/1", "unit": 0, "enhanced_layer": True}, + { + "name": "ge-0/0/2", + "trunk": {"allowed_vlans": ["vlan200", "vlan300"], "native_vlan": "400"}, + "unit": 0, + "enhanced_layer": True, + }, + ] + self.assertEqual(gather_list, result["gathered"]) + def test_junos_l2_interfaces_merged_idempotent(self): - self.get_config.return_value = load_fixture( - "junos_interfaces_config.xml", - ) - src = load_fixture("junos_l2_interfaces.cfg", content="str") - set_module_args(dict(src=src)) set_module_args( dict( - config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], + config=[ + dict(name="ge-0/0/1", access=dict(vlan="vlan100"), unit=0, enhanced_layer=True), + dict( + name="ge-0/0/2", + trunk=dict(allowed_vlans=["vlan200", "vlan300"], native_vlan="400"), + unit=0, + enhanced_layer=True, + ), + ], state="merged", ), ) - self.execute_module(changed=False, commands=[]) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) def test_junos_l2_interfaces_replaced(self): - self.get_res_config.return_value = load_fixture( - "junos_interfaces_config.xml", - ) set_module_args( dict( - config=[dict(name="ge-0/0/2", access=dict(vlan="vlan200"))], + config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"), enhanced_layer=False)], state="replaced", ), ) commands = [ '' - "ge-0/0/20" - "" - '' - '' - "ge-0/0/2" - "0" - "access" - "vlan200" - "", + "ge-0/0/10" + "access" + "vlan100" + "", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_junos_l2_interfaces_replaced_idempotent(self): - self.get_res_config.return_value = load_fixture( - "junos_interfaces_config.xml", - ) - src = load_fixture("junos_l2_interfaces.cfg", content="str") - set_module_args(dict(src=src)) set_module_args( dict( - config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], + config=[ + dict(name="ge-0/0/1", access=dict(vlan="vlan100"), unit=0, enhanced_layer=True), + dict( + name="ge-0/0/2", + trunk=dict(allowed_vlans=["vlan200", "vlan300"], native_vlan="400"), + unit=0, + enhanced_layer=True, + ), + ], state="replaced", ), ) - self.execute_module(changed=False, commands=[]) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) def test_junos_l2_interfaces_overridden(self): set_module_args( dict( - config=[dict(name="ge-0/0/3", access=dict(vlan="vlan300"))], + config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"), enhanced_layer=False)], state="overridden", ), ) commands = [ '' - "ge-0/0/30" - "" - "accessvlan300" - "", + "ge-0/0/10" + "access" + "vlan100" + "", ] result = self.execute_module(changed=True) - self.assertEqual(sorted(result["commands"]), commands) def test_junos_l2_interfaces_overridden_idempotent(self): - self.get_res_config.return_value = load_fixture( - "junos_interfaces_config.xml", - ) - src = load_fixture("junos_l2_interfaces.cfg", content="str") - set_module_args(dict(src=src)) set_module_args( dict( - config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], + config=[ + dict(name="ge-0/0/1", access=dict(vlan="vlan100"), unit=0, enhanced_layer=True), + dict( + name="ge-0/0/2", + trunk=dict(allowed_vlans=["vlan200", "vlan300"], native_vlan="400"), + unit=0, + enhanced_layer=True, + ), + ], state="overridden", ), ) - self.execute_module(changed=False, commands=[]) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) def test_junos_l2_interfaces_delete(self): self.get_res_config.return_value = load_fixture( @@ -216,22 +234,82 @@ class TestJunosL2InterfacesModule(TestJunosModule): self.assertEqual(sorted(result["commands"]), commands) def test_junos_l2_interfaces_delete_idempotent(self): - set_module_args(dict(config=[dict(name="ge-0/0/4")], state="deleted")) - self.execute_module(changed=False, commands=[]) + set_module_args(dict(config=[dict(name="ge-0/0/3")], state="deleted")) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_l2_interfaces_parsed(self): + parsed_str = """ + + + + + ge-0/0/6 + + 0 + + + trunk + + vlan02 + + + + + + + + ge-0/0/37 + + 0 + + + + vlan31 + + + + + + + + + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = [ + { + "name": "ge-0/0/6", + "trunk": { + "allowed_vlans": ["vlan02"], + }, + "unit": 0, + "enhanced_layer": True, + }, + { + "access": { + "vlan": "vlan31", + }, + "name": "ge-0/0/37", + "unit": 0, + "enhanced_layer": False, + }, + ] + self.assertEqual(result["parsed"], parsed_list) def test_junos_l2_interfaces_rendered(self): set_module_args( dict( - config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], - state="merged", + config=[dict(name="ge-0/0/4", access=dict(vlan="vlan100"))], + state="rendered", ), ) - commands = [ + rendered = ( '' - "ge-0/0/10" - "access" - "vlan100" - "" - "", - ] - self.execute_module(changed=False, commands=commands) + "ge-0/0/40" + "access" + "vlan100" + "" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py index 2a4806839..8f98536c7 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py @@ -29,7 +29,6 @@ from .junos_module import TestJunosModule class TestJunosCommandModule(TestJunosModule): - module = junos_netconf def setUp(self): diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py index 786057021..593acd831 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py @@ -86,8 +86,24 @@ class TestJunosOspfv2Module(TestJunosModule): self.execute_show_command.side_effect = load_from_file - def sort_ospf(self, entry_list): - entry_list.sort(key=lambda i: i.get("name")) + def sorted_xml(self, xml_string): + temp = [] + index = 0 + while index < len(xml_string): + temp_line = "" + if xml_string[index] == "<": + while index < len(xml_string) and xml_string[index] != ">": + temp_line += xml_string[index] + index += 1 + temp_line += ">" + index += 1 + temp.append(temp_line) + else: + while index < len(xml_string) and xml_string[index] != "<": + temp_line += xml_string[index] + index += 1 + temp.append(temp_line) + return sorted(temp) def test_junos_ospfv2_merged(self): set_module_args( @@ -95,15 +111,52 @@ class TestJunosOspfv2Module(TestJunosModule): config=[ dict( router_id="10.200.16.75", + rfc1583compatibility="False", + external_preference=10, + overload=dict( + allow_route_leaking=True, + as_external=True, + stub_network=True, + timeout=1200, + ), + spf_options=dict( + delay=3000, + holddown=4000, + rapid_runs=9, + no_ignore_our_externals=True, + ), + prefix_export_limit=30000, areas=[ dict( area_id="0.0.0.100", stub=dict(default_metric=200, set=True), + area_ranges=[ + dict( + address="10.200.17.0/24", + exact=True, + restrict=True, + override_metric=2000, + ), + ], interfaces=[ dict( name="so-0/0/0.0", priority=3, metric=5, + flood_reduction=False, + passive=True, + bandwidth_based_metrics=[ + dict( + bandwidth="1g", + metric=5, + ), + ], + timers=dict( + dead_interval=4, + hello_interval=2, + poll_interval=2, + retransmit_interval=2, + ), ), ], ), @@ -115,84 +168,74 @@ class TestJunosOspfv2Module(TestJunosModule): ) commands = [ '' - "0.0.0.100so-0/0/0.0" - "35" - "200", + "30004000" + "9" + "1200" + "10" + "30000" + "" + "0.0.0.10010.200.17.0/24" + "2000" + "so-0/0/0.035" + "1g5" + "42" + "22" + "200", '' "10.200.16.75", ] result = self.execute_module(changed=True, commands=commands) self.assertEqual(sorted(result["commands"]), sorted(commands)) - def test_junos_ospfv2_merged_bandwith(self): + def test_junos_ospfv2_merged_areas(self): set_module_args( dict( config=[ dict( - router_id="10.200.16.77", areas=[ dict( - area_id="0.0.0.10", + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + area_ranges=[ + dict( + address="10.200.17.0/24", + ), + dict( + address="10.200.18.0/24", + ), + ], interfaces=[ dict( - name="so-0/0/0.0", - metric=5, + name="so-0/1/0.0", bandwidth_based_metrics=[ - dict(bandwidth="10g", metric=5), + dict( + bandwidth="1g", + metric=5, + ), + dict( + bandwidth="10g", + metric=5, + ), ], ), + dict( + name="so-0/1/0.0", + priority=3, + ), ], ), - ], - ), - ], - state="merged", - ), - ) - result = self.execute_module(changed=True) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn("0.0.0.10", str(result["commands"])) - self.assertIn( - "so-0/0/0.0", - str(result["commands"]), - ) - self.assertIn( - "10g", - str(result["commands"]), - ) - self.assertIn("5", str(result["commands"])) - - def test_junos_ospfv2_merged_02(self): - set_module_args( - dict( - config=[ - dict( - router_id="10.200.16.75", - areas=[ dict( - area_id="0.0.0.100", - area_range="3:3::/64", - stub=dict(set=True), + area_id="0.0.0.200", + area_range="10.200.20.0/24", interfaces=[ dict( - name="so-0/0/0.0", - priority=3, - metric=5, - flood_reduction=True, - passive=True, - timers=dict( - dead_interval=100, - hello_interval=80, - retransmit_interval=90, - transit_delay=True, - ), + name="so-0/1/0.0", + bandwidth_based_metrics=[ + dict( + bandwidth="1g", + metric=5, + ), + ], ), ], ), @@ -202,472 +245,564 @@ class TestJunosOspfv2Module(TestJunosModule): state="merged", ), ) - result = self.execute_module(changed=True) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn( - "0.0.0.100", - str(result["commands"]), - ) - self.assertIn( - "so-0/0/0.0", - str(result["commands"]), - ) - self.assertIn("3", str(result["commands"])) - self.assertIn("", str(result["commands"])) - self.assertIn("5", str(result["commands"])) - self.assertIn("", str(result["commands"])) - self.assertIn( - "100", - str(result["commands"]), - ) - self.assertIn( - "80", - str(result["commands"]), - ) - self.assertIn( - "90", - str(result["commands"]), - ) - self.assertIn("", str(result["commands"])) - self.assertIn( - "", - str(result["commands"]), - ) - self.assertIn("", str(result["commands"])) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn( - "10.200.16.75", - str(result["commands"]), - ) + commands = [ + '' + "0.0.0.100" + "10.200.17.0/24" + "10.200.18.0/24" + "so-0/1/0.0" + "1g5" + "10g5" + "so-0/1/0.03" + "200" + "0.0.0.20010.200.20.0/24" + "so-0/1/0.0" + "1g5" + "", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) - def test_junos_ospfv2_merged_03(self): + def test_junos_ospfv2_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = [ + { + "areas": [ + { + "area_id": "0.0.0.100", + "area_range": "['10.200.17.0/24', '10.200.15.0/24']", + "area_ranges": [ + { + "address": "10.200.17.0/24", + "exact": True, + "override_metric": 2000, + "restrict": True, + }, + { + "address": "10.200.15.0/24", + "exact": True, + "override_metric": 2000, + "restrict": True, + }, + ], + "interfaces": [ + { + "bandwidth_based_metrics": [ + { + "bandwidth": "1g", + "metric": 5, + }, + { + "bandwidth": "10g", + "metric": 40, + }, + ], + "metric": 5, + "name": "so-0/0/0.0", + "passive": True, + "priority": 3, + "timers": { + "dead_interval": 4, + "hello_interval": 2, + "poll_interval": 2, + "retransmit_interval": 2, + }, + }, + ], + "stub": { + "default_metric": 100, + "set": True, + }, + }, + { + "area_id": "0.0.0.200", + "area_range": "['10.200.19.0/24']", + "area_ranges": [ + { + "address": "10.200.19.0/24", + "exact": True, + "override_metric": 2000, + "restrict": True, + }, + ], + "interfaces": [ + { + "authentication": { + "password": "$9$eX2vMLoaUH.5bsgJZjPf369", + "type": { + "simple_password": "$9$eX2vMLoaUH.5bsgJZjPf369", + }, + }, + "name": "so-0/1/0.0", + "priority": 3, + }, + { + "authentication": { + "md5": [ + { + "key": "$9$vBL87Vg4ZiqfDi/t0OSy7-V", + "key_id": 10, + }, + ], + }, + "name": "so-0/2/0.0", + "priority": 2, + }, + ], + }, + { + "area_id": "0.0.0.120", + "area_range": "['10.200.20.0/24']", + "area_ranges": [ + { + "address": "10.200.20.0/24", + "exact": True, + "override_metric": 2000, + "restrict": True, + }, + ], + "interfaces": [ + { + "authentication": { + "md5": [ + { + "key": "$9$IIShrvx7V2oGs2mTF3purev", + "key_id": 10, + }, + ], + }, + "name": "so-0/2/0.1", + "priority": 2, + }, + ], + }, + ], + "overload": { + "allow_route_leaking": True, + "as_external": True, + "stub_network": True, + "timeout": 1200, + }, + "reference_bandwidth": "10g", + "rfc1583compatibility": False, + "router_id": "10.200.16.75", + }, + ] + + def test_junos_ospfv2_replaced(self): set_module_args( dict( config=[ dict( router_id="10.200.16.75", - external_preference=2, - overload=dict(timeout=80), - preference=1, - prefix_export_limit=20000, - reference_bandwidth="10g", - rfc1583compatibility=False, + rfc1583compatibility="False", + external_preference=10, + overload=dict( + allow_route_leaking=True, + as_external=True, + stub_network=True, + timeout=1200, + ), spf_options=dict( - delay=1000, - holddown=15000, + delay=3000, + holddown=4000, rapid_runs=9, + no_ignore_our_externals=True, ), - ), - ], - state="merged", - ), - ) - result = self.execute_module(changed=True) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn( - "1000", - str(result["commands"]), - ) - self.assertIn( - "80", - str(result["commands"]), - ) - self.assertIn( - "2", - str(result["commands"]), - ) - self.assertIn( - "1", - str(result["commands"]), - ) - self.assertIn( - "20000", - str(result["commands"]), - ) - self.assertIn( - "10g", - str(result["commands"]), - ) - self.assertIn("", str(result["commands"])) - self.assertIn( - "10.200.16.75", - str(result["commands"]), - ) - - def test_junos_ospfv2_replaced_01(self): - set_module_args( - dict( - config=[ - dict( - router_id="10.200.16.77", + prefix_export_limit=30000, areas=[ dict( - area_id="0.0.0.10", + area_id="0.0.0.100", stub=dict(default_metric=200, set=True), - interfaces=[ - dict( - name="so-0/0/0.0", - priority=3, - metric=2, - passive=True, - ), + area_ranges=[ dict( - name="so-0/0/0.1", - priority=4, - metric=4, + address="10.200.17.0/24", + exact=True, + restrict=True, + override_metric=2000, ), ], - ), - dict( - area_id="0.0.0.1=30", - interfaces=[ - dict(name="ge-1/1/1.0"), - dict(name="ge-2/2/2.0"), - ], - ), - ], - ), - ], - state="replaced", - ), - ) - result = self.execute_module(changed=True) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn( - '0.0.0.20', - str(result["commands"]), - ) - self.assertIn( - '0.0.0.10', - str(result["commands"]), - ) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn("2", str(result["commands"])) - self.assertIn("3", str(result["commands"])) - self.assertIn( - "so-0/0/0.1", - str(result["commands"]), - ) - self.assertIn( - "200", - str(result["commands"]), - ) - self.assertIn( - "10.200.16.77", - str(result["commands"]), - ) - - def test_junos_ospfv2_merged_01(self): - set_module_args( - dict( - config=[ - dict( - router_id="10.200.16.77", - areas=[ - dict( - area_id="0.0.0.10", - stub=dict(default_metric=200, set=True), interfaces=[ dict( name="so-0/0/0.0", priority=3, - metric=2, + metric=5, + flood_reduction=False, passive=True, - ), - dict( - name="so-0/0/0.1", - priority=4, - metric=4, + bandwidth_based_metrics=[ + dict( + bandwidth="1g", + metric=5, + ), + ], + timers=dict( + dead_interval=4, + hello_interval=2, + poll_interval=2, + retransmit_interval=2, + ), ), ], ), - dict( - area_id="0.0.0.1=30", - interfaces=[ - dict(name="ge-1/1/1.0"), - dict(name="ge-2/2/2.0"), - ], - ), ], ), ], - state="overridden", + state="replaced", ), ) - result = self.execute_module(changed=True) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn( - '0.0.0.20', - str(result["commands"]), - ) - self.assertIn( - '0.0.0.10', - str(result["commands"]), - ) - self.assertIn( - '', - str(result["commands"]), - ) - self.assertIn("2", str(result["commands"])) - self.assertIn("3", str(result["commands"])) - self.assertIn( - "so-0/0/0.1", - str(result["commands"]), - ) - self.assertIn( - "200", - str(result["commands"]), - ) - self.assertIn( - "10.200.16.77", - str(result["commands"]), - ) - - def test_junos_ospfv2_deleted(self): - """ - :return: - """ - set_module_args(dict(config=[], state="deleted")) - commands = [ '' - '0.0.0.10' - '0.0.0.20' - "", + '0.0.0.1000.0.0.200' + '' + '' + '' + "300040009" + "1200" + "" + "1030000" + "0.0.0.10010.200.17.0/24" + "2000" + "so-0/0/0.035" + "1g5" + "42" + "22" + "200", + '' + "10.200.16.75", ] - result = self.execute_module(changed=True) + result = self.execute_module(changed=True, commands=commands) self.assertEqual(sorted(result["commands"]), sorted(commands)) - def test_junos_ospfv2_rendered(self): + def test_junos_ospfv2_overridden(self): set_module_args( dict( config=[ dict( router_id="10.200.16.75", + rfc1583compatibility="False", + external_preference=10, + overload=dict( + allow_route_leaking=True, + as_external=True, + stub_network=True, + timeout=1200, + ), + spf_options=dict( + delay=3000, + holddown=4000, + rapid_runs=9, + no_ignore_our_externals=True, + ), + prefix_export_limit=30000, areas=[ dict( area_id="0.0.0.100", stub=dict(default_metric=200, set=True), + area_ranges=[ + dict( + address="10.200.17.0/24", + exact=True, + restrict=True, + override_metric=2000, + ), + ], interfaces=[ dict( name="so-0/0/0.0", priority=3, metric=5, + flood_reduction=False, + passive=True, + bandwidth_based_metrics=[ + dict( + bandwidth="1g", + metric=5, + ), + ], + timers=dict( + dead_interval=4, + hello_interval=2, + poll_interval=2, + retransmit_interval=2, + ), ), ], ), ], ), ], - state="rendered", + state="overridden", ), ) - rendered = ( + commands = [ '' - "0.0.0.100" - "so-0/0/0.03" - "5" - "200" - ) - result = self.execute_module(changed=False) - self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + '0.0.0.100' + '0.0.0.200' + '' + '' + '' + "30004000" + "9" + "1200" + "" + "10" + "30000" + "0.0.0.100" + "10.200.17.0/24" + "2000" + "so-0/0/0.035" + "" + "1g5" + "42" + "22" + "200" + "", + '' + "10.200.16.75", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) - def test_junos_vlans_gathered(self): - """ - :return: - """ - set_module_args(dict(state="gathered")) - result = self.execute_module(changed=False) - gather_list = [ + def test_junos_ospfv2_rendered(self): + set_module_args( dict( - router_id="10.200.16.77", - areas=[ - dict( - area_id="0.0.0.10", - stub=dict(default_metric=200, set=True), - interfaces=[ - dict( - name="so-0/0/0.0", - priority=3, - metric=5, - passive=True, - flood_reduction=True, - ), - ], - ), - dict( - area_id="0.0.0.20", - interfaces=[ - dict(name="ge-1/1/0.0"), - dict(name="ge-2/2/0.0"), - ], - ), - ], + config=[], + state="deleted", ), + ) + commands = [ + '' + '0.0.0.100' + '' + '', ] - self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) - def test_junos_vlans_parsed(self): + def test_junos_ospfv2_parsed(self): parsed_str = """ - - - 18.4R1-S2.4 - - - - 0.0.0.200 - - so-0/0/0.1 - 3 - 5 - - - - 0.0.0.100 - - 200 - - - so-0/0/0.0 - 5 - 3 - - - 10g - 5 - - - - - - - - 10.200.16.7 - - - + + + + + + 3000 + 4000 + 9 + + + 20000 + + 1200 + + + + + 10g + + + 0.0.0.100 + + 100 + + + 10.200.17.0/24 + + + 2000 + + + 10.200.15.0/24 + + + 2000 + + + so-0/0/0.0 + + + + + 1g + 5 + + + 10g + 40 + + + 5 + 3 + 2 + 2 + 4 + 2 + + + + + + + """ set_module_args(dict(running_config=parsed_str, state="parsed")) result = self.execute_module(changed=False) - parsed_list = [ + parsed_dict = [ { "areas": [ - { - "area_id": "0.0.0.200", - "interfaces": [ - {"metric": 3, "name": "so-0/0/0.1", "priority": 5}, - ], - }, { "area_id": "0.0.0.100", "interfaces": [ { - "bandwidth_based_metrics": [ - {"metric": 5, "bandwidth": "10g"}, - ], - "metric": 5, "name": "so-0/0/0.0", "priority": 3, + "metric": 5, + "timers": { + "hello_interval": 2, + "dead_interval": 4, + "retransmit_interval": 2, + "poll_interval": 2, + }, + "passive": True, + "bandwidth_based_metrics": [ + { + "metric": 5, + "bandwidth": "1g", + }, + { + "metric": 40, + "bandwidth": "10g", + }, + ], + }, + ], + "area_range": "['10.200.17.0/24', '10.200.15.0/24']", + "area_ranges": [ + { + "address": "10.200.17.0/24", + "override_metric": 2000, + "exact": True, + "restrict": True, + }, + { + "address": "10.200.15.0/24", + "override_metric": 2000, + "exact": True, + "restrict": True, }, ], - "stub": {"default_metric": 200, "set": True}, + "stub": { + "set": True, + "default_metric": 100, + }, }, ], - "router_id": "10.200.16.7", + "overload": { + "allow_route_leaking": True, + "as_external": True, + "stub_network": True, + "timeout": 1200, + }, + "prefix_export_limit": 20000, + "reference_bandwidth": "10g", + "rfc1583compatibility": False, + "spf_options": { + "delay": 3000, + "holddown": 4000, + "rapid_runs": 9, + "no_ignore_our_externals": True, + }, }, ] - self.assertEqual(result["parsed"], parsed_list) - def test_junos_vlans_parsed_02(self): - parsed_str = """ - - - 18.4R1-S2.4 - - - - 0.0.0.200 - - so-0/0/0.1 - 3 - 5 - - - - 0.0.0.100 - - 200 - - - so-0/0/0.0 - 5 - 3 - - - 10g - 5 - - - 1g - 5 - - - - - - - - 10.200.16.7 - - - - """ - set_module_args(dict(running_config=parsed_str, state="parsed")) - result = self.execute_module(changed=False) - parsed_list = [ - { - "areas": [ - { - "area_id": "0.0.0.200", - "interfaces": [ - {"metric": 3, "name": "so-0/0/0.1", "priority": 5}, - ], - }, - { - "area_id": "0.0.0.100", - "interfaces": [ - { - "bandwidth_based_metrics": [ - {"metric": 5, "bandwidth": "10g"}, - {"metric": 5, "bandwidth": "1g"}, + def test_junos_ospfv2_rendered(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + rfc1583compatibility="False", + external_preference=10, + overload=dict( + allow_route_leaking=True, + as_external=True, + stub_network=True, + timeout=1200, + ), + spf_options=dict( + delay=3000, + holddown=4000, + rapid_runs=9, + no_ignore_our_externals=True, + ), + prefix_export_limit=30000, + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + area_ranges=[ + dict( + address="10.200.17.0/24", + exact=True, + restrict=True, + override_metric=2000, + ), ], - "metric": 5, - "name": "so-0/0/0.0", - "priority": 3, - }, + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + flood_reduction=False, + passive=True, + bandwidth_based_metrics=[ + dict( + bandwidth="1g", + metric=5, + ), + ], + timers=dict( + dead_interval=4, + hello_interval=2, + poll_interval=2, + retransmit_interval=2, + ), + ), + ], + ), ], - "stub": {"default_metric": 200, "set": True}, - }, + ), ], - "router_id": "10.200.16.7", - }, - ] - self.assertEqual(result["parsed"], parsed_list) + state="rendered", + ), + ) + rendered = ( + '' + "30004000" + "9" + "1200" + "" + "10" + "30000" + "0.0.0.100" + "10.200.17.0/24" + "2000" + "so-0/0/0.0" + "35" + "1g" + "5" + "42" + "2" + "2" + "200" + "" + ) + result = self.execute_module(changed=False) + self.assertEqual( + self.sorted_xml(result["rendered"]), + self.sorted_xml(rendered), + ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py index 054947448..a96d95bac 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py @@ -352,7 +352,6 @@ class TestJunosOspfv3Module(TestJunosModule): self.execute_module(changed=False, commands=[]) def test_junos_ospfv3_parsed(self): - set_module_args( dict( running_config='\n' diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py index 38e3599d0..f679fa5a3 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py @@ -41,7 +41,6 @@ from ansible_collections.junipernetworks.junos.plugins.modules import junos_pack class TestJunosPackageModule(TestJunosModule): - module = junos_package def setUp(self): @@ -79,3 +78,14 @@ class TestJunosPackageModule(TestJunosModule): args, kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args self.assertEqual(args, ("junos-vsrx-12.1X46-D10.2-domestic.tgz",)) self.assertEqual(kwargs["no_copy"], True) + + def test_junos_package_src_unlink(self): + jnpr_mock.junos.utils.sw.SW().install.return_value = 1 + set_module_args( + dict(src="junos-vsrx-12.1X46-D10.2-domestic.tgz", unlink=True), + ) + self.execute_module(changed=True) + + args, kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args + self.assertEqual(args, ("junos-vsrx-12.1X46-D10.2-domestic.tgz",)) + self.assertEqual(kwargs["unlink"], True) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py index de66f103d..4c914aa3d 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py @@ -44,7 +44,6 @@ RPC_CLI_MAP = { class TestJunosCommandModule(TestJunosModule): - module = junos_rpc def setUp(self): diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py index 6286d57de..0788d6523 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py @@ -43,7 +43,6 @@ from ansible_collections.junipernetworks.junos.plugins.modules import junos_scp class TestJunosScpModule(TestJunosModule): - module = junos_scp def setUp(self): diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py index bdb94ed6c..b41161672 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py @@ -346,7 +346,6 @@ class TestJunosSecurity_policiesModule(TestJunosModule): ) def test_junos_security_policies_merged_02(self): - set_module_args( dict( config={ diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py index e593037dc..764d1a7e8 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py @@ -246,6 +246,256 @@ class TestJunosSecurity_zonesModule(TestJunosModule): self.sorted_xml(str(result["commands"])), ) + def test_junos_security_zones_parsed(self): + parsed_str = """ + + + 18.4R1-S2.4 + + + + + test description + + + all + + + bgp + + + + all + + + dhcp + + + + + ge-0/0/1.0 + + + ge-0/0/2.0 + + test_screen + + + + test_sec_zone1 + +
+ test_adr1 + 10.0.0.0/24 + test desc +
+
+ test_adr2 + + 1.1.1.1 + + +
+
+ test_adr3 + + 10.2.0.1 + + 10.2.0.2 + + +
+
+ test_adr4 + + 10.3.0.1/24 + +
+
+ test_adr5 + 10.1.0.0/24 + test desc +
+ + test_adrset1 +
+ test_adr1 +
+
+ test_adr2 +
+
+ + test_adrset2 +
+ test_adr3 +
+
+ test_adr4 +
+
+ + test_adrset3 +
+ test_adr5 +
+ + test_adrset1 + + + test_adrset2 + + test description +
+
+ + test_profile + + + allow-any-host + 20 + + + + test description + + + + all + + + bgp + + + + all + + + dhcp + + + + + ge-0/0/3.0 + + test_screen + + + +
+
+
+
+
+ """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "functional_zone_management": { + "description": "test description 2", + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + {"except": True, "name": "bfd"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + {"except": True, "name": "dhcpv6"}, + ], + }, + "interfaces": ["ge-0/0/1.0", "ge-0/0/2.0"], + "screen": "test_screen", + }, + "zones": [ + { + "address_book": { + "address_sets": [ + { + "addresses": ["test_adr1", "test_adr2"], + "name": "test_adrset1", + }, + { + "addresses": ["test_adr3", "test_adr4"], + "name": "test_adrset2", + }, + { + "address_sets": [ + "test_adrset1", + "test_adrset2", + ], + "addresses": ["test_adr5"], + "description": "test description", + "name": "test_adrset3", + }, + ], + "addresses": [ + { + "description": "test desc", + "ip_prefix": "10.0.0.0/24", + "name": "test_adr1", + }, + { + "dns_name": { + "ipv6_only": True, + "name": "1.1.1.1", + }, + "name": "test_adr2", + }, + { + "name": "test_adr3", + "range_address": { + "from": "10.2.0.1", + "to": "10.2.0.2", + }, + }, + { + "name": "test_adr4", + "wildcard_address": "10.3.0.1/24", + }, + { + "description": "test desc", + "ip_prefix": "10.1.0.0/24", + "name": "test_adr5", + }, + ], + }, + "advance_policy_based_routing_profile": "test_profile", + "advanced_connection_tracking": { + "mode": "allow-any-host", + "timeout": "20", + "track_all_policies_to_this_zone": True, + }, + "application_tracking": True, + "description": "test description", + "enable_reverse_reroute": True, + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": {"ge-0/0/3.0"}, + "name": "test_sec_zone1", + "screen": "test_screen", + "source_identity_log": True, + "tcp_rst": True, + "unidirectional_session_refreshing": True, + }, + { + "name": "test_sec_zone2", + "source_identity_log": True, + "tcp_rst": True, + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + def test_junos_security_zones_parsed_01(self): parsed_str = """ diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py index db31904e8..ed73b8c5a 100644 --- a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py @@ -103,6 +103,199 @@ class TestJunosSnmp_serverModule(TestJunosModule): str(result["commands"]), ) + def test_junos_snmp_server_merged_views(self): + set_module_args( + dict( + config=dict( + views=[ + dict( + name="all", + oids=[dict(oid=".1")], + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '', + str(result["commands"]), + ) + self.assertIn( + "all.1", + str(result["commands"]), + ) + self.assertIn( + "", + str(result["commands"]), + ) + + def test_junos_snmp_server_merged_trap_options(self): + set_module_args( + dict( + config=dict( + trap_options=dict( + agent_address=dict( + outgoing_interface=True, + ), + context_oid=True, + ), + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '', + str(result["commands"]), + ) + self.assertIn( + "outgoing-interface", + str(result["commands"]), + ) + self.assertIn( + "", + str(result["commands"]), + ) + + def test_junos_snmp_server_merged_trap_groups(self): + set_module_args( + dict( + config=dict( + trap_groups=[ + dict( + categories=dict( + authentication=True, + ), + name="egress", + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '', + str(result["commands"]), + ) + self.assertIn( + "egress", + str(result["commands"]), + ) + self.assertIn( + "", + str(result["commands"]), + ) + + def test_junos_snmp_server_merged_trap_groups_02(self): + set_module_args( + dict( + config=dict( + trap_groups=[ + dict( + categories=dict( + chassis=True, + chassis_cluster=True, + configuration=True, + dot3oam_events=True, + link=True, + ), + name="monitor", + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '', + str(result["commands"]), + ) + self.assertIn( + "", + str(result["commands"]), + ) + + def test_junos_snmp_server_merged_trap_groups_otn_alrams(self): + set_module_args( + dict( + config=dict( + trap_groups=[ + dict( + categories=dict( + otn_alarms=dict( + oc_lof=True, + oc_lom=True, + oc_los=True, + ), + ), + name="monitor", + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '', + str(result["commands"]), + ) + self.assertIn( + "", + str(result["commands"]), + ) + self.assertIn( + "monitor", + str(result["commands"]), + ) + + def test_junos_snmp_server_merged_trap_options_set(self): + set_module_args( + dict( + config=dict( + trap_options=dict( + set=True, + ), + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + expected_commands = '' + self.assertEqual(expected_commands, "/n".join(result["commands"])) + + def test_junos_snmp_server_merged_trap_options_02(self): + set_module_args( + dict( + config=dict( + trap_options=dict( + enterprise_oid=True, + source_address=dict( + address="192.168.2.0", + ), + ), + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '', + str(result["commands"]), + ) + self.assertIn( + "192.168.2.0", + str(result["commands"]), + ) + self.assertIn( + "", + str(result["commands"]), + ) + def test_junos_snmp_server_merged_client_02(self): set_module_args( dict( -- cgit v1.2.3