diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-04-16 17:00:19 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-04-16 17:00:19 -0400 |
commit | 341a805fca9a06ce12e9f4bbbe15b3dded9eb6a4 (patch) | |
tree | 71fce1c6c426f75c7126522a3a6efb57e4a9b26e /tests/unittests/test_data.py | |
parent | dcd4b2b371059bd6249b4e43af371ee1162273e8 (diff) | |
download | vyos-cloud-init-341a805fca9a06ce12e9f4bbbe15b3dded9eb6a4.tar.gz vyos-cloud-init-341a805fca9a06ce12e9f4bbbe15b3dded9eb6a4.zip |
fix cloud-config-archive handling
handling of cloud-config-archive input would fail in fully_decoded_payload.
part.get_charset() would return a Charset object, but
get_charset.input_codec is a string suitable for passing to decode.
This handles that correctly, and is more careful about binary data inside
input.
The test added verifies that cloud-config inside a cloud-config-archive
is handled correctly and also that binary data there is ignored without
exceptions raised.
LP: #1445143
Diffstat (limited to 'tests/unittests/test_data.py')
-rw-r--r-- | tests/unittests/test_data.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/unittests/test_data.py b/tests/unittests/test_data.py index b950c9a5..1b15dafa 100644 --- a/tests/unittests/test_data.py +++ b/tests/unittests/test_data.py @@ -512,6 +512,33 @@ c: 4 ci.paths.get_ipath("cloud_config"), "", 0o600) + def test_cloud_config_archive(self): + non_decodable = b'\x11\xc9\xb4gTH\xee\x12' + data = [{'content': '#cloud-config\npassword: gocubs\n'}, + {'content': '#cloud-config\nlocale: chicago\n'}, + {'content': non_decodable}] + message = b'#cloud-config-archive\n' + util.yaml_dumps(data).encode() + + ci = stages.Init() + ci.datasource = FakeDataSource(message) + + fs = {} + + def fsstore(filename, content, mode=0o0644, omode="wb"): + fs[filename] = content + + # consuming the user-data provided should write 'cloud_config' file + # which will have our yaml in it. + with mock.patch('cloudinit.util.write_file') as mockobj: + mockobj.side_effect = fsstore + ci.fetch() + ci.consume_data() + + cfg = util.load_yaml(fs[ci.paths.get_ipath("cloud_config")]) + self.assertEqual(cfg.get('password'), 'gocubs') + self.assertEqual(cfg.get('locale'), 'chicago') + + class TestUDProcess(helpers.ResourceUsingTestCase): def test_bytes_in_userdata(self): |