diff --git a/changelogs/fragments/t8104-vyos_static_routes.yaml b/changelogs/fragments/t8104-vyos_static_routes.yaml new file mode 100644 index 00000000..2928b324 --- /dev/null +++ b/changelogs/fragments/t8104-vyos_static_routes.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - vyos_static_routes - Fixed interface handling in next-hop parsing diff --git a/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py b/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py index 99b3917b..710d91fe 100644 --- a/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py +++ b/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py @@ -1,177 +1,178 @@ # # -*- coding: utf-8 -*- # Copyright 2019 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ The vyos static_routes 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. """ from __future__ import absolute_import, division, print_function __metaclass__ = type from copy import deepcopy from re import M, findall, search from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.static_routes.static_routes import ( Static_routesArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( get_route_type, ) class Static_routesFacts(object): """The vyos static_routes fact class""" def __init__(self, module, subspec="config", options="options"): self._module = module self.argument_spec = Static_routesArgs.argument_spec spec = deepcopy(self.argument_spec) if subspec: if options: facts_argument_spec = spec[subspec][options] else: facts_argument_spec = spec[subspec] else: facts_argument_spec = spec self.generated_spec = utils.generate_dict(facts_argument_spec) def get_device_data(self, connection): return connection.get_config() def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for static_routes :param connection: the device connection :param ansible_facts: Facts dictionary :param data: previously collected conf :rtype: dictionary :returns: facts """ if not data: data = self.get_device_data(connection) # typically data is populated from the current device configuration # data = connection.get('show running-config | section ^interface') # using mock data instead objs = [] r_v4 = [] r_v6 = [] af = [] static_routes = findall(r"set protocols static route(6)? (\S+)", data, M) if static_routes: for route in set(static_routes): route_regex = r" %s .+$" % route[1] cfg = findall(route_regex, data, M) sr = self.render_config(cfg) sr["dest"] = route[1].strip("'") afi = self.get_afi(sr["dest"]) if afi == "ipv4": r_v4.append(sr) else: r_v6.append(sr) if r_v4: afi_v4 = {"afi": "ipv4", "routes": r_v4} af.append(afi_v4) if r_v6: afi_v6 = {"afi": "ipv6", "routes": r_v6} af.append(afi_v6) config = {"address_families": af} if config: objs.append(config) ansible_facts["ansible_network_resources"].pop("static_routes", None) facts = {} if objs: facts["static_routes"] = [] params = utils.validate_config(self.argument_spec, {"config": objs}) for cfg in params["config"]: facts["static_routes"].append(utils.remove_empties(cfg)) ansible_facts["ansible_network_resources"].update(facts) return ansible_facts def render_config(self, conf): """ Render config as dictionary structure and delete keys from spec for null values :param spec: The facts tree, generated from the argspec :param conf: The configuration :rtype: dictionary :returns: The generated config """ next_hops_conf = "\n".join(filter(lambda x: ("next-hop" in x or "interface" in x), conf)) blackhole_conf = "\n".join(filter(lambda x: ("blackhole" in x), conf)) routes_dict = { "blackhole_config": self.parse_blackhole(blackhole_conf), "next_hops": self.parse_next_hop(next_hops_conf), } return routes_dict def parse_blackhole(self, conf): blackhole = None if conf: distance = search(r"^.*blackhole distance (.\S+)", conf, M) bh = conf.find("blackhole") if distance is not None: blackhole = {} value = distance.group(1).strip("'") blackhole["distance"] = int(value) elif bh: blackhole = {} blackhole["type"] = "blackhole" return blackhole def get_afi(self, address): route_type = get_route_type(address) if route_type == "route": return "ipv4" elif route_type == "route6": return "ipv6" def parse_next_hop(self, conf): nh_list = None nh_info = {} if conf: nh_list = [] hop_list = [ match[0] if match[0] else match[1] for match in findall(r"^.*next-hop(.+)|(\s+interface.+)$", conf, M) ] if hop_list: for hop in hop_list: distance = search(r"^.*distance (.\S+)", hop, M) interface = search(r"^.*interface (.\S+)", hop, M) dis = hop.find("disable") hop_info = hop.split(" ") if interface: nh_info["interface"] = interface.group(1).strip("'") else: nh_info = {"forward_router_address": hop_info[1].strip("'")} if distance: value = distance.group(1).strip("'") nh_info["admin_distance"] = int(value) elif dis >= 1: nh_info["enabled"] = False for element in nh_list: - if element["forward_router_address"] == nh_info["forward_router_address"]: - if "interface" in nh_info.keys(): - element["interface"] = nh_info["interface"] + if element.get("forward_router_address") == nh_info.get( + "forward_router_address", + ): if "admin_distance" in nh_info.keys(): element["admin_distance"] = nh_info["admin_distance"] if "enabled" in nh_info.keys(): element["enabled"] = nh_info["enabled"] nh_info = None if nh_info is not None: nh_list.append(nh_info) + nh_info = {} return nh_list diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/_get_version.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/_get_version.yaml new file mode 100644 index 00000000..2588b194 --- /dev/null +++ b/tests/integration/targets/vyos_static_routes/tests/cli/_get_version.yaml @@ -0,0 +1,28 @@ +- 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') diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_static_routes/tests/cli/_parsed_config.cfg index b2ecd4e9..8d6638cb 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/_parsed_config.cfg +++ b/tests/integration/targets/vyos_static_routes/tests/cli/_parsed_config.cfg @@ -1,6 +1,7 @@ +set protocols static route 192.0.2.32/28 interface 'eth1' set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' set protocols static route 192.0.2.32/28 blackhole set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' set protocols static route6 2001:db8:1000::/36 blackhole distance '2' diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/_populate.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/_populate.yaml index 52d760da..4b57d5f2 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/_populate.yaml @@ -1,16 +1,37 @@ --- - ansible.builtin.include_tasks: _remove_config.yaml -- name: Setup +- name: ensure facts + include_tasks: _get_version.yaml + +- name: Setup 1.4- + vyos.vyos.vyos_config: + lines: + - set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' + - set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' + - set protocols static interface-route 192.0.2.32/28 next-hop-interface eth1 + - set protocols static route 192.0.2.32/28 blackhole + - set protocols static route 192.0.2.32/28 + - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' + - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' + - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' + - set protocols static route6 2001:db8:1000::/36 + vars: + ansible_connection: ansible.netcommon.network_cli + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: Setup 1.4+ vyos.vyos.vyos_config: lines: - set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' + - set protocols static route 192.0.2.32/28 interface eth1 - set protocols static route 192.0.2.32/28 blackhole - set protocols static route 192.0.2.32/28 - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' - set protocols static route6 2001:db8:1000::/36 vars: ansible_connection: ansible.netcommon.network_cli + when: vyos_version is version('1.4.0', '>=', version_type='semver') diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/merged.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/merged.yaml index 273f4608..a2bf47dd 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/merged.yaml @@ -1,63 +1,67 @@ --- - debug: msg: START vyos_static_routes merged 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: result vyos.vyos.vyos_static_routes: &id001 config: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: - forward_router_address: 192.0.2.10 - forward_router_address: 192.0.2.9 + - interface: eth2 + - address_families: - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 state: merged - name: Assert that before dicts were correctly generated assert: that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" - name: Assert that correct set of commands were generated assert: that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - "{{ merged.commands | symmetric_difference(result.commands) | length == 0 }}" - name: Assert that after dicts was correctly generated assert: that: - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_static_routes: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false - name: Assert that before dicts were correctly generated assert: that: - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/overridden.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/overridden.yaml index da5aff47..19f6774a 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/overridden.yaml @@ -1,49 +1,50 @@ --- - debug: msg: START vyos_static_routes overridden integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Overrides all device configuration with provided configuration register: result vyos.vyos.vyos_static_routes: &id001 config: - address_families: - afi: ipv4 routes: - dest: 198.0.2.48/28 next_hops: - forward_router_address: 192.0.2.18 + - interface: eth2 state: overridden - name: Assert that before dicts were correctly generated assert: that: - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - name: Assert that correct commands were generated assert: that: - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - name: Assert that after dicts were correctly generated assert: that: - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" - name: Overrides all device configuration with provided configurations (IDEMPOTENT) register: result vyos.vyos.vyos_static_routes: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false - name: Assert that before dicts were correctly generated assert: that: - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/parsed.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/parsed.yaml index 9881bd0a..11f09320 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/parsed.yaml @@ -1,35 +1,37 @@ --- - debug: msg: START vyos_static_routes parsed integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Gather static_routes facts register: static_routes_facts vyos.vyos.vyos_facts: gather_subset: - default gather_network_resources: - static_routes - name: Provide the running configuration for parsing (config to be parsed) register: result vyos.vyos.vyos_static_routes: &id001 running_config: "{{ lookup('file', '_parsed_config.cfg') }}" state: parsed + - debug: + msg: "{{ ansible_facts['network_resources']['static_routes'] }}" - name: Assert that correct parsing done assert: that: "{{ ansible_facts['network_resources']['static_routes'] | symmetric_difference(result['parsed']) |length == 0 }}" - name: Gather the existing running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_static_routes: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/rendered.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/rendered.yaml index 761cff7a..cc34c22b 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/rendered.yaml @@ -1,49 +1,51 @@ --- - debug: msg: START vyos_static_routes rendered integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_static_routes: &id001 config: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: - forward_router_address: 192.0.2.10 - forward_router_address: 192.0.2.9 - address_families: - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 + + - interface: eth2 state: rendered - name: Assert that correct set of commands were generated assert: that: - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" - name: Structure provided configuration into device specific commands (IDEMPOTENT) register: result vyos.vyos.vyos_static_routes: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/replaced.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/replaced.yaml index 26150e57..8f2a3c57 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/replaced.yaml @@ -1,55 +1,57 @@ --- - debug: msg: START vyos_static_routes replaced integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Replace device configurations of listed static routes with provided configurations register: result vyos.vyos.vyos_static_routes: &id001 config: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: - forward_router_address: 192.0.2.7 - forward_router_address: 192.0.2.8 - forward_router_address: 192.0.2.9 + + - interface: eth2 state: replaced - name: Assert that correct set of commands were generated assert: that: - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - name: Assert that before dicts are correctly generated assert: that: - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" - name: Assert that after dict is correctly generated assert: that: - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" - name: Replace device configurations of listed static routes with provided configurarions (IDEMPOTENT) register: result vyos.vyos.vyos_static_routes: *id001 - name: Assert that task was idempotent assert: that: - result['changed'] == false - name: Assert that before dict is correctly generated assert: that: - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tests/cli/rtt.yaml b/tests/integration/targets/vyos_static_routes/tests/cli/rtt.yaml index 2f8d475b..c59165ef 100644 --- a/tests/integration/targets/vyos_static_routes/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_static_routes/tests/cli/rtt.yaml @@ -1,74 +1,78 @@ --- - debug: msg: START vyos_static_routes round trip integration tests on connection={{ ansible_connection }} +- include_tasks: _get_version.yaml + - include_tasks: _remove_config.yaml - block: - name: Apply the provided configuration (base config) register: base_config vyos.vyos.vyos_static_routes: config: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: - forward_router_address: 192.0.2.10 - forward_router_address: 192.0.2.9 - address_families: - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 state: merged - name: Gather static_routes facts vyos.vyos.vyos_facts: gather_subset: - default gather_network_resources: - static_routes - name: Apply the provided configuration (config to be reverted) register: result vyos.vyos.vyos_static_routes: config: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: - forward_router_address: 192.0.2.7 + - interface: "eth2" + - forward_router_address: 192.0.2.8 - forward_router_address: 192.0.2.9 state: merged - name: Assert that changes were applied assert: that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" - name: Revert back to base config using facts round trip register: revert vyos.vyos.vyos_static_routes: config: "{{ ansible_facts['network_resources']['static_routes'] }}" state: overridden - name: Assert that config was reverted assert: that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/vars/main.yaml b/tests/integration/targets/vyos_static_routes/vars/main.bak similarity index 100% copy from tests/integration/targets/vyos_static_routes/vars/main.yaml copy to tests/integration/targets/vyos_static_routes/vars/main.bak diff --git a/tests/integration/targets/vyos_static_routes/vars/main.yaml b/tests/integration/targets/vyos_static_routes/vars/pre-v1_4.yaml similarity index 89% copy from tests/integration/targets/vyos_static_routes/vars/main.yaml copy to tests/integration/targets/vyos_static_routes/vars/pre-v1_4.yaml index 6ce4cea6..f739eb26 100644 --- a/tests/integration/targets/vyos_static_routes/vars/main.yaml +++ b/tests/integration/targets/vyos_static_routes/vars/pre-v1_4.yaml @@ -1,123 +1,131 @@ --- merged: before: [] commands: - set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' + - set protocols static interface-route 192.0.2.32/28 next-hop-interface 'eth2' - set protocols static route 192.0.2.32/28 blackhole - set protocols static route 192.0.2.32/28 - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' - set protocols static route6 2001:db8:1000::/36 after: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: + - interface: eth2 - forward_router_address: 192.0.2.9 - forward_router_address: 192.0.2.10 - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 populate: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: - forward_router_address: 192.0.2.9 - forward_router_address: 192.0.2.10 - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: + - interface: eth1 - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 replaced: commands: + - delete protocols static route 192.0.2.32/28 next-hop-interface 'eth1' - delete protocols static route 192.0.2.32/28 next-hop '192.0.2.10' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.8' - set protocols static route 192.0.2.32/28 blackhole distance '2' + - set protocols static interface-route 192.0.2.32/28 next-hop-interface 'eth2' after: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: - forward_router_address: 192.0.2.7 - forward_router_address: 192.0.2.8 - forward_router_address: 192.0.2.9 - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 overridden: commands: - delete protocols static route 192.0.2.32/28 - delete protocols static route6 2001:db8:1000::/36 - set protocols static route 198.0.2.48/28 next-hop '192.0.2.18' - set protocols static route 198.0.2.48/28 + - set protocols static interface-route 198.0.2.48/28 next-hop-interface 'eth2' after: - address_families: - afi: ipv4 routes: - dest: 198.0.2.48/28 next_hops: + - interface: eth2 - forward_router_address: 192.0.2.18 rendered: commands: - set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' - set protocols static route 192.0.2.32/28 blackhole - set protocols static route 192.0.2.32/28 - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' - set protocols static route6 2001:db8:1000::/36 + - set protocols static interface-route6 2001:db8:1000::/36 next-hop-interface 'eth2' deleted_afi_all: commands: - delete protocols static route - delete protocols static route6 after: [] round_trip: after: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: - forward_router_address: 192.0.2.7 - forward_router_address: 192.0.2.8 - forward_router_address: 192.0.2.9 - forward_router_address: 192.0.2.10 - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 diff --git a/tests/integration/targets/vyos_static_routes/vars/main.yaml b/tests/integration/targets/vyos_static_routes/vars/v1_4.yaml similarity index 89% rename from tests/integration/targets/vyos_static_routes/vars/main.yaml rename to tests/integration/targets/vyos_static_routes/vars/v1_4.yaml index 6ce4cea6..ae88711b 100644 --- a/tests/integration/targets/vyos_static_routes/vars/main.yaml +++ b/tests/integration/targets/vyos_static_routes/vars/v1_4.yaml @@ -1,123 +1,134 @@ --- merged: before: [] commands: + - set protocols static route 192.0.2.32/28 + - set protocols static route 192.0.2.32/28 blackhole - set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' - - set protocols static route 192.0.2.32/28 blackhole - - set protocols static route 192.0.2.32/28 + - set protocols static route 192.0.2.32/28 interface 'eth2' + - set protocols static route6 2001:db8:1000::/36 + - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' - - set protocols static route6 2001:db8:1000::/36 after: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: + - interface: eth2 - forward_router_address: 192.0.2.9 - forward_router_address: 192.0.2.10 - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 populate: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: type: blackhole next_hops: + - interface: eth1 - forward_router_address: 192.0.2.9 - forward_router_address: 192.0.2.10 - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 replaced: commands: + - delete protocols static route 192.0.2.32/28 interface 'eth1' - delete protocols static route 192.0.2.32/28 next-hop '192.0.2.10' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.8' - set protocols static route 192.0.2.32/28 blackhole distance '2' + - set protocols static route 192.0.2.32/28 interface 'eth2' + after: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: + - interface: eth2 - forward_router_address: 192.0.2.7 - forward_router_address: 192.0.2.8 - forward_router_address: 192.0.2.9 - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2 overridden: commands: - delete protocols static route 192.0.2.32/28 - delete protocols static route6 2001:db8:1000::/36 - set protocols static route 198.0.2.48/28 next-hop '192.0.2.18' - set protocols static route 198.0.2.48/28 + - set protocols static route 198.0.2.48/28 interface 'eth2' after: - address_families: - afi: ipv4 routes: - dest: 198.0.2.48/28 next_hops: + - interface: eth2 - forward_router_address: 192.0.2.18 rendered: commands: - set protocols static route 192.0.2.32/28 next-hop '192.0.2.10' - set protocols static route 192.0.2.32/28 next-hop '192.0.2.9' - set protocols static route 192.0.2.32/28 blackhole - set protocols static route 192.0.2.32/28 - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' - set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - set protocols static route6 2001:db8:1000::/36 blackhole distance '2' - set protocols static route6 2001:db8:1000::/36 + - set protocols static route6 2001:db8:1000::/36 interface 'eth2' deleted_afi_all: commands: - delete protocols static route - delete protocols static route6 after: [] round_trip: after: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: + - interface: eth2 - forward_router_address: 192.0.2.7 - forward_router_address: 192.0.2.8 - forward_router_address: 192.0.2.9 - forward_router_address: 192.0.2.10 - afi: ipv6 routes: - dest: 2001:db8:1000::/36 blackhole_config: distance: 2 next_hops: - forward_router_address: 2001:db8:2000:2::1 - forward_router_address: 2001:db8:2000:2::2