diff options
| author | zdc <zdc@users.noreply.github.com> | 2020-12-25 18:57:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-25 18:57:19 +0200 |
| commit | 27c317f83d8e393254b6766b34fdf8d29148ea8f (patch) | |
| tree | ea824de28fa639ba6ba8b212efaf53b5df2e90d9 /tests/integration_tests/modules/test_write_files.py | |
| parent | 66dc53b1b3f8786f3bbb25e914c1dc8161af0494 (diff) | |
| parent | c6bcb8df28daa234686a563549681082eb3283a1 (diff) | |
| download | vyos-cloud-init-27c317f83d8e393254b6766b34fdf8d29148ea8f.tar.gz vyos-cloud-init-27c317f83d8e393254b6766b34fdf8d29148ea8f.zip | |
Merge pull request #28 from zdc/T2117-equuleus-20.4
T2117: Cloud-init updated to 20.4
Diffstat (limited to 'tests/integration_tests/modules/test_write_files.py')
| -rw-r--r-- | tests/integration_tests/modules/test_write_files.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/integration_tests/modules/test_write_files.py b/tests/integration_tests/modules/test_write_files.py new file mode 100644 index 00000000..15832ae3 --- /dev/null +++ b/tests/integration_tests/modules/test_write_files.py @@ -0,0 +1,66 @@ +"""Integration test for the write_files module. + +This test specifies files to be created by the ``write_files`` module +and then checks if those files were created during boot. + +(This is ported from +``tests/cloud_tests/testcases/modules/write_files.yaml``.)""" + +import base64 +import pytest + + +ASCII_TEXT = "ASCII text" +B64_CONTENT = base64.b64encode(ASCII_TEXT.encode("utf-8")) + +# NOTE: the binary data can be any binary data, not only executables +# and can be generated via the base 64 command as such: +# $ base64 < hello > hello.txt +# the opposite is running: +# $ base64 -d < hello.txt > hello +# +USER_DATA = """\ +#cloud-config +write_files: +- encoding: b64 + content: {} + owner: root:root + path: /root/file_b64 + permissions: '0644' +- content: | + # My new /root/file_text + + SMBDOPTIONS="-D" + path: /root/file_text +- content: !!binary | + /Z/xrHR4WINT0UNoKPQKbuovp6+Js+JK + path: /root/file_binary + permissions: '0555' +- encoding: gzip + content: !!binary | + H4sIAIDb/U8C/1NW1E/KzNMvzuBKTc7IV8hIzcnJVyjPL8pJ4QIA6N+MVxsAAAA= + path: /root/file_gzip + permissions: '0755' +""".format(B64_CONTENT.decode("ascii")) + + +@pytest.mark.ci +@pytest.mark.user_data(USER_DATA) +class TestWriteFiles: + + @pytest.mark.parametrize( + "cmd,expected_out", ( + ("file /root/file_b64", ASCII_TEXT), + ("md5sum </root/file_binary", "3801184b97bb8c6e63fa0e1eae2920d7"), + ("sha256sum </root/file_binary", ( + "2c791c4037ea5bd7e928d6a87380f8ba" + "7a803cd83d5e4f269e28f5090f0f2c9a" + )), + ("file /root/file_gzip", + "POSIX shell script, ASCII text executable"), + ("file /root/file_text", ASCII_TEXT), + ) + ) + def test_write_files(self, cmd, expected_out, class_client): + out = class_client.execute(cmd) + assert expected_out in out |
