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.
This commit is contained in:
Owen W. Taylor
2018-05-29 16:15:54 -04:00
parent 5093a94f20
commit ddee4f840b
2 changed files with 37 additions and 13 deletions

View File

@@ -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)

View File

@@ -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()