Skip to content

Commit a87cb0e

Browse files
committed
Add foreman.target lifecycle tests (stop/start and restart)
Extends foreman_target_test.py with lifecycle tests intended to run at the end of the test suite. Tests that foreman.target can be cleanly stopped and restarted, and that Foreman becomes available again afterwards via the HTTPS endpoint (same curl pattern as test_https_foreman_ping in httpd_test.py).
1 parent b1902f0 commit a87cb0e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/target_lifecycle_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import time
2+
3+
FOREMAN_PING_RETRIES = 60
4+
FOREMAN_PING_DELAY = 10
5+
CURL_CMD = "curl --silent --output /dev/null"
6+
7+
8+
def _wait_for_foreman(server, server_fqdn, certificates):
9+
"""Poll the Foreman HTTPS frontend until available or timeout."""
10+
for _ in range(FOREMAN_PING_RETRIES):
11+
cmd = server.run(
12+
f"{CURL_CMD} --cacert {certificates['ca_certificate']}"
13+
f" --write-out '%{{http_code}}' https://{server_fqdn}/api/v2/ping"
14+
)
15+
if cmd.stdout == '200':
16+
return
17+
time.sleep(FOREMAN_PING_DELAY)
18+
raise AssertionError("Foreman did not become available after target lifecycle operation")
19+
20+
21+
def test_foreman_target_stop_start(server, server_fqdn, certificates):
22+
result = server.run("systemctl stop foreman.target")
23+
assert result.rc == 0, f"Failed to stop foreman.target: {result.stderr}"
24+
assert not server.service("foreman.target").is_running
25+
26+
result = server.run("systemctl start foreman.target")
27+
assert result.rc == 0, f"Failed to start foreman.target: {result.stderr}"
28+
_wait_for_foreman(server, server_fqdn, certificates)
29+
assert server.service("foreman.target").is_running
30+
31+
32+
def test_foreman_target_restart(server, server_fqdn, certificates):
33+
result = server.run("systemctl restart foreman.target")
34+
assert result.rc == 0, f"Failed to restart foreman.target: {result.stderr}"
35+
_wait_for_foreman(server, server_fqdn, certificates)
36+
assert server.service("foreman.target").is_running

0 commit comments

Comments
 (0)