summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromnom62 <75066712+omnom62@users.noreply.github.com>2025-04-03 08:11:36 +1000
committerGitHub <noreply@github.com>2025-04-02 23:11:36 +0100
commit9a6bd2f99c91d81391fbff8a32b7b6f3ee3b5e57 (patch)
treed03053cf10dc14a514a708e57d10ec3a7b8e3826
parent41e4b0734ca961d18c0a016a50b3c6e598a10dff (diff)
downloadvyos.vyos-9a6bd2f99c91d81391fbff8a32b7b6f3ee3b5e57.tar.gz
vyos.vyos-9a6bd2f99c91d81391fbff8a32b7b6f3ee3b5e57.zip
T6831 OSPF VIF (#400)
* t6831_ospf_vif init * ospf_vif 1.3 provisioning workflow * changelog * ospf-interface unit tests fix * parser tests * ospf vif parsers updated * added vif unt test cases for ospf_interfaces * ospf vif integration tests * fixing eth names and utils func * ospf vif prep/demolih updates * added new vif test cases
-rw-r--r--changelogs/fragments/T6831_ospf_vif.yml3
-rw-r--r--plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py28
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py139
-rw-r--r--plugins/module_utils/network/vyos/utils/utils.py12
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/tasks/post_tasks.yml2
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/tasks/pre_tasks.yml2
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml1
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml6
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml1
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml5
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml1
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml6
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/vars/pre-v1_4.yaml5
-rw-r--r--tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml5
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py32
-rw-r--r--tests/unit/modules/network/vyos/test_vyos_ospf_interfaces14.py61
16 files changed, 225 insertions, 84 deletions
diff --git a/changelogs/fragments/T6831_ospf_vif.yml b/changelogs/fragments/T6831_ospf_vif.yml
new file mode 100644
index 00000000..97a4c7c8
--- /dev/null
+++ b/changelogs/fragments/T6831_ospf_vif.yml
@@ -0,0 +1,3 @@
+---
+minor_changes:
+ - vyos_ospf_interfaces - add support for VyOS 1.3- virtual interfaces
diff --git a/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py
index 852e1da7..2160fc71 100644
--- a/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py
+++ b/plugins/module_utils/network/vyos/facts/ospf_interfaces/ospf_interfaces.py
@@ -23,17 +23,16 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.osp
Ospf_interfacesArgs,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ospf_interfaces import (
- Ospf_interfacesTemplate
+ Ospf_interfacesTemplate,
)
-
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ospf_interfaces_14 import (
- Ospf_interfacesTemplate14
+ Ospf_interfacesTemplate14,
+)
+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
-from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion
-
class Ospf_interfacesFacts(object):
"""The vyos ospf_interfaces facts class"""
@@ -54,7 +53,9 @@ class Ospf_interfacesFacts(object):
for config_line in data.splitlines():
ospf_int = re.search(r"set protocols (?:ospf|ospfv3) interface (\S+).*", config_line)
if ospf_int:
- config_dict[ospf_int.group(1)] = config_dict.get(ospf_int.group(1), "") + config_line + "\n"
+ config_dict[ospf_int.group(1)] = (
+ config_dict.get(ospf_int.group(1), "") + config_line + "\n"
+ )
return list(config_dict.values())
def get_config_set_1_2(self, data):
@@ -63,12 +64,15 @@ class Ospf_interfacesFacts(object):
config_set = []
int_string = ""
for config_line in data.splitlines():
- ospf_int = re.search(r"set interfaces \S+ (\S+) .*", config_line)
+ ospf_int_raw = re.findall(r"^set interfaces \S+ (\S+)", config_line, re.M)
+ ospf_int_vif = re.findall(r"^set interfaces \S+ (\S+) vif (\d+)", config_line, re.M)
+
+ ospf_int = ospf_int_raw + ospf_int_vif
if ospf_int:
- if ospf_int.group(1) not in interface_list:
+ if ospf_int not in interface_list:
if int_string:
config_set.append(int_string)
- interface_list.append(ospf_int.group(1))
+ interface_list.append(ospf_int)
int_string = ""
int_string = int_string + config_line + "\n"
if int_string:
@@ -115,7 +119,6 @@ class Ospf_interfacesFacts(object):
if key in objs and objs[key]:
objs[key] = list(objs[key].values())
ospf_interfaces_facts.append(objs)
-
ansible_facts["ansible_network_resources"].pop("ospf_interfaces", None)
facts = {"ospf_interfaces": []}
params = utils.remove_empties(
@@ -123,11 +126,10 @@ class Ospf_interfacesFacts(object):
self.argument_spec,
{"config": ospf_interfaces_facts},
redact=True,
- )
+ ),
)
if params.get("config"):
for cfg in params["config"]:
facts["ospf_interfaces"].append(utils.remove_empties(cfg))
ansible_facts["ansible_network_resources"].update(facts)
-
return ansible_facts
diff --git a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py
index 0d7eaf84..134effca 100644
--- a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py
+++ b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py
@@ -23,6 +23,7 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.r
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import (
get_interface_type,
+ get_interface_with_vif,
)
@@ -36,21 +37,23 @@ def _get_parameters(data):
def _tmplt_ospf_int_delete(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
- command = (
- "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0]
- )
+ command = "interfaces " + int_type + " " + name + " " + params[1] + " " + params[0]
return command
def _tmplt_ospf_int_cost(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -62,11 +65,14 @@ def _tmplt_ospf_int_cost(config_data):
def _tmplt_ospf_int_auth_password(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -79,11 +85,14 @@ def _tmplt_ospf_int_auth_password(config_data):
def _tmplt_ospf_int_auth_md5(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -98,11 +107,14 @@ def _tmplt_ospf_int_auth_md5(config_data):
def _tmplt_ospf_int_auth_md5_delete(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -114,11 +126,14 @@ def _tmplt_ospf_int_auth_md5_delete(config_data):
def _tmplt_ospf_int_bw(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -130,11 +145,14 @@ def _tmplt_ospf_int_bw(config_data):
def _tmplt_ospf_int_hello_interval(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -146,11 +164,14 @@ def _tmplt_ospf_int_hello_interval(config_data):
def _tmplt_ospf_int_dead_interval(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -162,15 +183,10 @@ def _tmplt_ospf_int_dead_interval(config_data):
def _tmplt_ospf_int_mtu_ignore(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
- "interfaces "
- + int_type
- + " {name} ".format(**config_data)
- + params[1]
- + " "
- + params[0]
- + " mtu-ignore"
+ "interfaces " + int_type + " " + name + " " + params[1] + " " + params[0] + " mtu-ignore"
)
return command
@@ -178,11 +194,14 @@ def _tmplt_ospf_int_mtu_ignore(config_data):
def _tmplt_ospf_int_network(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -194,11 +213,14 @@ def _tmplt_ospf_int_network(config_data):
def _tmplt_ospf_int_priority(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -210,11 +232,14 @@ def _tmplt_ospf_int_priority(config_data):
def _tmplt_ospf_int_retransmit_interval(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -226,11 +251,14 @@ def _tmplt_ospf_int_retransmit_interval(config_data):
def _tmplt_ospf_int_transmit_delay(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -242,11 +270,14 @@ def _tmplt_ospf_int_transmit_delay(config_data):
def _tmplt_ospf_int_ifmtu(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -258,11 +289,14 @@ def _tmplt_ospf_int_ifmtu(config_data):
def _tmplt_ospf_int_instance(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
command = (
"interfaces "
+ int_type
- + " {name} ".format(**config_data)
+ + " "
+ + name
+ + " "
+ params[1]
+ " "
+ params[0]
@@ -274,16 +308,9 @@ def _tmplt_ospf_int_instance(config_data):
def _tmplt_ospf_int_passive(config_data):
int_type = get_interface_type(config_data["name"])
+ name = get_interface_with_vif(config_data["name"])
params = _get_parameters(config_data["address_family"])
- command = (
- "interfaces "
- + int_type
- + " {name} ".format(**config_data)
- + params[1]
- + " "
- + params[0]
- + " passive"
- )
+ command = "interfaces " + int_type + " " + name + " " + params[1] + " " + params[0] + " passive"
return command
@@ -308,6 +335,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
*$""",
@@ -316,7 +344,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"remval": _tmplt_ospf_int_delete,
"compval": "address_family",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -332,6 +360,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+authentication
@@ -343,7 +372,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_auth_password,
"compval": "address_family.authentication",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -362,6 +391,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+authentication
@@ -377,7 +407,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"remval": _tmplt_ospf_int_auth_md5_delete,
"compval": "address_family.authentication",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -399,6 +429,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+bandwidth
@@ -409,7 +440,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_bw,
"compval": "address_family.bandwidth",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -426,6 +457,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+cost
@@ -436,7 +468,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_cost,
"compval": "address_family.cost",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -453,6 +485,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+hello-interval
@@ -463,7 +496,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_hello_interval,
"compval": "address_family.hello_interval",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -480,6 +513,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+dead-interval
@@ -490,7 +524,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_dead_interval,
"compval": "address_family.dead_interval",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -507,6 +541,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+(?P<mtu>mtu-ignore)
@@ -516,7 +551,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_mtu_ignore,
"compval": "address_family.mtu_ignore",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -533,6 +568,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+network
@@ -543,7 +579,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_network,
"compval": "address_family.network",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -560,6 +596,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+priority
@@ -570,7 +607,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_priority,
"compval": "address_family.priority",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -587,6 +624,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+retransmit-interval
@@ -597,7 +635,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_retransmit_interval,
"compval": "address_family.retransmit_interval",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -614,6 +652,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+transmit-delay
@@ -624,7 +663,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_transmit_delay,
"compval": "address_family.transmit_delay",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -641,6 +680,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+ifmtu
@@ -651,7 +691,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_ifmtu,
"compval": "address_family.ifmtu",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -668,6 +708,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+instance-id
@@ -678,7 +719,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_instance,
"compval": "address_family.instance",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -695,6 +736,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+(?P<pass>passive)
@@ -704,7 +746,7 @@ class Ospf_interfacesTemplate(NetworkTemplate):
"setval": _tmplt_ospf_int_passive,
"compval": "address_family.passive",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
"address_family": {
"{{ afi }}": {
"afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}',
@@ -721,12 +763,13 @@ class Ospf_interfacesTemplate(NetworkTemplate):
\s+interfaces
\s+(?P<type>\S+)
\s+(?P<name>\S+)
+ (?:\s+vif\s+(?P<vif>\d+))?
.*$""",
re.VERBOSE,
),
"setval": "set interface {{ type }} {{ name }}",
"result": {
- "name": "{{ name }}",
+ "name": "{{ name + '.' + vif if vif is defined else name }}",
},
},
]
diff --git a/plugins/module_utils/network/vyos/utils/utils.py b/plugins/module_utils/network/vyos/utils/utils.py
index 8722251e..a6b03c80 100644
--- a/plugins/module_utils/network/vyos/utils/utils.py
+++ b/plugins/module_utils/network/vyos/utils/utils.py
@@ -50,6 +50,18 @@ def get_interface_type(interface):
return "dummy"
+def get_interface_with_vif(interface):
+ """Gets virtual interface if any or return as is"""
+ vlan = None
+ interface_real = interface
+ if "." in interface:
+ interface_real, vlan = interface.split(".")
+
+ if vlan is not None:
+ interface_real = interface_real + " vif " + vlan
+ return interface_real
+
+
def dict_delete(base, comparable):
"""
This function generates a dict containing key, value pairs for keys
diff --git a/tests/integration/targets/vyos_ospf_interfaces/tasks/post_tasks.yml b/tests/integration/targets/vyos_ospf_interfaces/tasks/post_tasks.yml
index 0883ef48..f6b009a8 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/tasks/post_tasks.yml
+++ b/tests/integration/targets/vyos_ospf_interfaces/tasks/post_tasks.yml
@@ -3,5 +3,7 @@
vyos.vyos.vyos_config:
lines: |-
delete interfaces bonding bond2
+ delete interfaces ethernet eth2 vif 3
+ delete interfaces ethernet eth2 vif 18
vars:
ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_ospf_interfaces/tasks/pre_tasks.yml b/tests/integration/targets/vyos_ospf_interfaces/tasks/pre_tasks.yml
index af74ff7a..fdb4981c 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/tasks/pre_tasks.yml
+++ b/tests/integration/targets/vyos_ospf_interfaces/tasks/pre_tasks.yml
@@ -3,5 +3,7 @@
vyos.vyos.vyos_config:
lines: |-
set interfaces bonding bond2
+ set interfaces ethernet eth2 vif 3
+ set interfaces ethernet eth2 vif 18
vars:
ansible_connection: ansible.netcommon.network_cli
diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml
index 59fe52ac..bd70d071 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml
+++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml
@@ -17,7 +17,6 @@
- assert:
that:
- - result.commands|length == 2
- result.changed == true
- result.commands|symmetric_difference(deleted.commands) == []
- result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == []
diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml
index 7b091dd7..ddff03c9 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml
+++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml
@@ -17,6 +17,11 @@
- afi: ipv6
mtu_ignore: true
instance: 33
+ - name: eth2.3
+ address_family:
+ - afi: ipv4
+ cost: 60
+ priority: 40
- name: bond2
address_family:
- afi: ipv4
@@ -30,7 +35,6 @@
- assert:
that:
- - result.commands|length == 6
- result.changed == true
- result.commands|symmetric_difference(merged.commands) == []
- result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == []
diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml
index 7e728069..252336fc 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml
+++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml
@@ -24,7 +24,6 @@
- assert:
that:
- - result.commands|length == 8
- result.changed == true
- result.commands|symmetric_difference(overridden.commands) == []
- result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == []
diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml
index 4cb5f4f9..5a07c95d 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml
+++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml
@@ -17,6 +17,11 @@
- afi: ipv6
mtu_ignore: true
instance: 33
+ - name: eth2.3
+ address_family:
+ - afi: ipv4
+ cost: 60
+ priority: 40
- name: bond2
address_family:
- afi: ipv4
diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml
index 2bb8a02f..7a5b9fa8 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml
+++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml
@@ -35,7 +35,6 @@
- assert:
that:
- - result.commands|length == 8
- result.changed == true
- result.commands|symmetric_difference(replaced.commands) == []
- result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == []
diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml
index c74248e0..e2464457 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml
+++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml
@@ -19,6 +19,11 @@
- afi: ipv6
mtu_ignore: true
instance: 33
+ - name: eth2.3
+ address_family:
+ - afi: ipv4
+ cost: 60
+ priority: 40
- name: bond2
address_family:
- afi: ipv4
@@ -32,7 +37,6 @@
- assert:
that:
- - baseconfig.commands|length == 6
- baseconfig.changed == true
- baseconfig.commands|symmetric_difference(merged.commands) == []
- baseconfig.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == []
diff --git a/tests/integration/targets/vyos_ospf_interfaces/vars/pre-v1_4.yaml b/tests/integration/targets/vyos_ospf_interfaces/vars/pre-v1_4.yaml
index a9e03421..7f84e92e 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/vars/pre-v1_4.yaml
+++ b/tests/integration/targets/vyos_ospf_interfaces/vars/pre-v1_4.yaml
@@ -4,6 +4,8 @@ merged_commands:
- set interfaces ethernet eth0 ip ospf priority 26
- set interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore
- set interfaces ethernet eth0 ipv6 ospfv3 instance-id 33
+ - set interfaces ethernet eth2 vif 3 ip ospf cost 60
+ - set interfaces ethernet eth2 vif 3 ip ospf priority 40
- set interfaces bonding bond2 ip ospf transmit-delay 45
- set interfaces bonding bond2 ipv6 ospfv3 passive
@@ -12,6 +14,7 @@ populate_commands:
- set interfaces ethernet eth0 ip ospf priority 26
- set interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore
- set interfaces ethernet eth0 ipv6 ospfv3 instance-id 33
+ - set interfaces ethernet eth2 vif 18 ip ospf cost 80
- set interfaces bonding bond2 ip ospf transmit-delay 45
- set interfaces bonding bond2 ipv6 ospfv3 passive
@@ -20,6 +23,7 @@ remove_commands:
- delete interfaces ethernet eth0 ipv6 ospfv3
- delete interfaces ethernet eth1 ip ospf
- delete interfaces ethernet eth1 ipv6 ospfv3
+ - delete interfaces ethernet eth2 vif 3 ip ospf
- delete interfaces bonding bond1 ip ospf
- delete interfaces bonding bond1 ipv6 ospfv3
- delete interfaces bonding bond2 ip ospf
@@ -41,6 +45,7 @@ replaced_commands:
overridden_commands:
- delete interfaces bonding bond2 ip ospf
- delete interfaces bonding bond2 ipv6 ospfv3
+ - delete interfaces ethernet eth2 vif 18 ip ospf
- set interfaces ethernet eth0 ip ospf transmit-delay 50
- set interfaces ethernet eth0 ip ospf network point-to-point
- set interfaces ethernet eth0 ipv6 ospfv3 dead-interval 39
diff --git a/tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml b/tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml
index 15b7f5a7..3864f33a 100644
--- a/tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml
+++ b/tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml
@@ -4,6 +4,8 @@ merged_commands:
- set protocols ospf interface eth0 priority 26
- set protocols ospfv3 interface eth0 mtu-ignore
- set protocols ospfv3 interface eth0 instance-id 33
+ - set protocols ospf interface eth2.3 cost 60
+ - set protocols ospf interface eth2.3 priority 40
- set protocols ospfv3 interface bond2 passive
- set protocols ospf interface bond2 transmit-delay 45
@@ -12,11 +14,13 @@ populate_commands:
- set protocols ospf interface eth0 priority 26
- set protocols ospfv3 interface eth0 mtu-ignore
- set protocols ospfv3 interface eth0 instance-id 33
+ - set protocols ospf interface eth2.18 cost 80
- set protocols ospfv3 interface bond2 passive
- set protocols ospf interface bond2 transmit-delay 45
remove_commands:
- delete protocols ospf interface eth0
+ - delete protocols ospf interface eth2.3
- delete protocols ospf interface bond2
- delete protocols ospfv3 interface bond2
- delete protocols ospfv3 interface eth0
@@ -36,6 +40,7 @@ replaced_commands:
overridden_commands:
- delete protocols ospf interface bond2
- delete protocols ospfv3 interface bond2
+ - delete protocols ospf interface eth2.18
- set protocols ospf interface eth0 transmit-delay 50
- set protocols ospf interface eth0 network point-to-point
- set protocols ospfv3 interface eth0 dead-interval 39
diff --git a/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py
index c7d69d0d..b0a0f0ff 100644
--- a/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py
+++ b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py
@@ -44,13 +44,13 @@ class TestVyosOspfInterfacesModule(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.ospf_interfaces.ospf_interfaces.get_os_version"
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospf_interfaces.ospf_interfaces.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.ospf_interfaces.ospf_interfaces.get_os_version"
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces.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
@@ -118,6 +118,34 @@ class TestVyosOspfInterfacesModule(TestVyosModule):
]
self.execute_module(changed=True, commands=commands)
+ def test_vyos_ospf_interfaces_merged_vif_config(self):
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ name="eth0.3",
+ address_family=[
+ dict(
+ afi="ipv4",
+ cost=100,
+ authentication=dict(plaintext_password="abcdefg!"),
+ priority=55,
+ ),
+ dict(afi="ipv6", mtu_ignore=True),
+ ],
+ ),
+ ],
+ state="merged",
+ ),
+ )
+ commands = [
+ "set interfaces ethernet eth0 vif 3 ip ospf cost 100",
+ "set interfaces ethernet eth0 vif 3 ip ospf priority 55",
+ "set interfaces ethernet eth0 vif 3 ip ospf authentication plaintext-password abcdefg!",
+ "set interfaces ethernet eth0 vif 3 ipv6 ospfv3 mtu-ignore",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
def test_vyos_ospf_interfaces_merged_idempotent(self):
set_module_args(
dict(
diff --git a/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces14.py b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces14.py
index ef27860a..d3f8bc38 100644
--- a/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces14.py
+++ b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces14.py
@@ -18,6 +18,7 @@
# Make coding more python3-ish
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
from unittest.mock import patch
@@ -34,22 +35,22 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
def setUp(self):
super(TestVyosOspfInterfacesModule14, self).setUp()
self.mock_get_resource_connection_config = patch(
- "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection"
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection",
)
self.get_resource_connection_config = self.mock_get_resource_connection_config.start()
self.mock_execute_show_command = patch(
- "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces.Ospf_interfacesFacts.get_device_data"
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces.Ospf_interfacesFacts.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.ospf_interfaces.ospf_interfaces.get_os_version"
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospf_interfaces.ospf_interfaces.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.ospf_interfaces.ospf_interfaces.get_os_version"
+ "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces.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
@@ -104,7 +105,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="merged",
- )
+ ),
)
commands = [
"set protocols ospf interface bond2 transmit-delay 9",
@@ -116,6 +117,34 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
]
self.execute_module(changed=True, commands=commands)
+ def test_vyos_ospf_interfaces_merged_vif_config(self):
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ name="eth0.3",
+ address_family=[
+ dict(
+ afi="ipv4",
+ cost=100,
+ authentication=dict(plaintext_password="abcdefg!"),
+ priority=55,
+ ),
+ dict(afi="ipv6", mtu_ignore=True),
+ ],
+ ),
+ ],
+ state="merged",
+ ),
+ )
+ commands = [
+ "set protocols ospf interface eth0.3 cost 100",
+ "set protocols ospf interface eth0.3 priority 55",
+ "set protocols ospf interface eth0.3 authentication plaintext-password abcdefg!",
+ "set protocols ospfv3 interface eth0.3 mtu-ignore",
+ ]
+ self.execute_module(changed=True, commands=commands)
+
def test_vyos_ospf_interfaces_merged_idempotent(self):
set_module_args(
dict(
@@ -137,7 +166,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
],
),
],
- )
+ ),
)
self.execute_module(changed=False, commands=[])
@@ -162,7 +191,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
],
),
],
- )
+ ),
)
commands = [
"set protocols ospfv3 interface eth0 cost 500",
@@ -198,7 +227,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="replaced",
- )
+ ),
)
commands = [
"set protocols ospf interface bond2 transmit-delay 9",
@@ -249,7 +278,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="replaced",
- )
+ ),
)
commands = [
"delete protocols ospf interface eth1 cost 100",
@@ -287,7 +316,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="replaced",
- )
+ ),
)
self.execute_module(changed=False, commands=[])
@@ -318,7 +347,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="overridden",
- )
+ ),
)
commands = [
"set protocols ospf interface bond2 transmit-delay 9",
@@ -355,7 +384,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="overridden",
- )
+ ),
)
self.execute_module(changed=False, commands=[])
@@ -368,7 +397,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="deleted",
- )
+ ),
)
commands = ["delete protocols ospfv3 interface eth0"]
self.execute_module(changed=True, commands=commands)
@@ -382,7 +411,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="deleted",
- )
+ ),
)
self.execute_module(changed=False, commands=[])
@@ -414,7 +443,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
),
],
state="rendered",
- )
+ ),
)
commands = [
"set protocols ospf interface eth0 cost 100",
@@ -456,7 +485,7 @@ class TestVyosOspfInterfacesModule14(TestVyosModule):
"md5_key": {
"key": "1111111111232345",
"key_id": 10,
- }
+ },
},
"bandwidth": 70,
"transmit_delay": 45,