Repository: fedora-infra/bodhi

Issue:
Koji kerberos argument must be str, not unicode
The Bodhi staging environment is upset about being given a unicode parameter for one of Koji's krb settings:

```
2017-06-19 14:04:52,668 ERROR [bodhi.server][MainThread] Error caught.  Handling HTML response.
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/usr/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 99, in tm_tween
    reraise(*exc_info)
  File "/usr/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 80, in tm_tween
    response = handler(request)
  File "/usr/lib/python2.7/site-packages/pyramid/router.py", line 163, in handle_request
    response = view_callable(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/config/views.py", line 596, in __call__
    return view(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/config/views.py", line 329, in attr_view
    return view(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/config/views.py", line 305, in predicate_wrapper
    return view(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/config/views.py", line 245, in _secured_view
    return view(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/config/views.py", line 355, in rendered_view
    result = view(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/config/views.py", line 501, in _requestonly_view
    response = view(request)
  File "/usr/lib/python2.7/site-packages/cornice/service.py", line 564, in wrapper
    validator(request)
  File "/usr/lib/python2.7/site-packages/bodhi/server/validators.py", line 90, in validate_nvrs
    cache_nvrs(request, build)
  File "/usr/lib/python2.7/site-packages/bodhi/server/validators.py", line 84, in cache_nvrs
    request.buildinfo[build]['info'] = request.koji.getBuild(build)
  File "/usr/lib/python2.7/site-packages/pyramid/decorator.py", line 37, in __get__
    val = self.wrapped(inst)
  File "/usr/lib/python2.7/site-packages/pyramid/util.py", line 52, in <lambda>
    fn = lambda this: callable(this)
  File "/usr/lib/python2.7/site-packages/bodhi/server/__init__.py", line 96, in get_koji
    return buildsys.get_session()
  File "/usr/lib/python2.7/site-packages/bodhi/server/buildsys.py", line 416, in get_session
    return _buildsystem()
  File "/usr/lib/python2.7/site-packages/bodhi/server/buildsys.py", line 439, in get_koji_login
    return koji_login(config=settings)
  File "/usr/lib/python2.7/site-packages/bodhi/server/buildsys.py", line 390, in koji_login
    if not koji_client.krb_login(**get_krb_conf(config)):
  File "/usr/lib/python2.7/site-packages/koji/__init__.py", line 2070, in krb_login
    ccache = krbV.CCache(name='FILE:' + ccache, context=ctx)
TypeError: __init__() argument 2 must be string, not unicode
```

This is due to the recent configuration refactor I did. We just need to make sure Koji krb settings are strs instead of unicodes.


Discussion:

Resolving patch:
diff --git a/bodhi/server/config.py b/bodhi/server/config.py
--- a/bodhi/server/config.py
+++ b/bodhi/server/config.py
@@ -409,16 +409,16 @@ class BodhiConfig(dict):
             'validator': unicode},
         'koji_hub': {
             'value': 'https://koji.stg.fedoraproject.org/kojihub',
-            'validator': unicode},
+            'validator': str},
         'krb_ccache': {
             'value': None,
-            'validator': _validate_none_or(unicode)},
+            'validator': _validate_none_or(str)},
         'krb_keytab': {
             'value': None,
-            'validator': _validate_none_or(unicode)},
+            'validator': _validate_none_or(str)},
         'krb_principal': {
             'value': None,
-            'validator': _validate_none_or(unicode)},
+            'validator': _validate_none_or(str)},
         'libravatar_dns': {
             'value': False,
             'validator': _validate_bool},


Test patch:
diff --git a/bodhi/tests/server/test_config.py b/bodhi/tests/server/test_config.py
--- a/bodhi/tests/server/test_config.py
+++ b/bodhi/tests/server/test_config.py
@@ -202,6 +202,33 @@ def test_comps_unsafe_http_url(self):
         self.assertEqual(str(exc.exception), ('Invalid config values were set: \n\tcomps_url: This '
                                               'setting must be a URL starting with https://.'))
 
+    def test_koji_settings_are_strs(self):
+        """
+        Ensure that the koji related settings are strings.
+
+        This test ensures that #1624[0] stays fixed.
+
+        [0] https://github.com/fedora-infra/bodhi/issues/1624
+        """
+        c = config.BodhiConfig()
+        c.load_config()
+        # Let's set all of these to unicodes, and we'll assert that they get turned into strs.
+        c['koji_hub'] = u'http://example.com/kojihub'
+        c['krb_ccache'] = u'/tmp/krb5cc_%{uid}'
+        c['krb_keytab'] = u'/etc/krb5.bodhi.keytab'
+        c['krb_principal'] = u'bodhi/bodhi@FEDORAPROJECT.ORG'
+
+        # This should not raise an Exception, but it should convert the above to strs.
+        c._validate()
+
+        for k in ('koji_hub', 'krb_ccache', 'krb_keytab', 'krb_principal'):
+            self.assertEqual(type(c[k]), str)
+        # And the values should match what we did above.
+        self.assertEqual(c['koji_hub'], 'http://example.com/kojihub')
+        self.assertEqual(c['krb_ccache'], '/tmp/krb5cc_%{uid}')
+        self.assertEqual(c['krb_keytab'], '/etc/krb5.bodhi.keytab')
+        self.assertEqual(c['krb_principal'], 'bodhi/bodhi@FEDORAPROJECT.ORG')
+
     def test_valid_config(self):
         """A valid config should not raise Exceptions."""
         c = config.BodhiConfig()