refactor: support Ansible 2.19

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>
This commit is contained in:
Rich Megginson 2025-06-26 09:38:28 -06:00 committed by Richard Megginson
parent 14f9044bfc
commit 65e74567d4
32 changed files with 292 additions and 344 deletions

View file

@ -0,0 +1,3 @@
plugins/modules/network_connections.py validate-modules:missing-gplv3-license
plugins/modules/network_state.py validate-modules:missing-gplv3-license
tests/network/ensure_provider_tests.py shebang!skip

View file

@ -0,0 +1,3 @@
plugins/modules/network_connections.py validate-modules:missing-gplv3-license
plugins/modules/network_state.py validate-modules:missing-gplv3-license
tests/network/ensure_provider_tests.py shebang!skip

View file

@ -1 +0,0 @@
../tests/playbooks/down_profile.yml

View file

@ -176,13 +176,13 @@
network_state:
routes:
config:
- destination: ::/0
next-hop-interface: eth1
next-hop-address: fe80::1
- destination: ::/0
next-hop-interface: eth1
next-hop-address: fe80::1
ansible.builtin.include_role:
name: linux-system-roles.network
- name: Configure the ethernet device eth1 with dhcp4 configured
- name: Configure the ethernet device eth1 with dhcp4 configured again
vars:
network_state:
interfaces:

View file

@ -1,11 +0,0 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Set down profile {{ profile }}
hosts: all
vars:
network_connections:
- name: "{{ profile }}"
persistent_state: absent
state: down
roles:
- linux-system-roles.network

View file

@ -1 +0,0 @@
../tests/playbooks/remove_profile.yml

View file

@ -45,7 +45,7 @@
hidden: true
register: files_to_delete
- name: Remove old data
- name: Remove old data from files_to_delete
file:
path: "{{ item.path }}"
state: absent

View file

@ -1,9 +0,0 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Import the playbook 'down_profile.yml'
import_playbook: down_profile.yml
- name: Delete the interface
hosts: all
tasks:
- name: Include the task 'delete_interface.yml'
include_tasks: tasks/delete_interface.yml

View file

@ -1,10 +0,0 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Remove {{ profile }}
hosts: all
vars:
network_connections:
- name: "{{ profile }}"
persistent_state: absent
roles:
- linux-system-roles.network

View file

@ -39,7 +39,7 @@
# not take precedence over other routes or not ignore other
# routes
route_metric4: 65535
- name: Include the task 'assert_device_present.yml'
- name: Include the task 'assert_device_present.yml' again
include_tasks: tasks/assert_device_present.yml
- name: Include the task 'assert_profile_present.yml'
include_tasks: tasks/assert_profile_present.yml
@ -67,7 +67,7 @@
- name: "TEARDOWN: remove profiles."
debug:
msg: "##################################################"
- name: Import network role
- name: Import network role to remove interface
import_role:
name: linux-system-roles.network
vars:
@ -76,7 +76,7 @@
persistent_state: absent
state: down
ignore_errors: true # noqa ignore-errors
- name: Include the task 'manage_test_interface.yml'
- name: Include the task 'manage_test_interface.yml' to remove interface
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent
@ -84,11 +84,11 @@
TEST: I can configure an interface with auto_gateway disabled
debug:
msg: "##################################################"
- name: Include the task 'manage_test_interface.yml'
- name: Include the task 'manage_test_interface.yml' to disable auto_gateway
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Import network role
- name: Import network role to disable auto_gateway
import_role:
name: linux-system-roles.network
vars:
@ -105,13 +105,13 @@
- "203.0.113.2/24"
gateway6: "2001:db8::1"
gateway4: "203.0.113.1"
- name: Include the task 'assert_device_present.yml'
- name: Include the task 'assert_device_present.yml' - 3
include_tasks: tasks/assert_device_present.yml
- name: Include the task 'assert_profile_present.yml'
- name: Include the task 'assert_profile_present.yml' again
include_tasks: tasks/assert_profile_present.yml
vars:
profile: "{{ interface }}"
- name: "Show ipv4 routes"
- name: "Show ipv4 routes again"
command: "ip route"
register: ipv4_routes
changed_when: false
@ -120,7 +120,7 @@
that: __test_str not in ipv4_routes.stdout
vars:
__test_str: default via 203.0.113.1 dev {{ interface }}
- name: "Get ipv6 routes"
- name: "Get ipv6 routes again"
command: "ip -6 route"
register: ipv6_route
changed_when: false
@ -130,10 +130,10 @@
vars:
__test_str: default via 2001:db8::1 dev {{ interface }}
when: network_provider == "nm"
- name: "TEARDOWN: remove profiles."
- name: "TEARDOWN: remove profiles. again"
debug:
msg: "##################################################"
- name: Import network role
- name: Import network role to remove interface again
import_role:
name: linux-system-roles.network
vars:
@ -142,7 +142,7 @@
persistent_state: absent
state: down
ignore_errors: true # noqa ignore-errors
- name: Include the task 'manage_test_interface.yml'
- name: Include the task 'manage_test_interface.yml' to remove interface again
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent

View file

@ -4,65 +4,52 @@
hosts: all
vars:
interface: LSR-TST-br31
tasks:
- name: "Set interface={{ interface }}"
set_fact:
interface: "{{ interface }}"
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Add test bridge
hosts: all
vars:
network_connections:
- name: "{{ interface }}"
interface_name: "{{ interface }}"
state: up
type: bridge
ip:
dhcp4: false
auto6: true
roles:
- linux-system-roles.network
- name: Add test bridge
include_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
interface_name: "{{ interface }}"
state: up
type: bridge
ip:
dhcp4: false
auto6: true
- name: Import the playbook 'run_tasks.yml'
import_playbook: run_tasks.yml
vars:
task: tasks/assert_device_present.yml
- name: Assert device present
include_tasks: tasks/assert_device_present.yml
- name: Import the playbook 'run_tasks.yml'
import_playbook: run_tasks.yml
vars:
profile: "{{ interface }}"
task: tasks/assert_profile_present.yml
- name: Assert profile present
include_tasks: tasks/assert_profile_present.yml
vars:
profile: "{{ interface }}"
- name: Import the playbook 'down_profile+delete_interface.yml'
import_playbook: down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Include the task 'down_profile+delete_interface.yml'
include_tasks: tasks/down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Import the playbook 'remove_profile.yml'
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'remove_profile.yml'
include_tasks: tasks/remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Import the playbook 'run_tasks.yml'
import_playbook: run_tasks.yml
vars:
profile: "{{ interface }}"
task: tasks/assert_profile_absent.yml
- name: Assert profile absent
include_tasks: tasks/assert_profile_absent.yml
vars:
profile: "{{ interface }}"
- name: Import the playbook 'run_tasks.yml'
import_playbook: run_tasks.yml
vars:
task: tasks/assert_device_absent.yml
- name: Assert device absent
include_tasks: tasks/assert_device_absent.yml
- name: Verify that cleanup restored state to default
hosts: all
tasks:
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -1,28 +1,25 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Test configuring bridges
hosts: all
tasks:
- name: Define vars
set_fact:
interface: "LSR-TST-br31"
cloned_mac: "12:23:34:45:56:70"
- name: Add test bridge
hosts: all
vars:
network_connections:
- name: "{{ interface }}"
interface_name: "{{ interface }}"
state: up
type: bridge
ip:
dhcp4: false
auto6: true
cloned_mac: "{{ cloned_mac }}"
roles:
- linux-system-roles.network
interface: "LSR-TST-br31"
cloned_mac: "12:23:34:45:56:70"
tasks:
- name: Add test bridge
include_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
interface_name: "{{ interface }}"
state: up
type: bridge
ip:
dhcp4: false
auto6: true
cloned_mac: "{{ cloned_mac }}"
- name: Verify ifcfg MACADDR entry
command: >-
grep ^MACADDR= /etc/sysconfig/network-scripts/ifcfg-{{ interface }}
@ -51,18 +48,15 @@
cloned_mac_address_nm.stdout.find(cloned_mac) != -1
msg: "cloned-mac-address is configured incorrectly"
- name: Import the playbook 'down_profile+delete_interface.yml'
import_playbook: down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
- name: Include the tasks 'down_profile+delete_interface.yml'
include_tasks: tasks/down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
- name: Import the playbook 'remove_profile.yml'
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'remove_profile.yml'
include_tasks: tasks/remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Verify that cleanup restored state to default
hosts: all
tasks:
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -5,24 +5,20 @@
vars:
type: veth
interface: ethtest0
tasks:
- name: "Set type={{ type }} and interface={{ interface }}" # noqa name
set_fact:
type: "{{ type }}"
interface: "{{ interface }}"
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
- name: Import network role
import_role:
- name: Include network role
include_role:
name: linux-system-roles.network
vars:
network_connections:
@ -120,24 +116,24 @@
- "'9999' in ipv6_dns.stdout"
msg: "DNS priority is configured incorrectly"
- name: Import the playbook 'down_profile+delete_interface.yml'
import_playbook: down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Import the playbook 'remove_profile.yml'
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Assert profile and device are absent
hosts: all
tasks:
- name: Include the tasks 'down_profile+delete_interface.yml'
include_tasks: tasks/down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Include the task 'remove_profile.yml'
include_tasks: tasks/remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_profile_absent.yml'
include_tasks: tasks/assert_profile_absent.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -1,81 +1,69 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Play for showing the network provider
hosts: all
tasks:
- name: Show inside ethernet tests
debug:
msg: Inside ethernet tests
- name: Show network_provider
debug:
var: network_provider
- name: Test configuring ethernet devices
hosts: all
vars:
type: veth
interface: lsr27
tasks:
- name: "Set type={{ type }} and interface={{ interface }}" # noqa name
set_fact:
type: "{{ type }}"
interface: "{{ interface }}"
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
- name: Show inside ethernet tests
debug:
msg: Inside ethernet tests
- name: Test static interface up
hosts: all
vars:
network_connections:
- name: "{{ interface }}"
interface_name: "{{ interface }}"
state: up
type: ethernet
autoconnect: true
ip:
address: 192.0.2.1/24
roles:
- linux-system-roles.network
tasks:
- name: Include the task 'assert_output_in_stderr_without_warnings.yml'
include_tasks: tasks/assert_output_in_stderr_without_warnings.yml
- name: Play for cleaning up the test device and the connection profile
hosts: all
tasks:
- name: Show network_provider
debug:
var: network_provider
# FIXME: assert profile present
# FIXME: assert profile/device up + IP address
- name: Import the playbook 'down_profile+delete_interface.yml'
import_playbook: down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Import the playbook 'remove_profile.yml'
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Assert device and profile are absent
hosts: all
tasks:
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
- name: Test static interface up
include_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
interface_name: "{{ interface }}"
state: up
type: ethernet
autoconnect: true
ip:
address: 192.0.2.1/24
- name: Include the task 'assert_output_in_stderr_without_warnings.yml'
include_tasks: tasks/assert_output_in_stderr_without_warnings.yml
- name: Show network_provider after running role
debug:
var: network_provider
# FIXME: assert profile present
# FIXME: assert profile/device up + IP address
- name: Include the tasks 'down_profile+delete_interface.yml'
include_tasks: tasks/down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Include the task 'remove_profile.yml'
include_tasks: tasks/remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_profile_absent.yml'
include_tasks: tasks/assert_profile_absent.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify that cleanup restored state to default
hosts: all
tasks:
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -5,18 +5,15 @@
vars:
type: veth
interface: ethtest0
tasks:
- name: "Set type={{ type }} and interface={{ interface }}" # noqa name
set_fact:
type: "{{ type }}"
interface: "{{ interface }}"
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
@ -24,31 +21,28 @@
set_fact:
connection_failed: false
- name: Import network role
import_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
interface_name: "{{ interface }}"
type: ethernet
ip:
ipv6_disabled: true
__header: "# Ansible managed test header"
ignore_errors: true # noqa ignore-errors
changed_when: false
- name: Try configuration
block:
- name: Include network role
include_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
interface_name: "{{ interface }}"
type: ethernet
ip:
ipv6_disabled: true
__header: "# Ansible managed test header"
- name: Assert that configuring `ipv6_disabled` will only fail when the
running version of NetworKManager does not support it
assert:
that:
- __network_connections_result.stderr is
search("ip.ipv6_disabled is not supported by the running version
of NetworkManager")
msg: Reconfiguring network connection is not failed with the error
"ip.ipv6_disabled is not supported by the running version of
NetworkManger"
when: __network_connections_result.failed
rescue:
- name: Assert that configuring `ipv6_disabled` will only fail when the
running version of NetworkManager does not support it
assert:
that: ansible_failed_result.stderr is search(errmsg)
msg: Reconfiguring network connection is not failed with the error {{ errmsg }}
vars:
errmsg: ip.ipv6_disabled is not supported by the running version of NetworkManager
- name: Verify nmcli connection ipv6.method
shell: |
@ -71,28 +65,28 @@
connection_failed: true
when: __network_connections_result.failed
- name: Import the playbook 'down_profile.yml'
import_playbook: down_profile.yml
vars:
profile: "{{ interface }}"
when: not connection_failed
- name: Include the task 'down_profile.yml'
include_tasks: tasks/down_profile.yml
vars:
profile: "{{ interface }}"
when: not connection_failed
# FIXME: assert profile/device down
- name: Include the tasks 'remove_profile.yml'
include_tasks: tasks/remove_profile.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Import the playbook 'remove_profile.yml'
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Delete the interface, then assert that device and profile are absent
hosts: all
tasks:
- name: Include the task 'delete_interface.yml'
include_tasks: tasks/delete_interface.yml
- name: Include the task 'assert_profile_absent.yml'
include_tasks: tasks/assert_profile_absent.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -25,13 +25,13 @@
set_fact:
type: "{{ type }}"
interface: "{{ interface1 }}"
- name: Include the task 'show_interfaces.yml'
- name: Include the task 'show_interfaces.yml' again
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
- name: Include the task 'manage_test_interface.yml' after changing interface
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
- name: Include the task 'assert_device_present.yml' after changing interface
include_tasks: tasks/assert_device_present.yml
@ -189,9 +189,9 @@
set_fact:
type: "{{ type }}"
interface: "{{ interface0 }}"
- name: Include the task 'delete_interface.yml'
- name: Include the task 'delete_interface.yml' again
include_tasks: tasks/delete_interface.yml
- name: Include the task 'assert_device_absent.yml'
- name: Include the task 'assert_device_absent.yml' again
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -23,13 +23,13 @@
- name: Set interface1
set_fact:
interface: "{{ interface1 }}"
- name: Show interfaces
- name: Show interfaces again
include_tasks: tasks/show_interfaces.yml
- name: Manage test interface
- name: Manage test interface with second interface
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Assert device is 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

View file

@ -5,25 +5,21 @@
vars:
type: veth
interface: ethtest0
tasks:
- name: "Set type={{ type }} and interface={{ interface }}" # noqa name
set_fact:
type: "{{ type }}"
interface: "{{ interface }}"
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
- name: Configure connection profile and specify the numeric table in
static routes
import_role:
include_role:
name: linux-system-roles.network
vars:
network_connections:
@ -77,7 +73,6 @@
msg: "the route table 30200 does not exist or does not contain the
specified route"
- name: Assert that the route table 30400 contains the specified route
assert:
that:
@ -96,7 +91,7 @@
- name: Reconfigure connection profile and specify the named table in
static routes
import_role:
include_role:
name: linux-system-roles.network
vars:
network_connections:
@ -152,24 +147,24 @@
state: absent
path: /etc/iproute2/rt_tables.d/table.conf
- name: Import the playbook 'down_profile+delete_interface.yml'
import_playbook: down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Import the playbook 'remove_profile.yml'
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Assert device and profile are absent
hosts: all
tasks:
- name: Include the tasks 'down_profile+delete_interface.yml'
include_tasks: tasks/down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Include the task 'remove_profile.yml'
include_tasks: tasks/remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_profile_absent.yml'
include_tasks: tasks/assert_profile_absent.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -6,22 +6,20 @@
type: veth
interface: ethtest0
tasks:
- name: "Set type={{ type }} and interface={{ interface }}" # noqa name
set_fact:
type: "{{ type }}"
interface: "{{ interface }}"
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
- name: Configure connection profile and specify the route types in
static routes
import_role:
include_role:
name: linux-system-roles.network
vars:
network_connections:
@ -102,7 +100,7 @@
specified route"
- name: Removing some routes
import_role:
include_role:
name: linux-system-roles.network
vars:
network_connections:
@ -173,24 +171,24 @@
msg: "the route table 30600 does not exist or does not contain the
type routes"
- name: Import the playbook 'down_profile+delete_interface.yml'
import_playbook: down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Import the playbook 'remove_profile.yml'
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Assert device and profile are absent
hosts: all
tasks:
- name: Include the tasks 'down_profile+delete_interface.yml'
include_tasks: tasks/down_profile+delete_interface.yml
vars:
profile: "{{ interface }}"
# FIXME: assert profile/device down
- name: Include the task 'remove_profile.yml'
include_tasks: tasks/remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_profile_absent.yml'
include_tasks: tasks/assert_profile_absent.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -5,18 +5,15 @@
vars:
type: veth
interface: ethtest0
tasks:
- name: "Set type={{ type }} and interface={{ interface }}" # noqa name
set_fact:
type: "{{ type }}"
interface: "{{ interface }}"
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
@ -36,7 +33,7 @@
block:
- name: Configure connection profile and specify the numeric table in
static routes
import_role:
include_role:
name: linux-system-roles.network
vars:
network_connections:
@ -311,26 +308,27 @@
msg: "the specified IPv6 routing rule was not configured in the
connection '{{ interface }}'"
- name: Remove profile and device, assert device and profile are absent
hosts: all
tasks:
- name: Remove the dedicated test file in `/etc/iproute2/rt_tables.d/`
file:
state: absent
path: /etc/iproute2/rt_tables.d/table.conf
- name: Include the task 'remove+down_profile.yml'
include_tasks: tasks/remove+down_profile.yml
vars:
profile: "{{ interface }}"
when: not __network_end_play | d(false)
- name: Include the task 'delete_interface.yml'
include_tasks: tasks/delete_interface.yml
- name: Include the task 'assert_profile_absent.yml'
include_tasks: tasks/assert_profile_absent.yml
vars:
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -14,7 +14,6 @@
tags:
- always
- name: Test creating the bridge connection
tags:
- tests::states:create

View file

@ -4,13 +4,10 @@
# set network provider and gather facts
- name: Switch initscripts provider to nm
hosts: all
vars:
network_provider: initscripts
interface: LST-TST-br34
tasks:
- name: Set fact to use initscripts network_provider
set_fact:
network_provider: initscripts
interface: LST-TST-br34
tags:
- always
- name: "Through the initscripts provider, create test bridge
{{ interface }}"
include_role:
@ -23,20 +20,25 @@
ip:
dhcp4: false
auto6: false
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
- name: Include the task 'remove+down_profile.yml'
include_tasks: tasks/remove+down_profile.yml
vars:
profile: "{{ interface }}"
# The initscripts should not remove the interface for down/absent
- name: Include the task 'assert_device_present.yml'
- name: Include the task 'assert_device_present.yml' with new profile
include_tasks: tasks/assert_device_present.yml
- name: Set fact to use nm network_provider
set_fact:
network_provider: nm
tags:
- always
- name: "Through the nm provider, create test bridge {{ interface }}"
include_role:
name: linux-system-roles.network
@ -48,18 +50,24 @@
ip:
dhcp4: false
auto6: false
- name: Include the task 'assert_device_present.yml'
- name: Include the task 'assert_device_present.yml' with nm provider
include_tasks: tasks/assert_device_present.yml
- name: Include the task 'remove+down_profile.yml'
- name: Include the task 'remove+down_profile.yml' with nm provider
include_tasks: tasks/remove+down_profile.yml
vars:
profile: "{{ interface }}"
# NetworkManager should not remove pre-exist interface for down/absent
- name: Include the task 'assert_device_present.yml'
- name: Include the task 'assert_device_present.yml' with nm provider again
include_tasks: tasks/assert_device_present.yml
- name: Include the task 'delete_interface.yml'
include_tasks: tasks/delete_interface.yml
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -55,7 +55,7 @@
- tasks/cleanup_profile+device.yml
- tasks/check_network_dns.yml
- name: "Get the rpm package facts"
- name: "Get the rpm package facts again"
package_facts:
manager: "auto"

View file

@ -43,7 +43,7 @@
ip:
dhcp4: false
auto6: false
- name: Include the task 'assert_device_present.yml'
- name: Include the task 'assert_device_present.yml' after running role
include_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ vlan_interface }}"
@ -58,7 +58,7 @@
- name: "TEARDOWN: remove profiles."
debug:
msg: "##################################################"
- name: Import network role
- name: Import network role to remove interfaces
import_role:
name: linux-system-roles.network
vars:
@ -70,7 +70,7 @@
persistent_state: absent
state: down
ignore_errors: true # noqa ignore-errors
- name: Include the task 'manage_test_interface.yml'
- name: Include the task 'manage_test_interface.yml' to remove interfaces
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent

View file

@ -36,7 +36,7 @@
key_mgmt: "wpa-psk"
password: "p@55w0rD"
- name: "Get the rpm package facts"
- name: "Get the rpm package facts again"
package_facts:
manager: "auto"

View file

@ -1,10 +1,16 @@
# SPDX-License-Identifier: BSD-3-Clause
---
# module_warning - see https://github.com/ansible/ansible/issues/85394
- name: "Assert that warnings is empty"
assert:
that:
- "'warnings' not in __network_connections_result"
- "'warnings' not in __network_connections_result or
__network_connections_result.warnings | reject('match', module_warning ~ '$') | list | length == 0"
msg: "There are unexpected warnings"
vars:
module_warning: >-
Error loading plugin 'ansible.netcommon.network': No module named 'ansible_collections.ansible.netcommon'
- name: "Assert that there is output in stderr"
assert:
that:

View file

@ -0,0 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Include the task 'down_profile.yml'
include_tasks: down_profile.yml
- name: Include the task 'delete_interface.yml'
include_tasks: tasks/delete_interface.yml

View file

@ -1,10 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Set down {{ profile }}
hosts: all
include_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ profile }}"
state: down
roles:
- linux-system-roles.network

View file

@ -1,10 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Include network role
- name: Remove {{ profile }}
include_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
- name: "{{ profile }}"
persistent_state: absent
...

View file

@ -90,23 +90,23 @@
rescue:
- name: Show failed item
debug:
var: "{{ item }}"
with_items:
- ansible_failed_result
- ansible_failed_task
- __network_nm_nvr.stdout
- __NM_capath_ignored_NVRs
msg: item {{ item }}
loop:
- "{{ ansible_failed_result }}"
- "{{ ansible_failed_task }}"
- "{{ __network_nm_nvr.stdout }}"
- "{{ __NM_capath_ignored_NVRs }}"
changed_when: false
- name: Assert role behavior
vars:
expected_failure: __network_nm_nvr.stdout in __NM_capath_ignored_NVRs
failure: __network_connections_result.failed
expected_failure: "{{ __network_nm_nvr.stdout in __NM_capath_ignored_NVRs }}"
failure: "{{ __network_connections_result is failed }}"
assert:
that: (failure and expected_failure) or
(not failure and not expected_failure)
msg: "Role {{ failure and 'failed' or 'did not fail' }} but was expected
{{ expected_failure and '' or 'not' }} to fail.
msg: "Role {{ failure | ternary('failed', 'did not fail') }} but was expected
{{ expected_failure | ternary('', 'not') }} to fail.
NM NVR: {{ __network_nm_nvr.stdout }}"
- name: Assert role failure
assert:

View file

@ -8,8 +8,14 @@
tasks:
- name: Include the task 'el_repo_setup.yml'
include_tasks: tasks/el_repo_setup.yml
# module_warning - see https://github.com/ansible/ansible/issues/85394
- name: Test warning and info logs
assert:
that:
- "'warnings' not in __network_connections_result"
- "'warnings' not in __network_connections_result or
__network_connections_result.warnings | reject('match', module_warning ~ '$') | list | length == 0"
msg: "There are warnings"
vars:
module_warning: >-
Error loading plugin 'ansible.netcommon.network': No module named 'ansible_collections.ansible.netcommon'

View file

@ -12,7 +12,7 @@
type: veth
interface: veth1298
- name: Test veth interface management
- name: Test veth interface management with dummy interface
include_tasks: tasks/create_and_remove_interface.yml
vars:
type: dummy