diff --git a/Dockerfile b/Dockerfile index b5cc377..dc24386 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ from registry.fedoraproject.org/fedora:37 run dnf -y update fedora-gpg-keys && \ - dnf -y install git python3-jinja2 python3-koji python3-yaml && \ + dnf -y install git python3-pytest python3-pytest-cov python3-jinja2 python3-koji python3-yaml && \ dnf clean all workdir /workspace diff --git a/feedback_pipeline.py b/feedback_pipeline.py index af76faf..7becd7b 100755 --- a/feedback_pipeline.py +++ b/feedback_pipeline.py @@ -150,7 +150,7 @@ def datetime_now_string(): return datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S") -def load_settings(): +def load_settings(argv=None): settings = {} parser = argparse.ArgumentParser() @@ -159,7 +159,7 @@ def load_settings(): parser.add_argument("--use-cache", dest="use_cache", action='store_true', help="Use local data instead of pulling Content Resolver. Saves a lot of time! Needs a 'cache_data.json' file at the same location as the script is at.") parser.add_argument("--dev-buildroot", dest="dev_buildroot", action='store_true', help="Buildroot grows pretty quickly. Use a fake one for development.") parser.add_argument("--dnf-cache-dir", dest="dnf_cache_dir_override", help="Override the dnf cache_dir.") - args = parser.parse_args() + args = parser.parse_args(argv) settings["configs"] = args.configs settings["output"] = args.output @@ -7245,7 +7245,7 @@ def generate_historic_data(query): ############################################################################### -def main(): +def main(argv=None): # ------------------------------------------------- # Stage 1: Data collection and analysis using DNF @@ -7254,7 +7254,7 @@ def main(): # measuring time of execution time_started = datetime_now_string() - settings = load_settings() + settings = load_settings(argv) settings["global_refresh_time_started"] = datetime.datetime.now().strftime("%-d %B %Y %H:%M UTC") diff --git a/test_configs/base-test.yaml b/test_configs/base-test.yaml new file mode 100644 index 0000000..6282d42 --- /dev/null +++ b/test_configs/base-test.yaml @@ -0,0 +1,76 @@ +--- +# This configuration file defines an "Environment" in Feedback Pipeline. +# https://tiny.distro.builders +# +# Environments influence how a workload looks like when installed. +# That's achieved by including specific packages — like coreutils-single — that +# influence the result. +# Environments can also act as base images when monitoring container sizes. + +document: feedback-pipeline-environment +version: 1 +data: + # id is the filename — that automatically prevents collisions for free! + + + ### MANDATORY FIELDS ### + + # Name is an identifier for humans + # + # (mandatory field) + name: Test F34 Environment + + # A short description, perhaps hinting the purpose + # + # (mandatory field) + description: A base environment on top of which all test workloads are analyzed. + + # Who maintains it? This is just a freeform string + # for humans to read. In Fedora, a FAS nick is recommended. + # + # (mandatory field) + maintainer: asamalik + + # Different instances of the environment, one per repository. + # + # (mandatory field) + repositories: + - repo-test + + # Packages defining this environment. + # This list includes packages for all + # architectures — that's the one to use by default. + # + # (mandatory field) + packages: + - fedora-repos-eln + - fedora-release-eln + + # Labels connect things together. + # Workloads get installed in environments with the same label. + # They also get included in views with the same label. + # + # (mandatory field) + labels: + - eln + - eln-but-not-included + - eln-extras + + ### OPTIONAL FIELDS ### + + # Architecture-specific packages. + # + # (optional field) + #arch_packages: + # x86_64: + # - arch-specific-package + + # Extra installation options. + # The following are now supported: + # - "include-docs" - include documentation packages + # - "include-weak-deps" - automatically pull in "recommends" weak dependencies + # + # (optional field) + #options: + #- option + diff --git a/test_configs/view-test.yaml b/test_configs/view-test.yaml new file mode 100644 index 0000000..883a0bd --- /dev/null +++ b/test_configs/view-test.yaml @@ -0,0 +1,13 @@ +--- +document: feedback-pipeline-compose-view +version: 1 +data: + name: Test Package Set + description: Test package set based on F34 + maintainer: bakery + labels: + - eln + repository: repo-test + buildroot_strategy: dep_tracker + + diff --git a/test_feedback_pipeline.py b/test_feedback_pipeline.py index f6c355b..f74e693 100644 --- a/test_feedback_pipeline.py +++ b/test_feedback_pipeline.py @@ -2,5 +2,99 @@ import feedback_pipeline -def test_build_completion(): - assert 1 == 1 \ No newline at end of file +import json +import os +import pytest +import tempfile + +from shutil import rmtree + +@pytest.fixture(scope="module") +def feedback_pipeline_output(): + with tempfile.TemporaryDirectory() as tmp: + os.mkdir(f"{tmp}/history") + feedback_pipeline.main([ + "--dev-buildroot", "--dnf-cache-dir", + "/tmp/test_cr", "test_configs", tmp]) + yield tmp + + +def test_bash_test_repo_workload(feedback_pipeline_output): + expected_pkg_added_ids = set([ + 'filesystem-3.14-5.fc34.aarch64', + 'glibc-minimal-langpack-2.33-5.fc34.aarch64', + 'tzdata-2021a-1.fc34.noarch', + 'basesystem-11-11.fc34.noarch', + 'bash-5.1.0-2.fc34.aarch64', + 'ncurses-libs-6.2-4.20200222.fc34.aarch64', + 'ncurses-base-6.2-4.20200222.fc34.noarch', + 'libgcc-11.0.1-0.3.fc34.aarch64', + 'glibc-2.33-5.fc34.aarch64', + 'setup-2.13.7-3.fc34.noarch', + 'glibc-common-2.33-5.fc34.aarch64' + ]) + + with open(f"{feedback_pipeline_output}/workload--bash--base-test--repo-test--aarch64.json") as w: + workload = json.load(w) + assert set(workload["data"]["pkg_added_ids"]) == expected_pkg_added_ids + +def test_bash_test_repo_view(feedback_pipeline_output): + expected_pkgs = {'alternatives-1.15-2.fc34', + 'basesystem-11-11.fc34', + 'bash-5.1.0-2.fc34', + 'ca-certificates-2020.2.41-7.fc34', + 'coreutils-8.32-21.fc34', + 'coreutils-common-8.32-21.fc34', + 'crypto-policies-20210213-1.git5c710c0.fc34', + 'fedora-gpg-keys-34-1', + 'fedora-release-34-1', + 'fedora-release-common-34-1', + 'fedora-release-identity-basic-34-1', + 'fedora-repos-34-1', + 'fedora-repos-eln-34-1', + 'fedora-repos-rawhide-34-1', + 'filesystem-3.14-5.fc34', + 'gc-8.0.4-5.fc34', + 'glibc-2.33-5.fc34', + 'glibc-common-2.33-5.fc34', + 'glibc-minimal-langpack-2.33-5.fc34', + 'gmp-1:6.2.0-6.fc34', + 'grep-3.6-2.fc34', + 'guile22-2.2.7-2.fc34', + 'libacl-2.3.1-1.fc34', + 'libattr-2.5.1-1.fc34', + 'libcap-2.48-2.fc34', + 'libffi-3.1-28.fc34', + 'libgcc-11.0.1-0.3.fc34', + 'libselinux-3.2-1.fc34', + 'libsepol-3.2-1.fc34', + 'libstdc++-11.0.1-0.3.fc34', + 'libtasn1-4.16.0-4.fc34', + 'libtool-ltdl-2.4.6-40.fc34', + 'libunistring-0.9.10-10.fc34', + 'libxcrypt-4.4.18-1.fc34', + 'make-1:4.3-5.fc34', + 'ncurses-base-6.2-4.20200222.fc34', + 'ncurses-libs-6.2-4.20200222.fc34', + 'openssl-libs-1:1.1.1k-1.fc34', + 'p11-kit-0.23.22-3.fc34', + 'p11-kit-trust-0.23.22-3.fc34', + 'pcre-8.44-3.fc34.1', + 'pcre2-10.36-4.fc34', + 'pcre2-syntax-10.36-4.fc34', + 'pizza-package-000-placeholder', + 'readline-8.1-2.fc34', + 'sed-4.8-7.fc34', + 'setup-2.13.7-3.fc34', + 'tar-2:1.34-1.fc34', + 'tzdata-2021a-1.fc34', + 'zlib-1.2.11-26.fc34'} + + with open(f"{feedback_pipeline_output}/view-packages--view-test.json") as w: + view = json.load(w) + assert set(view['pkgs'].keys()) == expected_pkgs + + + +if __name__ == "__main__": + test_mock_argv()