diff --git a/changelogs/fragments/T7012_ospf-integration-tests.yaml b/changelogs/fragments/T7012_ospf-integration-tests.yaml new file mode 100644 index 00000000..b696b2aa --- /dev/null +++ b/changelogs/fragments/T7012_ospf-integration-tests.yaml @@ -0,0 +1,9 @@ +--- +minor_changes: + - vyos_ospf_interfaces - add support for VyOS 1.4+, which moved interface configuration from the interfaces to ospf/ospfv3 interfaces configuration +bugfixes: + - vyos_ospf_interfaces - fixed get_config to cater for unordered command lists in 1.4+ +trivial: + - vyos_ospf_interfaces - re-worked intergration test suite structure to D.R.Y. + - vyos_ospf_interfaces - added support for 1.4+ VyOS + - vyos_ospf_interfaces - updated unit test suite to cater for 1.4+ bugfixes 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 c0e74895..852e1da7 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 @@ -1,142 +1,133 @@ # -*- 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 fact class It is in this file the configuration is collected from the device for a given resource, parsed, and the facts tree is populated based on the configuration. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils 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.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.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""" def __init__(self, module, subspec="config", options="options"): self._module = module self.argument_spec = Ospf_interfacesArgs.argument_spec def get_device_data(self, connection): if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): # use set protocols ospf in order to get both ospf and ospfv3 return connection.get("show configuration commands | match 'set protocols ospf'") return connection.get('show configuration commands | match "set interfaces"') def get_config_set_1_4(self, data): """To classify the configurations beased on interface""" - interface_list = [] - config_set = [] - int_string = "" + config_dict = {} for config_line in data.splitlines(): - ospf_int = re.search(r"set protocols (?:ospf|ospfv3) interface (\S+) .*", config_line) + ospf_int = re.search(r"set protocols (?:ospf|ospfv3) interface (\S+).*", config_line) if ospf_int: - if ospf_int.group(1) not in interface_list: - if int_string: - config_set.append(int_string) - interface_list.append(ospf_int.group(1)) - int_string = "" - int_string = int_string + config_line + "\n" - if int_string: - config_set.append(int_string) - return config_set + 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): """To classify the configurations beased on interface""" interface_list = [] config_set = [] int_string = "" for config_line in data.splitlines(): ospf_int = re.search(r"set interfaces \S+ (\S+) .*", config_line) if ospf_int: if ospf_int.group(1) not in interface_list: if int_string: config_set.append(int_string) interface_list.append(ospf_int.group(1)) int_string = "" int_string = int_string + config_line + "\n" if int_string: config_set.append(int_string) return config_set def get_config_set(self, data, connection): """To classify the configurations beased on interface""" if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): return self.get_config_set_1_4(data) return self.get_config_set_1_2(data) def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for Ospf_interfaces network resource :param connection: the device connection :param ansible_facts: Facts dictionary :param data: previously collected conf :rtype: dictionary :returns: facts """ facts = {} objs = [] if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): ospf_interface_class = Ospf_interfacesTemplate14 else: ospf_interface_class = Ospf_interfacesTemplate ospf_interfaces_parser = ospf_interface_class(lines=[], module=self._module) if not data: data = self.get_device_data(connection) # parse native config using the Ospf_interfaces template ospf_interfaces_facts = [] resources = self.get_config_set(data, connection) for resource in resources: ospf_interfaces_parser = ospf_interface_class( lines=resource.split("\n"), module=self._module, ) objs = ospf_interfaces_parser.parse() for key, sortv in [("address_family", "afi")]: 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( ospf_interfaces_parser.validate_config( 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 aaaf7ff2..0d7eaf84 100644 --- a/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py +++ b/plugins/module_utils/network/vyos/rm_templates/ospf_interfaces.py @@ -1,733 +1,733 @@ # -*- 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, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( get_interface_type, ) def _get_parameters(data): if data["afi"] == "ipv6": val = ["ospfv3", "ipv6"] else: val = ["ospf", "ip"] return val def _tmplt_ospf_int_delete(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] ) return command def _tmplt_ospf_int_cost(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " cost {cost}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_auth_password(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " authentication plaintext-password {plaintext_password}".format( **config_data["address_family"]["authentication"], ) ) return command def _tmplt_ospf_int_auth_md5(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " authentication md5 key-id {key_id} ".format( **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): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " authentication" ) return command def _tmplt_ospf_int_bw(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " bandwidth {bandwidth}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_hello_interval(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " hello-interval {hello_interval}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_dead_interval(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " dead-interval {dead_interval}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_mtu_ignore(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " mtu-ignore" ) return command def _tmplt_ospf_int_network(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " network {network}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_priority(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " priority {priority}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_retransmit_interval(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " retransmit-interval {retransmit_interval}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_transmit_delay(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " transmit-delay {transmit_delay}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_ifmtu(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " ifmtu {ifmtu}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_instance(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " instance-id {instance}".format(**config_data["address_family"]) ) return command def _tmplt_ospf_int_passive(config_data): int_type = get_interface_type(config_data["name"]) params = _get_parameters(config_data["address_family"]) command = ( "interfaces " + int_type + " {name} ".format(**config_data) + params[1] + " " + params[0] + " passive" ) return command class Ospf_interfacesTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} super(Ospf_interfacesTemplate, self).__init__( lines=lines, tmplt=self, prefix=prefix, module=module, ) # fmt: off PARSERS = [ { "name": "ip_ospf", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) *$""", re.VERBOSE, ), "remval": _tmplt_ospf_int_delete, "compval": "address_family", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', }, }, }, }, { "name": "authentication_password", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+authentication \s+plaintext-password \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_auth_password, "compval": "address_family.authentication", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "authentication": { "plaintext_password": "{{ text }}", }, }, }, }, }, { "name": "authentication_md5", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+authentication \s+md5 \s+key-id \s+(?P\d+) \s+md5-key \s+(?P\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": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "authentication": { "md5_key": { "key_id": "{{ id }}", "key": "{{ text }}", }, }, }, }, }, }, { "name": "bandwidth", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+bandwidth \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_bw, "compval": "address_family.bandwidth", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "bandwidth": "{{ bw }}", }, }, }, }, { "name": "cost", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+cost \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_cost, "compval": "address_family.cost", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "cost": "{{ val }}", }, }, }, }, { "name": "hello_interval", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+hello-interval \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_hello_interval, "compval": "address_family.hello_interval", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "hello_interval": "{{ val }}", }, }, }, }, { "name": "dead_interval", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+dead-interval \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_dead_interval, "compval": "address_family.dead_interval", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "dead_interval": "{{ val }}", }, }, }, }, { "name": "mtu_ignore", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) - \s+(?P\'mtu-ignore\') + \s+(?Pmtu-ignore) *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_mtu_ignore, "compval": "address_family.mtu_ignore", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "mtu_ignore": "{{ True if mtu is defined }}", }, }, }, }, { "name": "network", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+network \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_network, "compval": "address_family.network", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "network": "{{ val }}", }, }, }, }, { "name": "priority", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+priority \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_priority, "compval": "address_family.priority", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "priority": "{{ val }}", }, }, }, }, { "name": "retransmit_interval", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+retransmit-interval \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_retransmit_interval, "compval": "address_family.retransmit_interval", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "retransmit_interval": "{{ val }}", }, }, }, }, { "name": "transmit_delay", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+transmit-delay \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_transmit_delay, "compval": "address_family.transmit_delay", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "transmit_delay": "{{ val }}", }, }, }, }, { "name": "ifmtu", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+ifmtu \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_ifmtu, "compval": "address_family.ifmtu", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "ifmtu": "{{ val }}", }, }, }, }, { "name": "instance", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) \s+instance-id \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_instance, "compval": "address_family.instance", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "instance": "{{ val }}", }, }, }, }, { "name": "passive", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) \s+(?Pip|ipv6) \s+(?Pospf|ospfv3) - \s+(?P\'passive\') + \s+(?Ppassive) *$""", re.VERBOSE, ), "setval": _tmplt_ospf_int_passive, "compval": "address_family.passive", "result": { "name": "{{ name }}", "address_family": { "{{ afi }}": { "afi": '{{ "ipv4" if afi == "ip" else "ipv6" }}', "passive": "{{ True if pass is defined }}", }, }, }, }, { "name": "interface_name", "getval": re.compile( r""" ^set \s+interfaces \s+(?P\S+) \s+(?P\S+) .*$""", re.VERBOSE, ), "setval": "set interface {{ type }} {{ name }}", "result": { "name": "{{ name }}", }, }, ] # fmt: on 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 7f49d47a..43fae1e9 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,650 +1,650 @@ # -*- 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"] ) ) 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"] ) + "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" ) 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 ) # fmt: off PARSERS = [ { "name": "ip_ospf", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\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+) *$""", 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 }}" } } } } }, { "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+) *$""", 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 }}" } } } } } }, { "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 }}" } } } }, { "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 }}" } } } }, { "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 }}" } } } }, { "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 }}" } } } }, { "name": "mtu_ignore", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) - \s+(?P\'mtu-ignore\') + \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 }}" } } } }, { "name": "network", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) \s+network \s+(?P\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 }}" } } } }, { "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 }}" } } } }, { "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 }}" } } } }, { "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 }}" } } } }, { "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 }}" } } } }, { "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 }}" } } } }, { "name": "passive", "getval": re.compile( r""" ^set \s+protocols \s+(?Pospf|ospfv3) \s+interface \s+(?P\S+) - \s+(?P\'passive\') + \s+(?Ppassive) *$""", 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 }}" } } } }, { "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/tests/integration/targets/vyos_ospf_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_ospf_interfaces/tasks/main.yaml index e6378581..4a9d2cd0 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tasks/main.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tasks/main.yaml @@ -1,5 +1,13 @@ --- +- name: Run preflight setup + ansible.builtin.import_tasks: pre_tasks.yml + failed_when: false + - name: Run CLI tests ansible.builtin.include_tasks: cli.yaml tags: - network_cli + +- name: Run post-test cleanup tasks + ansible.builtin.import_tasks: post_tasks.yml + failed_when: false diff --git a/tests/integration/targets/vyos_ospf_interfaces/tasks/post_tasks.yml b/tests/integration/targets/vyos_ospf_interfaces/tasks/post_tasks.yml new file mode 100644 index 00000000..0883ef48 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tasks/post_tasks.yml @@ -0,0 +1,7 @@ +--- +- name: Demolish environment + vyos.vyos.vyos_config: + lines: |- + delete interfaces bonding bond2 + 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 new file mode 100644 index 00000000..af74ff7a --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tasks/pre_tasks.yml @@ -0,0 +1,7 @@ +--- +- name: Setup environment + vyos.vyos.vyos_config: + lines: |- + set interfaces bonding bond2 + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_get_version.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_get_version.yaml new file mode 100644 index 00000000..a7691499 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_get_version.yaml @@ -0,0 +1,31 @@ +- name: make sure to get facts + vyos.vyos.vyos_facts: + vars: + ansible_connection: ansible.netcommon.network_cli + register: vyos_facts + when: vyos_version is not defined + +- name: debug vyos_facts + debug: + var: vyos_facts + +- name: pull version from facts + set_fact: + vyos_version: "{{ vyos_facts.ansible_facts.ansible_net_version.split('-')[0].split(' ')[-1] }}" + when: vyos_version is not defined + +- name: fix '.0' versions + set_fact: + vyos_version: "{{ vyos_version }}.0" + when: vyos_version.count('.') == 1 + +- name: include correct vars + include_vars: pre-v1_4.yaml + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: include correct vars + include_vars: v1_4.yaml + when: vyos_version is version('1.4.0', '>=', version_type='semver') + +# - name: include common vars +# include_vars: main.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config.cfg deleted file mode 100644 index 48f286ee..00000000 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config.cfg +++ /dev/null @@ -1,9 +0,0 @@ -set interfaces ethernet eth1 firewall in name 'INBOUND' -set interfaces ethernet eth1 firewall out name 'OUTBOUND' -set interfaces ethernet eth1 firewall local name 'LOCAL' -set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' -set interfaces ethernet eth2 firewall in name 'INBOUND' -set interfaces ethernet eth2 firewall out name 'OUTBOUND' -set interfaces ethernet eth2 firewall local name 'LOCAL' -set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' -set interfaces ethernet eth0 diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config_1_3.cfg similarity index 66% rename from tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed.cfg rename to tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config_1_3.cfg index aa576770..b8112dd0 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed.cfg +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config_1_3.cfg @@ -1,6 +1,6 @@ set interfaces ethernet eth0 ip ospf cost '50' set interfaces ethernet eth0 ip ospf priority '26' -set interfaces ethernet eth0 ipv6 ospfv3 'mtu-ignore' +set interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore set interfaces ethernet eth0 ipv6 ospfv3 instance-id '33' set interfaces bonding bond2 ip ospf transmit-delay '45' -set interfaces bonding bond2 ipv6 ospfv3 'passive' +set interfaces bonding bond2 ipv6 ospfv3 passive diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config_1_4.cfg b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config_1_4.cfg new file mode 100644 index 00000000..269a5aba --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config_1_4.cfg @@ -0,0 +1,6 @@ +set protocols ospf interface eth0 cost '50' +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 bond2 transmit-delay '45' +set protocols ospfv3 interface bond2 passive diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_populate.yaml index 4a24ff99..ccd0f679 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_populate.yaml @@ -1,14 +1,11 @@ --- - ansible.builtin.include_tasks: _remove_config.yaml -- name: Setup +- name: ensure facts + include_tasks: _get_version.yaml + +- name: Setup {{ vyos_version }} vyos.vyos.vyos_config: - lines: - - set interfaces ethernet eth0 ip ospf cost 50 - - 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 bonding bond2 ip ospf transmit-delay 45 - - set interfaces bonding bond2 ipv6 ospfv3 passive + lines: "{{ populate_commands }}" vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_remove_config.yaml index 1d0b96dc..74d79f62 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_remove_config.yaml @@ -1,15 +1,9 @@ --- +- name: ensure facts + include_tasks: _get_version.yaml + - name: Remove pre-existing OSPF processes vyos.vyos.vyos_config: - lines: - - delete interfaces ethernet eth0 ip ospf - - delete interfaces ethernet eth0 ipv6 ospfv3 - - delete interfaces ethernet eth1 ip ospf - - delete interfaces ethernet eth1 ipv6 ospfv3 - - delete interfaces bonding bond1 ip ospf - - delete interfaces bonding bond1 ipv6 ospfv3 - - delete interfaces bonding bond2 ip ospf - - delete interfaces bonding bond2 ipv6 ospfv3 - - delete interfaces bonding bond2 + lines: "{{ remove_commands }}" vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml index 0d13f76d..cb70065a 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml @@ -1,14 +1,17 @@ --- - debug: msg: START vyos_ospfv3_interfaces parsed integration tests on connection={{ ansible_connection }} +- name: ensure facts + include_tasks: _get_version.yaml + - name: Provide the running configuration for parsing (config to be parsed) register: result vyos.vyos.vyos_ospf_interfaces: - running_config: "{{ lookup('file', '_parsed.cfg') }}" + running_config: "{{ lookup('file', parsed_config_file) }}" state: parsed - assert: that: - result.changed == false - result.parsed|symmetric_difference(merged.after) == [] 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 42da6ac2..c74248e0 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml @@ -1,62 +1,64 @@ --- - debug: msg: START vyos_ospf_interfaces rtt integration tests on connection={{ ansible_connection }} +- include_tasks: _populate.yaml + - include_tasks: _remove_config.yaml - block: - name: Merge the provided configuration with the existing running configuration register: baseconfig vyos.vyos.vyos_ospf_interfaces: config: - name: eth0 address_family: - afi: ipv4 cost: 50 priority: 26 - afi: ipv6 mtu_ignore: true instance: 33 - 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: - baseconfig.commands|length == 6 - baseconfig.changed == true - baseconfig.commands|symmetric_difference(merged.commands) == [] - baseconfig.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] - name: Apply the provided configuration (config to be reverted) register: result vyos.vyos.vyos_ospf_interfaces: config: - name: eth0 address_family: - afi: ipv4 transmit_delay: 50 priority: 26 network: point-to-point - afi: ipv6 dead_interval: 39 - name: Revert back to base config using facts round trip register: revert vyos.vyos.vyos_ospf_interfaces: config: "{{ ansible_facts['network_resources']['ospf_interfaces'] }}" state: overridden - name: Assert that config was reverted assert: that: baseconfig.after == revert.after always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/vars/main.yaml b/tests/integration/targets/vyos_ospf_interfaces/vars/main.yaml index 5c618eed..06260fe4 100644 --- a/tests/integration/targets/vyos_ospf_interfaces/vars/main.yaml +++ b/tests/integration/targets/vyos_ospf_interfaces/vars/main.yaml @@ -1,133 +1,100 @@ --- merged: - commands: - - set interfaces ethernet eth0 ip ospf cost 50 - - 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 bonding bond2 ip ospf transmit-delay 45 - - set interfaces bonding bond2 ipv6 ospfv3 passive + commands: "{{ merged_commands }}" after: - address_family: - afi: ipv4 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 replaced: - commands: - - 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 - - delete interfaces ethernet eth0 ip ospf cost 50 - - delete interfaces ethernet eth0 ipv6 ospfv3 instance-id 33 - - delete interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore - - set interfaces bonding bond2 ip ospf bandwidth 70 - - set interfaces bonding bond2 ip ospf authentication md5 key-id 10 md5-key ******** - + commands: "{{ replaced_commands }}" after: - 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 network: point-to-point priority: 26 transmit_delay: 50 - afi: ipv6 dead_interval: 39 name: eth0 overridden: - commands: - - delete interfaces bonding bond2 ip ospf - - delete interfaces bonding bond2 ipv6 ospfv3 - - 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 - - delete interfaces ethernet eth0 ip ospf cost 50 - - delete interfaces ethernet eth0 ipv6 ospfv3 instance-id 33 - - delete interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore - + commands: "{{ overridden_commands }}" after: - address_family: - afi: ipv4 network: point-to-point priority: 26 transmit_delay: 50 - afi: ipv6 dead_interval: 39 name: eth0 deleted: - commands: - - delete interfaces bonding bond2 ip ospf - - delete interfaces bonding bond2 ipv6 ospfv3 + commands: "{{ deleted_commands }}" after: - address_family: - afi: ipv4 cost: 50 priority: 26 - afi: ipv6 instance: "33" mtu_ignore: true name: eth0 rendered: - commands: - - set interfaces ethernet eth1 firewall in name 'INBOUND' - - set interfaces ethernet eth1 firewall out name 'OUTBOUND' - - set interfaces ethernet eth1 firewall local name 'LOCAL' - - set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' - - set interfaces ethernet eth2 firewall in name 'INBOUND' - - set interfaces ethernet eth2 firewall out name 'OUTBOUND' - - set interfaces ethernet eth2 firewall local name 'LOCAL' - - set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' + commands: "{{ rendered_commands }}" + round_trip: after: - name: eth0 - access_rules: - afi: ipv4 rules: - direction: in name: INBOUND - direction: local name: LOCAL - direction: out name: OUTBOUND - afi: ipv6 rules: - direction: local name: V6-LOCAL name: eth1 - name: eth2 access_rules: - afi: ipv4 rules: - direction: in name: INBOUND - direction: local name: LOCAL - direction: out name: OUTBOUND - afi: ipv6 rules: - direction: local name: V6-LOCAL 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 new file mode 100644 index 00000000..a9e03421 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/vars/pre-v1_4.yaml @@ -0,0 +1,53 @@ +--- +merged_commands: + - set interfaces ethernet eth0 ip ospf cost 50 + - 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 bonding bond2 ip ospf transmit-delay 45 + - set interfaces bonding bond2 ipv6 ospfv3 passive + +populate_commands: + - set interfaces ethernet eth0 ip ospf cost 50 + - 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 bonding bond2 ip ospf transmit-delay 45 + - set interfaces bonding bond2 ipv6 ospfv3 passive + +remove_commands: + - delete interfaces ethernet eth0 ip ospf + - delete interfaces ethernet eth0 ipv6 ospfv3 + - delete interfaces ethernet eth1 ip ospf + - delete interfaces ethernet eth1 ipv6 ospfv3 + - delete interfaces bonding bond1 ip ospf + - delete interfaces bonding bond1 ipv6 ospfv3 + - delete interfaces bonding bond2 ip ospf + - delete interfaces bonding bond2 ipv6 ospfv3 + - delete interfaces bonding bond2 + +parsed_config_file: "_parsed_config_1_3.cfg" + +replaced_commands: + - 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 + - delete interfaces ethernet eth0 ip ospf cost 50 + - delete interfaces ethernet eth0 ipv6 ospfv3 instance-id 33 + - delete interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore + - set interfaces bonding bond2 ip ospf bandwidth 70 + - set interfaces bonding bond2 ip ospf authentication md5 key-id 10 md5-key ******** + +overridden_commands: + - delete interfaces bonding bond2 ip ospf + - delete interfaces bonding bond2 ipv6 ospfv3 + - 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 + - delete interfaces ethernet eth0 ip ospf cost 50 + - delete interfaces ethernet eth0 ipv6 ospfv3 instance-id 33 + - delete interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore + +deleted_commands: + - delete interfaces bonding bond2 ip ospf + - delete interfaces bonding bond2 ipv6 ospfv3 diff --git a/tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml b/tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml new file mode 100644 index 00000000..15b7f5a7 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml @@ -0,0 +1,48 @@ +--- +merged_commands: + - set protocols ospf interface eth0 cost 50 + - set protocols ospf interface eth0 priority 26 + - set protocols ospfv3 interface eth0 mtu-ignore + - set protocols ospfv3 interface eth0 instance-id 33 + - set protocols ospfv3 interface bond2 passive + - set protocols ospf interface bond2 transmit-delay 45 + +populate_commands: + - set protocols ospf interface eth0 cost 50 + - set protocols ospf interface eth0 priority 26 + - set protocols ospfv3 interface eth0 mtu-ignore + - set protocols ospfv3 interface eth0 instance-id 33 + - 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 bond2 + - delete protocols ospfv3 interface bond2 + - delete protocols ospfv3 interface eth0 + +parsed_config_file: "_parsed_config_1_4.cfg" + +replaced_commands: + - 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 + - delete protocols ospf interface eth0 cost 50 + - delete protocols ospfv3 interface eth0 instance-id 33 + - delete protocols ospfv3 interface eth0 mtu-ignore + - set protocols ospf interface bond2 bandwidth 70 + - set protocols ospf interface bond2 authentication md5 key-id 10 md5-key ******** + +overridden_commands: + - delete protocols ospf interface bond2 + - delete protocols ospfv3 interface bond2 + - 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 + - delete protocols ospf interface eth0 cost 50 + - delete protocols ospfv3 interface eth0 instance-id 33 + - delete protocols ospfv3 interface eth0 mtu-ignore + +deleted_commands: + - delete protocols ospf interface bond2 + - delete protocols ospfv3 interface bond2 diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config.cfg index 1fab55e3..2dfa661b 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config.cfg @@ -1,4 +1,4 @@ set interfaces ethernet eth0 ipv6 ospfv3 instance-id '33' -set interfaces ethernet eth0 ipv6 ospfv3 'mtu-ignore' +set interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore set interfaces ethernet eth1 ip ospf cost '100' set interfaces ethernet eth1 ipv6 ospfv3 ifmtu '33' diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config_14.cfg index d630d94c..0053877e 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config_14.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config_14.cfg @@ -1,4 +1,4 @@ set protocols ospfv3 interface eth0 instance-id '33' -set protocols ospfv3 interface eth0 'mtu-ignore' +set protocols ospfv3 interface eth0 mtu-ignore set protocols ospf interface eth1 cost '100' set protocols ospfv3 interface eth1 ifmtu '33'