93d33ecb0c
SLICE-08 (devops-engineer): .env.example updated with Proxmox deployment vars (documented, sourced from ~/coreci/.env.secrets per D-026), PRAXIS_CLIENT_DIST for StaticFiles, PRAXIS_SCENARIO. config.json secrets.scopes already extended in SPECIFY (proxmox + voice scopes). SLICE-09 (devops-engineer): 10 bats test files (G-106 fix: 10 not 9) covering all proxmox scripts — 121 tests, 114 pass + 7 skipped (e2e). Mocked curl/pct/ssh; no live cluster needed for unit tests. SLICE-10 (devops-engineer): e2e-deploy.sh — sources secrets from both coreci + praxis .env.secrets, runs full deploy, verifies /health + client HTML serving. REQ-DEPLOY-15 covered. All 6 grill binding decisions addressed: G-101 MUST: GITEA_TOKEN baked into snippet (stage-snippet.sh) G-102 MUST: PRAXIS_DB_PATH env read (db/store.py + db/migrate.py) G-103 FIX: all 16 env vars in injection list (install-service.sh) G-104 FIX: health-check timeout 600s (health-check.sh) G-105 FIX: Dockerfile copy ordering (pyproject before source) G-106 FIX: bats test count = 10 REQ-DEPLOY-12, 14, 15 covered. All 20 REQ-IDs now implemented. ---ci--- project: praxis phase: 1 milestone: v0.2 status: execute slice: 08-10 wave: 4 ---/ci---
95 lines
2.9 KiB
Bash
95 lines
2.9 KiB
Bash
#!/usr/bin/env bats
|
|
# Bats tests for scripts/proxmox/lxc-start.sh (praxis CT start).
|
|
#
|
|
# Run: bats scripts/proxmox/test/lxc-start.bats
|
|
#
|
|
# lxc-start.sh POSTs to /nodes/{node}/lxc/{vmid}/status/start, then
|
|
# polls the returned UPID until the async start task completes. These
|
|
# tests exercise the real lxc-start.sh with a mocked api.sh (pve_curl
|
|
# returns the UPID, pve_poll records the call) so the start-POST +
|
|
# UPID-poll + empty-UPID error path are verified without a live
|
|
# Proxmox endpoint.
|
|
|
|
setup() {
|
|
SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
|
|
START="${SCRIPT_DIR}/lxc-start.sh"
|
|
|
|
STUB_DIR="$(mktemp -d)"
|
|
export STUB_DIR
|
|
LOG="${STUB_DIR}/calls.log"
|
|
export CALL_LOG="$LOG"
|
|
: > "$LOG" 2>/dev/null || true
|
|
|
|
# Sandbox: <ROOT>/lxc-start.sh (SCRIPT_DIR) + <ROOT>/api.sh (sourced).
|
|
ROOT="${STUB_DIR}/root"
|
|
mkdir -p "$ROOT"
|
|
cp "$START" "${ROOT}/lxc-start.sh"
|
|
|
|
# Mocked api.sh — pve_env no-op; pve_curl records method + path then
|
|
# returns STUB_UPID; pve_poll records the UPID it was asked to wait on.
|
|
cat > "${ROOT}/api.sh" <<'ASTUB'
|
|
pve_env() { :; }
|
|
pve_curl() {
|
|
method="$1"; path="$2"; shift 2
|
|
printf '%s\n' "${method} ${path}" >> "$CALL_LOG"
|
|
printf '%s\n' "${STUB_UPID:-null}"
|
|
}
|
|
pve_poll() {
|
|
printf 'poll:%s\n' "$1" >> "$CALL_LOG"
|
|
}
|
|
pve_tls_insecure() { :; }
|
|
pve_auth_header() { :; }
|
|
ASTUB
|
|
|
|
chmod +x "${ROOT}"/*.sh
|
|
|
|
export PROXMOX_API_URL="https://proxmox.test:8006/api2/json"
|
|
export PROXMOX_API_TOKEN="root@pam!test=secret"
|
|
export PROXMOX_NODE="testnode"
|
|
}
|
|
|
|
teardown() {
|
|
[ -n "${STUB_DIR:-}" ] && rm -rf "$STUB_DIR"
|
|
}
|
|
|
|
@test "start: POST /nodes/{node}/lxc/{vmid}/status/start + UPID poll → running" {
|
|
STUB_UPID="UPID:testnode:00056789:START"
|
|
export STUB_UPID
|
|
run "${ROOT}/lxc-start.sh" 200
|
|
[ "$status" -eq 0 ]
|
|
grep -q '^POST /nodes/testnode/lxc/200/status/start$' "$LOG"
|
|
grep -q '^poll:UPID:testnode:00056789:START$' "$LOG"
|
|
grep -q 'lxc-start: VMID 200 is running' <<< "$output"
|
|
}
|
|
|
|
@test "start: empty UPID (null) → exit 1, no poll, error logged" {
|
|
STUB_UPID="null"
|
|
export STUB_UPID
|
|
run "${ROOT}/lxc-start.sh" 201
|
|
[ "$status" -ne 0 ]
|
|
grep -q '^POST /nodes/testnode/lxc/201/status/start$' "$LOG"
|
|
grep -q 'failed to start (empty UPID)' <<< "$output"
|
|
! grep -q '^poll:' "$LOG"
|
|
}
|
|
|
|
@test "start: empty-string UPID → exit 1, no poll" {
|
|
STUB_UPID=""
|
|
export STUB_UPID
|
|
run "${ROOT}/lxc-start.sh" 202
|
|
[ "$status" -ne 0 ]
|
|
grep -q 'failed to start (empty UPID)' <<< "$output"
|
|
! grep -q '^poll:' "$LOG"
|
|
}
|
|
|
|
@test "start: missing VMID arg → exit non-zero (usage)" {
|
|
run "${ROOT}/lxc-start.sh"
|
|
[ "$status" -ne 0 ]
|
|
grep -q 'usage: lxc-start.sh' <<< "$output"
|
|
}
|
|
|
|
@test "start: pve_env fails on missing PROXMOX_NODE → exit non-zero (set -u on \${PROXMOX_NODE})" {
|
|
STUB_UPID="UPID:e:1"
|
|
export STUB_UPID
|
|
run env -u PROXMOX_NODE "${ROOT}/lxc-start.sh" 203
|
|
[ "$status" -ne 0 ]
|
|
} |