diff --git a/pkg/ipam/subnet_test.go b/pkg/ipam/subnet_test.go index 0b160893e85..aea2cac8d62 100644 --- a/pkg/ipam/subnet_test.go +++ b/pkg/ipam/subnet_test.go @@ -1136,3 +1136,13 @@ func TestPopPodNic(t *testing.T) { subnet.popPodNic(podName, nicName) require.Equal(t, 0, len(subnet.PodToNicList[podName])) } + +func TestGetStaticMac(t *testing.T) { + subnet, err := NewSubnet("v4Subnet", "10.0.0.0/24", nil) + require.NoError(t, err) + require.NotNil(t, subnet) + podName := "pod1.default" + nicName := "nic1" + err = subnet.GetStaticMac(podName, nicName, "", false) + require.NoError(t, err) +} diff --git a/pkg/ovs/ovn-nb-acl_test.go b/pkg/ovs/ovn-nb-acl_test.go index 42366e183ce..c91ccb50f0f 100644 --- a/pkg/ovs/ovn-nb-acl_test.go +++ b/pkg/ovs/ovn-nb-acl_test.go @@ -577,7 +577,7 @@ func (suite *OvnClientTestSuite) testCreateSgDenyAllACL() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient t.Run("normal create sg deny all acl", func(t *testing.T) { sgName := "test_create_deny_all_acl_pg" @@ -617,6 +617,11 @@ func (suite *OvnClientTestSuite) testCreateSgDenyAllACL() { require.Error(t, err) }) + t.Run("should print log err when sg name is empty", func(t *testing.T) { + err := nbClient.CreateSgDenyAllACL("") + require.ErrorContains(t, err, "the port group name or logical switch name is required") + }) + t.Run("fail nb client should log err", func(t *testing.T) { sgName := "test_failed_client" err := failedNbClient.CreateSgDenyAllACL(sgName) @@ -719,6 +724,11 @@ func (suite *OvnClientTestSuite) testCreateSgBaseACL() { match = fmt.Sprintf("%s == @%s && ip.proto == 112", portDirection, pgName) expect(pg, match, ovnnb.ACLDirectionFromLport) }) + + t.Run("should return no err when sg name is empty", func(t *testing.T) { + err := nbClient.CreateSgBaseACL("", ovnnb.ACLDirectionFromLport) + require.NoError(t, err) + }) } func (suite *OvnClientTestSuite) testUpdateSgACL() { @@ -832,6 +842,16 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { require.Equal(t, expect, rulACL) require.Contains(t, pg.ACLs, rulACL.UUID) }) + + t.Run("should print log err when sg name is empty", func(t *testing.T) { + sg := &kubeovnv1.SecurityGroup{ + ObjectMeta: metav1.ObjectMeta{ + Name: "", + }, + } + err = nbClient.UpdateSgACL(sg, ovnnb.ACLDirectionToLport) + require.ErrorContains(t, err, "the port group name or logical switch name is required") + }) } func (suite *OvnClientTestSuite) testUpdateLogicalSwitchACL() { @@ -1130,6 +1150,11 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { } } }) + + t.Run("should print log err when ls name is empty", func(t *testing.T) { + err := nbClient.SetLogicalSwitchPrivate("", cidrBlock, nodeSwitchCidrBlock, allowSubnets) + require.ErrorContains(t, err, "the port group name or logical switch name is required") + }) } func (suite *OvnClientTestSuite) testNewSgRuleACL() { @@ -1356,7 +1381,7 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient pgName := "test-del-acls-pg" lsName := "test-del-acls-ls" matchPrefix := "outport == @ovn.sg.test_del_acl_pg && ip" @@ -2450,7 +2475,7 @@ func (suite *OvnClientTestSuite) testCreateBareACL() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient t.Run("create bare ACL successfully", func(t *testing.T) { err := nbClient.CreateBareACL("test-parent", "from-lport", "1000", "ip4.src == 10.0.0.1", "allow") @@ -2529,7 +2554,7 @@ func (suite *OvnClientTestSuite) testUpdateACL() { t := suite.T() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient // nbClient := suite.ovnNBClient pgName := "test_update_acl_pg" diff --git a/pkg/ovs/ovn-nb-address_set_test.go b/pkg/ovs/ovn-nb-address_set_test.go index bb73d045945..a003033931e 100644 --- a/pkg/ovs/ovn-nb-address_set_test.go +++ b/pkg/ovs/ovn-nb-address_set_test.go @@ -163,6 +163,11 @@ func (suite *OvnClientTestSuite) testAddressSetUpdateAddress() { require.Error(t, err) require.Contains(t, err.Error(), "get address set") }) + + t.Run("update address set with invalid address", func(t *testing.T) { + err := nbClient.AddressSetUpdateAddress(asName, "192.168.1.1/xx") + require.NoError(t, err) + }) } func (suite *OvnClientTestSuite) testDeleteAddressSet() { @@ -327,6 +332,15 @@ func (suite *OvnClientTestSuite) testUpdateAddressSet() { nbClient := suite.ovnNBClient + as := newAddressSet("test_update_as", map[string]string{ + sgKey: "test-sg", + }) + + t.Run("update with nil address set", func(t *testing.T) { + err := nbClient.UpdateAddressSet(as, nil) + require.Error(t, err) + }) + t.Run("update with nil address set", func(t *testing.T) { err := nbClient.UpdateAddressSet(nil) require.Error(t, err) diff --git a/pkg/ovs/ovn-nb-bfd_test.go b/pkg/ovs/ovn-nb-bfd_test.go index 0fe4b2c6ff1..d63e34912a0 100644 --- a/pkg/ovs/ovn-nb-bfd_test.go +++ b/pkg/ovs/ovn-nb-bfd_test.go @@ -60,7 +60,7 @@ func (suite *OvnClientTestSuite) testListBFD() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrpName := "test-list-bfd" dstIP1 := "192.168.124.2" @@ -116,7 +116,7 @@ func (suite *OvnClientTestSuite) testDeleteBFD() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrpName := "test-del-bfd" dstIP1 := "192.168.124.4" dstIP2 := "192.168.124.5" @@ -175,7 +175,7 @@ func (suite *OvnClientTestSuite) testListDownBFDs() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrpName := "test-list-down-bfd" dstIP1 := "192.168.124.6" dstIP2 := "192.168.124.7" @@ -501,7 +501,7 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient t.Run("BFD status change with wrong table", func(t *testing.T) { t.Parallel() diff --git a/pkg/ovs/ovn-nb-logical_router_port_test.go b/pkg/ovs/ovn-nb-logical_router_port_test.go index 66f1028b502..1e9f0f5a19b 100644 --- a/pkg/ovs/ovn-nb-logical_router_port_test.go +++ b/pkg/ovs/ovn-nb-logical_router_port_test.go @@ -30,7 +30,7 @@ func (suite *OvnClientTestSuite) testCreatePeerRouterPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient localLrName := "test-create-peer-lr-local" remoteLrName := "test-create-peer-lr-remote" localRouterPort := fmt.Sprintf("%s-%s", localLrName, remoteLrName) @@ -82,7 +82,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPortRA() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrpName := "test-update-ra-lrp" lrName := "test-update-ra-lr" @@ -225,7 +225,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test-create-lrp-lr" err := nbClient.CreateLogicalRouter(lrName) @@ -498,7 +498,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPortOp() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrpName := "test-create-op-lrp" lrName := "test-create-op-lr" @@ -795,7 +795,7 @@ func (suite *OvnClientTestSuite) testAddLogicalRouterPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test-add-lrp-lr" err := nbClient.CreateLogicalRouter(lrName) diff --git a/pkg/ovs/ovn-nb-logical_switch_port_test.go b/pkg/ovs/ovn-nb-logical_switch_port_test.go index 284f73f209a..a331266c5db 100644 --- a/pkg/ovs/ovn-nb-logical_switch_port_test.go +++ b/pkg/ovs/ovn-nb-logical_switch_port_test.go @@ -18,7 +18,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-create-lsp-ls" ips := "10.244.0.37,fc00::af4:25" mac := "00:00:00:AB:B4:65" @@ -308,7 +308,7 @@ func (suite *OvnClientTestSuite) testCreateVirtualLogicalSwitchPorts() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-create-virtual-port-ls" vips := []string{"192.168.33.10", "192.168.33.12"} @@ -354,7 +354,7 @@ func (suite *OvnClientTestSuite) testCreateVirtualLogicalSwitchPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lspName := "test-create-one-virtual-port-lsp" lsName := "test-create-one-virtual-port-ls" lsName2 := "test-create-one-virtual-port-ls2" @@ -439,7 +439,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortVirtualParents() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-update-port-virt-parents-ls" ips := []string{"192.168.211.31", "192.168.211.32"} @@ -497,7 +497,7 @@ func (suite *OvnClientTestSuite) testSetVirtualLogicalSwitchPortVirtualParents() t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-update-virtual-port-virt-parents-ls" ip := "192.168.211.31" @@ -565,7 +565,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortArpProxy() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-set-lsp-arp-proxy-ls" ips := "10.244.0.37,fc00::af4:25" mac := "00:00:00:AB:B4:65" @@ -1171,7 +1171,7 @@ func (suite *OvnClientTestSuite) testEnablePortLayer2forward() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-enable-port-l2-ls" lspName := "test-enable-port-l2-lsp" ns := "test-enable-port-l2-ns" @@ -1313,7 +1313,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-update-lsp-ls" lspName := "test-update-lsp-lsp" @@ -1392,7 +1392,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitchPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lspName := "test-delete-port-lsp" lsName := "test-delete-port-ls" @@ -1438,7 +1438,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitchPorts() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-delete-ports-ls" lspName1 := "test-delete-port-lsp1" @@ -1489,7 +1489,7 @@ func (suite *OvnClientTestSuite) testListNormalLogicalSwitchPorts() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "a-normal-ls" lspName := "a-lsp-listed" @@ -1584,7 +1584,7 @@ func (suite *OvnClientTestSuite) testListLogicalSwitchPorts() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-list-lsp-ls" err := nbClient.CreateBareLogicalSwitch(lsName) @@ -1762,7 +1762,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitchPortOp() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lspName := "test-del-op-lsp" lsName := "test-del-op-ls" diff --git a/pkg/ovs/ovn-nb-logical_switch_test.go b/pkg/ovs/ovn-nb-logical_switch_test.go index 26ccf0ac2d6..a129a137f1f 100644 --- a/pkg/ovs/ovn-nb-logical_switch_test.go +++ b/pkg/ovs/ovn-nb-logical_switch_test.go @@ -104,7 +104,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchAddPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient t.Run("add port to logical switch", func(t *testing.T) { lsName := "test-add-port-ls" @@ -162,7 +162,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchDelPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-del-port-ls" lspName := "test-del-port-lsp" @@ -306,7 +306,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitch() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient name := "test-delete-ls" t.Run("no err when delete existent logical switch", func(t *testing.T) { @@ -724,7 +724,7 @@ func (suite *OvnClientTestSuite) testCreateBareLogicalSwitch() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-create-bare-ls" diff --git a/pkg/ovs/ovn-nb-nat_test.go b/pkg/ovs/ovn-nb-nat_test.go index b52d047e2b3..dec5c6184cf 100644 --- a/pkg/ovs/ovn-nb-nat_test.go +++ b/pkg/ovs/ovn-nb-nat_test.go @@ -86,7 +86,7 @@ func (suite *OvnClientTestSuite) testCreateNats() { require.ErrorContains(t, err, "nats is empty") // failed client to create nats - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient err = failedNbClient.CreateNats(lrName, nats...) require.Error(t, err) } @@ -96,7 +96,7 @@ func (suite *OvnClientTestSuite) testUpdateSnat() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test-update-snat-lr" externalIP := "192.168.30.254" logicalIP := "10.250.0.4" @@ -155,7 +155,7 @@ func (suite *OvnClientTestSuite) testUpdateDnatAndSnat() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test-update-dnat-and-snat-lr" lspName := "test-update-dnat-and-snat-lrp" externalIP := "192.168.30.214" @@ -245,7 +245,7 @@ func (suite *OvnClientTestSuite) testUpdateNat() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test-update-nat-lr" externalIP := "192.168.30.254" @@ -321,7 +321,7 @@ func (suite *OvnClientTestSuite) testDeleteNat() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test-del-nat-lr" externalIP := "192.168.30.254" logicalIP := "10.250.0.4" @@ -400,7 +400,7 @@ func (suite *OvnClientTestSuite) testDeleteNats() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test-del-nats-lr" externalIPs := []string{"192.168.30.254", "192.168.30.253"} logicalIPs := []string{"10.250.0.4", "10.250.0.5"} @@ -547,7 +547,7 @@ func (suite *OvnClientTestSuite) testGetNat() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test_get_nat_lr" @@ -637,7 +637,7 @@ func (suite *OvnClientTestSuite) testNewNat() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lrName := "test-new-nat-lr" natType := "snat" diff --git a/pkg/ovs/ovn-nb-suite_test.go b/pkg/ovs/ovn-nb-suite_test.go index 514b9f5d743..e903b39a77b 100644 --- a/pkg/ovs/ovn-nb-suite_test.go +++ b/pkg/ovs/ovn-nb-suite_test.go @@ -30,8 +30,8 @@ type OvnClientTestSuite struct { ovnNBClient *OVNNbClient ovnSBClient *OVNSbClient - faiedOvnNBClient *OVNNbClient - ovnLegacyClient *LegacyClient + failedOvnNBClient *OVNNbClient + ovnLegacyClient *LegacyClient } func emptyNbDatabaseModel() (model.ClientDBModel, error) { @@ -50,9 +50,9 @@ func (suite *OvnClientTestSuite) SetupSuite() { fakeNBServer, nbSock1 := newOVSDBServer(suite.T(), "fake-nb", emptyNbDBModel, nbClientSchema) nbEndpoint1 := fmt.Sprintf("unix:%s", nbSock1) require.FileExists(suite.T(), nbSock1) - faiedOvnNBClient, err := newOvnNbClient(suite.T(), nbEndpoint1, 10) + failedOvnNBClient, err := newOvnNbClient(suite.T(), nbEndpoint1, 10) require.NoError(suite.T(), err) - suite.faiedOvnNBClient = faiedOvnNBClient + suite.failedOvnNBClient = failedOvnNBClient // close the server to simulate the failed case fakeNBServer.Close() require.NoFileExists(suite.T(), nbSock1) diff --git a/pkg/ovs/ovn-nb_global_test.go b/pkg/ovs/ovn-nb_global_test.go index f1009539d0a..1767588e3f4 100644 --- a/pkg/ovs/ovn-nb_global_test.go +++ b/pkg/ovs/ovn-nb_global_test.go @@ -22,7 +22,7 @@ func (suite *OvnClientTestSuite) testGetNbGlobal() { t := suite.T() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient t.Cleanup(func() { err := failedNbClient.DeleteNbGlobal() @@ -60,7 +60,7 @@ func (suite *OvnClientTestSuite) testUpdateNbGlobal() { t := suite.T() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient t.Cleanup(func() { err := nbClient.DeleteNbGlobal() diff --git a/pkg/ovs/ovn-nb_test.go b/pkg/ovs/ovn-nb_test.go index 9cf8110e667..94b6b05530e 100644 --- a/pkg/ovs/ovn-nb_test.go +++ b/pkg/ovs/ovn-nb_test.go @@ -15,7 +15,7 @@ func (suite *OvnClientTestSuite) testCreateGatewayLogicalSwitch() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-create-gw-ls" lrName := "test-create-gw-lr" lspName := fmt.Sprintf("%s-%s", lsName, lrName) @@ -58,7 +58,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalPatchPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-create-router-ls" lrName := "test-create-router-lr" @@ -148,7 +148,7 @@ func (suite *OvnClientTestSuite) testRemoveRouterPort() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-remove-router-type-ls" lrName := "test-remove-router-type-lr" @@ -189,7 +189,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalGatewaySwitch() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient lsName := "test-del-gw-ls" lrName := "test-del-gw-lr" @@ -224,7 +224,7 @@ func (suite *OvnClientTestSuite) testDeleteSecurityGroup() { t.Parallel() nbClient := suite.ovnNBClient - failedNbClient := suite.faiedOvnNBClient + failedNbClient := suite.failedOvnNBClient sgName := "test_del_sg" asName := "test_del_sg_as" pgName := GetSgPortGroupName(sgName)