diff options
author | Joshua Harlow <harlowja@gmail.com> | 2013-07-24 08:39:03 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@gmail.com> | 2013-07-24 08:39:03 -0700 |
commit | 851906b6acde33fddcbdd1d41f366d6652d1e84d (patch) | |
tree | 0a715c1ee75bb730ae7f1e3dd6f1746413db801c /tests | |
parent | 2939f498f51025ebd0c9bdf302b578dfcbf54d0c (diff) | |
download | vyos-cloud-init-851906b6acde33fddcbdd1d41f366d6652d1e84d.tar.gz vyos-cloud-init-851906b6acde33fddcbdd1d41f366d6652d1e84d.zip |
Fix small prefix bug + jsonp tests.
Fix the wrong usage of the prefix removal array action
by just using the new util function that does these
actions correctly.
Add in a couple of unit tests to verify the jsonp merging
and usage works as expected.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_userdata.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/unittests/test_userdata.py b/tests/unittests/test_userdata.py index 0ebb0484..5cd50f4f 100644 --- a/tests/unittests/test_userdata.py +++ b/tests/unittests/test_userdata.py @@ -6,6 +6,7 @@ import logging import os from email.mime.base import MIMEBase +from email.mime.multipart import MIMEMultipart from cloudinit import handlers from cloudinit import helpers as c_helpers @@ -50,6 +51,64 @@ class TestConsumeUserData(helpers.FilesystemMockingTestCase): self._log.addHandler(self._log_handler) return log_file + def test_simple_jsonp(self): + blob = ''' +#cloud-config-jsonp +[ + { "op": "add", "path": "/baz", "value": "qux" }, + { "op": "add", "path": "/bar", "value": "qux2" } +] +''' + + ci = stages.Init() + ci.datasource = FakeDataSource(blob) + new_root = self.makeDir() + self.patchUtils(new_root) + self.patchOS(new_root) + ci.fetch() + ci.consume_userdata() + cc_contents = util.load_file(ci.paths.get_ipath("cloud_config")) + cc = util.load_yaml(cc_contents) + self.assertEquals(2, len(cc)) + self.assertEquals('qux', cc['baz']) + self.assertEquals('qux2', cc['bar']) + + def test_mixed_cloud_config(self): + blob_cc = ''' +#cloud-config +a: b +c: d +''' + message_cc = MIMEBase("text", "cloud-config") + message_cc.set_payload(blob_cc) + + blob_jp = ''' +#cloud-config-jsonp +[ + { "op": "replace", "path": "/a", "value": "c" }, + { "op": "remove", "path": "/c" } +] +''' + + message_jp = MIMEBase('text', "cloud-config-jsonp") + message_jp.set_payload(blob_jp) + + message = MIMEMultipart() + message.attach(message_cc) + message.attach(message_jp) + + ci = stages.Init() + ci.datasource = FakeDataSource(str(message)) + new_root = self.makeDir() + self.patchUtils(new_root) + self.patchOS(new_root) + ci.fetch() + ci.consume_userdata() + cc_contents = util.load_file(ci.paths.get_ipath("cloud_config")) + cc = util.load_yaml(cc_contents) + self.assertEquals(1, len(cc)) + self.assertEquals('c', cc['a']) + def test_merging_cloud_config(self): blob = ''' #cloud-config |