How to use the koji.GenericError function in koji

To help you get started, we’ve selected a few koji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github koji-project / koji / tests / test_hub / test_get_host.py View on Github external
def test_get_host_invalid_hostinfo(self):
        with self.assertRaises(koji.GenericError):
            self.exports.getHost({'host_id': 567})

        self.assertEqual(len(self.queries), 0)
github koji-project / koji / tests / test_hub / test_get_archive_file.py View on Github external
def test_non_existing_file(self, list_archive_files):
        list_archive_files.return_value = FILES

        rv = kojihub.get_archive_file(1, 'archive3.xml')
        list_archive_files.assert_called_with(1, strict=False)
        self.assertEqual(rv, None)

        list_archive_files.reset_mock()

        with self.assertRaises(koji.GenericError) as cm:
            kojihub.get_archive_file(1, 'archive3.xml', strict=True)
        list_archive_files.assert_called_with(1, strict=True)
        self.assertEqual(cm.exception.args[0], 'No such file: archive3.xml in archive#1')
github koji-project / koji / tests / test_hub / test_edit_host.py View on Github external
def test_edit_host_missing(self):
        kojihub.get_host = mock.MagicMock()
        kojihub.get_host.side_effect = koji.GenericError
        with self.assertRaises(koji.GenericError):
            self.exports.editHost('hostname')
        kojihub.get_host.assert_called_once_with('hostname', strict=True)
        self.assertEqual(self.inserts, [])
        self.assertEqual(self.updates, [])
github koji-project / koji / www / kojiweb / wsgi_publisher.py View on Github external
#determine log level
        level = opts['LogLevel']
        valid_levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
        # the config value can be a single level name or a series of
        # logger:level names pairs. processed in order found
        default = None
        for part in level.split():
            pair = part.split(':', 1)
            if len(pair) == 2:
                name, level = pair
            else:
                name = 'koji'
                level = part
                default = level
            if level not in valid_levels:
                raise koji.GenericError("Invalid log level: %s" % level)
            #all our loggers start with koji
            if name == '':
                name = 'koji'
                default = level
            elif name.startswith('.'):
                name = 'koji' + name
            elif not name.startswith('koji'):
                name = 'koji.' + name
            level_code = logging._levelNames[level]
            logging.getLogger(name).setLevel(level_code)
        logger = logging.getLogger("koji")
        # if KojiDebug is set, force main log level to DEBUG
        if opts.get('KojiDebug'):
            logger.setLevel(logging.DEBUG)
        elif default is None:
            #LogLevel did not configure a default level
github koji-project / koji / koji / tasks.py View on Github external
def handler(self, wait_list, task_list):
        for task in wait_list:
            if not isinstance(task, int) or not self.session.getTaskInfo(task):
                self.logger.debug("invalid task id %s, removing from wait_list" % task)
                wait_list.remove(task)

        # note, tasks in wait_list are not children of this task so we can't
        # just use self.wait()
        while wait_list:
            for task in wait_list[:]:
                if self.session.taskFinished(task):
                    info = self.session.getTaskInfo(task)
                    if info and koji.TASK_STATES[info['state']] in ['CANCELED', 'FAILED']:
                        raise koji.GenericError("Dependency %s failed to complete." % info['id'])
                    wait_list.remove(task)
            # let the system rest before polling again
            time.sleep(1)

        subtasks = []
        for task in task_list:
            # **((len(task)>2 and task[2]) or {}) expands task[2] into opts if it exists, allows for things like 'priority=15'
            task_id = self.session.host.subtask(method=task[0], arglist=task[1], parent=self.id, **((len(task) > 2 and task[2]) or {}))
            if task_id:
                subtasks.append(task_id)
        if subtasks:
            self.wait(subtasks, all=True)
github koji-project / koji / plugins / builder / runroot.py View on Github external
def _get_path_params(self, path, rw=False):
        found = False
        for mount_data in self.config['paths']:
            if path.startswith(mount_data['mountpoint']):
                found = True
                break
        if not found:
            raise koji.GenericError("bad config: missing corresponding mountpoint")
        options = []
        for o in mount_data['options'].split(','):
            if rw and o == 'ro':
                options.append('rw')
            else:
                options.append(o)
        rel_path = path[len(mount_data['mountpoint']):]
        rel_path = rel_path[1:] if rel_path.startswith('/') else rel_path
        res = (os.path.join(mount_data['path'], rel_path), path, mount_data['fstype'], ','.join(options))
        return res
github koji-project / koji / koji / tasks.py View on Github external
def handler(self, task_id, host):
        #note: this is a foreground task
        tinfo = self.session.getTaskInfo(task_id)
        state = koji.TASK_STATES[tinfo['state']]
        if state != 'CLOSED':
            raise koji.GenericError("Stage one restart task is %s" % state)
        if host['id'] != self.session.host.getID():
            raise koji.GenericError("Host mismatch")
        if self.manager.start_time < tinfo['completion_ts']:
            start_time = time.asctime(time.localtime(self.manager.start_time))
            raise koji.GenericError("Restart failed - start time is %s" % start_time)
github koji-project / koji / plugins / cli / save_failed_tree.py View on Github external
activate_session(session, options)

    if opts.mode == "buildroot":
        br_id = id_val
    else:
        brs = [b['id'] for b in session.listBuildroots(taskID=id_val)]
        if not brs:
            print(_("No buildroots for task %s") % id_val)
            return 1
        br_id = max(brs)
        if len(brs) > 1:
            print(_("Multiple buildroots for task. Choosing last one (%s)") % br_id)

    try:
        task_id = session.saveFailedTree(br_id, opts.full)
    except koji.GenericError as e:
        m = str(e)
        if 'Invalid method' in m:
            print(_("* The save_failed_tree plugin appears to not be "
                    "installed on the koji hub.  Please contact the "
                    "administrator."))
            return 1
        raise

    if not opts.quiet:
        print(_("Created task %s for buildroot %s") % (task_id, br_id))
        print("Task info: %s/taskinfo?taskID=%s"
                % (options.weburl, task_id))

    if opts.nowait:
        return
    else:
github koji-project / koji / www / kojiweb / index.py View on Github external
def buildtargetdelete(environ, targetID):
    server = _getServer(environ)
    _assertLogin(environ)

    targetID = int(targetID)

    target = server.getBuildTarget(targetID)
    if target == None:
        raise koji.GenericError('invalid build target: %i' % targetID)

    server.deleteBuildTarget(target['id'])

    _redirect(environ, 'buildtargets')
github koji-project / koji / koji / tasks.py View on Github external
def umount_all(topdir):
    "Unmount every mount under topdir"
    logger = logging.getLogger("koji.build")
    for path in scan_mounts(topdir):
        logger.debug('Unmounting %s' % path)
        cmd = ['umount', '-l', path]
        rv = os.spawnvp(os.P_WAIT, cmd[0], cmd)
        if rv != 0:
            raise koji.GenericError('umount failed (exit code %r) for %s' % (rv, path))
    #check mounts again
    remain = scan_mounts(topdir)
    if remain:
        raise koji.GenericError("Unmounting incomplete: %r" % remain)