diff --git a/install-probe.sh b/install-probe.sh index a39b126..e5e26d4 100755 --- a/install-probe.sh +++ b/install-probe.sh @@ -219,7 +219,8 @@ find_ct() { } create_ct() { - local ctname=$1 tag=$2 tstore=${LXC_TEMPLATE_STORAGE:-local} storage=${LXC_STORAGE:-} tmpl name + local ctname=$1 tag=$2 tstore=${LXC_TEMPLATE_STORAGE:-local} storage tmpl name + storage=$(pick_storage) CTID=${LXC_ID:-$(pvesh get /cluster/nextid)} tmpl=$(pveam list "$tstore" 2>/dev/null | awk '{ print $1 }' | grep -E 'vztmpl/debian-1[23]-standard' | sort -V | tail -1 || true) if [ -z "$tmpl" ]; then @@ -230,14 +231,6 @@ create_ct() { pveam download "$tstore" "$name" >/dev/null || die "could not download $name to $tstore (set LXC_TEMPLATE_STORAGE)" tmpl="$tstore:vztmpl/$name" fi - if [ -z "$storage" ]; then - local avail - avail=$(pvesm status --content rootdir --enabled 1 2>/dev/null | awk 'NR > 1 && $3 == "active" { print $1 }') - for name in local-lvm local-zfs $avail; do - if echo "$avail" | grep -qx "$name"; then storage=$name; break; fi - done - [ -n "$storage" ] || die "no active storage for containers found; set LXC_STORAGE" - fi log "creating container $CTID ($ctname) from $tmpl on $storage, bridge ${LXC_BRIDGE:-vmbr0}" pct create "$CTID" "$tmpl" --hostname "$ctname" --cores "${LXC_CORES:-1}" --memory "${LXC_MEMORY:-512}" --swap 256 \ --rootfs "$storage:${LXC_DISK:-4}" \ @@ -246,6 +239,28 @@ create_ct() { --description "Network Monitor $ROLE, created by the $NAME installer" >/dev/null || die "pct create failed" } +# Storage for the container's disk: LXC_STORAGE, else an active storage on this node that +# allows containers (content rootdir), preferring local-lvm and local-zfs. In a cluster, +# storages assigned to other nodes show as "disabled" here and don't count. +pick_storage() { + local avail name line + if [ -n "${LXC_STORAGE:-}" ]; then echo "$LXC_STORAGE"; return; fi + avail=$(pvesm status --content rootdir 2>/dev/null | awk 'NR > 1 && $3 == "active" { print $1 }' || true) + for name in local-lvm local-zfs $avail; do + if echo "$avail" | grep -qx "$name"; then echo "$name"; return; fi + done + { + printf '\nerror: no storage on this node can hold the container.\n' + printf 'Storages that allow containers (content rootdir), and their status on %s:\n' "$(hostname)" + pvesm status --content rootdir 2>/dev/null | awk 'NR > 1 { printf " %-20s %s\n", $1, $3 }' + printf '"disabled" means not enabled for this node (Datacenter > Storage > Enable / Nodes).\n' + printf 'Fix one of them, or let the local directory storage hold containers:\n' + printf ' pvesm set local --content %s,rootdir\n' "$(awk '/^dir: local$/ { f = 1; next } f && /^[a-z]+:/ { f = 0 } f && $1 == "content" { print $2 }' /etc/pve/storage.cfg 2>/dev/null || echo 'backup,iso,vztmpl')" + printf 'then run the installer again with LXC_STORAGE= before bash.\n' + } >&2 + exit 1 +} + wait_ct_network() { log "waiting for container $CTID to get network" local i=0 diff --git a/install.sh b/install.sh index 79c6ca9..7e32f11 100755 --- a/install.sh +++ b/install.sh @@ -214,7 +214,8 @@ find_ct() { } create_ct() { - local ctname=$1 tag=$2 tstore=${LXC_TEMPLATE_STORAGE:-local} storage=${LXC_STORAGE:-} tmpl name + local ctname=$1 tag=$2 tstore=${LXC_TEMPLATE_STORAGE:-local} storage tmpl name + storage=$(pick_storage) CTID=${LXC_ID:-$(pvesh get /cluster/nextid)} tmpl=$(pveam list "$tstore" 2>/dev/null | awk '{ print $1 }' | grep -E 'vztmpl/debian-1[23]-standard' | sort -V | tail -1 || true) if [ -z "$tmpl" ]; then @@ -225,14 +226,6 @@ create_ct() { pveam download "$tstore" "$name" >/dev/null || die "could not download $name to $tstore (set LXC_TEMPLATE_STORAGE)" tmpl="$tstore:vztmpl/$name" fi - if [ -z "$storage" ]; then - local avail - avail=$(pvesm status --content rootdir --enabled 1 2>/dev/null | awk 'NR > 1 && $3 == "active" { print $1 }') - for name in local-lvm local-zfs $avail; do - if echo "$avail" | grep -qx "$name"; then storage=$name; break; fi - done - [ -n "$storage" ] || die "no active storage for containers found; set LXC_STORAGE" - fi log "creating container $CTID ($ctname) from $tmpl on $storage, bridge ${LXC_BRIDGE:-vmbr0}" pct create "$CTID" "$tmpl" --hostname "$ctname" --cores "${LXC_CORES:-1}" --memory "${LXC_MEMORY:-512}" --swap 256 \ --rootfs "$storage:${LXC_DISK:-4}" \ @@ -241,6 +234,28 @@ create_ct() { --description "Network Monitor $ROLE, created by the $NAME installer" >/dev/null || die "pct create failed" } +# Storage for the container's disk: LXC_STORAGE, else an active storage on this node that +# allows containers (content rootdir), preferring local-lvm and local-zfs. In a cluster, +# storages assigned to other nodes show as "disabled" here and don't count. +pick_storage() { + local avail name line + if [ -n "${LXC_STORAGE:-}" ]; then echo "$LXC_STORAGE"; return; fi + avail=$(pvesm status --content rootdir 2>/dev/null | awk 'NR > 1 && $3 == "active" { print $1 }' || true) + for name in local-lvm local-zfs $avail; do + if echo "$avail" | grep -qx "$name"; then echo "$name"; return; fi + done + { + printf '\nerror: no storage on this node can hold the container.\n' + printf 'Storages that allow containers (content rootdir), and their status on %s:\n' "$(hostname)" + pvesm status --content rootdir 2>/dev/null | awk 'NR > 1 { printf " %-20s %s\n", $1, $3 }' + printf '"disabled" means not enabled for this node (Datacenter > Storage > Enable / Nodes).\n' + printf 'Fix one of them, or let the local directory storage hold containers:\n' + printf ' pvesm set local --content %s,rootdir\n' "$(awk '/^dir: local$/ { f = 1; next } f && /^[a-z]+:/ { f = 0 } f && $1 == "content" { print $2 }' /etc/pve/storage.cfg 2>/dev/null || echo 'backup,iso,vztmpl')" + printf 'then run the installer again with LXC_STORAGE= before bash.\n' + } >&2 + exit 1 +} + wait_ct_network() { log "waiting for container $CTID to get network" local i=0 diff --git a/tests/test_installers.py b/tests/test_installers.py index 244a7fb..c922e20 100644 --- a/tests/test_installers.py +++ b/tests/test_installers.py @@ -107,3 +107,20 @@ export -f pct pvesh pveam pvesm sleep id log.write_text("") r = run() assert r.returncode == 0 and "reusing container 105" in r.stdout and "pct create" not in log.read_text() + + +def test_proxmox_no_container_storage_explains_why(tmp_path): + stubs = f''' +pct() {{ case $1 in list) printf 'VMID Status Lock Name\\n' ;; esac; true; }} +pvesh() {{ echo 105; }} +pveam() {{ echo "pveam $*" >> {tmp_path}/calls; true; }} +pvesm() {{ printf "Name Type Status Total\\nlocal-lvm lvmthin disabled 0\\ngmktec-nvme lvmthin disabled 0\\n"; }} +id() {{ if [ "$1" = -u ]; then echo 0; else command id "$@"; fi; }} +export -f pct pvesh pveam pvesm id +''' + (tmp_path / "pve").mkdir() + env = {**os.environ, "NETMON_PVE_DIR": str(tmp_path / "pve"), "INSTALL_DIR": str(tmp_path / "opt")} + r = subprocess.run(["bash", "-c", stubs + "bash install.sh"], cwd=ROOT, capture_output=True, text=True, env=env, timeout=60) + assert r.returncode != 0 + assert "gmktec-nvme" in r.stderr and "disabled" in r.stderr and "LXC_STORAGE" in r.stderr + assert not (tmp_path / "calls").exists() # nothing downloaded before giving up