summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceSmartOS.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2015-01-26 14:31:09 -0500
committerBarry Warsaw <barry@python.org>2015-01-26 14:31:09 -0500
commitde5974fe93dd717e0c7ba6de17db3192cc258cff (patch)
treea877b3ee6d3362892c0683e054d62f8c0e924908 /cloudinit/sources/DataSourceSmartOS.py
parent926a3df79a10ede61967c60f48ff0670a36e689a (diff)
downloadvyos-cloud-init-de5974fe93dd717e0c7ba6de17db3192cc258cff.tar.gz
vyos-cloud-init-de5974fe93dd717e0c7ba6de17db3192cc258cff.zip
* More str/bytes fixes.
* Temporarily skip the MAAS tests in py3 since they need to be ported to oauthlib.
Diffstat (limited to 'cloudinit/sources/DataSourceSmartOS.py')
-rw-r--r--cloudinit/sources/DataSourceSmartOS.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
index 7a975d78..d3ed40c5 100644
--- a/cloudinit/sources/DataSourceSmartOS.py
+++ b/cloudinit/sources/DataSourceSmartOS.py
@@ -30,6 +30,7 @@
# Comments with "@datadictionary" are snippets of the definition
import base64
+import binascii
import os
import serial
@@ -350,8 +351,18 @@ def query_data(noun, seed_device, seed_timeout, strip=False, default=None,
if b64:
try:
- return base64.b64decode(resp)
- except TypeError:
+ # Generally, we want native strings in the values. Python 3's
+ # b64decode will return bytes though, so decode them to utf-8 if
+ # possible. If that fails, return the bytes.
+ decoded = base64.b64decode(resp)
+ try:
+ if isinstance(decoded, bytes):
+ return decoded.decode('utf-8')
+ except UnicodeDecodeError:
+ pass
+ return decoded
+ # Bogus input produces different errors in Python 2 and 3; catch both.
+ except (TypeError, binascii.Error):
LOG.warn("Failed base64 decoding key '%s'", noun)
return resp