summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-03-27 10:06:57 -0400
committerScott Moser <smoser@ubuntu.com>2014-03-27 10:06:57 -0400
commit2f9b47be819e4aa90d0cfd940557b90cbd6912de (patch)
treef39e6f00ddb1b744321c3d4072bd74ac88189759 /tests/unittests/test_datasource
parent11d6dbfad89e3f9a56925f7671fa7ee3e86af918 (diff)
parent2ecefdf51cd93b593bea450b4d751021da91e748 (diff)
downloadvyos-cloud-init-2f9b47be819e4aa90d0cfd940557b90cbd6912de.tar.gz
vyos-cloud-init-2f9b47be819e4aa90d0cfd940557b90cbd6912de.zip
OpenNebula: support base64 encoded user-data
This change adds the possibility to have base64 encoded userdata in OpenNebula source. OpenNebula uses a text file with shell variables for storing the configuration variables (including user provided data). Some user data may not be renderable into this format, so using base64 encoding alleviates the problem. The change here allows the user to provide a second variable USERDATA_ENCODING (or USER_DATA_ENCODING) and set that value to 'base64' to indicate that USERDATA is base64 encoded.
Diffstat (limited to 'tests/unittests/test_datasource')
-rw-r--r--tests/unittests/test_datasource/test_opennebula.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/unittests/test_datasource/test_opennebula.py b/tests/unittests/test_datasource/test_opennebula.py
index 6fc5b2ac..ec6b752b 100644
--- a/tests/unittests/test_datasource/test_opennebula.py
+++ b/tests/unittests/test_datasource/test_opennebula.py
@@ -4,6 +4,7 @@ from cloudinit import util
from mocker import MockerTestCase
from tests.unittests.helpers import populate_dir
+from base64 import b64encode
import os
import pwd
@@ -164,10 +165,31 @@ class TestOpenNebulaDataSource(MockerTestCase):
public_keys.append(SSH_KEY % (c + 1,))
- def test_user_data(self):
+ def test_user_data_plain(self):
for k in ('USER_DATA', 'USERDATA'):
my_d = os.path.join(self.tmp, k)
- populate_context_dir(my_d, {k: USER_DATA})
+ populate_context_dir(my_d, {k: USER_DATA,
+ 'USERDATA_ENCODING': ''})
+ results = ds.read_context_disk_dir(my_d)
+
+ self.assertTrue('userdata' in results)
+ self.assertEqual(USER_DATA, results['userdata'])
+
+ def test_user_data_encoding_required_for_decode(self):
+ b64userdata = b64encode(USER_DATA)
+ for k in ('USER_DATA', 'USERDATA'):
+ my_d = os.path.join(self.tmp, k)
+ populate_context_dir(my_d, {k: b64userdata})
+ results = ds.read_context_disk_dir(my_d)
+
+ self.assertTrue('userdata' in results)
+ self.assertEqual(b64userdata, results['userdata'])
+
+ def test_user_data_base64_encoding(self):
+ for k in ('USER_DATA', 'USERDATA'):
+ my_d = os.path.join(self.tmp, k)
+ populate_context_dir(my_d, {k: b64encode(USER_DATA),
+ 'USERDATA_ENCODING': 'base64'})
results = ds.read_context_disk_dir(my_d)
self.assertTrue('userdata' in results)