diff --git a/changelogs/fragments/T9419_ospf_interfaces_passive_area.yml b/changelogs/fragments/T9419_ospf_interfaces_passive_area.yml new file mode 100644 index 00000000..ecf1c79f --- /dev/null +++ b/changelogs/fragments/T9419_ospf_interfaces_passive_area.yml @@ -0,0 +1,9 @@ +--- +bugfixes: + - vyos_ospf_interfaces - passive false for ipv4 renders "passive disable", which exempts the + interface from passive-interface default, and "passive disable" on the device is read back as + passive false; before, passive false rendered nothing and the exemption was not recognised + (T9419). For ipv6, OSPFv3 has no such exemption, so passive false means not passive. +minor_changes: + - vyos_ospf_interfaces - new option address_family.area, the OSPF area of an interface (VyOS 1.4 + and later). diff --git a/docs/vyos.vyos.vyos_ospf_interfaces_module.rst b/docs/vyos.vyos.vyos_ospf_interfaces_module.rst index 9cf292a9..a1c7be18 100644 --- a/docs/vyos.vyos.vyos_ospf_interfaces_module.rst +++ b/docs/vyos.vyos.vyos_ospf_interfaces_module.rst @@ -1,1320 +1,1339 @@ .. _vyos.vyos.vyos_ospf_interfaces_module: ****************************** vyos.vyos.vyos_ospf_interfaces ****************************** **OSPF Interfaces Resource Module.** Version added: 1.2.0 .. contents:: :local: :depth: 1 Synopsis -------- - This module manages OSPF configuration of interfaces on devices running VYOS. - The provided examples of commands are valid for VyOS 1.4+ Parameters ---------- .. raw:: html + + + + + + +
Parameter Choices/Defaults Comments
config
list / elements=dictionary
A list of OSPF configuration for interfaces.
address_family
list / elements=dictionary
OSPF settings on the interfaces in address-family context.
afi
string / required
    Choices:
  • ipv4
  • ipv6
Address Family Identifier (AFI) for OSPF settings on the interfaces.
+
+ area + +
+ string +
+
+ +
OSPF area of the interface, as a number or in dotted-decimal notation.
+
Supported on VyOS 1.4 and later.
+
authentication
dictionary
Authentication settings on the interface.
md5_key
dictionary
md5 parameters.
key
string
md5 key.
key_id
integer
key id.
plaintext_password
string
Plain Text password.
bandwidth
integer
Bandwidth of interface (kilobits/sec)
cost
integer
metric associated with interface.
dead_interval
integer
Time interval to detect a dead router.
hello_interval
integer
Timer interval between transmission of hello packets.
ifmtu
integer
interface MTU.
instance
string
Instance ID.
mtu_ignore
boolean
    Choices:
  • no
  • yes
if True, Disable MTU check for Database Description packets.
network
string
Interface type.
passive
boolean
    Choices:
  • no
  • yes
If True, disables forming adjacency.
+
For ipv4, false exempts the interface from passive-interface default (passive disable). OSPFv3 has no such exemption, so for ipv6, false means the interface is not passive.
priority
integer
Interface priority.
retransmit_interval
integer
LSA retransmission interval.
transmit_delay
integer
LSA transmission delay.
name
string
Name/Identifier of the interface.
running_config
string
This option is used only with state parsed.
The value of this option should be the output received from the VYOS device by executing the command show configuration commands | match "set interfaces".
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
state
string
    Choices:
  • merged ←
  • replaced
  • overridden
  • deleted
  • gathered
  • parsed
  • rendered
The state the configuration should be left in.

Examples -------- .. code-block:: yaml # Using merged # # Before state: # ------------- # # @vyos:~$ show configuration commands | match "ospf" - name: Merge provided configuration with device configuration vyos.vyos.vyos_ospf_interfaces: config: - name: "eth1" address_family: - afi: "ipv4" transmit_delay: 50 priority: 26 network: "point-to-point" - afi: "ipv6" dead_interval: 39 - name: "bond2" address_family: - afi: "ipv4" transmit_delay: 45 bandwidth: 70 authentication: md5_key: key_id: 10 key: "1111111111232345" - afi: "ipv6" passive: true state: merged # After State: # -------------- # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # "after": [ # " # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "before": [ # { # "name": "eth0" # }, # { # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "changed": true, # "commands": [ # "set protocols ospf interface eth1 transmit-delay 50", # "set protocols ospf interface eth1 priority 26", # "set protocols ospf interface eth1 network point-to-point", # "set protocols ospfv3 interface eth1 dead-interval 39", # "set protocols ospf interface bond2 transmit-delay 45", # "set protocols ospf interface bond2 bandwidth 70", # "set protocols ospf interface bond2 authentication md5 key-id 10 md5-key 1111111111232345", # "set protocols ospfv3 interface bond2 passive" # ], # Using replaced: # Before State: # ------------ # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' - name: Replace provided configuration with device configuration vyos.vyos.vyos_ospf_interfaces: config: - name: "eth1" address_family: - afi: "ipv4" cost: 100 - afi: "ipv6" ifmtu: 33 - name: "bond2" address_family: - afi: "ipv4" transmit_delay: 45 - afi: "ipv6" passive: true state: replaced # After State: # ----------- # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 cost '100' # set protocols ospfv3 interface eth1 ifmtu '33' # vyos@vyos:~$ # Module Execution # ---------------- # "after": [ # { # "address_family": [ # { # "afi": "ipv4", # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 100 # }, # { # "afi": "ipv6", # "ifmtu": 33 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "before": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "changed": true, # "commands": [ # "set protocols ospf interface eth1 cost 100", # "set protocols ospfv3 interface eth1 ifmtu 33", # "delete protocols ospf interface eth1 network point-to-point", # "delete protocols ospf interface eth1 priority 26", # "delete protocols ospf interface eth1 transmit-delay 50", # "delete protocols ospfv3 interface eth1 dead-interval 39", # "delete protocols ospf interface bond2 authentication", # "delete protocols ospf interface bond2 bandwidth 70" # ], # # Using Overridden: # ----------------- # Before State: # ------------ # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 cost '100' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # set protocols ospfv3 interface eth1 ifmtu '33' # vyos@vyos:~$ - name: Override device configuration with provided configuration vyos.vyos.vyos_ospf_interfaces: config: - name: "eth0" address_family: - afi: "ipv4" cost: 100 - afi: "ipv6" ifmtu: 33 passive: true state: overridden # After State: # ----------- # 200~vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface eth0 cost '100' # set protocols ospfv3 interface eth0 ifmtu '33' # set protocols ospfv3 interface eth0 'passive' # vyos@vyos:~$ # # # "after": [ # { # "name": "bond2" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 100 # }, # { # "afi": "ipv6", # "ifmtu": 33, # "passive": true # } # ], # "name": "eth0" # }, # { # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "before": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 100, # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39, # "ifmtu": 33 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "changed": true, # "commands": [ # "delete protocols ospf interface bond2", # "delete protocols ospfv3 interface bond2", # "delete protocols ospf interface eth1", # "delete protocols ospfv3 interface eth1", # "set protocols ospf interface eth0 cost 100", # "set protocols ospfv3 interface eth0 ifmtu 33", # "set protocols ospfv3 interface eth0 passive" # ], # # Using deleted: # ------------- # before state: # ------------- # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth0 cost '100' # set protocols ospfv3 interface eth0 ifmtu '33' # set protocols ospfv3 interface eth0 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # vyos@vyos:~$ - name: Delete device configuration vyos.vyos.vyos_ospf_interfaces: config: - name: "eth0" state: deleted # After State: # ----------- # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # vyos@vyos:~$ # # # "after": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "before": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 100 # }, # { # "afi": "ipv6", # "ifmtu": 33, # "passive": true # } # ], # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "changed": true, # "commands": [ # "delete protocols ospf interface eth0", # "delete protocols ospfv3 interface eth0" # ], # # Using parsed: # parsed.cfg: # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth0 cost '50' # set protocols ospf interface eth0 priority '26' # set protocols ospfv3 interface eth0 instance-id '33' # set protocols ospfv3 interface eth0 'mtu-ignore' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # - name: parse configs vyos.vyos.vyos_ospf_interfaces: running_config: "{{ lookup('file', './parsed.cfg') }}" state: parsed # Module Execution: # ---------------- # "parsed": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 50, # "priority": 26 # }, # { # "afi": "ipv6", # "instance": "33", # "mtu_ignore": true # } # ], # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # } # ] # Using rendered: # -------------- - name: Render vyos.vyos.vyos_ospf_interfaces: config: - name: "eth1" address_family: - afi: "ipv4" transmit_delay: 50 priority: 26 network: "point-to-point" - afi: "ipv6" dead_interval: 39 - name: "bond2" address_family: - afi: "ipv4" transmit_delay: 45 bandwidth: 70 authentication: md5_key: key_id: 10 key: "1111111111232345" - afi: "ipv6" passive: true state: rendered # Module Execution: # ---------------- # "rendered": [ # "set protocols ospf interface eth1 transmit-delay 50", # "set protocols ospf interface eth1 priority 26", # "set protocols ospf interface eth1 network point-to-point", # "set protocols ospfv3 interface eth1 dead-interval 39", # "set protocols ospf interface bond2 transmit-delay 45", # "set protocols ospf interface bond2 bandwidth 70", # "set protocols ospf interface bond2 authentication md5 key-id 10 md5-key 1111111111232345", # "set protocols ospfv3 interface bond2 passive" # ] # # Using Gathered: # -------------- # Native Config: # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # vyos@vyos:~$ - name: gather configs vyos.vyos.vyos_ospf_interfaces: state: gathered # Module Execution: # ----------------- # "gathered": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], Return Values ------------- Common return values are documented `here `_, the following are the fields unique to this module: .. raw:: html
Key Returned Description
after
dictionary
when changed
The resulting configuration after module execution.

Sample:
This output will always be in the same format as the module argspec.
before
dictionary
when state is merged, replaced, overridden, deleted or purged
The configuration prior to the module execution.

Sample:
This output will always be in the same format as the module argspec.
commands
list
when state is merged, replaced, overridden, deleted or purged
The set of commands pushed to the remote device.

Sample:
["set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345'", "set protocols ospf interface bond2 bandwidth '70'", "set protocols ospf interface bond2 transmit-delay '45'"]
gathered
list
when state is gathered
Facts about the network resource gathered from the remote device as structured data.

Sample:
This output will always be in the same format as the module argspec.
parsed
list
when state is parsed
The device native config provided in running_config option parsed into structured data as per module argspec.

Sample:
This output will always be in the same format as the module argspec.
rendered
list
when state is rendered
The provided configuration in the task rendered in device-native format (offline).

Sample:
["set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345'", "set protocols ospf interface bond2 bandwidth '70'", "set protocols ospf interface bond2 transmit-delay '45'"]


Status ------ Authors ~~~~~~~ - Gomathi Selvi Srinivasan (@GomathiselviS) diff --git a/plugins/module_utils/network/vyos/argspec/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/vyos/argspec/ospf_interfaces/ospf_interfaces.py index ced9f98e..31a90009 100644 --- a/plugins/module_utils/network/vyos/argspec/ospf_interfaces/ospf_interfaces.py +++ b/plugins/module_utils/network/vyos/argspec/ospf_interfaces/ospf_interfaces.py @@ -1,95 +1,97 @@ # -*- coding: utf-8 -*- # Copyright 2024 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# # WARNING # ############################################# # # This file is auto generated by the # cli_rm_builder. # # Manually editing this file is not advised. # # To update the argspec make the desired changes # in the module docstring and re-run # cli_rm_builder. # ############################################# """ The arg spec for the vyos_ospf_interfaces module """ class Ospf_interfacesArgs(object): # pylint: disable=R0903 """The arg spec for the vyos_ospf_interfaces module""" argument_spec = { "config": { "type": "list", "elements": "dict", "options": { "name": {"type": "str"}, "address_family": { "type": "list", "elements": "dict", "options": { "afi": { "type": "str", "choices": ["ipv4", "ipv6"], "required": True, }, "authentication": { "type": "dict", "options": { "plaintext_password": { "type": "str", "no_log": True, }, "md5_key": { "type": "dict", "no_log": False, "options": { "key_id": {"type": "int"}, "key": {"type": "str", "no_log": True}, }, }, }, }, "bandwidth": {"type": "int"}, "cost": {"type": "int"}, "dead_interval": {"type": "int"}, "hello_interval": {"type": "int"}, "mtu_ignore": {"type": "bool"}, "network": {"type": "str"}, "priority": {"type": "int"}, "retransmit_interval": {"type": "int"}, "transmit_delay": {"type": "int"}, "ifmtu": {"type": "int"}, "instance": {"type": "str"}, "passive": {"type": "bool"}, + "area": {"type": "str"}, }, }, }, }, "running_config": {"type": "str"}, "state": { "type": "str", "choices": [ "merged", "replaced", "overridden", "deleted", "gathered", "parsed", "rendered", ], "default": "merged", }, } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py b/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py index bc93ac24..1936af1e 100644 --- a/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py +++ b/plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py @@ -1,193 +1,225 @@ # # -*- coding: utf-8 -*- # Copyright 2020 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # from __future__ import absolute_import, division, print_function + __metaclass__ = type """ The vyos_ospf_interfaces config file. It is in this file where the current configuration (as dict) is compared to the provided configuration (as dict) and the command set necessary to bring the current configuration to its desired end-state is created. """ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_merge, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ospf_interfaces import ( Ospf_interfacesTemplate, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.ospf_interfaces_14 import ( 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 class Ospf_interfaces(ResourceModule): """ The vyos_ospf_interfaces config class """ def __init__(self, module): super(Ospf_interfaces, self).__init__( empty_fact_val={}, facts_module=Facts(module), module=module, resource="ospf_interfaces", tmplt=Ospf_interfacesTemplate(), ) self.parsers = [ "authentication_password", "authentication_md5", "bandwidth", "cost", "hello_interval", "dead_interval", "mtu_ignore", "network", "priority", "retransmit_interval", "transmit_delay", "ifmtu", "instance", - "passive", ] def _validate_template(self): version = get_os_version(self._module) if LooseVersion(version) >= LooseVersion("1.4"): self._tmplt = Ospf_interfacesTemplate14() + # the interface area only exists on VyOS 1.4 and later + if "area" not in self.parsers: + self.parsers.append("area") else: self._tmplt = Ospf_interfacesTemplate() def parse(self): """override parse to check template""" self._validate_template() return super().parse() def get_parser(self, name): """get_parsers""" self._validate_template() return super().get_parser(name) def execute_module(self): """Execute the module :rtype: A dictionary :returns: The result from module execution """ self._validate_template() if self.state not in ["parsed", "gathered"]: self.generate_commands() self.run_commands() return self.result def generate_commands(self): """Generate configuration commands to send based on want, have and desired state. """ wantd = {} haved = {} for entry in self.want: wantd.update({entry["name"]: entry}) for entry in self.have: haved.update({entry["name"]: entry}) # turn all lists of dicts into dicts prior to merge for entry in wantd, haved: self._ospf_int_list_to_dict(entry) # if state is merged, merge want onto have and then compare if self.state == "merged": wantd = dict_merge(haved, wantd) # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": h_del = {} for k, v in haved.items(): if k in wantd or not wantd: h_del.update({k: v}) haved = h_del have_int = [] for k, have in haved.items(): if k in wantd: have_int.append(k) self._remove_ospf_int(have) wantd = {} if self.state == "overridden": have_int = [] for k, have in haved.items(): if k not in wantd: have_int.append(k) self._remove_ospf_int(have) # remove superfluous config for overridden and deleted if self.state in ["overridden", "deleted"]: # removing the interfaces from haved that are already negated for interface in have_int: haved.pop(interface) for k, have in haved.items(): if k not in wantd: self._compare(want={}, have=have) for k, want in wantd.items(): self._compare(want=want, have=haved.pop(k, {})) def _remove_ospf_int(self, entry): int_name = entry.get("name", {}) int_addr = entry.get("address_family", {}) for k, addr in int_addr.items(): rem_entry = {"name": int_name, "address_family": {"afi": k}} self.addcmd(rem_entry, "ip_ospf", True) def _compare(self, want, have): """Leverages the base class `compare()` method and populates the list of commands to be run by comparing the `want` and `have` data with the `parsers` defined for the Ospf_interfaces network resource. """ self._compare_addr_family(want=want, have=have) def _compare_addr_family(self, want, have): wdict = want.get("address_family", {}) hdict = have.get("address_family", {}) wname = want.get("name") hname = have.get("name") + for name in set(wdict) | set(hdict): + self._compare_passive( + wname or hname, + name, + wdict.get(name, {}).pop("passive", None), + hdict.get(name, {}).pop("passive", None), + ) for name, entry in wdict.items(): for key, param in entry.items(): w_addr = {"afi": name, key: param} h_addr = {} if hdict.get(name): h_addr = {"afi": name, key: hdict[name].pop(key, {})} w = {"name": wname, "address_family": w_addr} h = {"name": hname, "address_family": h_addr} self.compare(parsers=self.parsers, want=w, have=h) for name, entry in hdict.items(): for key, param in entry.items(): h_addr = {"afi": name, key: param} w_addr = {} w = {"name": wname, "address_family": w_addr} h = {"name": hname, "address_family": h_addr} self.compare(parsers=self.parsers, want=w, have=h) def _ospf_int_list_to_dict(self, entry): for name, family in entry.items(): if "address_family" in family: addr_dict = {} for entry in family.get("address_family", []): addr_dict.update({entry["afi"]: entry}) family["address_family"] = addr_dict self._ospf_int_list_to_dict(family["address_family"]) + + def _compare_passive(self, name, afi, want, have): + """passive has three states in OSPFv2: absent, passive, and passive disable + (exempt from passive-interface default, passive: false); OSPFv3 has only the flag, + where passive: false means not passive.""" + # OSPFv3, and the pre-1.4 template, have no "passive disable": false means not passive + if afi == "ipv6" or not isinstance(self._tmplt, Ospf_interfacesTemplate14): + want, have = want or None, have or None + if want == have: + return + + def entry(value): + return {"name": name, "address_family": {"afi": afi, "passive": value}} + + if have is not None: + if have is False and want is True: + # only the exemption goes; the passive node stays + self.addcmd(entry(False), "passive", True) + elif want is None: + self.addcmd(entry(True), "passive", True) + if want is not None: + self.addcmd(entry(want), "passive", False) diff --git a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces_14.py b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces_14.py index 8d09011f..d18eeab3 100644 --- a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces_14.py +++ b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces_14.py @@ -1,632 +1,677 @@ # -*- coding: utf-8 -*- # Copyright 2020 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The Ospf_interfaces parser templates file. This contains a list of parser definitions and associated functions that facilitates both facts gathering and native command generation for the given network resource. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) def _get_parameters(data): if data["afi"] == "ipv6": val = ["ospfv3", "ipv6"] else: val = ["ospf", "ip"] return val def _tmplt_ospf_int_delete(config_data): params = _get_parameters(config_data["address_family"]) command = "protocols " + params[0] + " interface {name}".format(**config_data) return command def _tmplt_ospf_int_cost(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " cost {cost}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_auth_password(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " authentication plaintext-password {plaintext_password}".format( - **config_data["address_family"]["authentication"] + **config_data["address_family"]["authentication"], ) ) return command def _tmplt_ospf_int_auth_md5(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " authentication md5 key-id {key_id} ".format( - **config_data["address_family"]["authentication"]["md5_key"] + **config_data["address_family"]["authentication"]["md5_key"], ) + "md5-key {key}".format(**config_data["address_family"]["authentication"]["md5_key"]) ) return command def _tmplt_ospf_int_auth_md5_delete(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " authentication" ) return command def _tmplt_ospf_int_bw(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " bandwidth {bandwidth}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_hello_interval(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " hello-interval {hello_interval}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_dead_interval(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " dead-interval {dead_interval}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_mtu_ignore(config_data): params = _get_parameters(config_data["address_family"]) command = "protocols " + params[0] + " interface {name}".format(**config_data) + " mtu-ignore" return command def _tmplt_ospf_int_network(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " network {network}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_priority(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " priority {priority}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_retransmit_interval(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " retransmit-interval {retransmit_interval}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_transmit_delay(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " transmit-delay {transmit_delay}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_ifmtu(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " ifmtu {ifmtu}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_instance(config_data): params = _get_parameters(config_data["address_family"]) command = ( "protocols " + params[0] + " interface {name}".format(**config_data) + " instance-id {instance}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_passive(config_data): params = _get_parameters(config_data["address_family"]) command = "protocols " + params[0] + " interface {name}".format(**config_data) + " passive" + # OSPFv2 exempts an interface from passive-interface default with "passive disable" + if config_data["address_family"].get("passive") is False: + command += " disable" + + return command + + +def _tmplt_ospf_int_area(config_data): + params = _get_parameters(config_data["address_family"]) + command = ( + "protocols " + + params[0] + + " interface {name}".format(**config_data) + + " area {area}".format(**config_data["address_family"]) + ) return command class Ospf_interfacesTemplate14(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} super(Ospf_interfacesTemplate14, self).__init__( - lines=lines, tmplt=self, prefix=prefix, module=module + lines=lines, + tmplt=self, + prefix=prefix, + module=module, ) # fmt: off PARSERS = [ { "name": "ip_ospf", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+)\s*$""", re.VERBOSE, ), "remval": _tmplt_ospf_int_delete, "compval": "address_family", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - } - } - } + }, + }, + }, }, { "name": "authentication_password", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+authentication \s+plaintext-password \s+(?P\S+)\s*$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_auth_password, "compval": "address_family.authentication", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', "authentication": { - "plaintext_password": "{{ text }}" - } - } - } - } + "plaintext_password": "{{ text }}", + }, + }, + }, + }, }, { "name": "authentication_md5", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+authentication \s+md5 \s+key-id \s+(?P\d+) \s+md5-key \s+(?P\S+)\s*$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_auth_md5, "remval": _tmplt_ospf_int_auth_md5_delete, "compval": "address_family.authentication", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', "authentication": { "md5_key": { "key_id": "{{ id }}", - "key": "{{ text }}" - } - } - } - } - } + "key": "{{ text }}", + }, + }, + }, + }, + }, }, { "name": "bandwidth", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+bandwidth \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_bw, "compval": "address_family.bandwidth", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "bandwidth": "{{ bw }}" - } - } - } + "bandwidth": "{{ bw }}", + }, + }, + }, }, { "name": "cost", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+cost \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_cost, "compval": "address_family.cost", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "cost": "{{ val }}" - } - } - } + "cost": "{{ val }}", + }, + }, + }, }, { "name": "hello_interval", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+hello-interval \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_hello_interval, "compval": "address_family.hello_interval", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "hello_interval": "{{ val }}" - } - } - } + "hello_interval": "{{ val }}", + }, + }, + }, }, { "name": "dead_interval", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+dead-interval \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_dead_interval, "compval": "address_family.dead_interval", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "dead_interval": "{{ val }}" - } - } - } + "dead_interval": "{{ val }}", + }, + }, + }, }, { "name": "mtu_ignore", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+(?Pmtu-ignore) *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_mtu_ignore, "compval": "address_family.mtu_ignore", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "mtu_ignore": "{{ True if mtu is defined }}" - } - } - } + "mtu_ignore": "{{ True if mtu is defined }}", + }, + }, + }, }, { "name": "network", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+network \s+(?P\S+)\s*$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_network, "compval": "address_family.network", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "network": "{{ val }}" - } - } - } + "network": "{{ val }}", + }, + }, + }, }, { "name": "priority", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+priority \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_priority, "compval": "address_family.priority", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "priority": "{{ val }}" - } - } - } + "priority": "{{ val }}", + }, + }, + }, }, { "name": "retransmit_interval", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+retransmit-interval \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_retransmit_interval, "compval": "address_family.retransmit_interval", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "retransmit_interval": "{{ val }}" - } - } - } + "retransmit_interval": "{{ val }}", + }, + }, + }, }, { "name": "transmit_delay", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+transmit-delay \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_transmit_delay, "compval": "address_family.transmit_delay", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "transmit_delay": "{{ val }}" - } - } - } + "transmit_delay": "{{ val }}", + }, + }, + }, }, { "name": "ifmtu", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+ifmtu \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_ifmtu, "compval": "address_family.ifmtu", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "ifmtu": "{{ val }}" - } - } - } + "ifmtu": "{{ val }}", + }, + }, + }, }, { "name": "instance", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+instance-id \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_instance, "compval": "address_family.instance", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "instance": "{{ val }}" - } - } - } + "instance": "{{ val }}", + }, + }, + }, }, { "name": "passive", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+(?Ppassive) - *$""", + (?:\s+(?Pdisable))? + \s*$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_passive, "compval": "address_family.passive", "result": { "name": "{{ name }}", "address_family": { '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', - "passive": "{{ True if pass is defined }}" - } - } - } + "passive": "{{ False if dis is defined else True }}", + }, + }, + }, + }, + { + "name": "area", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+(?Pospf|ospfv3) + \s+interface + \s+(?P\S+) + \s+area + \s+'?(?P[^'\s]+)'? + \s*$""", + re.VERBOSE, + ), + "setval": _tmplt_ospf_int_area, + "compval": "address_family.area", + "result": { + "name": "{{ name }}", + "address_family": { + '{{ "ipv4" if proto == "ospf" else "ipv6" }}': { + "afi": '{{ "ipv4" if proto == "ospf" else "ipv6" }}', + "area": "{{ area }}", + }, + }, + }, }, { "name": "interface_name", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) .*$""", re.VERBOSE, ), "setval": "set protocols {{ proto }} interface {{ name }}", "result": { "name": "{{ name }}", - } + }, }, ] # fmt: on diff --git a/plugins/modules/vyos_ospf_interfaces.py b/plugins/modules/vyos_ospf_interfaces.py index d49e9d35..4e0f1250 100644 --- a/plugins/modules/vyos_ospf_interfaces.py +++ b/plugins/modules/vyos_ospf_interfaces.py @@ -1,948 +1,957 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 2024 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ The module file for vyos_ospf_interfaces """ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ module: vyos_ospf_interfaces version_added: 1.2.0 short_description: OSPF Interfaces Resource Module. description: - This module manages OSPF configuration of interfaces on devices running VYOS. - The provided examples of commands are valid for VyOS 1.4+ author: Gomathi Selvi Srinivasan (@GomathiselviS) options: config: description: A list of OSPF configuration for interfaces. type: list elements: dict suboptions: name: description: - Name/Identifier of the interface. type: str address_family: description: - OSPF settings on the interfaces in address-family context. type: list elements: dict suboptions: afi: description: - Address Family Identifier (AFI) for OSPF settings on the interfaces. type: str choices: ['ipv4', 'ipv6'] required: true authentication: description: - Authentication settings on the interface. type: dict suboptions: plaintext_password: description: - Plain Text password. type: str md5_key: description: - md5 parameters. type: dict suboptions: key_id: description: - key id. type: int key: description: - md5 key. type: str bandwidth: description: - Bandwidth of interface (kilobits/sec) type: int cost: description: - metric associated with interface. type: int dead_interval: description: - Time interval to detect a dead router. type: int hello_interval: description: - Timer interval between transmission of hello packets. type: int mtu_ignore: description: - if True, Disable MTU check for Database Description packets. type: bool network: description: - Interface type. type: str priority: description: - Interface priority. type: int retransmit_interval: description: - LSA retransmission interval. type: int transmit_delay: description: - LSA transmission delay. type: int ifmtu: description: - interface MTU. type: int instance: description: - Instance ID. type: str passive: description: - If True, disables forming adjacency. + - For C(ipv4), C(false) exempts the interface from C(passive-interface default) + (C(passive disable)). OSPFv3 has no such exemption, so for C(ipv6), C(false) + means the interface is not passive. type: bool + area: + description: + - OSPF area of the interface, as a number or in dotted-decimal notation. + - Supported on VyOS 1.4 and later. + type: str running_config: description: - This option is used only with state I(parsed). - The value of this option should be the output received from the VYOS device by executing the command B(show configuration commands | match "set interfaces"). - The state I(parsed) reads the configuration from C(running_config) option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the I(parsed) key within the result. type: str state: description: - The state the configuration should be left in. type: str choices: - merged - replaced - overridden - deleted - gathered - parsed - rendered default: merged """ EXAMPLES = """ # Using merged # # Before state: # ------------- # # @vyos:~$ show configuration commands | match "ospf" - name: Merge provided configuration with device configuration vyos.vyos.vyos_ospf_interfaces: config: - name: "eth1" address_family: - afi: "ipv4" transmit_delay: 50 priority: 26 network: "point-to-point" - afi: "ipv6" dead_interval: 39 - name: "bond2" address_family: - afi: "ipv4" transmit_delay: 45 bandwidth: 70 authentication: md5_key: key_id: 10 key: "1111111111232345" - afi: "ipv6" passive: true state: merged # After State: # -------------- # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # "after": [ # " # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "before": [ # { # "name": "eth0" # }, # { # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "changed": true, # "commands": [ # "set protocols ospf interface eth1 transmit-delay 50", # "set protocols ospf interface eth1 priority 26", # "set protocols ospf interface eth1 network point-to-point", # "set protocols ospfv3 interface eth1 dead-interval 39", # "set protocols ospf interface bond2 transmit-delay 45", # "set protocols ospf interface bond2 bandwidth 70", # "set protocols ospf interface bond2 authentication md5 key-id 10 md5-key 1111111111232345", # "set protocols ospfv3 interface bond2 passive" # ], # Using replaced: # Before State: # ------------ # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' - name: Replace provided configuration with device configuration vyos.vyos.vyos_ospf_interfaces: config: - name: "eth1" address_family: - afi: "ipv4" cost: 100 - afi: "ipv6" ifmtu: 33 - name: "bond2" address_family: - afi: "ipv4" transmit_delay: 45 - afi: "ipv6" passive: true state: replaced # After State: # ----------- # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 cost '100' # set protocols ospfv3 interface eth1 ifmtu '33' # vyos@vyos:~$ # Module Execution # ---------------- # "after": [ # { # "address_family": [ # { # "afi": "ipv4", # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 100 # }, # { # "afi": "ipv6", # "ifmtu": 33 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "before": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "changed": true, # "commands": [ # "set protocols ospf interface eth1 cost 100", # "set protocols ospfv3 interface eth1 ifmtu 33", # "delete protocols ospf interface eth1 network point-to-point", # "delete protocols ospf interface eth1 priority 26", # "delete protocols ospf interface eth1 transmit-delay 50", # "delete protocols ospfv3 interface eth1 dead-interval 39", # "delete protocols ospf interface bond2 authentication", # "delete protocols ospf interface bond2 bandwidth 70" # ], # # Using Overridden: # ----------------- # Before State: # ------------ # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 cost '100' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # set protocols ospfv3 interface eth1 ifmtu '33' # vyos@vyos:~$ - name: Override device configuration with provided configuration vyos.vyos.vyos_ospf_interfaces: config: - name: "eth0" address_family: - afi: "ipv4" cost: 100 - afi: "ipv6" ifmtu: 33 passive: true state: overridden # After State: # ----------- # 200~vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface eth0 cost '100' # set protocols ospfv3 interface eth0 ifmtu '33' # set protocols ospfv3 interface eth0 'passive' # vyos@vyos:~$ # # # "after": [ # { # "name": "bond2" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 100 # }, # { # "afi": "ipv6", # "ifmtu": 33, # "passive": true # } # ], # "name": "eth0" # }, # { # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "before": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 100, # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39, # "ifmtu": 33 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "changed": true, # "commands": [ # "delete protocols ospf interface bond2", # "delete protocols ospfv3 interface bond2", # "delete protocols ospf interface eth1", # "delete protocols ospfv3 interface eth1", # "set protocols ospf interface eth0 cost 100", # "set protocols ospfv3 interface eth0 ifmtu 33", # "set protocols ospfv3 interface eth0 passive" # ], # # Using deleted: # ------------- # before state: # ------------- # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth0 cost '100' # set protocols ospfv3 interface eth0 ifmtu '33' # set protocols ospfv3 interface eth0 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # vyos@vyos:~$ - name: Delete device configuration vyos.vyos.vyos_ospf_interfaces: config: - name: "eth0" state: deleted # After State: # ----------- # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # vyos@vyos:~$ # # # "after": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "before": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 100 # }, # { # "afi": "ipv6", # "ifmtu": 33, # "passive": true # } # ], # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], # "changed": true, # "commands": [ # "delete protocols ospf interface eth0", # "delete protocols ospfv3 interface eth0" # ], # # Using parsed: # parsed.cfg: # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth0 cost '50' # set protocols ospf interface eth0 priority '26' # set protocols ospfv3 interface eth0 instance-id '33' # set protocols ospfv3 interface eth0 'mtu-ignore' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # - name: parse configs vyos.vyos.vyos_ospf_interfaces: running_config: "{{ lookup('file', './parsed.cfg') }}" state: parsed # Module Execution: # ---------------- # "parsed": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "address_family": [ # { # "afi": "ipv4", # "cost": 50, # "priority": 26 # }, # { # "afi": "ipv6", # "instance": "33", # "mtu_ignore": true # } # ], # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # } # ] # Using rendered: # -------------- - name: Render vyos.vyos.vyos_ospf_interfaces: config: - name: "eth1" address_family: - afi: "ipv4" transmit_delay: 50 priority: 26 network: "point-to-point" - afi: "ipv6" dead_interval: 39 - name: "bond2" address_family: - afi: "ipv4" transmit_delay: 45 bandwidth: 70 authentication: md5_key: key_id: 10 key: "1111111111232345" - afi: "ipv6" passive: true state: rendered # Module Execution: # ---------------- # "rendered": [ # "set protocols ospf interface eth1 transmit-delay 50", # "set protocols ospf interface eth1 priority 26", # "set protocols ospf interface eth1 network point-to-point", # "set protocols ospfv3 interface eth1 dead-interval 39", # "set protocols ospf interface bond2 transmit-delay 45", # "set protocols ospf interface bond2 bandwidth 70", # "set protocols ospf interface bond2 authentication md5 key-id 10 md5-key 1111111111232345", # "set protocols ospfv3 interface bond2 passive" # ] # # Using Gathered: # -------------- # Native Config: # vyos@vyos:~$ show configuration commands | match "ospf" # set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345' # set protocols ospf interface bond2 bandwidth '70' # set protocols ospf interface bond2 transmit-delay '45' # set protocols ospfv3 interface bond2 'passive' # set protocols ospf interface eth1 network 'point-to-point' # set protocols ospf interface eth1 priority '26' # set protocols ospf interface eth1 transmit-delay '50' # set protocols ospfv3 interface eth1 dead-interval '39' # vyos@vyos:~$ - name: gather configs vyos.vyos.vyos_ospf_interfaces: state: gathered # Module Execution: # ----------------- # "gathered": [ # { # "address_family": [ # { # "afi": "ipv4", # "authentication": { # "md5_key": { # "key": "1111111111232345", # "key_id": 10 # } # }, # "bandwidth": 70, # "transmit_delay": 45 # }, # { # "afi": "ipv6", # "passive": true # } # ], # "name": "bond2" # }, # { # "name": "eth0" # }, # { # "address_family": [ # { # "afi": "ipv4", # "network": "point-to-point", # "priority": 26, # "transmit_delay": 50 # }, # { # "afi": "ipv6", # "dead_interval": 39 # } # ], # "name": "eth1" # }, # { # "name": "eth2" # }, # { # "name": "eth3" # } # ], """ RETURN = """ before: description: The configuration prior to the module execution. returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) type: dict sample: > This output will always be in the same format as the module argspec. after: description: The resulting configuration after module execution. returned: when changed type: dict sample: > This output will always be in the same format as the module argspec. commands: description: The set of commands pushed to the remote device. returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) type: list sample: - "set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345'" - "set protocols ospf interface bond2 bandwidth '70'" - "set protocols ospf interface bond2 transmit-delay '45'" rendered: description: The provided configuration in the task rendered in device-native format (offline). returned: when I(state) is C(rendered) type: list sample: - "set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345'" - "set protocols ospf interface bond2 bandwidth '70'" - "set protocols ospf interface bond2 transmit-delay '45'" gathered: description: Facts about the network resource gathered from the remote device as structured data. returned: when I(state) is C(gathered) type: list sample: > This output will always be in the same format as the module argspec. parsed: description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. returned: when I(state) is C(parsed) type: list sample: > This output will always be in the same format as the module argspec. """ from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.ospf_interfaces.ospf_interfaces import ( Ospf_interfacesArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.ospf_interfaces.ospf_interfaces import ( Ospf_interfaces, ) def main(): """ Main entry point for module execution :returns: the result form module invocation """ module = AnsibleModule( argument_spec=Ospf_interfacesArgs.argument_spec, mutually_exclusive=[["config", "running_config"]], required_if=[ ["state", "merged", ["config"]], ["state", "replaced", ["config"]], ["state", "overridden", ["config"]], ["state", "rendered", ["config"]], ["state", "parsed", ["running_config"]], ], supports_check_mode=True, ) result = Ospf_interfaces(module).execute_module() module.exit_json(**result) if __name__ == "__main__": main() 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 ddff03c9..ec4f6ebf 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml @@ -1,52 +1,110 @@ --- - debug: msg: START vyos_ospf_interfaces merged integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - block: - name: Merge the provided configuration with the existing running configuration register: result vyos.vyos.vyos_ospf_interfaces: &id001 config: - name: eth0 address_family: - afi: ipv4 cost: 50 priority: 26 - afi: ipv6 mtu_ignore: true instance: 33 - name: eth2.3 address_family: - afi: ipv4 cost: 60 priority: 40 - name: bond2 address_family: - afi: ipv4 transmit_delay: 45 - afi: ipv6 passive: true state: merged - vyos.vyos.vyos_facts: gather_network_resources: ospf_interfaces - assert: that: - result.changed == true - result.commands|symmetric_difference(merged.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_ospf_interfaces: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml + +- block: + - name: Merge an interface exempt from passive-interface default, with an area + register: result + vyos.vyos.vyos_ospf_interfaces: &id_b9 + config: + - name: eth1 + address_family: + - afi: ipv4 + passive: false + area: "0" + - afi: ipv6 + area: "0.0.0.0" + state: merged + + - vyos.vyos.vyos_facts: + gather_network_resources: ospf_interfaces + + - assert: + that: + - result.changed == true + - "'set protocols ospf interface eth1 passive disable' in result.commands" + - "'set protocols ospf interface eth1 area 0' in result.commands" + - "'set protocols ospfv3 interface eth1 area 0.0.0.0' in result.commands" + - result.after == ansible_facts['network_resources']['ospf_interfaces'] + + - name: Merge an interface exempt from passive-interface default, with an area (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospf_interfaces: *id_b9 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Make the exempted interface passive again + register: result + vyos.vyos.vyos_ospf_interfaces: + config: + - name: eth1 + address_family: + - afi: ipv4 + passive: true + state: merged + + - assert: + that: + - result.commands == expected + - eth1_ipv4.passive == true + vars: + expected: + - delete protocols ospf interface eth1 passive disable + - set protocols ospf interface eth1 passive + eth1_ipv4: "{{ (result.after | selectattr('name', 'equalto', 'eth1') | first).address_family | selectattr('afi', 'equalto', 'ipv4') | first }}" + + when: vyos_version is version('1.4.0', '>=', version_type='semver') + always: + - include_tasks: _remove_config.yaml diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_passive_disable_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_passive_disable_config.cfg new file mode 100644 index 00000000..869bcc11 --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_passive_disable_config.cfg @@ -0,0 +1,3 @@ +set protocols ospf interface eth1 cost '10' +set protocols ospf interface eth1 passive disable +set protocols ospfv3 interface eth1 cost '10' 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 af1418db..d7628b93 100644 --- a/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces14.py +++ b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces14.py @@ -1,539 +1,622 @@ # Spawned from test_vyos_ospf_interfaces (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 . # 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_ospf_interfaces from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args from .vyos_module import TestVyosModule, load_fixture class TestVyosOspfInterfacesModule14(TestVyosModule): module = vyos_ospf_interfaces 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", ) 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", ) 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", ) 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", ) 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(TestVyosOspfInterfacesModule14, self).tearDown() self.mock_get_resource_connection_config.stop() self.mock_execute_show_command.stop() self.mock_get_os_version.stop() def load_fixtures(self, commands=None, filename=None): if filename is None: filename = "vyos_ospf_interfaces_config_14.cfg" def load_from_file(*args, **kwargs): output = load_fixture(filename) return output self.execute_show_command.side_effect = load_from_file def sort_address_family(self, entry_list): for entry in entry_list: if entry.get("address_family"): entry["address_family"].sort(key=lambda i: i.get("afi")) def test_vyos_ospf_interfaces_merged_new_config(self): set_module_args( dict( config=[ dict( name="eth0", address_family=[ dict( afi="ipv4", cost=100, authentication=dict(plaintext_password="abcdefg!"), priority=55, ), dict(afi="ipv6", mtu_ignore=True, instance=20), ], ), dict( name="bond2", address_family=[ dict( afi="ipv4", transmit_delay=9, ), dict(afi="ipv6", passive=True), ], ), ], state="merged", ), ) commands = [ "set protocols ospf interface bond2 transmit-delay 9", "set protocols ospfv3 interface bond2 passive", "set protocols ospf interface eth0 cost 100", "set protocols ospf interface eth0 priority 55", "set protocols ospf interface eth0 authentication plaintext-password abcdefg!", "set protocols ospfv3 interface eth0 instance-id 20", ] 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( config=[ dict( name="eth0", address_family=[ dict(afi="ipv6", mtu_ignore=True, instance=33), ], ), dict( name="eth1", address_family=[ dict( afi="ipv4", cost=100, ), dict(afi="ipv6", ifmtu=33), ], ), ], ), ) self.execute_module(changed=False, commands=[]) def test_vyos_ospf_interfaces_existing_config_merged(self): set_module_args( dict( config=[ dict( name="eth0", address_family=[ dict(afi="ipv6", cost=500), ], ), dict( name="eth1", address_family=[ dict( afi="ipv4", priority=100, ), dict(afi="ipv6", ifmtu=25), ], ), ], ), ) commands = [ "set protocols ospfv3 interface eth0 cost 500", "set protocols ospf interface eth1 priority 100", "set protocols ospfv3 interface eth1 ifmtu 25", ] self.execute_module(changed=True, commands=commands) def test_vyos_ospf_interfaces_replaced(self): set_module_args( dict( config=[ dict( name="eth0", address_family=[ dict( afi="ipv4", cost=100, authentication=dict(plaintext_password="abcdefg!"), priority=55, ), ], ), dict( name="bond2", address_family=[ dict( afi="ipv4", transmit_delay=9, ), dict(afi="ipv6", passive=True), ], ), ], state="replaced", ), ) commands = [ "set protocols ospf interface bond2 transmit-delay 9", "set protocols ospfv3 interface bond2 passive", "set protocols ospf interface eth0 cost 100", "set protocols ospf interface eth0 priority 55", "set protocols ospf interface eth0 authentication plaintext-password abcdefg!", "delete protocols ospfv3 interface eth0 instance-id 33", "delete protocols ospfv3 interface eth0 mtu-ignore", ] self.execute_module(changed=True, commands=commands) def test_vyos_ospf_passive_interfaces_replaced(self): set_module_args( dict( config=[ dict( name="eth0", address_family=[ dict( afi="ipv4", passive=True, ), ], ), dict( name="eth1", address_family=[ dict( afi="ipv4", passive=True, ), dict( afi="ipv6", passive=True, ), ], ), dict( name="bond2", address_family=[ dict( afi="ipv4", passive=True, ), dict(afi="ipv6", passive=True), ], ), ], state="replaced", ), ) commands = [ "delete protocols ospf interface eth1 cost 100", "delete protocols ospfv3 interface eth0 instance-id 33", "delete protocols ospfv3 interface eth0 mtu-ignore", "delete protocols ospfv3 interface eth1 ifmtu 33", "set protocols ospf interface bond2 passive", "set protocols ospfv3 interface bond2 passive", "set protocols ospf interface eth0 passive", "set protocols ospf interface eth1 passive", "set protocols ospfv3 interface eth1 passive", ] self.maxDiff = None self.execute_module(changed=True, commands=commands) def test_vyos_ospf_interfaces_replaced_idempotent(self): set_module_args( dict( config=[ dict( name="eth0", address_family=[ dict(afi="ipv6", mtu_ignore=True, instance=33), ], ), dict( name="eth1", address_family=[ dict( afi="ipv4", cost=100, ), dict(afi="ipv6", ifmtu=33), ], ), ], state="replaced", ), ) self.execute_module(changed=False, commands=[]) def test_vyos_ospf_interfaces_overridden(self): set_module_args( dict( config=[ dict( name="eth0", address_family=[ dict( afi="ipv4", cost=100, authentication=dict(plaintext_password="abcdefg!"), priority=55, ), ], ), dict( name="bond2", address_family=[ dict( afi="ipv4", transmit_delay=9, ), dict(afi="ipv6", passive=True), ], ), ], state="overridden", ), ) commands = [ "set protocols ospf interface bond2 transmit-delay 9", "set protocols ospfv3 interface bond2 passive", "set protocols ospf interface eth0 cost 100", "set protocols ospf interface eth0 priority 55", "set protocols ospf interface eth0 authentication plaintext-password abcdefg!", "delete protocols ospf interface eth1", "delete protocols ospfv3 interface eth1", "delete protocols ospfv3 interface eth0 mtu-ignore", "delete protocols ospfv3 interface eth0 instance-id 33", ] self.execute_module(changed=True, commands=commands) def test_vyos_ospf_interfaces_overridden_idempotent(self): set_module_args( dict( config=[ dict( name="eth0", address_family=[ dict(afi="ipv6", mtu_ignore=True, instance=33), ], ), dict( name="eth1", address_family=[ dict( afi="ipv4", cost=100, ), dict(afi="ipv6", ifmtu=33), ], ), ], state="overridden", ), ) self.execute_module(changed=False, commands=[]) def test_vyos_ospf_interfaces_deleted(self): set_module_args( dict( config=[ dict( name="eth0", ), ], state="deleted", ), ) commands = ["delete protocols ospfv3 interface eth0"] self.execute_module(changed=True, commands=commands) def test_vyos_ospf_interfaces_notpresent_deleted(self): set_module_args( dict( config=[ dict( name="eth3", ), ], state="deleted", ), ) self.execute_module(changed=False, commands=[]) def test_vyos_ospf_interfaces_rendered(self): set_module_args( dict( config=[ dict( name="eth0", address_family=[ dict( afi="ipv4", cost=100, authentication=dict(plaintext_password="abcdefg!"), priority=55, ), dict(afi="ipv6", mtu_ignore=True, instance=20), ], ), dict( name="bond2", address_family=[ dict( afi="ipv4", transmit_delay=9, ), dict(afi="ipv6", passive=True), ], ), ], state="rendered", ), ) commands = [ "set protocols ospf interface eth0 cost 100", "set protocols ospf interface eth0 authentication plaintext-password abcdefg!", "set protocols ospf interface eth0 priority 55", "set protocols ospfv3 interface eth0 mtu-ignore", "set protocols ospfv3 interface eth0 instance-id 20", "set protocols ospf interface bond2 transmit-delay 9", "set protocols ospfv3 interface bond2 passive", ] result = self.execute_module(changed=False) self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"]) def test_vyos_ospf_interfaces_parsed(self): commands = [ "set protocols ospf interface bond2 authentication md5 key-id 10 md5-key '1111111111232345'", "set protocols ospf interface bond2 bandwidth '70'", "set protocols ospf interface bond2 transmit-delay '45'", "set protocols ospfv3 interface bond2 'passive'", "set protocols ospf interface eth0 cost '50'", "set protocols ospf interface eth0 priority '26'", "set protocols ospfv3 interface eth0 instance-id '33'", "set protocols ospfv3 interface eth0 'mtu-ignore'", "set protocols ospf interface eth1 network 'point-to-point'", "set protocols ospf interface eth1 priority '26'", "set protocols ospf interface eth1 transmit-delay '50'", "set protocols ospfv3 interface eth1 dead-interval '39'", ] parsed_str = "\n".join(commands) set_module_args(dict(running_config=parsed_str, state="parsed")) result = self.execute_module(changed=False) parsed_list = [ { "address_family": [ { "afi": "ipv4", "authentication": { "md5_key": { "key": "1111111111232345", "key_id": 10, }, }, "bandwidth": 70, "transmit_delay": 45, }, {"afi": "ipv6", "passive": True}, ], "name": "bond2", }, { "address_family": [ {"afi": "ipv4", "cost": 50, "priority": 26}, {"afi": "ipv6", "instance": "33", "mtu_ignore": True}, ], "name": "eth0", }, { "address_family": [ { "afi": "ipv4", "network": "point-to-point", "priority": 26, "transmit_delay": 50, }, {"afi": "ipv6", "dead_interval": 39}, ], "name": "eth1", }, ] result_list = self.sort_address_family(result["parsed"]) given_list = self.sort_address_family(parsed_list) self.assertEqual(result_list, given_list) def test_vyos_ospf_interfaces_gathered(self): set_module_args(dict(state="gathered")) result = self.execute_module(changed=False, filename="vyos_ospf_interfaces_config.cfg") gathered_list = [ { "address_family": [{"afi": "ipv6", "instance": "33", "mtu_ignore": True}], "name": "eth0", }, { "address_family": [ {"afi": "ipv4", "cost": 100}, {"afi": "ipv6", "ifmtu": 33}, ], "name": "eth1", }, ] result_list = self.sort_address_family(result["gathered"]) given_list = self.sort_address_family(gathered_list) self.assertEqual(result_list, given_list) + + def test_vyos_ospf_interfaces_passive_false_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="eth1", + address_family=[ + dict(afi="ipv4", passive=False), + dict(afi="ipv6", passive=False), + ], + ), + ], + state="rendered", + ), + ) + self.assertEqual( + self.execute_module(changed=False)["rendered"], + ["set protocols ospf interface eth1 passive disable"], + ) + + def test_vyos_ospf_interfaces_passive_disable_to_passive(self): + set_module_args( + dict( + config=[dict(name="eth1", address_family=[dict(afi="ipv4", passive=True)])], + state="merged", + ), + ) + self.execute_module( + changed=True, + commands=[ + "delete protocols ospf interface eth1 passive disable", + "set protocols ospf interface eth1 passive", + ], + sort=False, + filename="vyos_ospf_interfaces_passive_disable_config.cfg", + ) + + def test_vyos_ospf_interfaces_passive_disable_and_area_parsed(self): + set_module_args( + dict( + running_config="set protocols ospf interface eth1 passive disable\n" + "set protocols ospf interface eth1 area '0.0.0.1'\n" + "set protocols ospfv3 interface eth1 area '0'", + state="parsed", + ), + ) + self.assertEqual( + self.execute_module(changed=False)["parsed"], + [ + { + "name": "eth1", + "address_family": [ + {"afi": "ipv4", "passive": False, "area": "0.0.0.1"}, + {"afi": "ipv6", "area": "0"}, + ], + }, + ], + ) + + def test_vyos_ospf_interfaces_area_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="eth1", + address_family=[ + dict(afi="ipv4", area="0"), + dict(afi="ipv6", area="0.0.0.0"), + ], + ), + ], + state="rendered", + ), + ) + self.assertEqual( + sorted(self.execute_module(changed=False)["rendered"]), + [ + "set protocols ospf interface eth1 area 0", + "set protocols ospfv3 interface eth1 area 0.0.0.0", + ], + )