Merge builder.py changes from master

* 47c4363 Fix #467 - Inject modules.yaml to mock repository
* eaeaf29 unused method
* 6412a7f use module owner for whitelisting Koji packages
* 80f78c7 rename to match what it actually does
* 4c57329 include %module_name, %module_stream and %module_version in the module-build-macros and fix sending active=True in pdc.py
This commit is contained in:
Jakub Kadlčík
2017-04-04 13:32:08 +02:00
parent 98dce17eab
commit 3ba114c0b1
3 changed files with 40 additions and 30 deletions

View File

@@ -241,9 +241,9 @@ class CoprModuleBuilder(GenericBuilder):
log.info(result.data["modulemd"])
@staticmethod
def get_disttag_srpm(disttag):
def get_disttag_srpm(disttag, module_build):
# @FIXME
return KojiModuleBuilder.get_disttag_srpm(disttag)
return KojiModuleBuilder.get_disttag_srpm(disttag, module_build)
@property
def module_build_tag(self):

View File

@@ -119,7 +119,7 @@ class KojiModuleBuilder(GenericBuilder):
@staticmethod
def get_disttag_srpm(disttag):
def get_disttag_srpm(disttag, build):
#Taken from Karsten's create-distmacro-pkg.sh
# - however removed any provides to system-release/redhat-release
@@ -129,7 +129,12 @@ class KojiModuleBuilder(GenericBuilder):
release = "1"
today = datetime.date.today().strftime('%a %b %d %Y')
spec_content = """%global dist {disttag}
spec_content = """
%global dist {disttag}
%global _module_name {module_name}
%global _module_stream {module_stream}
%global _module_version {module_version}
Name: {name}
Version: {version}
Release: {release}%dist
@@ -154,6 +159,9 @@ It should NEVER be installed on any system as it will really mess up
mkdir -p %buildroot/%_rpmconfigdir/macros.d 2>/dev/null |:
echo %%dist %dist > %buildroot/%_rpmconfigdir/macros.d/macros.modules
echo %%_module_build 1 >> %buildroot/%_rpmconfigdir/macros.d/macros.modules
echo %%_module_name %_module_name >> %buildroot/%_rpmconfigdir/macros.d/macros.modules
echo %%_module_stream %_module_stream >> %buildroot/%_rpmconfigdir/macros.d/macros.modules
echo %%_module_version %_module_version >> %buildroot/%_rpmconfigdir/macros.d/macros.modules
chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
@@ -165,7 +173,9 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
%changelog
* {today} Fedora-Modularity - {version}-{release}{disttag}
- autogenerated macro by Module Build Service (MBS)
""".format(disttag=disttag, today=today, name=name, version=version, release=release)
""".format(disttag=disttag, today=today, name=name, version=version,
release=release, module_name=build.name, module_stream=build.stream,
module_version=build.version)
td = tempfile.mkdtemp(prefix="module_build_service-build-macros")
fd = open(os.path.join(td, "%s.spec" % name), "w")
fd.write(spec_content)
@@ -560,21 +570,10 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
self.koji_session.editTag2(tag_name, **opts)
return self._get_tag(tag_name) # Return up2date taginfo
def _get_component_owner(self, package):
user = self.koji_session.getLoggedInUser()['name']
if not self.koji_session.getUser(user):
raise ValueError("Unknown user %s" % user)
return user
def _koji_whitelist_packages(self, packages, tags = None):
def _koji_whitelist_packages(self, packages, tags=None):
if not tags:
tags = [self.module_tag, self.module_build_tag]
# TODO: This has to be done per-package or just without the need
# to pass the `packages` to it depending on the result of
# issue #337.
owner = self._get_component_owner(packages[0])
# This will help with potential resubmiting of failed builds
pkglists = {}
for tag in tags:
@@ -583,13 +582,12 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
self.koji_session.multicall = True
for tag in tags:
pkglist = pkglists[tag['id']]
to_add = []
for package in packages:
if pkglist.get(package, None):
log.debug("%s Package %s is already whitelisted." % (self, package))
continue
self.koji_session.packageListAdd(tag['name'], package, owner)
self.koji_session.packageListAdd(tag['name'], package, self.owner)
self.koji_session.multiCall(strict=True)
@module_build_service.utils.validate_koji_tag(['build_tag', 'dest_tag'])

View File

@@ -27,7 +27,7 @@ import os
import koji
import kobo.rpmlib
import shutil
import subprocess
import yaml
import threading
from module_build_service import conf, log, db
@@ -39,6 +39,7 @@ import module_build_service.scheduler.consumer
from base import GenericBuilder
from utils import execute_cmd, build_from_scm, fake_repo_done_message
from KojiModuleBuilder import KojiModuleBuilder
from module_build_service.models import ModuleBuild
logging.basicConfig(level=logging.DEBUG)
@@ -150,14 +151,25 @@ mdpolicy=group:primary
"""
log.debug("Creating repository in %s" % self.resultsdir)
path = self.resultsdir
if os.path.exists(path + '/repodata/repomd.xml'):
comm = ['/usr/bin/createrepo_c', '--update', path]
else:
comm = ['/usr/bin/createrepo_c', path]
cmd = subprocess.Popen(
comm, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
return out, err
repodata_path = os.path.join(path, "repodata")
# Remove old repodata files
if os.path.exists(repodata_path):
for name in os.listdir(repodata_path):
os.remove(os.path.join(repodata_path, name))
# Generate the mmd the same way as pungi does.
m1 = ModuleBuild.query.filter(ModuleBuild.name == self.module_str).one()
modules = {"modules": []}
modules["modules"].append(yaml.safe_load(m1.mmd().dumps()))
mmd_path = os.path.join(path, "modules.yaml")
with open(mmd_path, "w") as outfile:
outfile.write(yaml.safe_dump(modules))
# Generate repo and inject modules.yaml there.
execute_cmd(['/usr/bin/createrepo_c', path])
execute_cmd(['/usr/bin/modifyrepo_c', '--mdtype=modules', mmd_path, repodata_path])
def _add_repo(self, name, baseurl, extra = ""):
"""
@@ -401,9 +413,9 @@ mdpolicy=group:primary
return self.build_srpm(artifact_name, source, build_id)
@staticmethod
def get_disttag_srpm(disttag):
def get_disttag_srpm(disttag, module_build):
# @FIXME
return KojiModuleBuilder.get_disttag_srpm(disttag)
return KojiModuleBuilder.get_disttag_srpm(disttag, module_build)
def cancel_build(self, task_id):
pass