From f1587108183830ca8fa073c802bfe4886577531c Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 8 Mar 2023 15:23:57 +0000 Subject: [PATCH] Switch to using our onedir to run the package tests Signed-off-by: Pedro Algarvio --- .github/workflows/test-action-macos.yml | 1 + .github/workflows/test-action.yml | 1 - .../workflows/test-packages-action-macos.yml | 14 ++++- .github/workflows/test-packages-action.yml | 1 - noxfile.py | 57 ++++++++++++++++++- tools/ci.py | 6 +- 6 files changed, 71 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-action-macos.yml b/.github/workflows/test-action-macos.yml index 3333930dae3..05d6560080f 100644 --- a/.github/workflows/test-action-macos.yml +++ b/.github/workflows/test-action-macos.yml @@ -114,6 +114,7 @@ jobs: python3 -c "import os; os.makedirs('artifacts', exist_ok=True)" cd artifacts tar xvf ${{ inputs.package-name }}-${{ inputs.salt-version }}-onedir-${{ inputs.platform }}-${{ inputs.arch }}.tar.xz + - name: Set up Python ${{ inputs.python-version }} if: steps.nox-dependencies-cache.outputs.cache-hit != 'true' uses: actions/setup-python@v4 diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 6c978f38c7a..72f29429c41 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -103,7 +103,6 @@ jobs: path: nox.${{ inputs.distro-slug }}.tar.* key: ${{ inputs.cache-prefix }}|testrun-deps|${{ inputs.distro-slug }}|${{ inputs.nox-session }}|${{ matrix.transport }}|${{ hashFiles('requirements/**/*.txt', 'cicd/golden-images.json') }} - # Skip jobs if nox.*.tar.* is already cached - name: Download Onedir Tarball as an Artifact if: steps.nox-dependencies-cache.outputs.cache-hit != 'true' uses: actions/download-artifact@v3 diff --git a/.github/workflows/test-packages-action-macos.yml b/.github/workflows/test-packages-action-macos.yml index d59072436f0..82b68eb8189 100644 --- a/.github/workflows/test-packages-action-macos.yml +++ b/.github/workflows/test-packages-action-macos.yml @@ -89,7 +89,6 @@ jobs: path: nox.${{ inputs.distro-slug }}.tar.* key: ${{ inputs.cache-prefix }}|testrun-deps|${{ inputs.distro-slug }}|${{ matrix.nox-session }}|${{ hashFiles('requirements/**/*.txt', 'cicd/golden-images.json') }} - # Skip jobs if nox.*.tar.* is already cached - name: Download Onedir Tarball as an Artifact if: steps.nox-dependencies-cache.outputs.cache-hit != 'true' uses: actions/download-artifact@v3 @@ -187,6 +186,19 @@ jobs: run: | tree pkg/artifacts + - name: Download Onedir Tarball as an Artifact + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.package-name }}-${{ inputs.salt-version }}-onedir-${{ inputs.platform }}-${{ inputs.arch }}.tar.xz + path: artifacts/ + + - name: Decompress Onedir Tarball + shell: bash + run: | + python3 -c "import os; os.makedirs('artifacts', exist_ok=True)" + cd artifacts + tar xvf ${{ inputs.package-name }}-${{ inputs.salt-version }}-onedir-${{ inputs.platform }}-${{ inputs.arch }}.tar.xz + - name: Set up Python ${{ inputs.python-version }} uses: actions/setup-python@v4 with: diff --git a/.github/workflows/test-packages-action.yml b/.github/workflows/test-packages-action.yml index ae4e53df3c1..4a0eeb718f3 100644 --- a/.github/workflows/test-packages-action.yml +++ b/.github/workflows/test-packages-action.yml @@ -90,7 +90,6 @@ jobs: path: nox.${{ inputs.distro-slug }}.tar.* key: ${{ inputs.cache-prefix }}|testrun-deps|${{ inputs.distro-slug }}|${{ matrix.nox-session }}|${{ hashFiles('requirements/**/*.txt', 'cicd/golden-images.json') }} - # Skip jobs if nox.*.tar.* is already cached - name: Download Onedir Tarball as an Artifact if: steps.nox-dependencies-cache.outputs.cache-hit != 'true' uses: actions/download-artifact@v3 diff --git a/noxfile.py b/noxfile.py index 18934c08fc3..21d017666d1 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1762,12 +1762,14 @@ def build(session): session.run("python", "-m", "twine", "check", "dist/*") -def _pkg_test(session, cmd_args, test_type): +def _pkg_test(session, cmd_args, test_type, onedir=False): pydir = _get_pydir(session) junit_report_filename = f"test-results-{test_type}" runtests_log_filename = f"runtests-{test_type}" # Install requirements - if _upgrade_pip_setuptools_and_wheel(session): + if onedir and IS_LINUX: + session_run_always(session, "python3", "-m", "relenv", "toolchain", "fetch") + if _upgrade_pip_setuptools_and_wheel(session, onedir=onedir): if IS_WINDOWS: file_name = "pkgtests-windows.txt" else: @@ -1780,6 +1782,10 @@ def _pkg_test(session, cmd_args, test_type): install_command = ["--progress-bar=off", "-r", requirements_file] session.install(*install_command, silent=PIP_INSTALL_SILENT) + env = {} + if onedir: + env["ONEDIR_TESTRUN"] = "1" + pytest_args = ( cmd_args[:] + [ @@ -1788,7 +1794,7 @@ def _pkg_test(session, cmd_args, test_type): ] + session.posargs ) - _pytest(session, False, pytest_args) + _pytest(session, False, pytest_args, env=env) @nox.session(python=_PYTHON_VERSIONS, name="test-pkgs") @@ -1799,6 +1805,21 @@ def test_pkgs(session): _pkg_test(session, ["pkg/tests/"], "pkg") +@nox.session( + python=str(ONEDIR_PYTHON_PATH), + name="test-pkgs-onedir", + venv_params=["--system-site-packages"], +) +def test_pkgs_onedir(session): + if not ONEDIR_ARTIFACT_PATH.exists(): + session.error( + "The salt onedir artifact, expected to be in '{}', was not found".format( + ONEDIR_ARTIFACT_PATH.relative_to(REPO_ROOT) + ) + ) + _pkg_test(session, ["pkg/tests/"], "pkg", onedir=True) + + @nox.session(python=_PYTHON_VERSIONS, name="test-upgrade-pkgs") @nox.parametrize("classic", [False, True]) def test_upgrade_pkgs(session, classic): @@ -1823,3 +1844,33 @@ def test_upgrade_pkgs(session, classic): cmd_args = ["pkg/tests/", "--no-install"] + session.posargs _pkg_test(session, cmd_args, test_type) + + +@nox.session( + python=str(ONEDIR_PYTHON_PATH), + name="test-upgrade-pkgs-onedir", + venv_params=["--system-site-packages"], +) +@nox.parametrize("classic", [False, True]) +def test_upgrade_pkgs_onedir(session, classic): + """ + pytest pkg upgrade tests session + """ + test_type = "pkg_upgrade" + cmd_args = [ + "pkg/tests/upgrade/test_salt_upgrade.py::test_salt_upgrade", + "--upgrade", + "--no-uninstall", + ] + if classic: + cmd_args = cmd_args + ["--classic"] + # Workaround for installing and running classic packages from 3005.1 + # They can only run with importlib-metadata<5.0.0. + subprocess.run(["pip3", "install", "importlib-metadata==4.13.0"], check=False) + try: + _pkg_test(session, cmd_args, test_type, onedir=True) + except nox.command.CommandFailed: + sys.exit(1) + + cmd_args = ["pkg/tests/", "--no-install"] + session.posargs + _pkg_test(session, cmd_args, test_type, onedir=True) diff --git a/tools/ci.py b/tools/ci.py index e074ff9b2c5..645051dc603 100644 --- a/tools/ci.py +++ b/tools/ci.py @@ -670,7 +670,7 @@ def pkg_matrix(ctx: Context, distro_slug: str, pkg_type: str): """ _matrix = [] sessions = [ - "test-pkgs-3", + "test-pkgs-onedir", ] if ( distro_slug @@ -686,13 +686,13 @@ def pkg_matrix(ctx: Context, distro_slug: str, pkg_type: str): # we will need to ensure when we release 3006.0 # we allow for 3006.0 jobs to run, because then # we will have arm64 onedir packages to upgrade from - sessions.append("'test-upgrade-pkgs-3(classic=False)'") + sessions.append("'test-upgrade-pkgs-onedir(classic=False)'") if ( distro_slug not in ["centosstream-9", "ubuntu-22.04", "ubuntu-22.04-arm64"] and "MSI" != pkg_type ): # Packages for these OSs where never built for classic previously - sessions.append("'test-upgrade-pkgs-3(classic=True)'") + sessions.append("'test-upgrade-pkgs-onedir(classic=True)'") for sess in sessions: _matrix.append({"nox-session": sess})