#!/usr/bin/env bash set -u -o pipefail TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "${TEST_ROOT}/tests/testlib.sh" source "${TEST_ROOT}/inc/cluster-update.inc" nodes_json='[ {"node":"pve3","status":"offline"}, {"node":"pve1","status":"online"}, {"node":"pve2","status":"online"}, {"node":"bad node","status":"online"} ]' expected=$'pve1\tonline\npve2\tonline\npve3\toffline' assert_equal "$expected" \ "$(printf '%s' "$nodes_json" | TAPM_CLUSTER_NODES_FROM_JSON)" \ "cluster node discovery filters and sorts API output" wrapped_json='{"data":[{"node":"pve2.example","status":"ONLINE"}]}' assert_equal $'pve2.example\tonline' \ "$(printf '%s' "$wrapped_json" | TAPM_CLUSTER_NODES_FROM_JSON)" \ "wrapped API response and normalized status" if printf '%s' 'not-json' | TAPM_CLUSTER_NODES_FROM_JSON 2>/dev/null; then printf 'FAIL: malformed cluster JSON was accepted\n' >&2 exit 1 fi assert_failure "remote node rejects shell characters" \ TAPM_UPDATE_REMOTE_NODE 'pve1;reboot' test_dir="$(mktemp -d)" trap 'rm -rf "$test_dir"' EXIT TAPM_COROSYNC_CONFIG="${test_dir}/corosync.conf" printf 'totem {}\n' >"$TAPM_COROSYNC_CONFIG" update_log="${test_dir}/updates" LightCyan=0 LightYellow=0 Green=0 Red=0 Default=0 idsCL[0]='' pvesh() { return 0 } TAPM_CLUSTER_NODE_ROWS() { printf 'pve1\tonline\npve2\tonline\npve3\toffline\n' } TAPM_LOCAL_CLUSTER_NODE() { printf 'pve1\n' } TAPM_UPDATE_REMOTE_NODE() { printf 'remote:%s\n' "$1" >>"$update_log" } INSTALL_LOCAL_UPDATES() { printf 'local:pve1\n' >>"$update_log" } if INSTALL_CLUSTER_UPDATES >/dev/null; then printf 'FAIL: cluster update ignored an offline node\n' >&2 exit 1 fi assert_equal $'remote:pve2\nlocal:pve1' \ "$(cat "$update_log")" \ "online remotes and initiating node update once" finish_tests