Respect Pimox guest exec failures
This commit is contained in:
parent
5a14e2d409
commit
9b9afc1c4e
30
jeannie
30
jeannie
|
|
@ -1051,6 +1051,26 @@ echo 'Pimox VM ${vmid} guest-agent network-get-interfaces:'
|
||||||
sudo '${qm_bin}' guest cmd '${vmid}' network-get-interfaces" >&2 || true
|
sudo '${qm_bin}' guest cmd '${vmid}' network-get-interfaces" >&2 || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pimox_guest_exec_exitcode() {
|
||||||
|
local guest_exec_json="$1"
|
||||||
|
|
||||||
|
GUEST_EXEC_JSON="${guest_exec_json}" python3 - <<'PY'
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
document = json.loads(os.environ.get("GUEST_EXEC_JSON", ""))
|
||||||
|
except Exception:
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(int(document.get("exitcode", 1)))
|
||||||
|
except Exception:
|
||||||
|
sys.exit(2)
|
||||||
|
PY
|
||||||
|
}
|
||||||
|
|
||||||
wait_for_pimox_guest_ssh() {
|
wait_for_pimox_guest_ssh() {
|
||||||
local host="$1"
|
local host="$1"
|
||||||
local user="$2"
|
local user="$2"
|
||||||
|
|
@ -1214,6 +1234,7 @@ configure_pimox_worker_guest_network() {
|
||||||
local script
|
local script
|
||||||
local encoded_script
|
local encoded_script
|
||||||
local network_output
|
local network_output
|
||||||
|
local network_exitcode
|
||||||
local worker_address
|
local worker_address
|
||||||
local lan_probe_host="${LAB_PIMOX_WORKER_LAN_PROBE_HOST:-${LAB_DEBIAN_LAN_IP:-}}"
|
local lan_probe_host="${LAB_PIMOX_WORKER_LAN_PROBE_HOST:-${LAB_DEBIAN_LAN_IP:-}}"
|
||||||
local require_lan_probe="${LAB_PIMOX_WORKER_REQUIRE_LAN_PROBE:-true}"
|
local require_lan_probe="${LAB_PIMOX_WORKER_REQUIRE_LAN_PROBE:-true}"
|
||||||
|
|
@ -1308,7 +1329,14 @@ EOF
|
||||||
while ((SECONDS < deadline)); do
|
while ((SECONDS < deadline)); do
|
||||||
if network_output="$(pimox_ssh "${pimox_host}" "${pimox_user}" "${pimox_key}" "sudo '${qm_bin}' guest exec '${vmid}' -- bash -lc \"printf '%s' '${encoded_script}' | base64 -d | sudo bash\"" 2>&1)"; then
|
if network_output="$(pimox_ssh "${pimox_host}" "${pimox_user}" "${pimox_key}" "sudo '${qm_bin}' guest exec '${vmid}' -- bash -lc \"printf '%s' '${encoded_script}' | base64 -d | sudo bash\"" 2>&1)"; then
|
||||||
printf '%s\n' "${network_output}" | sed 's/^/ guest-network: /'
|
printf '%s\n' "${network_output}" | sed 's/^/ guest-network: /'
|
||||||
return 0
|
if network_exitcode="$(pimox_guest_exec_exitcode "${network_output}")" && [[ "${network_exitcode}" == "0" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "Static guest network validation failed inside Pimox VM ${vmid}." >&2
|
||||||
|
if [[ -n "${network_exitcode:-}" ]]; then
|
||||||
|
echo "Guest exit code: ${network_exitcode}" >&2
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,12 @@ test_pimox_worker_static_ip_selection() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_pimox_guest_exec_exitcode_parser() {
|
||||||
|
assert_eq "pimox guest exec parses success exitcode" "0" "$(pimox_guest_exec_exitcode '{"exitcode":0,"exited":1}')"
|
||||||
|
assert_eq "pimox guest exec parses failed exitcode" "1" "$(pimox_guest_exec_exitcode '{"exitcode":1,"exited":1}')"
|
||||||
|
assert_command_failure_contains "pimox guest exec rejects invalid JSON" "" pimox_guest_exec_exitcode 'not json'
|
||||||
|
}
|
||||||
|
|
||||||
test_pimox_worker_count_detects_generated_topology
|
test_pimox_worker_count_detects_generated_topology
|
||||||
test_configured_worker_count_cannot_hide_existing_workers
|
test_configured_worker_count_cannot_hide_existing_workers
|
||||||
test_configured_worker_count_can_expand_target_set
|
test_configured_worker_count_can_expand_target_set
|
||||||
|
|
@ -343,6 +349,7 @@ test_inventory_validator_accepts_current_inventory
|
||||||
test_inventory_validator_rejects_ip_drift
|
test_inventory_validator_rejects_ip_drift
|
||||||
test_heal_cooldown_escalates_to_diagnostics
|
test_heal_cooldown_escalates_to_diagnostics
|
||||||
test_pimox_worker_static_ip_selection
|
test_pimox_worker_static_ip_selection
|
||||||
|
test_pimox_guest_exec_exitcode_parser
|
||||||
|
|
||||||
if ((FAILURES > 0)); then
|
if ((FAILURES > 0)); then
|
||||||
printf '\n%s unit test(s) failed.\n' "${FAILURES}" >&2
|
printf '\n%s unit test(s) failed.\n' "${FAILURES}" >&2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue