Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T7012 ospf_interfaces integration tests #387

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
9 changes: 9 additions & 0 deletions changelogs/fragments/T7012_ospf-integration-tests.yaml
Original file line number Diff line number Diff line change
@@ -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+
omnom62 marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,12 @@ def get_device_data(self, connection):

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)
omnom62 marked this conversation as resolved.
Show resolved Hide resolved
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"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def __init__(self, lines=None, module=None):
\s+(?P<name>\S+)
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+(?P<mtu>\'mtu-ignore\')
\s+(?P<mtu>mtu-ignore)
*$""",
re.VERBOSE,
),
Expand Down Expand Up @@ -697,7 +697,7 @@ def __init__(self, lines=None, module=None):
\s+(?P<name>\S+)
\s+(?P<afi>ip|ipv6)
\s+(?P<proto>ospf|ospfv3)
\s+(?P<pass>\'passive\')
\s+(?P<pass>passive)
*$""",
re.VERBOSE,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def __init__(self, lines=None, module=None):
\s+(?P<proto>ospf|ospfv3)
\s+interface
\s+(?P<name>\S+)
\s+(?P<mtu>\'mtu-ignore\')
\s+(?P<mtu>mtu-ignore)
*$""",
re.VERBOSE,
),
Expand Down Expand Up @@ -613,7 +613,7 @@ def __init__(self, lines=None, module=None):
\s+(?P<proto>ospf|ospfv3)
\s+interface
\s+(?P<name>\S+)
\s+(?P<pass>\'passive\')
\s+(?P<pass>passive)
*$""",
re.VERBOSE,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
- 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- debug:
msg: START vyos_ospf_interfaces rtt integration tests on connection={{ ansible_connection }}

- include_tasks: _populate.yaml

- include_tasks: _remove_config.yaml
omnom62 marked this conversation as resolved.
Show resolved Hide resolved

- block:
Expand Down
45 changes: 6 additions & 39 deletions tests/integration/targets/vyos_ospf_interfaces/vars/main.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
---
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
Expand All @@ -24,16 +18,7 @@ merged:
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
Expand All @@ -56,16 +41,7 @@ replaced:
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
Expand All @@ -77,9 +53,7 @@ overridden:
name: eth0

deleted:
commands:
- delete interfaces bonding bond2 ip ospf
- delete interfaces bonding bond2 ipv6 ospfv3
commands: "{{ deleted_commands }}"
after:
- address_family:
- afi: ipv4
Expand All @@ -91,15 +65,8 @@ deleted:
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions tests/integration/targets/vyos_ospf_interfaces/vars/v1_4.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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'