From 8c5ebd144aa8675dc996b20b1fba59c60f0ae562 Mon Sep 17 00:00:00 2001 From: Bruno Pimentel Date: Wed, 27 Mar 2024 12:23:10 -0300 Subject: [PATCH 1/2] rpm tests: mount the repofiles during the build process The generated repofiles need to be mounted during the build process so that dnf can use the prefetched RPM files. This patch changes the global utils so that every time a x86_64 repos.d folder is present in a test case, it will be mounted to /etc/yum.repos.d. Signed-off-by: Bruno Pimentel --- tests/integration/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/integration/utils.py b/tests/integration/utils.py index 847324747..250a82cad 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -90,6 +90,17 @@ def build_image_for_test_case(tmp_path: Path, containerfile: str, test_case: str "--network", "none", ] + + # this should be extended to support more archs when we have the means of testing it in our CI + rpm_repos_path = f"{tmp_path}/{test_case}-output/deps/rpm/x86_64/repos.d" + if Path(rpm_repos_path).exists(): + cmd.extend( + [ + "-v", + f"{rpm_repos_path}:/etc/yum.repos.d:Z", + ] + ) + return _build_image(cmd, tag=f"localhost/{test_case}") From 3492a15406c577dbb50765f725d3e789b1d3c1e1 Mon Sep 17 00:00:00 2001 From: Bruno Pimentel Date: Wed, 27 Mar 2024 12:23:55 -0300 Subject: [PATCH 2/2] rpm tests: add E2E test scenario Signed-off-by: Bruno Pimentel --- .../test_data/rpm_e2e_test/.build-config.yaml | 2 + .../test_data/rpm_e2e_test/bom.json | 171 ++++++++++++++++++ .../rpm_e2e_test/container/Containerfile | 6 + .../rpm_e2e_test/fetch_deps_sha256sums.json | 15 ++ .../rpm_e2e_test/vendor_sha256sums.json | 1 + tests/integration/test_rpm.py | 67 +++++++ 6 files changed, 262 insertions(+) create mode 100644 tests/integration/test_data/rpm_e2e_test/.build-config.yaml create mode 100644 tests/integration/test_data/rpm_e2e_test/bom.json create mode 100644 tests/integration/test_data/rpm_e2e_test/container/Containerfile create mode 100644 tests/integration/test_data/rpm_e2e_test/fetch_deps_sha256sums.json create mode 100644 tests/integration/test_data/rpm_e2e_test/vendor_sha256sums.json create mode 100644 tests/integration/test_rpm.py diff --git a/tests/integration/test_data/rpm_e2e_test/.build-config.yaml b/tests/integration/test_data/rpm_e2e_test/.build-config.yaml new file mode 100644 index 000000000..ecfb4f6a7 --- /dev/null +++ b/tests/integration/test_data/rpm_e2e_test/.build-config.yaml @@ -0,0 +1,2 @@ +environment_variables: [] +project_files: [] diff --git a/tests/integration/test_data/rpm_e2e_test/bom.json b/tests/integration/test_data/rpm_e2e_test/bom.json new file mode 100644 index 000000000..22b3550dd --- /dev/null +++ b/tests/integration/test_data/rpm_e2e_test/bom.json @@ -0,0 +1,171 @@ +{ + "bomFormat": "CycloneDX", + "components": [ + { + "name": "gpm-libs", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/gpm-libs@1.20.7-44.fc39?arch=x86_64&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/g/gpm-libs-1.20.7-44.fc39.x86_64.rpm", + "type": "library", + "version": "1.20.7" + }, + { + "name": "gpm", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/gpm@1.20.7-44.fc39?arch=i686&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/source/tree/Packages/g/gpm-1.20.7-44.fc39.src.rpm", + "type": "library", + "version": "1.20.7" + }, + { + "name": "libsodium", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/libsodium@1.0.18-14.fc39?arch=i686&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/source/tree/Packages/l/libsodium-1.0.18-14.fc39.src.rpm", + "type": "library", + "version": "1.0.18" + }, + { + "name": "libsodium", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/libsodium@1.0.18-14.fc39?arch=x86_64&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/l/libsodium-1.0.18-14.fc39.x86_64.rpm", + "type": "library", + "version": "1.0.18" + }, + { + "name": "vim-common", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/vim-common@9.0.1927-1.fc39?arch=x86_64&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/v/vim-common-9.0.1927-1.fc39.x86_64.rpm", + "type": "library", + "version": "9.0.1927" + }, + { + "name": "vim-data", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/vim-data@9.0.1927-1.fc39?arch=noarch&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/v/vim-data-9.0.1927-1.fc39.noarch.rpm", + "type": "library", + "version": "9.0.1927" + }, + { + "name": "vim-enhanced", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/vim-enhanced@9.0.1927-1.fc39?arch=x86_64&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/v/vim-enhanced-9.0.1927-1.fc39.x86_64.rpm", + "type": "library", + "version": "9.0.1927" + }, + { + "name": "vim-filesystem", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/vim-filesystem@9.0.1927-1.fc39?arch=noarch&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/v/vim-filesystem-9.0.1927-1.fc39.noarch.rpm", + "type": "library", + "version": "9.0.1927" + }, + { + "name": "vim-minimal", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/vim-minimal@9.0.1927-1.fc39?arch=x86_64&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/v/vim-minimal-9.0.1927-1.fc39.x86_64.rpm", + "type": "library", + "version": "9.0.1927" + }, + { + "name": "vim", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/vim@9.0.1927-1.fc39?arch=i686&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/source/tree/Packages/v/vim-9.0.1927-1.fc39.src.rpm", + "type": "library", + "version": "9.0.1927" + }, + { + "name": "which", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/which@2.21-40.fc39?arch=i686&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/source/tree/Packages/w/which-2.21-40.fc39.src.rpm", + "type": "library", + "version": "2.21" + }, + { + "name": "which", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/which@2.21-40.fc39?arch=x86_64&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/w/which-2.21-40.fc39.x86_64.rpm", + "type": "library", + "version": "2.21" + }, + { + "name": "xxd", + "properties": [ + { + "name": "cachi2:found_by", + "value": "cachi2" + } + ], + "purl": "pkg:rpm/fedora%20project/xxd@9.0.1927-1.fc39?arch=x86_64&epoch=2&download_url=http%3A//fedora.c3sl.ufpr.br/linux/releases/39/Everything/x86_64/os/Packages/x/xxd-9.0.1927-1.fc39.x86_64.rpm", + "type": "library", + "version": "9.0.1927" + } + ], + "metadata": { + "tools": [ + { + "name": "cachi2", + "vendor": "red hat" + } + ] + }, + "specVersion": "1.4", + "version": 1 +} diff --git a/tests/integration/test_data/rpm_e2e_test/container/Containerfile b/tests/integration/test_data/rpm_e2e_test/container/Containerfile new file mode 100644 index 000000000..cdbaeeb17 --- /dev/null +++ b/tests/integration/test_data/rpm_e2e_test/container/Containerfile @@ -0,0 +1,6 @@ +FROM registry.fedoraproject.org/fedora:39 + +RUN dnf -y install \ + vim + +CMD ["vim", "--help"] diff --git a/tests/integration/test_data/rpm_e2e_test/fetch_deps_sha256sums.json b/tests/integration/test_data/rpm_e2e_test/fetch_deps_sha256sums.json new file mode 100644 index 000000000..bde295821 --- /dev/null +++ b/tests/integration/test_data/rpm_e2e_test/fetch_deps_sha256sums.json @@ -0,0 +1,15 @@ +{ + "rpm/x86_64/releases/gpm-1.20.7-44.fc39.src.rpm": "sha256:2eb2412dde91b1130433c90ad53b889cb1e0fb0df324e015f29e76d7235ac438", + "rpm/x86_64/releases/gpm-libs-1.20.7-44.fc39.x86_64.rpm": "sha256:f5c8f20f0f9468da8cdf140d7df30ed117a43b73eee816888e2624b0fcd048ca", + "rpm/x86_64/releases/libsodium-1.0.18-14.fc39.src.rpm": "sha256:d20e5f6e358aa0c07260872ffb00d502f77778ae7496a836da0a65a6ce1cd709", + "rpm/x86_64/releases/libsodium-1.0.18-14.fc39.x86_64.rpm": "sha256:e38200a7b1012935dc83e8039c71c0fd2f84a4463ca086cb42f60f488cdad8e7", + "rpm/x86_64/releases/vim-9.0.1927-1.fc39.src.rpm": "sha256:dae76267f265093d0e1b178c05af197bc21b994a264c9c4e7701cce095b62f03", + "rpm/x86_64/releases/vim-common-9.0.1927-1.fc39.x86_64.rpm": "sha256:4cb8015a858439f519d5d2aa82fd853f3d1dd7f927a33d25d9598e54ee6201bc", + "rpm/x86_64/releases/vim-data-9.0.1927-1.fc39.noarch.rpm": "sha256:35d7b9542e46eca30d951960effe9a8e738543a839f0dbb3cf723da0958c355b", + "rpm/x86_64/releases/vim-enhanced-9.0.1927-1.fc39.x86_64.rpm": "sha256:615d46a08fbbd0eca6a6e8d2d23a6b5847db11c886e0dc979ffebab66236532d", + "rpm/x86_64/releases/vim-filesystem-9.0.1927-1.fc39.noarch.rpm": "sha256:f645ed8cda2fa07ba991320a684d9b71de75ff25220468b08fb36f6a5a231178", + "rpm/x86_64/releases/vim-minimal-9.0.1927-1.fc39.x86_64.rpm": "sha256:37a216f1af9f2eb961a9fa6674861146d11ca56fc9c576fa17a8cb7d806aa0af", + "rpm/x86_64/releases/which-2.21-40.fc39.src.rpm": "sha256:791428d30c136a2ff8e781b9c32cbd3d506699f1369ae2a589c02fceb72d4533", + "rpm/x86_64/releases/which-2.21-40.fc39.x86_64.rpm": "sha256:ec1d8a1c0d88883a03e96ba88a6278899bd559fb37833cb2383ffdd6a38c22ae", + "rpm/x86_64/releases/xxd-9.0.1927-1.fc39.x86_64.rpm": "sha256:e770b0a0e5e51225a76069d2210551a90f3140913f90f33759d002055179ecc7" +} diff --git a/tests/integration/test_data/rpm_e2e_test/vendor_sha256sums.json b/tests/integration/test_data/rpm_e2e_test/vendor_sha256sums.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/integration/test_data/rpm_e2e_test/vendor_sha256sums.json @@ -0,0 +1 @@ +{} diff --git a/tests/integration/test_rpm.py b/tests/integration/test_rpm.py new file mode 100644 index 000000000..a3deb7759 --- /dev/null +++ b/tests/integration/test_rpm.py @@ -0,0 +1,67 @@ +from pathlib import Path +from typing import List + +import pytest + +from . import utils + + +@pytest.mark.parametrize( + "test_params, check_cmd, expected_cmd_output", + [ + # Test case that checks fetching RPM files, generating repos and repofiles, building an + # image that requires the RPM files to be installed and running the image to check if the + # RPMs were properly installed + pytest.param( + utils.TestParameters( + repo="https://github.com/cachito-testing/cachi2-rpm.git", + ref="eef99f074a9abd288b421697d7e00cec77590d0d", + packages=( + { + "type": "rpm", + }, + ), + flags=["--dev-package-managers"], + expected_exit_code=0, + expected_output="All dependencies fetched successfully", + ), + ["vim", "--version"], + ["VIM - Vi IMproved 9.0"], + id="rpm_e2e_test", + ), + ], +) +def test_e2e_rpm( + test_params: utils.TestParameters, + check_cmd: List[str], + expected_cmd_output: str, + cachi2_image: utils.ContainerImage, + tmp_path: Path, + test_data_dir: Path, + request: pytest.FixtureRequest, +) -> None: + """ + End to end test for rpms. + + :param test_params: Test case arguments + :param tmp_path: Temp directory for pytest + """ + test_case = request.node.callspec.id + + source_folder = utils.clone_repository( + test_params.repo, test_params.ref, f"{test_case}-source", tmp_path + ) + + output_folder = utils.fetch_deps_and_check_output( + tmp_path, test_case, test_params, source_folder, test_data_dir, cachi2_image + ) + + utils.build_image_and_check_cmd( + tmp_path, + output_folder, + test_data_dir, + test_case, + check_cmd, + expected_cmd_output, + cachi2_image, + )