|
9 | 9 |
|
10 | 10 | from ...config.tests.test_controller import TestRegistrationMixin |
11 | 11 | from .. import tasks |
| 12 | +from ..connectors.exceptions import CommandTimeoutException |
12 | 13 | from .utils import CreateConnectionsMixin |
13 | 14 |
|
14 | 15 | Command = load_model("connection", "Command") |
@@ -67,6 +68,30 @@ def test_launch_command_timeout(self, *args): |
67 | 68 | self.assertEqual(command.status, "failed") |
68 | 69 | self.assertEqual(command.output, "Background task time limit exceeded.\n") |
69 | 70 |
|
| 71 | + @mock.patch( |
| 72 | + _mock_execute, |
| 73 | + side_effect=CommandTimeoutException("connection timed out after 30s"), |
| 74 | + ) |
| 75 | + @mock.patch(_mock_connect, return_value=True) |
| 76 | + def test_launch_command_ssh_timeout(self, *args): |
| 77 | + dc = self._create_device_connection() |
| 78 | + command = Command( |
| 79 | + device=dc.device, |
| 80 | + connection=dc, |
| 81 | + type="custom", |
| 82 | + input={"command": "/usr/sbin/exotic_command"}, |
| 83 | + ) |
| 84 | + command.full_clean() |
| 85 | + command.save() |
| 86 | + # must call this explicitly because lack of transactions in this test case |
| 87 | + tasks.launch_command.delay(command.pk) |
| 88 | + command.refresh_from_db() |
| 89 | + self.assertEqual(command.status, "failed") |
| 90 | + self.assertEqual( |
| 91 | + command.output, |
| 92 | + "The command took longer than expected: connection timed out after 30s\n", |
| 93 | + ) |
| 94 | + |
70 | 95 | @mock.patch(_mock_execute, side_effect=RuntimeError("test error")) |
71 | 96 | @mock.patch(_mock_connect, return_value=True) |
72 | 97 | def test_launch_command_exception(self, *args): |
|
0 commit comments