diff --git a/.sanity-ansible-ignore-2.18.txt b/.sanity-ansible-ignore-2.18.txt new file mode 100644 index 0000000..5eff638 --- /dev/null +++ b/.sanity-ansible-ignore-2.18.txt @@ -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 diff --git a/.sanity-ansible-ignore-2.19.txt b/.sanity-ansible-ignore-2.19.txt new file mode 100644 index 0000000..5eff638 --- /dev/null +++ b/.sanity-ansible-ignore-2.19.txt @@ -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 diff --git a/examples/down_profile.yml b/examples/down_profile.yml deleted file mode 120000 index fe44746..0000000 --- a/examples/down_profile.yml +++ /dev/null @@ -1 +0,0 @@ -../tests/playbooks/down_profile.yml \ No newline at end of file diff --git a/examples/network_state_example.yml b/examples/network_state_example.yml index 80d22a5..157f2d2 100644 --- a/examples/network_state_example.yml +++ b/examples/network_state_example.yml @@ -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: diff --git a/examples/remove+down_profile.yml b/examples/remove+down_profile.yml deleted file mode 100644 index 840c732..0000000 --- a/examples/remove+down_profile.yml +++ /dev/null @@ -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 diff --git a/examples/remove_profile.yml b/examples/remove_profile.yml deleted file mode 120000 index d9959bc..0000000 --- a/examples/remove_profile.yml +++ /dev/null @@ -1 +0,0 @@ -../tests/playbooks/remove_profile.yml \ No newline at end of file diff --git a/tests/get_coverage.yml b/tests/get_coverage.yml index 271b6b8..9bd8ee0 100644 --- a/tests/get_coverage.yml +++ b/tests/get_coverage.yml @@ -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 diff --git a/tests/playbooks/down_profile+delete_interface.yml b/tests/playbooks/down_profile+delete_interface.yml deleted file mode 100644 index 67c26dd..0000000 --- a/tests/playbooks/down_profile+delete_interface.yml +++ /dev/null @@ -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 diff --git a/tests/playbooks/remove_profile.yml b/tests/playbooks/remove_profile.yml deleted file mode 100644 index a50e848..0000000 --- a/tests/playbooks/remove_profile.yml +++ /dev/null @@ -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 diff --git a/tests/playbooks/tests_auto_gateway.yml b/tests/playbooks/tests_auto_gateway.yml index 18a9d1e..28f5952 100644 --- a/tests/playbooks/tests_auto_gateway.yml +++ b/tests/playbooks/tests_auto_gateway.yml @@ -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 diff --git a/tests/playbooks/tests_bridge.yml b/tests/playbooks/tests_bridge.yml index 880a074..09f4c8a 100644 --- a/tests/playbooks/tests_bridge.yml +++ b/tests/playbooks/tests_bridge.yml @@ -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 diff --git a/tests/playbooks/tests_bridge_cloned_mac.yml b/tests/playbooks/tests_bridge_cloned_mac.yml index b30a9ae..96ae931 100644 --- a/tests/playbooks/tests_bridge_cloned_mac.yml +++ b/tests/playbooks/tests_bridge_cloned_mac.yml @@ -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 diff --git a/tests/playbooks/tests_eth_dns_support.yml b/tests/playbooks/tests_eth_dns_support.yml index 044346f..5322370 100644 --- a/tests/playbooks/tests_eth_dns_support.yml +++ b/tests/playbooks/tests_eth_dns_support.yml @@ -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 -... diff --git a/tests/playbooks/tests_ethernet.yml b/tests/playbooks/tests_ethernet.yml index 2fdc547..372208f 100644 --- a/tests/playbooks/tests_ethernet.yml +++ b/tests/playbooks/tests_ethernet.yml @@ -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 diff --git a/tests/playbooks/tests_ipv6_disabled.yml b/tests/playbooks/tests_ipv6_disabled.yml index 2cbe43e..f8aea90 100644 --- a/tests/playbooks/tests_ipv6_disabled.yml +++ b/tests/playbooks/tests_ipv6_disabled.yml @@ -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 -... diff --git a/tests/playbooks/tests_network_state.yml b/tests/playbooks/tests_network_state.yml index 054933c..5e6260f 100644 --- a/tests/playbooks/tests_network_state.yml +++ b/tests/playbooks/tests_network_state.yml @@ -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 diff --git a/tests/playbooks/tests_route_device.yml b/tests/playbooks/tests_route_device.yml index 3feba4e..13a4d87 100644 --- a/tests/playbooks/tests_route_device.yml +++ b/tests/playbooks/tests_route_device.yml @@ -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 diff --git a/tests/playbooks/tests_route_table.yml b/tests/playbooks/tests_route_table.yml index ca5ce92..251e489 100644 --- a/tests/playbooks/tests_route_table.yml +++ b/tests/playbooks/tests_route_table.yml @@ -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 -... diff --git a/tests/playbooks/tests_route_type.yml b/tests/playbooks/tests_route_type.yml index 4394109..22c24fe 100644 --- a/tests/playbooks/tests_route_type.yml +++ b/tests/playbooks/tests_route_type.yml @@ -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 -... diff --git a/tests/playbooks/tests_routing_rules.yml b/tests/playbooks/tests_routing_rules.yml index 3527faf..1495bbd 100644 --- a/tests/playbooks/tests_routing_rules.yml +++ b/tests/playbooks/tests_routing_rules.yml @@ -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 -... diff --git a/tests/playbooks/tests_states.yml b/tests/playbooks/tests_states.yml index 451c5df..e9943dd 100644 --- a/tests/playbooks/tests_states.yml +++ b/tests/playbooks/tests_states.yml @@ -14,7 +14,6 @@ tags: - always - - name: Test creating the bridge connection tags: - tests::states:create diff --git a/tests/playbooks/tests_switch_provider.yml b/tests/playbooks/tests_switch_provider.yml index 006b945..9840411 100644 --- a/tests/playbooks/tests_switch_provider.yml +++ b/tests/playbooks/tests_switch_provider.yml @@ -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 diff --git a/tests/playbooks/tests_team_plugin_installation.yml b/tests/playbooks/tests_team_plugin_installation.yml index 7236b07..b9c9288 100644 --- a/tests/playbooks/tests_team_plugin_installation.yml +++ b/tests/playbooks/tests_team_plugin_installation.yml @@ -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" diff --git a/tests/playbooks/tests_vlan_mtu.yml b/tests/playbooks/tests_vlan_mtu.yml index 1e9824a..ade0aa7 100644 --- a/tests/playbooks/tests_vlan_mtu.yml +++ b/tests/playbooks/tests_vlan_mtu.yml @@ -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 diff --git a/tests/playbooks/tests_wireless_plugin_installation.yml b/tests/playbooks/tests_wireless_plugin_installation.yml index 47c1be1..bd8e4df 100644 --- a/tests/playbooks/tests_wireless_plugin_installation.yml +++ b/tests/playbooks/tests_wireless_plugin_installation.yml @@ -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" diff --git a/tests/tasks/assert_output_in_stderr_without_warnings.yml b/tests/tasks/assert_output_in_stderr_without_warnings.yml index d760d3d..94110ef 100644 --- a/tests/tasks/assert_output_in_stderr_without_warnings.yml +++ b/tests/tasks/assert_output_in_stderr_without_warnings.yml @@ -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: diff --git a/tests/tasks/down_profile+delete_interface.yml b/tests/tasks/down_profile+delete_interface.yml new file mode 100644 index 0000000..35520dd --- /dev/null +++ b/tests/tasks/down_profile+delete_interface.yml @@ -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 diff --git a/tests/playbooks/down_profile.yml b/tests/tasks/down_profile.yml similarity index 74% rename from tests/playbooks/down_profile.yml rename to tests/tasks/down_profile.yml index 3f18a40..25db269 100644 --- a/tests/playbooks/down_profile.yml +++ b/tests/tasks/down_profile.yml @@ -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 diff --git a/tests/tasks/remove_profile.yml b/tests/tasks/remove_profile.yml index 7378e86..1538e01 100644 --- a/tests/tasks/remove_profile.yml +++ b/tests/tasks/remove_profile.yml @@ -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 -... diff --git a/tests/tasks/test_802.1x_capath.yml b/tests/tasks/test_802.1x_capath.yml index de57765..4f6b8c5 100644 --- a/tests/tasks/test_802.1x_capath.yml +++ b/tests/tasks/test_802.1x_capath.yml @@ -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: diff --git a/tests/tests_default.yml b/tests/tests_default.yml index d722c24..6577a51 100644 --- a/tests/tests_default.yml +++ b/tests/tests_default.yml @@ -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' diff --git a/tests/tests_helpers_and_asserts.yml b/tests/tests_helpers_and_asserts.yml index 4d8aed6..adab888 100644 --- a/tests/tests_helpers_and_asserts.yml +++ b/tests/tests_helpers_and_asserts.yml @@ -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