|
41 | 41 | SWITCH = "Switch the current release symlink" |
42 | 42 | RECEIPT = "Write the release receipt on the controller" |
43 | 43 | TIMEOUT_MARKER = "cloudfall-test-timeout" |
| 44 | +REFUSED_MARKER = "cloudfall-test-refused" |
44 | 45 |
|
45 | 46 | FAKE_SYSTEMD_RUN = f"""#!/bin/sh |
46 | 47 | # Stand-in for systemd-run --wait --pipe: chdir like --working-directory, |
|
55 | 56 | done |
56 | 57 | shift |
57 | 58 | cd "$directory" || exit 200 |
| 59 | +if [ -f "$directory/{REFUSED_MARKER}" ]; then |
| 60 | + echo "Failed to start transient service unit: Unit already exists." >&2 |
| 61 | + exit 1 |
| 62 | +fi |
58 | 63 | "$@" |
59 | 64 | status=$? |
60 | 65 | if [ -f "$directory/{TIMEOUT_MARKER}" ]; then |
@@ -129,12 +134,18 @@ def _local_inventory(tmp_path: Path) -> Path: |
129 | 134 |
|
130 | 135 |
|
131 | 136 | def _run_release_command( |
132 | | - tmp_path: Path, arguments: list[str], *, timed_out: bool = False |
| 137 | + tmp_path: Path, |
| 138 | + arguments: list[str], |
| 139 | + *, |
| 140 | + timed_out: bool = False, |
| 141 | + refused: bool = False, |
133 | 142 | ) -> tuple[int, Path]: |
134 | 143 | """Run the role's release command tasks; answer the exit code and result.""" |
135 | 144 | release_directory, working_directory, systemd_run = _release_tree(tmp_path) |
136 | 145 | if timed_out: |
137 | 146 | (working_directory / TIMEOUT_MARKER).write_text("", encoding="utf-8") |
| 147 | + if refused: |
| 148 | + (working_directory / REFUSED_MARKER).write_text("", encoding="utf-8") |
138 | 149 | result_file = tmp_path / "result.json" |
139 | 150 | variables = { |
140 | 151 | "cloudfall_server_id": "b", |
@@ -297,6 +308,20 @@ def test_s005_5_a_timed_out_release_command_fails_naming_the_timeout( |
297 | 308 | assert "timed out after 300 seconds and was stopped" in output |
298 | 309 |
|
299 | 310 |
|
| 311 | +def test_s005_4_a_unit_that_never_starts_names_systemd_run_s_reason( |
| 312 | + tmp_path: Path, capsys: pytest.CaptureFixture[str] |
| 313 | +) -> None: |
| 314 | + """A unit that never starts fails with systemd-run's own message.""" |
| 315 | + exit_code, result_file = _run_release_command(tmp_path, ["0"], refused=True) |
| 316 | + |
| 317 | + assert exit_code == 82 |
| 318 | + output = _captured_output(capsys) |
| 319 | + assert "exited with code 1" in output |
| 320 | + assert "Failed to start transient service unit" in output |
| 321 | + assert not (tmp_path / "releases" / "20261027T000000Z-abcdef1" / "table").exists() |
| 322 | + assert not result_file.exists() |
| 323 | + |
| 324 | + |
300 | 325 | def test_s005_5_the_timeout_is_the_unit_runtime_limit(tmp_path: Path) -> None: |
301 | 326 | _run_release_command(tmp_path, ["0"]) |
302 | 327 |
|
|
0 commit comments