Sfoglia il codice sorgente

fix(reinstall): say which step failed when the installer cannot continue (#1737) (#1852)

Nacho 1 mese fa
parent
commit
be75f4da58

+ 1 - 0
CHANGELOG.md

@@ -42,6 +42,7 @@ y este proyecto se adhiere a [Versionado Semántico](https://semver.org/lang/es/
 
 ### Fixed
 
+- A reinstall that cannot download the agent binary or install the package now says so on stderr, instead of dying silently on the first failing command (#1737).
 - An SSH reinstall that fails now reports the last line the router printed on stderr, not just "Process exited with status 1", so the reason (a failing curl, a full filesystem, a missing command) reaches the operator (#1737).
 - Addresses that come and go within a minute are no longer clients (#1818). Randomised MACs, phones that probe once and mesh units that bounce an association all reached the device table, the counters and the new-client alert within a single poll. A MAC the database has never seen now has to stay online for a minute before it is stored, counted or alerted, and when it finally lands the row keeps the moment it was first seen instead of the moment it was promoted. The wait is kept in memory on purpose: it is a judgement about the current poll cycle, so a restart costs one extra minute at most, and a device that already exists in the table is never held back. Without a database the check steps aside and the old behaviour returns.
 - The neighbour scan survives a radio whose AP interface refuses to scan (#1839). On Asuswrt and other Broadcom firmwares every radio exposes an AP interface and a managed one, the AP one answers `Operation not supported (-95)` to a scan, and the picker preferred AP, so those units reported no neighbours at all while the managed interface on the same radio would have answered. The agent keeps the AP first and, when the scan fails, retries on another interface of the same radio within the same cycle, at most twice, which leaves the uplink alone on units where AP works and fixes the ones where it does not. Each radio also reports the outcome of its scan, the interface that answered and the reason when none did, so a refusal and an empty band no longer look the same on the server.

+ 35 - 0
server-go/internal/reinstall/messages_1737_test.go

@@ -0,0 +1,35 @@
+package reinstall_test
+
+import (
+	"os/exec"
+	"strings"
+	"testing"
+
+	"github.com/gnacho/netpulse/server-go/internal/reinstall"
+)
+
+// #1737: un fallo del instalador tiene que dejar rastro en stderr. El servidor
+// ya devuelve esa ultima linea al operador, pero un wget silencioso o un
+// opkg que falla sin decir nada dejaban solo "Process exited with status 1".
+func TestScriptExplainsItsFailures(t *testing.T) {
+	s := reinstall.ScriptWithTargets(
+		"test-router", strings.Repeat("a1", 32), "https://192.168.1.226:3000", "sha256//AAAA",
+		map[string]string{"arm64": "cafebabe"},
+		reinstall.WanTargets{},
+	)
+
+	for _, want := range []string{
+		`no pude descargar el binario de $SERVER (curl)`,
+		`no pude descargar el binario de $SERVER (wget)`,
+		`el paquete .ipk no se pudo instalar`,
+		`el paquete .apk no se pudo instalar`,
+	} {
+		if !strings.Contains(s, want) {
+			t.Errorf("el script no explica el fallo: %q", want)
+		}
+	}
+
+	if err := exec.Command("sh", "-n", "-c", s).Run(); err != nil {
+		t.Fatalf("script invalido: %v", err)
+	}
+}

+ 9 - 2
server-go/internal/reinstall/reinstall.go

@@ -333,12 +333,16 @@ if command -v opkg >/dev/null 2>&1; then
 	pkg_fetch "$PKG_URL&format=ipk" /tmp/netpulse-agent.ipk || rm -f /tmp/netpulse-agent.ipk
 	if [ -s /tmp/netpulse-agent.ipk ] && opkg install --force-reinstall /tmp/netpulse-agent.ipk >/dev/null 2>&1; then
 		PKG_OK=1
+	else
+		echo "netpulse-agent: el paquete .ipk no se pudo instalar; sigo con los ficheros sueltos" >&2
 	fi
 	rm -f /tmp/netpulse-agent.ipk
 elif command -v apk >/dev/null 2>&1; then
 	pkg_fetch "$PKG_URL&format=apk" /tmp/netpulse-agent.apk || rm -f /tmp/netpulse-agent.apk
 	if [ -s /tmp/netpulse-agent.apk ] && apk add --allow-untrusted /tmp/netpulse-agent.apk >/dev/null 2>&1; then
 		PKG_OK=1
+	else
+		echo "netpulse-agent: el paquete .apk no se pudo instalar; sigo con los ficheros sueltos" >&2
 	fi
 	rm -f /tmp/netpulse-agent.apk
 fi
@@ -348,10 +352,13 @@ fi
 
 if [ "$PKG_OK" != "1" ]; then
 # Descargar el binario del propio server (auth por token)
+# #1737: sin estos mensajes el fallo llega como "Process exited with status
+# 1" y nada mas. wget -q no imprime su motivo, asi que la descarga fallida
+# por wget era completamente muda.
 if command -v curl >/dev/null 2>&1; then
-	curl -fsSL $CURL_TLS --connect-timeout 10 -m 600 -H "Authorization: Bearer $TOKEN" "$SERVER/api/agents/$SLUG/binary?arch=$GOARCH" -o /tmp/netpulse-agent.new
+	curl -fsSL $CURL_TLS --connect-timeout 10 -m 600 -H "Authorization: Bearer $TOKEN" "$SERVER/api/agents/$SLUG/binary?arch=$GOARCH" -o /tmp/netpulse-agent.new || { echo "netpulse-agent: no pude descargar el binario de $SERVER (curl)" >&2; exit 22; }
 else
-	wget -q $WGET_TLS -T 60 -O /tmp/netpulse-agent.new --header="Authorization: Bearer $TOKEN" "$SERVER/api/agents/$SLUG/binary?arch=$GOARCH"
+	wget -q $WGET_TLS -T 60 -O /tmp/netpulse-agent.new --header="Authorization: Bearer $TOKEN" "$SERVER/api/agents/$SLUG/binary?arch=$GOARCH" || { echo "netpulse-agent: no pude descargar el binario de $SERVER (wget)" >&2; exit 22; }
 fi
 
 # Verificación sha256 contra el digest embebido (#463); vacío = sin verificar