From 2c9984c803cdad9ea85738bb52d12fe2715a248d Mon Sep 17 00:00:00 2001 From: jobrauer Date: Wed, 8 Jul 2020 09:45:44 +0200 Subject: [PATCH] Add test_scratch_final_mmd --- tests/integration/example.test.env.yaml | 5 +++ tests/integration/test_scratch_final_mmd.py | 38 +++++++++++++++++++ tests/integration/utils.py | 42 ++++++++++++++++----- 3 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 tests/integration/test_scratch_final_mmd.py diff --git a/tests/integration/example.test.env.yaml b/tests/integration/example.test.env.yaml index d2576fb2..97318be8 100644 --- a/tests/integration/example.test.env.yaml +++ b/tests/integration/example.test.env.yaml @@ -110,3 +110,8 @@ testdata: branch: test-highest-version-selection stream_module: testmodule test_stream: test-stream-highest-version + scratch_final_mmd: + # build to be reused - debug only + build_id: 3345 + module: testmodule + branch: test-scratch-final-mmd diff --git a/tests/integration/test_scratch_final_mmd.py b/tests/integration/test_scratch_final_mmd.py new file mode 100644 index 00000000..4d8e59ed --- /dev/null +++ b/tests/integration/test_scratch_final_mmd.py @@ -0,0 +1,38 @@ + +def test_scratch_final_mmd(scenario, repo, mbs, pkg_util): + """Test that scratch builds have properly generated final mmds. + + Steps: + * Submit a scratch build and wait for it to be ready. + * Query MBS API for final mmds. + + Checks: + * That there's a mmd for each arch. + * Content of the final mmd is roughly as expected. + """ + build = pkg_util.run("--scratch", "--watch", reuse=scenario.get("build_id"))[0] + + original_mmd = repo.modulemd + expected_arches = set(build.module_build_data["arches"]) + expected_rpms = set(original_mmd["data"]["components"]["rpms"].keys()) + + # Get the actual final mmds + mmds = mbs.get_final_mmds(build) + + assert expected_arches == set(mmds.keys()) + + for arch in expected_arches: + mmd = mmds.get(arch)["data"] + assert arch == mmd["arch"] + assert expected_rpms == set(mmd["components"]["rpms"].keys()) + assert build.module_build_data["context"] == mmd["context"] + + # assert that the submitted rpms are present in the artifacts list + actual_artifact_rpms = set(mmd["artifacts"]["rpms"]) + for rpm in expected_rpms: + actual_rpm = build.components(package=rpm) + assert actual_rpm + n, v, r = actual_rpm[0]["nvr"].split("-") + artifact_name = "{}-0:{}-{}.{}" + artifacts = {artifact_name.format(n, v, r, a) for a in [arch, "src"]} + assert artifacts.issubset(actual_artifact_rpms) diff --git a/tests/integration/utils.py b/tests/integration/utils.py index ab496d8a..4e618b58 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -197,7 +197,7 @@ class PackagingUtility: instead of triggering and waiting for new one(s) to finish. Intended to be used while developing the tests. :return: list of Build objects for the MBS builds created - :rtype: list of Build objects + :rtype: list[Build] """ build_ids = [] @@ -321,7 +321,7 @@ class Build: :param int batch: the number of the batch the components should be in :param string package: name of the component (package) :return: List of filtered components - :rtype: list of dict + :rtype: list[dict] """ filtered = self.component_data["items"] if batch is not None: @@ -484,6 +484,15 @@ class MBS: def __init__(self, mbs_api): self._mbs_api = mbs_api + @staticmethod + def _get_build_id(build_data): + if type(build_data) is Build: + return build_data.id + elif type(build_data) is int: + return build_data + else: + raise TypeError + def get_builds(self, module, stream, order_desc_by=None): """Get list of Builds objects via mbs api. @@ -543,13 +552,14 @@ class MBS: r.raise_for_status() return [Build(self._mbs_api, build["id"]) for build in r.json()["items"]] - def get_module_build(self, build_id, **kwargs): + def get_module_build(self, build_data, **kwargs): """Query MBS API on module-builds endpoint for a specific build - :attribute build_id (int): build ID + :attribute build_data (int|Build): build ID :return: module build object :rtype: Build """ + build_id = self._get_build_id(build_data) url = f"{self._mbs_api}module-builds/{build_id}" r = requests.get(url, params=kwargs) @@ -565,11 +575,7 @@ class MBS: :param int interval: scan interval in seconds """ start = time.time() - - if type(build_data) is not int: - build_id = build_data.id - else: - build_id = build_data + build_id = self._get_build_id(build_data) while (time.time() - start) < timeout: build = self.get_module_build(build_id) @@ -593,3 +599,21 @@ class MBS: else: return False return self.wait_for_module_build(build_data, predicate, timeout, interval) + + def get_final_mmds(self, build_data): + """Get build's final mmds. + + :param int|Build build_data: build obj or ID + :return: dict of parsed mmds (for each arch available) + :rtype: dict + """ + build_id = self._get_build_id(build_data) + + url = f"{self._mbs_api}final-modulemd/{build_id}" + r = requests.get(url) + r.raise_for_status() + + mmds = {} + for arch, mmd in r.json().items(): + mmds[arch] = yaml.safe_load(mmd) + return mmds