summaryrefslogtreecommitdiff
path: root/cloudinit/config/tests/test_final_message.py
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-06-30 13:17:40 -0400
committerGitHub <noreply@github.com>2020-06-30 11:17:40 -0600
commit66e114a660c53400e389f119781f378311b65108 (patch)
tree7d0c3ca519f0e245288a9fb9d51a899d8f67cea0 /cloudinit/config/tests/test_final_message.py
parentbaf11418c196ca72e6d570b64051d8ed35065abb (diff)
downloadvyos-cloud-init-66e114a660c53400e389f119781f378311b65108.tar.gz
vyos-cloud-init-66e114a660c53400e389f119781f378311b65108.zip
Enable use of the caplog fixture in pytest tests, and add a cc_final_message test using it (#461)
caplog is only available in pytest itself from 3.0 onwards. In xenial, we only have pytest 2.8.7. However, in xenial we do have pytest-catchlog available (as python3-pytest-catchlog), so we use that where appropriate.
Diffstat (limited to 'cloudinit/config/tests/test_final_message.py')
-rw-r--r--cloudinit/config/tests/test_final_message.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/cloudinit/config/tests/test_final_message.py b/cloudinit/config/tests/test_final_message.py
index 76cb0ad1..46ba99b2 100644
--- a/cloudinit/config/tests/test_final_message.py
+++ b/cloudinit/config/tests/test_final_message.py
@@ -1,4 +1,5 @@
# This file is part of cloud-init. See LICENSE file for license information.
+import logging
from unittest import mock
import pytest
@@ -12,10 +13,19 @@ class TestHandle:
# contents).
@pytest.mark.parametrize(
- "instance_dir_exists,file_is_written", [(True, True), (False, False)]
+ "instance_dir_exists,file_is_written,expected_log_substring",
+ [
+ (True, True, None),
+ (False, False, "Failed to write boot finished file "),
+ ],
)
def test_boot_finished_written(
- self, instance_dir_exists, file_is_written, tmpdir
+ self,
+ instance_dir_exists,
+ file_is_written,
+ expected_log_substring,
+ caplog,
+ tmpdir,
):
instance_dir = tmpdir.join("var/lib/cloud/instance")
if instance_dir_exists:
@@ -26,8 +36,11 @@ class TestHandle:
paths=mock.Mock(boot_finished=boot_finished.strpath)
)
- handle(None, {}, m_cloud, mock.Mock(), [])
+ handle(None, {}, m_cloud, logging.getLogger(), [])
# We should not change the status of the instance directory
assert instance_dir_exists == instance_dir.exists()
assert file_is_written == boot_finished.exists()
+
+ if expected_log_substring:
+ assert expected_log_substring in caplog.text