summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Otubo <otubo@redhat.com>2020-12-09 18:52:51 +0100
committerGitHub <noreply@github.com>2020-12-09 12:52:51 -0500
commitb8df254738a43b690d1f511bc5c13290140c7ed0 (patch)
treea9c3cf4a3415a023092bf2445347431c2eadc51c
parent54e202a6480e48dbb8a72004f7a5003f7c4edfae (diff)
downloadcloud-init-git-b8df254738a43b690d1f511bc5c13290140c7ed0.tar.gz
sandbox CA Cert tests to not require ca-certificates (#715)
CA Cert tests will fail on systems that don't have ca-certificates installed and configured. Signed-off-by: Daniel Watkins <oddbloke@ubuntu.com> Signed-off-by: Eduardo Otubo <otubo@redhat.com>
-rw-r--r--tests/unittests/test_handler/test_handler_ca_certs.py12
1 files 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 e74a0a08..a16430d5 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 @@ class TestAddCaCerts(TestCase):
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 @@ class TestAddCaCerts(TestCase):
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")])