mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 03:38:12 +08:00
Merge #77 Create (koji) builder session on behalf of users
This commit is contained in:
@@ -221,12 +221,13 @@ class GenericBuilder(six.with_metaclass(ABCMeta)):
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
class Builder:
|
||||
class Builder(object):
|
||||
"""Wrapper class"""
|
||||
|
||||
def __new__(cls, module, backend, config, **extra):
|
||||
def __new__(cls, owner, module, backend, config, **extra):
|
||||
"""
|
||||
:param module : a module string e.g. 'testmodule-1.0'
|
||||
:param owner: a string representing who kicked off the builds
|
||||
:param module: a module string e.g. 'testmodule-1.0'
|
||||
:param backend: a string representing backend e.g. 'koji'
|
||||
:param config: instance of rida.config.Config
|
||||
|
||||
@@ -235,7 +236,8 @@ class Builder:
|
||||
"""
|
||||
|
||||
if backend == "koji":
|
||||
return KojiModuleBuilder(module=module, config=config, **extra)
|
||||
return KojiModuleBuilder(owner=owner, module=module,
|
||||
config=config, **extra)
|
||||
else:
|
||||
raise ValueError("Builder backend='%s' not recognized" % backend)
|
||||
|
||||
@@ -245,19 +247,21 @@ class KojiModuleBuilder(GenericBuilder):
|
||||
|
||||
backend = "koji"
|
||||
|
||||
def __init__(self, module, config, tag_name):
|
||||
def __init__(self, owner, module, config, tag_name):
|
||||
"""
|
||||
:param owner: a string representing who kicked off the builds
|
||||
:param module: string representing module
|
||||
:param config: rida.config.Config instance
|
||||
:param tag_name: name of tag for given module
|
||||
"""
|
||||
self.owner = owner
|
||||
self.module_str = module
|
||||
self.tag_name = tag_name
|
||||
self.__prep = False
|
||||
log.debug("Using koji profile %r" % config.koji_profile)
|
||||
log.debug("Using koji_config: %s" % config.koji_config)
|
||||
|
||||
self.koji_session, self.koji_module = self.get_session_from_config(config)
|
||||
self.koji_session = self.get_session(config, owner)
|
||||
self.arches = config.koji_arches
|
||||
if not self.arches:
|
||||
raise ValueError("No koji_arches specified in the config.")
|
||||
@@ -360,15 +364,11 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
|
||||
return srpm_paths[0]
|
||||
|
||||
@staticmethod
|
||||
def get_session_from_config(config):
|
||||
def get_session(config, owner):
|
||||
koji_config = munch.Munch(koji.read_config(
|
||||
profile_name=config.koji_profile,
|
||||
user_config=config.koji_config,
|
||||
))
|
||||
koji_module = koji.get_profile_module(
|
||||
config.koji_profile,
|
||||
config=koji_config,
|
||||
)
|
||||
|
||||
address = koji_config.server
|
||||
log.info("Connecting to koji %r" % address)
|
||||
@@ -384,7 +384,7 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
|
||||
principal=principal,
|
||||
keytab=keytab,
|
||||
ccache=ccache,
|
||||
proxyuser=None,
|
||||
proxyuser=owner,
|
||||
)
|
||||
else:
|
||||
koji_session.krb_login(ccache=ccache)
|
||||
@@ -393,11 +393,12 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
|
||||
os.path.expanduser(koji_config.cert),
|
||||
None,
|
||||
os.path.expanduser(koji_config.serverca),
|
||||
proxyuser=None,
|
||||
proxyuser=owner,
|
||||
)
|
||||
else:
|
||||
raise ValueError("Unrecognized koji authtype %r" % authtype)
|
||||
return (koji_session, koji_module)
|
||||
|
||||
return koji_session
|
||||
|
||||
def buildroot_connect(self):
|
||||
log.info("%r connecting buildroot." % self)
|
||||
|
||||
@@ -70,7 +70,8 @@ def _finalize(config, session, msg, state):
|
||||
# And install the macros.
|
||||
module_name = parent.name
|
||||
tag = parent.koji_tag
|
||||
builder = rida.builder.KojiModuleBuilder(module_name, config, tag_name=tag)
|
||||
builder = rida.builder.Builder(parent.owner, module_name, 'koji',
|
||||
config, tag_name=tag)
|
||||
builder.buildroot_connect()
|
||||
# tag && add to srpm-build group
|
||||
nvr = "{}-{}-{}".format(msg.build_name, msg.build_version,
|
||||
|
||||
@@ -118,7 +118,8 @@ def wait(config, session, msg):
|
||||
log.debug("Assigning koji tag=%s to module build" % tag)
|
||||
build.koji_tag = tag
|
||||
|
||||
builder = rida.builder.KojiModuleBuilder(build.name, config, tag_name=tag)
|
||||
builder = rida.builder.Builder(build.owner, build.name, 'koji', config,
|
||||
tag_name=tag)
|
||||
build.buildroot_task_id = builder.buildroot_connect()
|
||||
log.debug("Adding dependencies %s into buildroot for module %s" % (dependencies, module_info))
|
||||
builder.buildroot_add_repos(dependencies)
|
||||
|
||||
@@ -75,7 +75,8 @@ def done(config, session, msg):
|
||||
log.warn("Odd! All components in batch failed for %r." % module_build)
|
||||
return
|
||||
|
||||
builder = rida.builder.KojiModuleBuilder(module_build.name, config, tag_name=tag)
|
||||
builder = rida.builder.Builder(module_build.owner, module_build.name,
|
||||
'koji', config, tag_name=tag)
|
||||
builder.buildroot_connect()
|
||||
|
||||
# Ok, for the subset of builds that did complete successfully, check to
|
||||
|
||||
@@ -187,7 +187,9 @@ class Poller(threading.Thread):
|
||||
# TODO re-use
|
||||
|
||||
if conf.system == "koji":
|
||||
koji_session, _ = rida.builder.KojiModuleBuilder.get_session_from_config(conf)
|
||||
# we don't do this on behalf of users
|
||||
koji_session = (
|
||||
rida.builder.KojiModuleBuilder.get_session(conf, None))
|
||||
log.info("Querying tasks for statuses:")
|
||||
res = models.ComponentBuild.query.filter_by(state=koji.BUILD_STATES['BUILDING']).all()
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class TestRepoDone(unittest.TestCase):
|
||||
self.fn(config=self.config, session=self.session, msg=msg)
|
||||
|
||||
@mock.patch('rida.builder.KojiModuleBuilder.buildroot_ready')
|
||||
@mock.patch('rida.builder.KojiModuleBuilder.get_session_from_config')
|
||||
@mock.patch('rida.builder.KojiModuleBuilder.get_session')
|
||||
@mock.patch('rida.builder.KojiModuleBuilder.build')
|
||||
@mock.patch('rida.builder.KojiModuleBuilder.buildroot_connect')
|
||||
@mock.patch('rida.models.ModuleBuild.from_repo_done_event')
|
||||
|
||||
Reference in New Issue
Block a user