Free validator ports in the cloud on clear/cancel/delete
An address still being associated (assigning_fip) has no fip_id in the database, so "clear queue" did not detach it, and the association then finished after the row was gone, leaving the floating IP on the validator port for good. - After clear/cancel/delete, ask the cloud which floating IPs sit on the affected validator ports (new ListFloatingIPsByPort) and detach those that this system queued (known in ip_registry); foreign ones are left. - SetFIPAssociated applies only to a row still in assigning_fip; if the address was removed meanwhile, associateFIP detaches the floating IP. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c0e300f71c
commit
1ee5757004
8 files changed
+287
-5
No files matched your search
@@ -996,3 +996,93 @@ func TestValidatorsStartInParallel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// gatedOS blocks AssociateFloatingIP until release is closed, to hold an
|
||||
// association "in flight" while the test clears the queue.
|
||||
type gatedOS struct {
|
||||
*openstack.MockClient
|
||||
started chan struct{}
|
||||
release chan struct{}
|
||||
}
|
||||
|
||||
func (g gatedOS) AssociateFloatingIP(ctx context.Context, fipID, portID string) error {
|
||||
g.started <- struct{}{}
|
||||
<-g.release
|
||||
return g.MockClient.AssociateFloatingIP(ctx, fipID, portID)
|
||||
}
|
||||
|
||||
func portFIPs(t *testing.T, mock *openstack.MockClient, port string) []openstack.FloatingIP {
|
||||
t.Helper()
|
||||
got, err := mock.ListFloatingIPsByPort(context.Background(), port)
|
||||
if err != nil {
|
||||
t.Fatalf("list by port: %v", err)
|
||||
}
|
||||
return got
|
||||
}
|
||||
|
||||
// Clear queue while an association is still running in the cloud: the
|
||||
// validator port must end up free once the association finishes.
|
||||
func TestClearQueueFreesPortOfInFlightAssociation(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
o, d, mock := newTestOrchestrator(t, 180)
|
||||
g := gatedOS{MockClient: mock, started: make(chan struct{}, 1), release: make(chan struct{})}
|
||||
o.OS = g
|
||||
o.Async = true
|
||||
|
||||
mock.Seed("fip-1", "1.2.3.4", "svc-project")
|
||||
if err := d.RegisterValidator(ctx, "validator-1", "host-1", "port-1", "v0.1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := d.SeedQueue(ctx, []string{"1.2.3.4"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
o.Tick(ctx) // claims the address and starts the association
|
||||
<-g.started
|
||||
|
||||
if _, err := o.ClearQueue(ctx); err != nil {
|
||||
t.Fatalf("clear queue: %v", err)
|
||||
}
|
||||
close(g.release) // the association completes after the clear
|
||||
o.Wait()
|
||||
|
||||
if got := portFIPs(t, mock, "port-1"); len(got) != 0 {
|
||||
t.Fatalf("port-1 still holds %d floating ip(s): %+v", len(got), got)
|
||||
}
|
||||
}
|
||||
|
||||
// Clear queue frees ports that already hold a queued address, including an
|
||||
// attachment left over from earlier, but never touches a floating IP the
|
||||
// system did not queue.
|
||||
func TestClearQueueFreesAllValidatorPorts(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
o, d, mock := newTestOrchestrator(t, 180)
|
||||
|
||||
mock.Seed("fip-1", "1.2.3.4", "svc-project")
|
||||
mock.SeedWithPort("fip-leak", "1.2.3.9", "svc-project", "port-2") // leaked earlier
|
||||
mock.SeedWithPort("fip-foreign", "9.9.9.9", "svc-project", "port-2")
|
||||
if err := d.RegisterValidator(ctx, "validator-1", "h", "port-1", "v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := d.SeedQueue(ctx, []string{"1.2.3.4", "1.2.3.9"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
o.Tick(ctx) // validator-1 gets 1.2.3.4 attached; 1.2.3.9 stays queued, its stale attachment on port-2 is unknown to the queue
|
||||
if err := d.RegisterValidator(ctx, "validator-2", "h", "port-2", "v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := portFIPs(t, mock, "port-1"); len(got) != 1 {
|
||||
t.Fatalf("setup: expected 1 floating ip on port-1, got %d", len(got))
|
||||
}
|
||||
|
||||
if _, err := o.ClearQueue(ctx); err != nil {
|
||||
t.Fatalf("clear queue: %v", err)
|
||||
}
|
||||
if got := portFIPs(t, mock, "port-1"); len(got) != 0 {
|
||||
t.Fatalf("port-1 not free: %+v", got)
|
||||
}
|
||||
got := portFIPs(t, mock, "port-2")
|
||||
if len(got) != 1 || got[0].Address != "9.9.9.9" {
|
||||
t.Fatalf("port-2: expected only the foreign 9.9.9.9 to remain, got %+v", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user