mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 02:15:17 +00:00
The big problem was trying to use `vars` with `import_playbook`. We do not need to use `import_playbook` when `include_tasks` will work. Perhaps the original author of these tests thought that the play `roles` keyword was the only way to invoke roles, so that had to be "called" using an `import_playbook`? Use `include_tasks` instead of `import_playbook`, and move some of those "tasks" playbooks to be tasks files in tests/tasks. Use `include_role` instead of `import_role`. Do not set variables using `set_fact` if they have already been set at the appropriate scope using `vars`. "Modernize" the code somewhat. Improve formatting. Work around an Ansible bug https://github.com/ansible/ansible/issues/85394 Fix ansible-lint and ansible-test issues related newer versions of those tools. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
190 lines
7.3 KiB
YAML
190 lines
7.3 KiB
YAML
# SPDX-License-Identifier: BSD-3-Clause
|
|
---
|
|
- name: Test output device of routes
|
|
hosts: all
|
|
vars:
|
|
type: veth
|
|
interface0: ethtest0
|
|
interface1: ethtest1
|
|
|
|
tasks:
|
|
- name: Set type and interface0
|
|
set_fact:
|
|
type: "{{ type }}"
|
|
interface: "{{ interface0 }}"
|
|
- name: Show interfaces
|
|
include_tasks: tasks/show_interfaces.yml
|
|
- name: Manage test interface
|
|
include_tasks: tasks/manage_test_interface.yml
|
|
vars:
|
|
state: present
|
|
- name: Assert device is present
|
|
include_tasks: tasks/assert_device_present.yml
|
|
- name: Set interface1
|
|
set_fact:
|
|
interface: "{{ interface1 }}"
|
|
- name: Show interfaces again
|
|
include_tasks: tasks/show_interfaces.yml
|
|
- name: Manage test interface with second interface
|
|
include_tasks: tasks/manage_test_interface.yml
|
|
vars:
|
|
state: present
|
|
- name: Assert device is present with second interface
|
|
include_tasks: tasks/assert_device_present.yml
|
|
- name: Test the route or the warning log when configuring the route with
|
|
or without the interface name
|
|
block:
|
|
- name: Configure the IP addresses and the route with interface name
|
|
specified
|
|
import_role:
|
|
name: linux-system-roles.network
|
|
vars:
|
|
network_connections:
|
|
- name: "{{ interface0 }}"
|
|
interface_name: "{{ interface0 }}"
|
|
state: up
|
|
type: ethernet
|
|
autoconnect: false
|
|
ip:
|
|
address:
|
|
- 198.51.100.3/24
|
|
- 2001:db8::2/32
|
|
route:
|
|
- network: 198.51.10.64
|
|
prefix: 26
|
|
gateway: 198.51.100.6
|
|
metric: 4
|
|
- network: 2001:db6::4
|
|
prefix: 128
|
|
gateway: 2001:db8::1
|
|
metric: 2
|
|
- name: "{{ interface1 }}"
|
|
interface_name: "{{ interface1 }}"
|
|
state: up
|
|
type: ethernet
|
|
autoconnect: false
|
|
ip:
|
|
address:
|
|
- 198.51.100.6/24
|
|
- 2001:db8::4/32
|
|
route:
|
|
- network: 198.51.12.128
|
|
prefix: 26
|
|
gateway: 198.51.100.1
|
|
metric: 2
|
|
- name: Get the IPv4 routes from the route table main
|
|
command: ip -4 route
|
|
register: route_table_main_ipv4
|
|
changed_when: false
|
|
|
|
- name: Assert that the route table main contains the specified IPv4
|
|
routes
|
|
assert:
|
|
that:
|
|
# When running with nm provider, the route will be configured
|
|
# with `proto static`
|
|
# In RHEL-6.10 managed host, the attribute in the route is not
|
|
# equally spaced
|
|
- route_table_main_ipv4.stdout is search("198.51.10.64/26 via
|
|
198.51.100.6 dev ethtest0\s+(proto static )?metric 4")
|
|
- route_table_main_ipv4.stdout is search("198.51.12.128/26 via
|
|
198.51.100.1 dev ethtest1\s+(proto static )?metric 2")
|
|
msg: "the route table main does not contain the specified IPv4
|
|
route"
|
|
|
|
- name: Get the IPv6 routes from the route table main
|
|
command: ip -6 route
|
|
register: route_table_main_ipv6
|
|
changed_when: false
|
|
|
|
- name: Assert that the route table main contains the specified IPv6
|
|
routes
|
|
assert:
|
|
that:
|
|
- route_table_main_ipv6.stdout is search("2001:db6::4 via
|
|
2001:db8::1 dev ethtest0\s+(proto static )?metric 2")
|
|
msg: "the route table main does not contain the specified IPv6
|
|
route"
|
|
- name: Get the interface1 MAC address
|
|
command: cat /sys/class/net/{{ interface1 }}/address
|
|
register: interface1_mac
|
|
changed_when: false
|
|
- name: Configure the IP addresses and the route with only the MAC
|
|
address specified
|
|
import_role:
|
|
name: linux-system-roles.network
|
|
vars:
|
|
network_connections:
|
|
- name: "{{ interface1 }}"
|
|
mac: "{{ interface1_mac.stdout }}"
|
|
type: ethernet
|
|
autoconnect: false
|
|
ip:
|
|
address:
|
|
- 198.51.100.4/24
|
|
- 2001:db8::6/32
|
|
route:
|
|
- network: 198.58.10.64
|
|
prefix: 26
|
|
gateway: 198.51.100.102
|
|
metric: 4
|
|
|
|
- name: Assert that the warning about specifying the route without
|
|
the output device is logged for initscripts provider
|
|
assert:
|
|
that:
|
|
- __network_connections_result.stderr is search("\[003\]
|
|
<warn> .0, state.None persistent_state.present,
|
|
'{{ interface1 }}'. The connection {{ interface1 }} does not
|
|
specify an interface name. Therefore, the route to
|
|
198.58.10.64/26 will be configured without the output device
|
|
and the kernel will choose it automatically which might result
|
|
in an unwanted device being used. To avoid this, specify
|
|
`interface_name` in the connection appropriately.")
|
|
msg: The warning about specifying the route without the output
|
|
device is not logged for initscripts provider
|
|
when: network_provider == "initscripts"
|
|
|
|
- name: Assert that no warning is logged for nm provider
|
|
assert:
|
|
that:
|
|
- __network_connections_result.stderr is not search("<warn>")
|
|
msg: The warning is logged for nm provider
|
|
when: network_provider == "nm"
|
|
always:
|
|
- name: Remove test configuration
|
|
tags:
|
|
- "tests::cleanup"
|
|
block:
|
|
- name: Bring down test devices and profiles
|
|
include_role:
|
|
name: linux-system-roles.network
|
|
vars:
|
|
network_connections:
|
|
- name: "{{ interface0 }}"
|
|
persistent_state: absent
|
|
state: down
|
|
- name: "{{ interface1 }}"
|
|
persistent_state: absent
|
|
state: down
|
|
- name: Delete interface1
|
|
include_tasks: tasks/delete_interface.yml
|
|
- name: Assert interface1 is absent
|
|
include_tasks: tasks/assert_device_absent.yml
|
|
- name: Set interface0
|
|
set_fact:
|
|
interface: "{{ interface0 }}"
|
|
- name: Delete interface0
|
|
include_tasks: tasks/delete_interface.yml
|
|
- name: Assert interface0 is absent
|
|
include_tasks: tasks/assert_device_absent.yml
|
|
- name: Assert interface0 profile and interface1 profile are absent
|
|
include_tasks: tasks/assert_profile_absent.yml
|
|
vars:
|
|
profile: "{{ item }}"
|
|
loop:
|
|
- "{{ interface0 }}"
|
|
- "{{ interface1 }}"
|
|
- name: Verify network state restored to default
|
|
include_tasks: tasks/check_network_dns.yml
|
|
...
|