summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/config/cc_seed_random.py8
-rw-r--r--cloudinit/sources/DataSourceOpenNebula.py11
2 files changed, 17 insertions, 2 deletions
diff --git a/cloudinit/config/cc_seed_random.py b/cloudinit/config/cc_seed_random.py
index 3b7235bf..981e1b08 100644
--- a/cloudinit/config/cc_seed_random.py
+++ b/cloudinit/config/cc_seed_random.py
@@ -38,7 +38,13 @@ def _decode(data, encoding=None):
if not encoding or encoding.lower() in ['raw']:
return data
elif encoding.lower() in ['base64', 'b64']:
- return base64.b64decode(data)
+ # Try to give us a native string in both Python 2 and 3, and remember
+ # that b64decode() returns bytes in Python 3.
+ decoded = base64.b64decode(data)
+ try:
+ return decoded.decode('utf-8')
+ except UnicodeDecodeError:
+ return decoded
elif encoding.lower() in ['gzip', 'gz']:
return util.decomp_gzip(data, quiet=False)
else:
diff --git a/cloudinit/sources/DataSourceOpenNebula.py b/cloudinit/sources/DataSourceOpenNebula.py
index 691b39f8..6da569ec 100644
--- a/cloudinit/sources/DataSourceOpenNebula.py
+++ b/cloudinit/sources/DataSourceOpenNebula.py
@@ -25,6 +25,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64
+import codecs
import os
import pwd
import re
@@ -34,6 +35,8 @@ from cloudinit import log as logging
from cloudinit import sources
from cloudinit import util
+import six
+
LOG = logging.getLogger(__name__)
DEFAULT_IID = "iid-dsopennebula"
@@ -43,6 +46,12 @@ CONTEXT_DISK_FILES = ["context.sh"]
VALID_DSMODES = ("local", "net", "disabled")
+def utf8_open(path):
+ if six.PY3:
+ return open(path, 'r', encoding='utf-8')
+ return codecs.open(path, 'r', encoding='utf-8')
+
+
class DataSourceOpenNebula(sources.DataSource):
def __init__(self, sys_cfg, distro, paths):
sources.DataSource.__init__(self, sys_cfg, distro, paths)
@@ -380,7 +389,7 @@ def read_context_disk_dir(source_dir, asuser=None):
"does not exist", asuser)
try:
path = os.path.join(source_dir, 'context.sh')
- with open(path, 'r', encoding='utf-8') as f:
+ with utf8_open(path) as f:
content = f.read().strip()
context = parse_shell_config(content, asuser=asuser)