def stress(errors, n): errors[n] = "Failed to start" try: koji.get_profile_module('koji') except Exception: # if we don't catch this, nose seems to ignore the test errors[n] = ''.join(traceback.format_exception(*sys.exc_info())) return else: errors[n] = None
def stress(errors, n): errors[n] = "Failed to start" try: config = mock.Mock(topdir='topdir') koji.get_profile_module('koji', config=config) except Exception: # if we don't catch this, pytest seems to ignore the test errors[n] = ''.join(traceback.format_exception(*sys.exc_info())) return else: errors[n] = None
def __init__(self, arch=None): if arch: self.kojihub = arch else: self.kojihub = "koji" self.koji_module = koji.get_profile_module(self.kojihub) self.kojisession = self.koji_module.ClientSession(self.koji_module.config.server, {'krb_rdns': False}) self.kojisession.ssl_login(CLIENTCERT)
def get_koji_session(): # pragma: no cover """ Generate a Koji session. :return: a Koji session :rtype: koji.ClientSession """ profile = koji.get_profile_module(config.koji_profile) return koji.ClientSession(profile.config.server)
def __init__(self, koji_profile, rpmsign_class, logger=None, log_level=logging.INFO): # noqa: D102 self.koji_profile = koji_profile self.koji_module = koji.get_profile_module(self.koji_profile) self.koji_session = koji.ClientSession(self.koji_module.config.server) self.rpmsign_class = rpmsign_class self._get_rpm_sighdr_sigkey_cache = {} self.logger = logger or get_logger(self, log_level) if self.koji_module.config.authtype == "kerberos": self.koji_session.krb_login()
def get_session(profile): """ Return an authenticated Koji session """ # Return a cached session, if available. mykoji = koji.get_profile_module(profile) opts = mykoji.grab_session_options(mykoji.config) session = mykoji.ClientSession(mykoji.config.server, opts) # Log in ("activate") this sesssion: # Note: this can raise SystemExit if there is a problem, eg with Kerberos: activate_session(session, mykoji.config) assert session.logged_in userinfo = session.getLoggedInUser() username = userinfo['name'] log.info('authenticated to %s as %s' % (mykoji.config.server, username)) return session
def get_session(profile): """ Return an anonymous koji session for KOJI_PROFILE. :profile str: eg "cbs" :returns: anonymous koji.ClientSession """ mykoji = koji.get_profile_module(profile) # Workaround https://pagure.io/koji/issue/1022 . Koji 1.17 will not need # this. if '~' in str(mykoji.config.cert): mykoji.config.cert = os.path.expanduser(mykoji.config.cert) if '~' in str(mykoji.config.ca): mykoji.config.ca = os.path.expanduser(mykoji.config.ca) opts = vars(mykoji.config) # Force an anonymous session (noauth): opts['noauth'] = True session = mykoji.ClientSession(mykoji.config.server, opts) return session
def get_session(profile): """ Return an anonymous koji session for this profile name. :param str profile: profile name, like "koji" or "cbs". If None, we will use a profile name from the "KOJI_PROFILE" environment variable. :returns: anonymous koji.ClientSession """ profile = get_profile_name(profile) # Note, get_profile_module() raises koji.ConfigurationError if we # could not find this profile's name in /etc/koji.conf.d/*.conf and # ~/.koji/config.d/*.conf. mykoji = koji.get_profile_module(profile) # Workaround https://pagure.io/koji/issue/1022 . Koji 1.17 will not need # this. if '~' in str(mykoji.config.cert): mykoji.config.cert = os.path.expanduser(mykoji.config.cert) if '~' in str(mykoji.config.ca): mykoji.config.ca = os.path.expanduser(mykoji.config.ca) # Note, Koji has a grab_session_options() method that can also create a # stripped-down dict of our module's (OptParse) configuration, like: # opts = mykoji.grab_session_options(mykoji.config) # The idea is that callers then pass that opts dict into ClientSession's # constructor. # There are two reasons we don't use that here: # 1. The dict is only suitable for the ClientSession(..., opts), not for # activate_session(..., opts). activate_session() really wants the full # set of key/values in mykoji.config. # 2. We may call activate_session() later outside of this method, so we # need to preserve all the configuration data from mykoji.config inside # the ClientSession object. We might as well just store it in the # ClientSession's .opts and then pass that into activate_session(). opts = vars(mykoji.config) # Force an anonymous session (noauth): opts['noauth'] = True session = mykoji.ClientSession(mykoji.config.server, opts) # activate_session with noauth will simply ensure that we can connect with # a getAPIVersion RPC. Let's avoid it here because it just slows us down. # activate_session(session, opts) return session
def list_builds_from_tag(tag, koji_profile): """ Get builds from a Koji tag passed as argument. A Koji profile can also be passed as argument. Returns a dictionary (build name, (version, tag)) """ builds = {} try: koji_module = koji.get_profile_module(koji_profile) except Exception as e: print('Error: could not load the koji profile ({})'.format(e)) sys.exit(1) client = koji_module.ClientSession(koji_module.config.server) try: for _b in client.listTagged(tag): builds[_b['name']] = {'version': _b['version'], 'tag': _b['tag_name']} except Exception as e: print('Error: could not list builds ({})'.format(e)) sys.exit(1) tag_builds[tag] = builds return builds
def __init__(self, profile): self.profile = profile mykoji = koji.get_profile_module(profile) opts = vars(mykoji.config) self.session = mykoji.ClientSession(mykoji.config.server, opts)
def get_koji_session(profile): mykoji = koji.get_profile_module(profile) opts = mykoji.grab_session_options(mykoji.config) return mykoji.ClientSession(mykoji.config.server, opts)
def koji_session() -> koji.ClientSession: module = koji.get_profile_module("koji") session_opts = koji.grab_session_options(module.config) session = koji.ClientSession(module.config.server, session_opts) return session