forked from canonical/cloud-init
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: uninstall custom signal handlers before shutdown (canonical#5913)
Fixes canonicalGH-5849
- Loading branch information
1 parent
c9b9eef
commit 4d559e7
Showing
10 changed files
with
154 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""cloudinit.signal_handler tests""" | ||
|
||
import inspect | ||
import signal | ||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
|
||
from cloudinit import signal_handler | ||
|
||
REENTRANT = "reentrant" | ||
|
||
|
||
class TestSignalHandler: | ||
|
||
@pytest.mark.parametrize( | ||
"m_args", | ||
[ | ||
(signal.SIGINT, inspect.currentframe()), | ||
(9, None), | ||
(signal.SIGTERM, None), | ||
(1, inspect.currentframe()), | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"m_suspended", | ||
[ | ||
(REENTRANT, 0), | ||
(True, 0), | ||
(False, 1), | ||
], | ||
) | ||
def test_suspend_signal(self, m_args, m_suspended): | ||
"""suspend_crash should prevent crashing (exit 1) on signal | ||
otherwise cloud-init should exit 1 | ||
""" | ||
sig, frame = m_args | ||
suspended, rc = m_suspended | ||
|
||
with patch.object(signal_handler.sys, "exit", Mock()) as m_exit: | ||
if suspended is True: | ||
with signal_handler.suspend_crash(): | ||
signal_handler._handle_exit(sig, frame) | ||
elif suspended == REENTRANT: | ||
with signal_handler.suspend_crash(): | ||
with signal_handler.suspend_crash(): | ||
signal_handler._handle_exit(sig, frame) | ||
else: | ||
signal_handler._handle_exit(sig, frame) | ||
m_exit.assert_called_with(rc) |