summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Howard <ben.howard@canonical.com>2015-02-18 08:18:09 -0700
committerBen Howard <ben.howard@canonical.com>2015-02-18 08:18:09 -0700
commit14d75254351009087efb5baa5cef808c5ef43e17 (patch)
tree2670497ceaaecf2e943d691b0ccf2f916beebb07
parent9c224b8bbe5e133fca00d04d070337ffed23bbd9 (diff)
parent589ced475c9e200d4645f0b06f7846dae412b194 (diff)
downloadvyos-cloud-init-14d75254351009087efb5baa5cef808c5ef43e17.tar.gz
vyos-cloud-init-14d75254351009087efb5baa5cef808c5ef43e17.zip
Fix for ascii decode in DataSourceAzure (LP: #1422993).
-rw-r--r--cloudinit/sources/DataSourceAzure.py4
-rw-r--r--tests/unittests/helpers.py5
-rw-r--r--tests/unittests/test_datasource/test_azure.py6
-rw-r--r--tox.ini4
4 files changed, 15 insertions, 4 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 444070bb..6e030217 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -137,7 +137,7 @@ class DataSourceAzureNet(sources.DataSource):
if found != ddir:
cached_ovfenv = util.load_file(
- os.path.join(ddir, 'ovf-env.xml'), quiet=True)
+ os.path.join(ddir, 'ovf-env.xml'), quiet=True, decode=False)
if cached_ovfenv != files['ovf-env.xml']:
# source was not walinux-agent's datadir, so we have to clean
# up so 'wait_for_files' doesn't return early due to stale data
@@ -593,7 +593,7 @@ def load_azure_ds_dir(source_dir):
if not os.path.isfile(ovf_file):
raise NonAzureDataSource("No ovf-env file found")
- with open(ovf_file, "r") as fp:
+ with open(ovf_file, "rb") as fp:
contents = fp.read()
md, ud, cfg = read_azure_ovf(contents)
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index ce77af93..7516bd02 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -287,10 +287,11 @@ def populate_dir(path, files):
if not os.path.exists(path):
os.makedirs(path)
for (name, content) in files.items():
- with open(os.path.join(path, name), "w") as fp:
- fp.write(content)
+ with open(os.path.join(path, name), "wb") as fp:
+ fp.write(content.encode('utf-8'))
fp.close()
+
try:
skipIf = unittest.skipIf
except AttributeError:
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 965bce4b..38d70fcd 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -360,6 +360,12 @@ class TestAzureDataSource(TestCase):
self.assertTrue(os.path.exists(ovf_env_path))
self.assertEqual(xml, load_file(ovf_env_path))
+ def test_ovf_can_include_unicode(self):
+ xml = construct_valid_ovf_env(data={})
+ xml = u'\ufeff{0}'.format(xml)
+ dsrc = self._get_ds({'ovfcontent': xml})
+ dsrc.get_data()
+
def test_existing_ovf_same(self):
# waagent/SharedConfig left alone if found ovf-env.xml same as cached
odata = {'UserData': b64e("SOMEUSERDATA")}
diff --git a/tox.ini b/tox.ini
index 686a1e7a..20ba6546 100644
--- a/tox.ini
+++ b/tox.ini
@@ -11,6 +11,8 @@ deps =
nose
pep8==1.5.7
pyflakes
+setenv =
+ LC_ALL = C
[testenv:py26]
commands = nosetests {posargs:tests}
@@ -21,3 +23,5 @@ deps =
nose
pep8==1.5.7
pyflakes
+setenv =
+ LC_ALL = C