Created
February 6, 2026 15:50
-
-
Save trozet/1c4bcd1250f34c253f119c1d34da225f to your computer and use it in GitHub Desktop.
libovsdbops duplicate txns with no real update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/go-controller/pkg/libovsdb/ops/switch_test.go b/go-controller/pkg/libovsdb/ops/switch_test.go | |
| index f24d0ad162..29ee4bfef7 100644 | |
| --- a/go-controller/pkg/libovsdb/ops/switch_test.go | |
| +++ b/go-controller/pkg/libovsdb/ops/switch_test.go | |
| @@ -5,10 +5,93 @@ import ( | |
| "fmt" | |
| "testing" | |
| + libovsdbclient "github.com/ovn-kubernetes/libovsdb/client" | |
| + "github.com/ovn-kubernetes/libovsdb/ovsdb" | |
| + | |
| "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb" | |
| libovsdbtest "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/testing/libovsdb" | |
| ) | |
| +type transactCapturingClient struct { | |
| + libovsdbclient.Client | |
| + opsByCall [][]ovsdb.Operation | |
| +} | |
| + | |
| +func (t *transactCapturingClient) Transact(ctx context.Context, ops ...ovsdb.Operation) ([]ovsdb.OperationResult, error) { | |
| + copiedOps := append([]ovsdb.Operation(nil), ops...) | |
| + t.opsByCall = append(t.opsByCall, copiedOps) | |
| + return t.Client.Transact(ctx, ops...) | |
| +} | |
| + | |
| +func TestCreateOrUpdateLogicalSwitchPortsTransactsUpdateOnUnchangedSecondCall(t *testing.T) { | |
| + initialSwitch := &nbdb.LogicalSwitch{ | |
| + Name: "sw0", | |
| + UUID: buildNamedUUID(), | |
| + } | |
| + | |
| + nbClient, cleanup, err := libovsdbtest.NewNBTestHarness( | |
| + libovsdbtest.TestSetup{ | |
| + NBData: []libovsdbtest.TestData{initialSwitch}, | |
| + }, | |
| + nil, | |
| + ) | |
| + if err != nil { | |
| + t.Fatalf("failed to set up NB test harness: %v", err) | |
| + } | |
| + t.Cleanup(cleanup.Cleanup) | |
| + | |
| + capturingClient := &transactCapturingClient{Client: nbClient} | |
| + sw := &nbdb.LogicalSwitch{Name: initialSwitch.Name} | |
| + lsp := &nbdb.LogicalSwitchPort{ | |
| + Name: "lsp0", | |
| + UUID: buildNamedUUID(), | |
| + Addresses: []string{"0a:58:0a:80:00:01 10.128.0.2"}, | |
| + } | |
| + | |
| + err = createOrUpdateLogicalSwitchPorts(capturingClient, sw, false, lsp) | |
| + if err != nil { | |
| + t.Fatalf("first createOrUpdateLogicalSwitchPorts call failed: %v", err) | |
| + } | |
| + if len(capturingClient.opsByCall) != 1 { | |
| + t.Fatalf("expected exactly 1 transaction after first call, got %d", len(capturingClient.opsByCall)) | |
| + } | |
| + | |
| + err = createOrUpdateLogicalSwitchPorts(capturingClient, sw, false, lsp) | |
| + if err != nil { | |
| + t.Fatalf("second createOrUpdateLogicalSwitchPorts call failed: %v", err) | |
| + } | |
| + if len(capturingClient.opsByCall) != 2 { | |
| + t.Fatalf("expected exactly 2 transactions after second call, got %d", len(capturingClient.opsByCall)) | |
| + } | |
| + | |
| + secondCallOps := capturingClient.opsByCall[1] | |
| + if len(secondCallOps) == 0 { | |
| + t.Fatalf("expected second call to include ovsdb operations, got none") | |
| + } | |
| + | |
| + foundLSPUpdateOp := false | |
| + for _, op := range secondCallOps { | |
| + if op.Table == "Logical_Switch_Port" && op.Op == ovsdb.OperationUpdate { | |
| + foundLSPUpdateOp = true | |
| + break | |
| + } | |
| + } | |
| + if !foundLSPUpdateOp { | |
| + t.Fatalf("expected second call to contain a Logical_Switch_Port update op, got ops: %+v", secondCallOps) | |
| + } | |
| + | |
| + storedSwitch, err := GetLogicalSwitch(nbClient, &nbdb.LogicalSwitch{Name: initialSwitch.Name}) | |
| + if err != nil { | |
| + t.Fatalf("failed to read logical switch from NBDB: %v", err) | |
| + } | |
| + if len(storedSwitch.Ports) != 1 { | |
| + t.Fatalf("expected logical switch to contain exactly 1 port, got %d", len(storedSwitch.Ports)) | |
| + } | |
| + if storedSwitch.Ports[0] != lsp.UUID { | |
| + t.Fatalf("expected logical switch port UUID %q, got %q", lsp.UUID, storedSwitch.Ports[0]) | |
| + } | |
| +} | |
| + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment