#166 Support Python 3
Closed: Fixed 5 years ago Opened 5 years ago by lholecek.

Looks like tw2.jit package does not support Python 3. It's an indirect dependency for moksha.wsgi (which is needed by moksha). (Edit: Only moksha.hub is required which works fine with Python 3.)

After a workaround for that package [1] and a small fix in tests, it's at least possible to run TEST=true py.test greenwave successfully.

[1] I've installed the package manually from git repo after converting code with 2to3 and replacing BeautifulSoup package with beautifulsoup4 (bs4 module). Thought tests for the package fail.


Hmm, moksha is not used directly anywhere in Greenwave though... is it just a transitive dependency from fedmsg?

But fedmsg already has a working Python 3 port. How does that work, if moksha is not ported?

Looks like moksha.hub is required transitively by fedmsg - which seems to work fine with Python 3.

Now there are lots of issues using resultsdb from functional tests.

Hm. But we don't import resultsdb code directly anymore, right? It's just invoked as a subprocess.

True enough. If we make that unversioned python subprocess call into an explicit python2 call.. this might work. :)

Yeah, there is no issue with Resultsdb. Just a few import tweaks needed, and some unicode/str cleanups, and things mostly work... Here is a tough one though:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/usr/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/dcallagh/work/greenwave/greenwave/utils.py", line 55, in wrapped
    return func(*args, **kwargs)
  File "/home/dcallagh/work/greenwave/greenwave/api_v1.py", line 257, in make_decision
    results.extend(retrieve_results(item))
  File "/home/dcallagh/work/greenwave/greenwave/cache.py", line 17, in wrapper
    return decorator(fn)(*args)
  File "/usr/lib/python3.6/site-packages/dogpile/cache/region.py", line 1250, in decorate
    should_cache_fn)
  File "/usr/lib/python3.6/site-packages/dogpile/cache/region.py", line 796, in get_or_create
    key = self.key_mangler(key)
  File "/usr/lib/python3.6/site-packages/dogpile/cache/util.py", line 124, in sha1_mangle_key
    return sha1(key).hexdigest()
TypeError: Unicode-objects must be encoded before hashing

Metadata Update from @ralph:
- Issue assigned to ralph

5 years ago

Metadata Update from @ralph:
- Assignee reset

5 years ago

Metadata Update from @ralph:
- Issue assigned to dcallagh

5 years ago

We can work around the issue with sha1_mangle_key() by just using our own implementation that encodes as UTF-8 first. Easy enough. (I should probably file an issue with dogpile about that, it seems surprising that nobody has hit the same problem on Python 3 before...)

However now the tests are failing because our cache keys are using the repr() of a dict which means they are sensitive to dict ordering. Like this test failure shows:

E   AssertionError: Expected call: delete("greenwave.resources:retrieve_results|{u'item': u'glibc-1.0-16.el7', u'type': u'koji_build'}")
E   Actual call: delete("greenwave.resources:retrieve_results|{'type': 'koji_build', 'item': 'glibc-1.0-16.el7'}")

I actually noticed that while working on PR#184, the problem goes away there because the function's args change to (subject_type, subject_identifier) strings, instead of a dict.

So I think let's put a pin in this for now, and try again after PR#184 lands. Everything should work then.

TypeError: '<' not supported between instances of 'dict' and 'dict'

🤔

Metadata Update from @dcallagh:
- Issue set to the milestone: 0.8

5 years ago

Metadata Update from @lholecek:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

5 years ago

Login to comment on this ticket.

Metadata