commit 2cba56ed214642d467d02eb9954e2d3b22d21471
Author: Nicolas Chauvet <kwizart(a)gmail.com>
Date: Wed Nov 9 12:02:31 2016 +0100
Enable runroot_hub koji_hub plugin
roles/koji_hub/files/runroot_hub.py | 62 ++++++++++++++++++++++++++++++++++
roles/koji_hub/tasks/main.yml | 6 +++
roles/koji_hub/templates/hub.conf.j2 | 1 +
3 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/roles/koji_hub/files/runroot_hub.py b/roles/koji_hub/files/runroot_hub.py
new file mode 100644
index 0000000..3238739
--- /dev/null
+++ b/roles/koji_hub/files/runroot_hub.py
@@ -0,0 +1,62 @@
+#koji hub plugin
+# There is a kojid plugin that goes with this hub plugin. The kojid builder
+# plugin has a config file. This hub plugin has no config file.
+
+
+from koji.context import context
+from koji.plugin import export
+import koji
+import random
+import sys
+
+#XXX - have to import kojihub for make_task
+sys.path.insert(0, '/usr/share/koji-hub/')
+import kojihub
+
+__all__ = ('runroot',)
+
+
+def get_channel_arches(channel):
+ """determine arches available in channel"""
+ chan = context.handlers.call('getChannel', channel, strict=True)
+ ret = {}
+ for host in context.handlers.call('listHosts', channelID=chan['id'],
enabled=True):
+ for a in host['arches'].split():
+ ret[koji.canonArch(a)] = 1
+ return ret
+
+@export
+def runroot(tagInfo, arch, command, channel=None, **opts):
+ """ Create a runroot task """
+ context.session.assertPerm('runroot')
+ taskopts = {
+ 'priority': 15,
+ 'arch': arch,
+ }
+
+ taskopts['channel'] = channel or 'runroot'
+
+ if arch == 'noarch':
+ #not all arches can generate a proper buildroot for all tags
+ tag = kojihub.get_tag(tagInfo)
+ if not tag['arches']:
+ raise koji.GenericError, 'no arches defined for tag %s' %
tag['name']
+
+ #get all known arches for the system
+ fullarches = kojihub.get_all_arches()
+
+ tagarches = tag['arches'].split()
+
+ # If our tag can't do all arches, then we need to
+ # specify one of the arches it can do.
+ if set(fullarches) - set(tagarches):
+ chanarches = get_channel_arches(taskopts['channel'])
+ choices = [x for x in tagarches if x in chanarches]
+ if not choices:
+ raise koji.GenericError, 'no common arches for tag/channel:
%s/%s' \
+ % (tagInfo, taskopts['channel'])
+ taskopts['arch'] = koji.canonArch(random.choice(choices))
+
+ args = koji.encode_args(tagInfo, arch, command,**opts)
+ return kojihub.make_task('runroot', args, **taskopts)
+
diff --git a/roles/koji_hub/tasks/main.yml b/roles/koji_hub/tasks/main.yml
index f95fef4..1bbfcdf 100644
--- a/roles/koji_hub/tasks/main.yml
+++ b/roles/koji_hub/tasks/main.yml
@@ -25,6 +25,12 @@
- config
- koji_hub
+- name: install the runroot_hub.py
+ copy: src=runroot_hub.py dest=/etc/koji-hub/plugins/runroot_hub.py owner=root
mode=0644
+ tags:
+ - config
+ - koji_hub
+
- name: make koji pki directory
file: state=directory path=/etc/pki/koji/ owner=root group=root
diff --git a/roles/koji_hub/templates/hub.conf.j2 b/roles/koji_hub/templates/hub.conf.j2
index 661ba67..55d6aeb 100644
--- a/roles/koji_hub/templates/hub.conf.j2
+++ b/roles/koji_hub/templates/hub.conf.j2
@@ -65,6 +65,7 @@ DisableNotifications = False
#Plugins = koji-disable-builds-plugin
#Plugins = darkserver-plugin
#Plugins = fedmsg-koji-plugin runroot_hub hub_containerbuild
+Plugins = runroot_hub
#
{% if inventory_hostname.startswith('koji') %}
Show replies by date