summaryrefslogtreecommitdiffstats
path: root/ansible_collections/junipernetworks/junos/tests/unit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
commit7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch)
treeefb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/junipernetworks/junos/tests/unit
parentReleasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff)
downloadansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.tar.xz
ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.zip
Merging upstream version 9.4.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/junipernetworks/junos/tests/unit')
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/compat/builtins.py35
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/compat/mock.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/mock/loader.py12
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l2_interfaces_config.cfg53
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2_config.cfg242
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/junos_module.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py11
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py13
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py230
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py1023
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py12
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py1
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py250
-rw-r--r--ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py193
20 files changed, 1472 insertions, 611 deletions
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 <tkuratomi@ansible.com>
-#
-# 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 <http://www.gnu.org/licenses/>.
-
-# 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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
+ <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
+ <interfaces>
+ <interface>
+ <name>ge-0/0/1</name>
+ <description>Configured by Ansible</description>
+ <disable/>
+ <speed>100m</speed>
+ <mtu>1024</mtu>
+ <hold-time>
+ <up>2000</up>
+ <down>2200</down>
+ </hold-time>
+ <link-mode>full-duplex</link-mode>
+ <unit>
+ <name>0</name>
+ <family>
+ <ethernet-switching>
+ <interface-mode>access</interface-mode>
+ <vlan>
+ <members>vlan100</members>
+ </vlan>
+ </ethernet-switching>
+ </family>
+ </unit>
+ </interface>
+ <interface>
+ <name>ge-0/0/2</name>
+ <description>Configured by Ansible</description>
+ <native-vlan-id>400</native-vlan-id>
+ <speed>10m</speed>
+ <mtu>2048</mtu>
+ <hold-time>
+ <up>3000</up>
+ <down>3200</down>
+ </hold-time>
+ <unit>
+ <name>0</name>
+ <family>
+ <ethernet-switching>
+ <interface-mode>trunk</interface-mode>
+ <vlan>
+ <members>vlan200</members>
+ <members>vlan300</members>
+ </vlan>
+ </ethernet-switching>
+ </family>
+ </unit>
+ </interface>
+ </interfaces>
+ </configuration>
+</rpc-reply>
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 @@
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
- <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
- <protocols>
- <ospf>
- <area>
- <name>0.0.0.10</name>
- <stub>
- <default-metric>200</default-metric>
- </stub>
- <interface>
- <name>so-0/0/0.0</name>
- <passive></passive>
- <metric>5</metric>
- <priority>3</priority>
- <flood-reduction/>
- </interface>
- </area>
- <area>
- <name>0.0.0.20</name>
- <interface>
- <name>ge-1/1/0.0</name>
- </interface>
- <interface>
- <name>ge-2/2/0.0</name>
- </interface>
- </area>
- </ospf>
- </protocols>
- <routing-options>
- <router-id>10.200.16.77</router-id>
- </routing-options>
- </configuration>
+ <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
+ <protocols>
+ <ospf>
+ <spf-options>
+ <delay>3000</delay>
+ <holddown>4000</holddown>
+ <rapid-runs>9</rapid-runs>
+ <no-ignore-our-externals/>
+ </spf-options>
+ <prefix-export-limit>20000</prefix-export-limit>
+ <overload>
+ <timeout>1200</timeout>
+ <allow-route-leaking/>
+ <stub-network/>
+ <as-external/>
+ </overload>
+ <reference-bandwidth>10g</reference-bandwidth>
+ <no-rfc-1583/>
+ <area>
+ <name>0.0.0.100</name>
+ <stub>
+ <default-metric>100</default-metric>
+ </stub>
+ <area-range>
+ <name>10.200.17.0/24</name>
+ <restrict/>
+ <exact/>
+ <override-metric>2000</override-metric>
+ </area-range>
+ <area-range>
+ <name>10.200.15.0/24</name>
+ <restrict/>
+ <exact/>
+ <override-metric>2000</override-metric>
+ </area-range>
+ <interface>
+ <name>so-0/0/0.0</name>
+ <passive>
+ </passive>
+ <bandwidth-based-metrics>
+ <bandwidth>
+ <name>1g</name>
+ <metric>5</metric>
+ </bandwidth>
+ <bandwidth>
+ <name>10g</name>
+ <metric>40</metric>
+ </bandwidth>
+ </bandwidth-based-metrics>
+ <metric>5</metric>
+ <priority>3</priority>
+ <retransmit-interval>2</retransmit-interval>
+ <hello-interval>2</hello-interval>
+ <dead-interval>4</dead-interval>
+ <poll-interval>2</poll-interval>
+ </interface>
+ </area>
+ <area>
+ <name>0.0.0.200</name>
+ <stub>
+ <default-metric>100</default-metric>
+ </stub>
+ <area-range>
+ <name>10.400.17.0/24</name>
+ <restrict/>
+ <exact/>
+ <override-metric>2000</override-metric>
+ </area-range>
+ <interface>
+ <name>so-0/0/1.0</name>
+ <passive>
+ </passive>
+ <bandwidth-based-metrics>
+ <bandwidth>
+ <name>1g</name>
+ <metric>5</metric>
+ </bandwidth>
+ </bandwidth-based-metrics>
+ <authentication>
+ <md5>
+ <name>20</name>
+ <key>$9$.fz6pu1crvEc-w2gDjz36</key>
+ <start-time>2023-7-12.03:00:00 +0000</start-time>
+ </md5>
+ <md5>
+ <name>10</name>
+ <key>$9$m5F/u0ISlMhSdsg4jiFn/</key>
+ <start-time>2023-7-12.03:00:00 +0000</start-time>
+ </md5>
+ </authentication>
+ </interface>
+ <interface>
+ <name>so-0/0/2.0</name>
+ <authentication>
+ <md5>
+ <name>20</name>
+ <key>$9$.fz6pu1crvEc-w2gDjz36</key>
+ <start-time>2023-7-12.03:00:00 +0000</start-time>
+ </md5>
+ </authentication>
+ </interface>
+ <interface>
+ <name>so-0/0/3.0</name>
+ <authentication>
+ <md5>
+ <name>20</name>
+ <key>$9$.fz6pu1crvEc-w2gDjz36</key>
+ <start-time>2023-7-12.03:00:00 +0000</start-time>
+ </md5>
+ </authentication>
+ </interface>
+ </area>
+ </ospf>
+ <bgp>
+ <family>
+ <inet>
+ <unicast>
+ <local-ipv4-address>9.9.9.9</local-ipv4-address>
+ <extended-nexthop/>
+ <extended-nexthop-color/>
+ </unicast>
+ <flow>
+ <loops>
+ <loops>4</loops>
+ </loops>
+ <no-install/>
+ <output-queue-priority>
+ <expedited/>
+ </output-queue-priority>
+ <legacy-redirect-ip-action>
+ <receive/>
+ <send/>
+ </legacy-redirect-ip-action>
+ <secondary-independent-resolution/>
+ </flow>
+ <any>
+ <accepted-prefix-limit>
+ <maximum>20</maximum>
+ <teardown>
+ <limit-threshold>99</limit-threshold>
+ <idle-timeout>
+ <timeout>2000</timeout>
+ </idle-timeout>
+ </teardown>
+ </accepted-prefix-limit>
+ <damping/>
+ <delay-route-advertisements>
+ <minimum-delay>
+ <routing-uptime>23000</routing-uptime>
+ <inbound-convergence>32000</inbound-convergence>
+ </minimum-delay>
+ <maximum-delay>
+ <route-age>20</route-age>
+ <routing-uptime>32000</routing-uptime>
+ </maximum-delay>
+ </delay-route-advertisements>
+ <defer-initial-multipath-build>
+ <maximum-delay>2</maximum-delay>
+ </defer-initial-multipath-build>
+ <graceful-restart>
+ <forwarding-state-bit>from-fib</forwarding-state-bit>
+ </graceful-restart>
+ </any>
+ <labeled-unicast>
+ <prefix-limit>
+ <maximum>20</maximum>
+ <teardown>
+ <limit-threshold>99</limit-threshold>
+ <idle-timeout>
+ <forever/>
+ </idle-timeout>
+ </teardown>
+ </prefix-limit>
+ <route-refresh-priority>
+ <priority>3</priority>
+ </route-refresh-priority>
+ <per-prefix-label/>
+ <per-group-label/>
+ <rib>
+ <inet.3/>
+ </rib>
+ <explicit-null>
+ <connected-only/>
+ </explicit-null>
+ <resolve-vpn/>
+ <entropy-label>
+ <no-next-hop-validation/>
+ </entropy-label>
+ </labeled-unicast>
+ </inet>
+ <evpn>
+ <signaling>
+ <accepted-prefix-limit>
+ <maximum>20</maximum>
+ <teardown>
+ <limit-threshold>98</limit-threshold>
+ <idle-timeout>
+ <timeout>2001</timeout>
+ </idle-timeout>
+ </teardown>
+ </accepted-prefix-limit>
+ <damping/>
+ <defer-initial-multipath-build>
+ <maximum-delay>2</maximum-delay>
+ </defer-initial-multipath-build>
+ </signaling>
+ </evpn>
+ </family>
+ </bgp>
+ </protocols>
+</configuration>
</rpc-reply>
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 = [
'<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
- "<nc:interface><nc:name>ge-0/0/1</nc:name>"
- "<nc:description>This is configured with ansible resource module</nc:description>"
- "<nc:speed>100m</nc:speed>"
- "<nc:mtu>1024</nc:mtu>"
- "</nc:interface></nc:interfaces>",
+ "<nc:interface><nc:name>ge-0/0/1</nc:name><nc:description>This is configured with ansible resource module</nc:description>"
+ "<nc:speed>100m</nc:speed><nc:mtu>1024</nc:mtu><nc:enable/></nc:interface></nc:interfaces>",
]
+
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 = [
'<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
"<nc:interface><nc:name>ge-0/0/2</nc:name>"
"<nc:description>This is configured with ansible</nc:description>"
- "<nc:speed>100m</nc:speed><nc:mtu>1024</nc:mtu></nc:interface></nc:interfaces>",
+ "<nc:speed>100m</nc:speed><nc:mtu>1024</nc:mtu><nc:enable/></nc:interface></nc:interfaces>",
]
self.assertEqual(sorted(result["commands"]), commands)
@@ -194,7 +191,7 @@ class TestJunosInterfacesModule(TestJunosModule):
'<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
"<nc:interface><nc:name>ge-0/0/2</nc:name>"
"<nc:description>This is configured with ansible</nc:description>"
- "<nc:speed>100m</nc:speed><nc:mtu>1024</nc:mtu></nc:interface></nc:interfaces>",
+ "<nc:speed>100m</nc:speed><nc:mtu>1024</nc:mtu><nc:enable/></nc:interface></nc:interfaces>",
]
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 = [
'<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>'
- "<nc:name>ge-0/0/2</nc:name><nc:unit><nc:name>0</nc:name>"
- "<nc:family><nc:ethernet-switching>"
- '<nc:interface-mode delete="delete"/><nc:vlan delete="delete"/>'
- '</nc:ethernet-switching></nc:family></nc:unit><nc:native-vlan-id delete="delete"/>'
- "</nc:interface><nc:interface><nc:name>ge-0/0/2</nc:name>"
- "<nc:unit><nc:name>0</nc:name><nc:family>"
- "<nc:ethernet-switching><nc:interface-mode>access</nc:interface-mode>"
- "<nc:vlan><nc:members>vlan200</nc:members></nc:vlan>"
- "</nc:ethernet-switching></nc:family></nc:unit></nc:interface></nc:interfaces>",
+ "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>"
+ "<nc:family><nc:ethernet-switching><nc:port-mode>access</nc:port-mode>"
+ "<nc:vlan><nc:members>vlan100</nc:members></nc:vlan></nc:ethernet-switching></nc:family>"
+ "</nc:unit></nc:interface></nc:interfaces>",
]
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 = [
'<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>'
- "<nc:name>ge-0/0/3</nc:name><nc:unit><nc:name>0</nc:name>"
- "<nc:family><nc:ethernet-switching>"
- "<nc:interface-mode>access</nc:interface-mode><nc:vlan><nc:members>vlan300</nc:members></nc:vlan>"
- "</nc:ethernet-switching></nc:family></nc:unit></nc:interface></nc:interfaces>",
+ "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>"
+ "<nc:family><nc:ethernet-switching><nc:port-mode>access</nc:port-mode>"
+ "<nc:vlan><nc:members>vlan100</nc:members></nc:vlan></nc:ethernet-switching></nc:family>"
+ "</nc:unit></nc:interface></nc:interfaces>",
]
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 = """
+ <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
+ <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
+ <interfaces>
+ <interface>
+ <name>ge-0/0/6</name>
+ <unit>
+ <name>0</name>
+ <family>
+ <ethernet-switching>
+ <interface-mode>trunk</interface-mode>
+ <vlan>
+ <members>vlan02</members>
+ </vlan>
+ </ethernet-switching>
+ </family>
+ </unit>
+ </interface>
+
+ <interface>
+ <name>ge-0/0/37</name>
+ <unit>
+ <name>0</name>
+ <family>
+ <ethernet-switching>
+ <vlan>
+ <members>vlan31</members>
+ </vlan>
+ </ethernet-switching>
+ </family>
+ </unit>
+ </interface>
+ </interfaces>
+ </configuration>
+ </rpc-reply>
+ """
+ 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 = (
'<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>'
- "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>"
- "<nc:family><nc:ethernet-switching><nc:interface-mode>access</nc:interface-mode>"
- "<nc:vlan><nc:members>vlan100</nc:members>"
- "</nc:vlan></nc:ethernet-switching></nc:family></nc:unit>"
- "</nc:interface></nc:interfaces>",
- ]
- self.execute_module(changed=False, commands=commands)
+ "<nc:name>ge-0/0/4</nc:name><nc:unit><nc:name>0</nc:name><nc:family>"
+ "<nc:ethernet-switching><nc:interface-mode>access</nc:interface-mode><nc:vlan>"
+ "<nc:members>vlan100</nc:members></nc:vlan></nc:ethernet-switching></nc:family>"
+ "</nc:unit></nc:interface></nc:interfaces>"
+ )
+ 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 = [
'<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf>'
- "<nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name>"
- "<nc:priority>3</nc:priority><nc:metric>5</nc:metric></nc:interface><nc:stub>"
- "<nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>",
+ "<nc:spf-options><nc:delay>3000</nc:delay><nc:holddown>4000</nc:holddown>"
+ "<nc:rapid-runs>9</nc:rapid-runs><nc:no-ignore-our-externals/></nc:spf-options>"
+ "<nc:overload><nc:timeout>1200</nc:timeout><nc:allow-route-leaking/><nc:as-external/><nc:stub-network/></nc:overload>"
+ "<nc:external-preference>10</nc:external-preference>"
+ "<nc:prefix-export-limit>30000</nc:prefix-export-limit>"
+ "<nc:no-rfc-1583/>"
+ "<nc:area><nc:name>0.0.0.100</nc:name><nc:area-range><nc:name>10.200.17.0/24</nc:name>"
+ "<nc:exact/><nc:restrict/><nc:override-metric>2000</nc:override-metric></nc:area-range>"
+ "<nc:interface><nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority><nc:metric>5</nc:metric>"
+ "<nc:passive/><nc:bandwidth-based-metrics><nc:bandwidth><nc:name>1g</nc:name><nc:metric>5</nc:metric>"
+ "</nc:bandwidth></nc:bandwidth-based-metrics><nc:dead-interval>4</nc:dead-interval><nc:hello-interval>2</nc:hello-interval>"
+ "<nc:poll-interval>2</nc:poll-interval><nc:retransmit-interval>2</nc:retransmit-interval></nc:interface>"
+ "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>",
'<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
"<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>",
]
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(
- '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn(
- '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn("<nc:name>0.0.0.10</nc:name>", str(result["commands"]))
- self.assertIn(
- "<nc:interface><nc:name>so-0/0/0.0</nc:name>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:bandwidth-based-metrics><nc:bandwidth><nc:name>10g</nc:name>",
- str(result["commands"]),
- )
- self.assertIn("<nc:metric>5</nc:metric>", 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(
- '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:ospf><nc:area><nc:name>0.0.0.100</nc:name>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:interface><nc:name>so-0/0/0.0</nc:name>",
- str(result["commands"]),
- )
- self.assertIn("<nc:priority>3</nc:priority>", str(result["commands"]))
- self.assertIn("<nc:flood-reduction/>", str(result["commands"]))
- self.assertIn("<nc:metric>5</nc:metric>", str(result["commands"]))
- self.assertIn("<nc:passive/>", str(result["commands"]))
- self.assertIn(
- "<nc:dead-interval>100</nc:dead-interval>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:hello-interval>80</nc:hello-interval>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:retransmit-interval>90</nc:retransmit-interval>",
- str(result["commands"]),
- )
- self.assertIn("</nc:interface>", str(result["commands"]))
- self.assertIn(
- "<nc:stub/></nc:area></nc:ospf></nc:protocols>",
- str(result["commands"]),
- )
- self.assertIn("</nc:interface>", str(result["commands"]))
- self.assertIn(
- '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>",
- str(result["commands"]),
- )
+ commands = [
+ '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
+ "<nc:ospf><nc:area><nc:name>0.0.0.100</nc:name><nc:area-range>"
+ "<nc:name>10.200.17.0/24</nc:name></nc:area-range><nc:area-range>"
+ "<nc:name>10.200.18.0/24</nc:name></nc:area-range><nc:interface>"
+ "<nc:name>so-0/1/0.0</nc:name><nc:bandwidth-based-metrics><nc:bandwidth>"
+ "<nc:name>1g</nc:name><nc:metric>5</nc:metric></nc:bandwidth><nc:bandwidth>"
+ "<nc:name>10g</nc:name><nc:metric>5</nc:metric></nc:bandwidth></nc:bandwidth-based-metrics>"
+ "</nc:interface><nc:interface><nc:name>so-0/1/0.0</nc:name><nc:priority>3</nc:priority>"
+ "</nc:interface><nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area>"
+ "<nc:area><nc:name>0.0.0.200</nc:name><nc:area-range><nc:name>10.200.20.0/24</nc:name>"
+ "</nc:area-range><nc:interface><nc:name>so-0/1/0.0</nc:name><nc:bandwidth-based-metrics>"
+ "<nc:bandwidth><nc:name>1g</nc:name><nc:metric>5</nc:metric></nc:bandwidth>"
+ "</nc:bandwidth-based-metrics></nc:interface></nc:area></nc:ospf></nc:protocols>",
+ ]
+ 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(
- '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:spf-options><nc:delay>1000</nc:delay>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:overload><nc:timeout>80</nc:timeout></nc:overload>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:external-preference>2</nc:external-preference>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:preference>1</nc:preference>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:prefix-export-limit>20000</nc:prefix-export-limit>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:reference-bandwidth>10g</nc:reference-bandwidth>",
- str(result["commands"]),
- )
- self.assertIn("<nc:no-rfc-1583/>", str(result["commands"]))
- self.assertIn(
- "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>",
- 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(
- '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn(
- '<nc:ospf><nc:area delete="delete">0.0.0.20</nc:area></nc:ospf>',
- str(result["commands"]),
- )
- self.assertIn(
- '<nc:ospf><nc:area delete="delete">0.0.0.10</nc:area></nc:ospf>',
- str(result["commands"]),
- )
- self.assertIn(
- '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn("<nc:metric>2</nc:metric>", str(result["commands"]))
- self.assertIn("<nc:priority>3</nc:priority>", str(result["commands"]))
- self.assertIn(
- "<nc:interface><nc:name>so-0/0/0.1</nc:name>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:router-id>10.200.16.77</nc:router-id></nc:routing-options>",
- 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(
- '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn(
- '<nc:ospf><nc:area delete="delete">0.0.0.20</nc:area></nc:ospf>',
- str(result["commands"]),
- )
- self.assertIn(
- '<nc:ospf><nc:area delete="delete">0.0.0.10</nc:area></nc:ospf>',
- str(result["commands"]),
- )
- self.assertIn(
- '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
- str(result["commands"]),
- )
- self.assertIn("<nc:metric>2</nc:metric>", str(result["commands"]))
- self.assertIn("<nc:priority>3</nc:priority>", str(result["commands"]))
- self.assertIn(
- "<nc:interface><nc:name>so-0/0/0.1</nc:name>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub>",
- str(result["commands"]),
- )
- self.assertIn(
- "<nc:router-id>10.200.16.77</nc:router-id></nc:routing-options>",
- str(result["commands"]),
- )
-
- def test_junos_ospfv2_deleted(self):
- """
- :return:
- """
- set_module_args(dict(config=[], state="deleted"))
-
commands = [
'<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
- '<nc:ospf><nc:area delete="delete">0.0.0.10</nc:area></nc:ospf>'
- '<nc:ospf><nc:area delete="delete">0.0.0.20</nc:area></nc:ospf>'
- "</nc:protocols>",
+ '<nc:ospf><nc:area delete="delete">0.0.0.100</nc:area><nc:area delete="delete">0.0.0.200</nc:area>'
+ '<nc:spf-options delete="delete"/><nc:reference-bandwidth delete="delete"/>'
+ '<nc:no-rfc-1583 delete="delete"/><nc:overload delete="delete"/>'
+ '<nc:prefix-export-limit delete="delete"/></nc:ospf><nc:ospf>'
+ "<nc:spf-options><nc:delay>3000</nc:delay><nc:holddown>4000</nc:holddown><nc:rapid-runs>9</nc:rapid-runs>"
+ "<nc:no-ignore-our-externals/></nc:spf-options><nc:overload><nc:timeout>1200</nc:timeout>"
+ "<nc:allow-route-leaking/><nc:as-external/><nc:stub-network/></nc:overload>"
+ "<nc:external-preference>10</nc:external-preference><nc:prefix-export-limit>30000</nc:prefix-export-limit>"
+ "<nc:no-rfc-1583/><nc:area><nc:name>0.0.0.100</nc:name><nc:area-range><nc:name>10.200.17.0/24</nc:name>"
+ "<nc:exact/><nc:restrict/><nc:override-metric>2000</nc:override-metric></nc:area-range><nc:interface>"
+ "<nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority><nc:metric>5</nc:metric><nc:passive/>"
+ "<nc:bandwidth-based-metrics><nc:bandwidth><nc:name>1g</nc:name><nc:metric>5</nc:metric></nc:bandwidth>"
+ "</nc:bandwidth-based-metrics><nc:dead-interval>4</nc:dead-interval><nc:hello-interval>2</nc:hello-interval>"
+ "<nc:poll-interval>2</nc:poll-interval><nc:retransmit-interval>2</nc:retransmit-interval></nc:interface>"
+ "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>",
+ '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
+ "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>",
]
- 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 = [
'<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
- "<nc:ospf><nc:area><nc:name>0.0.0.100</nc:name><nc:interface>"
- "<nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority>"
- "<nc:metric>5</nc:metric></nc:interface>"
- "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>"
- )
- result = self.execute_module(changed=False)
- self.assertEqual(sorted(result["rendered"]), sorted(rendered))
+ '<nc:ospf><nc:area delete="delete">0.0.0.100</nc:area>'
+ '<nc:area delete="delete">0.0.0.200</nc:area><nc:spf-options delete="delete"/>'
+ '<nc:reference-bandwidth delete="delete"/><nc:no-rfc-1583 delete="delete"/>'
+ '<nc:overload delete="delete"/>'
+ '<nc:prefix-export-limit delete="delete"/></nc:ospf><nc:ospf><nc:spf-options>'
+ "<nc:delay>3000</nc:delay><nc:holddown>4000</nc:holddown>"
+ "<nc:rapid-runs>9</nc:rapid-runs><nc:no-ignore-our-externals/>"
+ "</nc:spf-options><nc:overload><nc:timeout>1200</nc:timeout>"
+ "<nc:allow-route-leaking/><nc:as-external/><nc:stub-network/>"
+ "</nc:overload><nc:external-preference>10</nc:external-preference>"
+ "<nc:prefix-export-limit>30000</nc:prefix-export-limit><nc:no-rfc-1583/>"
+ "<nc:area><nc:name>0.0.0.100</nc:name><nc:area-range>"
+ "<nc:name>10.200.17.0/24</nc:name><nc:exact/><nc:restrict/>"
+ "<nc:override-metric>2000</nc:override-metric></nc:area-range><nc:interface>"
+ "<nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority><nc:metric>5</nc:metric>"
+ "<nc:passive/><nc:bandwidth-based-metrics><nc:bandwidth>"
+ "<nc:name>1g</nc:name><nc:metric>5</nc:metric></nc:bandwidth></nc:bandwidth-based-metrics>"
+ "<nc:dead-interval>4</nc:dead-interval><nc:hello-interval>2</nc:hello-interval>"
+ "<nc:poll-interval>2</nc:poll-interval><nc:retransmit-interval>2</nc:retransmit-interval>"
+ "</nc:interface><nc:stub><nc:default-metric>200</nc:default-metric>"
+ "</nc:stub></nc:area></nc:ospf></nc:protocols>",
+ '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">'
+ "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>",
+ ]
+ 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 = [
+ '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf>'
+ '<nc:area delete="delete">0.0.0.100</nc:area><nc:spf-options delete="delete"/>'
+ '<nc:reference-bandwidth delete="delete"/><nc:no-rfc-1583 delete="delete"/>'
+ '<nc:overload delete="delete"/></nc:ospf></nc:protocols>',
]
- 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 = """
- <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
- <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
- <version>18.4R1-S2.4</version>
- <protocols>
- <ospf>
- <area>
- <name>0.0.0.200</name>
- <interface>
- <name>so-0/0/0.1</name>
- <metric>3</metric>
- <priority>5</priority>
- </interface>
- </area>
- <area>
- <name>0.0.0.100</name>
- <stub>
- <default-metric>200</default-metric>
- </stub>
- <interface>
- <name>so-0/0/0.0</name>
- <metric>5</metric>
- <priority>3</priority>
- <bandwidth-based-metrics>
- <bandwidth>
- <name>10g</name>
- <metric>5</metric>
- </bandwidth>
- </bandwidth-based-metrics>
- </interface>
- </area>
- </ospf>
- </protocols>
- <routing-options>
- <router-id>10.200.16.7</router-id>
- </routing-options>
- </configuration>
- </rpc-reply>
+ <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
+ <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
+ <protocols>
+ <ospf>
+ <spf-options>
+ <delay>3000</delay>
+ <holddown>4000</holddown>
+ <rapid-runs>9</rapid-runs>
+ <no-ignore-our-externals/>
+ </spf-options>
+ <prefix-export-limit>20000</prefix-export-limit>
+ <overload>
+ <timeout>1200</timeout>
+ <allow-route-leaking/>
+ <stub-network/>
+ <as-external/>
+ </overload>
+ <reference-bandwidth>10g</reference-bandwidth>
+ <no-rfc-1583/>
+ <area>
+ <name>0.0.0.100</name>
+ <stub>
+ <default-metric>100</default-metric>
+ </stub>
+ <area-range>
+ <name>10.200.17.0/24</name>
+ <restrict/>
+ <exact/>
+ <override-metric>2000</override-metric>
+ </area-range>
+ <area-range>
+ <name>10.200.15.0/24</name>
+ <restrict/>
+ <exact/>
+ <override-metric>2000</override-metric>
+ </area-range>
+ <interface>
+ <name>so-0/0/0.0</name>
+ <passive>
+ </passive>
+ <bandwidth-based-metrics>
+ <bandwidth>
+ <name>1g</name>
+ <metric>5</metric>
+ </bandwidth>
+ <bandwidth>
+ <name>10g</name>
+ <metric>40</metric>
+ </bandwidth>
+ </bandwidth-based-metrics>
+ <metric>5</metric>
+ <priority>3</priority>
+ <retransmit-interval>2</retransmit-interval>
+ <hello-interval>2</hello-interval>
+ <dead-interval>4</dead-interval>
+ <poll-interval>2</poll-interval>
+ </interface>
+ </area>
+ </ospf>
+
+ </protocols>
+ </configuration>
+ </rpc-reply>
"""
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 = """
- <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
- <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
- <version>18.4R1-S2.4</version>
- <protocols>
- <ospf>
- <area>
- <name>0.0.0.200</name>
- <interface>
- <name>so-0/0/0.1</name>
- <metric>3</metric>
- <priority>5</priority>
- </interface>
- </area>
- <area>
- <name>0.0.0.100</name>
- <stub>
- <default-metric>200</default-metric>
- </stub>
- <interface>
- <name>so-0/0/0.0</name>
- <metric>5</metric>
- <priority>3</priority>
- <bandwidth-based-metrics>
- <bandwidth>
- <name>10g</name>
- <metric>5</metric>
- </bandwidth>
- <bandwidth>
- <name>1g</name>
- <metric>5</metric>
- </bandwidth>
- </bandwidth-based-metrics>
- </interface>
- </area>
- </ospf>
- </protocols>
- <routing-options>
- <router-id>10.200.16.7</router-id>
- </routing-options>
- </configuration>
- </rpc-reply>
- """
- 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 = (
+ '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf>'
+ "<nc:spf-options><nc:delay>3000</nc:delay><nc:holddown>4000</nc:holddown>"
+ "<nc:rapid-runs>9</nc:rapid-runs><nc:no-ignore-our-externals/></nc:spf-options>"
+ "<nc:overload><nc:timeout>1200</nc:timeout><nc:allow-route-leaking/><nc:as-external/>"
+ "<nc:stub-network/></nc:overload>"
+ "<nc:external-preference>10</nc:external-preference>"
+ "<nc:prefix-export-limit>30000</nc:prefix-export-limit>"
+ "<nc:no-rfc-1583/><nc:area><nc:name>0.0.0.100</nc:name><nc:area-range>"
+ "<nc:name>10.200.17.0/24</nc:name><nc:exact/><nc:restrict/>"
+ "<nc:override-metric>2000</nc:override-metric></nc:area-range><nc:interface>"
+ "<nc:name>so-0/0/0.0</nc:name>"
+ "<nc:priority>3</nc:priority><nc:metric>5</nc:metric><nc:passive/>"
+ "<nc:bandwidth-based-metrics><nc:bandwidth><nc:name>1g</nc:name>"
+ "<nc:metric>5</nc:metric></nc:bandwidth></nc:bandwidth-based-metrics>"
+ "<nc:dead-interval>4</nc:dead-interval><nc:hello-interval>2</nc:hello-interval>"
+ "<nc:poll-interval>2</nc:poll-interval>"
+ "<nc:retransmit-interval>2</nc:retransmit-interval></nc:interface><nc:stub>"
+ "<nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf>"
+ "</nc:protocols>"
+ )
+ 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='<?xml version="1.0" encoding="UTF-8"?>\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 = """
+ <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
+ <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">
+ <version>18.4R1-S2.4</version>
+ <security>
+ <zones>
+ <functional-zone>
+ <management>
+ <description>test description</description>
+ <host-inbound-traffic>
+ <protocols>
+ <name>all</name>
+ </protocols>
+ <protocols>
+ <name>bgp</name>
+ <except />
+ </protocols>
+ <system-services>
+ <name>all</name>
+ </system-services>
+ <system-services>
+ <name>dhcp</name>
+ <except />
+ </system-services>
+ </host-inbound-traffic>
+ <interfaces>
+ <name>ge-0/0/1.0</name>
+ </interfaces>
+ <interfaces>
+ <name>ge-0/0/2.0</name>
+ </interfaces>
+ <screen>test_screen</screen>
+ </management>
+ </functional-zone>
+ <security-zone>
+ <name>test_sec_zone1</name>
+ <address-book>
+ <address>
+ <name>test_adr1</name>
+ <ip-prefix>10.0.0.0/24</ip-prefix>
+ <description>test desc</description>
+ </address>
+ <address>
+ <name>test_adr2</name>
+ <dns-name>
+ <name>1.1.1.1</name>
+ <ipv6-only />
+ </dns-name>
+ </address>
+ <address>
+ <name>test_adr3</name>
+ <range-address>
+ <name>10.2.0.1</name>
+ <to>
+ <range-high>10.2.0.2</range-high>
+ </to>
+ </range-address>
+ </address>
+ <address>
+ <name>test_adr4</name>
+ <wildcard-address>
+ <name>10.3.0.1/24</name>
+ </wildcard-address>
+ </address>
+ <address>
+ <name>test_adr5</name>
+ <ip-prefix>10.1.0.0/24</ip-prefix>
+ <description>test desc</description>
+ </address>
+ <address-set>
+ <name>test_adrset1</name>
+ <address>
+ <name>test_adr1</name>
+ </address>
+ <address>
+ <name>test_adr2</name>
+ </address>
+ </address-set>
+ <address-set>
+ <name>test_adrset2</name>
+ <address>
+ <name>test_adr3</name>
+ </address>
+ <address>
+ <name>test_adr4</name>
+ </address>
+ </address-set>
+ <address-set>
+ <name>test_adrset3</name>
+ <address>
+ <name>test_adr5</name>
+ </address>
+ <address-set>
+ <name>test_adrset1</name>
+ </address-set>
+ <address-set>
+ <name>test_adrset2</name>
+ </address-set>
+ <description>test description</description>
+ </address-set>
+ </address-book>
+ <advance-policy-based-routing-profile>
+ <profile>test_profile</profile>
+ </advance-policy-based-routing-profile>
+ <advanced-connection-tracking>
+ <mode>allow-any-host</mode>
+ <timeout>20</timeout>
+ <track-all-policies-to-this-zone/>
+ </advanced-connection-tracking>
+ <application-tracking />
+ <description>test description</description>
+ <enable-reverse-reroute />
+ <host-inbound-traffic>
+ <protocols>
+ <name>all</name>
+ </protocols>
+ <protocols>
+ <name>bgp</name>
+ <except />
+ </protocols>
+ <system-services>
+ <name>all</name>
+ </system-services>
+ <system-services>
+ <name>dhcp</name>
+ <except />
+ </system-services>
+ </host-inbound-traffic>
+ <interfaces>
+ <name>ge-0/0/3.0</name>
+ </interfaces>
+ <screen>test_screen</screen>
+ <source-identity-log />
+ <tcp-rst />
+ <unidirectional-session-refreshing />
+ </security-zone>
+ </zones>
+ </security>
+ </configuration>
+ </rpc-reply>
+ """
+ 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 = """
<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">
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(
+ '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "<nc:view><nc:name>all</nc:name><nc:oid><nc:name>.1</nc:name>",
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "</nc:oid></nc:view></nc:snmp>",
+ 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(
+ '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "<nc:trap-options><nc:agent-address>outgoing-interface</nc:agent-address><nc:context-oid/>",
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "</nc:trap-options></nc:snmp>",
+ 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(
+ '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "<nc:trap-group><nc:categories><nc:authentication/></nc:categories><nc:name>egress</nc:name>",
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "</nc:trap-group></nc:snmp>",
+ 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(
+ '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "<nc:trap-group><nc:categories><nc:chassis/><nc:chassis-cluster/><nc:configuration/>",
+ 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(
+ '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "<nc:trap-group><nc:categories><nc:otn-alarms><nc:oc-lof/><nc:oc-lom/><nc:oc-los/></nc:otn-alarms></nc:categories>",
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "<nc:name>monitor</nc:name></nc:trap-group></nc:snmp>",
+ 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 = '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:trap-options/></nc:snmp>'
+ 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(
+ '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">',
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "<nc:trap-options><nc:source-address><nc:address>192.168.2.0</nc:address></nc:source-address>",
+ str(result["commands"]),
+ )
+ self.assertIn(
+ "</nc:trap-options></nc:snmp>",
+ str(result["commands"]),
+ )
+
def test_junos_snmp_server_merged_client_02(self):
set_module_args(
dict(