From f813fb33b71748fa11805effaba959c897c98748 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Mon, 27 Sep 2021 07:05:06 -0400 Subject: [PATCH] fix ensure_provider_tests.py; fix generated tests; add check to CI Fix ensure_provider_tests.py so that the tests are correctly generated. Because the generated tests have not been checked in a while, there was some drift between the actual tests and what should have been generated, so the new generated tests have also been included. When `ensure_provider_tests.py` detects differences, it will now show the diffs using a unified diff format. Added a new tox testenv `ensure_provider_tests` - use `tox -e ensure_provider_tests` to run - to pass arguments, use `tox -e ensure_provider_tests -- generate` Added `ensure_provider_tests` as one of the tox testenvs to run for github tox CI. Signed-off-by: Rich Megginson --- .github/workflows/tox.yml | 2 +- .sanity-ansible-ignore-2.11.txt | 2 ++ .sanity-ansible-ignore-2.9.txt | 2 ++ .travis/custom.sh | 13 ----------- tests/ensure_provider_tests.py | 16 ++++++++++++++ tests/git-post-commit.sh | 22 +++++++++++++++++++ tests/git-pre-commit.sh | 13 +++++++++++ tests/tests_auto_gateway_nm.yml | 1 + tests/tests_bond_deprecated_nm.yml | 1 + tests/tests_dummy_nm.yml | 1 + tests/tests_eth_dns_support_nm.yml | 1 + tests/tests_eth_pci_address_match_nm.yml | 1 + tests/tests_ethernet_nm.yml | 1 - tests/tests_ethtool_coalesce_nm.yml | 1 + tests/tests_ethtool_features_nm.yml | 1 + tests/tests_ethtool_ring_nm.yml | 2 ++ tests/tests_ipv6_disabled_nm.yml | 1 + tests/tests_ipv6_nm.yml | 1 + tests/tests_provider_nm.yml | 1 + tests/tests_reapply_nm.yml | 1 - tests/tests_states_nm.yml | 1 - tests/tests_team_nm.yml | 1 - tests/tests_team_plugin_installation_nm.yml | 1 + tests/tests_vlan_mtu_nm.yml | 1 - tests/tests_wireless_nm.yml | 1 - .../tests_wireless_plugin_installation_nm.yml | 1 + tests/tests_wireless_wpa3_owe_nm.yml | 1 + tests/tests_wireless_wpa3_sae_nm.yml | 3 ++- tox.ini | 6 +++++ 29 files changed, 79 insertions(+), 21 deletions(-) delete mode 100755 .travis/custom.sh create mode 100755 tests/git-post-commit.sh create mode 100755 tests/git-pre-commit.sh diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index d72afe7..6be5605 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -38,7 +38,7 @@ jobs: toxenvs="py${toxpyver}" case "$toxpyver" in 27) toxenvs="${toxenvs},coveralls,flake8,pylint" ;; - 36) toxenvs="${toxenvs},coveralls,black,yamllint,ansible-lint,collection,ansible-test" ;; + 36) toxenvs="${toxenvs},coveralls,ensure_provider_tests,black,yamllint,ansible-lint,collection,ansible-test" ;; 37) toxenvs="${toxenvs},coveralls" ;; 38) toxenvs="${toxenvs},coveralls" ;; esac diff --git a/.sanity-ansible-ignore-2.11.txt b/.sanity-ansible-ignore-2.11.txt index 9a89e03..44fa888 100644 --- a/.sanity-ansible-ignore-2.11.txt +++ b/.sanity-ansible-ignore-2.11.txt @@ -59,6 +59,8 @@ tests/network/ensure_provider_tests.py metaclass-boilerplate!skip tests/network/ensure_provider_tests.py shebang!skip tests/network/get_coverage.sh shebang!skip tests/network/get_total_coverage.sh shebang!skip +tests/network/git-pre-commit.sh shebang!skip +tests/network/git-post-commit.sh shebang!skip tests/network/integration/conftest.py future-import-boilerplate!skip tests/network/integration/conftest.py metaclass-boilerplate!skip tests/network/integration/test_ethernet.py future-import-boilerplate!skip diff --git a/.sanity-ansible-ignore-2.9.txt b/.sanity-ansible-ignore-2.9.txt index 80b2c52..5333899 100644 --- a/.sanity-ansible-ignore-2.9.txt +++ b/.sanity-ansible-ignore-2.9.txt @@ -37,6 +37,8 @@ tests/network/ensure_provider_tests.py metaclass-boilerplate!skip tests/network/ensure_provider_tests.py shebang!skip tests/network/get_coverage.sh shebang!skip tests/network/get_total_coverage.sh shebang!skip +tests/network/git-pre-commit.sh shebang!skip +tests/network/git-post-commit.sh shebang!skip tests/network/integration/conftest.py future-import-boilerplate!skip tests/network/integration/conftest.py metaclass-boilerplate!skip tests/network/integration/test_ethernet.py future-import-boilerplate!skip diff --git a/.travis/custom.sh b/.travis/custom.sh deleted file mode 100755 index 210630d..0000000 --- a/.travis/custom.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: MIT - -set -e - -# https://github.com/koalaman/shellcheck/wiki/SC1091 -# shellcheck disable=SC1091 -. "$LSR_SCRIPTDIR/utils.sh" - -# Write your custom commands here that should be run when `tox -e custom`: -if lsr_check_python_version python -eq '3.6'; then - (set -x; cd "${TOPDIR}/tests"; python ./ensure_provider_tests.py) -fi diff --git a/tests/ensure_provider_tests.py b/tests/ensure_provider_tests.py index 65e7c62..c060de5 100755 --- a/tests/ensure_provider_tests.py +++ b/tests/ensure_provider_tests.py @@ -4,6 +4,7 @@ """ # vim: fileencoding=utf8 +import difflib import glob import os import sys @@ -40,6 +41,7 @@ RUN_PLAYBOOK_WITH_NM = """# SPDX-License-Identifier: BSD-3-Clause - hosts: all name: Run playbook '{test_playbook}' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm @@ -118,8 +120,13 @@ NM_CONDITIONAL_TESTS = { MINIMUM_VERSION: "'1.20.0'", "comment": "# NetworkManager 1.20.0 introduced ethtool settings support", }, + "playbooks/tests_ethtool_ring.yml": { + MINIMUM_VERSION: "'1.25.2'", + "comment": "# NetworkManager 1.25.2 introduced ethtool ring support", + }, } + IGNORE = [ # checked by tests_regression_nm.yml "playbooks/tests_checkpoint_cleanup.yml", @@ -207,6 +214,15 @@ def check_playbook(generate, testfile, test_playbook, nominal_data): testdata = ifile.read() if testdata != nominal_data: print(f"ERROR: Playbook does not match nominal value: {testfile}") + sys.stdout.writelines( + difflib.unified_diff( + nominal_data.splitlines(keepends=True), + testdata.splitlines(keepends=True), + fromfile=f"{testfile}.expected", + tofile=f"{testfile}.actual", + ) + ) + returncode = 1 return is_missing, returncode diff --git a/tests/git-post-commit.sh b/tests/git-post-commit.sh new file mode 100755 index 0000000..567d79c --- /dev/null +++ b/tests/git-post-commit.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause + +set -euo pipefail + +# Run script ensure_provider_tests.py and append test files generated by it to the commit. + +# This script is intended to be used as git post-commit hook. +# Make sure file is executable and copy it to /.git/hooks/post-commit +# This script has to be used together with pre-commit to work properly. + +GITPATH=$(git rev-parse --show-toplevel) + +if [ -e "$GITPATH/.commit" ]; then + rm "$GITPATH/.commit" + + cd "$GITPATH/tests" + python ./ensure_provider_tests.py generate + cd "$GITPATH" + git add tests/tests_*_nm.yml tests/tests_*_initscripts.yml + git commit --amend -C HEAD --no-verify +fi diff --git a/tests/git-pre-commit.sh b/tests/git-pre-commit.sh new file mode 100755 index 0000000..febc929 --- /dev/null +++ b/tests/git-pre-commit.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause + +set -euo pipefail + +# This script is intended to be used as git pre-commit hook. +# Make sure file is executable and copy it into /.git/hooks/pre-commit +# This script has to be used together with post-commit to work properly. + +GITPATH=$(git rev-parse --show-toplevel) + +touch "$GITPATH/.commit" + diff --git a/tests/tests_auto_gateway_nm.yml b/tests/tests_auto_gateway_nm.yml index f55f18f..a536255 100644 --- a/tests/tests_auto_gateway_nm.yml +++ b/tests/tests_auto_gateway_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_auto_gateway.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_bond_deprecated_nm.yml b/tests/tests_bond_deprecated_nm.yml index 5a910a2..5f5fd04 100644 --- a/tests/tests_bond_deprecated_nm.yml +++ b/tests/tests_bond_deprecated_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_bond_deprecated.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_dummy_nm.yml b/tests/tests_dummy_nm.yml index 63bb99b..2c6d6a1 100644 --- a/tests/tests_dummy_nm.yml +++ b/tests/tests_dummy_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_dummy.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_eth_dns_support_nm.yml b/tests/tests_eth_dns_support_nm.yml index b35284c..c982631 100644 --- a/tests/tests_eth_dns_support_nm.yml +++ b/tests/tests_eth_dns_support_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_eth_dns_support.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_eth_pci_address_match_nm.yml b/tests/tests_eth_pci_address_match_nm.yml index 3df788a..6837d71 100644 --- a/tests/tests_eth_pci_address_match_nm.yml +++ b/tests/tests_eth_pci_address_match_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_eth_pci_address_match.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_ethernet_nm.yml b/tests/tests_ethernet_nm.yml index 238172d..483e05a 100644 --- a/tests/tests_ethernet_nm.yml +++ b/tests/tests_ethernet_nm.yml @@ -6,7 +6,6 @@ name: Run playbook 'playbooks/tests_ethernet.yml' with nm as provider tasks: - include_tasks: tasks/el_repo_setup.yml - - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_ethtool_coalesce_nm.yml b/tests/tests_ethtool_coalesce_nm.yml index d2ca5ab..a42f0dc 100644 --- a/tests/tests_ethtool_coalesce_nm.yml +++ b/tests/tests_ethtool_coalesce_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_ethtool_coalesce.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_ethtool_features_nm.yml b/tests/tests_ethtool_features_nm.yml index e3354d5..8d1fc99 100644 --- a/tests/tests_ethtool_features_nm.yml +++ b/tests/tests_ethtool_features_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_ethtool_features.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_ethtool_ring_nm.yml b/tests/tests_ethtool_ring_nm.yml index 0a7ba83..950ecd8 100644 --- a/tests/tests_ethtool_ring_nm.yml +++ b/tests/tests_ethtool_ring_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_ethtool_ring.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm @@ -30,6 +31,7 @@ # The test requires or should run with NetworkManager, therefore it cannot run # on RHEL/CentOS 6 +# NetworkManager 1.25.2 introduced ethtool ring support - import_playbook: playbooks/tests_ethtool_ring.yml when: - ansible_distribution_major_version != '6' diff --git a/tests/tests_ipv6_disabled_nm.yml b/tests/tests_ipv6_disabled_nm.yml index 24ee62d..388b880 100644 --- a/tests/tests_ipv6_disabled_nm.yml +++ b/tests/tests_ipv6_disabled_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_ipv6_disabled.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_ipv6_nm.yml b/tests/tests_ipv6_nm.yml index f186912..c55eb36 100644 --- a/tests/tests_ipv6_nm.yml +++ b/tests/tests_ipv6_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_ipv6.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_provider_nm.yml b/tests/tests_provider_nm.yml index 5d85231..07d283a 100644 --- a/tests/tests_provider_nm.yml +++ b/tests/tests_provider_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_provider.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_reapply_nm.yml b/tests/tests_reapply_nm.yml index eb48ddb..dfcbce2 100644 --- a/tests/tests_reapply_nm.yml +++ b/tests/tests_reapply_nm.yml @@ -6,7 +6,6 @@ name: Run playbook 'playbooks/tests_reapply.yml' with nm as provider tasks: - include_tasks: tasks/el_repo_setup.yml - - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_states_nm.yml b/tests/tests_states_nm.yml index 34c8a24..a2bd548 100644 --- a/tests/tests_states_nm.yml +++ b/tests/tests_states_nm.yml @@ -6,7 +6,6 @@ name: Run playbook 'playbooks/tests_states.yml' with nm as provider tasks: - include_tasks: tasks/el_repo_setup.yml - - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_team_nm.yml b/tests/tests_team_nm.yml index 8048029..84db32d 100644 --- a/tests/tests_team_nm.yml +++ b/tests/tests_team_nm.yml @@ -6,7 +6,6 @@ name: Run playbook 'playbooks/tests_team.yml' with nm as provider tasks: - include_tasks: tasks/el_repo_setup.yml - - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_team_plugin_installation_nm.yml b/tests/tests_team_plugin_installation_nm.yml index 4572736..f88f61d 100644 --- a/tests/tests_team_plugin_installation_nm.yml +++ b/tests/tests_team_plugin_installation_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_team_plugin_installation.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_vlan_mtu_nm.yml b/tests/tests_vlan_mtu_nm.yml index c38263c..dc4f5a2 100644 --- a/tests/tests_vlan_mtu_nm.yml +++ b/tests/tests_vlan_mtu_nm.yml @@ -6,7 +6,6 @@ name: Run playbook 'playbooks/tests_vlan_mtu.yml' with nm as provider tasks: - include_tasks: tasks/el_repo_setup.yml - - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_wireless_nm.yml b/tests/tests_wireless_nm.yml index 03b5ad6..a4bb4fd 100644 --- a/tests/tests_wireless_nm.yml +++ b/tests/tests_wireless_nm.yml @@ -6,7 +6,6 @@ name: Run playbook 'playbooks/tests_wireless.yml' with nm as provider tasks: - include_tasks: tasks/el_repo_setup.yml - - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_wireless_plugin_installation_nm.yml b/tests/tests_wireless_plugin_installation_nm.yml index 5e55f50..a4a9489 100644 --- a/tests/tests_wireless_plugin_installation_nm.yml +++ b/tests/tests_wireless_plugin_installation_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_wireless_plugin_installation.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_wireless_wpa3_owe_nm.yml b/tests/tests_wireless_wpa3_owe_nm.yml index 7a0daf1..67599ec 100644 --- a/tests/tests_wireless_wpa3_owe_nm.yml +++ b/tests/tests_wireless_wpa3_owe_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_wireless_wpa3_owe.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm diff --git a/tests/tests_wireless_wpa3_sae_nm.yml b/tests/tests_wireless_wpa3_sae_nm.yml index b294d58..327014d 100644 --- a/tests/tests_wireless_wpa3_sae_nm.yml +++ b/tests/tests_wireless_wpa3_sae_nm.yml @@ -5,6 +5,7 @@ - hosts: all name: Run playbook 'playbooks/tests_wireless_wpa3_sae.yml' with nm as provider tasks: + - include_tasks: tasks/el_repo_setup.yml - name: Set network provider to 'nm' set_fact: network_provider: nm @@ -18,4 +19,4 @@ - import_playbook: playbooks/tests_wireless_wpa3_sae.yml when: - ansible_distribution_major_version != '6' - - ansible_distribution_major_version != '7' + - ansible_distribution_major_version != '7' and ansible_distribution != 'RedHat' diff --git a/tox.ini b/tox.ini index 59c58a2..297d20a 100644 --- a/tox.ini +++ b/tox.ini @@ -17,3 +17,9 @@ setenv = RUN_PYTEST_EXTRA_ARGS = -v RUN_FLAKE8_EXTRA_ARGS = --exclude tests/ensure_provider_tests.py,scripts/print_all_options.py,tests/network/ensure_provider_tests.py,.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg LSR_PUBLISH_COVERAGE = normal + +[testenv:ensure_provider_tests] +basepython = python3 +changedir = tests +commands = + python ./ensure_provider_tests.py {posargs}