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.

Classify VMware unsupported version floor

rcourtman3ec65cc03f29
diff --git a/docs/release-control/v6/internal/VMWARE_VCENTER_PHASE1_API_RUNTIME_SPEC.md b/docs/release-control/v6/internal/VMWARE_VCENTER_PHASE1_API_RUNTIME_SPEC.md
index a0a6724f9c..441cad1f84 100644
--- a/docs/release-control/v6/internal/VMWARE_VCENTER_PHASE1_API_RUNTIME_SPEC.md
+++ b/docs/release-control/v6/internal/VMWARE_VCENTER_PHASE1_API_RUNTIME_SPEC.md
@@ -115,6 +115,8 @@ Phase-1 rule:
setup result
3. saved-connection tests must reuse stored secrets server-side and may accept
an edit overlay payload without requiring masked-secret re-entry
+4. exhausting the implemented VI JSON release probe floor should classify as
+ `unsupported_version`, not as a generic endpoint error
## Runtime Health And Poll Summary Contract
diff --git a/docs/release-control/v6/internal/VMWARE_VCENTER_PHASE1_PROOF_MATRIX.md b/docs/release-control/v6/internal/VMWARE_VCENTER_PHASE1_PROOF_MATRIX.md
index bdc7695ecd..3d0f422bb3 100644
--- a/docs/release-control/v6/internal/VMWARE_VCENTER_PHASE1_PROOF_MATRIX.md
+++ b/docs/release-control/v6/internal/VMWARE_VCENTER_PHASE1_PROOF_MATRIX.md
@@ -191,7 +191,9 @@ Pass when:
Pass when:
1. the draft validates through the shared VMware setup path
-2. failures classify clearly instead of collapsing into generic unknown error
+2. failures classify clearly instead of collapsing into generic unknown error,
+ including `tls`, `network`, `auth`, `permission`, and
+ `unsupported_version` where applicable
3. the path does not require a unified agent or direct `ESXi` routing
4. a green result reflects the declared phase-1 floor rather than one partial
VMware API-family success
diff --git a/internal/api/vmware_handlers_test.go b/internal/api/vmware_handlers_test.go
index ea994f5937..3b387e077d 100644
--- a/internal/api/vmware_handlers_test.go
+++ b/internal/api/vmware_handlers_test.go
@@ -343,6 +343,50 @@ func TestVMwareHandlers_HandleTestConnection_SuccessAndFailure(t *testing.T) {
}
}
+func TestVMwareHandlers_HandleTestConnection_PreservesUnsupportedVersionCategory(t *testing.T) {
+ setVMwareFeatureForTest(t, true)
+
+ handler, _ := newVMwareHandlersForTest(t)
+ handler.newClient = func(cfg vmware.ClientConfig) (vmwareClient, error) {
+ return &fakeVMwareClient{
+ testConnection: func(context.Context) (*vmware.InventorySummary, error) {
+ return nil, &vmware.ConnectionError{
+ Category: "unsupported_version",
+ Message: "VMware vCenter version is outside the implemented VI JSON probe floor; Pulse currently probes 9.0.0.0, 8.0.3, 8.0.2.0, 8.0.1.0",
+ }
+ },
+ }, nil
+ }
+
+ body := marshalVMwareRequest(t, map[string]any{
+ "host": "vcsa.lab.local",
+ "username": "[email protected]",
+ "password": "super-secret",
+ })
+ req := httptest.NewRequest(http.MethodPost, "/api/vmware/connections/test", bytes.NewReader(body))
+ rec := httptest.NewRecorder()
+ handler.HandleTestConnection(rec, req)
+
+ if rec.Code != http.StatusBadRequest {
+ t.Fatalf("expected 400, got %d: %s", rec.Code, rec.Body.String())
+ }
+
+ var payload struct {
+ Code string `json:"code"`
+ Message string `json:"message"`
+ Details map[string]string `json:"details"`
+ }
+ if err := json.NewDecoder(rec.Body).Decode(&payload); err != nil {
+ t.Fatalf("decode error response: %v", err)
+ }
+ if payload.Code != "vmware_connection_failed" {
+ t.Fatalf("unexpected code: %+v", payload)
+ }
+ if payload.Details["category"] != "unsupported_version" {
+ t.Fatalf("expected unsupported_version category, got %+v", payload.Details)
+ }
+}
+
func TestVMwareHandlers_HandleTestSavedConnection_UsesStoredSecretsAndUpdatesRuntimeSummary(t *testing.T) {
setVMwareFeatureForTest(t, true)
diff --git a/internal/vmware/client.go b/internal/vmware/client.go
index ebfb65442f..958374d1a0 100644
--- a/internal/vmware/client.go
+++ b/internal/vmware/client.go
@@ -27,6 +27,8 @@ const (
inventoryResponseLimitByte = 8 << 20
)
+var supportedVIJSONReleases = []string{"9.0.0.0", "8.0.3", "8.0.2.0", "8.0.1.0"}
+
var featureVMwareEnabled atomic.Bool
func init() {
@@ -335,25 +337,8 @@ func (c *Client) getAutomationJSON(
}
switch resp.StatusCode {
case http.StatusOK:
- case http.StatusUnauthorized:
- return &ConnectionError{Category: "auth", Message: fmt.Sprintf("VMware authentication failed while reading %s", label)}
- case http.StatusForbidden:
- return &ConnectionError{Category: "permission", Message: fmt.Sprintf("VMware permissions are insufficient for %s", label)}
- case http.StatusNotFound:
- return &ConnectionError{
- Category: "not_found",
- Message: fmt.Sprintf("VMware %s endpoint is unavailable", label),
- }
- case http.StatusServiceUnavailable:
- return &ConnectionError{
- Category: "unavailable",
- Message: fmt.Sprintf("VMware %s is temporarily unavailable", label),
- }
default:
- return &ConnectionError{
- Category: "endpoint",
- Message: fmt.Sprintf("VMware %s request failed with HTTP %d", label, resp.StatusCode),
- }
+ return classifyReadStatusCode(label, resp.StatusCode)
}
if err := json.Unmarshal(body, target); err != nil {
return &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware %s response was not valid JSON", label)}
@@ -362,23 +347,36 @@ func (c *Client) getAutomationJSON(
}
func (c *Client) resolveVIJSONRelease(ctx context.Context) (string, viJSONServiceContentRefs, error) {
- releases := []string{"9.0.0.0", "8.0.3", "8.0.2.0", "8.0.1.0"}
var lastErr error
- for _, release := range releases {
+ for _, release := range supportedVIJSONReleases {
refs, err := c.fetchVIJSONServiceContentRefs(ctx, release)
if err == nil {
return release, refs, nil
}
lastErr = err
- connectionErr, ok := err.(*ConnectionError)
- if !ok || connectionErr.Category != "endpoint" {
+ if !isVIJSONNotFound(err) {
return "", viJSONServiceContentRefs{}, err
}
}
+ if lastErr != nil && isVIJSONNotFound(lastErr) {
+ return "", viJSONServiceContentRefs{}, &ConnectionError{
+ Category: "unsupported_version",
+ Message: fmt.Sprintf(
+ "VMware vCenter version is outside the implemented VI JSON probe floor; Pulse currently probes %s",
+ strings.Join(supportedVIJSONReleases, ", "),
+ ),
+ }
+ }
if lastErr != nil {
return "", viJSONServiceContentRefs{}, lastErr
}
- return "", viJSONServiceContentRefs{}, &ConnectionError{Category: "endpoint", Message: "VMware VI JSON API release negotiation failed"}
+ return "", viJSONServiceContentRefs{}, &ConnectionError{
+ Category: "unsupported_version",
+ Message: fmt.Sprintf(
+ "VMware vCenter version is outside the implemented VI JSON probe floor; Pulse currently probes %s",
+ strings.Join(supportedVIJSONReleases, ", "),
+ ),
+ }
}
func (c *Client) fetchVIJSONServiceContentRefs(ctx context.Context, release string) (viJSONServiceContentRefs, error) {
@@ -397,11 +395,8 @@ func (c *Client) fetchVIJSONServiceContentRefs(ctx context.Context, release stri
if readErr != nil {
return viJSONServiceContentRefs{}, fmt.Errorf("read vi-json service content response: %w", readErr)
}
- if resp.StatusCode == http.StatusNotFound {
- return viJSONServiceContentRefs{}, &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware VI JSON API release %s is unavailable", release)}
- }
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
- return viJSONServiceContentRefs{}, &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware VI JSON API service-instance request failed with HTTP %d", resp.StatusCode)}
+ return viJSONServiceContentRefs{}, classifyReadStatusCode("vi-json service content", resp.StatusCode)
}
var payload struct {
SessionManager viJSONReference `json:"sessionManager"`
@@ -458,11 +453,28 @@ func (c *Client) loginVIJSON(ctx context.Context, release string, sessionManager
return sessionID, nil
case http.StatusUnauthorized, http.StatusForbidden:
return "", &ConnectionError{Category: "auth", Message: "VMware authentication failed while creating the VI JSON API session"}
+ case http.StatusServiceUnavailable:
+ return "", &ConnectionError{Category: "unavailable", Message: "VMware VI JSON API login is temporarily unavailable"}
default:
return "", &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware VI JSON API login failed with HTTP %d", resp.StatusCode)}
}
}
+func classifyReadStatusCode(label string, statusCode int) error {
+ switch statusCode {
+ case http.StatusUnauthorized:
+ return &ConnectionError{Category: "auth", Message: fmt.Sprintf("VMware authentication failed while reading %s", label)}
+ case http.StatusForbidden:
+ return &ConnectionError{Category: "permission", Message: fmt.Sprintf("VMware permissions are insufficient for %s", label)}
+ case http.StatusNotFound:
+ return &ConnectionError{Category: "not_found", Message: fmt.Sprintf("VMware %s endpoint is unavailable", label)}
+ case http.StatusServiceUnavailable:
+ return &ConnectionError{Category: "unavailable", Message: fmt.Sprintf("VMware %s is temporarily unavailable", label)}
+ default:
+ return &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware %s request failed with HTTP %d", label, statusCode)}
+ }
+}
+
func classifyTransportError(stage string, err error) error {
if err == nil {
return nil
diff --git a/internal/vmware/client_metrics.go b/internal/vmware/client_metrics.go
index 9864d07a0a..0aefbaf962 100644
--- a/internal/vmware/client_metrics.go
+++ b/internal/vmware/client_metrics.go
@@ -307,14 +307,8 @@ func (c *Client) postVIJSONJSON(ctx context.Context, sessionID, path, label stri
}
switch resp.StatusCode {
case http.StatusOK:
- case http.StatusUnauthorized:
- return &ConnectionError{Category: "auth", Message: fmt.Sprintf("VMware authentication failed while reading %s", label)}
- case http.StatusForbidden:
- return &ConnectionError{Category: "permission", Message: fmt.Sprintf("VMware permissions are insufficient for %s", label)}
- case http.StatusNotFound:
- return &ConnectionError{Category: "not_found", Message: fmt.Sprintf("VMware %s endpoint is unavailable", label)}
default:
- return &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware %s request failed with HTTP %d", label, resp.StatusCode)}
+ return classifyReadStatusCode(label, resp.StatusCode)
}
if err := json.Unmarshal(responseBody, target); err != nil {
return &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware %s response was not valid JSON", label)}
diff --git a/internal/vmware/client_signals.go b/internal/vmware/client_signals.go
index 713f3883c3..48486ac3a5 100644
--- a/internal/vmware/client_signals.go
+++ b/internal/vmware/client_signals.go
@@ -510,14 +510,8 @@ func (c *Client) getVIJSONJSON(ctx context.Context, sessionID, path, label strin
}
switch resp.StatusCode {
case http.StatusOK:
- case http.StatusUnauthorized:
- return &ConnectionError{Category: "auth", Message: fmt.Sprintf("VMware authentication failed while reading %s", label)}
- case http.StatusForbidden:
- return &ConnectionError{Category: "permission", Message: fmt.Sprintf("VMware permissions are insufficient for %s", label)}
- case http.StatusNotFound:
- return &ConnectionError{Category: "not_found", Message: fmt.Sprintf("VMware %s endpoint is unavailable", label)}
default:
- return &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware %s request failed with HTTP %d", label, resp.StatusCode)}
+ return classifyReadStatusCode(label, resp.StatusCode)
}
if err := json.Unmarshal(body, target); err != nil {
return &ConnectionError{Category: "endpoint", Message: fmt.Sprintf("VMware %s response was not valid JSON", label)}
diff --git a/internal/vmware/client_test.go b/internal/vmware/client_test.go
index 193e53edc8..a4d656ee21 100644
--- a/internal/vmware/client_test.go
+++ b/internal/vmware/client_test.go
@@ -136,6 +136,75 @@ func TestClientTestConnectionRequiresSignalFloor(t *testing.T) {
}
}
+func TestClientResolveVIJSONReleaseFallsBackToSupportedProbeFloor(t *testing.T) {
+ mux := http.NewServeMux()
+ 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" || refs.PerfManagerMoID != "PerformanceManager" || refs.EventManagerMoID != "EventManager" {
+ t.Fatalf("unexpected refs: %+v", refs)
+ }
+}
+
+func TestClientResolveVIJSONReleaseClassifiesUnsupportedVersionFloor(t *testing.T) {
+ server := httptest.NewTLSServer(http.NewServeMux())
+ 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())
+ if err == nil {
+ t.Fatal("expected unsupported version error")
+ }
+ connectionErr, ok := err.(*ConnectionError)
+ if !ok {
+ t.Fatalf("expected ConnectionError, got %T", err)
+ }
+ if connectionErr.Category != "unsupported_version" {
+ t.Fatalf("connection error category = %q, want unsupported_version", connectionErr.Category)
+ }
+ if !strings.Contains(connectionErr.Message, "9.0.0.0") || !strings.Contains(connectionErr.Message, "8.0.1.0") {
+ t.Fatalf("expected message to mention implemented probe floor, got %q", connectionErr.Message)
+ }
+}
+
type vmwareTestServerConfig struct {
omitHostOverallStatus bool
}