Repository: fedora-infra/bodhi

Issue:
koji 1.22 doesn't support krb_login, it supports gssapi_login
Please make the changes needed to support gssapi_login.


Discussion:
Does this need anything special other than change krb_login() call to gssapi_login()?
I can't see any docstring under gssapi_login().
> Does this need anything special other than change krb_login() call to gssapi_login()?
> I can't see any docstring under gssapi_login().

I am trying that currently in staging and it seems to fail with 
```
from bodhi.server.config import config
from bodhi.server import bugs, buildsys
config.load_config()
buildsys.setup_buildsystem(config)
kc = buildsys.get_session()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/bodhi/server/buildsys.py", line 694, in get_session
    return _buildsystem()
  File "/usr/lib/python3.8/site-packages/bodhi/server/buildsys.py", line 726, in get_koji_login
    return koji_login(config=settings, authenticate=authenticate)
  File "/usr/lib/python3.8/site-packages/bodhi/server/buildsys.py", line 650, in koji_login
    if authenticate and not koji_client.gssapi_login(**get_krb_conf(config)):
  File "/usr/lib/python3.8/site-packages/koji/__init__.py", line 2572, in gssapi_login
    raise AuthError('unable to obtain a session')
koji.AuthError: unable to obtain a session
>>> 
```

So that will need a bit more investigation
Ok seems to have been a issue with the hosts I was using, just replacing with gssapi_login seems to work fine.

Resolving patch:
diff --git a/bodhi/server/buildsys.py b/bodhi/server/buildsys.py
--- a/bodhi/server/buildsys.py
+++ b/bodhi/server/buildsys.py
@@ -647,14 +647,14 @@ def koji_login(config: 'BodhiConfig', authenticate: bool) -> koji.ClientSession:
     }
 
     koji_client = koji.ClientSession(_koji_hub, koji_options)
-    if authenticate and not koji_client.krb_login(**get_krb_conf(config)):
-        log.error('Koji krb_login failed')
+    if authenticate and not koji_client.gssapi_login(**get_krb_conf(config)):
+        log.error('Koji gssapi_login failed')
     return koji_client
 
 
 def get_krb_conf(config: 'BodhiConfig') -> typing.Mapping[str, str]:
     """
-    Return arguments for krb_login.
+    Return arguments for gssapi_login.
 
     Args:
         config: Bodhi's configuration dictionary.


Test patch:
diff --git a/bodhi/tests/server/test_buildsys.py b/bodhi/tests/server/test_buildsys.py
--- a/bodhi/tests/server/test_buildsys.py
+++ b/bodhi/tests/server/test_buildsys.py
@@ -105,12 +105,12 @@ class TestKojiLogin:
     """This class contains tests for the koji_login() function."""
 
     @mock.patch.object(buildsys, '_koji_hub', 'http://example.com/koji')
-    @mock.patch('bodhi.server.buildsys.koji.ClientSession.krb_login')
+    @mock.patch('bodhi.server.buildsys.koji.ClientSession.gssapi_login')
     @mock.patch('bodhi.server.buildsys.log.error')
     @mock.patch('time.sleep')
-    def test_AuthError(self, sleep, error, krb_login):
+    def test_AuthError(self, sleep, error, gssapi_login):
         """backoff should take effect if an AuthError is raised."""
-        krb_login.side_effect = [koji.AuthError, koji.AuthError, True]
+        gssapi_login.side_effect = [koji.AuthError, koji.AuthError, True]
         config = {'some_meaningless_other_key': 'boring_value', 'krb_ccache': 'a_ccache',
                   'krb_keytab': 'a_keytab', 'krb_principal': 'a_principal'}
         default_koji_opts = {
@@ -127,8 +127,8 @@ def test_AuthError(self, sleep, error, krb_login):
         for key in default_koji_opts:
             assert default_koji_opts[key] == client.opts[key]
         assert type(client) == koji.ClientSession
-        # Due to the use of backoff, we should have called krb_login three times.
-        assert krb_login.mock_calls == (
+        # Due to the use of backoff, we should have called gssapi_login three times.
+        assert gssapi_login.mock_calls == (
             [mock.call(ccache='a_ccache', keytab='a_keytab', principal='a_principal')] * 3)
         # No error should have been logged
         assert error.call_count == 0
@@ -138,10 +138,10 @@ def test_AuthError(self, sleep, error, krb_login):
         assert sleep.call_count == 2
 
     @mock.patch.object(buildsys, '_koji_hub', 'http://example.com/koji')
-    @mock.patch('bodhi.server.buildsys.koji.ClientSession.krb_login')
+    @mock.patch('bodhi.server.buildsys.koji.ClientSession.gssapi_login')
     @mock.patch('bodhi.server.buildsys.log.error')
-    def test_authenticate_false(self, error, krb_login):
-        """If authenticate is False, no attempt to call krb_login() shold be made."""
+    def test_authenticate_false(self, error, gssapi_login):
+        """If authenticate is False, no attempt to call gssapi_login() shold be made."""
         config = {'some_meaningless_other_key': 'boring_value', 'krb_ccache': 'a_ccache',
                   'krb_keytab': 'a_keytab', 'krb_principal': 'a_principal'}
         default_koji_opts = {
@@ -159,34 +159,34 @@ def test_authenticate_false(self, error, krb_login):
             assert default_koji_opts[key] == client.opts[key]
         assert type(client) == koji.ClientSession
         # Since authenticate was False, the login should not have happened.
-        assert krb_login.call_count == 0
+        assert gssapi_login.call_count == 0
         # No error should have been logged
         assert error.call_count == 0
 
-    # krb_login returns a bool to indicate success or failure
+    # gssapi_login returns a bool to indicate success or failure
     @mock.patch.object(buildsys, '_koji_hub', 'http://example.com/koji')
-    @mock.patch('bodhi.server.buildsys.koji.ClientSession.krb_login')
+    @mock.patch('bodhi.server.buildsys.koji.ClientSession.gssapi_login')
     @mock.patch('bodhi.server.buildsys.log.error')
-    def test_login_failure(self, error, krb_login):
+    def test_login_failure(self, error, gssapi_login):
         """Assert correct behavior for a failed login event."""
-        krb_login.return_value = False
+        gssapi_login.return_value = False
         config = {'some_meaningless_other_key': 'boring_value', 'krb_ccache': 'a_ccache',
                   'krb_keytab': 'a_keytab', 'krb_principal': 'a_principal'}
 
         client = buildsys.koji_login(config, authenticate=True)
 
         assert type(client) == koji.ClientSession
-        krb_login.assert_called_once_with(ccache='a_ccache', keytab='a_keytab',
-                                          principal='a_principal')
-        error.assert_called_once_with('Koji krb_login failed')
+        gssapi_login.assert_called_once_with(ccache='a_ccache', keytab='a_keytab',
+                                             principal='a_principal')
+        error.assert_called_once_with('Koji gssapi_login failed')
 
-    # krb_login returns a bool to indicate success or failure
+    # gssapi_login returns a bool to indicate success or failure
     @mock.patch.object(buildsys, '_koji_hub', 'http://example.com/koji')
-    @mock.patch('bodhi.server.buildsys.koji.ClientSession.krb_login')
+    @mock.patch('bodhi.server.buildsys.koji.ClientSession.gssapi_login')
     @mock.patch('bodhi.server.buildsys.log.error')
-    def test_login_success(self, error, krb_login):
+    def test_login_success(self, error, gssapi_login):
         """Assert correct behavior for a successful login event."""
-        krb_login.return_value = True
+        gssapi_login.return_value = True
         config = {'some_meaningless_other_key': 'boring_value', 'krb_ccache': 'a_ccache',
                   'krb_keytab': 'a_keytab', 'krb_principal': 'a_principal'}
         default_koji_opts = {
@@ -203,8 +203,8 @@ def test_login_success(self, error, krb_login):
         for key in default_koji_opts:
             assert default_koji_opts[key] == client.opts[key]
         assert type(client) == koji.ClientSession
-        krb_login.assert_called_once_with(ccache='a_ccache', keytab='a_keytab',
-                                          principal='a_principal')
+        gssapi_login.assert_called_once_with(ccache='a_ccache', keytab='a_keytab',
+                                             principal='a_principal')
         # No error should have been logged
         assert error.call_count == 0
 
@@ -231,8 +231,8 @@ class TestSetupBuildsystem:
     """Tests :func:`bodhi.server.buildsys.setup_buildsystem` function"""
 
     @mock.patch('bodhi.server.buildsys._buildsystem', None)
-    @mock.patch('bodhi.server.buildsys.koji.ClientSession.krb_login')
-    def test_authenticate_false(self, krb_login):
+    @mock.patch('bodhi.server.buildsys.koji.ClientSession.gssapi_login')
+    def test_authenticate_false(self, gssapi_login):
         """If authenticate is set to False, the Koji client should should be unauthenticated."""
         config = {
             'krb_ccache': 'a_ccache', 'krb_keytab': 'a_keytab', 'krb_principal': 'a_principal',
@@ -241,13 +241,13 @@ def test_authenticate_false(self, krb_login):
 
         buildsys.setup_buildsystem(config, authenticate=False)
 
-        # Instantiating the buildsystem should not cause a krb_login to happen.
+        # Instantiating the buildsystem should not cause a gssapi_login to happen.
         buildsys._buildsystem()
-        assert krb_login.call_count == 0
+        assert gssapi_login.call_count == 0
 
     @mock.patch('bodhi.server.buildsys._buildsystem', None)
-    @mock.patch('bodhi.server.buildsys.koji.ClientSession.krb_login')
-    def test_authenticate_true(self, krb_login):
+    @mock.patch('bodhi.server.buildsys.koji.ClientSession.gssapi_login')
+    def test_authenticate_true(self, gssapi_login):
         """If authenticate is set to True, the Koji client should should be authenticated."""
         config = {
             'krb_ccache': 'a_ccache', 'krb_keytab': 'a_keytab', 'krb_principal': 'a_principal',
@@ -256,10 +256,10 @@ def test_authenticate_true(self, krb_login):
 
         buildsys.setup_buildsystem(config, authenticate=True)
 
-        # Instantiating the buildsystem should cause a krb_login to happen.
+        # Instantiating the buildsystem should cause a gssapi_login to happen.
         buildsys._buildsystem()
-        krb_login.assert_called_once_with(ccache='a_ccache', keytab='a_keytab',
-                                          principal='a_principal')
+        gssapi_login.assert_called_once_with(ccache='a_ccache', keytab='a_keytab',
+                                             principal='a_principal')
 
     @mock.patch('bodhi.server.buildsys._buildsystem', mock.Mock())
     def test_initialized_buildsystem(self):
diff --git a/bodhi/tests/server/test_push.py b/bodhi/tests/server/test_push.py
--- a/bodhi/tests/server/test_push.py
+++ b/bodhi/tests/server/test_push.py
@@ -1178,8 +1178,8 @@ class TetUpdateSigStatus(base.BasePyTestCase):
     @mock.patch.dict('bodhi.server.push.config',
                      {'buildsystem': 'koji', 'koji_hub': 'https://example.com/koji'})
     @mock.patch('bodhi.server.buildsys._buildsystem', None)
-    @mock.patch('bodhi.server.buildsys.koji.ClientSession.krb_login')
-    def test_sets_up_buildsys_without_auth(self, krb_login):
+    @mock.patch('bodhi.server.buildsys.koji.ClientSession.gssapi_login')
+    def test_sets_up_buildsys_without_auth(self, gssapi_login):
         """
         bodhi-push should not set up authentication for the build system.
 
@@ -1189,4 +1189,4 @@ def test_sets_up_buildsys_without_auth(self, krb_login):
 
         push.update_sig_status(u)
 
-        assert krb_login.call_count == 0
+        assert gssapi_login.call_count == 0