Merge ~larsks/cloud-init:feature/hide-oauthlib-import-failure into cloud-init:master

Proposed by Lars Kellogg-Stedman on 2017-08-25
Status: Merged
Merged at revision: af4630c9846fe979152320035e9cc6c411506503
Proposed branch: ~larsks/cloud-init:feature/hide-oauthlib-import-failure
Merge into: cloud-init:master
Diff against target: 28 lines (+9/-1)
1 file modified
cloudinit/url_helper.py (+9/-1)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve on 2017-08-25
Scott Moser 2017-08-25 Pending
Review via email: mp+329620@code.launchpad.net

Commit Message

url_helper: fail gracefully if oauthlib is not available

We are unable to ship python-oauthlib in RHEL. This commit allows
imports of url_helper to succeed even when oauthlib is unavailable
and OauthUrlHelper.oauth_headers to raise a NotImplementedException
when called.

LP: #1713760

Description of the Change

url_helper: fail gracefully if oauthlib is not available

We are unable to ship python-oauthlib in RHEL. This commit allows
imports of url_helper to succeed even when oauthlib is unavailable
and OauthUrlHelper.oauth_headers to raise a NotImplementedException
when called.

To post a comment you must log in.

PASSED: Continuous integration, rev:29025c3b9dd3ac1eb1d3858f9826adacdb700ac2
https://jenkins.ubuntu.com/server/job/cloud-init-ci/201/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/201/rebuild

review: Approve (continuous-integration)
Chad Smith (chad.smith) wrote :

This branch is good as is, though I'd like to see a mocked ImportError test to confirm the raise NotImplementedError. Example is in tests/unittests/test_handler/test_schema.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
2index 7cf76aa..c83061a 100644
3--- a/cloudinit/url_helper.py
4+++ b/cloudinit/url_helper.py
5@@ -17,7 +17,11 @@ import time
6 from email.utils import parsedate
7 from functools import partial
8
9-import oauthlib.oauth1 as oauth1
10+try:
11+ import oauthlib.oauth1 as oauth1
12+except ImportError:
13+ oauth1 = None
14+
15 from requests import exceptions
16
17 from six.moves.urllib.parse import (
18@@ -488,6 +492,10 @@ class OauthUrlHelper(object):
19
20 def oauth_headers(url, consumer_key, token_key, token_secret, consumer_secret,
21 timestamp=None):
22+
23+ if oauth1 is None:
24+ raise NotImplementedError('oauth support is not available')
25+
26 if timestamp:
27 timestamp = str(timestamp)
28 else:

Subscribers

People subscribed via source and target branches