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)
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)
def osbuildImage(name, version, distro, image_types, target, arches, opts=None, priority=None): """Create an image via osbuild""" context.session.assertPerm("image") args = [name, version, distro, image_types, target, arches, opts] task = {"channel": "image"} try: jsonschema.validate(args, OSBUILD_IMAGE_SCHMEA) except jsonschema.exceptions.ValidationError as err: raise koji.ParameterError(str(err)) from None if priority and priority < 0 and not context.session.hasPerm('admin'): raise koji.ActionNotAllowed('only admins may create high-priority tasks') return kojihub.make_task('osbuildImage', args, **task)
def osbuildImage(name, version, distro, image_types, target, arches, opts=None, priority=None): """Create an image via osbuild""" context.session.assertPerm("image") args = [name, version, distro, image_types, target, arches, opts] task = {"channel": "image"} if priority and priority < 0 and not context.session.hasPerm('admin'): raise koji.ActionNotAllowed( 'only admins may create high-priority tasks') return kojihub.make_task('osbuildImage', args, **task)
def buildContainer(src, target, opts=None, priority=None, channel='container'): """Create a container build task :param str src: The source URI for this container. :param str target: The build target for this container. :param dict opts: Settings for this build, for example "scratch: true". The full list of available options is in builder_containerbuild.py. :param int priority: the amount to increase (or decrease) the task priority, relative to the default priority; higher values mean lower priority; only admins have the right to specify a negative priority here :param str channel: the channel to allocate the task to (defaults to the "container" channel) :returns: the task ID (integer) """ new_opts, taskOpts = _get_task_opts_and_opts(opts, priority, channel) return kojihub.make_task('buildContainer', [src, target, new_opts], **taskOpts)
def saveFailedTree(buildrootID, full=False, **opts): """Create saveFailedTree task If arguments are invalid, error message is returned. Otherwise task id of newly created task is returned.""" global config, allowed_methods # let it raise errors buildrootID = int(buildrootID) full = bool(full) # read configuration only once if config is None: config = six.moves.configparser.SafeConfigParser() config.read(CONFIG_FILE) allowed_methods = config.get('permissions', 'allowed_methods').split() if len(allowed_methods) == 1 and allowed_methods[0] == '*': allowed_methods = '*' brinfo = kojihub.get_buildroot(buildrootID, strict=True) taskID = brinfo['task_id'] task_info = kojihub.Task(taskID).getInfo() if task_info['state'] != koji.TASK_STATES['FAILED']: raise koji.PreBuildError( "Task %s has not failed. Only failed tasks can upload their buildroots." % taskID) elif allowed_methods != '*' and task_info['method'] not in allowed_methods: raise koji.PreBuildError("Only %s tasks can upload their buildroots (Task %s is %s)." % \ (', '.join(allowed_methods), task_info['id'], task_info['method'])) elif task_info[ "owner"] != context.session.user_id and not context.session.hasPerm( 'admin'): raise koji.ActionNotAllowed( "Only owner of failed task or 'admin' can run this task.") elif not kojihub.get_host(task_info['host_id'])['enabled']: raise koji.PreBuildError("Host is disabled.") args = koji.encode_args(buildrootID, full, **opts) taskopts = { 'assign': brinfo['host_id'], } return kojihub.make_task('saveFailedTree', args, **taskopts)
def kiwiBuild(target, arches, desc_url, desc_path, optional_arches=None, profile=None, scratch=False, priority=None): context.session.assertPerm('image') taskOpts = { 'channel': 'image', } if priority: if priority < 0: if not context.session.hasPerm('admin'): raise koji.ActionNotAllowed( 'only admins may create high-priority tasks') taskOpts['priority'] = koji.PRIO_DEFAULT + priority opts = { 'optional_arches': optional_arches, 'profile': profile, 'scratch': scratch, } return kojihub.make_task('kiwiBuild', [target, arches, desc_url, desc_path, opts], **taskOpts)
def buildContainer(src, target, opts=None, priority=None, channel='container'): """Create a container build task :param str src: The source URI for this container. :param str target: The build target for this container. :param dict opts: Settings for this build, for example "scratch: true". The full list of available options is in builder_containerbuild.py. :param int priority: the amount to increase (or decrease) the task priority relative to Koji's default priority. A positive integer will lower the priority of this build, and Koji will process it after other tasks. Alternatively, a negative integer will raise the priority so that Koji processes this ahead of other tasks. Only Koji admins may specify a negative priority. :param str channel: the channel to allocate the task to (defaults to the "container" channel) :returns: the task ID (integer) """ new_opts, taskOpts = _get_task_opts_and_opts(opts, priority, channel) return kojihub.make_task('buildContainer', [src, target, new_opts], **taskOpts)
def saveFailedTree(buildrootID, full=False, **opts): """Create saveFailedTree task If arguments are invalid, error message is returned. Otherwise task id of newly created task is returned.""" global config, allowed_methods # let it raise errors buildrootID = int(buildrootID) full = bool(full) # read configuration only once if config is None: config = six.moves.configparser.SafeConfigParser() config.read(CONFIG_FILE) allowed_methods = config.get('permissions', 'allowed_methods').split() if len(allowed_methods) == 1 and allowed_methods[0] == '*': allowed_methods = '*' brinfo = kojihub.get_buildroot(buildrootID, strict=True) taskID = brinfo['task_id'] task_info = kojihub.Task(taskID).getInfo() if task_info['state'] != koji.TASK_STATES['FAILED']: raise koji.PreBuildError("Task %s has not failed. Only failed tasks can upload their buildroots." % taskID) elif allowed_methods != '*' and task_info['method'] not in allowed_methods: raise koji.PreBuildError("Only %s tasks can upload their buildroots (Task %s is %s)." % \ (', '.join(allowed_methods), task_info['id'], task_info['method'])) elif task_info["owner"] != context.session.user_id and not context.session.hasPerm('admin'): raise koji.ActionNotAllowed("Only owner of failed task or 'admin' can run this task.") elif not kojihub.get_host(task_info['host_id'])['enabled']: raise koji.PreBuildError("Host is disabled.") args = koji.encode_args(buildrootID, full, **opts) taskopts = { 'assign': brinfo['host_id'], } return kojihub.make_task('saveFailedTree', args, **taskopts)
def buildContainer(src, target, opts=None, priority=None, channel='container'): """Create a container build task target: the build target priority: the amount to increase (or decrease) the task priority, relative to the default priority; higher values mean lower priority; only admins have the right to specify a negative priority here channel: the channel to allocate the task to (defaults to the "container" channel) Returns the task ID """ if not opts: opts = {} taskOpts = {} if priority: if priority < 0: if not context.session.hasPerm('admin'): raise koji.ActionNotAllowed('only admins may create' ' high-priority tasks') taskOpts['priority'] = koji.PRIO_DEFAULT + priority if channel: taskOpts['channel'] = channel return kojihub.make_task('buildContainer', [src, target, opts], **taskOpts)