Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add integration test for signal handling warnings/errors #6037

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cloudinit/signal_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def _handle_exit(signum, frame):
contents = StringIO(SIG_MESSAGE.format(vr.version_string(), name))
_pprint_frame(frame, 1, BACK_FRAME_TRACE_DEPTH, contents)
log_util.multi_log(
contents.getvalue(), log=LOG, log_level=_SIGNAL_EXIT_BEHAVIOR.log_level
f"Received signal {name} resulting in exit. Cause:\n"
+ contents.getvalue(),
log=LOG,
log_level=_SIGNAL_EXIT_BEHAVIOR.log_level,
)
sys.exit(_SIGNAL_EXIT_BEHAVIOR.exit_code)

Expand Down
6 changes: 5 additions & 1 deletion tests/integration_tests/modules/test_power_state_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.integration_settings import PLATFORM
from tests.integration_tests.releases import IS_UBUNTU
from tests.integration_tests.util import verify_ordered_items_in_text
from tests.integration_tests.util import (
verify_clean_boot,
verify_ordered_items_in_text,
)

USER_DATA = """\
#cloud-config
Expand Down Expand Up @@ -83,6 +86,7 @@ def test_poweroff(
instance.instance.start(wait=True)
log = instance.read_from_file("/var/log/cloud-init.log")
assert _can_connect(instance)
verify_clean_boot(instance)
lines_to_check = [
"Running module power_state_change",
expected,
Expand Down
21 changes: 21 additions & 0 deletions tests/integration_tests/test_signal_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.util import verify_clean_boot

USER_DATA = """\
#cloud-config
runcmd:
- pkill cloud-init
- sleep 5
- echo 'whoops' > /var/tmp/whoops
"""


@pytest.mark.user_data(USER_DATA)
def test_no_warnings(client: IntegrationInstance):
"""Test that the signal handler does not log errors when suppressed."""
verify_clean_boot(client)
log = client.read_from_file("/var/log/cloud-init.log")
assert "Received signal 15 resulting in exit" in log
assert client.execute("test -f /var/tmp/whoops").failed