From a934ae9543ccc9c13fbdedddcc04fa82853a7ec2 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 2 Mar 2015 15:56:15 -0500 Subject: get_cmdline_url: fix in python3 when calling get_cmdline_url was passing a string to response.contents.startswith() where response.contents is now bytes. this changes it to convert input to text, and also to default to text. --- cloudinit/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cloudinit') 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) -- cgit v1.2.3 From 72958f9c40f53c634d1eb7ef55547271e1972d2c Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 2 Mar 2015 16:34:46 -0500 Subject: DataSourceMAAS: fix oauthlib imports In both python2 and python3, This throws "'module' object has no attribute 'oauth1'" $ python3 -c 'import oauthlib; oauthlib.oauth1.Client("x")' While this works fine: $ python3 -c 'import oauthlib.oauth1 as oauth1; oauth1.Client("x")' --- cloudinit/sources/DataSourceMAAS.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cloudinit') 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 -- cgit v1.2.3