|
12 | 12 |
|
13 | 13 | import logging
|
14 | 14 | import os
|
15 |
| -from unittest.mock import mock_open |
16 | 15 |
|
17 | 16 | import pytest
|
18 | 17 | import slurm_plugin
|
19 | 18 | from assertpy import assert_that
|
20 |
| -from slurm_plugin.computemgtd import ComputemgtdConfig, _is_self_node_down, _is_ubuntu2404, _self_terminate |
| 19 | +from slurm_plugin.computemgtd import ComputemgtdConfig, _is_self_node_down, _self_terminate |
21 | 20 | from slurm_plugin.slurm_resources import DynamicNode
|
22 | 21 |
|
23 | 22 |
|
@@ -104,38 +103,13 @@ def test_is_self_node_down(mock_node_info, expected_result, mocker):
|
104 | 103 | assert_that(_is_self_node_down("queue1-st-c5xlarge-1")).is_equal_to(expected_result)
|
105 | 104 |
|
106 | 105 |
|
107 |
| -@pytest.mark.parametrize( |
108 |
| - ("is_ubuntu2404", "expected_cmd"), |
109 |
| - [ |
110 |
| - (True, "sudo systemctl poweroff --force"), |
111 |
| - (False, "sudo shutdown -h now"), |
112 |
| - ], |
113 |
| -) |
114 |
| -def test_self_terminate(mocker, caplog, is_ubuntu2404, expected_cmd): |
| 106 | +def test_self_terminate(mocker, caplog): |
115 | 107 | """Verify self-termination is implemented via a shutdown command rather than calling TerminateInstances."""
|
116 |
| - mocker.patch("slurm_plugin.computemgtd._is_ubuntu2404", return_value=is_ubuntu2404) |
117 | 108 | run_command_patch = mocker.patch("slurm_plugin.computemgtd.run_command")
|
118 | 109 | sleep_patch = mocker.patch("slurm_plugin.computemgtd.time.sleep")
|
119 | 110 | with caplog.at_level(logging.INFO):
|
120 | 111 | _self_terminate()
|
121 | 112 | assert_that(caplog.text).contains("Preparing to self terminate the instance in 10 seconds!")
|
122 | 113 | assert_that(caplog.text).contains("Self terminating instance now!")
|
123 |
| - run_command_patch.assert_called_with(expected_cmd) |
| 114 | + run_command_patch.assert_called_with("sudo shutdown -h now") |
124 | 115 | sleep_patch.assert_called_with(10)
|
125 |
| - |
126 |
| - |
127 |
| -@pytest.mark.parametrize( |
128 |
| - ("file_content", "expected"), |
129 |
| - [ |
130 |
| - ('ID=ubuntu\nVERSION_ID="24.04"\n', True), |
131 |
| - ('ID=ubuntu\nVERSION_ID="24.04.2"\n', True), |
132 |
| - ('ID=ubuntu\nVERSION_ID="22.04"\n', False), |
133 |
| - ('ID=rocky\nVERSION_ID="9.3"\n', False), |
134 |
| - ("ID=ubuntu\n", False), |
135 |
| - ], |
136 |
| -) |
137 |
| -def test_is_ubuntu2404(file_content, expected, mocker): |
138 |
| - m = mock_open(read_data=file_content) |
139 |
| - mocker.patch("builtins.open", m) |
140 |
| - |
141 |
| - assert _is_ubuntu2404() is expected |
0 commit comments