Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Fall through server-error probes in vSphere release negotiation

rcourtmana70e285c4f92
diff --git a/internal/vmware/client.go b/internal/vmware/client.go
index 3e1b7fd7aa..b30708606d 100644
--- a/internal/vmware/client.go
+++ b/internal/vmware/client.go
@@ -422,7 +422,7 @@ func (c *Client) resolveVIJSONRelease(ctx context.Context) (string, viJSONServic
return release, refs, nil
}
lastErr = err
- if !isVIJSONNotFound(err) {
+ if !isVIJSONReleaseProbeRetryable(err) {
return "", viJSONServiceContentRefs{}, err
}
}
@@ -447,6 +447,26 @@ func (c *Client) resolveVIJSONRelease(ctx context.Context) (string, viJSONServic
}
}
+// isVIJSONReleaseProbeRetryable reports whether a failed service-content probe
+// for one vim25 release string should fall through to the next release in the
+// list. vCenter answers a newer-than-supported release path with 404 on some
+// builds and HTTP 500 on others (8.0.x returns 500 for the 9.0.0.0 path), so
+// both "not_found" and generic endpoint failures continue the negotiation.
+// Auth, permission, TLS, and network errors abort: they will not change with a
+// different release string.
+func isVIJSONReleaseProbeRetryable(err error) bool {
+ connectionErr, ok := err.(*ConnectionError)
+ if !ok {
+ return false
+ }
+ switch connectionErr.Category {
+ case "not_found", "endpoint":
+ return true
+ default:
+ return false
+ }
+}
+
func (c *Client) fetchVIJSONServiceContentRefs(ctx context.Context, release string) (viJSONServiceContentRefs, error) {
endpoint := fmt.Sprintf("%s/sdk/vim25/%s/ServiceInstance/ServiceInstance/content", c.baseURL.String(), release)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
diff --git a/internal/vmware/client_test.go b/internal/vmware/client_test.go
index aa37a4ffe8..5dda275fc6 100644
--- a/internal/vmware/client_test.go
+++ b/internal/vmware/client_test.go
@@ -371,6 +371,81 @@ func TestClientResolveVIJSONReleaseFallsBackToSupportedProbeFloor(t *testing.T)
}
}
+// Issue #1596: vCenter 8.0.3 answers the newer 9.0.0.0 release path with
+// HTTP 500 rather than 404. The negotiation must fall through to the next
+// release instead of aborting on the first probe.
+func TestClientResolveVIJSONReleaseFallsThroughServerErrorProbe(t *testing.T) {
+ mux := http.NewServeMux()
+ mux.HandleFunc("/sdk/vim25/9.0.0.0/ServiceInstance/ServiceInstance/content", func(w http.ResponseWriter, r *http.Request) {
+ http.Error(w, "internal error", http.StatusInternalServerError)
+ })
+ mux.HandleFunc("/sdk/vim25/8.0.3/ServiceInstance/ServiceInstance/content", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ if err := json.NewEncoder(w).Encode(map[string]any{
+ "sessionManager": map[string]any{"value": "SessionManager"},
+ "perfManager": map[string]any{"value": "PerformanceManager"},
+ "eventManager": map[string]any{"value": "EventManager"},
+ }); err != nil {
+ t.Fatalf("encode service content: %v", err)
+ }
+ })
+ server := httptest.NewTLSServer(mux)
+ defer server.Close()
+
+ client, err := NewClient(ClientConfig{
+ Host: server.URL,
+ Username: "admin",
+ Password: "secret",
+ InsecureSkipVerify: true,
+ Timeout: 5 * time.Second,
+ })
+ if err != nil {
+ t.Fatalf("NewClient: %v", err)
+ }
+
+ release, refs, err := client.resolveVIJSONRelease(context.Background())
+ if err != nil {
+ t.Fatalf("resolveVIJSONRelease: %v", err)
+ }
+ if release != "8.0.3" {
+ t.Fatalf("release = %q, want 8.0.3", release)
+ }
+ if refs.SessionManagerMoID != "SessionManager" {
+ t.Fatalf("unexpected refs: %+v", refs)
+ }
+}
+
+// Auth failures on the probe must still abort immediately: retrying other
+// release strings cannot fix credentials.
+func TestClientResolveVIJSONReleaseAbortsOnAuthProbe(t *testing.T) {
+ mux := http.NewServeMux()
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ http.Error(w, "unauthorized", http.StatusUnauthorized)
+ })
+ server := httptest.NewTLSServer(mux)
+ defer server.Close()
+
+ client, err := NewClient(ClientConfig{
+ Host: server.URL,
+ Username: "admin",
+ Password: "secret",
+ InsecureSkipVerify: true,
+ Timeout: 5 * time.Second,
+ })
+ if err != nil {
+ t.Fatalf("NewClient: %v", err)
+ }
+
+ _, _, err = client.resolveVIJSONRelease(context.Background())
+ connectionErr, ok := err.(*ConnectionError)
+ if !ok {
+ t.Fatalf("expected ConnectionError, got %T (%v)", err, err)
+ }
+ if connectionErr.Category != "auth" {
+ t.Fatalf("connection error category = %q, want auth", connectionErr.Category)
+ }
+}
+
func TestClientResolveVIJSONReleaseClassifiesUnsupportedVersionFloor(t *testing.T) {
server := httptest.NewTLSServer(http.NewServeMux())
defer server.Close()