diff options
author | Michael Hudson-Doyle <michael.hudson@canonical.com> | 2021-02-23 08:20:46 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 14:20:46 -0500 |
commit | e384a5436560c9494118f0999c314982d4912d27 (patch) | |
tree | 22a657982fce42d22a727b0b9160f79f779cc136 /cloudinit/config/tests/test_keys_to_console.py | |
parent | 38aee6eebb160d46287c63a979bb897b15bb2f96 (diff) | |
download | vyos-cloud-init-e384a5436560c9494118f0999c314982d4912d27.tar.gz vyos-cloud-init-e384a5436560c9494118f0999c314982d4912d27.zip |
cc_keys_to_console: add option to disable key emission (#811)
Specifically:
ssh:
emit_keys_to_console: false
We also port the cc_keys_to_console cloud tests to the new integration
testing framework, and add a test for this new option.
LP: #1915460
Diffstat (limited to 'cloudinit/config/tests/test_keys_to_console.py')
-rw-r--r-- | cloudinit/config/tests/test_keys_to_console.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/cloudinit/config/tests/test_keys_to_console.py b/cloudinit/config/tests/test_keys_to_console.py new file mode 100644 index 00000000..4083fc54 --- /dev/null +++ b/cloudinit/config/tests/test_keys_to_console.py @@ -0,0 +1,34 @@ +"""Tests for cc_keys_to_console.""" +from unittest import mock + +import pytest + +from cloudinit.config import cc_keys_to_console + + +class TestHandle: + """Tests for cloudinit.config.cc_keys_to_console.handle. + + TODO: These tests only cover the emit_keys_to_console config option, they + should be expanded to cover the full functionality. + """ + + @mock.patch("cloudinit.config.cc_keys_to_console.util.multi_log") + @mock.patch("cloudinit.config.cc_keys_to_console.os.path.exists") + @mock.patch("cloudinit.config.cc_keys_to_console.subp.subp") + @pytest.mark.parametrize("cfg,subp_called", [ + ({}, True), # Default to emitting keys + ({"ssh": {}}, True), # Default even if we have the parent key + ({"ssh": {"emit_keys_to_console": True}}, True), # Explicitly enabled + ({"ssh": {"emit_keys_to_console": False}}, False), # Disabled + ]) + def test_emit_keys_to_console_config( + self, m_subp, m_path_exists, _m_multi_log, cfg, subp_called + ): + # Ensure we always find the helper + m_path_exists.return_value = True + m_subp.return_value = ("", "") + + cc_keys_to_console.handle("name", cfg, mock.Mock(), mock.Mock(), ()) + + assert subp_called == (m_subp.call_count == 1) |