From 91b306e108929589be5f2c1e02d2c39807cd5520 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Apr 02 2018 20:38:27 +0000 Subject: Avoid failing at import time if krbV module is missing Several parts of Koji already handled this absence gracefully. This change extends that behavior to all places where krbV is imported. --- diff --git a/builder/kojid b/builder/kojid index 726d535..5149ce5 100755 --- a/builder/kojid +++ b/builder/kojid @@ -24,7 +24,7 @@ try: import krbV except ImportError: # pragma: no cover - pass + krbV = None import koji import koji.plugin import koji.util @@ -5782,7 +5782,7 @@ if __name__ == "__main__": quit("Error: Unable to log in. Bad credentials?") except xmlrpclib.ProtocolError: quit("Error: Unable to connect to server %s" % (options.server)) - elif 'krbV' in sys.modules: + elif krbV and 'krbV' in sys.modules: krb_principal = options.krb_principal if krb_principal is None: krb_principal = options.host_principal_format % socket.getfqdn() diff --git a/plugins/hub/messagebus.py b/plugins/hub/messagebus.py index 1e208c4..a45561c 100644 --- a/plugins/hub/messagebus.py +++ b/plugins/hub/messagebus.py @@ -14,7 +14,10 @@ import qpid.messaging.transports from ssl import wrap_socket import socket import os -import krbV +try: + import krbV +except ImportError: # pragma: no cover + krbV = None MAX_KEY_LENGTH = 255 CONFIG_FILE = '/etc/koji-hub/plugins/messagebus.conf' @@ -105,6 +108,9 @@ def get_sender(): url += config.get('broker', 'username') + '/' url += config.get('broker', 'password') + '@' elif auth == 'GSSAPI': + if krbV is None: + # TODO: port this to python-gssapi + raise PluginError('krbV module not installed') ccname = 'MEMORY:messagebus' os.environ['KRB5CCNAME'] = ccname ctx = krbV.default_context() diff --git a/util/koji-gc b/util/koji-gc index 89cc492..ae48648 100755 --- a/util/koji-gc +++ b/util/koji-gc @@ -9,7 +9,7 @@ try: import krbV except ImportError: # pragma: no cover - pass + krbV = None import koji from koji.util import LazyDict, LazyValue import koji.policy @@ -345,7 +345,7 @@ def ensure_connection(session): warn(_("WARNING: The server is at API version %d and the client is at %d" % (ret, koji.API_VERSION))) def has_krb_creds(): - if 'krbV' not in sys.modules: + if krbV is None or 'krbV' not in sys.modules: return False try: ctx = krbV.default_context() diff --git a/util/koji-shadow b/util/koji-shadow index a958c9c..d53f19d 100755 --- a/util/koji-shadow +++ b/util/koji-shadow @@ -25,7 +25,7 @@ try: import krbV except ImportError: # pragma: no cover - pass + krbV = None import koji import ConfigParser import fnmatch @@ -320,7 +320,7 @@ def activate_session(session): elif options.user: #authenticate using user/password session.login() - elif 'krbV' in sys.modules: + elif krbV and 'krbV' in sys.modules: try: if options.keytab and options.principal: session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=options.runas) diff --git a/vm/kojivmd b/vm/kojivmd index 41789ec..d2c1d9d 100755 --- a/vm/kojivmd +++ b/vm/kojivmd @@ -48,7 +48,7 @@ from optparse import OptionParser try: import krbV except ImportError: # pragma: no cover - pass + krbV = None # Register libvirt handler @@ -1099,7 +1099,7 @@ if __name__ == "__main__": quit("Error: Unable to log in. Bad credentials?") except xmlrpclib.ProtocolError: quit("Error: Unable to connect to server %s" % (options.server)) - elif 'krbV' in sys.modules: + elif krbV and 'krbV' in sys.modules: krb_principal = options.krb_principal if krb_principal is None: krb_principal = options.host_principal_format % socket.getfqdn()