Skip to content

Commit 357bbe5

Browse files
committed
test(linstor): pin the chart command form of the shutdown hook
Signed-off-by: Yan Bondarenko <[email protected]>
1 parent 527570d commit 357bbe5

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎packages/system/linstor/tests/test_satellite_pre_stop.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import json
55
from pathlib import Path
66
import subprocess
7+
import sys
78
import unittest
89
from unittest.mock import patch
910

1011

12+
REAL_RUN = subprocess.run
1113
SCRIPT = Path(__file__).resolve().parents[1] / "hack" / "satellite-pre-stop.py"
1214
SPEC = importlib.util.spec_from_file_location("satellite_pre_stop", SCRIPT)
1315
hook = importlib.util.module_from_spec(SPEC)
@@ -200,6 +202,23 @@ def test_unknown_argument_prevents_even_status(self):
200202
hook.main()
201203
self.run.assert_not_called()
202204

205+
def test_chart_command_form_passes_execute_as_the_only_argument(self):
206+
# The chart renders `python3 -c <script> --execute`; CPython sets
207+
# sys.argv[0] to "-c" for that form, so main() receives ["--execute"].
208+
probe = REAL_RUN([sys.executable, "-c", "import sys; print(sys.argv)", "--execute"],
209+
capture_output=True, text=True, check=True)
210+
self.assertEqual(probe.stdout.strip(), "['-c', '--execute']")
211+
hook.sys.argv = ["-c", "--execute"]
212+
self.run.return_value = self.status()
213+
hook.main()
214+
self.events.assert_called_once_with("finished", execute=True, resources=0)
215+
216+
def test_script_name_placeholder_before_execute_is_rejected(self):
217+
hook.sys.argv = ["-c", "hook", "--execute"]
218+
with self.assertRaisesRegex(ValueError, "unsupported-arguments"):
219+
hook.main()
220+
self.run.assert_not_called()
221+
203222
def test_empty_resource_list_is_a_noop(self):
204223
self.run.return_value = self.status()
205224
hook.main()

0 commit comments

Comments
 (0)