The "Scan Floating IP" button failed with a client timeout: the project now holds ~6.4k floating IPs and the scan listed them all in one unpaginated, timeout-less Neutron request on the HTTP request context. openstack: ListFreeFloatingIPs reads marker-based pages (fields= keeps them small) with per-page retry/backoff on transport errors, 5xx and 429, and every request now has a timeout (also ends hangs inside the orchestrator tick). orchestrator: the scan is a single-flight background job on the process context with progress (clearing/listing/enqueuing/done/error), dry_run, full discovery before anything is enqueued, then SubmitIPs in chunks of 500 in ascending IP order; a failed read leaves the queue untouched. The auto-cycle gets a "scanning" phase that polls the job, so the control loop and autoCycleMu are never held across OpenStack/DB work; it recovers after a restart and waits for (instead of adopting) a scan started by someone else. db: migration 0009 (indexes), paged ListIPsPage/ListRegistryPage, GROUP BY counters, EXISTS completion check, set-based ClearAllIPs. API: POST /admin/ips/scan -> 202 (dry_run, wait), GET /admin/ips/scan, paging and filters on /admin/ips and /admin/registry (bare arrays without limit), results_by_overall in /admin/status. dashboard: scan progress panel and dry-run button, paginated /ips and /registry with server-side filters, Overview on counters and capped lists with progress/ETA, "select all N by filter", hx-params fix for per-row buttons, real counts in confirmations. Also: docs (API, USAGE, DASHBOARD, README), plan and review under docs/changes/, bin/ rebuilt with new SHA256SUMS. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
87 lines
2.4 KiB
Go
87 lines
2.4 KiB
Go
package openstack
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gophercloud/gophercloud/v2"
|
|
)
|
|
|
|
// TestClientListFreeFloatingIPsAgainstFakeNeutron drives the real Client
|
|
// against an httptest server: marker pagination, the `fields` projection, a
|
|
// transient 503 that is retried and an empty port_id meaning "free".
|
|
func TestClientListFreeFloatingIPsAgainstFakeNeutron(t *testing.T) {
|
|
const total = 5
|
|
var requests int
|
|
failedOnce := false
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
requests++
|
|
q := r.URL.Query()
|
|
if got := q["fields"]; len(got) != 4 {
|
|
t.Errorf("expected 4 fields params, got %v", got)
|
|
}
|
|
if q.Get("limit") != "2" {
|
|
t.Errorf("expected limit=2, got %q", q.Get("limit"))
|
|
}
|
|
if q.Get("marker") == "id-1" && !failedOnce {
|
|
failedOnce = true
|
|
http.Error(w, "busy", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
start := 0
|
|
if m := q.Get("marker"); m != "" {
|
|
fmt.Sscanf(m, "id-%d", &start)
|
|
start++
|
|
}
|
|
type fip struct {
|
|
ID string `json:"id"`
|
|
Addr string `json:"floating_ip_address"`
|
|
PortID *string `json:"port_id"`
|
|
TenantID string `json:"tenant_id"`
|
|
}
|
|
var items []fip
|
|
for i := start; i < total && len(items) < 2; i++ {
|
|
f := fip{ID: fmt.Sprintf("id-%d", i), Addr: fmt.Sprintf("203.0.113.%d", i+1), TenantID: "p"}
|
|
if i == 1 {
|
|
p := "port-1"
|
|
f.PortID = &p
|
|
}
|
|
items = append(items, f)
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(map[string]any{"floatingips": items})
|
|
}))
|
|
defer srv.Close()
|
|
|
|
c := &Client{
|
|
networking: &gophercloud.ServiceClient{
|
|
ProviderClient: &gophercloud.ProviderClient{HTTPClient: *srv.Client()},
|
|
Endpoint: srv.URL + "/",
|
|
ResourceBase: srv.URL + "/v2.0/",
|
|
},
|
|
retry: pageRetry{Retries: 3, Sleep: func(context.Context, time.Duration) error { return nil }},
|
|
}
|
|
var all []FloatingIP
|
|
pages, err := c.ListFreeFloatingIPs(context.Background(), 2, func(p []FloatingIP) error {
|
|
all = append(all, p...)
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("list: %v", err)
|
|
}
|
|
if pages != 3 || len(all) != total {
|
|
t.Fatalf("expected 3 pages / 5 fips, got %d / %d", pages, len(all))
|
|
}
|
|
if all[1].PortID != "port-1" || all[0].PortID != "" || all[4].Address != "203.0.113.5" {
|
|
t.Fatalf("unexpected mapping: %+v", all)
|
|
}
|
|
if requests != 4 { // 3 pages + 1 retried 503
|
|
t.Fatalf("expected 4 requests, got %d", requests)
|
|
}
|
|
}
|