summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromnom62 <75066712+omnom62@users.noreply.github.com>2025-04-03 08:19:46 +1000
committerGitHub <noreply@github.com>2025-04-02 18:19:46 -0400
commit640519ab2bd3e95840d140a96d278659a9d0850d (patch)
treef6daae96ffa0116c76bd75e869026b1f13616a24
parent9a6bd2f99c91d81391fbff8a32b7b6f3ee3b5e57 (diff)
downloadvyos.vyos-640519ab2bd3e95840d140a96d278659a9d0850d.tar.gz
vyos.vyos-640519ab2bd3e95840d140a96d278659a9d0850d.zip
T7012 OSPFv2 integration tests fixes (#395)
* init for ospfv2 * ospfv2 rtt and merge and merge_update tests fixed * ospfv2 integration test partial fix * ospfv2 integration tests new structure and 1.4+ fixes * ospfv2 1.3- unit tests * ospfv2 changelog * Added unit tests suite for 1.4+ and vyos_ospfv2 * fixed some netsted dict, added pasive-interface default, added passive-interface exclude for 1.4+ * passive-interface-exclude support for 1.4+ * fix remove func for passive-interface-exclude in 1.4+ ospfv2 * parsed.yaml update * leftovers removed * prepare_vyous_tests.yaml to use network_cli and fail fast * ospfv2 integration tests pre-requisite scripts * reverted prepare_vyos_tests script * facts regex corrected * reworked facts regex --------- Co-authored-by: Daniil Baturin <daniil@baturin.org>
-rw-r--r--changelogs/fragments/T7012_ospfv2_integration_tests.yaml6
-rw-r--r--plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py19
-rw-r--r--plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py37
-rw-r--r--tests/integration/targets/vyos_ospfv2/tasks/main.yaml8
-rw-r--r--tests/integration/targets/vyos_ospfv2/tasks/post_tasks.yaml7
-rw-r--r--tests/integration/targets/vyos_ospfv2/tasks/pre_tasks.yaml7
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/_get_version.yaml30
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config_1_3.cfg (renamed from tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg)4
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config_1_4.cfg29
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml38
-rw-r--r--tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml8
-rw-r--r--tests/integration/targets/vyos_ospfv2/vars/main.yaml97
-rw-r--r--tests/integration/targets/vyos_ospfv2/vars/pre-v1_4.yaml123
-rw-r--r--tests/integration/targets/vyos_ospfv2/vars/v1_4.yaml123
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_ospfv2.py12
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_ospfv2v14.py437
16 files changed, 853 insertions, 132 deletions
diff --git a/changelogs/fragments/T7012_ospfv2_integration_tests.yaml b/changelogs/fragments/T7012_ospfv2_integration_tests.yaml
new file mode 100644
index 00000000..b1382697
--- /dev/null
+++ b/changelogs/fragments/T7012_ospfv2_integration_tests.yaml
@@ -0,0 +1,6 @@
+---
+trivial:
+ - vyos_ospfv2 - fix intergration test suite.
+ - vyos_ospfv2 - fix unit tests.
+bugfixes:
+ - vyos_ospfv2 - passive-interface processing for 1.3- and 1.4+
diff --git a/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py
index a9c1de1b..ababc6f1 100644
--- a/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py
+++ b/plugins/module_utils/network/vyos/config/ospfv2/ospfv2.py
@@ -33,6 +33,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils
_is_w_same,
list_diff_want_only,
)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version
+
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion
class Ospfv2(ConfigBase):
@@ -124,7 +127,7 @@ class Ospfv2(ConfigBase):
want = self._module.params["config"]
have = existing_ospfv2_facts
- resp = self.set_state(want, have)
+ resp = self.set_state(remove_empties(want), remove_empties(have))
return to_list(resp)
def set_state(self, w, h):
@@ -136,7 +139,6 @@ class Ospfv2(ConfigBase):
:returns: the commands necessary to migrate the current configuration
to the desired configuration
"""
-
commands = []
if self.state in ("merged", "replaced", "overridden", "rendered") and not w:
self._module.fail_json(
@@ -270,7 +272,6 @@ class Ospfv2(ConfigBase):
:param opr: True/False.
:return: generated list of commands.
"""
-
commands = []
h = {}
if have:
@@ -320,7 +321,6 @@ class Ospfv2(ConfigBase):
:param opr: True/False.
:return: generated list of commands.
"""
-
commands = []
h = []
if want:
@@ -336,6 +336,10 @@ class Ospfv2(ConfigBase):
command = cmd + attr.replace("_", "-") + " "
if attr == "network":
command += member["address"]
+ elif attr == "passive_interface" and member != "default" and LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
+ command = command.replace("passive-interface", "interface") + member + " passive"
+ elif attr == "passive_interface_exclude" and LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
+ command = command.replace("passive-interface-exclude", "interface") + member + " passive disable"
else:
command += member
commands.append(command)
@@ -348,7 +352,12 @@ class Ospfv2(ConfigBase):
cmd + attr.replace("_", "-") + " " + member["address"],
)
elif member not in h:
- commands.append(cmd + attr.replace("_", "-") + " " + member)
+ if attr == "passive_interface" and member != "default" and LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
+ commands.append(cmd + "interface" + " " + member + " passive")
+ elif attr == "passive_interface_exclude" and LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
+ command = command.replace("passive-interface-exclude", "interface") + member + " passive disable"
+ else:
+ commands.append(cmd + attr.replace("_", "-") + " " + member)
else:
commands.append(cmd + " " + attr.replace("_", "-"))
return commands
diff --git a/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py b/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py
index bdc7c9f8..d07bf13a 100644
--- a/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py
+++ b/plugins/module_utils/network/vyos/facts/ospfv2/ospfv2.py
@@ -22,6 +22,10 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common i
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv2.ospfv2 import (
Ospfv2Args,
)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import (
+ LooseVersion,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version
class Ospfv2Facts(object):
@@ -99,9 +103,9 @@ class Ospfv2Facts(object):
config["areas"] = self.parse_attrib_list(conf, "area", "area_id")
config["parameters"] = self.parse_attrib(conf, "parameters", "parameters")
config["neighbor"] = self.parse_attrib_list(conf, "neighbor", "neighbor_id")
- config["passive_interface"] = self.parse_leaf_list(conf, "passive-interface")
+ config["passive_interface"] = self.parse_passive(conf, "passive-interface")
config["redistribute"] = self.parse_attrib_list(conf, "redistribute", "route_type")
- config["passive_interface_exclude"] = self.parse_leaf_list(
+ config["passive_interface_exclude"] = self.parse_passive(
conf,
"passive-interface-exclude",
)
@@ -159,6 +163,29 @@ class Ospfv2Facts(object):
lst.sort()
return lst
+ def parse_passive(self, conf, attrib):
+ """
+ This function forms the regex to fetch the listed attributes
+ from the configuration data
+ :param conf: configuration data
+ :param attrib: attribute name
+ :return: generated rule list configuration
+ """
+ lst = []
+ items = []
+ if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
+ if attrib == "passive-interface-exclude":
+ items = findall("^interface (?:'*)(\\S+)(?:'*) passive disable$", conf, M)
+ else:
+ items = findall("^interface (?:'*)(\\S+)(?:'*) passive$", conf, M)
+
+ items += findall(r"^" + attrib + " (?:'*)(\\S+)(?:'*)", conf, M)
+ if items:
+ for i in set(items):
+ lst.append(i.strip("'"))
+ lst.sort()
+ return lst
+
def parse_distance(self, conf, attrib=None):
"""
This function triggers the parsing of 'distance' attributes
@@ -389,13 +416,13 @@ class Ospfv2Facts(object):
:param match: parent node/attribute name.
:return: generated config dictionary.
"""
-
config = {}
for attrib in attr_list:
regex = self.map_regex(attrib)
if match:
regex = match.replace("_", "-") + " " + regex
+
if conf:
if self.is_bool(attrib):
out = conf.find(attrib.replace("_", "-"))
@@ -403,13 +430,13 @@ class Ospfv2Facts(object):
if match:
if attrib == "set" and conf.find(match) >= 1:
config[attrib] = True
- en = conf.find(match + " 'enable'")
+ en = conf.find(match + " enable") != -1
if out >= 1:
if dis >= 1:
config[attrib] = False
else:
config[attrib] = True
- elif match and en >= 1:
+ elif match and en:
config[attrib] = True
else:
out = search(r"^.*" + regex + " (.+)", conf, M)
diff --git a/tests/integration/targets/vyos_ospfv2/tasks/main.yaml b/tests/integration/targets/vyos_ospfv2/tasks/main.yaml
index 9a3359ed..53afd6c2 100644
--- a/tests/integration/targets/vyos_ospfv2/tasks/main.yaml
+++ b/tests/integration/targets/vyos_ospfv2/tasks/main.yaml
@@ -1,4 +1,8 @@
---
+- name: Run preflight setup
+ ansible.builtin.import_tasks: pre_tasks.yaml
+ failed_when: false
+
- name: Run CLI tests
ansible.builtin.include_tasks: cli.yaml
tags:
@@ -9,3 +13,7 @@
when: ansible_version.full is version('2.10.0', '>=')
tags:
- network_cli
+
+- name: Run post-test cleanup tasks
+ ansible.builtin.import_tasks: post_tasks.yaml
+ failed_when: false
diff --git a/tests/integration/targets/vyos_ospfv2/tasks/post_tasks.yaml b/tests/integration/targets/vyos_ospfv2/tasks/post_tasks.yaml
new file mode 100644
index 00000000..e172db2d
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tasks/post_tasks.yaml
@@ -0,0 +1,7 @@
+---
+- name: Remove pre-requisite configuration
+ vyos.vyos.vyos_config:
+ lines: |-
+ delete policy route-map ingress
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_ospfv2/tasks/pre_tasks.yaml b/tests/integration/targets/vyos_ospfv2/tasks/pre_tasks.yaml
new file mode 100644
index 00000000..bdca8772
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tasks/pre_tasks.yaml
@@ -0,0 +1,7 @@
+---
+- name: Add pre-requisite configuration
+ vyos.vyos.vyos_config:
+ lines: |-
+ set policy route-map ingress
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_get_version.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/_get_version.yaml
new file mode 100644
index 00000000..50b0ec61
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_get_version.yaml
@@ -0,0 +1,30 @@
+- name: make sure to get facts
+ vyos.vyos.vyos_facts:
+ vars:
+ ansible_connection: ansible.netcommon.network_cli
+ register: vyos_facts
+ when: vyos_version is not defined
+
+- name: debug vyos_facts
+ debug:
+ var: vyos_facts
+
+- name: pull version from facts
+ set_fact:
+ vyos_version: "{{ vyos_facts.ansible_facts.ansible_net_version.split('-')[0].split(' ')[-1] }}"
+ when: vyos_version is not defined
+
+- name: fix '.0' versions
+ set_fact:
+ vyos_version: "{{ vyos_version }}.0"
+ when: vyos_version.count('.') == 1
+
+- name: include correct vars
+ include_vars: pre-v1_4.yaml
+ when: vyos_version is version('1.4.0', '<', version_type='semver')
+
+- name: include correct vars
+ include_vars: v1_4.yaml
+ when: vyos_version is version('1.4.0', '>=', version_type='semver')
+# - name: include common vars
+# include_vars: main.yaml
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config_1_3.cfg
index 9cc720b4..0d8100d8 100644
--- a/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config_1_3.cfg
@@ -1,6 +1,6 @@
set protocols ospf area 2 area-type 'normal'
set protocols ospf area 2 authentication 'plaintext-password'
-set protocols ospf area 2 shortcut 'enable'
+set protocols ospf area 2 shortcut enable
set protocols ospf area 3 area-type 'nssa'
set protocols ospf area 4 area-type stub default-cost '20'
set protocols ospf area 4 network '192.0.2.0/24'
@@ -15,7 +15,7 @@ set protocols ospf log-adjacency-changes 'detail'
set protocols ospf max-metric router-lsa 'administrative'
set protocols ospf max-metric router-lsa on-shutdown '10'
set protocols ospf max-metric router-lsa on-startup '10'
-set protocols ospf mpls-te 'enable'
+set protocols ospf mpls-te enable
set protocols ospf mpls-te router-address '192.0.11.11'
set protocols ospf neighbor 192.0.11.12 poll-interval '10'
set protocols ospf neighbor 192.0.11.12 priority '2'
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config_1_4.cfg b/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config_1_4.cfg
new file mode 100644
index 00000000..8e24ab69
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config_1_4.cfg
@@ -0,0 +1,29 @@
+set protocols ospf area 2 area-type 'normal'
+set protocols ospf area 2 authentication 'plaintext-password'
+set protocols ospf area 2 shortcut enable
+set protocols ospf area 3 area-type 'nssa'
+set protocols ospf area 4 area-type stub default-cost '20'
+set protocols ospf area 4 network '192.0.2.0/24'
+set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+set protocols ospf auto-cost reference-bandwidth '2'
+set protocols ospf default-information originate 'always'
+set protocols ospf default-information originate metric '10'
+set protocols ospf default-information originate metric-type '2'
+set protocols ospf default-information originate route-map 'ingress'
+set protocols ospf log-adjacency-changes 'detail'
+set protocols ospf max-metric router-lsa 'administrative'
+set protocols ospf max-metric router-lsa on-shutdown '10'
+set protocols ospf max-metric router-lsa on-startup '10'
+set protocols ospf mpls-te enable
+set protocols ospf mpls-te router-address '192.0.11.11'
+set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+set protocols ospf neighbor 192.0.11.12 priority '2'
+set protocols ospf parameters abr-type 'cisco'
+set protocols ospf parameters 'opaque-lsa'
+set protocols ospf parameters 'rfc1583-compatibility'
+set protocols ospf parameters router-id '192.0.1.1'
+set protocols ospf interface 'eth1' passive
+set protocols ospf interface 'eth2' passive
+set protocols ospf redistribute bgp metric '10'
+set protocols ospf redistribute bgp metric-type '2'
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml
index 872d3302..748dca70 100644
--- a/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml
@@ -1,37 +1,11 @@
---
- ansible.builtin.include_tasks: _remove_config.yaml
+- name: ensure facts
+ include_tasks: _get_version.yaml
+
- name: Setup
+ vyos.vyos.vyos_config:
+ lines: "{{ populate_commands }}"
vars:
- lines: >-
- "set protocols ospf mpls-te 'enable'
- \n set protocols ospf mpls-te router-address '192.0.11.11'
- \n set protocols ospf redistribute bgp metric-type '2'
- \n set protocols ospf redistribute bgp metric '10'
- \n set protocols ospf default-information originate metric-type '2'
- \n set protocols ospf default-information originate 'always'
- \n set protocols ospf default-information originate metric '10'
- \n set protocols ospf default-information originate route-map 'ingress'
- \n set protocols ospf auto-cost reference-bandwidth '2'
- \n set protocols ospf parameters router-id '192.0.1.1'
- \n set protocols ospf parameters 'opaque-lsa'
- \n set protocols ospf parameters abr-type 'cisco'
- \n set protocols ospf parameters 'rfc1583-compatibility'
- \n set protocols ospf passive-interface 'eth1'
- \n set protocols ospf passive-interface 'eth2'
- \n set protocols ospf max-metric router-lsa on-shutdown '10'
- \n set protocols ospf max-metric router-lsa 'administrative'
- \n set protocols ospf max-metric router-lsa on-startup '10'
- \n set protocols ospf log-adjacency-changes 'detail'
- \n set protocols ospf neighbor 192.0.11.12 priority '2'
- \n set protocols ospf neighbor 192.0.11.12 poll-interval '10'
- \n set protocols ospf area 2 authentication 'plaintext-password'
- \n set protocols ospf area 2 shortcut 'enable'
- \n set protocols ospf area 2 area-type 'normal'
- \n set protocols ospf area 3 area-type 'nssa'
- \n set protocols ospf area 4 range 192.0.3.0/24 cost '10'
- \n set protocols ospf area 4 range 192.0.4.0/24 cost '12'
- \n set protocols ospf area 4 area-type stub default-cost '20'
- \n set protocols ospf area 4 network '192.0.2.0/24'"
- ansible.netcommon.cli_config:
- config: "{{ lines }}"
+ ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml
index ad5b005d..4b6e0c5c 100644
--- a/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml
+++ b/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml
@@ -2,12 +2,18 @@
- debug:
msg: START vyos_ospfv2 parsed integration tests on connection={{ ansible_connection }}
+- name: ensure facts
+ include_tasks: _get_version.yaml
+
- name: Parse externally provided ospfv2 config to agnostic model
register: result
vyos.vyos.vyos_ospfv2:
- running_config: "{{ lookup('file', '_parsed_config.cfg') }}"
+ running_config: "{{ lookup('file', parsed_config_file) }}"
state: parsed
+- debug:
+ msg: "{{ parsed['after'] }}"
+
- name: Assert that config was correctly parsed
assert:
that:
diff --git a/tests/integration/targets/vyos_ospfv2/vars/main.yaml b/tests/integration/targets/vyos_ospfv2/vars/main.yaml
index 70d25fc7..1f1b9ba8 100644
--- a/tests/integration/targets/vyos_ospfv2/vars/main.yaml
+++ b/tests/integration/targets/vyos_ospfv2/vars/main.yaml
@@ -1,43 +1,7 @@
---
merged:
before: {}
- commands:
- - set protocols ospf mpls-te enable
- - set protocols ospf mpls-te router-address '192.0.11.11'
- - set protocols ospf redistribute bgp
- - set protocols ospf redistribute bgp metric-type 2
- - set protocols ospf redistribute bgp metric 10
- - set protocols ospf default-information originate metric-type 2
- - set protocols ospf default-information originate always
- - set protocols ospf default-information originate metric 10
- - set protocols ospf default-information originate route-map ingress
- - set protocols ospf auto-cost reference-bandwidth '2'
- - set protocols ospf parameters router-id '192.0.1.1'
- - set protocols ospf parameters opaque-lsa
- - set protocols ospf parameters abr-type 'cisco'
- - set protocols ospf parameters rfc1583-compatibility
- - set protocols ospf passive-interface eth1
- - set protocols ospf passive-interface eth2
- - set protocols ospf max-metric router-lsa on-shutdown 10
- - set protocols ospf max-metric router-lsa administrative
- - set protocols ospf max-metric router-lsa on-startup 10
- - set protocols ospf log-adjacency-changes 'detail'
- - set protocols ospf neighbor 192.0.11.12 priority 2
- - set protocols ospf neighbor 192.0.11.12 poll-interval 10
- - set protocols ospf neighbor 192.0.11.12
- - set protocols ospf area '2'
- - set protocols ospf area 2 authentication plaintext-password
- - set protocols ospf area 2 shortcut enable
- - set protocols ospf area 2 area-type normal
- - set protocols ospf area '3'
- - set protocols ospf area 3 area-type nssa
- - set protocols ospf area 4 range 192.0.3.0/24 cost 10
- - set protocols ospf area 4 range 192.0.3.0/24
- - set protocols ospf area 4 range 192.0.4.0/24 cost 12
- - set protocols ospf area 4 range 192.0.4.0/24
- - set protocols ospf area 4 area-type stub default-cost 20
- - set protocols ospf area '4'
- - set protocols ospf area 4 network 192.0.2.0/24
+ commands: "{{ merged_commands }}"
after:
areas:
- area_id: "2"
@@ -94,6 +58,7 @@ merged:
- metric: 10
metric_type: 2
route_type: bgp
+
merged_update:
before:
areas:
@@ -209,6 +174,7 @@ merged_update:
- delete protocols ospf area 4 area-type stub
- set protocols ospf area 4 network 192.0.22.0/24
- set protocols ospf area 4 network 192.0.32.0/24
+
populate:
areas:
- area_id: "2"
@@ -265,20 +231,9 @@ populate:
- metric: 10
metric_type: 2
route_type: bgp
+
replaced:
- commands:
- - delete protocols ospf passive-interface eth2
- - delete protocols ospf area 3
- - delete protocols ospf area 4 range 192.0.3.0/24 cost
- - delete protocols ospf area 4 range 192.0.3.0/24
- - delete protocols ospf area 4 range 192.0.4.0/24 cost
- - delete protocols ospf area 4 range 192.0.4.0/24
- - set protocols ospf mpls-te router-address '192.0.22.22'
- - set protocols ospf area 4 range 1.1.2.0/24 cost 10
- - set protocols ospf area 4 range 1.1.2.0/24
- - set protocols ospf area 4 network 192.0.12.0/24
- - set protocols ospf area 4 network 192.0.22.0/24
- - set protocols ospf area 4 network 192.0.32.0/24
+ commands: "{{ replaced_commands }}"
after:
areas:
- area_id: "2"
@@ -331,44 +286,10 @@ replaced:
- metric: 10
metric_type: 2
route_type: bgp
+
rendered:
- commands:
- - set protocols ospf mpls-te enable
- - set protocols ospf mpls-te router-address '192.0.11.11'
- - set protocols ospf redistribute bgp
- - set protocols ospf redistribute bgp metric-type 2
- - set protocols ospf redistribute bgp metric 10
- - set protocols ospf default-information originate metric-type 2
- - set protocols ospf default-information originate always
- - set protocols ospf default-information originate metric 10
- - set protocols ospf default-information originate route-map ingress
- - set protocols ospf auto-cost reference-bandwidth '2'
- - set protocols ospf parameters router-id '192.0.1.1'
- - set protocols ospf parameters opaque-lsa
- - set protocols ospf parameters abr-type 'cisco'
- - set protocols ospf parameters rfc1583-compatibility
- - set protocols ospf passive-interface eth1
- - set protocols ospf passive-interface eth2
- - set protocols ospf max-metric router-lsa on-shutdown 10
- - set protocols ospf max-metric router-lsa administrative
- - set protocols ospf max-metric router-lsa on-startup 10
- - set protocols ospf log-adjacency-changes 'detail'
- - set protocols ospf neighbor 192.0.11.12 priority 2
- - set protocols ospf neighbor 192.0.11.12 poll-interval 10
- - set protocols ospf neighbor 192.0.11.12
- - set protocols ospf area '2'
- - set protocols ospf area 2 authentication plaintext-password
- - set protocols ospf area 2 shortcut enable
- - set protocols ospf area 2 area-type normal
- - set protocols ospf area '3'
- - set protocols ospf area 3 area-type nssa
- - set protocols ospf area 4 range 192.0.3.0/24 cost 10
- - set protocols ospf area 4 range 192.0.3.0/24
- - set protocols ospf area 4 range 192.0.4.0/24 cost 12
- - set protocols ospf area 4 range 192.0.4.0/24
- - set protocols ospf area 4 area-type stub default-cost 20
- - set protocols ospf area '4'
- - set protocols ospf area 4 network 192.0.2.0/24
+ commands: "{{ rendered_commands }}"
+
parsed:
after:
areas:
@@ -426,10 +347,12 @@ parsed:
- metric: 10
metric_type: 2
route_type: bgp
+
deleted:
commands:
- delete protocols ospf
after: {}
+
round_trip:
after:
areas:
diff --git a/tests/integration/targets/vyos_ospfv2/vars/pre-v1_4.yaml b/tests/integration/targets/vyos_ospfv2/vars/pre-v1_4.yaml
new file mode 100644
index 00000000..a5e8a725
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/vars/pre-v1_4.yaml
@@ -0,0 +1,123 @@
+---
+merged_commands:
+ - set protocols ospf mpls-te enable
+ - set protocols ospf mpls-te router-address '192.0.11.11'
+ - set protocols ospf redistribute bgp
+ - set protocols ospf redistribute bgp metric-type 2
+ - set protocols ospf redistribute bgp metric 10
+ - set protocols ospf default-information originate metric-type 2
+ - set protocols ospf default-information originate always
+ - set protocols ospf default-information originate metric 10
+ - set protocols ospf default-information originate route-map ingress
+ - set protocols ospf auto-cost reference-bandwidth '2'
+ - set protocols ospf parameters router-id '192.0.1.1'
+ - set protocols ospf parameters opaque-lsa
+ - set protocols ospf parameters abr-type 'cisco'
+ - set protocols ospf parameters rfc1583-compatibility
+ - set protocols ospf passive-interface eth1
+ - set protocols ospf passive-interface eth2
+ - set protocols ospf max-metric router-lsa on-shutdown 10
+ - set protocols ospf max-metric router-lsa administrative
+ - set protocols ospf max-metric router-lsa on-startup 10
+ - set protocols ospf log-adjacency-changes 'detail'
+ - set protocols ospf neighbor 192.0.11.12 priority 2
+ - set protocols ospf neighbor 192.0.11.12 poll-interval 10
+ - set protocols ospf neighbor 192.0.11.12
+ - set protocols ospf area '2'
+ - set protocols ospf area 2 authentication plaintext-password
+ - set protocols ospf area 2 shortcut enable
+ - set protocols ospf area 2 area-type normal
+ - set protocols ospf area '3'
+ - set protocols ospf area 3 area-type nssa
+ - set protocols ospf area 4 range 192.0.3.0/24 cost 10
+ - set protocols ospf area 4 range 192.0.3.0/24
+ - set protocols ospf area 4 range 192.0.4.0/24 cost 12
+ - set protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf area 4 area-type stub default-cost 20
+ - set protocols ospf area '4'
+ - set protocols ospf area 4 network 192.0.2.0/24
+
+populate_commands:
+ - set protocols ospf mpls-te 'enable'
+ - set protocols ospf mpls-te router-address '192.0.11.11'
+ - set protocols ospf redistribute bgp metric-type '2'
+ - set protocols ospf redistribute bgp metric '10'
+ - set protocols ospf default-information originate metric-type '2'
+ - set protocols ospf default-information originate 'always'
+ - set protocols ospf default-information originate metric '10'
+ - set protocols ospf default-information originate route-map 'ingress'
+ - set protocols ospf auto-cost reference-bandwidth '2'
+ - set protocols ospf parameters router-id '192.0.1.1'
+ - set protocols ospf parameters 'opaque-lsa'
+ - set protocols ospf parameters abr-type 'cisco'
+ - set protocols ospf parameters 'rfc1583-compatibility'
+ - set protocols ospf passive-interface 'eth1'
+ - set protocols ospf passive-interface 'eth2'
+ - set protocols ospf max-metric router-lsa on-shutdown '10'
+ - set protocols ospf max-metric router-lsa 'administrative'
+ - set protocols ospf max-metric router-lsa on-startup '10'
+ - set protocols ospf log-adjacency-changes 'detail'
+ - set protocols ospf neighbor 192.0.11.12 priority '2'
+ - set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+ - set protocols ospf area 2 authentication 'plaintext-password'
+ - set protocols ospf area 2 shortcut 'enable'
+ - set protocols ospf area 2 area-type 'normal'
+ - set protocols ospf area 3 area-type 'nssa'
+ - set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+ - set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+ - set protocols ospf area 4 area-type stub default-cost '20'
+ - set protocols ospf area 4 network '192.0.2.0/24'
+
+replaced_commands:
+ - delete protocols ospf passive-interface eth2
+ - delete protocols ospf area 3
+ - delete protocols ospf area 4 range 192.0.3.0/24 cost
+ - delete protocols ospf area 4 range 192.0.3.0/24
+ - delete protocols ospf area 4 range 192.0.4.0/24 cost
+ - delete protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf mpls-te router-address '192.0.22.22'
+ - set protocols ospf area 4 range 1.1.2.0/24 cost 10
+ - set protocols ospf area 4 range 1.1.2.0/24
+ - set protocols ospf area 4 network 192.0.12.0/24
+ - set protocols ospf area 4 network 192.0.22.0/24
+ - set protocols ospf area 4 network 192.0.32.0/24
+
+rendered_commands:
+ - set protocols ospf mpls-te enable
+ - set protocols ospf mpls-te router-address '192.0.11.11'
+ - set protocols ospf redistribute bgp
+ - set protocols ospf redistribute bgp metric-type 2
+ - set protocols ospf redistribute bgp metric 10
+ - set protocols ospf default-information originate metric-type 2
+ - set protocols ospf default-information originate always
+ - set protocols ospf default-information originate metric 10
+ - set protocols ospf default-information originate route-map ingress
+ - set protocols ospf auto-cost reference-bandwidth '2'
+ - set protocols ospf parameters router-id '192.0.1.1'
+ - set protocols ospf parameters opaque-lsa
+ - set protocols ospf parameters abr-type 'cisco'
+ - set protocols ospf parameters rfc1583-compatibility
+ - set protocols ospf passive-interface eth1
+ - set protocols ospf passive-interface eth2
+ - set protocols ospf max-metric router-lsa on-shutdown 10
+ - set protocols ospf max-metric router-lsa administrative
+ - set protocols ospf max-metric router-lsa on-startup 10
+ - set protocols ospf log-adjacency-changes 'detail'
+ - set protocols ospf neighbor 192.0.11.12 priority 2
+ - set protocols ospf neighbor 192.0.11.12 poll-interval 10
+ - set protocols ospf neighbor 192.0.11.12
+ - set protocols ospf area '2'
+ - set protocols ospf area 2 authentication plaintext-password
+ - set protocols ospf area 2 shortcut enable
+ - set protocols ospf area 2 area-type normal
+ - set protocols ospf area '3'
+ - set protocols ospf area 3 area-type nssa
+ - set protocols ospf area 4 range 192.0.3.0/24 cost 10
+ - set protocols ospf area 4 range 192.0.3.0/24
+ - set protocols ospf area 4 range 192.0.4.0/24 cost 12
+ - set protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf area 4 area-type stub default-cost 20
+ - set protocols ospf area '4'
+ - set protocols ospf area 4 network 192.0.2.0/24
+
+parsed_config_file: "_parsed_config_1_3.cfg"
diff --git a/tests/integration/targets/vyos_ospfv2/vars/v1_4.yaml b/tests/integration/targets/vyos_ospfv2/vars/v1_4.yaml
new file mode 100644
index 00000000..4b7d0ab1
--- /dev/null
+++ b/tests/integration/targets/vyos_ospfv2/vars/v1_4.yaml
@@ -0,0 +1,123 @@
+---
+merged_commands:
+ - set protocols ospf mpls-te enable
+ - set protocols ospf mpls-te router-address '192.0.11.11'
+ - set protocols ospf redistribute bgp
+ - set protocols ospf redistribute bgp metric-type 2
+ - set protocols ospf redistribute bgp metric 10
+ - set protocols ospf default-information originate metric-type 2
+ - set protocols ospf default-information originate always
+ - set protocols ospf default-information originate metric 10
+ - set protocols ospf default-information originate route-map ingress
+ - set protocols ospf auto-cost reference-bandwidth '2'
+ - set protocols ospf parameters router-id '192.0.1.1'
+ - set protocols ospf parameters opaque-lsa
+ - set protocols ospf parameters abr-type 'cisco'
+ - set protocols ospf parameters rfc1583-compatibility
+ - set protocols ospf interface eth1 passive
+ - set protocols ospf interface eth2 passive
+ - set protocols ospf max-metric router-lsa on-shutdown 10
+ - set protocols ospf max-metric router-lsa administrative
+ - set protocols ospf max-metric router-lsa on-startup 10
+ - set protocols ospf log-adjacency-changes 'detail'
+ - set protocols ospf neighbor 192.0.11.12 priority 2
+ - set protocols ospf neighbor 192.0.11.12 poll-interval 10
+ - set protocols ospf neighbor 192.0.11.12
+ - set protocols ospf area '2'
+ - set protocols ospf area 2 authentication plaintext-password
+ - set protocols ospf area 2 shortcut enable
+ - set protocols ospf area 2 area-type normal
+ - set protocols ospf area '3'
+ - set protocols ospf area 3 area-type nssa
+ - set protocols ospf area 4 range 192.0.3.0/24 cost 10
+ - set protocols ospf area 4 range 192.0.3.0/24
+ - set protocols ospf area 4 range 192.0.4.0/24 cost 12
+ - set protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf area 4 area-type stub default-cost 20
+ - set protocols ospf area '4'
+ - set protocols ospf area 4 network 192.0.2.0/24
+
+populate_commands:
+ - set protocols ospf mpls-te 'enable'
+ - set protocols ospf mpls-te router-address '192.0.11.11'
+ - set protocols ospf redistribute bgp metric-type '2'
+ - set protocols ospf redistribute bgp metric '10'
+ - set protocols ospf default-information originate metric-type '2'
+ - set protocols ospf default-information originate 'always'
+ - set protocols ospf default-information originate metric '10'
+ - set protocols ospf default-information originate route-map 'ingress'
+ - set protocols ospf auto-cost reference-bandwidth '2'
+ - set protocols ospf parameters router-id '192.0.1.1'
+ - set protocols ospf parameters 'opaque-lsa'
+ - set protocols ospf parameters abr-type 'cisco'
+ - set protocols ospf parameters 'rfc1583-compatibility'
+ - set protocols ospf interface 'eth1' passive
+ - set protocols ospf interface 'eth2' passive
+ - set protocols ospf max-metric router-lsa on-shutdown '10'
+ - set protocols ospf max-metric router-lsa 'administrative'
+ - set protocols ospf max-metric router-lsa on-startup '10'
+ - set protocols ospf log-adjacency-changes 'detail'
+ - set protocols ospf neighbor 192.0.11.12 priority '2'
+ - set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+ - set protocols ospf area 2 authentication 'plaintext-password'
+ - set protocols ospf area 2 shortcut 'enable'
+ - set protocols ospf area 2 area-type 'normal'
+ - set protocols ospf area 3 area-type 'nssa'
+ - set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+ - set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+ - set protocols ospf area 4 area-type stub default-cost '20'
+ - set protocols ospf area 4 network '192.0.2.0/24'
+
+replaced_commands:
+ - delete protocols ospf interface eth2 passive
+ - delete protocols ospf area 3
+ - delete protocols ospf area 4 range 192.0.3.0/24 cost
+ - delete protocols ospf area 4 range 192.0.3.0/24
+ - delete protocols ospf area 4 range 192.0.4.0/24 cost
+ - delete protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf mpls-te router-address '192.0.22.22'
+ - set protocols ospf area 4 range 1.1.2.0/24 cost 10
+ - set protocols ospf area 4 range 1.1.2.0/24
+ - set protocols ospf area 4 network 192.0.12.0/24
+ - set protocols ospf area 4 network 192.0.22.0/24
+ - set protocols ospf area 4 network 192.0.32.0/24
+
+rendered_commands:
+ - set protocols ospf mpls-te enable
+ - set protocols ospf mpls-te router-address '192.0.11.11'
+ - set protocols ospf redistribute bgp
+ - set protocols ospf redistribute bgp metric-type 2
+ - set protocols ospf redistribute bgp metric 10
+ - set protocols ospf default-information originate metric-type 2
+ - set protocols ospf default-information originate always
+ - set protocols ospf default-information originate metric 10
+ - set protocols ospf default-information originate route-map ingress
+ - set protocols ospf auto-cost reference-bandwidth '2'
+ - set protocols ospf parameters router-id '192.0.1.1'
+ - set protocols ospf parameters opaque-lsa
+ - set protocols ospf parameters abr-type 'cisco'
+ - set protocols ospf parameters rfc1583-compatibility
+ - set protocols ospf interface eth1 passive
+ - set protocols ospf interface eth2 passive
+ - set protocols ospf max-metric router-lsa on-shutdown 10
+ - set protocols ospf max-metric router-lsa administrative
+ - set protocols ospf max-metric router-lsa on-startup 10
+ - set protocols ospf log-adjacency-changes 'detail'
+ - set protocols ospf neighbor 192.0.11.12 priority 2
+ - set protocols ospf neighbor 192.0.11.12 poll-interval 10
+ - set protocols ospf neighbor 192.0.11.12
+ - set protocols ospf area '2'
+ - set protocols ospf area 2 authentication plaintext-password
+ - set protocols ospf area 2 shortcut enable
+ - set protocols ospf area 2 area-type normal
+ - set protocols ospf area '3'
+ - set protocols ospf area 3 area-type nssa
+ - set protocols ospf area 4 range 192.0.3.0/24 cost 10
+ - set protocols ospf area 4 range 192.0.3.0/24
+ - set protocols ospf area 4 range 192.0.4.0/24 cost 12
+ - set protocols ospf area 4 range 192.0.4.0/24
+ - set protocols ospf area 4 area-type stub default-cost 20
+ - set protocols ospf area '4'
+ - set protocols ospf area 4 network 192.0.2.0/24
+
+parsed_config_file: "_parsed_config_1_4.cfg"
diff --git a/tests/unit/modules/network/vyos/test_vyos_ospfv2.py b/tests/unit/modules/network/vyos/test_vyos_ospfv2.py
index ec4018e1..2620b1cd 100644
--- a/tests/unit/modules/network/vyos/test_vyos_ospfv2.py
+++ b/tests/unit/modules/network/vyos/test_vyos_ospfv2.py
@@ -59,6 +59,18 @@ class TestVyosOspfv2Module(TestVyosModule):
)
self.execute_show_command = self.mock_execute_show_command.start()
+ self.mock_get_os_version = patch(
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospfv2.ospfv2.get_os_version"
+ )
+ self.test_version = "1.2"
+ self.get_os_version = self.mock_get_os_version.start()
+ self.get_os_version.return_value = self.test_version
+ self.mock_facts_get_os_version = patch(
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2.get_os_version"
+ )
+ self.get_facts_os_version = self.mock_facts_get_os_version.start()
+ self.get_facts_os_version.return_value = self.test_version
+ self.maxDiff = None
def tearDown(self):
super(TestVyosOspfv2Module, self).tearDown()
diff --git a/tests/unit/modules/network/vyos/test_vyos_ospfv2v14.py b/tests/unit/modules/network/vyos/test_vyos_ospfv2v14.py
new file mode 100644
index 00000000..5c77cb88
--- /dev/null
+++ b/tests/unit/modules/network/vyos/test_vyos_ospfv2v14.py
@@ -0,0 +1,437 @@
+# (c) 2016 Red Hat Inc.
+#
+# 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
+
+from unittest.mock import patch
+
+from ansible_collections.vyos.vyos.plugins.modules import vyos_ospfv2
+from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args
+
+from .vyos_module import TestVyosModule, load_fixture
+
+
+class TestVyosOspfv2Module14(TestVyosModule):
+ module = vyos_ospfv2
+
+ def setUp(self):
+ super(TestVyosOspfv2Module14, self).setUp()
+ self.mock_get_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config",
+ )
+ self.get_config = self.mock_get_config.start()
+
+ self.mock_load_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config",
+ )
+ self.load_config = self.mock_load_config.start()
+
+ self.mock_get_resource_connection_config = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection",
+ )
+ self.get_resource_connection_config = self.mock_get_resource_connection_config.start()
+
+ self.mock_get_resource_connection_facts = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection",
+ )
+ self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start()
+
+ self.mock_execute_show_command = patch(
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2.Ospfv2Facts.get_device_data",
+ )
+
+ self.execute_show_command = self.mock_execute_show_command.start()
+ self.mock_get_os_version = patch(
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospfv2.ospfv2.get_os_version"
+ )
+ self.test_version = "1.4"
+ self.get_os_version = self.mock_get_os_version.start()
+ self.get_os_version.return_value = self.test_version
+ self.mock_facts_get_os_version = patch(
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2.get_os_version"
+ )
+ self.get_facts_os_version = self.mock_facts_get_os_version.start()
+ self.get_facts_os_version.return_value = self.test_version
+ self.maxDiff = None
+
+ def tearDown(self):
+ super(TestVyosOspfv2Module14, self).tearDown()
+ self.mock_get_resource_connection_config.stop()
+ self.mock_get_resource_connection_facts.stop()
+ self.mock_get_config.stop()
+ self.mock_load_config.stop()
+ self.mock_execute_show_command.stop()
+
+ def load_fixtures(self, commands=None, filename=None):
+ if filename is None:
+ filename = "vyos_ospfv2_config.cfg"
+
+ def load_from_file(*args, **kwargs):
+ output = load_fixture(filename)
+ return output
+
+ self.execute_show_command.side_effect = load_from_file
+
+ def test_vyos_ospfv2_merged_new_config(self):
+ set_module_args(
+ dict(
+ config=dict(
+ log_adjacency_changes="detail",
+ mpls_te=dict(enabled=True, router_address="192.0.11.11"),
+ auto_cost=dict(reference_bandwidth=2),
+ areas=[
+ dict(
+ area_id="2",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="4",
+ area_type=dict(stub=dict(default_cost=10)),
+ network=[dict(address="192.0.2.0/24")],
+ range=[
+ dict(address="192.0.3.0/24", cost=10),
+ dict(address="192.0.4.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ )
+ commands = [
+ "set protocols ospf mpls-te enable",
+ "set protocols ospf mpls-te router-address '192.0.11.11'",
+ "set protocols ospf auto-cost reference-bandwidth '2'",
+ "set protocols ospf log-adjacency-changes 'detail'",
+ "set protocols ospf area '2'",
+ "set protocols ospf area 2 authentication plaintext-password",
+ "set protocols ospf area 2 shortcut enable",
+ "set protocols ospf area 2 area-type normal",
+ "set protocols ospf area 4 range 192.0.3.0/24 cost 10",
+ "set protocols ospf area 4 range 192.0.3.0/24",
+ "set protocols ospf area 4 range 192.0.4.0/24 cost 12",
+ "set protocols ospf area 4 range 192.0.4.0/24",
+ "set protocols ospf area 4 area-type stub default-cost 10",
+ "set protocols ospf area '4'",
+ "set protocols ospf area 4 network 192.0.2.0/24",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv2_merged_idem(self):
+ set_module_args(
+ dict(
+ config=dict(
+ areas=[
+ dict(
+ area_id="12",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="14",
+ area_type=dict(stub=dict(default_cost=20)),
+ network=[dict(address="192.0.12.0/24")],
+ range=[
+ dict(address="192.0.13.0/24", cost=10),
+ dict(address="192.0.14.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ )
+ self.execute_module(changed=False, commands=[])
+
+ def test_vyos_ospfv2_merged_update_existing(self):
+ set_module_args(
+ dict(
+ config=dict(
+ areas=[
+ dict(
+ area_id="12",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="14",
+ area_type=dict(stub=dict(set=False)),
+ network=[
+ dict(address="192.0.12.0/24"),
+ dict(address="192.0.22.0/24"),
+ ],
+ range=[
+ dict(address="192.0.13.0/24", cost=10),
+ dict(address="192.0.14.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ )
+ commands = [
+ "delete protocols ospf area 14 area-type stub",
+ "set protocols ospf area 14 network 192.0.22.0/24",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv2_replaced(self):
+ set_module_args(
+ dict(
+ config=dict(
+ log_adjacency_changes="detail",
+ mpls_te=dict(enabled=True, router_address="192.0.11.11"),
+ auto_cost=dict(reference_bandwidth=2),
+ areas=[
+ dict(
+ area_id="12",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="15",
+ area_type=dict(stub=dict(default_cost=10)),
+ network=[dict(address="192.0.12.0/24")],
+ range=[
+ dict(address="192.0.13.0/24", cost=10),
+ dict(address="192.0.14.0/24", cost=12),
+ dict(address="192.0.15.0/24", cost=14),
+ ],
+ ),
+ ],
+ ),
+ state="replaced",
+ ),
+ )
+ commands = [
+ "set protocols ospf mpls-te enable",
+ "set protocols ospf mpls-te router-address '192.0.11.11'",
+ "set protocols ospf auto-cost reference-bandwidth '2'",
+ "set protocols ospf log-adjacency-changes 'detail'",
+ "delete protocols ospf area 14",
+ "set protocols ospf area 15 range 192.0.13.0/24 cost 10",
+ "set protocols ospf area 15 range 192.0.13.0/24",
+ "set protocols ospf area 15 range 192.0.14.0/24 cost 12",
+ "set protocols ospf area 15 range 192.0.14.0/24",
+ "set protocols ospf area 15 range 192.0.15.0/24 cost 14",
+ "set protocols ospf area 15 range 192.0.15.0/24",
+ "set protocols ospf area 15 area-type stub default-cost 10",
+ "set protocols ospf area '15'",
+ "set protocols ospf area 15 network 192.0.12.0/24",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv2_replaced_idem(self):
+ set_module_args(
+ dict(
+ config=dict(
+ areas=[
+ dict(
+ area_id="12",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="14",
+ area_type=dict(stub=dict(default_cost=20)),
+ network=[dict(address="192.0.12.0/24")],
+ range=[
+ dict(address="192.0.13.0/24", cost=10),
+ dict(address="192.0.14.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="replaced",
+ ),
+ )
+ self.execute_module(changed=False, commands=[])
+
+ def test_vyos_ospfv2_deleted_no_config(self):
+ set_module_args(dict(config=None, state="deleted"))
+ commands = ["delete protocols ospf"]
+ self.execute_module(changed=True, commands=commands)
+
+ def test_vyos_ospfv2_gathered(self):
+ set_module_args(dict(state="gathered"))
+ result = self.execute_module(changed=False, filename="vyos_ospfv2_config.cfg")
+ gather_dict = {
+ "areas": [
+ {
+ "area_id": "2",
+ "area_type": {"normal": True},
+ "authentication": "plaintext-password",
+ "shortcut": "enable",
+ },
+ {
+ "area_id": "14",
+ "area_type": {"stub": {"default_cost": 20, "set": True}},
+ "network": [{"address": "192.0.12.0/24"}],
+ "range": [
+ {"address": "192.0.13.0/24", "cost": 10},
+ {"address": "192.0.14.0/24", "cost": 12},
+ ],
+ },
+ ],
+ }
+ self.assertEqual(sorted(gather_dict), sorted(result["gathered"]))
+
+ def test_vyos_ospfv2_parsed(self):
+ parsed_str = """set protocols ospf area 2 area-type 'normal'
+ set protocols ospf area 2 authentication 'plaintext-password'
+ set protocols ospf area 2 shortcut 'enable'
+ set protocols ospf area 3 area-type 'nssa'
+ set protocols ospf area 4 area-type stub default-cost '20'
+ set protocols ospf area 4 network '192.0.2.0/24'
+ set protocols ospf area 4 range 192.0.3.0/24 cost '10'
+ set protocols ospf area 4 range 192.0.4.0/24 cost '12'
+ set protocols ospf default-information originate 'always'
+ set protocols ospf default-information originate metric '10'
+ set protocols ospf default-information originate metric-type '2'
+set protocols ospf auto-cost reference-bandwidth '2'
+set protocols ospf default-information originate route-map 'ingress'
+set protocols ospf log-adjacency-changes 'detail'
+set protocols ospf max-metric router-lsa 'administrative'
+set protocols ospf max-metric router-lsa on-shutdown '10'
+set protocols ospf max-metric router-lsa on-startup '10'
+set protocols ospf mpls-te 'enable'
+set protocols ospf mpls-te router-address '192.0.11.11'
+set protocols ospf neighbor 192.0.11.12 poll-interval '10'
+set protocols ospf neighbor 192.0.11.12 priority '2'
+set protocols ospf parameters abr-type 'cisco'
+set protocols ospf parameters 'opaque-lsa'
+set protocols ospf parameters 'rfc1583-compatibility'
+set protocols ospf parameters router-id '192.0.1.1'
+set protocols ospf interface 'eth1' passive
+set protocols ospf interface 'eth2' passive
+set protocols ospf redistribute bgp metric '10'
+set protocols ospf redistribute bgp metric-type '2'"""
+ set_module_args(dict(running_config=parsed_str, state="parsed"))
+ result = self.execute_module(changed=False)
+ parsed_list = {
+ "areas": [
+ {
+ "area_id": "2",
+ "area_type": {"normal": True},
+ "authentication": "plaintext-password",
+ "shortcut": "enable",
+ },
+ {"area_id": "3", "area_type": {"nssa": {"set": True}}},
+ {
+ "area_id": "4",
+ "area_type": {"stub": {"default_cost": 20, "set": True}},
+ "network": [{"address": "192.0.2.0/24"}],
+ "range": [
+ {"address": "192.0.3.0/24", "cost": 10},
+ {"address": "192.0.4.0/24", "cost": 12},
+ ],
+ },
+ ],
+ "auto_cost": {"reference_bandwidth": 2},
+ "default_information": {
+ "originate": {
+ "always": True,
+ "metric": 10,
+ "metric_type": 2,
+ "route_map": "ingress",
+ },
+ },
+ "log_adjacency_changes": "detail",
+ "max_metric": {
+ "router_lsa": {
+ "administrative": True,
+ "on_shutdown": 10,
+ "on_startup": 10,
+ },
+ },
+ "mpls_te": {"enabled": True, "router_address": "192.0.11.11"},
+ "neighbor": [
+ {
+ "neighbor_id": "192.0.11.12",
+ "poll_interval": 10,
+ "priority": 2,
+ },
+ ],
+ "parameters": {
+ "abr_type": "cisco",
+ "opaque_lsa": True,
+ "rfc1583_compatibility": True,
+ "router_id": "192.0.1.1",
+ },
+ "passive_interface": ["eth2", "eth1"],
+ "redistribute": [{"metric": 10, "metric_type": 2, "route_type": "bgp"}],
+ }
+ self.assertEqual(sorted(parsed_list), sorted(result["parsed"]))
+
+ def test_vyos_ospfv2_rendered(self):
+ set_module_args(
+ dict(
+ config=dict(
+ log_adjacency_changes="detail",
+ mpls_te=dict(enabled=True, router_address="192.0.11.11"),
+ auto_cost=dict(reference_bandwidth=2),
+ areas=[
+ dict(
+ area_id="2",
+ area_type=dict(normal=True),
+ authentication="plaintext-password",
+ shortcut="enable",
+ ),
+ dict(
+ area_id="4",
+ area_type=dict(stub=dict(default_cost=10)),
+ network=[dict(address="192.0.2.0/24")],
+ range=[
+ dict(address="192.0.3.0/24", cost=10),
+ dict(address="192.0.4.0/24", cost=12),
+ ],
+ ),
+ ],
+ ),
+ state="rendered",
+ ),
+ )
+ commands = [
+ "set protocols ospf mpls-te enable",
+ "set protocols ospf mpls-te router-address '192.0.11.11'",
+ "set protocols ospf auto-cost reference-bandwidth '2'",
+ "set protocols ospf log-adjacency-changes 'detail'",
+ "set protocols ospf area '2'",
+ "set protocols ospf area 2 authentication plaintext-password",
+ "set protocols ospf area 2 shortcut enable",
+ "set protocols ospf area 2 area-type normal",
+ "set protocols ospf area 4 range 192.0.3.0/24 cost 10",
+ "set protocols ospf area 4 range 192.0.3.0/24",
+ "set protocols ospf area 4 range 192.0.4.0/24 cost 12",
+ "set protocols ospf area 4 range 192.0.4.0/24",
+ "set protocols ospf area 4 area-type stub default-cost 10",
+ "set protocols ospf area '4'",
+ "set protocols ospf area 4 network 192.0.2.0/24",
+ ]
+ result = self.execute_module(changed=False)
+ self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"])