Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make fetch_github_token more robust against RuntimeError from keyring #2070

Merged
merged 2 commits into from Jan 6, 2017

Conversation

boegel
Copy link
Member

@boegel boegel commented Dec 29, 2016

Other than getting rid of the useless GithubToken class, this also wraps the keyring.get_password call into a try/except RuntimeError, cfr. #2069.

@boegel boegel added this to the 3.1.0 milestone Dec 29, 2016
@boegel
Copy link
Member Author

boegel commented Dec 29, 2016

@verdurin please review?

@verdurin
Copy link
Member

This is what I say with the existing code, when I try --install-latest-eb-release, for reference:

Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/main.py", line 443, in <module>
    main()
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/main.py", line 295, in main
    eb_file = find_easybuild_easyconfig()
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 1269, in find_easybuild_easyconfig
    dev_repo = download_repo(GITHUB_EASYCONFIGS_REPO, branch='develop', account=GITHUB_EB_MAIN)
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 293, in download_repo
    latest_commit_sha = fetch_latest_commit_sha(repo, account, branch)
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 255, in fetch_latest_commit_sha
    github_user=github_user, token=token, per_page=GITHUB_MAX_PER_PAGE)
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 230, in github_api_get_request
    token = fetch_github_token(github_user)
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 1194, in fetch_github_token
    return GithubToken(user).token
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 1174, in __init__
    self.token = keyring.get_password(KEYRING_GITHUB_TOKEN, user)
  File "/usr/lib/python2.7/site-packages/keyring/core.py", line 42, in get_password
    return _keyring_backend.get_password(service_name, username)
  File "/usr/lib/python2.7/site-packages/keyring/backends/SecretService.py", line 51, in get_password
    collection = self.get_default_collection()
  File "/usr/lib/python2.7/site-packages/keyring/backends/SecretService.py", line 43, in get_default_collection
    collection.unlock()
  File "/usr/lib/python2.7/site-packages/secretstorage/collection.py", line 63, in unlock
    return unlock_objects(self.bus, [self.collection_path], callback)
  File "/usr/lib/python2.7/site-packages/secretstorage/util.py", line 168, in unlock_objects
    return exec_prompt_glib(bus, prompt)[0]
  File "/usr/lib/python2.7/site-packages/secretstorage/util.py", line 134, in exec_prompt_glib
    exec_prompt(bus, prompt, callback)
  File "/usr/lib/python2.7/site-packages/secretstorage/util.py", line 122, in exec_prompt
    prompt_iface.connect_to_signal('Completed', new_callback)
  File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 544, in connect_to_signal
    dbus_interface, **keywords)
  File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 369, in connect_to_signal
    **keywords)
  File "/usr/lib64/python2.7/site-packages/dbus/bus.py", line 148, in add_signal_receiver
    path, **keywords)
  File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 400, in add_signal_receiver
    self._require_main_loop()
RuntimeError: To make asynchronous calls, receive signals or export objects, D-Bus connections must be attached to a main loop by passing mainloop=... to the constructor or calling dbus.set_default_main_loop(...)

@boegel
Copy link
Member Author

boegel commented Dec 29, 2016

@verdurin this is a different problem than the one reported in #2069?

@verdurin
Copy link
Member

@boegel - just reporting one step at a time.

This is what I see with the new code, but with my Github username still configured:

[adam@marcel libX11]$ eb --install-latest-eb-release
== temporary log file in case of crash /tmp/eb-sX2H6v/easybuild-6E7vYQ.log
Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/main.py", line 443, in <module>
    main()
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/main.py", line 295, in main
    eb_file = find_easybuild_easyconfig()
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 1270, in find_easybuild_easyconfig
    dev_repo = download_repo(GITHUB_EASYCONFIGS_REPO, branch='develop', account=GITHUB_EB_MAIN)
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 293, in download_repo
    latest_commit_sha = fetch_latest_commit_sha(repo, account, branch)
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 255, in fetch_latest_commit_sha
    github_user=github_user, token=token, per_page=GITHUB_MAX_PER_PAGE)
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 230, in github_api_get_request
    token = fetch_github_token(github_user)
  File "/home/adam/.local/easybuild/software/EasyBuild/3.0.2/lib/python2.7/site-packages/easybuild_framework-3.0.2-py2.7.egg/easybuild/tools/github.py", line 1174, in fetch_github_token
    token = keyring.get_password(KEYRING_GITHUB_TOKEN, user)
  File "/usr/lib/python2.7/site-packages/keyring/core.py", line 42, in get_password
    return _keyring_backend.get_password(service_name, username)
  File "/usr/lib/python2.7/site-packages/keyring/backends/SecretService.py", line 51, in get_password
    collection = self.get_default_collection()
  File "/usr/lib/python2.7/site-packages/keyring/backends/SecretService.py", line 45, in get_default_collection
    raise InitError("Failed to unlock the collection!")
keyring.errors.InitError: Failed to unlock the collection!

@verdurin
Copy link
Member

verdurin commented Dec 29, 2016

With my Github username unset, the command completes normally, though it also did without the new code.

@boegel
Copy link
Member Author

boegel commented Dec 29, 2016

@verdurin Are you getting RuntimeError: To make asynchronous calls after you have also installed keyrings.alt?

The InitError shows that we'll probably need to resort to the generic except Exception rather than except RuntimeError...

@verdurin
Copy link
Member

@boegel I haven't installed keyrings.alt, because that doesn't appear to be packaged for Fedora yet, and I don't want to start messing up my system with pip etc.

All I've done is upgrade to the latest Fedora package, which has a dependency on python-SecretStorage.

@verdurin
Copy link
Member

@boegel maybe the Fedora maintainer will include keyrings.alt in a new build.

@verdurin
Copy link
Member

verdurin commented Dec 29, 2016

Probably redundant information, but I see that error when I try --new-pr or --install-github-token, too, and (correctly) --github-check reports which actions aren't supported.

@boegel
Copy link
Member Author

boegel commented Dec 29, 2016

@verdurin updated to catch Exception rather than RuntimeError

It is normal you get the same issue with --new-pr, but there it's a blocker since the GitHub token is required there in order for --new-pr to work.

@boegel
Copy link
Member Author

boegel commented Jan 6, 2017

@verdurin any last words on this, seems good to go to me?

@verdurin
Copy link
Member

verdurin commented Jan 6, 2017

@boegel yes, the unsightly exception is caught now. Good.

Thanks.

@boegel
Copy link
Member Author

boegel commented Jan 6, 2017

Going in, thanks for the feedback @verdurin!

@boegel boegel merged commit 5ebd676 into easybuilders:develop Jan 6, 2017
@boegel boegel deleted the more_robust_fetch_github_token branch January 6, 2017 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants