Skip to content

Commit 41e4b07

Browse files
authored
T6829 (area interfaces in OSPFv3 1.3-1.5) re-init (#399)
* T6829 re-init * re-init T6829 ospfv3 area interface for 1.3- * changelog * changelog fix * Doc is updated * adding 1.4+ support * ospfv3 area interfaces for 1.4+ * fixed ospfv3 facts and added area interface unit test for 1.4 * ospfv3 clean-up * doc updates
1 parent 241de48 commit 41e4b07

File tree

8 files changed

+166
-5
lines changed

8 files changed

+166
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bugfixes:
3+
- vyos_ospfv3 - added support for adding interfaces to areas
4+
trivial:
5+
- vyos_ospfv3 - updated unit test suites to include area interfaces
6+
- vyos_ospfv3 - added v1.4 unit test

docs/vyos.vyos.vyos_ospfv3_module.rst

+38
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,44 @@ Parameters
116116
<div>Name of import-list.</div>
117117
</td>
118118
</tr>
119+
<tr>
120+
<td class="elbow-placeholder"></td>
121+
<td class="elbow-placeholder"></td>
122+
<td colspan="2">
123+
<div class="ansibleOptionAnchor" id="parameter-"></div>
124+
<b>interface</b>
125+
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
126+
<div style="font-size: small">
127+
<span style="color: purple">list</span>
128+
/ <span style="color: purple">elements=dictionary</span>
129+
</div>
130+
</td>
131+
<td>
132+
</td>
133+
<td>
134+
<div>Enable OSPVv3 on an interface for this area.</div>
135+
<div style="font-size: small; color: darkgreen"><br/>aliases: interfaces</div>
136+
</td>
137+
</tr>
138+
<tr>
139+
<td class="elbow-placeholder"></td>
140+
<td class="elbow-placeholder"></td>
141+
<td class="elbow-placeholder"></td>
142+
<td colspan="1">
143+
<div class="ansibleOptionAnchor" id="parameter-"></div>
144+
<b>name</b>
145+
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
146+
<div style="font-size: small">
147+
<span style="color: purple">string</span>
148+
</div>
149+
</td>
150+
<td>
151+
</td>
152+
<td>
153+
<div>Interface name.</div>
154+
</td>
155+
</tr>
156+
119157
<tr>
120158
<td class="elbow-placeholder"></td>
121159
<td class="elbow-placeholder"></td>

plugins/module_utils/network/vyos/argspec/ospfv3/ospfv3.py

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ def __init__(self, **kwargs):
4747
"area_id": {"type": "str"},
4848
"export_list": {"type": "str"},
4949
"import_list": {"type": "str"},
50+
"interface": {
51+
"aliases": ["interfaces"],
52+
"type": "list",
53+
"elements": "dict",
54+
"options": {"name": {"type": "str"}},
55+
},
5056
"range": {
5157
"elements": "dict",
5258
"options": {

plugins/module_utils/network/vyos/config/ospfv3/ospfv3.py

+38-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
_in_target,
3434
_is_w_same,
3535
)
36+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import (
37+
LooseVersion,
38+
)
39+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version
3640

3741

3842
class Ospfv3(ConfigBase):
@@ -264,10 +268,12 @@ def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True):
264268
name = {
265269
"redistribute": "route_type",
266270
"range": "address",
271+
"interface": "name",
267272
}
268273
leaf_dict = {
269274
"redistribute": ("route_map", "route_type"),
270275
"range": ("address", "advertise", "not_advertise"),
276+
"interface": ("name"),
271277
}
272278
leaf = leaf_dict[attr]
273279
w = want.get(attr) or []
@@ -282,14 +288,26 @@ def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True):
282288
cmd = self._compute_command(opr=opr)
283289
h_item = search_obj_in_list(w_item[name[attr]], h, name[attr])
284290
if opr and key in leaf and not _is_w_same(w_item, h_item, key):
285-
if key == "route_type" or (
291+
if key in ["route_type", "name"] or (
286292
key == "address"
287293
and "advertise" not in w_item
288294
and "not-advertise" not in w_item
289295
):
290296
if not val:
291297
cmd = cmd.replace("set", "delete")
292-
commands.append(cmd + attr + " " + str(val))
298+
if (
299+
LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4")
300+
and attr == "interface"
301+
):
302+
words = cmd.split()
303+
cmd14_list = []
304+
for word in words:
305+
cmd14_list.append(word)
306+
if word == "ospfv3":
307+
cmd14_list.append(attr + " " + str(val))
308+
commands.append(" ".join(cmd14_list))
309+
else:
310+
commands.append(cmd + attr + " " + str(val))
293311
elif key in leaf_dict["range"] and key != "address":
294312
commands.append(
295313
cmd + attr + " " + w_item[name[attr]] + " " + key.replace("_", "-"),
@@ -306,8 +324,20 @@ def _render_list_dict_param(self, attr, want, have, cmd=None, opr=True):
306324
+ str(val),
307325
)
308326
elif not opr and key in leaf and not _in_target(h_item, key):
309-
if key in ("route_type", "address"):
310-
commands.append(cmd + attr + " " + str(val))
327+
if key in ("route_type", "address", "name"):
328+
if (
329+
LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4")
330+
and attr == "interface"
331+
):
332+
words = cmd.split()
333+
cmd14_list = []
334+
for word in words:
335+
cmd14_list.append(word)
336+
if word == "ospfv3":
337+
cmd14_list.append(attr + " " + str(val))
338+
commands.append(" ".join(cmd14_list))
339+
else:
340+
commands.append(cmd + attr + " " + str(val))
311341
else:
312342
commands.append(cmd + (attr + " " + w_item[name[attr]] + " " + key))
313343
return commands
@@ -373,6 +403,10 @@ def _render_areas(self, attr, want, have, opr=True):
373403
commands.extend(
374404
self._render_list_dict_param(key, w_area, h_area, cmd, opr),
375405
)
406+
elif key == "interface":
407+
commands.extend(
408+
self._render_list_dict_param(key, w_area, h_area, cmd, opr),
409+
)
376410
return commands
377411

378412
def _form_attr_cmd(self, key=None, attr=None, val=None, opr=True):

plugins/module_utils/network/vyos/facts/ospfv3/ospfv3.py

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospfv3.ospfv3 import (
2323
Ospfv3Args,
2424
)
25+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import (
26+
LooseVersion,
27+
)
28+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version
2529

2630

2731
class Ospfv3Facts(object):
@@ -100,6 +104,9 @@ def parse_attrib_list(self, conf, attrib, param):
100104
for item in set(items):
101105
i_regex = r" %s .+$" % item
102106
cfg = "\n".join(findall(i_regex, conf, M))
107+
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
108+
cfg14 = findall(r"(interface .+) area '%s'$" % item, conf, M)
109+
cfg += "\n " + item + " " + " ".join(cfg14)
103110
if attrib == "area":
104111
obj = self.parse_area(cfg, item)
105112
else:
@@ -121,6 +128,8 @@ def parse_area(self, conf, area_id):
121128
rule = self.parse_attrib(conf, "area_id", match=area_id)
122129
r_sub = {"range": self.parse_attrib_list(conf, "range", "address")}
123130
rule.update(r_sub)
131+
r_int = {"interface": self.parse_attrib_list(conf, "interface", "name")}
132+
rule.update(r_int)
124133
return rule
125134

126135
def parse_attrib(self, conf, param, match=None):
@@ -133,6 +142,7 @@ def parse_attrib(self, conf, param, match=None):
133142
"area_id": ["export_list", "import_list"],
134143
"redistribute": ["route_map"],
135144
"range": ["advertise", "not_advertise"],
145+
"interface": ["name"],
136146
"parameters": ["router_id"],
137147
}
138148
cfg_dict = self.parse_attr(conf, param_lst[param], match)

plugins/modules/vyos_ospfv3.py

+9
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@
6868
import_list:
6969
description: Name of import-list.
7070
type: str
71+
interface:
72+
description: Enable OSPVv3 on an interface for this area.
73+
aliases: ['interfaces']
74+
type: list
75+
elements: dict
76+
suboptions:
77+
name:
78+
description: Interface name.
79+
type: str
7180
range:
7281
description: Summarize routes matching prefix (border routers only).
7382
type: list

tests/integration/targets/vyos_ospf_interfaces/tests/cli/_get_version.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@
2626
- name: include correct vars
2727
include_vars: v1_4.yaml
2828
when: vyos_version is version('1.4.0', '>=', version_type='semver')
29-
3029
# - name: include common vars
3130
# include_vars: main.yaml

tests/unit/modules/network/vyos/test_vyos_ospfv3.py

+59
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ def setUp(self):
6060

6161
self.execute_show_command = self.mock_execute_show_command.start()
6262

63+
self.mock_get_os_version = patch(
64+
"ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospfv3.ospfv3.get_os_version",
65+
)
66+
67+
self.test_version = "1.3"
68+
self.get_os_version = self.mock_get_os_version.start()
69+
self.get_os_version.return_value = self.test_version
70+
self.mock_facts_get_os_version = patch(
71+
"ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv3.ospfv3.get_os_version",
72+
)
73+
self.get_facts_os_version = self.mock_facts_get_os_version.start()
74+
self.get_facts_os_version.return_value = self.test_version
75+
self.maxDiff = None
76+
6377
def tearDown(self):
6478
super(TestVyosOspfv3Module, self).tearDown()
6579
self.mock_get_resource_connection_config.stop()
@@ -94,6 +108,50 @@ def test_vyos_ospfv3_merged_new_config(self):
94108
dict(address="2001:db20::/32"),
95109
dict(address="2001:db30::/32"),
96110
],
111+
interfaces=[dict(name="eth0")],
112+
),
113+
dict(
114+
area_id="3",
115+
range=[dict(address="2001:db40::/32")],
116+
),
117+
],
118+
),
119+
state="merged",
120+
),
121+
)
122+
commands = [
123+
"set protocols ospfv3 redistribute bgp",
124+
"set protocols ospfv3 parameters router-id '192.0.2.10'",
125+
"set protocols ospfv3 area 2 range 2001:db10::/32",
126+
"set protocols ospfv3 area 2 range 2001:db20::/32",
127+
"set protocols ospfv3 area 2 range 2001:db30::/32",
128+
"set protocols ospfv3 area '2'",
129+
"set protocols ospfv3 area 2 interface eth0",
130+
"set protocols ospfv3 area 2 export-list export1",
131+
"set protocols ospfv3 area 2 import-list import1",
132+
"set protocols ospfv3 area '3'",
133+
"set protocols ospfv3 area 3 range 2001:db40::/32",
134+
]
135+
self.execute_module(changed=True, commands=commands)
136+
137+
def test_vyos_ospfv3_merged_new_config14(self):
138+
self.get_os_version.return_value = "1.4"
139+
set_module_args(
140+
dict(
141+
config=dict(
142+
redistribute=[dict(route_type="bgp")],
143+
parameters=dict(router_id="192.0.2.10"),
144+
areas=[
145+
dict(
146+
area_id="2",
147+
export_list="export1",
148+
import_list="import1",
149+
range=[
150+
dict(address="2001:db10::/32"),
151+
dict(address="2001:db20::/32"),
152+
dict(address="2001:db30::/32"),
153+
],
154+
interfaces=[dict(name="eth0")],
97155
),
98156
dict(
99157
area_id="3",
@@ -111,6 +169,7 @@ def test_vyos_ospfv3_merged_new_config(self):
111169
"set protocols ospfv3 area 2 range 2001:db20::/32",
112170
"set protocols ospfv3 area 2 range 2001:db30::/32",
113171
"set protocols ospfv3 area '2'",
172+
"set protocols ospfv3 interface eth0 area 2",
114173
"set protocols ospfv3 area 2 export-list export1",
115174
"set protocols ospfv3 area 2 import-list import1",
116175
"set protocols ospfv3 area '3'",

0 commit comments

Comments
 (0)