Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 67 additions & 46 deletions tests/ensure_provider_tests.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
"""Check that there is a playbook to run all role tests with both providers"""

# vim: fileencoding=utf8

import difflib
import glob
import os
import sys


GET_NM_VERSION = """
- name: Install NetworkManager and get NetworkManager version
when:
- ansible_facts['distribution_major_version'] != '6'
- __network_distro_major_version != '6'
tags:
- always
block:
Expand All @@ -30,8 +30,7 @@
ansible_facts.packages['NetworkManager'][0]['version'] }}"
"""

MINIMUM_NM_VERSION_CHECK = """
- networkmanager_version is version({minimum_nm_version}, '>=')
MINIMUM_NM_VERSION_CHECK = """ - networkmanager_version is version({minimum_nm_version}, '>=')
"""

EXTRA_RUN_CONDITION_PREFIX = " - "
Expand All @@ -51,31 +50,74 @@
network_provider: nm
tags:
- always
- name: Include distro variables
include_vars: vars/rh_distros_vars.yml
- name: Set platform facts
set_fact:
__network_distro_major_version: "{{{{ ansible_facts['distribution_major_version'] }}}}"
__network_is_rhel: "{{{{ ansible_facts['distribution'] == 'RedHat' }}}}"
__network_is_fedora: "{{{{ ansible_facts['distribution'] == 'Fedora' }}}}"
__network_is_centos: "{{{{ ansible_facts['distribution'] == 'CentOS' }}}}"
__network_is_os_family_rhel: "{{{{ ansible_facts['os_family'] == 'RedHat' }}}}"
__is_rh_distro: "{{{{ __network_is_rh_distro }}}}"
{get_nm_version}

# The test requires or should run with NetworkManager, therefore it cannot run
# on RHEL/CentOS 6
{comment}- name: Import the playbook '{test_playbook}'
import_playbook: {test_playbook}
when:
- ansible_facts['distribution_major_version'] != '6'
- __network_distro_major_version != '6'
{minimum_nm_version_check}{extra_run_condition}"""


RUN_PLAYBOOK_WITH_INITSCRIPTS = """# SPDX-License-Identifier: BSD-3-Clause
# This file was generated by ensure_provider_tests.py
---
# yamllint disable rule:line-length
- name: Run playbook '{test_playbook}' with initscripts as provider
hosts: all
tasks:
- name: Include the task 'el_repo_setup.yml'
include_tasks: tasks/el_repo_setup.yml
- name: Set network provider to 'initscripts'
set_fact:
network_provider: initscripts
tags:
- always
- name: Include distro variables
include_vars: vars/rh_distros_vars.yml
- name: Set platform facts
set_fact:
__network_distro_major_version: "{{{{ ansible_facts['distribution_major_version'] }}}}"
__network_is_rhel: "{{{{ ansible_facts['distribution'] == 'RedHat' }}}}"
__network_is_fedora: "{{{{ ansible_facts['distribution'] == 'Fedora' }}}}"
__network_is_centos: "{{{{ ansible_facts['distribution'] == 'CentOS' }}}}"
__network_is_os_family_rhel: "{{{{ ansible_facts['os_family'] == 'RedHat' }}}}"
__is_rh_distro: "{{{{ __network_is_rh_distro }}}}"
- name: Import the playbook '{test_playbook}'
import_playbook: {test_playbook}
when:
- __is_rh_distro
- __network_distro_major_version | int < 9
"""


MINIMUM_VERSION = "minimum_version"
EXTRA_RUN_CONDITION = "extra_run_condition"
NM_ONLY_TESTS = {
"playbooks/tests_802_1x_updated.yml": {
EXTRA_RUN_CONDITION: (
"(ansible_facts['distribution'] != 'RedHat' and\n"
" ansible_facts['distribution_major_version'] | int > 7) or\n"
" ansible_facts['distribution_major_version'] | int == 8"
"(not __network_is_rhel and\n"
" __network_distro_major_version | int > 7) or\n"
" __network_distro_major_version | int == 8"
),
},
"playbooks/tests_802_1x.yml": {
EXTRA_RUN_CONDITION: (
"(ansible_facts['distribution'] != 'RedHat' and\n"
" ansible_facts['distribution_major_version'] | int > 7) or\n"
" ansible_facts['distribution_major_version'] | int == 8"
"(not __network_is_rhel and\n"
" __network_distro_major_version | int > 7) or\n"
" __network_distro_major_version | int == 8"
),
},
"playbooks/tests_ignore_auto_dns.yml": {},
Expand All @@ -92,20 +134,20 @@
},
"playbooks/tests_provider.yml": {
MINIMUM_VERSION: "'1.20.0'",
"comment": "# NetworKmanager 1.20.0 added support for forgetting profiles",
"comment": "# NetworkManager 1.20.0 added support for forgetting profiles",
EXTRA_RUN_CONDITION: (
"(ansible_facts['distribution'] == 'Fedora'\n"
" and ansible_facts['distribution_major_version'] | int < 41)\n"
" or ansible_facts['distribution'] not in ['RedHat', 'CentOS', 'Fedora']\n"
" or ansible_facts['distribution_major_version'] | int < 9"
"(__network_is_fedora and\n"
" __network_distro_major_version | int < 41)\n"
" or not __network_is_os_family_rhel\n"
" or __network_distro_major_version | int < 9"
),
},
"playbooks/tests_eth_pci_address_match.yml": {
MINIMUM_VERSION: "'1.26.0'",
"comment": "# NetworkManager 1.26.0 added support for match.path setting",
},
"playbooks/tests_network_state.yml": {
EXTRA_RUN_CONDITION: "ansible_facts['distribution_major_version'] | int > 7",
EXTRA_RUN_CONDITION: "__network_distro_major_version | int > 7",
},
"playbooks/tests_reapply.yml": {},
"playbooks/tests_route_table.yml": {},
Expand All @@ -117,30 +159,30 @@
"playbooks/tests_routing_rules.yml": {},
# teaming support dropped in EL10
"playbooks/tests_team.yml": {
EXTRA_RUN_CONDITION: "ansible_facts['distribution'] not in ['RedHat', 'CentOS'] or\n ansible_facts['distribution_major_version'] | int < 10",
EXTRA_RUN_CONDITION: "not __is_rh_distro or\n __network_distro_major_version | int < 10",
},
"playbooks/tests_team_plugin_installation.yml": {
EXTRA_RUN_CONDITION: "ansible_facts['distribution'] not in ['RedHat', 'CentOS'] or\n ansible_facts['distribution_major_version'] | int < 10",
EXTRA_RUN_CONDITION: "not __is_rh_distro or\n __network_distro_major_version | int < 10",
},
# mac80211_hwsim (used for tests_wireless) only seems to be available
# and working on RHEL/CentOS 7
"playbooks/tests_wireless.yml": {
EXTRA_RUN_CONDITION: "ansible_facts['distribution_major_version'] == '7'",
EXTRA_RUN_CONDITION: "__network_distro_major_version == '7'",
},
"playbooks/tests_wireless_and_network_restart.yml": {},
"playbooks/tests_wireless_plugin_installation.yml": {},
"playbooks/tests_wireless_wpa3_owe.yml": {
"comment": "# OWE has not been supported by NetworkManager 1.18.8 on \
RHEL 7(dist-tag). Failed in setting up mock wifi on RHEL 8",
EXTRA_RUN_CONDITION: "ansible_facts['distribution_major_version'] > '7' and \
ansible_facts['distribution'] == 'CentOS' or\n ansible_facts['distribution_major_version'] > '32' \
and ansible_facts['distribution'] == 'Fedora'",
EXTRA_RUN_CONDITION: "__network_distro_major_version | int > 7 and \
__network_is_centos or\n __network_distro_major_version | int > 32 \
and __network_is_fedora",
},
"playbooks/tests_wireless_wpa3_sae.yml": {
"comment": "# SAE has not been supported by NetworkManager 1.18.8 on \
RHEL 7. Failed in setting up mock wifi on RHEL 8",
EXTRA_RUN_CONDITION: "ansible_facts['distribution_major_version'] != '7' and \
ansible_facts['distribution'] != 'RedHat'",
EXTRA_RUN_CONDITION: "__network_distro_major_version != '7' and \
not __network_is_rhel",
},
}
# NM_CONDITIONAL_TESTS is used to store the test playbooks which are demanding for NM
Expand Down Expand Up @@ -168,27 +210,6 @@
"playbooks/tests_switch_provider.yml",
]

RUN_PLAYBOOK_WITH_INITSCRIPTS = """# SPDX-License-Identifier: BSD-3-Clause
# This file was generated by ensure_provider_tests.py
---
# yamllint disable rule:line-length
- name: Run playbook '{test_playbook}' with initscripts as provider
hosts: all
tasks:
- name: Include the task 'el_repo_setup.yml'
include_tasks: tasks/el_repo_setup.yml
- name: Set network provider to 'initscripts'
set_fact:
network_provider: initscripts
tags:
- always

- name: Import the playbook '{test_playbook}'
import_playbook: {test_playbook}
when: (ansible_facts['distribution'] in ['CentOS','RedHat'] and\n \
ansible_facts['distribution_major_version'] | int < 9)
"""


def create_nm_playbook(test_playbook):
fileroot = os.path.splitext(os.path.basename(test_playbook))[0]
Expand Down
1 change: 1 addition & 0 deletions tests/library/network_connections.py
14 changes: 5 additions & 9 deletions tests/playbooks/manual_test_ethtool_coalesce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
register: original_ethtool_coalesce
changed_when: false
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand All @@ -57,8 +56,7 @@
debug:
msg: "##################################################"
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand Down Expand Up @@ -91,8 +89,7 @@
debug:
msg: "##################################################"
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand All @@ -118,14 +115,13 @@
- "tests::cleanup"
block:
- name: Deactivate the connection and remove the connection profile
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
persistent_state: absent
state: down
failed_when: false
__sr_failed_when: false
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
Expand Down
17 changes: 6 additions & 11 deletions tests/playbooks/tests_802_1x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
debug:
msg: "##################################################"
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand Down Expand Up @@ -48,8 +47,7 @@
command: ping -c1 203.0.113.1
changed_when: false
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand Down Expand Up @@ -79,8 +77,7 @@
executable: /bin/bash
changed_when: false
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand All @@ -105,8 +102,7 @@
command: ping -c1 203.0.113.1
changed_when: false
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand All @@ -121,8 +117,7 @@
- "tests::cleanup"
block:
- name: Deactivate the connection and remove the connection profile
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand All @@ -131,7 +126,7 @@
- name: br1
persistent_state: absent
state: down
failed_when: false
__sr_failed_when: false
- name: Include the task 'cleanup_802_1x_server.yml'
include_tasks: tasks/cleanup_802_1x_server.yml
- name: Remove test certificates
Expand Down
12 changes: 4 additions & 8 deletions tests/playbooks/tests_auto_gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
debug:
msg: "##################################################"
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand Down Expand Up @@ -68,8 +67,7 @@
debug:
msg: "##################################################"
- name: Import network role to remove interface
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand All @@ -89,8 +87,7 @@
vars:
state: present
- name: Import network role to disable auto_gateway
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand Down Expand Up @@ -134,8 +131,7 @@
debug:
msg: "##################################################"
- name: Import network role to remove interface again
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ interface }}"
Expand Down
8 changes: 3 additions & 5 deletions tests/playbooks/tests_bond.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
debug:
msg: "##################################################"
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
# Create a bond controller
Expand Down Expand Up @@ -98,8 +97,7 @@
- "tests::cleanup"
block:
- name: Import network role
import_role:
name: linux-system-roles.network
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
network_connections:
- name: "{{ port2_profile }}"
Expand All @@ -111,7 +109,7 @@
- name: "{{ controller_profile }}"
persistent_state: absent
state: down
failed_when: false
__sr_failed_when: false
- name: Delete the device '{{ controller_device }}'
command: ip link del {{ controller_device }}
failed_when: false
Expand Down
Loading
Loading