summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-03-02 18:48:52 -0500
committerScott Moser <smoser@ubuntu.com>2015-03-02 18:48:52 -0500
commitb11401a01151c7f53770b8b20efd3abebb42e68a (patch)
treeeb15f21f1861200ea628a03b17f5466ad5d83fc7
parentb2af44fb22719dc353bd867c2648e0dd5b2eec19 (diff)
parent72958f9c40f53c634d1eb7ef55547271e1972d2c (diff)
downloadvyos-cloud-init-b11401a01151c7f53770b8b20efd3abebb42e68a.tar.gz
vyos-cloud-init-b11401a01151c7f53770b8b20efd3abebb42e68a.zip
MAAS: fix oauth imports and reading of command line seed.
LP: #1427263
-rw-r--r--cloudinit/sources/DataSourceMAAS.py6
-rw-r--r--cloudinit/util.py4
-rw-r--r--tests/unittests/test__init__.py8
3 files changed, 10 insertions, 8 deletions
diff --git a/cloudinit/sources/DataSourceMAAS.py b/cloudinit/sources/DataSourceMAAS.py
index 35c5b5e1..6cc010b7 100644
--- a/cloudinit/sources/DataSourceMAAS.py
+++ b/cloudinit/sources/DataSourceMAAS.py
@@ -22,7 +22,7 @@ from __future__ import print_function
from email.utils import parsedate
import errno
-import oauthlib
+import oauthlib.oauth1 as oauth1
import os
import time
@@ -283,12 +283,12 @@ def check_seed_contents(content, seed):
def oauth_headers(url, consumer_key, token_key, token_secret, consumer_secret,
timestamp=None):
- client = oauthlib.oauth1.Client(
+ client = oauth1.Client(
consumer_key,
client_secret=consumer_secret,
resource_owner_key=token_key,
resource_owner_secret=token_secret,
- signature_method=oauthlib.SIGNATURE_PLAINTEXT)
+ signature_method=oauth1.SIGNATURE_PLAINTEXT)
uri, signed_headers, body = client.sign(url)
return signed_headers
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 039aa3f2..cc20305c 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -970,7 +970,7 @@ def get_fqdn_from_hosts(hostname, filename="/etc/hosts"):
def get_cmdline_url(names=('cloud-config-url', 'url'),
- starts="#cloud-config", cmdline=None):
+ starts=b"#cloud-config", cmdline=None):
if cmdline is None:
cmdline = get_cmdline()
@@ -986,6 +986,8 @@ def get_cmdline_url(names=('cloud-config-url', 'url'),
return (None, None, None)
resp = read_file_or_url(url)
+ # allow callers to pass starts as text when comparing to bytes contents
+ starts = encode_text(starts)
if resp.ok() and resp.contents.startswith(starts):
return (key, url, resp.contents)
diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py
index 1a307e56..c32783a6 100644
--- a/tests/unittests/test__init__.py
+++ b/tests/unittests/test__init__.py
@@ -181,7 +181,7 @@ class TestCmdlineUrl(unittest.TestCase):
def test_invalid_content(self):
url = "http://example.com/foo"
key = "mykey"
- payload = "0"
+ payload = b"0"
cmdline = "ro %s=%s bar=1" % (key, url)
with mock.patch('cloudinit.url_helper.readurl',
@@ -194,13 +194,13 @@ class TestCmdlineUrl(unittest.TestCase):
def test_valid_content(self):
url = "http://example.com/foo"
key = "mykey"
- payload = "xcloud-config\nmydata: foo\nbar: wark\n"
+ payload = b"xcloud-config\nmydata: foo\nbar: wark\n"
cmdline = "ro %s=%s bar=1" % (key, url)
with mock.patch('cloudinit.url_helper.readurl',
return_value=url_helper.StringResponse(payload)):
self.assertEqual(
- util.get_cmdline_url(names=[key], starts="xcloud-config",
+ util.get_cmdline_url(names=[key], starts=b"xcloud-config",
cmdline=cmdline),
(key, url, payload))
@@ -210,7 +210,7 @@ class TestCmdlineUrl(unittest.TestCase):
cmdline = "ro %s=%s bar=1" % (key, url)
with mock.patch('cloudinit.url_helper.readurl',
- return_value=url_helper.StringResponse('')):
+ return_value=url_helper.StringResponse(b'')):
self.assertEqual(
util.get_cmdline_url(names=["does-not-appear"],
starts="#cloud-config", cmdline=cmdline),