From ddee4f840b8030588fc56c2668ffa69f4ee24b74 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Tue, 29 May 2018 16:15:54 -0400 Subject: [PATCH] MockModuleBuilder: add artifacts to artifacts not components The built RPM artifacts were being added to the components list (the RPMs to build) instead of the proper artifacts section. Also, they need to be in NEVRA format, so use 'rpm -qf' to query the epochs from the built artifacts. --- .../builder/MockModuleBuilder.py | 34 +++++++++++++------ tests/test_builder/test_mock.py | 16 +++++++-- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/module_build_service/builder/MockModuleBuilder.py b/module_build_service/builder/MockModuleBuilder.py index 43809f60..b4f78474 100644 --- a/module_build_service/builder/MockModuleBuilder.py +++ b/module_build_service/builder/MockModuleBuilder.py @@ -29,6 +29,7 @@ import kobo.rpmlib import pipes import platform import re +import subprocess import threading from module_build_service import conf, log, Modulemd @@ -174,24 +175,35 @@ class MockModuleBuilder(GenericBuilder): # Generate the mmd the same way as pungi does. m1 = ModuleBuild.query.filter(ModuleBuild.name == self.module_str).one() m1_mmd = m1.mmd() - for rpm in os.listdir(self.resultsdir): - if not rpm.endswith(".rpm"): - continue + artifacts = Modulemd.SimpleSet() + + rpm_files = [f + for f in os.listdir(self.resultsdir) + if f.endswith(".rpm")] + + output = subprocess.check_output(['rpm', + '--queryformat', + '%{NAME} %{EPOCHNUM} %{VERSION} %{RELEASE} %{ARCH}\n', + '-qp'] + rpm_files, + cwd=self.resultsdir, + universal_newlines=True) + nevras = output.strip().split('\n') + if len(nevras) != len(rpm_files): + raise RuntimeError("rpm -qp returned an unexpected number of lines") + + for rpm_file, nevra in zip(rpm_files, nevras): + name, epoch, version, release, arch = nevra.split() if m1.last_batch_id() == m1.batch: # If RPM is filtered-out, do not add it to artifacts list. - nvr = kobo.rpmlib.parse_nvr(rpm) - if nvr["name"] in m1_mmd.get_rpm_filter().get(): + if name in m1_mmd.get_rpm_filter().get(): continue - pkglist_f.write(rpm + '\n') - rpm = rpm[:-len(".rpm")] - component = Modulemd.ComponentRpm() - component.set_name(str(rpm)) - component.set_rationale('none') - m1_mmd.add_rpm_component(component) + pkglist_f.write(rpm_file + '\n') + artifacts.add('{}-{}:{}-{}.{}'.format(name, epoch, version, release, arch)) pkglist_f.close() + m1_mmd.set_rpm_artifacts(artifacts) mmd_path = os.path.join(path, "modules.yaml") m1_mmd.dump(mmd_path) diff --git a/tests/test_builder/test_mock.py b/tests/test_builder/test_mock.py index 24eeea72..9633574c 100644 --- a/tests/test_builder/test_mock.py +++ b/tests/test_builder/test_mock.py @@ -3,6 +3,7 @@ import mock import koji import tempfile import shutil +from textwrap import dedent import kobo.rpmlib @@ -116,8 +117,14 @@ class TestMockModuleBuilder: "mksh-56b-1.module+24957a32.x86_64.rpm", "module-build-macros-0.1-1.module+24957a32.noarch.rpm" ] + rpm_qf_output = dedent("""\ + ed 0 1.14.1 4.module+24957a32 x86_64 + mksh 0 56b-1 module+24957a32 x86_64 + module-build-macros 0 0.1 1.module+24957a32 noarch + """) with mock.patch("os.listdir", return_value=rpms): - builder._createrepo() + with mock.patch("subprocess.check_output", return_value=rpm_qf_output): + builder._createrepo() with open(os.path.join(self.resultdir, "pkglist"), "r") as fd: pkglist = fd.read().strip() @@ -136,8 +143,13 @@ class TestMockModuleBuilder: "ed-1.14.1-4.module+24957a32.x86_64.rpm", "mksh-56b-1.module+24957a32.x86_64.rpm", ] + rpm_qf_output = dedent("""\ + ed 0 1.14.1 4.module+24957a32 x86_64 + mksh 0 56b-1 module+24957a32 x86_64 + """) with mock.patch("os.listdir", return_value=rpms): - builder._createrepo() + with mock.patch("subprocess.check_output", return_value=rpm_qf_output): + builder._createrepo() with open(os.path.join(self.resultdir, "pkglist"), "r") as fd: pkglist = fd.read().strip()