From b5b1340eab407bb0ac1b5e5ec07a346e4d5570ab Mon Sep 17 00:00:00 2001 From: Eduardo Otubo Date: Mon, 7 Dec 2020 17:36:45 +0100 Subject: [PATCH] Sandbox CA Cert tests so they don't fail where they're not installed CA Cert tests will fail on systems that don't have the, installed and configured. Signed-off-by: Daniel Watkins Signed-off-by: Eduardo Otubo --- .../unittests/test_handler/test_handler_ca_certs.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/unittests/test_handler/test_handler_ca_certs.py b/tests/unittests/test_handler/test_handler_ca_certs.py index e74a0a08b32..a16430d558d 100644 --- a/tests/unittests/test_handler/test_handler_ca_certs.py +++ b/tests/unittests/test_handler/test_handler_ca_certs.py @@ -152,6 +152,7 @@ def setUp(self): self.paths = helpers.Paths({ 'cloud_dir': tmpdir, }) + self.add_patch("cloudinit.config.cc_ca_certs.os.stat", "m_stat") def test_no_certs_in_list(self): """Test that no certificate are written if not provided.""" @@ -215,17 +216,12 @@ def test_single_cert_to_empty_existing_ca_file(self): expected = "cloud-init-ca-certs.crt\n" - with ExitStack() as mocks: - mock_write = mocks.enter_context( - mock.patch.object(util, 'write_file', autospec=True)) - mock_stat = mocks.enter_context( - mock.patch("cloudinit.config.cc_ca_certs.os.stat") - ) - mock_stat.return_value.st_size = 0 + with mock.patch.object(util, 'write_file', autospec=True) as m_write: + self.m_stat.return_value.st_size = 0 cc_ca_certs.add_ca_certs([cert]) - mock_write.assert_has_calls([ + m_write.assert_has_calls([ mock.call("/usr/share/ca-certificates/cloud-init-ca-certs.crt", cert, mode=0o644), mock.call("/etc/ca-certificates.conf", expected, omode="wb")])