From ad6c51dfeb82446e4ecd5751e247e24d904f46b0 Mon Sep 17 00:00:00 2001 From: zcq98 Date: Fri, 13 Sep 2024 10:22:45 +0800 Subject: [PATCH 01/10] add ovnSBClient for suite Signed-off-by: zcq98 --- pkg/ovs/ovn-nb-acl_test.go | 44 ++++++------ pkg/ovs/ovn-nb-address_set_test.go | 12 ++-- pkg/ovs/ovn-nb-bfd_test.go | 18 ++--- pkg/ovs/ovn-nb-dhcp_options_test.go | 14 ++-- pkg/ovs/ovn-nb-gateway_chassis_test.go | 6 +- .../ovn-nb-load_balancer_health_check_test.go | 14 ++-- pkg/ovs/ovn-nb-load_balancer_test.go | 26 +++---- pkg/ovs/ovn-nb-logical_router_policy_test.go | 14 ++-- pkg/ovs/ovn-nb-logical_router_port_test.go | 20 +++--- pkg/ovs/ovn-nb-logical_router_route_test.go | 14 ++-- pkg/ovs/ovn-nb-logical_router_test.go | 22 +++--- pkg/ovs/ovn-nb-logical_switch_port_test.go | 34 ++++----- pkg/ovs/ovn-nb-logical_switch_test.go | 22 +++--- pkg/ovs/ovn-nb-nat_test.go | 14 ++-- pkg/ovs/ovn-nb-port_group_test.go | 24 +++---- pkg/ovs/ovn-nb-suite_test.go | 71 ++++++++++++++++++- pkg/ovs/ovn-nb_global_test.go | 12 ++-- pkg/ovs/ovn-nb_test.go | 12 ++-- 18 files changed, 229 insertions(+), 164 deletions(-) diff --git a/pkg/ovs/ovn-nb-acl_test.go b/pkg/ovs/ovn-nb-acl_test.go index cdd98ea061c..1b431c4eece 100644 --- a/pkg/ovs/ovn-nb-acl_test.go +++ b/pkg/ovs/ovn-nb-acl_test.go @@ -68,7 +68,7 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient expect := func(row ovsdb.Row, action, direction, match, priority string) { intPriority, err := strconv.Atoi(priority) @@ -140,7 +140,7 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient expect := func(row ovsdb.Row, action, direction, match, priority string) { intPriority, err := strconv.Atoi(priority) @@ -212,7 +212,7 @@ func (suite *OvnClientTestSuite) testCreateGatewayACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient checkACL := func(parent interface{}, direction, priority, match string, options map[string]string) { pg, isPg := parent.(*ovnnb.PortGroup) @@ -359,7 +359,7 @@ func (suite *OvnClientTestSuite) testCreateNodeACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient checkACL := func(pg *ovnnb.PortGroup, direction, priority, match string, options map[string]string) { acl, err := ovnClient.GetACL(pg.Name, direction, priority, match, false) @@ -434,7 +434,7 @@ func (suite *OvnClientTestSuite) testCreateSgDenyAllACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient sgName := "test_create_deny_all_acl_pg" pgName := GetSgPortGroupName(sgName) @@ -470,7 +470,7 @@ func (suite *OvnClientTestSuite) testCreateSgBaseACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient expect := func(pg *ovnnb.PortGroup, match, direction string) { arpACL, err := ovnClient.GetACL(pg.Name, direction, util.SecurityGroupBasePriority, match, false) @@ -567,7 +567,7 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient sgName := "test_update_sg_acl_pg" v4AsName := GetSgV4AssociatedName(sgName) v6AsName := GetSgV6AssociatedName(sgName) @@ -680,7 +680,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test_update_acl_ls" cidrBlock := "192.168.2.0/24,2409:8720:4a00::0/64" @@ -746,7 +746,7 @@ func (suite *OvnClientTestSuite) testSetACLLog() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := GetSgPortGroupName("test_set_acl_log") err := ovnClient.CreatePortGroup(pgName, nil) @@ -795,7 +795,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient nodeSwitchCidrBlock := "100.64.0.0/16,fd00:100:64::/112" cidrBlock := "10.244.0.0/16,fc00::af4:0/112" @@ -953,7 +953,7 @@ func (suite *OvnClientTestSuite) testNewSgRuleACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient sgName := "test_create_sg_acl_pg" pgName := GetSgPortGroupName(sgName) highestPriority, _ := strconv.Atoi(util.SecurityGroupHighestPriority) @@ -1097,7 +1097,7 @@ func (suite *OvnClientTestSuite) testCreateAcls() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-create-acls-pg" priority := "5000" basePort := 12300 @@ -1172,7 +1172,7 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-del-acls-pg" lsName := "test-del-acls-ls" matchPrefix := "outport == @ovn.sg.test_del_acl_pg && ip" @@ -1387,7 +1387,7 @@ func (suite *OvnClientTestSuite) testDeleteACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-del-acl-pg" lsName := "test-del-acl-ls" matchPrefix := "outport == @ovn.sg.test_del_acl_pg && ip" @@ -1449,7 +1449,7 @@ func (suite *OvnClientTestSuite) testGetACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test_get_acl_pg" priority := "2000" match := "ip4.dst == 100.64.0.0/16" @@ -1505,7 +1505,7 @@ func (suite *OvnClientTestSuite) testListAcls() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-list-acl-pg" basePort := 50000 @@ -1549,7 +1549,7 @@ func (suite *OvnClientTestSuite) testNewACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-new-acl-pg" priority := "1000" match := "outport==@ovn.sg.test_create_acl_pg && ip" @@ -1815,7 +1815,7 @@ func (suite *OvnClientTestSuite) testSgRuleNoACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient sgName := "test-sg" pgName := GetSgPortGroupName(sgName) @@ -1894,7 +1894,7 @@ func (suite *OvnClientTestSuite) testSGLostACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("no lost ACLs", func(t *testing.T) { t.Parallel() @@ -2171,7 +2171,7 @@ func (suite *OvnClientTestSuite) testCreateBareACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("create bare ACL successfully", func(t *testing.T) { err := ovnClient.CreateBareACL("test-parent", "from-lport", "1000", "ip4.src == 10.0.0.1", "allow") @@ -2189,7 +2189,7 @@ func (suite *OvnClientTestSuite) testUpdateAnpRuleACLOps() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient expect := func(row ovsdb.Row, action, direction, match, priority string) { intPriority, err := strconv.Atoi(priority) @@ -2244,7 +2244,7 @@ func (suite *OvnClientTestSuite) testUpdateAnpRuleACLOps() { func (suite *OvnClientTestSuite) testUpdateACL() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("update ACL with nil input", func(t *testing.T) { err := ovnClient.UpdateACL(nil) diff --git a/pkg/ovs/ovn-nb-address_set_test.go b/pkg/ovs/ovn-nb-address_set_test.go index 5bd6af7b7dd..3c28ab000b8 100644 --- a/pkg/ovs/ovn-nb-address_set_test.go +++ b/pkg/ovs/ovn-nb-address_set_test.go @@ -20,7 +20,7 @@ func (suite *OvnClientTestSuite) testCreateAddressSet() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient asName := "test_create_as" t.Run("create address set", func(t *testing.T) { @@ -71,7 +71,7 @@ func (suite *OvnClientTestSuite) testAddressSetUpdateAddress() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient asName := "test_update_address_as" addresses := []string{"1.2.3.4", "1.2.3.6", "1.2.3.7"} @@ -169,7 +169,7 @@ func (suite *OvnClientTestSuite) testDeleteAddressSet() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient asName := "test_delete_as" t.Run("no err when delete existent address set", func(t *testing.T) { @@ -196,7 +196,7 @@ func (suite *OvnClientTestSuite) testDeleteAddressSets() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-del-ass-pg" asPrefix := "test_del_ass" externalIDs := map[string]string{sgKey: pgName} @@ -233,7 +233,7 @@ func (suite *OvnClientTestSuite) testListAddressSets() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient asName := "test_list_as_exist_key" @@ -325,7 +325,7 @@ func (suite *OvnClientTestSuite) testUpdateAddressSet() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("update with nil address set", func(t *testing.T) { err := ovnClient.UpdateAddressSet(nil) diff --git a/pkg/ovs/ovn-nb-bfd_test.go b/pkg/ovs/ovn-nb-bfd_test.go index fd9df258cc6..f9088a3487f 100644 --- a/pkg/ovs/ovn-nb-bfd_test.go +++ b/pkg/ovs/ovn-nb-bfd_test.go @@ -13,7 +13,7 @@ func (suite *OvnClientTestSuite) testCreateBFD() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient dstIP := "192.168.124.1" minRx, minTx, detectMult := 101, 102, 19 @@ -59,7 +59,7 @@ func (suite *OvnClientTestSuite) testListBFD() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-list-bfd" dstIP1 := "192.168.124.2" dstIP2 := "192.168.124.3" @@ -102,7 +102,7 @@ func (suite *OvnClientTestSuite) testDeleteBFD() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-del-bfd" dstIP1 := "192.168.124.4" dstIP2 := "192.168.124.5" @@ -150,7 +150,7 @@ func (suite *OvnClientTestSuite) testListDownBFDs() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-list-down-bfd" dstIP1 := "192.168.124.6" dstIP2 := "192.168.124.7" @@ -232,7 +232,7 @@ func (suite *OvnClientTestSuite) testListUpBFDs() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-list-up-bfd" dstIP1 := "192.168.124.11" dstIP2 := "192.168.124.12" @@ -296,7 +296,7 @@ func (suite *OvnClientTestSuite) testIsLrpBfdUp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient dstIP := "192.168.124.15" minRx, minTx, detectMult := 101, 102, 19 @@ -370,7 +370,7 @@ func (suite *OvnClientTestSuite) testBfdAddL3HAHandler() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("BFD status is nil", func(t *testing.T) { t.Parallel() @@ -465,7 +465,7 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("BFD status change with wrong table", func(t *testing.T) { t.Parallel() @@ -610,7 +610,7 @@ func (suite *OvnClientTestSuite) testBfdDelL3HAHandler() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("BFD deletion with wrong table", func(t *testing.T) { t.Parallel() diff --git a/pkg/ovs/ovn-nb-dhcp_options_test.go b/pkg/ovs/ovn-nb-dhcp_options_test.go index 87b100cff40..5a08ca59263 100644 --- a/pkg/ovs/ovn-nb-dhcp_options_test.go +++ b/pkg/ovs/ovn-nb-dhcp_options_test.go @@ -30,7 +30,7 @@ func (suite *OvnClientTestSuite) testUpdateDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-dhcp-opt-ls" subnet := mockSubnet(lsName, true) @@ -118,7 +118,7 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv4Options() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-v4-dhcp-opt-ls" cidr := "192.168.30.0/24" gateway := "192.168.30.1" @@ -221,7 +221,7 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv6Options() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-v6-dhcp-opt-ls" cidr := "fd00::c0a8:6e01/120" var serverID string @@ -308,7 +308,7 @@ func (suite *OvnClientTestSuite) testDeleteDHCPOptionsByUUIDs() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-del-dhcp-opt-uuid-ls" v4CidrBlock := []string{"192.168.30.0/24", "192.168.40.0/24", "192.168.50.0/24"} uuidList := make([]string, 0) @@ -338,7 +338,7 @@ func (suite *OvnClientTestSuite) testDeleteDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-del-dhcp-opt-ls" v4CidrBlock := []string{"192.168.30.0/24", "192.168.40.0/24", "192.168.50.0/24"} v6CidrBlock := []string{"fd00::c0a8:6401/120", "fd00::c0a8:6e01/120"} @@ -397,7 +397,7 @@ func (suite *OvnClientTestSuite) testGetDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-get-dhcp-opt-ls" t.Run("ipv4 dhcp options", func(t *testing.T) { @@ -471,7 +471,7 @@ func (suite *OvnClientTestSuite) testListDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-list-dhcp-opt-ls" v4CidrBlock := []string{"192.168.30.0/24", "192.168.40.0/24", "192.168.50.0/24"} diff --git a/pkg/ovs/ovn-nb-gateway_chassis_test.go b/pkg/ovs/ovn-nb-gateway_chassis_test.go index 42d48f213b7..2f8c234e7f3 100644 --- a/pkg/ovs/ovn-nb-gateway_chassis_test.go +++ b/pkg/ovs/ovn-nb-gateway_chassis_test.go @@ -11,7 +11,7 @@ func (suite *OvnClientTestSuite) testCreateGatewayChassises() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-create-gateway-chassises-lr" lrpName := "test-create-gateway-chassises-lrp" chassises := []string{"c7efec70-9519-4b03-8b67-057f2a95e5c7", "4a0891b6-fe81-4986-a367-aad0ea7ca9f3", "dcc2eda3-b3ea-4d53-afe0-7b6eaf7917ba"} @@ -46,7 +46,7 @@ func (suite *OvnClientTestSuite) testDeleteGatewayChassises() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-gateway-chassis-del-lr" lrpName := "test-gateway-chassis-del-lrp" chassises := []string{"ea8368a0-28cd-4549-9da5-a7ea67262619", "b25ffb94-8b32-4c7e-b5b0-0f343bf6bdd8", "62265268-8af7-4b36-a550-ab5ad38375e3"} @@ -79,7 +79,7 @@ func (suite *OvnClientTestSuite) testDeleteGatewayChassisOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-gateway-chassis-del-op-lr" lrpName := "test-gateway-chassis-del-op-lrp" chassis := "6c322ce8-02b7-42b3-925b-ae24020272a9" diff --git a/pkg/ovs/ovn-nb-load_balancer_health_check_test.go b/pkg/ovs/ovn-nb-load_balancer_health_check_test.go index d8e2dbe4e72..dad1a9b82e4 100644 --- a/pkg/ovs/ovn-nb-load_balancer_health_check_test.go +++ b/pkg/ovs/ovn-nb-load_balancer_health_check_test.go @@ -17,7 +17,7 @@ func (suite *OvnClientTestSuite) testAddLoadBalancerHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-create-lb-hc" vip = "1.1.1.1:80" lbhc, lbhcRepeat *ovnnb.LoadBalancerHealthCheck @@ -52,7 +52,7 @@ func (suite *OvnClientTestSuite) testUpdateLoadBalancerHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-update-lb-hc" vip = "2.2.2.2:80" lbhc *ovnnb.LoadBalancerHealthCheck @@ -89,7 +89,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-del-lb-hc" vip = "1.1.1.11:80" err error @@ -113,7 +113,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthChecks() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbNamePrefix = "test-del-lb-hcs" vipFormat = "5.5.5.%d:80" lbhc *ovnnb.LoadBalancerHealthCheck @@ -164,7 +164,7 @@ func (suite *OvnClientTestSuite) testGetLoadBalancerHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-get-lb-hc" vip = "1.1.1.22:80" vipNonExistent = "1.1.1.33:80" @@ -209,7 +209,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancerHealthChecks() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbNamePrefix = "test-list-lb-hcs" vipFormat = "6.6.6.%d:80" vips []string @@ -283,7 +283,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthCheckOp() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-del-lb-hc-op" vip = "1.1.1.44:80" vipNonExistent = "1.1.1.55:80" diff --git a/pkg/ovs/ovn-nb-load_balancer_test.go b/pkg/ovs/ovn-nb-load_balancer_test.go index 896c09ed2fe..861b141127c 100644 --- a/pkg/ovs/ovn-nb-load_balancer_test.go +++ b/pkg/ovs/ovn-nb-load_balancer_test.go @@ -18,7 +18,7 @@ func (suite *OvnClientTestSuite) testCreateLoadBalancer() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lbName := "test-create-lb" err := ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") @@ -40,7 +40,7 @@ func (suite *OvnClientTestSuite) testUpdateLoadBalancer() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lbName := "test-update-lb" err := ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") @@ -86,7 +86,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancers() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lbNamePrefix := "test-del-lbs" lbNames := make([]string, 0, 5) @@ -113,7 +113,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancer() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lbName := "test-del-lb" err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") @@ -130,7 +130,7 @@ func (suite *OvnClientTestSuite) testGetLoadBalancer() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lbName := "test-get-lb" err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") @@ -161,7 +161,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancers() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lbNamePrefix := "test-list-lbs" lbNames := make([]string, 0, 3) protocol := []string{"tcp", "udp"} @@ -244,7 +244,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lbName := "test-del-lb-op" err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") @@ -289,7 +289,7 @@ func (suite *OvnClientTestSuite) testSetLoadBalancerAffinityTimeout() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lbName := "test-set-lb-affinity-timeout" err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") @@ -331,7 +331,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerAddVip() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-lb-add-vip" vips, expectedVips map[string]string lb *ovnnb.LoadBalancer @@ -394,7 +394,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteVip() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-lb-del-vip" vips map[string]string deletedVips []string @@ -441,7 +441,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerAddIPPortMapping() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-lb-add-ip-port-mapping" vips, mappings map[string]string lb *ovnnb.LoadBalancer @@ -539,7 +539,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteIPPortMapping() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-lb-del-ip-port-mapping" vips, mappings map[string]string lb *ovnnb.LoadBalancer @@ -658,7 +658,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnClient + ovnClient = suite.ovnNBClient lbName = "test-lb-with-health-check" vips, mappings map[string]string lb *ovnnb.LoadBalancer diff --git a/pkg/ovs/ovn-nb-logical_router_policy_test.go b/pkg/ovs/ovn-nb-logical_router_policy_test.go index d3ea5585040..261dea5c580 100644 --- a/pkg/ovs/ovn-nb-logical_router_policy_test.go +++ b/pkg/ovs/ovn-nb-logical_router_policy_test.go @@ -26,7 +26,7 @@ func (suite *OvnClientTestSuite) testAddLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-add-policy-lr" priority := 11011 match := "ip4.src == $ovn.default.lm2_ip4" @@ -55,7 +55,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPolicies() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-create-policies-lr" priority := 11011 basePort := 12300 @@ -94,7 +94,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-del-policy-lr" priority := 11012 match := "ip4.src == $ovn.default.lm2_ip4" @@ -132,7 +132,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPolicies() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-clear-policies-lr" basePriority := 12100 match := "ip4.src == $ovn.default.lm2_ip4" @@ -200,7 +200,7 @@ func (suite *OvnClientTestSuite) testClearLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-clear-policy-lr" basePriority := 11012 match := "ip4.src == $ovn.default.lm2_ip4" @@ -244,7 +244,7 @@ func (suite *OvnClientTestSuite) testGetLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test_get_policy_lr" priority := 11000 match := "ip4.src == $ovn.default.lm2_ip4" @@ -294,7 +294,7 @@ func (suite *OvnClientTestSuite) testNewLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-new-policy-lr" priority := 10000 match := "ip4.src == $ovn.default.lm2_ip4" diff --git a/pkg/ovs/ovn-nb-logical_router_port_test.go b/pkg/ovs/ovn-nb-logical_router_port_test.go index 2cc6ebd8aee..5b7f9328daf 100644 --- a/pkg/ovs/ovn-nb-logical_router_port_test.go +++ b/pkg/ovs/ovn-nb-logical_router_port_test.go @@ -29,7 +29,7 @@ func (suite *OvnClientTestSuite) testCreatePeerRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient localLrName := "test-create-peer-lr-local" remoteLrName := "test-create-peer-lr-remote" localRouterPort := fmt.Sprintf("%s-%s", localLrName, remoteLrName) @@ -70,7 +70,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPortRA() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-update-ra-lrp" lrName := "test-update-ra-lr" @@ -137,7 +137,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPortOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-update-lrp-opt" lrName := "test-update-lrp-opt-lr" options := map[string]string{ @@ -192,7 +192,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-create-lrp-lr" err := ovnClient.CreateLogicalRouter(lrName) @@ -259,7 +259,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-update-lrp" lrName := "test-update-lrp-lr" @@ -300,7 +300,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient prefix := "test-del-ports-lrp" lrName := "test-del-ports-lr" @@ -338,7 +338,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-delete-port-lrp" lrName := "test-delete-port-lr" @@ -374,7 +374,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-create-op-lrp" lrName := "test-create-op-lr" @@ -455,7 +455,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrpName := "test-del-op-lrp" lrName := "test-del-op-lr" @@ -492,7 +492,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-op-lrp-lr" lrpName := "test-op-lrp-lrp" diff --git a/pkg/ovs/ovn-nb-logical_router_route_test.go b/pkg/ovs/ovn-nb-logical_router_route_test.go index 4138bdc3ecd..f479642e732 100644 --- a/pkg/ovs/ovn-nb-logical_router_route_test.go +++ b/pkg/ovs/ovn-nb-logical_router_route_test.go @@ -14,7 +14,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterStaticRoutes() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-create-routes-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP @@ -50,7 +50,7 @@ func (suite *OvnClientTestSuite) testAddLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-add-route-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP @@ -136,7 +136,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-del-route-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP @@ -216,7 +216,7 @@ func (suite *OvnClientTestSuite) testClearLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-clear-route-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP @@ -258,7 +258,7 @@ func (suite *OvnClientTestSuite) testGetLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test_get_route_lr" routeTable := util.MainRouteTable @@ -320,7 +320,7 @@ func (suite *OvnClientTestSuite) testListLogicalRouterStaticRoutes() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-list-routes-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP @@ -352,7 +352,7 @@ func (suite *OvnClientTestSuite) testNewLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-new-route-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP diff --git a/pkg/ovs/ovn-nb-logical_router_test.go b/pkg/ovs/ovn-nb-logical_router_test.go index d4a01e075bf..bab6c76dd03 100644 --- a/pkg/ovs/ovn-nb-logical_router_test.go +++ b/pkg/ovs/ovn-nb-logical_router_test.go @@ -28,7 +28,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient name := "test-create-lr" err := ovnClient.CreateLogicalRouter(name) @@ -45,7 +45,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-update-lr" err := ovnClient.CreateLogicalRouter(lrName) @@ -80,7 +80,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient name := "test-delete-lr" t.Run("no err when delete existent logical router", func(t *testing.T) { @@ -106,7 +106,7 @@ func (suite *OvnClientTestSuite) testGetLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient name := "test-get-lr" err := ovnClient.CreateLogicalRouter(name) @@ -137,7 +137,7 @@ func (suite *OvnClientTestSuite) testListLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient namePrefix := "test-list-lr" i := 0 @@ -207,7 +207,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateLoadBalancers() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-add-lb-to-lr" prefix := "test-add-lr-lb" lbNames := make([]string, 0, 3) @@ -273,7 +273,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdatePortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-update-port-op-lr" uuid := ovsclient.NamedUUID() @@ -329,7 +329,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdatePolicyOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-update-policy-op-lr" uuid := ovsclient.NamedUUID() @@ -385,7 +385,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateNatOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-update-nat-op-lr" uuid := ovsclient.NamedUUID() @@ -441,7 +441,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateStaticRouteOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-update-route-op-lr" uuid := ovsclient.NamedUUID() @@ -497,7 +497,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-op-lr" err := ovnClient.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 9016bbdb677..d1e49738940 100644 --- a/pkg/ovs/ovn-nb-logical_switch_port_test.go +++ b/pkg/ovs/ovn-nb-logical_switch_port_test.go @@ -17,7 +17,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-create-lsp-ls" ips := "10.244.0.37,fc00::af4:25" mac := "00:00:00:AB:B4:65" @@ -204,7 +204,7 @@ func (suite *OvnClientTestSuite) testCreateLocalnetLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lspName := "test-create-localnet-port-lsp" lsName := "test-create-localnet-port-ls" provider := "external" @@ -258,7 +258,7 @@ func (suite *OvnClientTestSuite) testCreateVirtualLogicalSwitchPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-create-virtual-port-ls" vips := []string{"192.168.33.10", "192.168.33.12"} @@ -290,7 +290,7 @@ func (suite *OvnClientTestSuite) testCreateBareLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-create-bare-port-ls" lspName := "test-create-bare-port-lsp" @@ -314,7 +314,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortVirtualParents() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-port-virt-parents-ls" ips := []string{"192.168.211.31", "192.168.211.32"} @@ -351,7 +351,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortArpProxy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-set-lsp-arp-proxy-ls" ips := "10.244.0.37,fc00::af4:25" mac := "00:00:00:AB:B4:65" @@ -389,7 +389,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurity() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-port-security-ls" lspName := "test-update-port-security-lsp" @@ -454,7 +454,7 @@ func (suite *OvnClientTestSuite) testSetSetLogicalSwitchPortExternalIDs() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-set-lsp-ext-id-ls" lspName := "test-set-lsp-ext-id-lsp" @@ -495,7 +495,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-set-sg-ls" lspNamePrefix := "test-set-sg-lsp" @@ -814,7 +814,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortsSecurityGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-set-sgs-ls" lspNamePrefix := "test-set-sgs-lsp" @@ -880,7 +880,7 @@ func (suite *OvnClientTestSuite) testEnablePortLayer2forward() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-enable-port-l2-ls" lspName := "test-enable-port-l2-lsp" ns := "test-enable-port-l2-ns" @@ -913,7 +913,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortVlanTag() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-set-port-vlan-tag-ls" lspName := "test-set-port-vlan-tag-lsp" vlanID := 100 @@ -979,7 +979,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-lsp-ls" lspName := "test-update-lsp-lsp" @@ -1033,7 +1033,7 @@ func (suite *OvnClientTestSuite) testListLogicalSwitchPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-list-lsp-ls" err := ovnClient.CreateBareLogicalSwitch(lsName) @@ -1098,7 +1098,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lspName := "test-delete-port-lsp" lsName := "test-delete-port-ls" @@ -1134,7 +1134,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lspName := "test-create-op-lsp" lsName := "test-create-op-ls" @@ -1216,7 +1216,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitchPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient 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 a2320a766a4..114f7477743 100644 --- a/pkg/ovs/ovn-nb-logical_switch_test.go +++ b/pkg/ovs/ovn-nb-logical_switch_test.go @@ -28,7 +28,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-create-ls-ls" lrName := "test-create-ls-lr" mac := util.GenerateMac() @@ -101,7 +101,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchAddPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-add-port-ls" lspName := "test-add-port-lsp" @@ -137,7 +137,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchDelPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-del-port-ls" lspName := "test-del-port-lsp" @@ -180,7 +180,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateLoadBalancers() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-add-lb-to-ls" prefix := "test-add-lb" lbNames := make([]string, 0, 3) @@ -257,7 +257,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient name := "test-delete-ls" t.Run("no err when delete existent logical switch", func(t *testing.T) { @@ -283,7 +283,7 @@ func (suite *OvnClientTestSuite) testGetLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient name := "test-get-ls" err := ovnClient.CreateBareLogicalSwitch(name) @@ -311,7 +311,7 @@ func (suite *OvnClientTestSuite) testListLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient namePrefix := "test-list-ls-" i := 0 @@ -382,7 +382,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdatePortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-port-op-ls" lspName := "test-update-port-op-lsp" lspUUID := ovsclient.NamedUUID() @@ -467,7 +467,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateLoadBalancerOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-lb-ls" lbUUIDs := []string{ovsclient.NamedUUID(), ovsclient.NamedUUID(), ovsclient.NamedUUID()} @@ -535,7 +535,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateACLOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-acl-op-ls" aclUUIDs := []string{ovsclient.NamedUUID(), ovsclient.NamedUUID()} @@ -600,7 +600,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-op-ls" err := ovnClient.CreateBareLogicalSwitch(lsName) diff --git a/pkg/ovs/ovn-nb-nat_test.go b/pkg/ovs/ovn-nb-nat_test.go index 17f15b45d2d..c3e09e8fc9f 100644 --- a/pkg/ovs/ovn-nb-nat_test.go +++ b/pkg/ovs/ovn-nb-nat_test.go @@ -29,7 +29,7 @@ func (suite *OvnClientTestSuite) testCreateNats() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-create-nats-lr" externalIPs := []string{"192.168.30.254", "192.168.30.253"} logicalIPs := []string{"10.250.0.4", "10.250.0.5"} @@ -81,7 +81,7 @@ func (suite *OvnClientTestSuite) testUpdateSnat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-update-snat-lr" externalIP := "192.168.30.254" logicalIP := "10.250.0.4" @@ -118,7 +118,7 @@ func (suite *OvnClientTestSuite) testUpdateDnatAndSnat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-update-dnat-and-snat-lr" lspName := "test-update-dnat-and-snat-lrp" externalIP := "192.168.30.254" @@ -189,7 +189,7 @@ func (suite *OvnClientTestSuite) testDeleteNat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-del-nat-lr" externalIP := "192.168.30.254" logicalIP := "10.250.0.4" @@ -244,7 +244,7 @@ func (suite *OvnClientTestSuite) testDeleteNats() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient 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"} @@ -375,7 +375,7 @@ func (suite *OvnClientTestSuite) testGetNat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test_get_nat_lr" err := ovnClient.CreateLogicalRouter(lrName) @@ -431,7 +431,7 @@ func (suite *OvnClientTestSuite) testNewNat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lrName := "test-new-nat-lr" natType := "snat" externalIP := "192.168.30.254" diff --git a/pkg/ovs/ovn-nb-port_group_test.go b/pkg/ovs/ovn-nb-port_group_test.go index af74789a077..0d3edc9ecbd 100644 --- a/pkg/ovs/ovn-nb-port_group_test.go +++ b/pkg/ovs/ovn-nb-port_group_test.go @@ -17,7 +17,7 @@ func (suite *OvnClientTestSuite) testCreatePortGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("create new port group", func(t *testing.T) { pgName := "test-create-new-pg" @@ -81,7 +81,7 @@ func (suite *OvnClientTestSuite) testPortGroupResetPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-reset-pg-ports-ls" pgName := "test-reset-pg-ports-pg" prefix := "test-reset-pg-ports-lsp" @@ -124,7 +124,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-add-ports-to-pg" lsName := "test-add-ports-to-ls" prefix := "test-add-lsp" @@ -197,7 +197,7 @@ func (suite *OvnClientTestSuite) testDeletePortGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-delete-pg" t.Run("no err when delete existent port group", func(t *testing.T) { @@ -223,7 +223,7 @@ func (suite *OvnClientTestSuite) testGetGetPortGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-get-pg" err := ovnClient.CreatePortGroup(pgName, map[string]string{ @@ -257,7 +257,7 @@ func (suite *OvnClientTestSuite) testListPortGroups() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("result should exclude pg when externalIDs's length is not equal", func(t *testing.T) { pgName := "test-list-pg-mismatch-length" @@ -339,7 +339,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-update-port-op-pg" lspUUIDs := []string{ovsclient.NamedUUID(), ovsclient.NamedUUID()} @@ -407,7 +407,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdateACLOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-update-acl-op-pg" aclUUIDs := []string{ovsclient.NamedUUID(), ovsclient.NamedUUID()} @@ -475,7 +475,7 @@ func (suite *OvnClientTestSuite) testPortGroupOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-port-op-pg" err := ovnClient.CreatePortGroup(pgName, map[string]string{ @@ -540,7 +540,7 @@ func (suite *OvnClientTestSuite) testPortGroupRemovePorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-remove-ports-pg" lsName := "test-remove-ports-ls" prefix := "test-remove-lsp" @@ -623,7 +623,7 @@ func (suite *OvnClientTestSuite) testUpdatePortGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Run("update external_ids", func(t *testing.T) { pgName := "test-update-external" @@ -758,7 +758,7 @@ func (suite *OvnClientTestSuite) testPortGroupSetPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient pgName := "test-set-ports-pg" lsName := "test-set-ports-ls" prefix := "test-set-lsp" diff --git a/pkg/ovs/ovn-nb-suite_test.go b/pkg/ovs/ovn-nb-suite_test.go index 48f2b414db5..37ba49a1cd3 100644 --- a/pkg/ovs/ovn-nb-suite_test.go +++ b/pkg/ovs/ovn-nb-suite_test.go @@ -22,11 +22,13 @@ import ( "github.com/stretchr/testify/suite" "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" + "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnsb" ) type OvnClientTestSuite struct { suite.Suite - ovnClient *OVNNbClient + ovnNBClient *OVNNbClient + ovnSBClient *OVNSbClient } func (suite *OvnClientTestSuite) SetupSuite() { @@ -39,10 +41,21 @@ func (suite *OvnClientTestSuite) SetupSuite() { endpoint := fmt.Sprintf("unix:%s", sock) require.FileExists(suite.T(), sock) - ovnClient, err := newOvnNbClient(suite.T(), endpoint, 10) + ovnNBClient, err := newOvnNbClient(suite.T(), endpoint, 10) require.NoError(suite.T(), err) + suite.ovnNBClient = ovnNBClient - suite.ovnClient = ovnClient + clientSchema = ovnsb.Schema() + clientDBModel, err = ovnsb.FullDatabaseModel() + require.NoError(suite.T(), err) + + _, sock = newOVSDBServer(suite.T(), clientDBModel, clientSchema) + endpoint = fmt.Sprintf("unix:%s", sock) + require.FileExists(suite.T(), sock) + + ovnSBClient, err := newOvnSbClient(suite.T(), endpoint, 10) + require.NoError(suite.T(), err) + suite.ovnSBClient = ovnSBClient } // In order for 'go test' to run this suite, we need to create @@ -904,3 +917,55 @@ func newNbClient(addr string, timeout int) (client.Client, error) { return c, nil } + +func newOvnSbClient(t *testing.T, ovnSbAddr string, ovnSbTimeout int) (*OVNSbClient, error) { + nbClient, err := newSbClient(ovnSbAddr, ovnSbTimeout) + require.NoError(t, err) + + return &OVNSbClient{ + ovsDbClient: ovsDbClient{ + Client: nbClient, + Timeout: time.Duration(ovnSbTimeout) * time.Second, + }, + }, nil +} + +func newSbClient(addr string, timeout int) (client.Client, error) { + dbModel, err := ovnsb.FullDatabaseModel() + if err != nil { + return nil, err + } + + logger := stdr.New(log.New(os.Stderr, "", log.LstdFlags)). + WithName("libovsdb"). + WithValues("database", dbModel.Name()) + stdr.SetVerbosity(1) + + options := []client.Option{ + client.WithReconnect(time.Duration(timeout)*time.Second, &backoff.ZeroBackOff{}), + client.WithLeaderOnly(false), + client.WithLogger(&logger), + } + + for _, ep := range strings.Split(addr, ",") { + options = append(options, client.WithEndpoint(ep)) + } + + c, err := client.NewOVSDBClient(dbModel, options...) + if err != nil { + return nil, err + } + + if err = c.Connect(context.TODO()); err != nil { + return nil, err + } + + monitorOpts := []client.MonitorOption{ + client.WithTable(&ovnsb.Chassis{}), + } + if _, err = c.Monitor(context.TODO(), c.NewMonitor(monitorOpts...)); err != nil { + return nil, err + } + + return c, nil +} diff --git a/pkg/ovs/ovn-nb_global_test.go b/pkg/ovs/ovn-nb_global_test.go index 4f1abd3b8ac..2e45f460792 100644 --- a/pkg/ovs/ovn-nb_global_test.go +++ b/pkg/ovs/ovn-nb_global_test.go @@ -21,7 +21,7 @@ func mockNBGlobal() *ovnnb.NBGlobal { func (suite *OvnClientTestSuite) testGetNbGlobal() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -50,7 +50,7 @@ func (suite *OvnClientTestSuite) testGetNbGlobal() { func (suite *OvnClientTestSuite) testUpdateNbGlobal() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -97,7 +97,7 @@ func (suite *OvnClientTestSuite) testUpdateNbGlobal() { func (suite *OvnClientTestSuite) testSetAzName() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -162,7 +162,7 @@ func (suite *OvnClientTestSuite) testSetAzName() { func (suite *OvnClientTestSuite) testSetICAutoRoute() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -264,7 +264,7 @@ func (suite *OvnClientTestSuite) testSetICAutoRoute() { func (suite *OvnClientTestSuite) testSetUseCtInvMatch() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -289,7 +289,7 @@ func (suite *OvnClientTestSuite) testSetUseCtInvMatch() { func (suite *OvnClientTestSuite) testSetLBCIDR() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient serviceCIDR := "10.96.0.0/12" t.Cleanup(func() { diff --git a/pkg/ovs/ovn-nb_test.go b/pkg/ovs/ovn-nb_test.go index 3426afb1654..e42048e1583 100644 --- a/pkg/ovs/ovn-nb_test.go +++ b/pkg/ovs/ovn-nb_test.go @@ -14,7 +14,7 @@ func (suite *OvnClientTestSuite) testCreateGatewayLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-create-gw-ls" lrName := "test-create-gw-lr" lspName := fmt.Sprintf("%s-%s", lsName, lrName) @@ -51,7 +51,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalPatchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-create-router-ls" lrName := "test-create-router-lr" lspName := fmt.Sprintf("%s-%s", lsName, lrName) @@ -107,7 +107,7 @@ func (suite *OvnClientTestSuite) testRemoveRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-remove-router-type-ls" lrName := "test-remove-router-type-lr" lspName := fmt.Sprintf("%s-%s", lsName, lrName) @@ -137,7 +137,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalGatewaySwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-del-gw-ls" lrName := "test-del-gw-lr" @@ -161,7 +161,7 @@ func (suite *OvnClientTestSuite) testDeleteSecurityGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient sgName := "test_del_sg" asName := "test_del_sg_as" pgName := GetSgPortGroupName(sgName) @@ -201,7 +201,7 @@ func (suite *OvnClientTestSuite) testGetEntityInfo() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-get-entity-ls" err := ovnClient.CreateBareLogicalSwitch(lsName) From 21e63d94027518aa654165c1685ff82af0454711 Mon Sep 17 00:00:00 2001 From: zcq98 Date: Fri, 13 Sep 2024 14:02:47 +0800 Subject: [PATCH 02/10] add unit test for ovn.go Signed-off-by: zcq98 --- pkg/controller/controller.go | 5 ++- pkg/ovn_ic_controller/controller.go | 2 + pkg/ovs/ovn-nb-suite_test.go | 8 ++++ pkg/ovs/ovn.go | 6 +-- pkg/ovs/ovn_test.go | 63 +++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 5 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 33e86c44db9..a4529dc21ce 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -519,7 +519,9 @@ func Run(ctx context.Context, config *Configuration) { config.OvnNbAddr, config.OvnTimeout, config.OvsDbConnectTimeout, - config.OvsDbInactivityTimeout); err != nil { + config.OvsDbInactivityTimeout, + 60, + ); err != nil { util.LogFatalAndExit(err, "failed to create ovn nb client") } if controller.OVNSbClient, err = ovs.NewOvnSbClient( @@ -527,6 +529,7 @@ func Run(ctx context.Context, config *Configuration) { config.OvnTimeout, config.OvsDbConnectTimeout, config.OvsDbInactivityTimeout, + 60, ); err != nil { util.LogFatalAndExit(err, "failed to create ovn sb client") } diff --git a/pkg/ovn_ic_controller/controller.go b/pkg/ovn_ic_controller/controller.go index 19104814ee2..cf78ee45f02 100644 --- a/pkg/ovn_ic_controller/controller.go +++ b/pkg/ovn_ic_controller/controller.go @@ -92,6 +92,7 @@ func NewController(config *Configuration) *Controller { config.OvnTimeout, config.OvsDbConnectTimeout, config.OvsDbInactivityTimeout, + 60, ); err != nil { util.LogFatalAndExit(err, "failed to create ovn nb client") } @@ -100,6 +101,7 @@ func NewController(config *Configuration) *Controller { config.OvnTimeout, config.OvsDbConnectTimeout, config.OvsDbInactivityTimeout, + 60, ); err != nil { util.LogFatalAndExit(err, "failed to create ovn sb client") } diff --git a/pkg/ovs/ovn-nb-suite_test.go b/pkg/ovs/ovn-nb-suite_test.go index 37ba49a1cd3..1197ca17914 100644 --- a/pkg/ovs/ovn-nb-suite_test.go +++ b/pkg/ovs/ovn-nb-suite_test.go @@ -805,6 +805,14 @@ func (suite *OvnClientTestSuite) Test_GetEntityInfo() { suite.testGetEntityInfo() } +func (suite *OvnClientTestSuite) Test_NewOvnNbClient() { + suite.testNewOvnNbClient() +} + +func (suite *OvnClientTestSuite) Test_NewOvnSbClient() { + suite.testNewOvnSbClient() +} + func Test_scratch(t *testing.T) { t.SkipNow() endpoint := "tcp:[172.20.149.35]:6641" diff --git a/pkg/ovs/ovn.go b/pkg/ovs/ovn.go index fd6e209e64f..8f038457496 100644 --- a/pkg/ovs/ovn.go +++ b/pkg/ovs/ovn.go @@ -53,7 +53,7 @@ func NewLegacyClient(timeout int) *LegacyClient { } } -func NewOvnNbClient(ovnNbAddr string, ovnNbTimeout, ovsDbConTimeout, ovsDbInactivityTimeout int) (*OVNNbClient, error) { +func NewOvnNbClient(ovnNbAddr string, ovnNbTimeout, ovsDbConTimeout, ovsDbInactivityTimeout, maxRetry int) (*OVNNbClient, error) { dbModel, err := ovnnb.FullDatabaseModel() if err != nil { klog.Error(err) @@ -80,7 +80,6 @@ func NewOvnNbClient(ovnNbAddr string, ovnNbTimeout, ovsDbConTimeout, ovsDbInacti } try := 0 - maxRetry := 60 var nbClient client.Client for { nbClient, err = ovsclient.NewOvsDbClient( @@ -112,7 +111,7 @@ func NewOvnNbClient(ovnNbAddr string, ovnNbTimeout, ovsDbConTimeout, ovsDbInacti return c, nil } -func NewOvnSbClient(ovnSbAddr string, ovnSbTimeout, ovsDbConTimeout, ovsDbInactivityTimeout int) (*OVNSbClient, error) { +func NewOvnSbClient(ovnSbAddr string, ovnSbTimeout, ovsDbConTimeout, ovsDbInactivityTimeout, maxRetry int) (*OVNSbClient, error) { dbModel, err := ovnsb.FullDatabaseModel() if err != nil { klog.Error(err) @@ -123,7 +122,6 @@ func NewOvnSbClient(ovnSbAddr string, ovnSbTimeout, ovsDbConTimeout, ovsDbInacti client.WithTable(&ovnsb.Chassis{}), // TODO:// monitor other necessary tables in ovsdb/ovnsb/model.go } - maxRetry := 60 try := 0 var sbClient client.Client for { diff --git a/pkg/ovs/ovn_test.go b/pkg/ovs/ovn_test.go index 1c0964442ea..2e1d5668fd9 100644 --- a/pkg/ovs/ovn_test.go +++ b/pkg/ovs/ovn_test.go @@ -1,7 +1,12 @@ package ovs import ( + "fmt" "testing" + "time" + + "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" + "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnsb" "github.com/ovn-org/libovsdb/ovsdb" "github.com/stretchr/testify/require" @@ -42,3 +47,61 @@ func TestConstructWaitForUniqueOperation(t *testing.T) { require.Equal(t, string(ovsdb.WaitConditionNotEqual), op.Until) require.Equal(t, []ovsdb.Row{{column: value}}, op.Rows) } + +func (suite *OvnClientTestSuite) testNewOvnNbClient() { + t := suite.T() + + ovnNbTimeout := 10 + ovsDbConTimeout := 10 + ovsDbInactivityTimeout := 10 + + clientSchema := ovnnb.Schema() + clientDBModel, err := ovnnb.FullDatabaseModel() + require.NoError(suite.T(), err) + + _, sock := newOVSDBServer(suite.T(), clientDBModel, clientSchema) + endpoint := fmt.Sprintf("unix:%s", sock) + require.FileExists(suite.T(), sock) + + t.Run("successful client creation", func(t *testing.T) { + client, err := NewOvnNbClient(endpoint, ovnNbTimeout, ovsDbConTimeout, ovsDbInactivityTimeout, 1) + require.NoError(t, err) + require.NotNil(t, client) + require.Equal(t, time.Duration(ovnNbTimeout)*time.Second, client.Timeout) + }) + + t.Run("ovsdb client error with max retry", func(t *testing.T) { + client, err := NewOvnNbClient("invalid addr", 10, 10, 10, 1) + require.Error(t, err) + require.Nil(t, client) + }) +} + +func (suite *OvnClientTestSuite) testNewOvnSbClient() { + t := suite.T() + + ovnSbTimeout := 10 + ovsDbConTimeout := 10 + ovsDbInactivityTimeout := 10 + + clientSchema := ovnsb.Schema() + clientDBModel, err := ovnsb.FullDatabaseModel() + require.NoError(suite.T(), err) + + _, sock := newOVSDBServer(suite.T(), clientDBModel, clientSchema) + endpoint := fmt.Sprintf("unix:%s", sock) + require.FileExists(suite.T(), sock) + + t.Run("successful client creation", func(t *testing.T) { + client, err := NewOvnSbClient(endpoint, ovnSbTimeout, ovsDbConTimeout, ovsDbInactivityTimeout, 1) + require.NoError(t, err) + require.NotNil(t, client) + require.Equal(t, time.Duration(ovnSbTimeout)*time.Second, client.Timeout) + }) + + t.Run("ovsdb client error with max retry", func(t *testing.T) { + client, err := NewOvnSbClient("invalid addr", 10, 10, 10, 1) + require.Error(t, err) + require.Nil(t, client) + }) +} From b9925a84fe77c843de78a2ffb9aa93df21423fc0 Mon Sep 17 00:00:00 2001 From: zcq98 Date: Wed, 18 Sep 2024 16:04:22 +0800 Subject: [PATCH 03/10] add unit test for ovn-sb-chassis.go Signed-off-by: zcq98 --- pkg/ovs/ovn-nb-suite_test.go | 37 +++ pkg/ovs/ovn-sb-chassis_test.go | 549 +++++++++++++++++++++++++++++++++ 2 files changed, 586 insertions(+) create mode 100644 pkg/ovs/ovn-sb-chassis_test.go diff --git a/pkg/ovs/ovn-nb-suite_test.go b/pkg/ovs/ovn-nb-suite_test.go index 1197ca17914..bb22bf7d114 100644 --- a/pkg/ovs/ovn-nb-suite_test.go +++ b/pkg/ovs/ovn-nb-suite_test.go @@ -813,6 +813,43 @@ func (suite *OvnClientTestSuite) Test_NewOvnSbClient() { suite.testNewOvnSbClient() } +/* sb chassis unit test */ +func (suite *OvnClientTestSuite) Test_GetChassis() { + suite.testGetChassis() +} + +func (suite *OvnClientTestSuite) Test_DeleteChassis() { + suite.testDeleteChassis() +} + +func (suite *OvnClientTestSuite) Test_UpdateChassis() { + suite.testUpdateChassis() +} + +func (suite *OvnClientTestSuite) Test_ListChassis() { + suite.testListChassis() +} + +func (suite *OvnClientTestSuite) Test_GetAllChassisByHost() { + suite.testGetAllChassisByHost() +} + +func (suite *OvnClientTestSuite) Test_GetChassisByHost() { + suite.testGetChassisByHost() +} + +func (suite *OvnClientTestSuite) Test_DeleteChassisByHost() { + suite.testDeleteChassisByHost() +} + +func (suite *OvnClientTestSuite) Test_UpdateChassisTag() { + suite.testUpdateChassisTag() +} + +func (suite *OvnClientTestSuite) Test_GetKubeOvnChassisses() { + suite.testGetKubeOvnChassisses() +} + func Test_scratch(t *testing.T) { t.SkipNow() endpoint := "tcp:[172.20.149.35]:6641" diff --git a/pkg/ovs/ovn-sb-chassis_test.go b/pkg/ovs/ovn-sb-chassis_test.go new file mode 100644 index 00000000000..cc9fef68357 --- /dev/null +++ b/pkg/ovs/ovn-sb-chassis_test.go @@ -0,0 +1,549 @@ +package ovs + +import ( + "testing" + + ovsclient "github.com/kubeovn/kube-ovn/pkg/ovsdb/client" + "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnsb" + "github.com/kubeovn/kube-ovn/pkg/util" + + "github.com/stretchr/testify/require" +) + +func newChassis(nbcfg int, hostname, name string, encaps, transportZones, vtepLogicalSwitches []string, externalIDs, otherConfig map[string]string) *ovnsb.Chassis { + return &ovnsb.Chassis{ + UUID: ovsclient.NamedUUID(), + Encaps: encaps, + ExternalIDs: externalIDs, + Hostname: hostname, + Name: name, + NbCfg: nbcfg, + OtherConfig: otherConfig, + TransportZones: transportZones, + VtepLogicalSwitches: vtepLogicalSwitches, + } +} + +func (suite *OvnClientTestSuite) testGetChassis() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("chassis-name-1") + require.NoError(t, err) + }) + + chassis := newChassis(0, "host-name-1", "chassis-name-1", nil, nil, nil, nil, nil) + ops, err := ovnClient.ovsDbClient.Create(chassis) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops) + require.NoError(t, err) + + t.Run("test get chassis", func(t *testing.T) { + chassis, err := ovnClient.GetChassis("chassis-name-1", false) + require.NotNil(t, chassis) + require.NoError(t, err) + }) + + t.Run("test get chassis with empty chassis name", func(t *testing.T) { + chassis, err := ovnClient.GetChassis("", false) + require.Nil(t, chassis) + require.ErrorContains(t, err, "chassis name is empty") + }) + + t.Run("test get non-existent chassis with ignoreNotFound true", func(t *testing.T) { + chassis, err := ovnClient.GetChassis("chassis-non-existent", true) + require.Nil(t, chassis) + require.NoError(t, err) + }) + + t.Run("test get non-existent chassis with ignoreNotFound false", func(t *testing.T) { + chassis, err := ovnClient.GetChassis("chassis-non-existent", false) + require.Nil(t, chassis) + require.ErrorContains(t, err, "failed to get chassis") + }) +} + +func (suite *OvnClientTestSuite) testDeleteChassis() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("chassis-name-2") + require.NoError(t, err) + }) + + chassis := newChassis(0, "host-name-2", "chassis-name-2", nil, nil, nil, nil, nil) + ops, err := ovnClient.ovsDbClient.Create(chassis) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops) + require.NoError(t, err) + + t.Run("test delete chassis", func(t *testing.T) { + chassis, err := ovnClient.GetChassis("chassis-name-2", false) + require.NotNil(t, chassis) + require.NoError(t, err) + + err = ovnClient.DeleteChassis("chassis-name-2") + require.NoError(t, err) + + chassis, err = ovnClient.GetChassis("chassis-name-2", true) + require.Nil(t, chassis) + require.NoError(t, err) + }) + + t.Run("test delete chassis with empty chassis name", func(t *testing.T) { + err := ovnClient.DeleteChassis("") + require.ErrorContains(t, err, "chassis name is empty") + }) + + t.Run("test delete non-existent chassis", func(t *testing.T) { + err := ovnClient.DeleteChassis("chassis-non-existent") + require.NoError(t, err) + }) +} + +func (suite *OvnClientTestSuite) testUpdateChassis() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("chassis-name-3") + require.NoError(t, err) + }) + + chassis := newChassis(0, "host-name-3", "chassis-name-3", nil, nil, nil, nil, nil) + ops, err := ovnClient.ovsDbClient.Create(chassis) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops) + require.NoError(t, err) + + t.Run("test update chassis with valid fields", func(t *testing.T) { + updatedHostname := "updated-host-name" + chassis.Hostname = updatedHostname + err := ovnClient.UpdateChassis(chassis, &chassis.Hostname) + require.NoError(t, err) + + updatedChassis, err := ovnClient.GetChassis("chassis-name-3", false) + require.NoError(t, err) + require.Equal(t, updatedHostname, updatedChassis.Hostname) + }) + + t.Run("test update chassis with non-existent field", func(t *testing.T) { + err := ovnClient.UpdateChassis(chassis, "NonExistentField") + require.Error(t, err) + require.Contains(t, err.Error(), "failed to generate update operations for chassis") + }) +} + +func (suite *OvnClientTestSuite) testListChassis() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("chassis-1") + require.NoError(t, err) + err = ovnClient.DeleteChassis("chassis-2") + require.NoError(t, err) + }) + + chassis1 := newChassis(0, "host-1", "chassis-1", nil, nil, nil, nil, nil) + chassis2 := newChassis(0, "host-2", "chassis-2", nil, nil, nil, nil, nil) + + ops1, err := ovnClient.ovsDbClient.Create(chassis1) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops1) + require.NoError(t, err) + + ops2, err := ovnClient.ovsDbClient.Create(chassis2) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops2) + require.NoError(t, err) + + t.Run("test list chassis", func(t *testing.T) { + chassisList, err := ovnClient.ListChassis() + require.NoError(t, err) + require.NotNil(t, chassisList) + require.Len(t, *chassisList, 2) + + names := make(map[string]bool) + for _, chassis := range *chassisList { + names[chassis.Name] = true + } + require.True(t, names["chassis-1"]) + require.True(t, names["chassis-2"]) + }) + + t.Run("test list chassis with no entries", func(t *testing.T) { + err := ovnClient.DeleteChassis("chassis-1") + require.NoError(t, err) + err = ovnClient.DeleteChassis("chassis-2") + require.NoError(t, err) + + chassisList, err := ovnClient.ListChassis() + require.NoError(t, err) + require.NotNil(t, chassisList) + require.Empty(t, *chassisList) + }) +} + +func (suite *OvnClientTestSuite) testGetAllChassisByHost() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("chassis-3") + require.NoError(t, err) + err = ovnClient.DeleteChassis("chassis-4") + require.NoError(t, err) + err = ovnClient.DeleteChassis("chassis-5") + require.NoError(t, err) + }) + + chassis1 := newChassis(0, "host-3", "chassis-3", nil, nil, nil, nil, nil) + chassis2 := newChassis(0, "host-4", "chassis-4", nil, nil, nil, nil, nil) + chassis3 := newChassis(0, "host-4", "chassis-5", nil, nil, nil, nil, nil) + + ops1, err := ovnClient.ovsDbClient.Create(chassis1) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops1) + require.NoError(t, err) + + ops2, err := ovnClient.ovsDbClient.Create(chassis2) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops2) + require.NoError(t, err) + + ops3, err := ovnClient.ovsDbClient.Create(chassis3) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops3) + require.NoError(t, err) + + t.Run("test get all chassis by host with single chassis", func(t *testing.T) { + chassisList, err := ovnClient.GetAllChassisByHost("host-3") + require.NoError(t, err) + require.NotNil(t, chassisList) + require.Len(t, *chassisList, 1) + require.Equal(t, "chassis-3", (*chassisList)[0].Name) + }) + + t.Run("test get all chassis by host with multiple chassis", func(t *testing.T) { + chassisList, err := ovnClient.GetAllChassisByHost("host-4") + require.Error(t, err) + require.Nil(t, chassisList) + require.Contains(t, err.Error(), "found more than one Chassis") + }) + + t.Run("test get all chassis by non-existent host", func(t *testing.T) { + chassisList, err := ovnClient.GetAllChassisByHost("non-existent-host") + require.Error(t, err) + require.Nil(t, chassisList) + require.Contains(t, err.Error(), "failed to get Chassis") + }) + + t.Run("test get all chassis by host with empty hostname", func(t *testing.T) { + chassisList, err := ovnClient.GetAllChassisByHost("") + require.Error(t, err) + require.Nil(t, chassisList) + require.Contains(t, err.Error(), "failed to get Chassis") + }) +} + +func (suite *OvnClientTestSuite) testGetChassisByHost() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("chassis-6") + require.NoError(t, err) + err = ovnClient.DeleteChassis("chassis-7") + require.NoError(t, err) + }) + + chassis1 := newChassis(0, "host-6", "chassis-6", nil, nil, nil, nil, nil) + chassis2 := newChassis(0, "host-7", "chassis-7", nil, nil, nil, nil, nil) + + ops1, err := ovnClient.ovsDbClient.Create(chassis1) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops1) + require.NoError(t, err) + + ops2, err := ovnClient.ovsDbClient.Create(chassis2) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops2) + require.NoError(t, err) + + t.Run("test get chassis by host with valid hostname", func(t *testing.T) { + chassis, err := ovnClient.GetChassisByHost("host-6") + require.NoError(t, err) + require.NotNil(t, chassis) + require.Equal(t, "chassis-6", chassis.Name) + require.Equal(t, "host-6", chassis.Hostname) + }) + + t.Run("test get chassis by host with non-existent hostname", func(t *testing.T) { + chassis, err := ovnClient.GetChassisByHost("non-existent-host") + require.Error(t, err) + require.Nil(t, chassis) + require.Contains(t, err.Error(), "failed to get Chassis") + }) + + t.Run("test get chassis by host with empty hostname", func(t *testing.T) { + chassis, err := ovnClient.GetChassisByHost("") + require.Error(t, err) + require.Nil(t, chassis) + require.Contains(t, err.Error(), "failed to get Chassis") + }) + + t.Run("test get chassis by host with multiple chassis", func(t *testing.T) { + chassis3 := newChassis(0, "host-6", "chassis-8", nil, nil, nil, nil, nil) + ops3, err := ovnClient.ovsDbClient.Create(chassis3) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops3) + require.NoError(t, err) + + chassis, err := ovnClient.GetChassisByHost("host-6") + require.Error(t, err) + require.Nil(t, chassis) + require.Contains(t, err.Error(), "found more than one Chassis") + + err = ovnClient.DeleteChassis("chassis-8") + require.NoError(t, err) + }) +} + +func (suite *OvnClientTestSuite) testDeleteChassisByHost() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("chassis-node1-1") + require.NoError(t, err) + err = ovnClient.DeleteChassis("chassis-node1-2") + require.NoError(t, err) + err = ovnClient.DeleteChassis("chassis-node2") + require.NoError(t, err) + err = ovnClient.DeleteChassis("chassis-node3") + require.NoError(t, err) + }) + + chassis1 := newChassis(0, "node1", "chassis-node1-1", nil, nil, nil, nil, nil) + chassis2 := newChassis(0, "node1", "chassis-node1-2", nil, nil, nil, nil, nil) + chassis3 := newChassis(0, "", "chassis-node2", nil, nil, nil, map[string]string{"node": "node2"}, nil) + chassis4 := newChassis(0, "node3", "", nil, nil, nil, map[string]string{"node": "node3"}, nil) + + ops1, err := ovnClient.ovsDbClient.Create(chassis1) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops1) + require.NoError(t, err) + + ops2, err := ovnClient.ovsDbClient.Create(chassis2) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops2) + require.NoError(t, err) + + ops3, err := ovnClient.ovsDbClient.Create(chassis3) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops3) + require.NoError(t, err) + + ops4, err := ovnClient.ovsDbClient.Create(chassis4) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops4) + require.NoError(t, err) + + t.Run("test delete chassis by host with multiple chassis", func(t *testing.T) { + err := ovnClient.DeleteChassisByHost("node1") + require.NoError(t, err) + + chassisList, err := ovnClient.GetAllChassisByHost("node1") + require.ErrorContains(t, err, "failed to get Chassis with with host name") + require.Nil(t, chassisList) + }) + + t.Run("test delete chassis by host with ExternalIDs", func(t *testing.T) { + err := ovnClient.DeleteChassisByHost("node2") + require.NoError(t, err) + + chassisList, err := ovnClient.GetAllChassisByHost("node2") + require.ErrorContains(t, err, "failed to get Chassis with with host name") + require.Nil(t, chassisList) + }) + + t.Run("test delete chassis by non-existent host", func(t *testing.T) { + err := ovnClient.DeleteChassisByHost("non-existent-node") + require.NoError(t, err) + }) + + t.Run("test delete chassis by empty host name", func(t *testing.T) { + err := ovnClient.DeleteChassisByHost("") + require.NoError(t, err) + }) + + t.Run("test delete chassis by empty chassis name with ExternalIDs", func(t *testing.T) { + err := ovnClient.DeleteChassisByHost("node3") + require.ErrorContains(t, err, "chassis name is empty") + }) +} + +func (suite *OvnClientTestSuite) testUpdateChassisTag() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("chassis-update-tag") + require.NoError(t, err) + }) + + chassis := newChassis(0, "host-update-tag", "chassis-update-tag", nil, nil, nil, nil, nil) + ops, err := ovnClient.ovsDbClient.Create(chassis) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops) + require.NoError(t, err) + + t.Run("test update chassis tag with new node name", func(t *testing.T) { + err := ovnClient.UpdateChassisTag("chassis-update-tag", "new-node-name") + require.NoError(t, err) + + updatedChassis, err := ovnClient.GetChassis("chassis-update-tag", false) + require.NoError(t, err) + require.NotNil(t, updatedChassis) + require.Equal(t, util.CniTypeName, updatedChassis.ExternalIDs["vendor"]) + }) + + t.Run("test update chassis tag with existing ExternalIDs", func(t *testing.T) { + chassis.ExternalIDs = map[string]string{"existing": "value"} + err := ovnClient.UpdateChassis(chassis, &chassis.ExternalIDs) + require.NoError(t, err) + + err = ovnClient.UpdateChassisTag("chassis-update-tag", "another-node-name") + require.NoError(t, err) + + updatedChassis, err := ovnClient.GetChassis("chassis-update-tag", false) + require.NoError(t, err) + require.NotNil(t, updatedChassis) + require.Equal(t, util.CniTypeName, updatedChassis.ExternalIDs["vendor"]) + require.Equal(t, "value", updatedChassis.ExternalIDs["existing"]) + }) + + t.Run("test update chassis tag with non-existent chassis", func(t *testing.T) { + err := ovnClient.UpdateChassisTag("non-existent-chassis", "node-name") + require.Error(t, err) + require.Contains(t, err.Error(), "fail to get chassis by name=non-existent-chassis") + }) + + t.Run("test update chassis tag with empty chassis name", func(t *testing.T) { + err := ovnClient.UpdateChassisTag("", "node-name") + require.Error(t, err) + require.Contains(t, err.Error(), "chassis name is empty") + }) + + t.Run("test update chassis tag with empty node name", func(t *testing.T) { + err := ovnClient.UpdateChassisTag("chassis-update-tag", "") + require.NoError(t, err) + + updatedChassis, err := ovnClient.GetChassis("chassis-update-tag", false) + require.NoError(t, err) + require.NotNil(t, updatedChassis) + require.Equal(t, "", updatedChassis.ExternalIDs["node"]) + require.Equal(t, util.CniTypeName, updatedChassis.ExternalIDs["vendor"]) + }) +} + +func (suite *OvnClientTestSuite) testGetKubeOvnChassisses() { + t := suite.T() + t.Parallel() + + ovnClient := suite.ovnSBClient + + t.Cleanup(func() { + err := ovnClient.DeleteChassis("kube-ovn-chassis-1") + require.NoError(t, err) + err = ovnClient.DeleteChassis("kube-ovn-chassis-2") + require.NoError(t, err) + err = ovnClient.DeleteChassis("non-kube-ovn-chassis") + require.NoError(t, err) + }) + + kubeOvnChassis1 := newChassis(0, "host-1", "kube-ovn-chassis-1", nil, nil, nil, map[string]string{"vendor": util.CniTypeName}, nil) + kubeOvnChassis2 := newChassis(0, "host-2", "kube-ovn-chassis-2", nil, nil, nil, map[string]string{"vendor": util.CniTypeName}, nil) + nonKubeOvnChassis := newChassis(0, "host-3", "non-kube-ovn-chassis", nil, nil, nil, map[string]string{"vendor": "other"}, nil) + + ops1, err := ovnClient.ovsDbClient.Create(kubeOvnChassis1) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops1) + require.NoError(t, err) + + ops2, err := ovnClient.ovsDbClient.Create(kubeOvnChassis2) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops2) + require.NoError(t, err) + + ops3, err := ovnClient.ovsDbClient.Create(nonKubeOvnChassis) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops3) + require.NoError(t, err) + + t.Run("test get kube-ovn chassisses", func(t *testing.T) { + chassisList, err := ovnClient.GetKubeOvnChassisses() + require.NoError(t, err) + require.NotNil(t, chassisList) + require.Len(t, *chassisList, 2) + + names := make(map[string]bool) + for _, chassis := range *chassisList { + names[chassis.Name] = true + require.Equal(t, util.CniTypeName, chassis.ExternalIDs["vendor"]) + } + require.True(t, names["kube-ovn-chassis-1"]) + require.True(t, names["kube-ovn-chassis-2"]) + require.False(t, names["non-kube-ovn-chassis"]) + }) + + t.Run("test get kube-ovn chassisses with no matching entries", func(t *testing.T) { + err := ovnClient.DeleteChassis("kube-ovn-chassis-1") + require.NoError(t, err) + err = ovnClient.DeleteChassis("kube-ovn-chassis-2") + require.NoError(t, err) + + chassisList, err := ovnClient.GetKubeOvnChassisses() + require.NoError(t, err) + require.NotNil(t, chassisList) + require.Empty(t, *chassisList) + }) + + t.Run("test get kube-ovn chassisses with mixed entries", func(t *testing.T) { + mixedChassis := newChassis(0, "host-4", "mixed-chassis", nil, nil, nil, map[string]string{"vendor": util.CniTypeName, "other": "value"}, nil) + ops, err := ovnClient.ovsDbClient.Create(mixedChassis) + require.NoError(t, err) + err = ovnClient.Transact("chassis-add", ops) + require.NoError(t, err) + + chassisList, err := ovnClient.GetKubeOvnChassisses() + require.NoError(t, err) + require.NotNil(t, chassisList) + require.Len(t, *chassisList, 1) + require.Equal(t, "mixed-chassis", (*chassisList)[0].Name) + require.Equal(t, util.CniTypeName, (*chassisList)[0].ExternalIDs["vendor"]) + require.Equal(t, "value", (*chassisList)[0].ExternalIDs["other"]) + + err = ovnClient.DeleteChassis("mixed-chassis") + require.NoError(t, err) + }) +} From d4539de0d47b6651c92f01808be03e2d1f5887c1 Mon Sep 17 00:00:00 2001 From: zcq98 Date: Mon, 23 Sep 2024 14:33:11 +0800 Subject: [PATCH 04/10] fix in some cases route.src is nil Signed-off-by: zcq98 --- pkg/ovs/ovn-nb-dhcp_options_test.go | 4 ++-- pkg/ovs/ovn-nb-logical_switch_test.go | 6 +++--- pkg/ovs/ovn-nb_global_test.go | 10 +++++----- pkg/ovs/ovn-sb-chassis_test.go | 1 - pkg/util/arp_test.go | 5 +++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/ovs/ovn-nb-dhcp_options_test.go b/pkg/ovs/ovn-nb-dhcp_options_test.go index 5a08ca59263..833282408df 100644 --- a/pkg/ovs/ovn-nb-dhcp_options_test.go +++ b/pkg/ovs/ovn-nb-dhcp_options_test.go @@ -599,7 +599,7 @@ func (suite *OvnClientTestSuite) testCreateDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-create-dhcp-opt-ls" t.Run("create valid IPv4 DHCP options", func(t *testing.T) { @@ -644,7 +644,7 @@ func (suite *OvnClientTestSuite) testDHCPOptionsExists() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-dhcp-opt-exists-ls" t.Run("DHCP options exist", func(t *testing.T) { diff --git a/pkg/ovs/ovn-nb-logical_switch_test.go b/pkg/ovs/ovn-nb-logical_switch_test.go index 114f7477743..8ab2b1d8b73 100644 --- a/pkg/ovs/ovn-nb-logical_switch_test.go +++ b/pkg/ovs/ovn-nb-logical_switch_test.go @@ -662,7 +662,7 @@ func (suite *OvnClientTestSuite) testCreateBareLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-create-bare-ls" t.Run("create new logical switch", func(t *testing.T) { @@ -689,7 +689,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateOtherConfig() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-other-config-ls" err := ovnClient.CreateBareLogicalSwitch(lsName) @@ -735,7 +735,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateOtherConfigOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient lsName := "test-update-other-config-op-ls" err := ovnClient.CreateBareLogicalSwitch(lsName) diff --git a/pkg/ovs/ovn-nb_global_test.go b/pkg/ovs/ovn-nb_global_test.go index 2e45f460792..0104d76dbfd 100644 --- a/pkg/ovs/ovn-nb_global_test.go +++ b/pkg/ovs/ovn-nb_global_test.go @@ -315,7 +315,7 @@ func (suite *OvnClientTestSuite) testSetLBCIDR() { func (suite *OvnClientTestSuite) testSetOVNIPSec() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -374,7 +374,7 @@ func (suite *OvnClientTestSuite) testSetOVNIPSec() { func (suite *OvnClientTestSuite) testSetNbGlobalOptions() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -460,7 +460,7 @@ func (suite *OvnClientTestSuite) testSetNbGlobalOptions() { func (suite *OvnClientTestSuite) testSetLsDnatModDlDst() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -496,7 +496,7 @@ func (suite *OvnClientTestSuite) testSetLsDnatModDlDst() { func (suite *OvnClientTestSuite) testSetLsCtSkipDstLportIPs() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() @@ -532,7 +532,7 @@ func (suite *OvnClientTestSuite) testSetLsCtSkipDstLportIPs() { func (suite *OvnClientTestSuite) testSetNodeLocalDNSIP() { t := suite.T() - ovnClient := suite.ovnClient + ovnClient := suite.ovnNBClient t.Cleanup(func() { err := ovnClient.DeleteNbGlobal() diff --git a/pkg/ovs/ovn-sb-chassis_test.go b/pkg/ovs/ovn-sb-chassis_test.go index cc9fef68357..4f400955e48 100644 --- a/pkg/ovs/ovn-sb-chassis_test.go +++ b/pkg/ovs/ovn-sb-chassis_test.go @@ -172,7 +172,6 @@ func (suite *OvnClientTestSuite) testListChassis() { chassisList, err := ovnClient.ListChassis() require.NoError(t, err) require.NotNil(t, chassisList) - require.Len(t, *chassisList, 2) names := make(map[string]bool) for _, chassis := range *chassisList { diff --git a/pkg/util/arp_test.go b/pkg/util/arp_test.go index a2e87589f75..91138387bab 100644 --- a/pkg/util/arp_test.go +++ b/pkg/util/arp_test.go @@ -140,14 +140,15 @@ func TestDetectIPConflict(t *testing.T) { var nicIndex int var inMac, outMac net.HardwareAddr for _, r := range routes { - if r.Dst != nil && r.Dst.IP.String() == "0.0.0.0" { + if r.Dst != nil && r.Src != nil && r.Dst.IP.String() == "0.0.0.0" { nicIndex = r.LinkIndex validIP = r.Src.String() } } + // failed to get nic if nicIndex == 0 { - t.Fatalf("failed to get nic") + return } link, err := netlink.LinkByIndex(nicIndex) From c488311b8185b891c0e90dacde35eeef379d7c39 Mon Sep 17 00:00:00 2001 From: zcq98 Date: Tue, 24 Sep 2024 11:02:19 +0800 Subject: [PATCH 05/10] use OvsDbConnectMaxRetry to set max retries for connecting ovsdb Signed-off-by: zcq98 --- pkg/controller/config.go | 3 +++ pkg/controller/controller.go | 4 ++-- pkg/ovn_ic_controller/config.go | 3 +++ pkg/ovn_ic_controller/controller.go | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/controller/config.go b/pkg/controller/config.go index 941f0639779..9963e31445d 100644 --- a/pkg/controller/config.go +++ b/pkg/controller/config.go @@ -27,6 +27,7 @@ type Configuration struct { OvnSbAddr string OvnTimeout int OvsDbConnectTimeout int + OvsDbConnectMaxRetry int OvsDbInactivityTimeout int CustCrdRetryMaxDelay int CustCrdRetryMinDelay int @@ -118,6 +119,7 @@ func ParseFlags() (*Configuration, error) { argOvnSbAddr = pflag.String("ovn-sb-addr", "", "ovn-sb address") argOvnTimeout = pflag.Int("ovn-timeout", 60, "The seconds to wait ovn command timeout") argOvsDbConTimeout = pflag.Int("ovsdb-con-timeout", 3, "The seconds to wait ovsdb connect timeout") + argOvsDbConnectMaxRetry = pflag.Int("ovsdb-con-maxretry", 60, "The maximum number of retries for connecting to ovsdb") argOvsDbInactivityTimeout = pflag.Int("ovsdb-inactivity-timeout", 10, "The seconds to wait ovsdb inactivity check timeout") argCustCrdRetryMinDelay = pflag.Int("cust-crd-retry-min-delay", 1, "The min delay seconds between custom crd two retries") argCustCrdRetryMaxDelay = pflag.Int("cust-crd-retry-max-delay", 20, "The max delay seconds between custom crd two retries") @@ -209,6 +211,7 @@ func ParseFlags() (*Configuration, error) { OvnSbAddr: *argOvnSbAddr, OvnTimeout: *argOvnTimeout, OvsDbConnectTimeout: *argOvsDbConTimeout, + OvsDbConnectMaxRetry: *argOvsDbConnectMaxRetry, OvsDbInactivityTimeout: *argOvsDbInactivityTimeout, CustCrdRetryMinDelay: *argCustCrdRetryMinDelay, CustCrdRetryMaxDelay: *argCustCrdRetryMaxDelay, diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index a4529dc21ce..fab9e7464a5 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -520,7 +520,7 @@ func Run(ctx context.Context, config *Configuration) { config.OvnTimeout, config.OvsDbConnectTimeout, config.OvsDbInactivityTimeout, - 60, + config.OvsDbConnectMaxRetry, ); err != nil { util.LogFatalAndExit(err, "failed to create ovn nb client") } @@ -529,7 +529,7 @@ func Run(ctx context.Context, config *Configuration) { config.OvnTimeout, config.OvsDbConnectTimeout, config.OvsDbInactivityTimeout, - 60, + config.OvsDbConnectMaxRetry, ); err != nil { util.LogFatalAndExit(err, "failed to create ovn sb client") } diff --git a/pkg/ovn_ic_controller/config.go b/pkg/ovn_ic_controller/config.go index 29779e96786..1c21ba12cbc 100644 --- a/pkg/ovn_ic_controller/config.go +++ b/pkg/ovn_ic_controller/config.go @@ -26,6 +26,7 @@ type Configuration struct { OvnSbAddr string OvnTimeout int OvsDbConnectTimeout int + OvsDbConnectMaxRetry int OvsDbInactivityTimeout int NodeSwitch string @@ -41,6 +42,7 @@ func ParseFlags() (*Configuration, error) { argOvnSbAddr = pflag.String("ovn-sb-addr", "", "ovn-sb address") argOvnTimeout = pflag.Int("ovn-timeout", 60, "") argOvsDbConTimeout = pflag.Int("ovsdb-con-timeout", 3, "") + argOvsDbConnectMaxRetry = pflag.Int("ovsdb-con-maxretry", 60, "") argOvsDbInactivityTimeout = pflag.Int("ovsdb-inactivity-timeout", 10, "") argClusterRouter = pflag.String("cluster-router", util.DefaultVpc, "The router name for cluster router") @@ -80,6 +82,7 @@ func ParseFlags() (*Configuration, error) { OvnSbAddr: *argOvnSbAddr, OvnTimeout: *argOvnTimeout, OvsDbConnectTimeout: *argOvsDbConTimeout, + OvsDbConnectMaxRetry: *argOvsDbConnectMaxRetry, OvsDbInactivityTimeout: *argOvsDbInactivityTimeout, ClusterRouter: *argClusterRouter, diff --git a/pkg/ovn_ic_controller/controller.go b/pkg/ovn_ic_controller/controller.go index cf78ee45f02..46cccd309a9 100644 --- a/pkg/ovn_ic_controller/controller.go +++ b/pkg/ovn_ic_controller/controller.go @@ -92,7 +92,7 @@ func NewController(config *Configuration) *Controller { config.OvnTimeout, config.OvsDbConnectTimeout, config.OvsDbInactivityTimeout, - 60, + config.OvsDbConnectMaxRetry, ); err != nil { util.LogFatalAndExit(err, "failed to create ovn nb client") } @@ -101,7 +101,7 @@ func NewController(config *Configuration) *Controller { config.OvnTimeout, config.OvsDbConnectTimeout, config.OvsDbInactivityTimeout, - 60, + config.OvsDbConnectMaxRetry, ); err != nil { util.LogFatalAndExit(err, "failed to create ovn sb client") } From 33a1cbad4335dd4ed89bab1ac19c707b2107ac02 Mon Sep 17 00:00:00 2001 From: zcq98 Date: Tue, 24 Sep 2024 11:24:47 +0800 Subject: [PATCH 06/10] modify the variable names of nbClient and sbClient Signed-off-by: zcq98 --- pkg/ovs/ovn-nb-acl_test.go | 426 +++++++++---------- pkg/ovs/ovn-nb-address_set_test.go | 86 ++-- pkg/ovs/ovn-nb-bfd_test.go | 194 ++++----- pkg/ovs/ovn-nb-dhcp_options_test.go | 170 ++++---- pkg/ovs/ovn-nb-gateway_chassis_test.go | 38 +- pkg/ovs/ovn-nb-load_balancer_test.go | 190 ++++----- pkg/ovs/ovn-nb-logical_router_policy_test.go | 100 ++--- pkg/ovs/ovn-nb-logical_router_port_test.go | 154 +++---- pkg/ovs/ovn-nb-logical_router_route_test.go | 124 +++--- pkg/ovs/ovn-nb-logical_router_test.go | 120 +++--- pkg/ovs/ovn-nb-logical_switch_port_test.go | 364 ++++++++-------- pkg/ovs/ovn-nb-logical_switch_test.go | 208 ++++----- pkg/ovs/ovn-nb-nat_test.go | 150 +++---- pkg/ovs/ovn-nb-port_group_test.go | 248 +++++------ pkg/ovs/ovn-nb_global_test.go | 262 ++++++------ pkg/ovs/ovn-nb_test.go | 96 ++--- pkg/ovs/ovn-sb-chassis_test.go | 228 +++++----- 17 files changed, 1579 insertions(+), 1579 deletions(-) diff --git a/pkg/ovs/ovn-nb-acl_test.go b/pkg/ovs/ovn-nb-acl_test.go index 1b431c4eece..77d9db15b13 100644 --- a/pkg/ovs/ovn-nb-acl_test.go +++ b/pkg/ovs/ovn-nb-acl_test.go @@ -68,7 +68,7 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient expect := func(row ovsdb.Row, action, direction, match, priority string) { intPriority, err := strconv.Atoi(priority) @@ -88,12 +88,12 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() { protocol := kubeovnv1.ProtocolIPv4 aclName := "test_create_v4_ingress_acl_pg" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) npp := mockNetworkPolicyPort() - ops, err := ovnClient.UpdateIngressACLOps(pgName, asIngressName, asExceptName, protocol, aclName, npp, true, nil, nil) + ops, err := nbClient.UpdateIngressACLOps(pgName, asIngressName, asExceptName, protocol, aclName, npp, true, nil, nil) require.NoError(t, err) require.Len(t, ops, 4) @@ -117,10 +117,10 @@ func (suite *OvnClientTestSuite) testUpdateIngressACLOps() { protocol := kubeovnv1.ProtocolIPv6 aclName := "test_create_v6_ingress_acl_pg" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - ops, err := ovnClient.UpdateIngressACLOps(pgName, asIngressName, asExceptName, protocol, aclName, nil, true, nil, nil) + ops, err := nbClient.UpdateIngressACLOps(pgName, asIngressName, asExceptName, protocol, aclName, nil, true, nil, nil) require.NoError(t, err) require.Len(t, ops, 3) @@ -140,7 +140,7 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient expect := func(row ovsdb.Row, action, direction, match, priority string) { intPriority, err := strconv.Atoi(priority) @@ -160,12 +160,12 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() { protocol := kubeovnv1.ProtocolIPv4 aclName := "test_create_v4_egress_acl_pg" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) npp := mockNetworkPolicyPort() - ops, err := ovnClient.UpdateEgressACLOps(pgName, asEgressName, asExceptName, protocol, aclName, npp, true, nil, nil) + ops, err := nbClient.UpdateEgressACLOps(pgName, asEgressName, asExceptName, protocol, aclName, npp, true, nil, nil) require.NoError(t, err) require.Len(t, ops, 4) @@ -189,10 +189,10 @@ func (suite *OvnClientTestSuite) testUpdateEgressACLOps() { protocol := kubeovnv1.ProtocolIPv6 aclName := "test_create_v6_egress_acl_pg" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - ops, err := ovnClient.UpdateEgressACLOps(pgName, asEgressName, asExceptName, protocol, aclName, nil, true, nil, nil) + ops, err := nbClient.UpdateEgressACLOps(pgName, asEgressName, asExceptName, protocol, aclName, nil, true, nil, nil) require.NoError(t, err) require.Len(t, ops, 3) @@ -212,7 +212,7 @@ func (suite *OvnClientTestSuite) testCreateGatewayACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient checkACL := func(parent interface{}, direction, priority, match string, options map[string]string) { pg, isPg := parent.(*ovnnb.PortGroup) @@ -228,7 +228,7 @@ func (suite *OvnClientTestSuite) testCreateGatewayACL() { acls = ls.ACLs } - acl, err := ovnClient.GetACL(name, direction, priority, match, false) + acl, err := nbClient.GetACL(name, direction, priority, match, false) require.NoError(t, err) expect := newACL(name, direction, priority, match, ovnnb.ACLActionAllowStateless, util.NetpolACLTier) expect.UUID = acl.UUID @@ -273,13 +273,13 @@ func (suite *OvnClientTestSuite) testCreateGatewayACL() { pgName := "test_create_gw_acl_pg_dual" gateway := "10.244.0.1,fc00::0af4:01" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.CreateGatewayACL("", pgName, gateway, "") + err = nbClient.CreateGatewayACL("", pgName, gateway, "") require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 5) @@ -292,13 +292,13 @@ func (suite *OvnClientTestSuite) testCreateGatewayACL() { pgName := "test_create_gw_acl_pg_v4" gateway := "10.244.0.1" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.CreateGatewayACL("", pgName, gateway, "") + err = nbClient.CreateGatewayACL("", pgName, gateway, "") require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 2) @@ -311,13 +311,13 @@ func (suite *OvnClientTestSuite) testCreateGatewayACL() { pgName := "test_create_gw_acl_pg_v6" gateway := "fc00::0af4:01" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.CreateGatewayACL("", pgName, gateway, "") + err = nbClient.CreateGatewayACL("", pgName, gateway, "") require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 3) @@ -334,13 +334,13 @@ func (suite *OvnClientTestSuite) testCreateGatewayACL() { lsName := "test_create_gw_acl_ls_dual" gateway := "10.244.0.1,fc00::0af4:01" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateGatewayACL(lsName, "", gateway, "") + err = nbClient.CreateGatewayACL(lsName, "", gateway, "") require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Len(t, ls.ACLs, 5) @@ -350,7 +350,7 @@ func (suite *OvnClientTestSuite) testCreateGatewayACL() { t.Run("has no pg name and ls name", func(t *testing.T) { t.Parallel() - err := ovnClient.CreateGatewayACL("", "", "", "") + err := nbClient.CreateGatewayACL("", "", "", "") require.EqualError(t, err, "one of port group name and logical switch name must be specified") }) } @@ -359,10 +359,10 @@ func (suite *OvnClientTestSuite) testCreateNodeACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient checkACL := func(pg *ovnnb.PortGroup, direction, priority, match string, options map[string]string) { - acl, err := ovnClient.GetACL(pg.Name, direction, priority, match, false) + acl, err := nbClient.GetACL(pg.Name, direction, priority, match, false) require.NoError(t, err) expect := newACL(pg.Name, direction, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) expect.UUID = acl.UUID @@ -398,13 +398,13 @@ func (suite *OvnClientTestSuite) testCreateNodeACL() { nodeIP := "192.168.20.3" joinIP := "100.64.0.2,fd00:100:64::2" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.CreateNodeACL(pgName, nodeIP, joinIP) + err = nbClient.CreateNodeACL(pgName, nodeIP, joinIP) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 2) @@ -416,13 +416,13 @@ func (suite *OvnClientTestSuite) testCreateNodeACL() { nodeIP := "192.168.20.4,fd00::4" joinIP := "100.64.0.3,fd00:100:64::3" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.CreateNodeACL(pgName, nodeIP, joinIP) + err = nbClient.CreateNodeACL(pgName, nodeIP, joinIP) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 4) @@ -434,22 +434,22 @@ func (suite *OvnClientTestSuite) testCreateSgDenyAllACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient sgName := "test_create_deny_all_acl_pg" pgName := GetSgPortGroupName(sgName) - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.CreateSgDenyAllACL(sgName) + err = nbClient.CreateSgDenyAllACL(sgName) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) // ingress acl match := fmt.Sprintf("outport == @%s && ip", pgName) - ingressACL, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, match, false) + ingressACL, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, match, false) require.NoError(t, err) expect := newACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, match, ovnnb.ACLActionDrop, util.NetpolACLTier) expect.UUID = ingressACL.UUID @@ -458,7 +458,7 @@ func (suite *OvnClientTestSuite) testCreateSgDenyAllACL() { // egress acl match = fmt.Sprintf("inport == @%s && ip", pgName) - egressACL, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupDropPriority, match, false) + egressACL, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupDropPriority, match, false) require.NoError(t, err) expect = newACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupDropPriority, match, ovnnb.ACLActionDrop, util.NetpolACLTier) expect.UUID = egressACL.UUID @@ -470,10 +470,10 @@ func (suite *OvnClientTestSuite) testCreateSgBaseACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient expect := func(pg *ovnnb.PortGroup, match, direction string) { - arpACL, err := ovnClient.GetACL(pg.Name, direction, util.SecurityGroupBasePriority, match, false) + arpACL, err := nbClient.GetACL(pg.Name, direction, util.SecurityGroupBasePriority, match, false) require.NoError(t, err) expect := newACL(pg.Name, direction, util.SecurityGroupBasePriority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier, func(acl *ovnnb.ACL) { @@ -491,14 +491,14 @@ func (suite *OvnClientTestSuite) testCreateSgBaseACL() { pgName := GetSgPortGroupName(sgName) portDirection := "outport" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) // ingress - err = ovnClient.CreateSgBaseACL(sgName, ovnnb.ACLDirectionToLport) + err = nbClient.CreateSgBaseACL(sgName, ovnnb.ACLDirectionToLport) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 5) @@ -530,14 +530,14 @@ func (suite *OvnClientTestSuite) testCreateSgBaseACL() { pgName := GetSgPortGroupName(sgName) portDirection := "inport" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) // egress - err = ovnClient.CreateSgBaseACL(sgName, ovnnb.ACLDirectionFromLport) + err = nbClient.CreateSgBaseACL(sgName, ovnnb.ACLDirectionFromLport) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 5) @@ -567,7 +567,7 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient sgName := "test_update_sg_acl_pg" v4AsName := GetSgV4AssociatedName(sgName) v6AsName := GetSgV6AssociatedName(sgName) @@ -602,19 +602,19 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { }, } - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) t.Run("update securityGroup ingress acl", func(t *testing.T) { - err = ovnClient.UpdateSgACL(sg, ovnnb.ACLDirectionToLport) + err = nbClient.UpdateSgACL(sg, ovnnb.ACLDirectionToLport) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) // ipv4 acl match := fmt.Sprintf("outport == @%s && ip4 && ip4.src == $%s", pgName, v4AsName) - v4Acl, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupAllowPriority, match, false) + v4Acl, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupAllowPriority, match, false) require.NoError(t, err) expect := newACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupAllowPriority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) expect.UUID = v4Acl.UUID @@ -623,7 +623,7 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { // ipv6 acl match = fmt.Sprintf("outport == @%s && ip6 && ip6.src == $%s", pgName, v6AsName) - v6Acl, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupAllowPriority, match, false) + v6Acl, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupAllowPriority, match, false) require.NoError(t, err) expect = newACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupAllowPriority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) expect.UUID = v6Acl.UUID @@ -632,7 +632,7 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { // rule acl match = fmt.Sprintf("outport == @%s && ip4 && ip4.src == 0.0.0.0/0 && icmp4", pgName) - rulACL, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, "2288", match, false) + rulACL, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, "2288", match, false) require.NoError(t, err) expect = newACL(pgName, ovnnb.ACLDirectionToLport, "2288", match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) expect.UUID = rulACL.UUID @@ -641,15 +641,15 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { }) t.Run("update securityGroup egress acl", func(t *testing.T) { - err = ovnClient.UpdateSgACL(sg, ovnnb.ACLDirectionFromLport) + err = nbClient.UpdateSgACL(sg, ovnnb.ACLDirectionFromLport) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) // ipv4 acl match := fmt.Sprintf("inport == @%s && ip4 && ip4.dst == $%s", pgName, v4AsName) - v4Acl, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupAllowPriority, match, false) + v4Acl, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupAllowPriority, match, false) require.NoError(t, err) expect := newACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupAllowPriority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) expect.UUID = v4Acl.UUID @@ -658,7 +658,7 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { // ipv6 acl match = fmt.Sprintf("inport == @%s && ip6 && ip6.dst == $%s", pgName, v6AsName) - v6Acl, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupAllowPriority, match, false) + v6Acl, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupAllowPriority, match, false) require.NoError(t, err) expect = newACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupAllowPriority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) expect.UUID = v6Acl.UUID @@ -667,7 +667,7 @@ func (suite *OvnClientTestSuite) testUpdateSgACL() { // rule acl match = fmt.Sprintf("inport == @%s && ip4 && ip4.dst == 0.0.0.0/0", pgName) - rulACL, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, "2290", match, false) + rulACL, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, "2290", match, false) require.NoError(t, err) expect = newACL(pgName, ovnnb.ACLDirectionFromLport, "2290", match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) expect.UUID = rulACL.UUID @@ -680,7 +680,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test_update_acl_ls" cidrBlock := "192.168.2.0/24,2409:8720:4a00::0/64" @@ -699,13 +699,13 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchACL() { }, } - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.UpdateLogicalSwitchACL(lsName, cidrBlock, subnetAcls, true) + err = nbClient.UpdateLogicalSwitchACL(lsName, cidrBlock, subnetAcls, true) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) for _, cidr := range strings.Split(cidrBlock, ",") { @@ -715,14 +715,14 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchACL() { if protocol == kubeovnv1.ProtocolIPv6 { match = "ip6.src == 2409:8720:4a00::0/64 && ip6.dst == 2409:8720:4a00::0/64" } - ingressACL, err := ovnClient.GetACL(lsName, ovnnb.ACLDirectionToLport, util.AllowEWTrafficPriority, match, false) + ingressACL, err := nbClient.GetACL(lsName, ovnnb.ACLDirectionToLport, util.AllowEWTrafficPriority, match, false) require.NoError(t, err) ingressExpect := newACL(lsName, ovnnb.ACLDirectionToLport, util.AllowEWTrafficPriority, match, ovnnb.ACLActionAllow, util.NetpolACLTier) ingressExpect.UUID = ingressACL.UUID ingressExpect.ExternalIDs["subnet"] = lsName require.Equal(t, ingressExpect, ingressACL) require.Contains(t, ls.ACLs, ingressACL.UUID) - egressACL, err := ovnClient.GetACL(lsName, ovnnb.ACLDirectionFromLport, util.AllowEWTrafficPriority, match, false) + egressACL, err := nbClient.GetACL(lsName, ovnnb.ACLDirectionFromLport, util.AllowEWTrafficPriority, match, false) require.NoError(t, err) egressExpect := newACL(lsName, ovnnb.ACLDirectionFromLport, util.AllowEWTrafficPriority, match, ovnnb.ACLActionAllow, util.NetpolACLTier) egressExpect.UUID = egressACL.UUID @@ -732,7 +732,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchACL() { } for _, subnetACL := range subnetAcls { - acl, err := ovnClient.GetACL(lsName, subnetACL.Direction, strconv.Itoa(subnetACL.Priority), subnetACL.Match, false) + acl, err := nbClient.GetACL(lsName, subnetACL.Direction, strconv.Itoa(subnetACL.Priority), subnetACL.Match, false) require.NoError(t, err) expect := newACL(lsName, subnetACL.Direction, strconv.Itoa(subnetACL.Priority), subnetACL.Match, subnetACL.Action, util.NetpolACLTier) expect.UUID = acl.UUID @@ -746,10 +746,10 @@ func (suite *OvnClientTestSuite) testSetACLLog() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := GetSgPortGroupName("test_set_acl_log") - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) t.Run("set ingress acl log to false", func(t *testing.T) { @@ -760,13 +760,13 @@ func (suite *OvnClientTestSuite) testSetACLLog() { acl.Severity = &ovnnb.ACLSeverityWarning }) - err = ovnClient.CreateAcls(pgName, portGroupKey, acl) + err = nbClient.CreateAcls(pgName, portGroupKey, acl) require.NoError(t, err) - err = ovnClient.SetACLLog(pgName, false, true) + err = nbClient.SetACLLog(pgName, false, true) require.NoError(t, err) - acl, err = ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.IngressDefaultDrop, match, false) + acl, err = nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.IngressDefaultDrop, match, false) require.NoError(t, err) require.False(t, acl.Log) }) @@ -779,13 +779,13 @@ func (suite *OvnClientTestSuite) testSetACLLog() { acl.Severity = &ovnnb.ACLSeverityWarning }) - err = ovnClient.CreateAcls(pgName, portGroupKey, acl) + err = nbClient.CreateAcls(pgName, portGroupKey, acl) require.NoError(t, err) - err = ovnClient.SetACLLog(pgName, true, false) + err = nbClient.SetACLLog(pgName, true, false) require.NoError(t, err) - acl, err = ovnClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.IngressDefaultDrop, match, false) + acl, err = nbClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.IngressDefaultDrop, match, false) require.NoError(t, err) require.True(t, acl.Log) }) @@ -795,7 +795,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient nodeSwitchCidrBlock := "100.64.0.0/16,fd00:100:64::/112" cidrBlock := "10.244.0.0/16,fc00::af4:0/112" @@ -811,19 +811,19 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { t.Parallel() lsName := "test_set_private_ls_dual" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCidrBlock, allowSubnets) + err = nbClient.SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCidrBlock, allowSubnets) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Len(t, ls.ACLs, 9) // default drop acl match := "ip" - acl, err := ovnClient.GetACL(lsName, direction, util.DefaultDropPriority, match, false) + acl, err := nbClient.GetACL(lsName, direction, util.DefaultDropPriority, match, false) require.NoError(t, err) require.Contains(t, ls.ACLs, acl.UUID) @@ -836,7 +836,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { match = fmt.Sprintf(`ip6.src == %s && ip6.dst == %s`, cidr, cidr) } - acl, err = ovnClient.GetACL(lsName, direction, util.SubnetAllowPriority, match, false) + acl, err = nbClient.GetACL(lsName, direction, util.SubnetAllowPriority, match, false) require.NoError(t, err) require.Contains(t, ls.ACLs, acl.UUID) @@ -854,7 +854,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { match = fmt.Sprintf("(ip6.src == %s && ip6.dst == %s) || (ip6.src == %s && ip6.dst == %s)", cidr, subnet, subnet, cidr) } - acl, err = ovnClient.GetACL(lsName, direction, util.SubnetAllowPriority, match, false) + acl, err = nbClient.GetACL(lsName, direction, util.SubnetAllowPriority, match, false) require.NoError(t, err) require.Contains(t, ls.ACLs, acl.UUID) } @@ -869,7 +869,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { match = fmt.Sprintf(`ip6.src == %s`, cidr) } - acl, err = ovnClient.GetACL(lsName, direction, util.NodeAllowPriority, match, false) + acl, err = nbClient.GetACL(lsName, direction, util.NodeAllowPriority, match, false) require.NoError(t, err) require.Contains(t, ls.ACLs, acl.UUID) } @@ -879,20 +879,20 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { t.Parallel() lsName := "test_set_private_ls_v4" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) cidrBlock := "10.244.0.0/16" - err = ovnClient.SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCidrBlock, allowSubnets) + err = nbClient.SetLogicalSwitchPrivate(lsName, cidrBlock, nodeSwitchCidrBlock, allowSubnets) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Len(t, ls.ACLs, 5) // default drop acl match := "ip" - acl, err := ovnClient.GetACL(lsName, direction, util.DefaultDropPriority, match, false) + acl, err := nbClient.GetACL(lsName, direction, util.DefaultDropPriority, match, false) require.NoError(t, err) require.Contains(t, ls.ACLs, acl.UUID) @@ -905,7 +905,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { match = fmt.Sprintf(`ip6.src == %s && ip6.dst == %s`, cidr, cidr) } - acl, err = ovnClient.GetACL(lsName, direction, util.SubnetAllowPriority, match, false) + acl, err = nbClient.GetACL(lsName, direction, util.SubnetAllowPriority, match, false) require.NoError(t, err) require.Contains(t, ls.ACLs, acl.UUID) @@ -923,7 +923,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { match = fmt.Sprintf("(ip6.src == %s && ip6.dst == %s) || (ip6.src == %s && ip6.dst == %s)", cidr, subnet, subnet, cidr) } - acl, err = ovnClient.GetACL(lsName, direction, util.SubnetAllowPriority, match, false) + acl, err = nbClient.GetACL(lsName, direction, util.SubnetAllowPriority, match, false) require.NoError(t, err) require.Contains(t, ls.ACLs, acl.UUID) } @@ -938,7 +938,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPrivate() { match = fmt.Sprintf(`ip6.src == %s`, cidr) } - acl, err = ovnClient.GetACL(lsName, direction, util.NodeAllowPriority, match, false) + acl, err = nbClient.GetACL(lsName, direction, util.NodeAllowPriority, match, false) if protocol == kubeovnv1.ProtocolIPv4 { require.NoError(t, err) require.Contains(t, ls.ACLs, acl.UUID) @@ -953,7 +953,7 @@ func (suite *OvnClientTestSuite) testNewSgRuleACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient sgName := "test_create_sg_acl_pg" pgName := GetSgPortGroupName(sgName) highestPriority, _ := strconv.Atoi(util.SecurityGroupHighestPriority) @@ -971,7 +971,7 @@ func (suite *OvnClientTestSuite) testNewSgRuleACL() { } priority := strconv.Itoa(highestPriority - sgRule.Priority) - acl, err := ovnClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) + acl, err := nbClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) require.NoError(t, err) match := fmt.Sprintf("outport == @%s && ip4 && ip4.src == $%s && icmp4", pgName, GetSgV4AssociatedName(sgRule.RemoteSecurityGroup)) @@ -993,7 +993,7 @@ func (suite *OvnClientTestSuite) testNewSgRuleACL() { } priority := strconv.Itoa(highestPriority - sgRule.Priority) - acl, err := ovnClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) + acl, err := nbClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) require.NoError(t, err) match := fmt.Sprintf("outport == @%s && ip4 && ip4.src == %s && icmp4", pgName, sgRule.RemoteAddress) @@ -1015,7 +1015,7 @@ func (suite *OvnClientTestSuite) testNewSgRuleACL() { } priority := strconv.Itoa(highestPriority - sgRule.Priority) - acl, err := ovnClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) + acl, err := nbClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) require.NoError(t, err) match := fmt.Sprintf("outport == @%s && ip6 && ip6.src == %s && icmp6", pgName, sgRule.RemoteAddress) @@ -1037,7 +1037,7 @@ func (suite *OvnClientTestSuite) testNewSgRuleACL() { } priority := strconv.Itoa(highestPriority - sgRule.Priority) - acl, err := ovnClient.newSgRuleACL(sgName, ovnnb.ACLDirectionFromLport, sgRule) + acl, err := nbClient.newSgRuleACL(sgName, ovnnb.ACLDirectionFromLport, sgRule) require.NoError(t, err) match := fmt.Sprintf("inport == @%s && ip4 && ip4.dst == %s && icmp4", pgName, sgRule.RemoteAddress) @@ -1059,7 +1059,7 @@ func (suite *OvnClientTestSuite) testNewSgRuleACL() { } priority := strconv.Itoa(highestPriority - sgRule.Priority) - acl, err := ovnClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) + acl, err := nbClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) require.NoError(t, err) match := fmt.Sprintf("outport == @%s && ip4 && ip4.src == %s && icmp4", pgName, sgRule.RemoteAddress) @@ -1083,7 +1083,7 @@ func (suite *OvnClientTestSuite) testNewSgRuleACL() { } priority := strconv.Itoa(highestPriority - sgRule.Priority) - acl, err := ovnClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) + acl, err := nbClient.newSgRuleACL(sgName, ovnnb.ACLDirectionToLport, sgRule) require.NoError(t, err) match := fmt.Sprintf("outport == @%s && ip4 && ip4.src == %s && %d <= tcp.dst <= %d", pgName, sgRule.RemoteAddress, sgRule.PortRangeMin, sgRule.PortRangeMax) @@ -1097,7 +1097,7 @@ func (suite *OvnClientTestSuite) testCreateAcls() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-create-acls-pg" priority := "5000" basePort := 12300 @@ -1105,25 +1105,25 @@ func (suite *OvnClientTestSuite) testCreateAcls() { acls := make([]*ovnnb.ACL, 0, 3) t.Run("add acl to port group", func(t *testing.T) { - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } - err = ovnClient.CreateAcls(pgName, portGroupKey, append(acls, nil)...) + err = nbClient.CreateAcls(pgName, portGroupKey, append(acls, nil)...) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, priority, match, false) + acl, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, priority, match, false) require.NoError(t, err) require.Equal(t, match, acl.Match) @@ -1133,25 +1133,25 @@ func (suite *OvnClientTestSuite) testCreateAcls() { t.Run("add acl to logical switch", func(t *testing.T) { lsName := "test-create-acls-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && udp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } - err = ovnClient.CreateAcls(lsName, logicalSwitchKey, append(acls, nil)...) + err = nbClient.CreateAcls(lsName, logicalSwitchKey, append(acls, nil)...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && udp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.GetACL(lsName, ovnnb.ACLDirectionToLport, priority, match, false) + acl, err := nbClient.GetACL(lsName, ovnnb.ACLDirectionToLport, priority, match, false) require.NoError(t, err) require.Equal(t, match, acl.Match) @@ -1160,10 +1160,10 @@ func (suite *OvnClientTestSuite) testCreateAcls() { }) t.Run("acl parent type is wrong", func(t *testing.T) { - err := ovnClient.CreateAcls(pgName, "", nil) + err := nbClient.CreateAcls(pgName, "", nil) require.ErrorContains(t, err, "acl parent type must be 'pg' or 'ls'") - err = ovnClient.CreateAcls(pgName, "wrong_key", nil) + err = nbClient.CreateAcls(pgName, "wrong_key", nil) require.ErrorContains(t, err, "acl parent type must be 'pg' or 'ls'") }) } @@ -1172,15 +1172,15 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-del-acls-pg" lsName := "test-del-acls-ls" matchPrefix := "outport == @ovn.sg.test_del_acl_pg && ip" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitch(lsName) + err = nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("delete all direction acls from port group", func(t *testing.T) { @@ -1191,7 +1191,7 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // to-lport for i := 0; i < 2; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } @@ -1199,22 +1199,22 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // from-lport for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionFromLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionFromLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } - err = ovnClient.CreateAcls(pgName, portGroupKey, acls...) + err = nbClient.CreateAcls(pgName, portGroupKey, acls...) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 5) - err = ovnClient.DeleteAcls(pgName, portGroupKey, "", nil) + err = nbClient.DeleteAcls(pgName, portGroupKey, "", nil) require.NoError(t, err) - pg, err = ovnClient.GetPortGroup(pgName, false) + pg, err = nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, pg.ACLs) }) @@ -1227,7 +1227,7 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // to-lport for i := 0; i < 2; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } @@ -1235,31 +1235,31 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // from-lport for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionFromLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionFromLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } - err = ovnClient.CreateAcls(pgName, portGroupKey, acls...) + err = nbClient.CreateAcls(pgName, portGroupKey, acls...) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 5) /* delete to-lport direction acl */ - err = ovnClient.DeleteAcls(pgName, portGroupKey, ovnnb.ACLDirectionToLport, nil) + err = nbClient.DeleteAcls(pgName, portGroupKey, ovnnb.ACLDirectionToLport, nil) require.NoError(t, err) - pg, err = ovnClient.GetPortGroup(pgName, false) + pg, err = nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 3) /* delete from-lport direction acl */ - err = ovnClient.DeleteAcls(pgName, portGroupKey, ovnnb.ACLDirectionFromLport, nil) + err = nbClient.DeleteAcls(pgName, portGroupKey, ovnnb.ACLDirectionFromLport, nil) require.NoError(t, err) - pg, err = ovnClient.GetPortGroup(pgName, false) + pg, err = nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, pg.ACLs) }) @@ -1272,7 +1272,7 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // to-lport for i := 0; i < 2; i++ { match := fmt.Sprintf("%s && udp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } @@ -1280,22 +1280,22 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // from-lport for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && udp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(lsName, ovnnb.ACLDirectionFromLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(lsName, ovnnb.ACLDirectionFromLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } - err = ovnClient.CreateAcls(lsName, logicalSwitchKey, acls...) + err = nbClient.CreateAcls(lsName, logicalSwitchKey, acls...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Len(t, ls.ACLs, 5) - err = ovnClient.DeleteAcls(lsName, logicalSwitchKey, "", nil) + err = nbClient.DeleteAcls(lsName, logicalSwitchKey, "", nil) require.NoError(t, err) - ls, err = ovnClient.GetLogicalSwitch(lsName, false) + ls, err = nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Empty(t, ls.ACLs) }) @@ -1308,7 +1308,7 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // to-lport for i := 0; i < 2; i++ { match := fmt.Sprintf("%s && udp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } @@ -1316,31 +1316,31 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // from-lport for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && udp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(lsName, ovnnb.ACLDirectionFromLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(lsName, ovnnb.ACLDirectionFromLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) acls = append(acls, acl) } - err = ovnClient.CreateAcls(lsName, logicalSwitchKey, acls...) + err = nbClient.CreateAcls(lsName, logicalSwitchKey, acls...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Len(t, ls.ACLs, 5) /* delete to-lport direction acl */ - err = ovnClient.DeleteAcls(lsName, logicalSwitchKey, ovnnb.ACLDirectionToLport, nil) + err = nbClient.DeleteAcls(lsName, logicalSwitchKey, ovnnb.ACLDirectionToLport, nil) require.NoError(t, err) - ls, err = ovnClient.GetLogicalSwitch(lsName, false) + ls, err = nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Len(t, ls.ACLs, 3) /* delete from-lport direction acl */ - err = ovnClient.DeleteAcls(lsName, logicalSwitchKey, ovnnb.ACLDirectionFromLport, nil) + err = nbClient.DeleteAcls(lsName, logicalSwitchKey, ovnnb.ACLDirectionFromLport, nil) require.NoError(t, err) - ls, err = ovnClient.GetLogicalSwitch(lsName, false) + ls, err = nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Empty(t, ls.ACLs) }) @@ -1353,7 +1353,7 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { // to-lport match := fmt.Sprintf("%s && udp.dst == %d", matchPrefix, basePort) - acl, err := ovnClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier, func(acl *ovnnb.ACL) { + acl, err := nbClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier, func(acl *ovnnb.ACL) { if acl.ExternalIDs == nil { acl.ExternalIDs = make(map[string]string) } @@ -1362,22 +1362,22 @@ func (suite *OvnClientTestSuite) testDeleteAcls() { require.NoError(t, err) acls = append(acls, acl) - err = ovnClient.CreateAcls(lsName, logicalSwitchKey, acls...) + err = nbClient.CreateAcls(lsName, logicalSwitchKey, acls...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Len(t, ls.ACLs, 1) newACL := &ovnnb.ACL{UUID: ls.ACLs[0]} - err = ovnClient.GetEntityInfo(newACL) + err = nbClient.GetEntityInfo(newACL) require.NoError(t, err) /* delete to-lport direction acl */ - err = ovnClient.DeleteAcls(lsName, logicalSwitchKey, ovnnb.ACLDirectionToLport, map[string]string{"subnet": lsName}) + err = nbClient.DeleteAcls(lsName, logicalSwitchKey, ovnnb.ACLDirectionToLport, map[string]string{"subnet": lsName}) require.NoError(t, err) - ls, err = ovnClient.GetLogicalSwitch(lsName, false) + ls, err = nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Empty(t, ls.ACLs) }) @@ -1387,15 +1387,15 @@ func (suite *OvnClientTestSuite) testDeleteACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-del-acl-pg" lsName := "test-del-acl-ls" matchPrefix := "outport == @ovn.sg.test_del_acl_pg && ip" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitch(lsName) + err = nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("delete acl from port group", func(t *testing.T) { @@ -1403,20 +1403,20 @@ func (suite *OvnClientTestSuite) testDeleteACL() { basePort := 5601 match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, acl) + err = nbClient.CreateAcls(pgName, portGroupKey, acl) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.ACLs, 1) - err = ovnClient.DeleteACL(pgName, portGroupKey, ovnnb.ACLDirectionToLport, priority, match) + err = nbClient.DeleteACL(pgName, portGroupKey, ovnnb.ACLDirectionToLport, priority, match) require.NoError(t, err) - pg, err = ovnClient.GetPortGroup(pgName, false) + pg, err = nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, pg.ACLs) }) @@ -1426,20 +1426,20 @@ func (suite *OvnClientTestSuite) testDeleteACL() { basePort := 5601 match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort) - acl, err := ovnClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(lsName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(lsName, logicalSwitchKey, acl) + err = nbClient.CreateAcls(lsName, logicalSwitchKey, acl) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Len(t, ls.ACLs, 1) - err = ovnClient.DeleteACL(lsName, logicalSwitchKey, ovnnb.ACLDirectionToLport, priority, match) + err = nbClient.DeleteACL(lsName, logicalSwitchKey, ovnnb.ACLDirectionToLport, priority, match) require.NoError(t, err) - ls, err = ovnClient.GetLogicalSwitch(lsName, false) + ls, err = nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Empty(t, ls.ACLs) }) @@ -1449,23 +1449,23 @@ func (suite *OvnClientTestSuite) testGetACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test_get_acl_pg" priority := "2000" match := "ip4.dst == 100.64.0.0/16" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, acl) + err = nbClient.CreateAcls(pgName, portGroupKey, acl) require.NoError(t, err) t.Run("direction, priority and match are same", func(t *testing.T) { t.Parallel() - acl, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, priority, match, false) + acl, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, priority, match, false) require.NoError(t, err) require.Equal(t, ovnnb.ACLDirectionToLport, acl.Direction) require.Equal(t, 2000, acl.Priority) @@ -1476,27 +1476,27 @@ func (suite *OvnClientTestSuite) testGetACL() { t.Run("direction, priority and match are not all same", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, priority, match, false) + _, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, priority, match, false) require.ErrorContains(t, err, "not found acl") - _, err = ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, "1010", match, false) + _, err = nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, "1010", match, false) require.ErrorContains(t, err, "not found acl") - _, err = ovnClient.GetACL(pgName, ovnnb.ACLDirectionToLport, priority, match+" && tcp", false) + _, err = nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, priority, match+" && tcp", false) require.ErrorContains(t, err, "not found acl") }) t.Run("should no err when direction, priority and match are not all same but ignoreNotFound=true", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, priority, match, true) + _, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, priority, match, true) require.NoError(t, err) }) t.Run("no acl belongs to parent exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetACL(pgName+"_1", ovnnb.ACLDirectionFromLport, priority, match, false) + _, err := nbClient.GetACL(pgName+"_1", ovnnb.ACLDirectionFromLport, priority, match, false) require.ErrorContains(t, err, "not found acl") }) } @@ -1505,36 +1505,36 @@ func (suite *OvnClientTestSuite) testListAcls() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-list-acl-pg" basePort := 50000 - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) matchPrefix := "outport == @ovn.sg.test_list_acl_pg && ip" // create two to-lport acl for i := 0; i < 2; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, "9999", match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, "9999", match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, acl) + err = nbClient.CreateAcls(pgName, portGroupKey, acl) require.NoError(t, err) } // create two from-lport acl for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionFromLport, "9999", match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionFromLport, "9999", match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, acl) + err = nbClient.CreateAcls(pgName, portGroupKey, acl) require.NoError(t, err) } /* list all direction acl */ - out, err := ovnClient.ListAcls("", nil) + out, err := nbClient.ListAcls("", nil) require.NoError(t, err) count := 0 for _, v := range out { @@ -1549,7 +1549,7 @@ func (suite *OvnClientTestSuite) testNewACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-new-acl-pg" priority := "1000" match := "outport==@ovn.sg.test_create_acl_pg && ip" @@ -1573,7 +1573,7 @@ func (suite *OvnClientTestSuite) testNewACL() { Tier: util.NetpolACLTier, } - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier, options) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier, options) require.NoError(t, err) expect.UUID = acl.UUID require.Equal(t, expect, acl) @@ -1815,11 +1815,11 @@ func (suite *OvnClientTestSuite) testSgRuleNoACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient sgName := "test-sg" pgName := GetSgPortGroupName(sgName) - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) t.Run("ipv4 ingress rule", func(t *testing.T) { @@ -1832,7 +1832,7 @@ func (suite *OvnClientTestSuite) testSgRuleNoACL() { PortRangeMax: 80, Priority: 200, } - noACL, err := ovnClient.sgRuleNoACL(sgName, ovnnb.ACLDirectionToLport, rule) + noACL, err := nbClient.sgRuleNoACL(sgName, ovnnb.ACLDirectionToLport, rule) require.NoError(t, err) require.True(t, noACL) }) @@ -1847,7 +1847,7 @@ func (suite *OvnClientTestSuite) testSgRuleNoACL() { PortRangeMax: 53, Priority: 199, } - noACL, err := ovnClient.sgRuleNoACL(sgName, ovnnb.ACLDirectionFromLport, rule) + noACL, err := nbClient.sgRuleNoACL(sgName, ovnnb.ACLDirectionFromLport, rule) require.NoError(t, err) require.True(t, noACL) }) @@ -1860,7 +1860,7 @@ func (suite *OvnClientTestSuite) testSgRuleNoACL() { RemoteAddress: "10.0.0.0/8", Priority: 198, } - noACL, err := ovnClient.sgRuleNoACL(sgName, ovnnb.ACLDirectionToLport, rule) + noACL, err := nbClient.sgRuleNoACL(sgName, ovnnb.ACLDirectionToLport, rule) require.NoError(t, err) require.True(t, noACL) }) @@ -1879,12 +1879,12 @@ func (suite *OvnClientTestSuite) testSgRuleNoACL() { match := fmt.Sprintf("inport == @%s && ip4 && ip4.dst == 172.16.0.0/16 && 443 <= tcp.dst <= 443", pgName) securityGroupHighestPriority, _ := strconv.Atoi(util.SecurityGroupHighestPriority) priority := securityGroupHighestPriority - rule.Priority - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionFromLport, strconv.Itoa(priority), match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionFromLport, strconv.Itoa(priority), match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, acl) + err = nbClient.CreateAcls(pgName, portGroupKey, acl) require.NoError(t, err) - noACL, err := ovnClient.sgRuleNoACL(sgName, ovnnb.ACLDirectionFromLport, rule) + noACL, err := nbClient.sgRuleNoACL(sgName, ovnnb.ACLDirectionFromLport, rule) require.NoError(t, err) require.False(t, noACL) }) @@ -1894,7 +1894,7 @@ func (suite *OvnClientTestSuite) testSGLostACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("no lost ACLs", func(t *testing.T) { t.Parallel() @@ -1931,20 +1931,20 @@ func (suite *OvnClientTestSuite) testSGLostACL() { } pgName := GetSgPortGroupName(sg.Name) - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - ingressACL, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, "2299", "outport == @ovn.sg.test.sg.no.lost.acl && ip4 && ip4.src == 192.168.0.0/24 && 80 <= tcp.dst <= 80", ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + ingressACL, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, "2299", "outport == @ovn.sg.test.sg.no.lost.acl && ip4 && ip4.src == 192.168.0.0/24 && 80 <= tcp.dst <= 80", ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, ingressACL) + err = nbClient.CreateAcls(pgName, portGroupKey, ingressACL) require.NoError(t, err) - egressACL, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionFromLport, "2299", "inport == @ovn.sg.test.sg.no.lost.acl && ip6 && ip6.dst == fd00::/64 && 53 <= udp.dst <= 53", ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + egressACL, err := nbClient.newACL(pgName, ovnnb.ACLDirectionFromLport, "2299", "inport == @ovn.sg.test.sg.no.lost.acl && ip6 && ip6.dst == fd00::/64 && 53 <= udp.dst <= 53", ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, egressACL) + err = nbClient.CreateAcls(pgName, portGroupKey, egressACL) require.NoError(t, err) - lost, err := ovnClient.SGLostACL(sg) + lost, err := nbClient.SGLostACL(sg) require.NoError(t, err) require.False(t, lost) }) @@ -1984,15 +1984,15 @@ func (suite *OvnClientTestSuite) testSGLostACL() { } pgName := GetSgPortGroupName(sg.Name) - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - egressACL, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionFromLport, "2299", "inport == @ovn.sg.test.sg.lost.ingress.acl && ip6 && ip6.dst == fd00::/64 && 53 <= udp.dst <= 53", ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + egressACL, err := nbClient.newACL(pgName, ovnnb.ACLDirectionFromLport, "2299", "inport == @ovn.sg.test.sg.lost.ingress.acl && ip6 && ip6.dst == fd00::/64 && 53 <= udp.dst <= 53", ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, egressACL) + err = nbClient.CreateAcls(pgName, portGroupKey, egressACL) require.NoError(t, err) - lost, err := ovnClient.SGLostACL(sg) + lost, err := nbClient.SGLostACL(sg) require.NoError(t, err) require.True(t, lost) }) @@ -2032,15 +2032,15 @@ func (suite *OvnClientTestSuite) testSGLostACL() { } pgName := GetSgPortGroupName(sg.Name) - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - ingressACL, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, "2299", "outport == @ovn.sg.test.sg.lost.egress.acl && ip4 && ip4.src == 192.168.0.0/24 && 80 <= tcp.dst <= 80", ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + ingressACL, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, "2299", "outport == @ovn.sg.test.sg.lost.egress.acl && ip4 && ip4.src == 192.168.0.0/24 && 80 <= tcp.dst <= 80", ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, ingressACL) + err = nbClient.CreateAcls(pgName, portGroupKey, ingressACL) require.NoError(t, err) - lost, err := ovnClient.SGLostACL(sg) + lost, err := nbClient.SGLostACL(sg) require.NoError(t, err) require.True(t, lost) }) @@ -2058,10 +2058,10 @@ func (suite *OvnClientTestSuite) testSGLostACL() { } pgName := GetSgPortGroupName(sg.Name) - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - lost, err := ovnClient.SGLostACL(sg) + lost, err := nbClient.SGLostACL(sg) require.NoError(t, err) require.False(t, lost) }) @@ -2171,15 +2171,15 @@ func (suite *OvnClientTestSuite) testCreateBareACL() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("create bare ACL successfully", func(t *testing.T) { - err := ovnClient.CreateBareACL("test-parent", "from-lport", "1000", "ip4.src == 10.0.0.1", "allow") + err := nbClient.CreateBareACL("test-parent", "from-lport", "1000", "ip4.src == 10.0.0.1", "allow") require.NoError(t, err) }) t.Run("create bare ACL with empty match", func(t *testing.T) { - err := ovnClient.CreateBareACL("test-parent", "from-lport", "1000", "", "allow") + err := nbClient.CreateBareACL("test-parent", "from-lport", "1000", "", "allow") require.Error(t, err) require.Contains(t, err.Error(), "new acl direction from-lport priority 1000 match") }) @@ -2189,7 +2189,7 @@ func (suite *OvnClientTestSuite) testUpdateAnpRuleACLOps() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient expect := func(row ovsdb.Row, action, direction, match, priority string) { intPriority, err := strconv.Atoi(priority) @@ -2212,9 +2212,9 @@ func (suite *OvnClientTestSuite) testUpdateAnpRuleACLOps() { isIngress := true isBanp := false - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - ops, err := ovnClient.UpdateAnpRuleACLOps(pgName, asName, protocol, aclName, priority, aclAction, logACLActions, rulePorts, isIngress, isBanp) + ops, err := nbClient.UpdateAnpRuleACLOps(pgName, asName, protocol, aclName, priority, aclAction, logACLActions, rulePorts, isIngress, isBanp) require.NoError(t, err) require.NotEmpty(t, ops) expect(ops[0].Row, ovnnb.ACLActionAllow, ovnnb.ACLDirectionToLport, fmt.Sprintf("outport == @%s && ip && ip4.src == $%s", pgName, asName), "1000") @@ -2232,9 +2232,9 @@ func (suite *OvnClientTestSuite) testUpdateAnpRuleACLOps() { isIngress := false isBanp := true - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - ops, err := ovnClient.UpdateAnpRuleACLOps(pgName, asName, protocol, aclName, priority, aclAction, logACLActions, rulePorts, isIngress, isBanp) + ops, err := nbClient.UpdateAnpRuleACLOps(pgName, asName, protocol, aclName, priority, aclAction, logACLActions, rulePorts, isIngress, isBanp) require.NoError(t, err) require.NotEmpty(t, ops) expect(ops[0].Row, ovnnb.ACLActionDrop, ovnnb.ACLDirectionFromLport, fmt.Sprintf("inport == @%s && ip && ip4.dst == $%s", pgName, asName), "2000") @@ -2244,10 +2244,10 @@ func (suite *OvnClientTestSuite) testUpdateAnpRuleACLOps() { func (suite *OvnClientTestSuite) testUpdateACL() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("update ACL with nil input", func(t *testing.T) { - err := ovnClient.UpdateACL(nil) + err := nbClient.UpdateACL(nil) require.Error(t, err) require.Contains(t, err.Error(), "address_set is nil") }) diff --git a/pkg/ovs/ovn-nb-address_set_test.go b/pkg/ovs/ovn-nb-address_set_test.go index 3c28ab000b8..bb73d045945 100644 --- a/pkg/ovs/ovn-nb-address_set_test.go +++ b/pkg/ovs/ovn-nb-address_set_test.go @@ -20,16 +20,16 @@ func (suite *OvnClientTestSuite) testCreateAddressSet() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient asName := "test_create_as" t.Run("create address set", func(t *testing.T) { - err := ovnClient.CreateAddressSet(asName, map[string]string{ + err := nbClient.CreateAddressSet(asName, map[string]string{ sgKey: "test-sg", }) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.NotEmpty(t, as.UUID) require.Equal(t, asName, as.Name) @@ -39,7 +39,7 @@ func (suite *OvnClientTestSuite) testCreateAddressSet() { }) t.Run("error occur because of invalid address set name", func(t *testing.T) { - err := ovnClient.CreateAddressSet("test-create-as", map[string]string{ + err := nbClient.CreateAddressSet("test-create-as", map[string]string{ sgKey: "test-sg", }) require.Error(t, err) @@ -47,15 +47,15 @@ func (suite *OvnClientTestSuite) testCreateAddressSet() { t.Run("create address set that already exists", func(t *testing.T) { asName := "existing_address_set" - err := ovnClient.CreateAddressSet(asName, nil) + err := nbClient.CreateAddressSet(asName, nil) require.NoError(t, err) // Attempt to create the same address set again - err = ovnClient.CreateAddressSet(asName, nil) + err = nbClient.CreateAddressSet(asName, nil) require.NoError(t, err) // Verify that only one address set exists - ass, err := ovnClient.ListAddressSets(nil) + ass, err := nbClient.ListAddressSets(nil) require.NoError(t, err) count := 0 for _, as := range ass { @@ -71,95 +71,95 @@ func (suite *OvnClientTestSuite) testAddressSetUpdateAddress() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient asName := "test_update_address_as" addresses := []string{"1.2.3.4", "1.2.3.6", "1.2.3.7"} - err := ovnClient.CreateAddressSet(asName, map[string]string{ + err := nbClient.CreateAddressSet(asName, map[string]string{ sgKey: "test-sg", }) require.NoError(t, err) t.Run("update address set v4 addresses", func(t *testing.T) { - err = ovnClient.AddressSetUpdateAddress(asName, addresses...) + err = nbClient.AddressSetUpdateAddress(asName, addresses...) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.ElementsMatch(t, addresses, as.Addresses) }) t.Run("update address set v6 addresses", func(t *testing.T) { addresses := []string{"fe80::20c:29ff:fee4:16cc", "fe80::20c:29ff:fee4:1611"} - err = ovnClient.AddressSetUpdateAddress(asName, addresses...) + err = nbClient.AddressSetUpdateAddress(asName, addresses...) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.ElementsMatch(t, addresses, as.Addresses) }) t.Run("clear address set addresses", func(t *testing.T) { - err = ovnClient.AddressSetUpdateAddress(asName) + err = nbClient.AddressSetUpdateAddress(asName) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.Empty(t, as.Addresses) }) t.Run("update with mixed IPv4 and IPv6 addresses", func(t *testing.T) { addresses := []string{"192.168.1.1", "2001:db8::1", "10.0.0.1", "fe80::1"} - err := ovnClient.AddressSetUpdateAddress(asName, addresses...) + err := nbClient.AddressSetUpdateAddress(asName, addresses...) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.ElementsMatch(t, addresses, as.Addresses) }) t.Run("update with CIDR notation", func(t *testing.T) { addresses := []string{"192.168.1.0/24", "2001:db8::/64"} - err := ovnClient.AddressSetUpdateAddress(asName, addresses...) + err := nbClient.AddressSetUpdateAddress(asName, addresses...) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"192.168.1.0/24", "2001:db8::/64"}, as.Addresses) }) t.Run("update with duplicate addresses", func(t *testing.T) { addresses := []string{"192.168.1.1", "192.168.1.1", "2001:db8::1", "2001:db8::1"} - err := ovnClient.AddressSetUpdateAddress(asName, addresses...) + err := nbClient.AddressSetUpdateAddress(asName, addresses...) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"192.168.1.1", "2001:db8::1"}, as.Addresses) }) t.Run("update with invalid CIDR", func(t *testing.T) { addresses := []string{"192.168.1.1", "invalid_cidr", "2001:db8::1"} - err := ovnClient.AddressSetUpdateAddress(asName, addresses...) + err := nbClient.AddressSetUpdateAddress(asName, addresses...) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"192.168.1.1", "invalid_cidr", "2001:db8::1"}, as.Addresses) }) t.Run("update with empty address list", func(t *testing.T) { - err := ovnClient.AddressSetUpdateAddress(asName) + err := nbClient.AddressSetUpdateAddress(asName) require.NoError(t, err) - as, err := ovnClient.GetAddressSet(asName, false) + as, err := nbClient.GetAddressSet(asName, false) require.NoError(t, err) require.Empty(t, as.Addresses) }) t.Run("update non-existent address set", func(t *testing.T) { nonExistentAS := "non_existent_as" - err := ovnClient.AddressSetUpdateAddress(nonExistentAS, "192.168.1.1") + err := nbClient.AddressSetUpdateAddress(nonExistentAS, "192.168.1.1") require.Error(t, err) require.Contains(t, err.Error(), "get address set") }) @@ -169,25 +169,25 @@ func (suite *OvnClientTestSuite) testDeleteAddressSet() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient asName := "test_delete_as" t.Run("no err when delete existent address set", func(t *testing.T) { t.Parallel() - err := ovnClient.CreateAddressSet(asName, nil) + err := nbClient.CreateAddressSet(asName, nil) require.NoError(t, err) - err = ovnClient.DeleteAddressSet(asName) + err = nbClient.DeleteAddressSet(asName) require.NoError(t, err) - _, err = ovnClient.GetAddressSet(asName, false) + _, err = nbClient.GetAddressSet(asName, false) require.ErrorContains(t, err, "object not found") }) t.Run("no err when delete non-existent logical router", func(t *testing.T) { t.Parallel() - err := ovnClient.DeleteAddressSet("test-delete-as-non-existent") + err := nbClient.DeleteAddressSet("test-delete-as-non-existent") require.NoError(t, err) }) } @@ -196,36 +196,36 @@ func (suite *OvnClientTestSuite) testDeleteAddressSets() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-del-ass-pg" asPrefix := "test_del_ass" externalIDs := map[string]string{sgKey: pgName} for i := 0; i < 3; i++ { asName := fmt.Sprintf("%s_%d", asPrefix, i) - err := ovnClient.CreateAddressSet(asName, externalIDs) + err := nbClient.CreateAddressSet(asName, externalIDs) require.NoError(t, err) } // create a new address set with no sg name, it should't be deleted asName := fmt.Sprintf("%s_%d", asPrefix, 3) - err := ovnClient.CreateAddressSet(asName, nil) + err := nbClient.CreateAddressSet(asName, nil) require.NoError(t, err) - err = ovnClient.DeleteAddressSets(externalIDs) + err = nbClient.DeleteAddressSets(externalIDs) require.NoError(t, err) // it should't be deleted - _, err = ovnClient.GetAddressSet(asName, false) + _, err = nbClient.GetAddressSet(asName, false) require.NoError(t, err) // should delete - ass, err := ovnClient.ListAddressSets(externalIDs) + ass, err := nbClient.ListAddressSets(externalIDs) require.NoError(t, err) require.Empty(t, ass) // delete address sets with empty externalIDs - err = ovnClient.DeleteAddressSets(map[string]string{}) + err = nbClient.DeleteAddressSets(map[string]string{}) require.NoError(t, err) } @@ -233,14 +233,14 @@ func (suite *OvnClientTestSuite) testListAddressSets() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient asName := "test_list_as_exist_key" - err := ovnClient.CreateAddressSet(asName, map[string]string{sgKey: "sg", "direction": "to-lport", "key": "value"}) + err := nbClient.CreateAddressSet(asName, map[string]string{sgKey: "sg", "direction": "to-lport", "key": "value"}) require.NoError(t, err) - ass, err := ovnClient.ListAddressSets(map[string]string{sgKey: "sg", "key": "value"}) + ass, err := nbClient.ListAddressSets(map[string]string{sgKey: "sg", "key": "value"}) require.NoError(t, err) require.Len(t, ass, 1) require.Equal(t, asName, ass[0].Name) @@ -325,10 +325,10 @@ func (suite *OvnClientTestSuite) testUpdateAddressSet() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("update with nil address set", func(t *testing.T) { - err := ovnClient.UpdateAddressSet(nil) + err := nbClient.UpdateAddressSet(nil) require.Error(t, err) require.Contains(t, err.Error(), "address_set is nil") }) diff --git a/pkg/ovs/ovn-nb-bfd_test.go b/pkg/ovs/ovn-nb-bfd_test.go index f9088a3487f..1e6b6f8eff7 100644 --- a/pkg/ovs/ovn-nb-bfd_test.go +++ b/pkg/ovs/ovn-nb-bfd_test.go @@ -13,7 +13,7 @@ func (suite *OvnClientTestSuite) testCreateBFD() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient dstIP := "192.168.124.1" minRx, minTx, detectMult := 101, 102, 19 @@ -22,7 +22,7 @@ func (suite *OvnClientTestSuite) testCreateBFD() { lrpName := "test-create-bfd" - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) require.Equal(t, lrpName, bfd.LogicalPort) @@ -40,11 +40,11 @@ func (suite *OvnClientTestSuite) testCreateBFD() { lrpName := "test-create-existing-bfd" - bfd1, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd1, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd1) - bfd2, err := ovnClient.CreateBFD(lrpName, dstIP, minRx+1, minTx+1, detectMult+1) + bfd2, err := nbClient.CreateBFD(lrpName, dstIP, minRx+1, minTx+1, detectMult+1) require.NoError(t, err) require.NotNil(t, bfd2) require.Equal(t, bfd1, bfd2) @@ -59,7 +59,7 @@ func (suite *OvnClientTestSuite) testListBFD() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-list-bfd" dstIP1 := "192.168.124.2" dstIP2 := "192.168.124.3" @@ -69,25 +69,25 @@ func (suite *OvnClientTestSuite) testListBFD() { t.Run("list BFDs", func(t *testing.T) { t.Parallel() - bfd1, err := ovnClient.CreateBFD(lrpName, dstIP1, minRx1, minTx1, detectMult1) + bfd1, err := nbClient.CreateBFD(lrpName, dstIP1, minRx1, minTx1, detectMult1) require.NoError(t, err) require.NotNil(t, bfd1) - bfd2, err := ovnClient.CreateBFD(lrpName, dstIP2, minRx2, minTx2, detectMult2) + bfd2, err := nbClient.CreateBFD(lrpName, dstIP2, minRx2, minTx2, detectMult2) require.NoError(t, err) require.NotNil(t, bfd2) - bfdList, err := ovnClient.ListBFDs(lrpName, dstIP1) + bfdList, err := nbClient.ListBFDs(lrpName, dstIP1) require.NoError(t, err) require.Len(t, bfdList, 1) require.Equal(t, bfd1.UUID, bfdList[0].UUID) - bfdList, err = ovnClient.ListBFDs(lrpName, dstIP2) + bfdList, err = nbClient.ListBFDs(lrpName, dstIP2) require.NoError(t, err) require.Len(t, bfdList, 1) require.Equal(t, bfd2.UUID, bfdList[0].UUID) - bfdList, err = ovnClient.ListBFDs(lrpName, "") + bfdList, err = nbClient.ListBFDs(lrpName, "") require.NoError(t, err) require.Len(t, bfdList, 2) uuids := strset.NewWithSize(len(bfdList)) @@ -102,38 +102,38 @@ func (suite *OvnClientTestSuite) testDeleteBFD() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-del-bfd" dstIP1 := "192.168.124.4" dstIP2 := "192.168.124.5" minRx1, minTx1, detectMult1 := 101, 102, 19 minRx2, minTx2, detectMult2 := 201, 202, 29 - _, err := ovnClient.CreateBFD(lrpName, dstIP1, minRx1, minTx1, detectMult1) + _, err := nbClient.CreateBFD(lrpName, dstIP1, minRx1, minTx1, detectMult1) require.NoError(t, err) - bfd2, err := ovnClient.CreateBFD(lrpName, dstIP2, minRx2, minTx2, detectMult2) + bfd2, err := nbClient.CreateBFD(lrpName, dstIP2, minRx2, minTx2, detectMult2) require.NoError(t, err) t.Run("delete BFD", func(t *testing.T) { - err = ovnClient.DeleteBFD(lrpName, dstIP1) + err = nbClient.DeleteBFD(lrpName, dstIP1) require.NoError(t, err) - bfdList, err := ovnClient.ListBFDs(lrpName, dstIP1) + bfdList, err := nbClient.ListBFDs(lrpName, dstIP1) require.NoError(t, err) require.Len(t, bfdList, 0) - bfdList, err = ovnClient.ListBFDs(lrpName, dstIP2) + bfdList, err = nbClient.ListBFDs(lrpName, dstIP2) require.NoError(t, err) require.Len(t, bfdList, 1) require.Equal(t, bfd2.UUID, bfdList[0].UUID) }) t.Run("delete multiple BFDs", func(t *testing.T) { - err = ovnClient.DeleteBFD(lrpName, "") + err = nbClient.DeleteBFD(lrpName, "") require.NoError(t, err) - bfdList, err := ovnClient.ListBFDs(lrpName, "") + bfdList, err := nbClient.ListBFDs(lrpName, "") require.NoError(t, err) require.Len(t, bfdList, 0) }) @@ -141,7 +141,7 @@ func (suite *OvnClientTestSuite) testDeleteBFD() { t.Run("delete non-existent BFD", func(t *testing.T) { t.Parallel() - err := ovnClient.DeleteBFD(lrpName, "192.168.124.17") + err := nbClient.DeleteBFD(lrpName, "192.168.124.17") require.NoError(t, err) }) } @@ -150,7 +150,7 @@ func (suite *OvnClientTestSuite) testListDownBFDs() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-list-down-bfd" dstIP1 := "192.168.124.6" dstIP2 := "192.168.124.7" @@ -160,15 +160,15 @@ func (suite *OvnClientTestSuite) testListDownBFDs() { t.Run("list down BFDs", func(t *testing.T) { t.Parallel() - bfd1, err := ovnClient.CreateBFD(lrpName, dstIP1, minRx, minTx, detectMult) + bfd1, err := nbClient.CreateBFD(lrpName, dstIP1, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd1) - bfd2, err := ovnClient.CreateBFD(lrpName, dstIP2, minRx, minTx, detectMult) + bfd2, err := nbClient.CreateBFD(lrpName, dstIP2, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd2) - bfd3, err := ovnClient.CreateBFD(lrpName, dstIP3, minRx, minTx, detectMult) + bfd3, err := nbClient.CreateBFD(lrpName, dstIP3, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd3) @@ -181,29 +181,29 @@ func (suite *OvnClientTestSuite) testListDownBFDs() { bfd2.Status = &adminDownStatus bfd3.Status = &upStatus - err = ovnClient.UpdateBFD(bfd1) + err = nbClient.UpdateBFD(bfd1) require.NoError(t, err) - err = ovnClient.UpdateBFD(bfd2) + err = nbClient.UpdateBFD(bfd2) require.NoError(t, err) - err = ovnClient.UpdateBFD(bfd3) + err = nbClient.UpdateBFD(bfd3) require.NoError(t, err) // Test listing down BFDs for specific IP - downBFDs, err := ovnClient.ListDownBFDs(dstIP1) + downBFDs, err := nbClient.ListDownBFDs(dstIP1) require.NoError(t, err) require.Len(t, downBFDs, 1) require.Equal(t, bfd1.UUID, downBFDs[0].UUID) - downBFDs, err = ovnClient.ListDownBFDs(dstIP2) + downBFDs, err = nbClient.ListDownBFDs(dstIP2) require.NoError(t, err) require.Len(t, downBFDs, 1) - downBFDs, err = ovnClient.ListDownBFDs(dstIP3) + downBFDs, err = nbClient.ListDownBFDs(dstIP3) require.NoError(t, err) require.Len(t, downBFDs, 0) // Test listing down BFDs for non-existent IP - nonExistentBFDs, err := ovnClient.ListDownBFDs("192.168.124.9") + nonExistentBFDs, err := nbClient.ListDownBFDs("192.168.124.9") require.NoError(t, err) require.Len(t, nonExistentBFDs, 0) }) @@ -212,17 +212,17 @@ func (suite *OvnClientTestSuite) testListDownBFDs() { t.Parallel() // Create a BFD with UP status - bfd, err := ovnClient.CreateBFD(lrpName, "192.168.124.10", minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, "192.168.124.10", minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) upStatus := ovnnb.BFDStatusUp bfd.Status = &upStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) // Try to list down BFDs - downBFDs, err := ovnClient.ListDownBFDs("192.168.124.10") + downBFDs, err := nbClient.ListDownBFDs("192.168.124.10") require.NoError(t, err) require.Len(t, downBFDs, 0) }) @@ -232,7 +232,7 @@ func (suite *OvnClientTestSuite) testListUpBFDs() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-list-up-bfd" dstIP1 := "192.168.124.11" dstIP2 := "192.168.124.12" @@ -242,15 +242,15 @@ func (suite *OvnClientTestSuite) testListUpBFDs() { t.Run("list up BFDs", func(t *testing.T) { t.Parallel() - bfd1, err := ovnClient.CreateBFD(lrpName, dstIP1, minRx, minTx, detectMult) + bfd1, err := nbClient.CreateBFD(lrpName, dstIP1, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd1) - bfd2, err := ovnClient.CreateBFD(lrpName, dstIP2, minRx, minTx, detectMult) + bfd2, err := nbClient.CreateBFD(lrpName, dstIP2, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd2) - bfd3, err := ovnClient.CreateBFD(lrpName, dstIP3, minRx, minTx, detectMult) + bfd3, err := nbClient.CreateBFD(lrpName, dstIP3, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd3) @@ -262,23 +262,23 @@ func (suite *OvnClientTestSuite) testListUpBFDs() { bfd2.Status = &downStatus bfd3.Status = &adminDownStatus - err = ovnClient.UpdateBFD(bfd1) + err = nbClient.UpdateBFD(bfd1) require.NoError(t, err) - err = ovnClient.UpdateBFD(bfd2) + err = nbClient.UpdateBFD(bfd2) require.NoError(t, err) - err = ovnClient.UpdateBFD(bfd3) + err = nbClient.UpdateBFD(bfd3) require.NoError(t, err) - upBFDs, err := ovnClient.ListUpBFDs(dstIP1) + upBFDs, err := nbClient.ListUpBFDs(dstIP1) require.NoError(t, err) require.Len(t, upBFDs, 1) require.Equal(t, bfd1.UUID, upBFDs[0].UUID) - upBFDs, err = ovnClient.ListUpBFDs(dstIP2) + upBFDs, err = nbClient.ListUpBFDs(dstIP2) require.NoError(t, err) require.Len(t, upBFDs, 0) - upBFDs, err = ovnClient.ListUpBFDs(dstIP3) + upBFDs, err = nbClient.ListUpBFDs(dstIP3) require.NoError(t, err) require.Len(t, upBFDs, 0) }) @@ -286,7 +286,7 @@ func (suite *OvnClientTestSuite) testListUpBFDs() { t.Run("list up BFDs with non-existent IP", func(t *testing.T) { t.Parallel() - upBFDs, err := ovnClient.ListUpBFDs("192.168.124.14") + upBFDs, err := nbClient.ListUpBFDs("192.168.124.14") require.NoError(t, err) require.Len(t, upBFDs, 0) }) @@ -296,7 +296,7 @@ func (suite *OvnClientTestSuite) testIsLrpBfdUp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient dstIP := "192.168.124.15" minRx, minTx, detectMult := 101, 102, 19 @@ -305,16 +305,16 @@ func (suite *OvnClientTestSuite) testIsLrpBfdUp() { t.Parallel() lrpName := "test-is-lrp-bfd-up" - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) upStatus := ovnnb.BFDStatusUp bfd.Status = &upStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) - isUp, err := ovnClient.isLrpBfdUp(lrpName, dstIP) + isUp, err := nbClient.isLrpBfdUp(lrpName, dstIP) require.NoError(t, err) require.True(t, isUp) }) @@ -323,16 +323,16 @@ func (suite *OvnClientTestSuite) testIsLrpBfdUp() { t.Parallel() lrpName := "test-is-lrp-bfd-down" - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) downStatus := ovnnb.BFDStatusDown bfd.Status = &downStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) - isUp, err := ovnClient.isLrpBfdUp(lrpName, dstIP) + isUp, err := nbClient.isLrpBfdUp(lrpName, dstIP) require.Error(t, err) require.False(t, isUp) require.Contains(t, err.Error(), "status is down") @@ -342,15 +342,15 @@ func (suite *OvnClientTestSuite) testIsLrpBfdUp() { t.Parallel() lrpName := "test-is-lrp-bfd-status-nil" - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) bfd.Status = nil - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) - isUp, err := ovnClient.isLrpBfdUp(lrpName, dstIP) + isUp, err := nbClient.isLrpBfdUp(lrpName, dstIP) require.Error(t, err) require.False(t, isUp) require.Contains(t, err.Error(), "status is nil") @@ -360,7 +360,7 @@ func (suite *OvnClientTestSuite) testIsLrpBfdUp() { t.Parallel() lrpName := "test-is-lrp-bfd-none" - isUp, err := ovnClient.isLrpBfdUp(lrpName, "192.168.124.16") + isUp, err := nbClient.isLrpBfdUp(lrpName, "192.168.124.16") require.NoError(t, err) require.True(t, isUp) }) @@ -370,7 +370,7 @@ func (suite *OvnClientTestSuite) testBfdAddL3HAHandler() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("BFD status is nil", func(t *testing.T) { t.Parallel() @@ -379,17 +379,17 @@ func (suite *OvnClientTestSuite) testBfdAddL3HAHandler() { dstIP := "192.168.124.19" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) bfd.Status = nil - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) - ovnClient.bfdAddL3HAHandler(ovnnb.BFDTable, bfd) + nbClient.bfdAddL3HAHandler(ovnnb.BFDTable, bfd) - updatedBfd, err := ovnClient.ListBFDs(lrpName, dstIP) + updatedBfd, err := nbClient.ListBFDs(lrpName, dstIP) require.NoError(t, err) require.Nil(t, updatedBfd[0].Status) }) @@ -401,18 +401,18 @@ func (suite *OvnClientTestSuite) testBfdAddL3HAHandler() { dstIP := "192.168.124.20" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) downStatus := ovnnb.BFDStatusDown bfd.Status = &downStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) - ovnClient.bfdAddL3HAHandler(ovnnb.BFDTable, bfd) + nbClient.bfdAddL3HAHandler(ovnnb.BFDTable, bfd) - updatedBfd, err := ovnClient.ListBFDs(lrpName, dstIP) + updatedBfd, err := nbClient.ListBFDs(lrpName, dstIP) require.NoError(t, err) require.NotNil(t, updatedBfd[0].Status) require.Equal(t, ovnnb.BFDStatusDown, *updatedBfd[0].Status) @@ -425,18 +425,18 @@ func (suite *OvnClientTestSuite) testBfdAddL3HAHandler() { dstIP := "192.168.124.21" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) upStatus := ovnnb.BFDStatusUp bfd.Status = &upStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) - ovnClient.bfdAddL3HAHandler(ovnnb.BFDTable, bfd) + nbClient.bfdAddL3HAHandler(ovnnb.BFDTable, bfd) - updatedBfd, err := ovnClient.ListBFDs(lrpName, dstIP) + updatedBfd, err := nbClient.ListBFDs(lrpName, dstIP) require.NoError(t, err) require.NotNil(t, updatedBfd[0].Status) require.Equal(t, ovnnb.BFDStatusUp, *updatedBfd[0].Status) @@ -449,13 +449,13 @@ func (suite *OvnClientTestSuite) testBfdAddL3HAHandler() { dstIP := "192.168.124.22" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) - ovnClient.bfdAddL3HAHandler("WrongTable", bfd) + nbClient.bfdAddL3HAHandler("WrongTable", bfd) - updatedBfd, err := ovnClient.ListBFDs(lrpName, dstIP) + updatedBfd, err := nbClient.ListBFDs(lrpName, dstIP) require.NoError(t, err) require.Nil(t, updatedBfd[0].Status) }) @@ -465,7 +465,7 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("BFD status change with wrong table", func(t *testing.T) { t.Parallel() @@ -474,20 +474,20 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { dstIP := "192.168.124.26" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) upStatus := ovnnb.BFDStatusUp bfd.Status = &upStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) newBfd := *bfd downStatus := ovnnb.BFDStatusDown newBfd.Status = &downStatus - ovnClient.bfdUpdateL3HAHandler("WrongTable", bfd, &newBfd) + nbClient.bfdUpdateL3HAHandler("WrongTable", bfd, &newBfd) }) t.Run("BFD status change with nil status", func(t *testing.T) { @@ -497,20 +497,20 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { dstIP := "192.168.124.27" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) bfd.Status = nil - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) newBfd := *bfd downStatus := ovnnb.BFDStatusDown newBfd.Status = &downStatus - ovnClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) + nbClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) - updatedBfd, err := ovnClient.ListBFDs(lrpName, dstIP) + updatedBfd, err := nbClient.ListBFDs(lrpName, dstIP) require.NoError(t, err) require.Nil(t, updatedBfd[0].Status) }) @@ -522,18 +522,18 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { dstIP := "192.168.124.28" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) upStatus := ovnnb.BFDStatusUp bfd.Status = &upStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) newBfd := *bfd newBfd.Status = &upStatus - ovnClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) + nbClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) }) t.Run("BFD status change from AdminDown to Down", func(t *testing.T) { @@ -543,20 +543,20 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { dstIP := "192.168.124.23" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) adminDownStatus := ovnnb.BFDStatusAdminDown bfd.Status = &adminDownStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) newBfd := *bfd downStatus := ovnnb.BFDStatusDown newBfd.Status = &downStatus - ovnClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) + nbClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) }) t.Run("BFD status change from Down to Up", func(t *testing.T) { @@ -566,20 +566,20 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { dstIP := "192.168.124.24" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) downStatus := ovnnb.BFDStatusDown bfd.Status = &downStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) newBfd := *bfd upStatus := ovnnb.BFDStatusUp newBfd.Status = &upStatus - ovnClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) + nbClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) }) t.Run("BFD status change from Up to Down", func(t *testing.T) { @@ -589,20 +589,20 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() { dstIP := "192.168.124.25" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) upStatus := ovnnb.BFDStatusUp bfd.Status = &upStatus - err = ovnClient.UpdateBFD(bfd) + err = nbClient.UpdateBFD(bfd) require.NoError(t, err) newBfd := *bfd downStatus := ovnnb.BFDStatusDown newBfd.Status = &downStatus - ovnClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) + nbClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd) }) } @@ -610,7 +610,7 @@ func (suite *OvnClientTestSuite) testBfdDelL3HAHandler() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("BFD deletion with wrong table", func(t *testing.T) { t.Parallel() @@ -619,14 +619,14 @@ func (suite *OvnClientTestSuite) testBfdDelL3HAHandler() { dstIP := "192.168.124.30" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) - ovnClient.bfdDelL3HAHandler("WrongTable", bfd) + nbClient.bfdDelL3HAHandler("WrongTable", bfd) // Verify that the BFD is not deleted - bfdList, err := ovnClient.ListBFDs(lrpName, dstIP) + bfdList, err := nbClient.ListBFDs(lrpName, dstIP) require.NoError(t, err) require.Len(t, bfdList, 1) }) @@ -638,10 +638,10 @@ func (suite *OvnClientTestSuite) testBfdDelL3HAHandler() { dstIP := "192.168.124.31" minRx, minTx, detectMult := 101, 102, 19 - bfd, err := ovnClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) + bfd, err := nbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult) require.NoError(t, err) require.NotNil(t, bfd) - ovnClient.bfdDelL3HAHandler(ovnnb.BFDTable, bfd) + nbClient.bfdDelL3HAHandler(ovnnb.BFDTable, bfd) }) } diff --git a/pkg/ovs/ovn-nb-dhcp_options_test.go b/pkg/ovs/ovn-nb-dhcp_options_test.go index 833282408df..aa6c6f54b15 100644 --- a/pkg/ovs/ovn-nb-dhcp_options_test.go +++ b/pkg/ovs/ovn-nb-dhcp_options_test.go @@ -30,18 +30,18 @@ func (suite *OvnClientTestSuite) testUpdateDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-dhcp-opt-ls" subnet := mockSubnet(lsName, true) t.Run("update dhcp options", func(t *testing.T) { - uuid, err := ovnClient.UpdateDHCPOptions(subnet, 1500) + uuid, err := nbClient.UpdateDHCPOptions(subnet, 1500) require.NoError(t, err) - v4DHCPOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) + v4DHCPOpt, err := nbClient.GetDHCPOptions(lsName, "IPv4", false) require.NoError(t, err) - v6DHCPOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv6", false) + v6DHCPOpt, err := nbClient.GetDHCPOptions(lsName, "IPv6", false) require.NoError(t, err) require.Equal(t, uuid.DHCPv4OptionsUUID, v4DHCPOpt.UUID) @@ -51,15 +51,15 @@ func (suite *OvnClientTestSuite) testUpdateDHCPOptions() { t.Run("delete dhcp options", func(t *testing.T) { subnet.Spec.EnableDHCP = false - uuid, err := ovnClient.UpdateDHCPOptions(subnet, 1500) + uuid, err := nbClient.UpdateDHCPOptions(subnet, 1500) require.NoError(t, err) require.Empty(t, uuid.DHCPv4OptionsUUID) require.Empty(t, uuid.DHCPv6OptionsUUID) - _, err = ovnClient.GetDHCPOptions(lsName, "IPv4", false) + _, err = nbClient.GetDHCPOptions(lsName, "IPv4", false) require.ErrorContains(t, err, "not found") - _, err = ovnClient.GetDHCPOptions(lsName, "IPv6", false) + _, err = nbClient.GetDHCPOptions(lsName, "IPv6", false) require.ErrorContains(t, err, "not found") }) @@ -68,14 +68,14 @@ func (suite *OvnClientTestSuite) testUpdateDHCPOptions() { subnet.Spec.U2OInterconnection = true subnet.Status.U2OInterconnectionIP = "10.244.0.2,fc00::0af4:02" - _, err := ovnClient.UpdateDHCPOptions(subnet, 1500) + _, err := nbClient.UpdateDHCPOptions(subnet, 1500) require.NoError(t, err) - v4DHCPOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) + v4DHCPOpt, err := nbClient.GetDHCPOptions(lsName, "IPv4", false) require.NoError(t, err) require.Equal(t, v4DHCPOpt.Options["router"], "10.244.0.2") - v6DHCPOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv6", false) + v6DHCPOpt, err := nbClient.GetDHCPOptions(lsName, "IPv6", false) require.NoError(t, err) require.Equal(t, v6DHCPOpt.Options["router"], "") }) @@ -86,10 +86,10 @@ func (suite *OvnClientTestSuite) testUpdateDHCPOptions() { subnet.Spec.Gateway = "10.244.0.1" subnet.Spec.Protocol = kubeovnv1.ProtocolIPv4 - uuid, err := ovnClient.UpdateDHCPOptions(subnet, 1500) + uuid, err := nbClient.UpdateDHCPOptions(subnet, 1500) require.NoError(t, err) - v4DHCPOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) + v4DHCPOpt, err := nbClient.GetDHCPOptions(lsName, "IPv4", false) require.NoError(t, err) require.Equal(t, uuid.DHCPv4OptionsUUID, v4DHCPOpt.UUID) }) @@ -99,16 +99,16 @@ func (suite *OvnClientTestSuite) testUpdateDHCPOptions() { subnet.Spec.Gateway = "fc00::0af4:01" subnet.Spec.Protocol = kubeovnv1.ProtocolIPv6 - uuid, err := ovnClient.UpdateDHCPOptions(subnet, 1500) + uuid, err := nbClient.UpdateDHCPOptions(subnet, 1500) require.NoError(t, err) - v6DHCPOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv6", false) + v6DHCPOpt, err := nbClient.GetDHCPOptions(lsName, "IPv6", false) require.NoError(t, err) require.Equal(t, uuid.DHCPv6OptionsUUID, v6DHCPOpt.UUID) }) t.Run("update dhcp options with nil input", func(t *testing.T) { - err := ovnClient.updateDHCPOptions(nil) + err := nbClient.updateDHCPOptions(nil) require.Error(t, err) require.Contains(t, err.Error(), "dhcp_options is nil") }) @@ -118,7 +118,7 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv4Options() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-v4-dhcp-opt-ls" cidr := "192.168.30.0/24" gateway := "192.168.30.1" @@ -126,10 +126,10 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv4Options() { t.Run("create dhcp options", func(t *testing.T) { t.Run("without options", func(t *testing.T) { - uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, "", 1500) + uuid, err := nbClient.updateDHCPv4Options(lsName, cidr, gateway, "", 1500) require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName, "IPv4", false) require.NoError(t, err) serverMac = dhcpOpt.Options["server_mac"] @@ -148,10 +148,10 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv4Options() { t.Run("with options", func(t *testing.T) { lsName := "test-update-v4-dhcp-opt-ls-with-opt" options := fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s", 7200, gateway, "169.254.0.1", "00:00:00:11:22:33") - uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, options, 1500) + uuid, err := nbClient.updateDHCPv4Options(lsName, cidr, gateway, options, 1500) require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName, "IPv4", false) require.NoError(t, err) require.Equal(t, uuid, dhcpOpt.UUID) @@ -166,10 +166,10 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv4Options() { }) t.Run("update dhcp options", func(t *testing.T) { - uuid, err := ovnClient.updateDHCPv4Options(lsName, cidr, gateway, "", 1500) + uuid, err := nbClient.updateDHCPv4Options(lsName, cidr, gateway, "", 1500) require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv4", false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName, "IPv4", false) require.NoError(t, err) require.Equal(t, uuid, dhcpOpt.UUID) @@ -184,24 +184,24 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv4Options() { }) t.Run("update dhcp options with invalid cidr", func(t *testing.T) { - _, err := ovnClient.updateDHCPv4Options(lsName, "", gateway, "", 1500) + _, err := nbClient.updateDHCPv4Options(lsName, "", gateway, "", 1500) require.ErrorContains(t, err, "must be a valid ipv4 address") }) t.Run("update dhcp options with invalid lsName", func(t *testing.T) { - _, err := ovnClient.updateDHCPv4Options("", cidr, gateway, "", 1500) + _, err := nbClient.updateDHCPv4Options("", cidr, gateway, "", 1500) require.ErrorContains(t, err, "the logical router name is required") }) t.Run("append necessary options to new options", func(t *testing.T) { options := "router=192.168.30.1" - err := ovnClient.CreateDHCPOptions(lsName+"-1", cidr, options) + err := nbClient.CreateDHCPOptions(lsName+"-1", cidr, options) require.NoError(t, err) - uuid, err := ovnClient.updateDHCPv4Options(lsName+"-1", cidr, gateway, "dns_server=8.8.8.8", 1500) + uuid, err := nbClient.updateDHCPv4Options(lsName+"-1", cidr, gateway, "dns_server=8.8.8.8", 1500) require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName+"-1", "IPv4", false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName+"-1", "IPv4", false) require.NoError(t, err) require.Equal(t, uuid, dhcpOpt.UUID) @@ -221,17 +221,17 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv6Options() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-v6-dhcp-opt-ls" cidr := "fd00::c0a8:6e01/120" var serverID string t.Run("create dhcp options", func(t *testing.T) { t.Run("without options", func(t *testing.T) { - uuid, err := ovnClient.updateDHCPv6Options(lsName, cidr, "") + uuid, err := nbClient.updateDHCPv6Options(lsName, cidr, "") require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv6", false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName, "IPv6", false) require.NoError(t, err) serverID = dhcpOpt.Options["server_id"] @@ -246,10 +246,10 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv6Options() { t.Run("with options", func(t *testing.T) { lsName := "test-update-v6-dhcp-opt-ls-with-opt" options := fmt.Sprintf("server_id=%s", "00:00:00:55:22:33") - uuid, err := ovnClient.updateDHCPv6Options(lsName, cidr, options) + uuid, err := nbClient.updateDHCPv6Options(lsName, cidr, options) require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv6", false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName, "IPv6", false) require.NoError(t, err) require.Equal(t, uuid, dhcpOpt.UUID) @@ -261,10 +261,10 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv6Options() { }) t.Run("update dhcp options", func(t *testing.T) { - uuid, err := ovnClient.updateDHCPv6Options(lsName, cidr, "") + uuid, err := nbClient.updateDHCPv6Options(lsName, cidr, "") require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, "IPv6", false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName, "IPv6", false) require.NoError(t, err) require.Equal(t, uuid, dhcpOpt.UUID) @@ -275,24 +275,24 @@ func (suite *OvnClientTestSuite) testUpdateDHCPv6Options() { }) t.Run("update dhcp options with invalid cidr", func(t *testing.T) { - _, err := ovnClient.updateDHCPv6Options(lsName, "", "") + _, err := nbClient.updateDHCPv6Options(lsName, "", "") require.ErrorContains(t, err, "must be a valid ipv6 address") }) t.Run("update dhcp options with invalid lsName", func(t *testing.T) { - _, err := ovnClient.updateDHCPv6Options("", cidr, "") + _, err := nbClient.updateDHCPv6Options("", cidr, "") require.ErrorContains(t, err, "the logical router name is required") }) t.Run("append necessary options to new options", func(t *testing.T) { options := fmt.Sprintf("server_id=%s", "00:00:00:55:22:33") - err := ovnClient.CreateDHCPOptions(lsName+"-1", cidr, options) + err := nbClient.CreateDHCPOptions(lsName+"-1", cidr, options) require.NoError(t, err) - uuid, err := ovnClient.updateDHCPv6Options(lsName+"-1", cidr, "dns_server=fc00::0af4:01") + uuid, err := nbClient.updateDHCPv6Options(lsName+"-1", cidr, "dns_server=fc00::0af4:01") require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName+"-1", "IPv6", false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName+"-1", "IPv6", false) require.NoError(t, err) require.Equal(t, uuid, dhcpOpt.UUID) @@ -308,28 +308,28 @@ func (suite *OvnClientTestSuite) testDeleteDHCPOptionsByUUIDs() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-del-dhcp-opt-uuid-ls" v4CidrBlock := []string{"192.168.30.0/24", "192.168.40.0/24", "192.168.50.0/24"} uuidList := make([]string, 0) // create three ipv4 dhcp options for _, cidr := range v4CidrBlock { - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) } - out, err := ovnClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName}) + out, err := nbClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName}) require.NoError(t, err) require.Len(t, out, 3) for _, o := range out { uuidList = append(uuidList, o.UUID) } - err = ovnClient.DeleteDHCPOptionsByUUIDs(uuidList...) + err = nbClient.DeleteDHCPOptionsByUUIDs(uuidList...) require.NoError(t, err) - out, err = ovnClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName}) + out, err = nbClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName}) require.NoError(t, err) require.Empty(t, out) } @@ -338,7 +338,7 @@ func (suite *OvnClientTestSuite) testDeleteDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-del-dhcp-opt-ls" v4CidrBlock := []string{"192.168.30.0/24", "192.168.40.0/24", "192.168.50.0/24"} v6CidrBlock := []string{"fd00::c0a8:6401/120", "fd00::c0a8:6e01/120"} @@ -346,13 +346,13 @@ func (suite *OvnClientTestSuite) testDeleteDHCPOptions() { prepare := func() { // create three ipv4 dhcp options for _, cidr := range v4CidrBlock { - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) } // create two ipv6 dhcp options for _, cidr := range v6CidrBlock { - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) } } @@ -361,22 +361,22 @@ func (suite *OvnClientTestSuite) testDeleteDHCPOptions() { prepare() /* delete ipv4 dhcp options */ - err := ovnClient.DeleteDHCPOptions(lsName, "IPv4") + err := nbClient.DeleteDHCPOptions(lsName, "IPv4") require.NoError(t, err) - out, err := ovnClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName, "protocol": "IPv4"}) + out, err := nbClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName, "protocol": "IPv4"}) require.NoError(t, err) require.Empty(t, out) - out, err = ovnClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName, "protocol": "IPv6"}) + out, err = nbClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName, "protocol": "IPv6"}) require.NoError(t, err) require.Len(t, out, 2) /* delete ipv6 dhcp options */ - err = ovnClient.DeleteDHCPOptions(lsName, "IPv6") + err = nbClient.DeleteDHCPOptions(lsName, "IPv6") require.NoError(t, err) - out, err = ovnClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName, "protocol": "IPv6"}) + out, err = nbClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName, "protocol": "IPv6"}) require.NoError(t, err) require.Empty(t, out) }) @@ -384,10 +384,10 @@ func (suite *OvnClientTestSuite) testDeleteDHCPOptions() { t.Run("delete all protocol dhcp options", func(t *testing.T) { prepare() - err := ovnClient.DeleteDHCPOptions(lsName, kubeovnv1.ProtocolDual) + err := nbClient.DeleteDHCPOptions(lsName, kubeovnv1.ProtocolDual) require.NoError(t, err) - out, err := ovnClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName, "protocol": "IPv6"}) + out, err := nbClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName, "protocol": "IPv6"}) require.NoError(t, err) require.Empty(t, out) }) @@ -397,32 +397,32 @@ func (suite *OvnClientTestSuite) testGetDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-get-dhcp-opt-ls" t.Run("ipv4 dhcp options", func(t *testing.T) { cidr := "192.168.30.0/24" protocol := kubeovnv1.ProtocolIPv4 - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) t.Run("found dhcp options", func(t *testing.T) { - _, err := ovnClient.GetDHCPOptions(lsName, protocol, false) + _, err := nbClient.GetDHCPOptions(lsName, protocol, false) require.NoError(t, err) }) t.Run("protocol is different", func(t *testing.T) { - _, err := ovnClient.GetDHCPOptions(lsName, kubeovnv1.ProtocolIPv6, false) + _, err := nbClient.GetDHCPOptions(lsName, kubeovnv1.ProtocolIPv6, false) require.ErrorContains(t, err, "not found") }) t.Run("logical switch name is different", func(t *testing.T) { - _, err := ovnClient.GetDHCPOptions(lsName+"x", protocol, false) + _, err := nbClient.GetDHCPOptions(lsName+"x", protocol, false) require.ErrorContains(t, err, "not found") }) t.Run("not found and ignoreNotFound=true", func(t *testing.T) { - _, err := ovnClient.GetDHCPOptions(lsName+"x", protocol, true) + _, err := nbClient.GetDHCPOptions(lsName+"x", protocol, true) require.NoError(t, err) }) }) @@ -430,39 +430,39 @@ func (suite *OvnClientTestSuite) testGetDHCPOptions() { t.Run("ipv6 dhcp options", func(t *testing.T) { cidr := "fd00::c0a8:6901/120" protocol := kubeovnv1.ProtocolIPv6 - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) t.Run("found dhcp options", func(t *testing.T) { - _, err := ovnClient.GetDHCPOptions(lsName, protocol, false) + _, err := nbClient.GetDHCPOptions(lsName, protocol, false) require.NoError(t, err) }) }) t.Run("invalid protocol", func(t *testing.T) { protocol := kubeovnv1.ProtocolDual - _, err := ovnClient.GetDHCPOptions(lsName, protocol, false) + _, err := nbClient.GetDHCPOptions(lsName, protocol, false) require.ErrorContains(t, err, "protocol must be IPv4 or IPv6") protocol = "" - _, err = ovnClient.GetDHCPOptions(lsName, protocol, false) + _, err = nbClient.GetDHCPOptions(lsName, protocol, false) require.ErrorContains(t, err, "protocol must be IPv4 or IPv6") }) t.Run("duplicate dhcp options", func(t *testing.T) { cidr := "192.168.30.0/24" - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) cidr = "fd00::c0a8:6901/120" - err = ovnClient.CreateDHCPOptions(lsName, cidr, "") + err = nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) protocol := kubeovnv1.ProtocolIPv4 - _, err = ovnClient.GetDHCPOptions(lsName, protocol, false) + _, err = nbClient.GetDHCPOptions(lsName, protocol, false) require.ErrorContains(t, err, "more than one IPv4 dhcp options in logical switch") protocol = kubeovnv1.ProtocolIPv6 - _, err = ovnClient.GetDHCPOptions(lsName, protocol, false) + _, err = nbClient.GetDHCPOptions(lsName, protocol, false) require.ErrorContains(t, err, "more than one IPv6 dhcp options in logical switch") }) } @@ -471,18 +471,18 @@ func (suite *OvnClientTestSuite) testListDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-list-dhcp-opt-ls" v4CidrBlock := []string{"192.168.30.0/24", "192.168.40.0/24", "192.168.50.0/24"} // create three ipv4 dhcp options for _, cidr := range v4CidrBlock { - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) } /* list all direction acl */ - out, err := ovnClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName}) + out, err := nbClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName}) require.NoError(t, err) require.Len(t, out, 3) } @@ -599,16 +599,16 @@ func (suite *OvnClientTestSuite) testCreateDHCPOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-create-dhcp-opt-ls" t.Run("create valid IPv4 DHCP options", func(t *testing.T) { cidr := "192.168.60.0/24" options := "router=192.168.60.1,dns_server=8.8.8.8" - err := ovnClient.CreateDHCPOptions(lsName, cidr, options) + err := nbClient.CreateDHCPOptions(lsName, cidr, options) require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, kubeovnv1.ProtocolIPv4, false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName, kubeovnv1.ProtocolIPv4, false) require.NoError(t, err) require.Equal(t, cidr, dhcpOpt.Cidr) require.Contains(t, dhcpOpt.Options, "router") @@ -618,10 +618,10 @@ func (suite *OvnClientTestSuite) testCreateDHCPOptions() { t.Run("create valid IPv6 DHCP options", func(t *testing.T) { cidr := "fd00::c0a8:7001/120" options := "server_id=00:00:00:00:00:01" - err := ovnClient.CreateDHCPOptions(lsName, cidr, options) + err := nbClient.CreateDHCPOptions(lsName, cidr, options) require.NoError(t, err) - dhcpOpt, err := ovnClient.GetDHCPOptions(lsName, kubeovnv1.ProtocolIPv6, false) + dhcpOpt, err := nbClient.GetDHCPOptions(lsName, kubeovnv1.ProtocolIPv6, false) require.NoError(t, err) require.Equal(t, cidr, dhcpOpt.Cidr) require.Contains(t, dhcpOpt.Options, "server_id") @@ -629,13 +629,13 @@ func (suite *OvnClientTestSuite) testCreateDHCPOptions() { t.Run("create DHCP options with invalid CIDR", func(t *testing.T) { cidr := "invalid-cidr" - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.Error(t, err) }) t.Run("create DHCP options with empty logical switch name", func(t *testing.T) { cidr := "192.168.70.0/24" - err := ovnClient.CreateDHCPOptions("", cidr, "") + err := nbClient.CreateDHCPOptions("", cidr, "") require.Error(t, err) }) } @@ -644,37 +644,37 @@ func (suite *OvnClientTestSuite) testDHCPOptionsExists() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-dhcp-opt-exists-ls" t.Run("DHCP options exist", func(t *testing.T) { cidr := "192.168.80.0/24" - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) - exists, err := ovnClient.DHCPOptionsExists(lsName, "IPv4") + exists, err := nbClient.DHCPOptionsExists(lsName, "IPv4") require.NoError(t, err) require.True(t, exists) }) t.Run("DHCP options do not exist", func(t *testing.T) { - exists, err := ovnClient.DHCPOptionsExists(lsName+"-1", "IPv4") + exists, err := nbClient.DHCPOptionsExists(lsName+"-1", "IPv4") require.NoError(t, err) require.False(t, exists) }) t.Run("DHCP options exist for IPv6", func(t *testing.T) { cidr := "fd00::c0a8:8001/120" - err := ovnClient.CreateDHCPOptions(lsName, cidr, "") + err := nbClient.CreateDHCPOptions(lsName, cidr, "") require.NoError(t, err) - exists, err := ovnClient.DHCPOptionsExists(lsName, "IPv6") + exists, err := nbClient.DHCPOptionsExists(lsName, "IPv6") require.NoError(t, err) require.True(t, exists) }) t.Run("DHCP options do not exist for IPv6", func(t *testing.T) { - exists, err := ovnClient.DHCPOptionsExists(lsName+"-1", "IPv6") + exists, err := nbClient.DHCPOptionsExists(lsName+"-1", "IPv6") require.NoError(t, err) require.False(t, exists) }) diff --git a/pkg/ovs/ovn-nb-gateway_chassis_test.go b/pkg/ovs/ovn-nb-gateway_chassis_test.go index 2f8c234e7f3..2784b4d60ff 100644 --- a/pkg/ovs/ovn-nb-gateway_chassis_test.go +++ b/pkg/ovs/ovn-nb-gateway_chassis_test.go @@ -11,28 +11,28 @@ func (suite *OvnClientTestSuite) testCreateGatewayChassises() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-create-gateway-chassises-lr" lrpName := "test-create-gateway-chassises-lrp" chassises := []string{"c7efec70-9519-4b03-8b67-057f2a95e5c7", "4a0891b6-fe81-4986-a367-aad0ea7ca9f3", "dcc2eda3-b3ea-4d53-afe0-7b6eaf7917ba"} - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) require.NoError(t, err) - err = ovnClient.CreateGatewayChassises(lrpName, chassises...) + err = nbClient.CreateGatewayChassises(lrpName, chassises...) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotNil(t, lrp) require.Len(t, lrp.GatewayChassis, len(chassises)) for i, chassisName := range chassises { gwChassisName := lrp.Name + "-" + chassisName - gwChassis, err := ovnClient.GetGatewayChassis(gwChassisName, false) + gwChassis, err := nbClient.GetGatewayChassis(gwChassisName, false) require.NoError(t, err) require.NotNil(t, gwChassis) require.Equal(t, gwChassisName, gwChassis.Name) @@ -46,31 +46,31 @@ func (suite *OvnClientTestSuite) testDeleteGatewayChassises() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-gateway-chassis-del-lr" lrpName := "test-gateway-chassis-del-lrp" chassises := []string{"ea8368a0-28cd-4549-9da5-a7ea67262619", "b25ffb94-8b32-4c7e-b5b0-0f343bf6bdd8", "62265268-8af7-4b36-a550-ab5ad38375e3"} - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) require.NoError(t, err) - err = ovnClient.CreateGatewayChassises(lrpName, chassises...) + err = nbClient.CreateGatewayChassises(lrpName, chassises...) require.NoError(t, err) - err = ovnClient.DeleteGatewayChassises(lrpName, append(chassises, "73bbe5d4-2b9b-47d0-aba8-94e86941881a")) + err = nbClient.DeleteGatewayChassises(lrpName, append(chassises, "73bbe5d4-2b9b-47d0-aba8-94e86941881a")) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotNil(t, lrp) require.Len(t, lrp.GatewayChassis, 0) for _, chassisName := range chassises { gwChassisName := lrpName + "-" + chassisName - _, err := ovnClient.GetGatewayChassis(gwChassisName, false) + _, err := nbClient.GetGatewayChassis(gwChassisName, false) require.ErrorContains(t, err, "object not found") } } @@ -79,25 +79,25 @@ func (suite *OvnClientTestSuite) testDeleteGatewayChassisOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-gateway-chassis-del-op-lr" lrpName := "test-gateway-chassis-del-op-lrp" chassis := "6c322ce8-02b7-42b3-925b-ae24020272a9" gwChassisName := lrpName + "-" + chassis - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) require.NoError(t, err) - err = ovnClient.CreateGatewayChassises(lrpName, chassis) + err = nbClient.CreateGatewayChassises(lrpName, chassis) require.NoError(t, err) - gwChassis, err := ovnClient.GetGatewayChassis(gwChassisName, false) + gwChassis, err := nbClient.GetGatewayChassis(gwChassisName, false) require.NoError(t, err) - uuid, ops, err := ovnClient.DeleteGatewayChassisOp(gwChassisName) + uuid, ops, err := nbClient.DeleteGatewayChassisOp(gwChassisName) require.NoError(t, err) require.Equal(t, gwChassis.UUID, uuid) require.Len(t, ops, 1) diff --git a/pkg/ovs/ovn-nb-load_balancer_test.go b/pkg/ovs/ovn-nb-load_balancer_test.go index 861b141127c..39452c32244 100644 --- a/pkg/ovs/ovn-nb-load_balancer_test.go +++ b/pkg/ovs/ovn-nb-load_balancer_test.go @@ -18,13 +18,13 @@ func (suite *OvnClientTestSuite) testCreateLoadBalancer() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lbName := "test-create-lb" - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Equal(t, lbName, lb.Name) require.NotEmpty(t, lb.UUID) @@ -32,7 +32,7 @@ func (suite *OvnClientTestSuite) testCreateLoadBalancer() { require.ElementsMatch(t, []string{"ip_dst"}, lb.SelectionFields) // should no err create lb repeatedly - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) } @@ -40,13 +40,13 @@ func (suite *OvnClientTestSuite) testUpdateLoadBalancer() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lbName := "test-update-lb" - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) t.Run("update vips", func(t *testing.T) { @@ -56,10 +56,10 @@ func (suite *OvnClientTestSuite) testUpdateLoadBalancer() { "[fd00:10:96::e83f]:8080": "[fc00::af4:f]:8080,[fc00::af4:10]:8080,[fc00::af4:11]:8080", } - err := ovnClient.UpdateLoadBalancer(lb, &lb.Vips) + err := nbClient.UpdateLoadBalancer(lb, &lb.Vips) require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Equal(t, map[string]string{ @@ -72,10 +72,10 @@ func (suite *OvnClientTestSuite) testUpdateLoadBalancer() { t.Run("clear vips", func(t *testing.T) { lb.Vips = nil - err := ovnClient.UpdateLoadBalancer(lb, &lb.Vips) + err := nbClient.UpdateLoadBalancer(lb, &lb.Vips) require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Nil(t, lb.Vips) @@ -86,25 +86,25 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancers() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lbNamePrefix := "test-del-lbs" lbNames := make([]string, 0, 5) for i := 0; i < 5; i++ { lbName := fmt.Sprintf("%s-%d", lbNamePrefix, i) - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) lbNames = append(lbNames, lbName) } - err := ovnClient.DeleteLoadBalancers(func(lb *ovnnb.LoadBalancer) bool { + err := nbClient.DeleteLoadBalancers(func(lb *ovnnb.LoadBalancer) bool { return slices.Contains(lbNames, lb.Name) }) require.NoError(t, err) for _, lbName := range lbNames { - _, err := ovnClient.GetLoadBalancer(lbName, false) + _, err := nbClient.GetLoadBalancer(lbName, false) require.ErrorContains(t, err, "not found load balancer") } } @@ -113,16 +113,16 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancer() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lbName := "test-del-lb" - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) - err = ovnClient.DeleteLoadBalancer(lbName) + err = nbClient.DeleteLoadBalancer(lbName) require.NoError(t, err) - _, err = ovnClient.GetLoadBalancer(lbName, false) + _, err = nbClient.GetLoadBalancer(lbName, false) require.ErrorContains(t, err, "not found load balancer") } @@ -130,15 +130,15 @@ func (suite *OvnClientTestSuite) testGetLoadBalancer() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lbName := "test-get-lb" - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) t.Run("should return no err when found load balancer", func(t *testing.T) { t.Parallel() - lr, err := ovnClient.GetLoadBalancer(lbName, false) + lr, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Equal(t, lbName, lr.Name) require.NotEmpty(t, lr.UUID) @@ -146,13 +146,13 @@ func (suite *OvnClientTestSuite) testGetLoadBalancer() { t.Run("should return err when not found load balancer", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetLoadBalancer("test-get-lb-non-existent", false) + _, err := nbClient.GetLoadBalancer("test-get-lb-non-existent", false) require.ErrorContains(t, err, "not found load balancer") }) t.Run("no err when not found load balancerand ignoreNotFound is true", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetLoadBalancer("test-get-lr-non-existent", true) + _, err := nbClient.GetLoadBalancer("test-get-lr-non-existent", true) require.NoError(t, err) }) } @@ -161,7 +161,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancers() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lbNamePrefix := "test-list-lbs" lbNames := make([]string, 0, 3) protocol := []string{"tcp", "udp"} @@ -169,7 +169,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancers() { for i := 0; i < 3; i++ { for _, p := range protocol { lbName := fmt.Sprintf("%s-%s-%d", lbNamePrefix, p, i) - err := ovnClient.CreateLoadBalancer(lbName, p, "") + err := nbClient.CreateLoadBalancer(lbName, p, "") require.NoError(t, err) lbNames = append(lbNames, lbName) @@ -179,7 +179,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancers() { t.Run("has no custom filter", func(t *testing.T) { t.Parallel() - lbs, err := ovnClient.ListLoadBalancers(nil) + lbs, err := nbClient.ListLoadBalancers(nil) require.NoError(t, err) require.NotEmpty(t, lbs) @@ -201,7 +201,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancers() { except := lbNames[1:] - lbs, err := ovnClient.ListLoadBalancers(func(lb *ovnnb.LoadBalancer) bool { + lbs, err := nbClient.ListLoadBalancers(func(lb *ovnnb.LoadBalancer) bool { return !slices.Contains(except, lb.Name) }) require.NoError(t, err) @@ -222,7 +222,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancers() { t.Parallel() for _, p := range protocol { - lbs, err := ovnClient.ListLoadBalancers(func(lb *ovnnb.LoadBalancer) bool { + lbs, err := nbClient.ListLoadBalancers(func(lb *ovnnb.LoadBalancer) bool { return *lb.Protocol == p }) require.NoError(t, err) @@ -244,19 +244,19 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lbName := "test-del-lb-op" - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) t.Run("normal delete", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.DeleteLoadBalancerOp(lbName) + ops, err := nbClient.DeleteLoadBalancerOp(lbName) require.NoError(t, err) require.Len(t, ops, 1) @@ -279,7 +279,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerOp() { t.Run("return ops is empty when delete non-existent load balancer", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.DeleteLoadBalancerOp(lbName + "-non-existent") + ops, err := nbClient.DeleteLoadBalancerOp(lbName + "-non-existent") require.NoError(t, err) require.Len(t, ops, 0) }) @@ -289,37 +289,37 @@ func (suite *OvnClientTestSuite) testSetLoadBalancerAffinityTimeout() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lbName := "test-set-lb-affinity-timeout" - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) oldOptions := make(map[string]string, 1) oldOptions["stateless"] = "true" lb.Options = oldOptions - err = ovnClient.UpdateLoadBalancer(lb, &lb.Options) + err = nbClient.UpdateLoadBalancer(lb, &lb.Options) require.NoError(t, err) expectedTimeout := 30 t.Run("add new affinity timeout to load balancer options", func(t *testing.T) { - err := ovnClient.SetLoadBalancerAffinityTimeout(lbName, expectedTimeout) + err := nbClient.SetLoadBalancerAffinityTimeout(lbName, expectedTimeout) require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Equal(t, lb.Options["affinity_timeout"], strconv.Itoa(expectedTimeout)) }) t.Run("add new affinityTimeout to load balancer options repeatedly", func(t *testing.T) { - err := ovnClient.SetLoadBalancerAffinityTimeout(lbName, expectedTimeout) + err := nbClient.SetLoadBalancerAffinityTimeout(lbName, expectedTimeout) require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Equal(t, lb.Options["affinity_timeout"], strconv.Itoa(expectedTimeout)) @@ -331,17 +331,17 @@ func (suite *OvnClientTestSuite) testLoadBalancerAddVip() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbName = "test-lb-add-vip" vips, expectedVips map[string]string lb *ovnnb.LoadBalancer err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) - _, err = ovnClient.GetLoadBalancer(lbName, false) + _, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) vips = map[string]string{ @@ -354,13 +354,13 @@ func (suite *OvnClientTestSuite) testLoadBalancerAddVip() { t.Run("add new vips to load balancer", func(t *testing.T) { for vip, backends := range vips { - err = ovnClient.LoadBalancerAddVip(lbName, vip, strings.Split(backends, ",")...) + err = nbClient.LoadBalancerAddVip(lbName, vip, strings.Split(backends, ",")...) require.NoError(t, err) expectedVips[vip] = backends } - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Equal(t, lb.Vips, expectedVips) @@ -375,13 +375,13 @@ func (suite *OvnClientTestSuite) testLoadBalancerAddVip() { t.Run("add new vips to load balancer repeatedly", func(t *testing.T) { for vip, backends := range vips { - err := ovnClient.LoadBalancerAddVip(lbName, vip, strings.Split(backends, ",")...) + err := nbClient.LoadBalancerAddVip(lbName, vip, strings.Split(backends, ",")...) require.NoError(t, err) expectedVips[vip] = backends } - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Equal(t, lb.Vips, expectedVips) @@ -394,7 +394,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteVip() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbName = "test-lb-del-vip" vips map[string]string deletedVips []string @@ -402,10 +402,10 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteVip() { err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) - _, err = ovnClient.GetLoadBalancer(lbName, false) + _, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) vips = map[string]string{ @@ -415,7 +415,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteVip() { } ignoreHealthCheck := true for vip, backends := range vips { - err = ovnClient.LoadBalancerAddVip(lbName, vip, strings.Split(backends, ",")...) + err = nbClient.LoadBalancerAddVip(lbName, vip, strings.Split(backends, ",")...) require.NoError(t, err) } @@ -426,12 +426,12 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteVip() { } for _, vip := range deletedVips { - err = ovnClient.LoadBalancerDeleteVip(lbName, vip, ignoreHealthCheck) + err = nbClient.LoadBalancerDeleteVip(lbName, vip, ignoreHealthCheck) require.NoError(t, err) delete(vips, vip) } - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Equal(t, vips, lb.Vips) } @@ -441,17 +441,17 @@ func (suite *OvnClientTestSuite) testLoadBalancerAddIPPortMapping() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbName = "test-lb-add-ip-port-mapping" vips, mappings map[string]string lb *ovnnb.LoadBalancer err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) - _, err = ovnClient.GetLoadBalancer(lbName, false) + _, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) vips = map[string]string{ @@ -475,13 +475,13 @@ func (suite *OvnClientTestSuite) testLoadBalancerAddIPPortMapping() { mappings[host] = host } - err = ovnClient.LoadBalancerAddVip(lbName, vip, list...) + err = nbClient.LoadBalancerAddVip(lbName, vip, list...) require.NoError(t, err) - err = ovnClient.LoadBalancerAddIPPortMapping(lbName, vip, mappings) + err = nbClient.LoadBalancerAddIPPortMapping(lbName, vip, mappings) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) for _, backend := range list { @@ -514,13 +514,13 @@ func (suite *OvnClientTestSuite) testLoadBalancerAddIPPortMapping() { mappings[host] = host } - err = ovnClient.LoadBalancerAddVip(lbName, vip, list...) + err = nbClient.LoadBalancerAddVip(lbName, vip, list...) require.NoError(t, err) - err = ovnClient.LoadBalancerAddIPPortMapping(lbName, vip, mappings) + err = nbClient.LoadBalancerAddIPPortMapping(lbName, vip, mappings) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) for _, backend := range list { @@ -539,17 +539,17 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteIPPortMapping() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbName = "test-lb-del-ip-port-mapping" vips, mappings map[string]string lb *ovnnb.LoadBalancer err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) - _, err = ovnClient.GetLoadBalancer(lbName, false) + _, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) vips = map[string]string{ @@ -576,13 +576,13 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteIPPortMapping() { vhost, _, err = net.SplitHostPort(vip) require.NoError(t, err) - err = ovnClient.LoadBalancerAddVip(lbName, vhost, strings.Split(backends, ",")...) + err = nbClient.LoadBalancerAddVip(lbName, vhost, strings.Split(backends, ",")...) require.NoError(t, err) - err = ovnClient.LoadBalancerAddIPPortMapping(lbName, vhost, mappings) + err = nbClient.LoadBalancerAddIPPortMapping(lbName, vhost, mappings) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) for _, backend := range list { @@ -592,10 +592,10 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteIPPortMapping() { require.Contains(t, lb.IPPortMappings, backend) } - err = ovnClient.LoadBalancerDeleteIPPortMapping(lbName, vip) + err = nbClient.LoadBalancerDeleteIPPortMapping(lbName, vip) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) for _, backend := range list { @@ -605,7 +605,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteIPPortMapping() { require.NotContains(t, lb.IPPortMappings, backend) } - err = ovnClient.LoadBalancerAddIPPortMapping(lbName, vhost, mappings) + err = nbClient.LoadBalancerAddIPPortMapping(lbName, vhost, mappings) require.NoError(t, err) } }, @@ -621,10 +621,10 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteIPPortMapping() { list := strings.Split(backends, ",") mappings = make(map[string]string) - err = ovnClient.LoadBalancerDeleteIPPortMapping(lbName, vip) + err = nbClient.LoadBalancerDeleteIPPortMapping(lbName, vip) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) for _, backend := range list { @@ -643,10 +643,10 @@ func (suite *OvnClientTestSuite) testLoadBalancerDeleteIPPortMapping() { t.Run("delete ip port mappings from load balancer repeatedly", func(t *testing.T) { for vip := range vips { - err = ovnClient.LoadBalancerDeleteIPPortMapping(lbName, vip) + err = nbClient.LoadBalancerDeleteIPPortMapping(lbName, vip) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) } }, @@ -658,7 +658,7 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbName = "test-lb-with-health-check" vips, mappings map[string]string lb *ovnnb.LoadBalancer @@ -667,10 +667,10 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) - _, err = ovnClient.GetLoadBalancer(lbName, false) + _, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) vips = map[string]string{ @@ -694,13 +694,13 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { mappings[host] = host } - err = ovnClient.LoadBalancerAddVip(lbName, vip, list...) + err = nbClient.LoadBalancerAddVip(lbName, vip, list...) require.NoError(t, err) - err = ovnClient.LoadBalancerAddIPPortMapping(lbName, vip, mappings) + err = nbClient.LoadBalancerAddIPPortMapping(lbName, vip, mappings) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) for _, backend := range list { @@ -733,10 +733,10 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { mappings[host] = host } - err = ovnClient.LoadBalancerUpdateIPPortMapping(lbName, vip, mappings) + err = nbClient.LoadBalancerUpdateIPPortMapping(lbName, vip, mappings) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) for _, backend := range list { @@ -752,12 +752,12 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { vip = "10.96.0.6:443" t.Run("add new health check to load balancer", func(t *testing.T) { - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) - _, lbhc, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhc, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) lbhcID = lbhc.UUID require.Contains(t, lb.HealthCheck, lbhcID) @@ -766,11 +766,11 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { t.Run("add new health check to load balancer repeatedly", func(t *testing.T) { - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) - _, lbhc, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhc, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) require.Contains(t, lb.HealthCheck, lbhcID) }, @@ -778,10 +778,10 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { t.Run("delete health check from load balancer", func(t *testing.T) { - err = ovnClient.LoadBalancerDeleteHealthCheck(lbName, lbhcID) + err = nbClient.LoadBalancerDeleteHealthCheck(lbName, lbhcID) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.NotContains(t, lb.HealthCheck, lbhcID) }, @@ -789,10 +789,10 @@ func (suite *OvnClientTestSuite) testLoadBalancerWithHealthCheck() { t.Run("delete health check from load balancer repeatedly", func(t *testing.T) { - err = ovnClient.LoadBalancerDeleteHealthCheck(lbName, lbhcID) + err = nbClient.LoadBalancerDeleteHealthCheck(lbName, lbhcID) require.NoError(t, err) - lb, err = ovnClient.GetLoadBalancer(lbName, false) + lb, err = nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.NotContains(t, lb.HealthCheck, lbhcID) }, diff --git a/pkg/ovs/ovn-nb-logical_router_policy_test.go b/pkg/ovs/ovn-nb-logical_router_policy_test.go index 261dea5c580..b571db7c4bd 100644 --- a/pkg/ovs/ovn-nb-logical_router_policy_test.go +++ b/pkg/ovs/ovn-nb-logical_router_policy_test.go @@ -26,28 +26,28 @@ func (suite *OvnClientTestSuite) testAddLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-add-policy-lr" priority := 11011 match := "ip4.src == $ovn.default.lm2_ip4" action := ovnnb.LogicalRouterPolicyActionAllow nextHops := []string{"100.64.0.2"} - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, nil) + err = nbClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, nil) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - policyList, err := ovnClient.GetLogicalRouterPolicy(lrName, priority, match, false) + policyList, err := nbClient.GetLogicalRouterPolicy(lrName, priority, match, false) require.NoError(t, err) require.Len(t, policyList, 1) require.Contains(t, lr.Policies, policyList[0].UUID) - err = ovnClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, nil) + err = nbClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, nil) require.NoError(t, err) } @@ -55,7 +55,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPolicies() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-create-policies-lr" priority := 11011 basePort := 12300 @@ -63,25 +63,25 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPolicies() { action := ovnnb.LogicalRouterPolicyActionAllow policies := make([]*ovnnb.LogicalRouterPolicy, 0, 3) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("add policies to logical router", func(t *testing.T) { for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - policy := ovnClient.newLogicalRouterPolicy(priority, match, action, nil, nil) + policy := nbClient.newLogicalRouterPolicy(priority, match, action, nil, nil) policies = append(policies, policy) } - err = ovnClient.CreateLogicalRouterPolicies(lrName, append(policies, nil)...) + err = nbClient.CreateLogicalRouterPolicies(lrName, append(policies, nil)...) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for i := 0; i < 3; i++ { match := fmt.Sprintf("%s && tcp.dst == %d", matchPrefix, basePort+i) - policyList, err := ovnClient.GetLogicalRouterPolicy(lrName, priority, match, false) + policyList, err := nbClient.GetLogicalRouterPolicy(lrName, priority, match, false) require.NoError(t, err) require.Len(t, policyList, 1) require.Equal(t, match, policyList[0].Match) @@ -94,35 +94,35 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-del-policy-lr" priority := 11012 match := "ip4.src == $ovn.default.lm2_ip4" action := ovnnb.LogicalRouterPolicyActionAllow nextHops := []string{"100.64.0.2"} - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, nil) + err = nbClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, nil) require.NoError(t, err) t.Run("no err when delete existent logical switch port", func(t *testing.T) { - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - policyList, err := ovnClient.GetLogicalRouterPolicy(lrName, priority, match, false) + policyList, err := nbClient.GetLogicalRouterPolicy(lrName, priority, match, false) require.NoError(t, err) require.Len(t, policyList, 1) require.Contains(t, lr.Policies, policyList[0].UUID) - err = ovnClient.DeleteLogicalRouterPolicy(lrName, priority, match) + err = nbClient.DeleteLogicalRouterPolicy(lrName, priority, match) require.NoError(t, err) - _, err = ovnClient.GetLogicalRouterPolicy(lrName, priority, match, false) + _, err = nbClient.GetLogicalRouterPolicy(lrName, priority, match, false) require.ErrorContains(t, err, "not found policy") - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.NotContains(t, lr.Policies, policyList[0].UUID) }) @@ -132,7 +132,7 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPolicies() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-clear-policies-lr" basePriority := 12100 match := "ip4.src == $ovn.default.lm2_ip4" @@ -145,21 +145,21 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPolicies() { "isU2ORoutePolicy": "true", } - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) prepare := func() { for i := 0; i < 3; i++ { priority := basePriority + i - err = ovnClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, externalIDs) + err = nbClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, externalIDs) require.NoError(t, err) } - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Policies, 3) - policies, err := ovnClient.ListLogicalRouterPolicies(lrName, -1, externalIDs, true) + policies, err := nbClient.ListLogicalRouterPolicies(lrName, -1, externalIDs, true) require.NoError(t, err) require.Len(t, policies, 3) } @@ -167,14 +167,14 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPolicies() { t.Run("delete some policies with different priority", func(t *testing.T) { prepare() - err = ovnClient.DeleteLogicalRouterPolicies(lrName, -1, externalIDs) + err = nbClient.DeleteLogicalRouterPolicies(lrName, -1, externalIDs) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.Policies) - policies, err := ovnClient.ListLogicalRouterPolicies(lrName, -1, externalIDs, true) + policies, err := nbClient.ListLogicalRouterPolicies(lrName, -1, externalIDs, true) require.NoError(t, err) require.Empty(t, policies) }) @@ -182,15 +182,15 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPolicies() { t.Run("delete same priority", func(t *testing.T) { prepare() - err = ovnClient.DeleteLogicalRouterPolicies(lrName, basePriority, externalIDs) + err = nbClient.DeleteLogicalRouterPolicies(lrName, basePriority, externalIDs) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Policies, 2) // no basePriority policy - policies, err := ovnClient.ListLogicalRouterPolicies(lrName, -1, externalIDs, true) + policies, err := nbClient.ListLogicalRouterPolicies(lrName, -1, externalIDs, true) require.NoError(t, err) require.Len(t, policies, 2) }) @@ -200,42 +200,42 @@ func (suite *OvnClientTestSuite) testClearLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-clear-policy-lr" basePriority := 11012 match := "ip4.src == $ovn.default.lm2_ip4" action := ovnnb.LogicalRouterPolicyActionAllow nextHops := []string{"100.64.0.2"} - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) for i := 0; i < 3; i++ { priority := basePriority + i - err = ovnClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, nil) + err = nbClient.AddLogicalRouterPolicy(lrName, priority, match, action, nextHops, nil) require.NoError(t, err) } - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Policies, 3) for i := 0; i < 3; i++ { priority := basePriority + i - _, err = ovnClient.GetLogicalRouterPolicy(lrName, priority, match, false) + _, err = nbClient.GetLogicalRouterPolicy(lrName, priority, match, false) require.NoError(t, err) } - err = ovnClient.ClearLogicalRouterPolicy(lrName) + err = nbClient.ClearLogicalRouterPolicy(lrName) require.NoError(t, err) for i := 0; i < 3; i++ { priority := basePriority + i - _, err = ovnClient.GetLogicalRouterPolicy(lrName, priority, match, false) + _, err = nbClient.GetLogicalRouterPolicy(lrName, priority, match, false) require.ErrorContains(t, err, "not found policy") } - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.Policies) } @@ -244,20 +244,20 @@ func (suite *OvnClientTestSuite) testGetLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test_get_policy_lr" priority := 11000 match := "ip4.src == $ovn.default.lm2_ip4" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.AddLogicalRouterPolicy(lrName, priority, match, ovnnb.LogicalRouterPolicyActionAllow, nil, nil) + err = nbClient.AddLogicalRouterPolicy(lrName, priority, match, ovnnb.LogicalRouterPolicyActionAllow, nil, nil) require.NoError(t, err) t.Run("priority and match are same", func(t *testing.T) { t.Parallel() - policyList, err := ovnClient.GetLogicalRouterPolicy(lrName, priority, match, false) + policyList, err := nbClient.GetLogicalRouterPolicy(lrName, priority, match, false) require.NoError(t, err) require.Len(t, policyList, 1) require.Equal(t, priority, policyList[0].Priority) @@ -268,24 +268,24 @@ func (suite *OvnClientTestSuite) testGetLogicalRouterPolicy() { t.Run("priority and match are not all same", func(t *testing.T) { t.Parallel() - _, err = ovnClient.GetLogicalRouterPolicy(lrName, 10010, match, false) + _, err = nbClient.GetLogicalRouterPolicy(lrName, 10010, match, false) require.ErrorContains(t, err, "not found policy") - _, err = ovnClient.GetLogicalRouterPolicy(lrName, priority, match+" && tcp", false) + _, err = nbClient.GetLogicalRouterPolicy(lrName, priority, match+" && tcp", false) require.ErrorContains(t, err, "not found policy") }) t.Run("should no err when priority and match are not all same but ignoreNotFound=true", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetLogicalRouterPolicy(lrName, priority, match, true) + _, err := nbClient.GetLogicalRouterPolicy(lrName, priority, match, true) require.NoError(t, err) }) t.Run("no policy belongs to parent exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetLogicalRouterPolicy(lrName+"_1", priority, match, false) + _, err := nbClient.GetLogicalRouterPolicy(lrName+"_1", priority, match, false) require.ErrorContains(t, err, "not found logical router") }) } @@ -294,14 +294,14 @@ func (suite *OvnClientTestSuite) testNewLogicalRouterPolicy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-new-policy-lr" priority := 10000 match := "ip4.src == $ovn.default.lm2_ip4" nextHops := []string{"100.64.0.2"} action := ovnnb.LogicalRouterPolicyActionAllow - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) expect := &ovnnb.LogicalRouterPolicy{ @@ -312,7 +312,7 @@ func (suite *OvnClientTestSuite) testNewLogicalRouterPolicy() { ExternalIDs: map[string]string{"key": "value"}, } - policy := ovnClient.newLogicalRouterPolicy(priority, match, action, nextHops, map[string]string{"key": "value"}) + policy := nbClient.newLogicalRouterPolicy(priority, match, action, nextHops, map[string]string{"key": "value"}) expect.UUID = policy.UUID require.Equal(t, expect, policy) } diff --git a/pkg/ovs/ovn-nb-logical_router_port_test.go b/pkg/ovs/ovn-nb-logical_router_port_test.go index 5b7f9328daf..f646705cf99 100644 --- a/pkg/ovs/ovn-nb-logical_router_port_test.go +++ b/pkg/ovs/ovn-nb-logical_router_port_test.go @@ -29,36 +29,36 @@ func (suite *OvnClientTestSuite) testCreatePeerRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient localLrName := "test-create-peer-lr-local" remoteLrName := "test-create-peer-lr-remote" localRouterPort := fmt.Sprintf("%s-%s", localLrName, remoteLrName) remoteRouterPort := fmt.Sprintf("%s-%s", remoteLrName, localLrName) - err := ovnClient.CreateLogicalRouter(localLrName) + err := nbClient.CreateLogicalRouter(localLrName) require.NoError(t, err) t.Run("create new port", func(t *testing.T) { - err = ovnClient.CreatePeerRouterPort(localLrName, remoteLrName, "192.168.230.1/24,192.168.231.1/24") + err = nbClient.CreatePeerRouterPort(localLrName, remoteLrName, "192.168.230.1/24,192.168.231.1/24") require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(localRouterPort, false) + lrp, err := nbClient.GetLogicalRouterPort(localRouterPort, false) require.NoError(t, err) require.NotEmpty(t, lrp.UUID) require.Equal(t, localLrName, lrp.ExternalIDs[logicalRouterKey]) require.ElementsMatch(t, []string{"192.168.230.1/24", "192.168.231.1/24"}, lrp.Networks) require.Equal(t, remoteRouterPort, *lrp.Peer) - lr, err := ovnClient.GetLogicalRouter(localLrName, false) + lr, err := nbClient.GetLogicalRouter(localLrName, false) require.NoError(t, err) require.ElementsMatch(t, []string{lrp.UUID}, lr.Ports) }) t.Run("update port networks", func(t *testing.T) { - err = ovnClient.CreatePeerRouterPort(localLrName, remoteLrName, "192.168.230.1/24,192.168.241.1/24") + err = nbClient.CreatePeerRouterPort(localLrName, remoteLrName, "192.168.230.1/24,192.168.241.1/24") require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(localRouterPort, false) + lrp, err := nbClient.GetLogicalRouterPort(localRouterPort, false) require.NoError(t, err) require.NotEmpty(t, lrp.UUID) require.ElementsMatch(t, []string{"192.168.230.1/24", "192.168.241.1/24"}, lrp.Networks) @@ -70,21 +70,21 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPortRA() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-update-ra-lrp" lrName := "test-update-ra-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) require.NoError(t, err) t.Run("update ipv6 ra config when enableIPv6RA is true and ipv6RAConfigsStr is empty", func(t *testing.T) { - err := ovnClient.UpdateLogicalRouterPortRA(lrpName, "", true) + err := nbClient.UpdateLogicalRouterPortRA(lrpName, "", true) require.NoError(t, err) - out, err := ovnClient.GetLogicalRouterPort(lrpName, false) + out, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"120"}, out.Ipv6Prefix) require.Equal(t, map[string]string{ @@ -96,10 +96,10 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPortRA() { }) t.Run("update ipv6 ra config when enableIPv6RA is true and exist ipv6RAConfigsStr", func(t *testing.T) { - err := ovnClient.UpdateLogicalRouterPortRA(lrpName, "address_mode=dhcpv6_stateful,max_interval=30", true) + err := nbClient.UpdateLogicalRouterPortRA(lrpName, "address_mode=dhcpv6_stateful,max_interval=30", true) require.NoError(t, err) - out, err := ovnClient.GetLogicalRouterPort(lrpName, false) + out, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"120"}, out.Ipv6Prefix) require.Equal(t, map[string]string{ @@ -109,26 +109,26 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPortRA() { }) t.Run("update ipv6 ra config when enableIPv6RA is false", func(t *testing.T) { - err := ovnClient.UpdateLogicalRouterPortRA(lrpName, "address_mode=dhcpv6_stateful,max_interval=30", false) + err := nbClient.UpdateLogicalRouterPortRA(lrpName, "address_mode=dhcpv6_stateful,max_interval=30", false) require.NoError(t, err) - out, err := ovnClient.GetLogicalRouterPort(lrpName, false) + out, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Empty(t, out.Ipv6Prefix) require.Empty(t, out.Ipv6RaConfigs) }) t.Run("do nothing when enableIPv6RA is true and ipv6RAConfigsStr is invalid", func(t *testing.T) { - err := ovnClient.UpdateLogicalRouterPortRA(lrpName, "address_mode=,test", true) + err := nbClient.UpdateLogicalRouterPortRA(lrpName, "address_mode=,test", true) require.NoError(t, err) }) t.Run("do nothing when enableIPv6RA is true and no ipv6 network", func(t *testing.T) { lrpName := "test-update-ra-lr-no-ipv6" - err := ovnClient.CreateLogicalRouterPort(lrName, lrpName, "", nil) + err := nbClient.CreateLogicalRouterPort(lrName, lrpName, "", nil) require.NoError(t, err) - err = ovnClient.UpdateLogicalRouterPortRA(lrpName, "address_mode=dhcpv6_stateful,max_interval=30", true) + err = nbClient.UpdateLogicalRouterPortRA(lrpName, "address_mode=dhcpv6_stateful,max_interval=30", true) require.NoError(t, err) }) } @@ -137,7 +137,7 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPortOptions() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-update-lrp-opt" lrName := "test-update-lrp-opt-lr" options := map[string]string{ @@ -145,44 +145,44 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPortOptions() { "k2": "v2", } - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:1001/120"}) require.NoError(t, err) t.Run("add logical router port options", func(t *testing.T) { - err := ovnClient.UpdateLogicalRouterPortOptions(lrpName, options) + err := nbClient.UpdateLogicalRouterPortOptions(lrpName, options) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Equal(t, options, lrp.Options) }) t.Run("remove logical router port options", func(t *testing.T) { - err := ovnClient.UpdateLogicalRouterPortOptions(lrpName, options) + err := nbClient.UpdateLogicalRouterPortOptions(lrpName, options) require.NoError(t, err) - err = ovnClient.UpdateLogicalRouterPortOptions(lrpName, map[string]string{"k2": ""}) + err = nbClient.UpdateLogicalRouterPortOptions(lrpName, map[string]string{"k2": ""}) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Equal(t, map[string]string{"k1": "v1"}, lrp.Options) }) t.Run("update logical router port options", func(t *testing.T) { - err := ovnClient.UpdateLogicalRouterPortOptions(lrpName, options) + err := nbClient.UpdateLogicalRouterPortOptions(lrpName, options) require.NoError(t, err) - err = ovnClient.UpdateLogicalRouterPortOptions(lrpName, map[string]string{ + err = nbClient.UpdateLogicalRouterPortOptions(lrpName, map[string]string{ "k2": "", "k3": "v3", }) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Equal(t, map[string]string{"k1": "v1", "k3": "v3"}, lrp.Options) }) @@ -192,10 +192,10 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-create-lrp-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("create new logical router port with ipv4", func(t *testing.T) { @@ -203,16 +203,16 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPort() { lrpName := "test-create-lrp-ipv4" - err := ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) + err := nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotEmpty(t, lrp.UUID) require.Equal(t, "00:11:22:37:af:62", lrp.MAC) require.ElementsMatch(t, []string{"192.168.123.1/24"}, lrp.Networks) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Contains(t, lr.Ports, lrp.UUID) }) @@ -222,16 +222,16 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPort() { lrpName := "test-create-lrp-ipv6" - err := ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:7b01/120"}) + err := nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"fd00::c0a8:7b01/120"}) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotEmpty(t, lrp.UUID) require.Equal(t, "00:11:22:37:af:62", lrp.MAC) require.ElementsMatch(t, []string{"fd00::c0a8:7b01/120"}, lrp.Networks) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Contains(t, lr.Ports, lrp.UUID) }) @@ -240,16 +240,16 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPort() { t.Parallel() lrpName := "test-create-lrp-dual" - err := ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24", "fd00::c0a8:7b01/120"}) + err := nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24", "fd00::c0a8:7b01/120"}) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotEmpty(t, lrp.UUID) require.Equal(t, "00:11:22:37:af:62", lrp.MAC) require.ElementsMatch(t, []string{"192.168.123.1/24", "fd00::c0a8:7b01/120"}, lrp.Networks) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Contains(t, lr.Ports, lrp.UUID) }) @@ -259,14 +259,14 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-update-lrp" lrName := "test-update-lrp-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) require.NoError(t, err) t.Run("normal update", func(t *testing.T) { @@ -274,10 +274,10 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPort() { Name: lrpName, Networks: []string{"192.168.123.1/24", "192.168.125.1/24"}, } - err = ovnClient.UpdateLogicalRouterPort(lrp) + err = nbClient.UpdateLogicalRouterPort(lrp) require.NoError(t, err) - lrp, err = ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err = nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"192.168.123.1/24", "192.168.125.1/24"}, lrp.Networks) }) @@ -287,10 +287,10 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouterPort() { Name: lrpName, Networks: nil, } - err = ovnClient.UpdateLogicalRouterPort(lrp, &lrp.Networks) + err = nbClient.UpdateLogicalRouterPort(lrp, &lrp.Networks) require.NoError(t, err) - lrp, err = ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err = nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Empty(t, lrp.Networks) }) @@ -300,36 +300,36 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient prefix := "test-del-ports-lrp" lrName := "test-del-ports-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) for i := 0; i < 3; i++ { lrpName := fmt.Sprintf("%s-%d", prefix, i) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) require.NoError(t, err) } - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for i := 0; i < 3; i++ { lrpName := fmt.Sprintf("%s-%d", prefix, i) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Contains(t, lr.Ports, lrp.UUID) } - err = ovnClient.DeleteLogicalRouterPorts(nil, func(lrp *ovnnb.LogicalRouterPort) bool { + err = nbClient.DeleteLogicalRouterPorts(nil, func(lrp *ovnnb.LogicalRouterPort) bool { return len(lrp.ExternalIDs) != 0 && lrp.ExternalIDs[logicalRouterKey] == lrName }) require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.Ports) } @@ -338,34 +338,34 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-delete-port-lrp" lrName := "test-delete-port-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) require.NoError(t, err) t.Run("no err when delete existent logical router port", func(t *testing.T) { - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Contains(t, lr.Ports, lrp.UUID) - err = ovnClient.DeleteLogicalRouterPort(lrpName) + err = nbClient.DeleteLogicalRouterPort(lrpName) require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.NotContains(t, lr.Ports, lrp.UUID) }) t.Run("no err when delete non-existent logical router port", func(t *testing.T) { - err := ovnClient.DeleteLogicalRouterPort("test-delete-lrp-non-existent") + err := nbClient.DeleteLogicalRouterPort("test-delete-lrp-non-existent") require.NoError(t, err) }) } @@ -374,11 +374,11 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-create-op-lrp" lrName := "test-create-op-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("merge ExternalIDs when exist ExternalIDs", func(t *testing.T) { @@ -390,7 +390,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPortOp() { }, } - ops, err := ovnClient.CreateLogicalRouterPortOp(lrp, lrName) + ops, err := nbClient.CreateLogicalRouterPortOp(lrp, lrName) require.NoError(t, err) require.Len(t, ops, 2) require.Equal(t, ovsdb.OvsMap{ @@ -424,7 +424,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterPortOp() { Name: lrpName, } - ops, err := ovnClient.CreateLogicalRouterPortOp(lrp, lrName) + ops, err := nbClient.CreateLogicalRouterPortOp(lrp, lrName) require.NoError(t, err) require.Len(t, ops, 2) @@ -455,20 +455,20 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrpName := "test-del-op-lrp" lrName := "test-del-op-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, "00:11:22:37:af:62", []string{"192.168.123.1/24"}) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) - ops, err := ovnClient.DeleteLogicalRouterPortOp(lrpName) + ops, err := nbClient.DeleteLogicalRouterPortOp(lrpName) require.NoError(t, err) require.Len(t, ops, 1) @@ -492,17 +492,17 @@ func (suite *OvnClientTestSuite) testLogicalRouterPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-op-lrp-lr" lrpName := "test-op-lrp-lrp" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalRouterPort(lrName, lrpName, util.GenerateMac(), []string{"172.177.19.1/24"}) + err = nbClient.CreateLogicalRouterPort(lrName, lrpName, util.GenerateMac(), []string{"172.177.19.1/24"}) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotNil(t, lrp) require.ElementsMatch(t, lrp.Networks, []string{"172.177.19.1/24"}) @@ -515,7 +515,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterPortOp() { } } - ops, err := ovnClient.LogicalRouterPortOp(lrpName, mutation) + ops, err := nbClient.LogicalRouterPortOp(lrpName, mutation) require.NoError(t, err) require.Len(t, ops, 1) require.Len(t, ops[0].Mutations, 1) diff --git a/pkg/ovs/ovn-nb-logical_router_route_test.go b/pkg/ovs/ovn-nb-logical_router_route_test.go index f479642e732..e593c891ef5 100644 --- a/pkg/ovs/ovn-nb-logical_router_route_test.go +++ b/pkg/ovs/ovn-nb-logical_router_route_test.go @@ -14,7 +14,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterStaticRoutes() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-create-routes-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP @@ -22,24 +22,24 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouterStaticRoutes() { nexthops := [...]string{"192.168.30.1", "192.168.40.1"} routes := make([]*ovnnb.LogicalRouterStaticRoute, 0, 5) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) for i, ipPrefix := range ipPrefixes { - route, err := ovnClient.newLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[i], nil) + route, err := nbClient.newLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[i], nil) require.NoError(t, err) routes = append(routes, route) } - err = ovnClient.CreateLogicalRouterStaticRoutes(lrName, append(routes, nil)...) + err = nbClient.CreateLogicalRouterStaticRoutes(lrName, append(routes, nil)...) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for i, ipPrefix := range ipPrefixes { - route, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[i], false) + route, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[i], false) require.NoError(t, err) require.Contains(t, lr.StaticRoutes, route.UUID) @@ -50,12 +50,12 @@ func (suite *OvnClientTestSuite) testAddLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-add-route-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("normal route", func(t *testing.T) { @@ -70,15 +70,15 @@ func (suite *OvnClientTestSuite) testAddLogicalRouterStaticRoute() { t.Run("create route", func(t *testing.T) { for i := range ipPrefixes { - err = ovnClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefixes[i], nil, nexthops[i]) + err = nbClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefixes[i], nil, nexthops[i]) require.NoError(t, err) } - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for i := range ipPrefixes { - route, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefixes[i], nexthops[i], false) + route, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefixes[i], nexthops[i], false) require.NoError(t, err) require.Equal(t, route.Nexthop, strings.Split(nexthops[i], "/")[0]) require.Contains(t, lr.StaticRoutes, route.UUID) @@ -88,15 +88,15 @@ func (suite *OvnClientTestSuite) testAddLogicalRouterStaticRoute() { t.Run("update route", func(t *testing.T) { updatedNexthops := [...]string{"192.168.30.254", "fd00:100:64::fe"} for i := range ipPrefixes { - err = ovnClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefixes[i], nil, updatedNexthops[i]) + err = nbClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefixes[i], nil, updatedNexthops[i]) require.NoError(t, err) } - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for i := range ipPrefixes { - routes, err := ovnClient.ListLogicalRouterStaticRoutes(lrName, &routeTable, &policy, ipPrefixes[i], nil) + routes, err := nbClient.ListLogicalRouterStaticRoutes(lrName, &routeTable, &policy, ipPrefixes[i], nil) require.NoError(t, err) require.Len(t, routes, 1) require.Equal(t, routes[0].Nexthop, updatedNexthops[i]) @@ -112,21 +112,21 @@ func (suite *OvnClientTestSuite) testAddLogicalRouterStaticRoute() { nexthops := []string{"192.168.50.1", "192.168.60.1"} t.Run("create route", func(t *testing.T) { - err = ovnClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthops...) + err = nbClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthops...) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for _, nexthop := range nexthops { - route, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) + route, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) require.NoError(t, err) require.Contains(t, lr.StaticRoutes, route.UUID) } }) t.Run("update route", func(t *testing.T) { - err = ovnClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthops...) + err = nbClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthops...) require.NoError(t, err) }) }) @@ -136,36 +136,36 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-del-route-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("normal route", func(t *testing.T) { ipPrefix := "192.168.30.0/24" nexthop := "192.168.30.1" - err = ovnClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthop) + err = nbClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthop) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - route, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) + route, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) require.NoError(t, err) require.Contains(t, lr.StaticRoutes, route.UUID) - err = ovnClient.DeleteLogicalRouterStaticRoute(lrName, &routeTable, &policy, ipPrefix, nexthop) + err = nbClient.DeleteLogicalRouterStaticRoute(lrName, &routeTable, &policy, ipPrefix, nexthop) require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.StaticRoutes) - _, err = ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) + _, err = nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) require.ErrorContains(t, err, "not found") }) @@ -173,41 +173,41 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouterStaticRoute() { ipPrefix := "192.168.40.0/24" nexthops := []string{"192.168.50.1", "192.168.60.1"} - err = ovnClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthops...) + err = nbClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthops...) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for _, nexthop := range nexthops { - route, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) + route, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) require.NoError(t, err) require.Contains(t, lr.StaticRoutes, route.UUID) } /* delete first route */ - err = ovnClient.DeleteLogicalRouterStaticRoute(lrName, &routeTable, &policy, ipPrefix, nexthops[0]) + err = nbClient.DeleteLogicalRouterStaticRoute(lrName, &routeTable, &policy, ipPrefix, nexthops[0]) require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - _, err = ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[0], false) + _, err = nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[0], false) require.ErrorContains(t, err, `not found logical router test-del-route-lr static route 'policy dst-ip ip_prefix 192.168.40.0/24 nexthop 192.168.50.1'`) - route, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[1], false) + route, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[1], false) require.NoError(t, err) require.ElementsMatch(t, []string{route.UUID}, lr.StaticRoutes) /* delete second route */ - err = ovnClient.DeleteLogicalRouterStaticRoute(lrName, &routeTable, &policy, ipPrefix, nexthops[1]) + err = nbClient.DeleteLogicalRouterStaticRoute(lrName, &routeTable, &policy, ipPrefix, nexthops[1]) require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.StaticRoutes) - _, err = ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[1], false) + _, err = nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[1], false) require.ErrorContains(t, err, `not found logical router test-del-route-lr static route 'policy dst-ip ip_prefix 192.168.40.0/24 nexthop 192.168.60.1'`) }) } @@ -216,7 +216,7 @@ func (suite *OvnClientTestSuite) testClearLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-clear-route-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP @@ -224,32 +224,32 @@ func (suite *OvnClientTestSuite) testClearLogicalRouterStaticRoute() { nexthops := []string{"192.168.30.1", "192.168.40.1"} routes := make([]*ovnnb.LogicalRouterStaticRoute, 0, 5) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) for i, ipPrefix := range ipPrefixes { - route, err := ovnClient.newLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[i], nil) + route, err := nbClient.newLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[i], nil) require.NoError(t, err) routes = append(routes, route) } - err = ovnClient.CreateLogicalRouterStaticRoutes(lrName, append(routes, nil)...) + err = nbClient.CreateLogicalRouterStaticRoutes(lrName, append(routes, nil)...) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.StaticRoutes, 2) - err = ovnClient.ClearLogicalRouterStaticRoute(lrName) + err = nbClient.ClearLogicalRouterStaticRoute(lrName) require.NoError(t, err) for _, ipPrefix := range ipPrefixes { - _, err = ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, "", false) + _, err = nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, "", false) require.ErrorContains(t, err, "not found") } - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.StaticRoutes) } @@ -258,11 +258,11 @@ func (suite *OvnClientTestSuite) testGetLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test_get_route_lr" routeTable := util.MainRouteTable - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("normal route", func(t *testing.T) { @@ -271,26 +271,26 @@ func (suite *OvnClientTestSuite) testGetLogicalRouterStaticRoute() { ipPrefix := "192.168.30.0/24" nexthop := "192.168.30.1" - err := ovnClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthop) + err := nbClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthop) require.NoError(t, err) t.Run("found route", func(t *testing.T) { - _, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) + _, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) require.NoError(t, err) }) t.Run("policy is different", func(t *testing.T) { - _, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, ovnnb.LogicalRouterStaticRoutePolicySrcIP, ipPrefix, nexthop, false) + _, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, ovnnb.LogicalRouterStaticRoutePolicySrcIP, ipPrefix, nexthop, false) require.ErrorContains(t, err, "not found") }) t.Run("ip_prefix is different", func(t *testing.T) { - _, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, "192.168.30.10", nexthop, false) + _, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, "192.168.30.10", nexthop, false) require.ErrorContains(t, err, "not found") }) t.Run("logical router name is different", func(t *testing.T) { - _, err := ovnClient.GetLogicalRouterStaticRoute(lrName+"x", routeTable, policy, ipPrefix, nexthop, false) + _, err := nbClient.GetLogicalRouterStaticRoute(lrName+"x", routeTable, policy, ipPrefix, nexthop, false) require.ErrorContains(t, err, "not found") }) }) @@ -301,16 +301,16 @@ func (suite *OvnClientTestSuite) testGetLogicalRouterStaticRoute() { ipPrefix := "192.168.40.0/24" nexthop := "192.168.40.1" - err := ovnClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthop) + err := nbClient.AddLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nil, nexthop) require.NoError(t, err) t.Run("found route", func(t *testing.T) { - _, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) + _, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, false) require.NoError(t, err) }) t.Run("nexthop is different", func(t *testing.T) { - _, err := ovnClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop+"1", false) + _, err := nbClient.GetLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop+"1", false) require.ErrorContains(t, err, "not found") }) }) @@ -320,7 +320,7 @@ func (suite *OvnClientTestSuite) testListLogicalRouterStaticRoutes() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-list-routes-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP @@ -328,21 +328,21 @@ func (suite *OvnClientTestSuite) testListLogicalRouterStaticRoutes() { nexthops := []string{"192.168.30.1", "192.168.40.1", "192.168.50.1"} routes := make([]*ovnnb.LogicalRouterStaticRoute, 0, 5) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) for i, ipPrefix := range ipPrefixes { - route, err := ovnClient.newLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[i], nil) + route, err := nbClient.newLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthops[i], nil) require.NoError(t, err) routes = append(routes, route) } - err = ovnClient.CreateLogicalRouterStaticRoutes(lrName, append(routes, nil)...) + err = nbClient.CreateLogicalRouterStaticRoutes(lrName, append(routes, nil)...) require.NoError(t, err) t.Run("include same router routes", func(t *testing.T) { - out, err := ovnClient.ListLogicalRouterStaticRoutes(lrName, nil, nil, "", nil) + out, err := nbClient.ListLogicalRouterStaticRoutes(lrName, nil, nil, "", nil) require.NoError(t, err) require.Len(t, out, 3) }) @@ -352,14 +352,14 @@ func (suite *OvnClientTestSuite) testNewLogicalRouterStaticRoute() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-new-route-lr" routeTable := util.MainRouteTable policy := ovnnb.LogicalRouterStaticRoutePolicyDstIP ipPrefix := "192.168.30.0/24" nexthop := "192.168.30.1" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) expect := &ovnnb.LogicalRouterStaticRoute{ @@ -369,7 +369,7 @@ func (suite *OvnClientTestSuite) testNewLogicalRouterStaticRoute() { BFD: nil, } - route, err := ovnClient.newLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, nil) + route, err := nbClient.newLogicalRouterStaticRoute(lrName, routeTable, policy, ipPrefix, nexthop, nil) require.NoError(t, err) expect.UUID = route.UUID require.Equal(t, expect, route) diff --git a/pkg/ovs/ovn-nb-logical_router_test.go b/pkg/ovs/ovn-nb-logical_router_test.go index bab6c76dd03..98da230d9ef 100644 --- a/pkg/ovs/ovn-nb-logical_router_test.go +++ b/pkg/ovs/ovn-nb-logical_router_test.go @@ -28,13 +28,13 @@ func (suite *OvnClientTestSuite) testCreateLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient name := "test-create-lr" - err := ovnClient.CreateLogicalRouter(name) + err := nbClient.CreateLogicalRouter(name) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(name, false) + lr, err := nbClient.GetLogicalRouter(name, false) require.NoError(t, err) require.Equal(t, name, lr.Name) require.NotEmpty(t, lr.UUID) @@ -45,21 +45,21 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-update-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) t.Run("update external-ids", func(t *testing.T) { lr.ExternalIDs = map[string]string{"foo": "bar"} - err = ovnClient.UpdateLogicalRouter(lr) + err = nbClient.UpdateLogicalRouter(lr) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Equal(t, map[string]string{"foo": "bar"}, lr.ExternalIDs) }) @@ -67,10 +67,10 @@ func (suite *OvnClientTestSuite) testUpdateLogicalRouter() { t.Run("clear external-ids", func(t *testing.T) { lr.ExternalIDs = nil - err = ovnClient.UpdateLogicalRouter(lr, &lr.ExternalIDs) + err = nbClient.UpdateLogicalRouter(lr, &lr.ExternalIDs) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.ExternalIDs) }) @@ -80,24 +80,24 @@ func (suite *OvnClientTestSuite) testDeleteLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient name := "test-delete-lr" t.Run("no err when delete existent logical router", func(t *testing.T) { t.Parallel() - err := ovnClient.CreateLogicalRouter(name) + err := nbClient.CreateLogicalRouter(name) require.NoError(t, err) - err = ovnClient.DeleteLogicalRouter(name) + err = nbClient.DeleteLogicalRouter(name) require.NoError(t, err) - _, err = ovnClient.GetLogicalRouter(name, false) + _, err = nbClient.GetLogicalRouter(name, false) require.ErrorContains(t, err, "not found logical router") }) t.Run("no err when delete non-existent logical router", func(t *testing.T) { t.Parallel() - err := ovnClient.DeleteLogicalRouter("test-delete-lr-non-existent") + err := nbClient.DeleteLogicalRouter("test-delete-lr-non-existent") require.NoError(t, err) }) } @@ -106,15 +106,15 @@ func (suite *OvnClientTestSuite) testGetLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient name := "test-get-lr" - err := ovnClient.CreateLogicalRouter(name) + err := nbClient.CreateLogicalRouter(name) require.NoError(t, err) t.Run("should return no err when found logical router", func(t *testing.T) { t.Parallel() - lr, err := ovnClient.GetLogicalRouter(name, false) + lr, err := nbClient.GetLogicalRouter(name, false) require.NoError(t, err) require.Equal(t, name, lr.Name) require.NotEmpty(t, lr.UUID) @@ -122,13 +122,13 @@ func (suite *OvnClientTestSuite) testGetLogicalRouter() { t.Run("should return err when not found logical router", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetLogicalRouter("test-get-lr-non-existent", false) + _, err := nbClient.GetLogicalRouter("test-get-lr-non-existent", false) require.ErrorContains(t, err, "not found logical router") }) t.Run("no err when not found logical router and ignoreNotFound is true", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetLogicalRouter("test-get-lr-non-existent", true) + _, err := nbClient.GetLogicalRouter("test-get-lr-non-existent", true) require.NoError(t, err) }) } @@ -137,14 +137,14 @@ func (suite *OvnClientTestSuite) testListLogicalRouter() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient namePrefix := "test-list-lr" i := 0 // create three logical router for ; i < 3; i++ { name := fmt.Sprintf("%s-%d", namePrefix, i) - err := ovnClient.CreateLogicalRouter(name) + err := nbClient.CreateLogicalRouter(name) require.NoError(t, err) } @@ -156,7 +156,7 @@ func (suite *OvnClientTestSuite) testListLogicalRouter() { ExternalIDs: map[string]string{"vendor": "test-vendor"}, } - err := createLogicalRouter(ovnClient, lr) + err := createLogicalRouter(nbClient, lr) require.NoError(t, err) } @@ -167,13 +167,13 @@ func (suite *OvnClientTestSuite) testListLogicalRouter() { Name: name, } - err := createLogicalRouter(ovnClient, lr) + err := createLogicalRouter(nbClient, lr) require.NoError(t, err) } t.Run("return all logical router which vendor is kube-ovn", func(t *testing.T) { t.Parallel() - lrs, err := ovnClient.ListLogicalRouter(true, nil) + lrs, err := nbClient.ListLogicalRouter(true, nil) require.NoError(t, err) count := 0 @@ -187,7 +187,7 @@ func (suite *OvnClientTestSuite) testListLogicalRouter() { t.Run("has custom filter", func(t *testing.T) { t.Parallel() - lrs, err := ovnClient.ListLogicalRouter(false, func(lr *ovnnb.LogicalRouter) bool { + lrs, err := nbClient.ListLogicalRouter(false, func(lr *ovnnb.LogicalRouter) bool { return len(lr.ExternalIDs) == 0 || lr.ExternalIDs["vendor"] != util.CniTypeName }) @@ -207,30 +207,30 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateLoadBalancers() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-add-lb-to-lr" prefix := "test-add-lr-lb" lbNames := make([]string, 0, 3) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) for i := 1; i <= 3; i++ { lbName := fmt.Sprintf("%s-%d", prefix, i) lbNames = append(lbNames, lbName) - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) } t.Run("add lbs to logical router", func(t *testing.T) { - err = ovnClient.LogicalRouterUpdateLoadBalancers(lrName, ovsdb.MutateOperationInsert, lbNames...) + err = nbClient.LogicalRouterUpdateLoadBalancers(lrName, ovsdb.MutateOperationInsert, lbNames...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalRouter(lrName, false) + ls, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for _, lbName := range lbNames { - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Contains(t, ls.LoadBalancer, lb.UUID) } @@ -238,20 +238,20 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateLoadBalancers() { t.Run("should no err when add non-existent lbs to logical router", func(t *testing.T) { // add a non-existent lb - err = ovnClient.LogicalSwitchUpdateLoadBalancers(lrName, ovsdb.MutateOperationInsert, "test-add-lb-non-existent") + err = nbClient.LogicalSwitchUpdateLoadBalancers(lrName, ovsdb.MutateOperationInsert, "test-add-lb-non-existent") require.NoError(t, err) }) t.Run("del lbs from logical router", func(t *testing.T) { // delete the first two lbs from logical switch - err = ovnClient.LogicalRouterUpdateLoadBalancers(lrName, ovsdb.MutateOperationDelete, lbNames[0:2]...) + err = nbClient.LogicalRouterUpdateLoadBalancers(lrName, ovsdb.MutateOperationDelete, lbNames[0:2]...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalRouter(lrName, false) + ls, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) for i, lbName := range lbNames { - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) // logical switch contains the last lb @@ -264,7 +264,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateLoadBalancers() { }) t.Run("del non-existent lbs from logical router", func(t *testing.T) { - err = ovnClient.LogicalRouterUpdateLoadBalancers(lrName, ovsdb.MutateOperationDelete, []string{"test-del-lb-non-existent", "test-del-lb-non-existent-1"}...) + err = nbClient.LogicalRouterUpdateLoadBalancers(lrName, ovsdb.MutateOperationDelete, []string{"test-del-lb-non-existent", "test-del-lb-non-existent-1"}...) require.NoError(t, err) }) } @@ -273,16 +273,16 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdatePortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-update-port-op-lr" uuid := ovsclient.NamedUUID() - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("add new port to logical router", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalRouterUpdatePortOp(lrName, uuid, ovsdb.MutateOperationInsert) + ops, err := nbClient.LogicalRouterUpdatePortOp(lrName, uuid, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -301,7 +301,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdatePortOp() { t.Run("del port from logical router", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalRouterUpdatePortOp(lrName, uuid, ovsdb.MutateOperationDelete) + ops, err := nbClient.LogicalRouterUpdatePortOp(lrName, uuid, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -320,7 +320,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdatePortOp() { t.Run("should return err when logical router does not exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.LogicalRouterUpdatePortOp("test-update-port-op-lr-non-existent", uuid, ovsdb.MutateOperationInsert) + _, err := nbClient.LogicalRouterUpdatePortOp("test-update-port-op-lr-non-existent", uuid, ovsdb.MutateOperationInsert) require.ErrorContains(t, err, "not found logical router") }) } @@ -329,16 +329,16 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdatePolicyOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-update-policy-op-lr" uuid := ovsclient.NamedUUID() - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("add new policy to logical router", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalRouterUpdatePolicyOp(lrName, []string{uuid}, ovsdb.MutateOperationInsert) + ops, err := nbClient.LogicalRouterUpdatePolicyOp(lrName, []string{uuid}, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -357,7 +357,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdatePolicyOp() { t.Run("del policy from logical router", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalRouterUpdatePolicyOp(lrName, []string{uuid}, ovsdb.MutateOperationDelete) + ops, err := nbClient.LogicalRouterUpdatePolicyOp(lrName, []string{uuid}, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -376,7 +376,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdatePolicyOp() { t.Run("should return err when logical router does not exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.LogicalRouterUpdatePolicyOp("test-update-policy-op-lr-non-existent", []string{uuid}, ovsdb.MutateOperationInsert) + _, err := nbClient.LogicalRouterUpdatePolicyOp("test-update-policy-op-lr-non-existent", []string{uuid}, ovsdb.MutateOperationInsert) require.ErrorContains(t, err, "not found logical router") }) } @@ -385,16 +385,16 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateNatOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-update-nat-op-lr" uuid := ovsclient.NamedUUID() - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("add new nat to logical router", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalRouterUpdateNatOp(lrName, []string{uuid}, ovsdb.MutateOperationInsert) + ops, err := nbClient.LogicalRouterUpdateNatOp(lrName, []string{uuid}, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -413,7 +413,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateNatOp() { t.Run("del nat from logical router", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalRouterUpdateNatOp(lrName, []string{uuid}, ovsdb.MutateOperationDelete) + ops, err := nbClient.LogicalRouterUpdateNatOp(lrName, []string{uuid}, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -432,7 +432,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateNatOp() { t.Run("should return err when logical router does not exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.LogicalRouterUpdateNatOp("test-update-nat-op-lr-non-existent", []string{uuid}, ovsdb.MutateOperationInsert) + _, err := nbClient.LogicalRouterUpdateNatOp("test-update-nat-op-lr-non-existent", []string{uuid}, ovsdb.MutateOperationInsert) require.ErrorContains(t, err, "not found logical router") }) } @@ -441,16 +441,16 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateStaticRouteOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-update-route-op-lr" uuid := ovsclient.NamedUUID() - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("add new static route to logical router", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalRouterUpdateStaticRouteOp(lrName, []string{uuid}, ovsdb.MutateOperationInsert) + ops, err := nbClient.LogicalRouterUpdateStaticRouteOp(lrName, []string{uuid}, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -469,7 +469,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateStaticRouteOp() { t.Run("del static route from logical router", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalRouterUpdateStaticRouteOp(lrName, []string{uuid}, ovsdb.MutateOperationDelete) + ops, err := nbClient.LogicalRouterUpdateStaticRouteOp(lrName, []string{uuid}, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -488,7 +488,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterUpdateStaticRouteOp() { t.Run("should return err when logical router does not exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.LogicalRouterUpdateStaticRouteOp("test-update-route-op-lr-non-existent", []string{uuid}, ovsdb.MutateOperationInsert) + _, err := nbClient.LogicalRouterUpdateStaticRouteOp("test-update-route-op-lr-non-existent", []string{uuid}, ovsdb.MutateOperationInsert) require.ErrorContains(t, err, "not found logical router") }) } @@ -497,10 +497,10 @@ func (suite *OvnClientTestSuite) testLogicalRouterOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-op-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) lrpUUID := ovsclient.NamedUUID() @@ -525,7 +525,7 @@ func (suite *OvnClientTestSuite) testLogicalRouterOp() { return mutation } - ops, err := ovnClient.LogicalRouterOp(lrName, lrpMutation, policyMutation) + ops, err := nbClient.LogicalRouterOp(lrName, lrpMutation, policyMutation) require.NoError(t, err) require.Len(t, ops[0].Mutations, 2) diff --git a/pkg/ovs/ovn-nb-logical_switch_port_test.go b/pkg/ovs/ovn-nb-logical_switch_port_test.go index d1e49738940..0505f24de9b 100644 --- a/pkg/ovs/ovn-nb-logical_switch_port_test.go +++ b/pkg/ovs/ovn-nb-logical_switch_port_test.go @@ -17,7 +17,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-create-lsp-ls" ips := "10.244.0.37,fc00::af4:25" mac := "00:00:00:AB:B4:65" @@ -25,14 +25,14 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { podName := "test-create-lsp-pod" podNamespace := "test-create-lsp-ns" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateDHCPOptions(lsName, "10.244.0.0/16", "") + err = nbClient.CreateDHCPOptions(lsName, "10.244.0.0/16", "") require.NoError(t, err) - err = ovnClient.CreateDHCPOptions(lsName, "fc00::/64", "") + err = nbClient.CreateDHCPOptions(lsName, "fc00::/64", "") require.NoError(t, err) - dhcpOptions, err := ovnClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName}) + dhcpOptions, err := nbClient.ListDHCPOptions(true, map[string]string{logicalSwitchKey: lsName}) require.NoError(t, err) require.Len(t, dhcpOptions, 2) @@ -46,10 +46,10 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { sgs := "sg,sg1" vpcName := "test-vpc" - err = ovnClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, dhcpUUIDs, vpcName) + err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, dhcpUUIDs, vpcName) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25"}, lsp.Addresses) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25 10.244.0.110 10.244.0.112"}, lsp.PortSecurity) @@ -73,10 +73,10 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { sgs := "sg,sg1" vpcName := "test-vpc" - err = ovnClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, "", true, dhcpUUIDs, vpcName) + err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, "", true, dhcpUUIDs, vpcName) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25"}, lsp.Addresses) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25"}, lsp.PortSecurity) @@ -98,10 +98,10 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { sgs := "sg,sg1,default-securitygroup" vpcName := "test-vpc" - err = ovnClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, dhcpUUIDs, vpcName) + err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, dhcpUUIDs, vpcName) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25"}, lsp.Addresses) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25 10.244.0.110 10.244.0.112"}, lsp.PortSecurity) @@ -125,10 +125,10 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { sgs := "sg,sg1" vpcName := "ovn-cluster" - err = ovnClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, dhcpUUIDs, vpcName) + err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, dhcpUUIDs, vpcName) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25"}, lsp.Addresses) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25 10.244.0.110 10.244.0.112"}, lsp.PortSecurity) @@ -151,10 +151,10 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { sgs := "sg,sg1" vpcName := "test-vpc" - err = ovnClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, false, sgs, vips, true, dhcpUUIDs, vpcName) + err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, false, sgs, vips, true, dhcpUUIDs, vpcName) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25"}, lsp.Addresses) require.Equal(t, map[string]string{ @@ -177,10 +177,10 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPort() { sgs := "sg,sg1" vpcName := "test-vpc" - err = ovnClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, nil, vpcName) + err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, podName, podNamespace, true, sgs, vips, true, nil, vpcName) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25"}, lsp.Addresses) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25 10.244.0.110 10.244.0.112"}, lsp.PortSecurity) @@ -204,19 +204,19 @@ func (suite *OvnClientTestSuite) testCreateLocalnetLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lspName := "test-create-localnet-port-lsp" lsName := "test-create-localnet-port-ls" provider := "external" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("create localnet logical switch port with vlan id", func(t *testing.T) { - err = ovnClient.CreateLocalnetLogicalSwitchPort(lsName, lspName, provider, "192.168.0.0/24,fd00::/120", 200) + err = nbClient.CreateLocalnetLogicalSwitchPort(lsName, lspName, provider, "192.168.0.0/24,fd00::/120", 200) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Equal(t, lspName, lsp.Name) require.Equal(t, "localnet", lsp.Type) @@ -232,10 +232,10 @@ func (suite *OvnClientTestSuite) testCreateLocalnetLogicalSwitchPort() { t.Run("create localnet logical switch port without vlan id", func(t *testing.T) { lspName := "test-create-localnet-port-lsp-no-vlan-id" - err = ovnClient.CreateLocalnetLogicalSwitchPort(lsName, lspName, provider, "192.168.1.0/24,fd01::/120", 0) + err = nbClient.CreateLocalnetLogicalSwitchPort(lsName, lspName, provider, "192.168.1.0/24,fd01::/120", 0) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Equal(t, lspName, lsp.Name) require.Equal(t, "localnet", lsp.Type) @@ -249,7 +249,7 @@ func (suite *OvnClientTestSuite) testCreateLocalnetLogicalSwitchPort() { }) t.Run("should no err when create logical switch port repeatedly", func(t *testing.T) { - err = ovnClient.CreateLocalnetLogicalSwitchPort(lsName, lspName, "external", "192.168.2.0/24,fd02::/120", 0) + err = nbClient.CreateLocalnetLogicalSwitchPort(lsName, lspName, "external", "192.168.2.0/24,fd02::/120", 0) require.NoError(t, err) }) } @@ -258,19 +258,19 @@ func (suite *OvnClientTestSuite) testCreateVirtualLogicalSwitchPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-create-virtual-port-ls" vips := []string{"192.168.33.10", "192.168.33.12"} - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("create virtual logical switch port", func(t *testing.T) { - err = ovnClient.CreateVirtualLogicalSwitchPorts(lsName, vips...) + err = nbClient.CreateVirtualLogicalSwitchPorts(lsName, vips...) require.NoError(t, err) for _, ip := range vips { lspName := fmt.Sprintf("%s-vip-%s", lsName, ip) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Equal(t, lspName, lsp.Name) require.Equal(t, "virtual", lsp.Type) @@ -281,7 +281,7 @@ func (suite *OvnClientTestSuite) testCreateVirtualLogicalSwitchPorts() { }) t.Run("should no err when create logical switch port repeatedly", func(t *testing.T) { - err = ovnClient.CreateVirtualLogicalSwitchPorts(lsName, vips...) + err = nbClient.CreateVirtualLogicalSwitchPorts(lsName, vips...) require.NoError(t, err) }) } @@ -290,21 +290,21 @@ func (suite *OvnClientTestSuite) testCreateBareLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-create-bare-port-ls" lspName := "test-create-bare-port-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "100.64.0.4,fd00:100:64::4", "00:00:00:C9:4E:EE") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "100.64.0.4,fd00:100:64::4", "00:00:00:C9:4E:EE") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"00:00:00:C9:4E:EE 100.64.0.4 fd00:100:64::4"}, lsp.Addresses) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Contains(t, ls.Ports, lsp.UUID) @@ -314,33 +314,33 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortVirtualParents() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-port-virt-parents-ls" ips := []string{"192.168.211.31", "192.168.211.32"} - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateVirtualLogicalSwitchPorts(lsName, ips...) + err = nbClient.CreateVirtualLogicalSwitchPorts(lsName, ips...) require.NoError(t, err) t.Run("set virtual-parents option", func(t *testing.T) { - err = ovnClient.SetLogicalSwitchPortVirtualParents(lsName, "virt-parents-ls-1,virt-parents-ls-2", ips...) + err = nbClient.SetLogicalSwitchPortVirtualParents(lsName, "virt-parents-ls-1,virt-parents-ls-2", ips...) require.NoError(t, err) for _, ip := range ips { lspName := fmt.Sprintf("%s-vip-%s", lsName, ip) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Equal(t, "virt-parents-ls-1,virt-parents-ls-2", lsp.Options["virtual-parents"]) } }) t.Run("clear virtual-parents option", func(t *testing.T) { - err = ovnClient.SetLogicalSwitchPortVirtualParents(lsName, "", ips...) + err = nbClient.SetLogicalSwitchPortVirtualParents(lsName, "", ips...) require.NoError(t, err) for _, ip := range ips { lspName := fmt.Sprintf("%s-vip-%s", lsName, ip) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Empty(t, lsp.Options["virtual-parents"]) } @@ -351,35 +351,35 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortArpProxy() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-set-lsp-arp-proxy-ls" ips := "10.244.0.37,fc00::af4:25" mac := "00:00:00:AB:B4:65" podNamespace := "test-ns" vpcName := "test-vpc" lspName := "test-set-lsp-arp-proxy-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("create logical switch port", func(t *testing.T) { - err = ovnClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, lspName, podNamespace, true, "", "", false, nil, vpcName) + err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ips, mac, lspName, podNamespace, true, "", "", false, nil, vpcName) require.NoError(t, err) }) t.Run("set arp_proxy option", func(t *testing.T) { enableArpProxy := true - err = ovnClient.SetLogicalSwitchPortArpProxy(lspName, enableArpProxy) + err = nbClient.SetLogicalSwitchPortArpProxy(lspName, enableArpProxy) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Equal(t, "true", lsp.Options["arp_proxy"]) }) t.Run("clear arp_proxy option", func(t *testing.T) { enableArpProxy := false - err = ovnClient.SetLogicalSwitchPortArpProxy(lspName, enableArpProxy) + err = nbClient.SetLogicalSwitchPortArpProxy(lspName, enableArpProxy) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Empty(t, lsp.Options["arp_proxy"]) }) @@ -389,21 +389,21 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurity() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-port-security-ls" lspName := "test-update-port-security-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) t.Run("update port_security and external_ids", func(t *testing.T) { - err = ovnClient.SetLogicalSwitchPortSecurity(true, lspName, "00:00:00:AB:B4:65", "10.244.0.37,fc00::af4:25", "10.244.100.10,10.244.100.11") + err = nbClient.SetLogicalSwitchPortSecurity(true, lspName, "00:00:00:AB:B4:65", "10.244.0.37,fc00::af4:25", "10.244.100.10,10.244.100.11") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25 10.244.100.10 10.244.100.11"}, lsp.PortSecurity) require.Equal(t, map[string]string{ @@ -415,10 +415,10 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurity() { }) t.Run("clear port_security and external_ids", func(t *testing.T) { - err = ovnClient.SetLogicalSwitchPortSecurity(false, lspName, "00:00:00:AB:B4:65", "10.244.0.37,fc00::af4:25", "") + err = nbClient.SetLogicalSwitchPortSecurity(false, lspName, "00:00:00:AB:B4:65", "10.244.0.37,fc00::af4:25", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.Empty(t, lsp.PortSecurity) @@ -431,13 +431,13 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurity() { t.Run("update port_security and external_ids when lsp.ExternalIDs is nil and vips is not nil", func(t *testing.T) { lspName := "test-update-port-security-lsp-nil-eid" - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - err = ovnClient.SetLogicalSwitchPortSecurity(true, lspName, "00:00:00:AB:B4:65", "10.244.0.37,fc00::af4:25", "10.244.100.10,10.244.100.11") + err = nbClient.SetLogicalSwitchPortSecurity(true, lspName, "00:00:00:AB:B4:65", "10.244.0.37,fc00::af4:25", "10.244.100.10,10.244.100.11") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.ElementsMatch(t, []string{"00:00:00:AB:B4:65 10.244.0.37 fc00::af4:25 10.244.100.10 10.244.100.11"}, lsp.PortSecurity) @@ -454,36 +454,36 @@ func (suite *OvnClientTestSuite) testSetSetLogicalSwitchPortExternalIDs() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-set-lsp-ext-id-ls" lspName := "test-set-lsp-ext-id-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) require.Equal(t, util.CniTypeName, lsp.ExternalIDs["vendor"]) - err = ovnClient.SetLogicalSwitchPortExternalIDs(lspName, map[string]string{"k1": "v1"}) + err = nbClient.SetLogicalSwitchPortExternalIDs(lspName, map[string]string{"k1": "v1"}) require.NoError(t, err) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) require.Equal(t, util.CniTypeName, lsp.ExternalIDs["vendor"]) require.Equal(t, "v1", lsp.ExternalIDs["k1"]) - err = ovnClient.SetLogicalSwitchPortExternalIDs(lspName, map[string]string{"k1": "v2"}) + err = nbClient.SetLogicalSwitchPortExternalIDs(lspName, map[string]string{"k1": "v2"}) require.NoError(t, err) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) @@ -495,11 +495,11 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-set-sg-ls" lspNamePrefix := "test-set-sg-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) addOpExpect := func(lsp *ovnnb.LogicalSwitchPort, sgs []string) { @@ -530,23 +530,23 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-complete" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) lsp.ExternalIDs[associatedSgKeyPrefix+"sg1"] = "true" lsp.ExternalIDs[sgsKey] = "sg1" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3") require.NoError(t, err) require.ElementsMatch(t, []string{"sg2", "sg3"}, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg2", "sg1", "sg3"}) }) @@ -555,24 +555,24 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-old-subset" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) lsp.ExternalIDs[associatedSgKeyPrefix+"sg1"] = "true" lsp.ExternalIDs[associatedSgKeyPrefix+"sg2"] = "true" lsp.ExternalIDs[sgsKey] = "sg1/sg2" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3", "sg4", "sg1") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3", "sg4", "sg1") require.NoError(t, err) require.ElementsMatch(t, []string{"sg4", "sg3"}, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg2", "sg1", "sg3", "sg4"}) }) @@ -581,10 +581,10 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-new-subset" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) @@ -592,14 +592,14 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { lsp.ExternalIDs[associatedSgKeyPrefix+"sg2"] = "true" lsp.ExternalIDs[associatedSgKeyPrefix+"sg3"] = "true" lsp.ExternalIDs[sgsKey] = "sg1/sg2/sg3" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg1") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg1") require.NoError(t, err) require.Empty(t, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg2", "sg1", "sg3"}) }) @@ -608,10 +608,10 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-partial" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) @@ -619,14 +619,14 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { lsp.ExternalIDs[associatedSgKeyPrefix+"sg2"] = "true" lsp.ExternalIDs[associatedSgKeyPrefix+"sg3"] = "true" lsp.ExternalIDs[sgsKey] = "sg1/sg2/sg3" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3", "sg4") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3", "sg4") require.NoError(t, err) require.ElementsMatch(t, []string{"sg4"}, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg2", "sg1", "sg3", "sg4"}) }) @@ -635,10 +635,10 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-new-empty" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) @@ -646,14 +646,14 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { lsp.ExternalIDs[associatedSgKeyPrefix+"sg2"] = "true" lsp.ExternalIDs[associatedSgKeyPrefix+"sg3"] = "true" lsp.ExternalIDs[sgsKey] = "sg1/sg2/sg3" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op) + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op) require.NoError(t, err) require.Empty(t, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg2", "sg1", "sg3"}) }) @@ -662,18 +662,18 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-old-empty" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg1") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg1") require.NoError(t, err) require.ElementsMatch(t, []string{"sg1", "sg2"}, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg2", "sg1"}) }) @@ -689,23 +689,23 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-complete" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) lsp.ExternalIDs[associatedSgKeyPrefix+"sg1"] = "true" lsp.ExternalIDs[sgsKey] = "sg1" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3") require.NoError(t, err) require.Empty(t, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg1"}) }) @@ -714,24 +714,24 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-old-subset" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) lsp.ExternalIDs[associatedSgKeyPrefix+"sg1"] = "true" lsp.ExternalIDs[associatedSgKeyPrefix+"sg2"] = "true" lsp.ExternalIDs[sgsKey] = "sg1/sg2" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3", "sg4", "sg1") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3", "sg4", "sg1") require.NoError(t, err) require.ElementsMatch(t, []string{"sg1", "sg2"}, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) removeOpExpect(lsp, []string{"sg2", "sg1"}) }) @@ -740,10 +740,10 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-new-subset" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) @@ -751,14 +751,14 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { lsp.ExternalIDs[associatedSgKeyPrefix+"sg2"] = "true" lsp.ExternalIDs[associatedSgKeyPrefix+"sg3"] = "true" lsp.ExternalIDs[sgsKey] = "sg1/sg2/sg3" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg1") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg1") require.NoError(t, err) require.ElementsMatch(t, []string{"sg2", "sg1"}, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg3"}) removeOpExpect(lsp, []string{"sg2", "sg1"}) @@ -768,10 +768,10 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-partial" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) @@ -779,14 +779,14 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { lsp.ExternalIDs[associatedSgKeyPrefix+"sg2"] = "true" lsp.ExternalIDs[associatedSgKeyPrefix+"sg3"] = "true" lsp.ExternalIDs[sgsKey] = "sg1/sg2/sg3" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3", "sg4") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg3", "sg4") require.NoError(t, err) require.ElementsMatch(t, []string{"sg3", "sg2"}, diffSgs) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) addOpExpect(lsp, []string{"sg1"}) removeOpExpect(lsp, []string{"sg2", "sg3"}) @@ -796,14 +796,14 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortSecurityGroup() { t.Parallel() lspName := lspNamePrefix + "-old-empty" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) - diffSgs, err := ovnClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg1") + diffSgs, err := nbClient.SetLogicalSwitchPortSecurityGroup(lsp, op, "sg2", "sg1") require.NoError(t, err) require.Empty(t, diffSgs) }) @@ -814,35 +814,35 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortsSecurityGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-set-sgs-ls" lspNamePrefix := "test-set-sgs-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) for i := 0; i < 3; i++ { lspName := fmt.Sprintf("%s-%d", lspNamePrefix, i) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) lsp.ExternalIDs[associatedSgKeyPrefix+"sg1"] = "false" lsp.ExternalIDs[associatedSgKeyPrefix+"sg2"] = "false" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs) require.NoError(t, err) } t.Run("add sg to lsp", func(t *testing.T) { - err := ovnClient.SetLogicalSwitchPortsSecurityGroup("sg2", "add") + err := nbClient.SetLogicalSwitchPortsSecurityGroup("sg2", "add") require.NoError(t, err) for i := 0; i < 3; i++ { lspName := fmt.Sprintf("%s-%d", lspNamePrefix, i) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) @@ -855,12 +855,12 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortsSecurityGroup() { }) t.Run("remove sg from lsp", func(t *testing.T) { - err := ovnClient.SetLogicalSwitchPortsSecurityGroup("sg2", "remove") + err := nbClient.SetLogicalSwitchPortsSecurityGroup("sg2", "remove") require.NoError(t, err) for i := 0; i < 3; i++ { lspName := fmt.Sprintf("%s-%d", lspNamePrefix, i) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) @@ -871,7 +871,7 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortsSecurityGroup() { }) t.Run("invalid op", func(t *testing.T) { - err := ovnClient.SetLogicalSwitchPortsSecurityGroup("sg2", "del") + err := nbClient.SetLogicalSwitchPortsSecurityGroup("sg2", "del") require.ErrorContains(t, err, "op must be 'add' or 'remove'") }) } @@ -880,7 +880,7 @@ func (suite *OvnClientTestSuite) testEnablePortLayer2forward() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-enable-port-l2-ls" lspName := "test-enable-port-l2-lsp" ns := "test-enable-port-l2-ns" @@ -888,22 +888,22 @@ func (suite *OvnClientTestSuite) testEnablePortLayer2forward() { ip := util.GenerateRandomIP("192.168.1.0/24") mac := util.GenerateMac() - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateLogicalSwitchPort(lsName, lspName, ip, mac, pod, ns, false, "", "", false, nil, "") + err = nbClient.CreateLogicalSwitchPort(lsName, lspName, ip, mac, pod, ns, false, "", "", false, nil, "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) require.Equal(t, util.CniTypeName, lsp.ExternalIDs["vendor"]) - err = ovnClient.EnablePortLayer2forward(lspName) + err = nbClient.EnablePortLayer2forward(lspName) require.NoError(t, err) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.Contains(t, lsp.Addresses, "unknown") @@ -913,18 +913,18 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortVlanTag() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-set-port-vlan-tag-ls" lspName := "test-set-port-vlan-tag-lsp" vlanID := 100 - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateLocalnetLogicalSwitchPort(lsName, lspName, "provider", "192.168.3.0/24,fd03::/120", vlanID) + err = nbClient.CreateLocalnetLogicalSwitchPort(lsName, lspName, "provider", "192.168.3.0/24,fd03::/120", vlanID) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotNil(t, lsp.Tag) @@ -935,10 +935,10 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortVlanTag() { require.Equal(t, "fd03::/120", lsp.ExternalIDs["ipv6_network"]) t.Run("clear logical switch port vlan id", func(t *testing.T) { - err = ovnClient.SetLogicalSwitchPortVlanTag(lspName, 0) + err = nbClient.SetLogicalSwitchPortVlanTag(lspName, 0) require.NoError(t, err) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.Nil(t, lsp.Tag) @@ -946,20 +946,20 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortVlanTag() { t.Run("set logical switch port vlan id", func(t *testing.T) { vlanID := 10 - err = ovnClient.SetLogicalSwitchPortVlanTag(lspName, vlanID) + err = nbClient.SetLogicalSwitchPortVlanTag(lspName, vlanID) require.NoError(t, err) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotNil(t, lsp.Tag) require.Equal(t, vlanID, *lsp.Tag) // no error when set the same vlan id - err = ovnClient.SetLogicalSwitchPortVlanTag(lspName, vlanID) + err = nbClient.SetLogicalSwitchPortVlanTag(lspName, vlanID) require.NoError(t, err) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotNil(t, lsp.Tag) @@ -967,10 +967,10 @@ func (suite *OvnClientTestSuite) testSetLogicalSwitchPortVlanTag() { }) t.Run("invalid vlan id", func(t *testing.T) { - err = ovnClient.SetLogicalSwitchPortVlanTag(lspName, -1) + err = nbClient.SetLogicalSwitchPortVlanTag(lspName, -1) require.ErrorContains(t, err, "invalid vlan id") - err = ovnClient.SetLogicalSwitchPortVlanTag(lspName, 4096) + err = nbClient.SetLogicalSwitchPortVlanTag(lspName, 4096) require.ErrorContains(t, err, "invalid vlan id") }) } @@ -979,17 +979,17 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-lsp-ls" lspName := "test-update-lsp-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) @@ -1001,10 +1001,10 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchPort() { lsp.Options = make(map[string]string, 1) } lsp.Options["virtual-parents"] = "test-virtual-parents" - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs, &lsp.Options) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs, &lsp.Options) require.NoError(t, err) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) @@ -1017,10 +1017,10 @@ func (suite *OvnClientTestSuite) testUpdateLogicalSwitchPort() { delete(lsp.ExternalIDs, "liveMigration") delete(lsp.Options, "virtual-parents") - err = ovnClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs, &lsp.Options) + err = nbClient.UpdateLogicalSwitchPort(lsp, &lsp.ExternalIDs, &lsp.Options) require.NoError(t, err) - lsp, err = ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) require.NotEmpty(t, lsp.ExternalIDs) @@ -1033,10 +1033,10 @@ func (suite *OvnClientTestSuite) testListLogicalSwitchPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-list-lsp-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("normal lsp", func(t *testing.T) { @@ -1044,10 +1044,10 @@ func (suite *OvnClientTestSuite) testListLogicalSwitchPorts() { // normal lsp lspName := "test-list-normal-lsp" - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - out, err := ovnClient.ListLogicalSwitchPorts(true, map[string]string{logicalSwitchKey: lsName}, func(lsp *ovnnb.LogicalSwitchPort) bool { + out, err := nbClient.ListLogicalSwitchPorts(true, map[string]string{logicalSwitchKey: lsName}, func(lsp *ovnnb.LogicalSwitchPort) bool { return lsp.Type == "" }) require.NoError(t, err) @@ -1063,13 +1063,13 @@ func (suite *OvnClientTestSuite) testListLogicalSwitchPorts() { lspName := "test-list-patch-lsp-lsp" lrpName := "test-list-patch-lsp-lrp" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateLogicalPatchPort(lsName, lrName, lspName, lrpName, "10.19.100.1/24", "") + err = nbClient.CreateLogicalPatchPort(lsName, lrName, lspName, lrpName, "10.19.100.1/24", "") require.NoError(t, err) - out, err := ovnClient.ListLogicalSwitchPorts(true, map[string]string{logicalSwitchKey: lsName}, func(lsp *ovnnb.LogicalSwitchPort) bool { + out, err := nbClient.ListLogicalSwitchPorts(true, map[string]string{logicalSwitchKey: lsName}, func(lsp *ovnnb.LogicalSwitchPort) bool { return lsp.Type == "router" && len(lsp.Options) != 0 && lsp.Options["router-port"] == lrpName }) require.NoError(t, err) @@ -1082,10 +1082,10 @@ func (suite *OvnClientTestSuite) testListLogicalSwitchPorts() { // virtual lsp lspName := "test-list-virtual-lsp" - err := ovnClient.CreateVirtualLogicalSwitchPort(lspName, lsName, "unknown") + err := nbClient.CreateVirtualLogicalSwitchPort(lspName, lsName, "unknown") require.NoError(t, err) - out, err := ovnClient.ListLogicalSwitchPorts(true, map[string]string{logicalSwitchKey: lsName}, func(lsp *ovnnb.LogicalSwitchPort) bool { + out, err := nbClient.ListLogicalSwitchPorts(true, map[string]string{logicalSwitchKey: lsName}, func(lsp *ovnnb.LogicalSwitchPort) bool { return lsp.Type == "virtual" }) require.NoError(t, err) @@ -1098,34 +1098,34 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lspName := "test-delete-port-lsp" lsName := "test-delete-port-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) t.Run("no err when delete existent logical switch port", func(t *testing.T) { - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Contains(t, ls.Ports, lsp.UUID) - err = ovnClient.DeleteLogicalSwitchPort(lspName) + err = nbClient.DeleteLogicalSwitchPort(lspName) require.NoError(t, err) - ls, err = ovnClient.GetLogicalSwitch(lsName, false) + ls, err = nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.NotContains(t, ls.Ports, lsp.UUID) }) t.Run("no err when delete non-existent logical switch port", func(t *testing.T) { - err := ovnClient.DeleteLogicalSwitchPort("test-delete-lrp-non-existent") + err := nbClient.DeleteLogicalSwitchPort("test-delete-lrp-non-existent") require.NoError(t, err) }) } @@ -1134,11 +1134,11 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lspName := "test-create-op-lsp" lsName := "test-create-op-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("merge ExternalIDs when exist ExternalIDs", func(t *testing.T) { @@ -1150,7 +1150,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPortOp() { }, } - ops, err := ovnClient.CreateLogicalSwitchPortOp(lsp, lsName) + ops, err := nbClient.CreateLogicalSwitchPortOp(lsp, lsName) require.NoError(t, err) require.Len(t, ops, 2) @@ -1185,7 +1185,7 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitchPortOp() { Name: lspName, } - ops, err := ovnClient.CreateLogicalSwitchPortOp(lsp, lsName) + ops, err := nbClient.CreateLogicalSwitchPortOp(lsp, lsName) require.NoError(t, err) require.Len(t, ops, 2) @@ -1216,20 +1216,20 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitchPortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lspName := "test-del-op-lsp" lsName := "test-del-op-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) - ops, err := ovnClient.DeleteLogicalSwitchPortOp(lspName) + ops, err := nbClient.DeleteLogicalSwitchPortOp(lspName) require.NoError(t, err) require.Len(t, ops, 1) diff --git a/pkg/ovs/ovn-nb-logical_switch_test.go b/pkg/ovs/ovn-nb-logical_switch_test.go index 8ab2b1d8b73..a506ccaab71 100644 --- a/pkg/ovs/ovn-nb-logical_switch_test.go +++ b/pkg/ovs/ovn-nb-logical_switch_test.go @@ -28,37 +28,37 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-create-ls-ls" lrName := "test-create-ls-lr" mac := util.GenerateMac() lspName := fmt.Sprintf("%s-%s", lsName, lrName) lrpName := fmt.Sprintf("%s-%s", lrName, lsName) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("create logical switch and router type port when logical switch does't exist and needRouter is true", func(t *testing.T) { - err = ovnClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:6400/120", "192.168.2.1,fd00::c0a8:6401", mac, true, false) + err = nbClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:6400/120", "192.168.2.1,fd00::c0a8:6401", mac, true, false) require.NoError(t, err) - _, err := ovnClient.GetLogicalSwitch(lsName, false) + _, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) - _, err = ovnClient.GetLogicalSwitchPort(lspName, false) + _, err = nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotNil(t, lrp) require.Equal(t, mac, lrp.MAC) }) t.Run("only update networks when logical switch exist and router type port exist and needRouter is true", func(t *testing.T) { - err = ovnClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:9900/120", "192.168.2.1,fd00::c0a8:9901", mac, true, false) + err = nbClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:9900/120", "192.168.2.1,fd00::c0a8:9901", mac, true, false) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotNil(t, lrp) require.ElementsMatch(t, []string{"192.168.2.1/24", "fd00::c0a8:9901/120"}, lrp.Networks) @@ -66,10 +66,10 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitch() { }) t.Run("don't update networks when logical switch exist and randomAllocateGW is true", func(t *testing.T) { - err = ovnClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:6400/120", "192.168.2.1,fd00::c0a8:6401", mac, true, true) + err = nbClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:6400/120", "192.168.2.1,fd00::c0a8:6401", mac, true, true) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.NotNil(t, lrp) require.ElementsMatch(t, []string{"192.168.2.1/24", "fd00::c0a8:9901/120"}, lrp.Networks) @@ -77,22 +77,22 @@ func (suite *OvnClientTestSuite) testCreateLogicalSwitch() { }) t.Run("remove router type port when needRouter is false", func(t *testing.T) { - err = ovnClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:9900/120", "192.168.2.1,fd00::c0a8:9901", "", false, false) + err = nbClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:9900/120", "192.168.2.1,fd00::c0a8:9901", "", false, false) require.NoError(t, err) }) t.Run("should no err when router type port doest't exist", func(t *testing.T) { - err = ovnClient.CreateLogicalSwitch(lsName+"-1", lrName+"-1", "192.168.2.0/24,fd00::c0a8:9900/120", "192.168.2.1,fd00::c0a8:9901", "", false, false) + err = nbClient.CreateLogicalSwitch(lsName+"-1", lrName+"-1", "192.168.2.0/24,fd00::c0a8:9900/120", "192.168.2.1,fd00::c0a8:9901", "", false, false) require.NoError(t, err) }) t.Run("create logical switch when logical switch does't exist and needRouter is false and randomAllocateGW is false", func(t *testing.T) { - err = ovnClient.CreateLogicalSwitch(lsName+"-2", lrName+"-2", "192.168.2.0/24,fd00::c0a8:9900/120", "192.168.2.1,fd00::c0a8:9901", "", false, true) + err = nbClient.CreateLogicalSwitch(lsName+"-2", lrName+"-2", "192.168.2.0/24,fd00::c0a8:9900/120", "192.168.2.1,fd00::c0a8:9901", "", false, true) require.NoError(t, err) }) t.Run("create logical switch using invalid gateway and cidrBlock", func(t *testing.T) { - err = ovnClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:6400/120", "192.168.2.1", mac, true, false) + err = nbClient.CreateLogicalSwitch(lsName, lrName, "192.168.2.0/24,fd00::c0a8:6400/120", "192.168.2.1", mac, true, false) require.ErrorContains(t, err, "ip 192.168.2.1 should be dualstack") }) } @@ -101,33 +101,33 @@ func (suite *OvnClientTestSuite) testLogicalSwitchAddPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-add-port-ls" lspName := "test-add-port-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) t.Run("add port to logical switch", func(t *testing.T) { - err = ovnClient.LogicalSwitchAddPort(lsName, lspName) + err = nbClient.LogicalSwitchAddPort(lsName, lspName) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Contains(t, ls.Ports, lsp.UUID) }) t.Run("add port to logical switch repeatedly", func(t *testing.T) { - err = ovnClient.LogicalSwitchAddPort(lsName, lspName) + err = nbClient.LogicalSwitchAddPort(lsName, lspName) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Contains(t, ls.Ports, lsp.UUID) }) @@ -137,40 +137,40 @@ func (suite *OvnClientTestSuite) testLogicalSwitchDelPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-del-port-ls" lspName := "test-del-port-lsp" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) - err = ovnClient.LogicalSwitchAddPort(lsName, lspName) + err = nbClient.LogicalSwitchAddPort(lsName, lspName) require.NoError(t, err) t.Run("del port from logical switch", func(t *testing.T) { - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Contains(t, ls.Ports, lsp.UUID) - err = ovnClient.LogicalSwitchDelPort(lsName, lspName) + err = nbClient.LogicalSwitchDelPort(lsName, lspName) require.NoError(t, err) - ls, err = ovnClient.GetLogicalSwitch(lsName, false) + ls, err = nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.NotContains(t, ls.Ports, lsp.UUID) }) t.Run("del port from logical switch repeatedly", func(t *testing.T) { - err := ovnClient.LogicalSwitchDelPort(lsName, lspName) + err := nbClient.LogicalSwitchDelPort(lsName, lspName) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.NotContains(t, ls.Ports, lsp.UUID) }) @@ -180,30 +180,30 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateLoadBalancers() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-add-lb-to-ls" prefix := "test-add-lb" lbNames := make([]string, 0, 3) - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) for i := 1; i <= 3; i++ { lbName := fmt.Sprintf("%s-%d", prefix, i) lbNames = append(lbNames, lbName) - err := ovnClient.CreateLoadBalancer(lbName, "tcp", "") + err := nbClient.CreateLoadBalancer(lbName, "tcp", "") require.NoError(t, err) } t.Run("add lbs to logical switch", func(t *testing.T) { - err = ovnClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationInsert, lbNames...) + err = nbClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationInsert, lbNames...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) for _, lbName := range lbNames { - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.Contains(t, ls.LoadBalancer, lb.UUID) } @@ -211,20 +211,20 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateLoadBalancers() { t.Run("should no err when add non-existent lbs to logical switch", func(t *testing.T) { // add a non-existent lb - err = ovnClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationInsert, "test-add-lb-non-existent") + err = nbClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationInsert, "test-add-lb-non-existent") require.NoError(t, err) }) t.Run("del lbs from logical switch", func(t *testing.T) { // delete the first two lbs from logical switch - err = ovnClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationDelete, lbNames[0:2]...) + err = nbClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationDelete, lbNames[0:2]...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) for i, lbName := range lbNames { - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) // logical switch contains the last lb @@ -237,17 +237,17 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateLoadBalancers() { }) t.Run("del non-existent lbs from logical switch", func(t *testing.T) { - err = ovnClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationDelete, []string{"test-del-lb-non-existent", "test-del-lb-non-existent-1"}...) + err = nbClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationDelete, []string{"test-del-lb-non-existent", "test-del-lb-non-existent-1"}...) require.NoError(t, err) }) t.Run("update with empty load balancer list", func(t *testing.T) { - err := ovnClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationInsert) + err := nbClient.LogicalSwitchUpdateLoadBalancers(lsName, ovsdb.MutateOperationInsert) require.NoError(t, err) }) t.Run("update load balancers for non-existent logical switch", func(t *testing.T) { - err := ovnClient.LogicalSwitchUpdateLoadBalancers("non-existent-ls", ovsdb.MutateOperationInsert, lbNames...) + err := nbClient.LogicalSwitchUpdateLoadBalancers("non-existent-ls", ovsdb.MutateOperationInsert, lbNames...) require.Error(t, err) require.Contains(t, err.Error(), "not found logical switch") }) @@ -257,24 +257,24 @@ func (suite *OvnClientTestSuite) testDeleteLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient name := "test-delete-ls" t.Run("no err when delete existent logical switch", func(t *testing.T) { t.Parallel() - err := ovnClient.CreateBareLogicalSwitch(name) + err := nbClient.CreateBareLogicalSwitch(name) require.NoError(t, err) - err = ovnClient.DeleteLogicalSwitch(name) + err = nbClient.DeleteLogicalSwitch(name) require.NoError(t, err) - _, err = ovnClient.GetLogicalSwitch(name, false) + _, err = nbClient.GetLogicalSwitch(name, false) require.ErrorContains(t, err, "not found logical switch") }) t.Run("no err when delete non-existent logical switch", func(t *testing.T) { t.Parallel() - err := ovnClient.DeleteLogicalSwitch("test-delete-ls-non-existent") + err := nbClient.DeleteLogicalSwitch("test-delete-ls-non-existent") require.NoError(t, err) }) } @@ -283,26 +283,26 @@ func (suite *OvnClientTestSuite) testGetLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient name := "test-get-ls" - err := ovnClient.CreateBareLogicalSwitch(name) + err := nbClient.CreateBareLogicalSwitch(name) require.NoError(t, err) t.Run("should return no err when found logical switch", func(t *testing.T) { - lr, err := ovnClient.GetLogicalSwitch(name, false) + lr, err := nbClient.GetLogicalSwitch(name, false) require.NoError(t, err) require.Equal(t, name, lr.Name) require.NotEmpty(t, lr.UUID) }) t.Run("should return err when not found logical switch", func(t *testing.T) { - _, err := ovnClient.GetLogicalSwitch("test-get-lr-non-existent", false) + _, err := nbClient.GetLogicalSwitch("test-get-lr-non-existent", false) require.ErrorContains(t, err, "not found logical switch") }) t.Run("no err when not found logical switch and ignoreNotFound is true", func(t *testing.T) { - _, err := ovnClient.GetLogicalSwitch("test-get-lr-non-existent", true) + _, err := nbClient.GetLogicalSwitch("test-get-lr-non-existent", true) require.NoError(t, err) }) } @@ -311,14 +311,14 @@ func (suite *OvnClientTestSuite) testListLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient namePrefix := "test-list-ls-" i := 0 // create three logical switch for ; i < 3; i++ { name := fmt.Sprintf("%s%d", namePrefix, i) - err := ovnClient.CreateBareLogicalSwitch(name) + err := nbClient.CreateBareLogicalSwitch(name) require.NoError(t, err) } @@ -330,7 +330,7 @@ func (suite *OvnClientTestSuite) testListLogicalSwitch() { ExternalIDs: map[string]string{"vendor": "test-vendor"}, } - err := createLogicalSwitch(ovnClient, ls) + err := createLogicalSwitch(nbClient, ls) require.NoError(t, err) } @@ -341,13 +341,13 @@ func (suite *OvnClientTestSuite) testListLogicalSwitch() { Name: name, } - err := createLogicalSwitch(ovnClient, ls) + err := createLogicalSwitch(nbClient, ls) require.NoError(t, err) } t.Run("return all logical switch which match vendor", func(t *testing.T) { t.Parallel() - lss, err := ovnClient.ListLogicalSwitch(true, nil) + lss, err := nbClient.ListLogicalSwitch(true, nil) require.NoError(t, err) require.NotEmpty(t, lss) @@ -362,7 +362,7 @@ func (suite *OvnClientTestSuite) testListLogicalSwitch() { t.Run("has custom filter", func(t *testing.T) { t.Parallel() - lss, err := ovnClient.ListLogicalSwitch(false, func(ls *ovnnb.LogicalSwitch) bool { + lss, err := nbClient.ListLogicalSwitch(false, func(ls *ovnnb.LogicalSwitch) bool { return len(ls.ExternalIDs) == 0 || ls.ExternalIDs["vendor"] != util.CniTypeName }) @@ -382,24 +382,24 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdatePortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-port-op-ls" lspName := "test-update-port-op-lsp" lspUUID := ovsclient.NamedUUID() - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotNil(t, lsp) t.Run("del port from logical switch", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalSwitchUpdatePortOp(lsName, lsp.UUID, ovsdb.MutateOperationDelete) + ops, err := nbClient.LogicalSwitchUpdatePortOp(lsName, lsp.UUID, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -418,44 +418,44 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdatePortOp() { t.Run("should return err when logical switch does not exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.LogicalSwitchUpdatePortOp("test-update-port-op-ls-non-existent", uuid.NewString(), ovsdb.MutateOperationInsert) + _, err := nbClient.LogicalSwitchUpdatePortOp("test-update-port-op-ls-non-existent", uuid.NewString(), ovsdb.MutateOperationInsert) require.ErrorContains(t, err, "not found logical switch") }) t.Run("update port with empty lspUUID", func(t *testing.T) { - ops, err := ovnClient.LogicalSwitchUpdatePortOp(lsName, "", ovsdb.MutateOperationInsert) + ops, err := nbClient.LogicalSwitchUpdatePortOp(lsName, "", ovsdb.MutateOperationInsert) require.NoError(t, err) require.Nil(t, ops) }) t.Run("delete port from non-existent logical switch", func(t *testing.T) { - _, err := ovnClient.LogicalSwitchUpdatePortOp("", ovsclient.NamedUUID(), ovsdb.MutateOperationDelete) + _, err := nbClient.LogicalSwitchUpdatePortOp("", ovsclient.NamedUUID(), ovsdb.MutateOperationDelete) require.Error(t, err) require.Contains(t, err.Error(), "no LS found for LSP") }) t.Run("delete port with multiple logical switches", func(t *testing.T) { lsName2 := "test-update-port-op-ls2" - err := ovnClient.CreateBareLogicalSwitch(lsName2) + err := nbClient.CreateBareLogicalSwitch(lsName2) require.NoError(t, err) lspName := "test-lsp-multiple" - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) - err = ovnClient.LogicalSwitchAddPort(lsName2, lspName) + err = nbClient.LogicalSwitchAddPort(lsName2, lspName) require.NoError(t, err) - _, err = ovnClient.LogicalSwitchUpdatePortOp("", lsp.UUID, ovsdb.MutateOperationDelete) + _, err = nbClient.LogicalSwitchUpdatePortOp("", lsp.UUID, ovsdb.MutateOperationDelete) require.Error(t, err) require.Contains(t, err.Error(), "multiple LS found for LSP") }) t.Run("insert port operation", func(t *testing.T) { - ops, err := ovnClient.LogicalSwitchUpdatePortOp(lsName, lspUUID, ovsdb.MutateOperationInsert) + ops, err := nbClient.LogicalSwitchUpdatePortOp(lsName, lspUUID, ovsdb.MutateOperationInsert) require.NoError(t, err) require.NotNil(t, ops) require.Len(t, ops, 1) @@ -467,16 +467,16 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateLoadBalancerOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-lb-ls" lbUUIDs := []string{ovsclient.NamedUUID(), ovsclient.NamedUUID(), ovsclient.NamedUUID()} - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("add new lb to logical switch", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalSwitchUpdateLoadBalancerOp(lsName, lbUUIDs, ovsdb.MutateOperationInsert) + ops, err := nbClient.LogicalSwitchUpdateLoadBalancerOp(lsName, lbUUIDs, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -501,7 +501,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateLoadBalancerOp() { t.Run("del port from logical switch", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.LogicalSwitchUpdateLoadBalancerOp(lsName, lbUUIDs, ovsdb.MutateOperationDelete) + ops, err := nbClient.LogicalSwitchUpdateLoadBalancerOp(lsName, lbUUIDs, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -526,7 +526,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateLoadBalancerOp() { t.Run("should no err when lbUUIDs is empty", func(t *testing.T) { t.Parallel() - _, err := ovnClient.LogicalSwitchUpdateLoadBalancerOp("test-port-op-ls-non-existent", nil, ovsdb.MutateOperationInsert) + _, err := nbClient.LogicalSwitchUpdateLoadBalancerOp("test-port-op-ls-non-existent", nil, ovsdb.MutateOperationInsert) require.NoError(t, err) }) } @@ -535,17 +535,17 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateACLOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-acl-op-ls" aclUUIDs := []string{ovsclient.NamedUUID(), ovsclient.NamedUUID()} - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("add new acl to logical switch", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.logicalSwitchUpdateACLOp(lsName, aclUUIDs, ovsdb.MutateOperationInsert) + ops, err := nbClient.logicalSwitchUpdateACLOp(lsName, aclUUIDs, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -568,7 +568,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateACLOp() { t.Run("del acl from logical switch", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.logicalSwitchUpdateACLOp(lsName, aclUUIDs, ovsdb.MutateOperationDelete) + ops, err := nbClient.logicalSwitchUpdateACLOp(lsName, aclUUIDs, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -591,7 +591,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateACLOp() { t.Run("should return err when logical switch does not exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.logicalSwitchUpdateACLOp("test-acl-op-ls-non-existent", aclUUIDs, ovsdb.MutateOperationInsert) + _, err := nbClient.logicalSwitchUpdateACLOp("test-acl-op-ls-non-existent", aclUUIDs, ovsdb.MutateOperationInsert) require.ErrorContains(t, err, "not found logical switch") }) } @@ -600,10 +600,10 @@ func (suite *OvnClientTestSuite) testLogicalSwitchOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-op-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) lspUUID := ovsclient.NamedUUID() @@ -628,7 +628,7 @@ func (suite *OvnClientTestSuite) testLogicalSwitchOp() { return mutation } - ops, err := ovnClient.LogicalSwitchOp(lsName, lspMutation, lbMutation) + ops, err := nbClient.LogicalSwitchOp(lsName, lspMutation, lbMutation) require.NoError(t, err) require.Len(t, ops[0].Mutations, 2) @@ -662,24 +662,24 @@ func (suite *OvnClientTestSuite) testCreateBareLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-create-bare-ls" t.Run("create new logical switch", func(t *testing.T) { - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Equal(t, lsName, ls.Name) require.Equal(t, util.CniTypeName, ls.ExternalIDs["vendor"]) }) t.Run("create existing logical switch", func(t *testing.T) { - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Equal(t, lsName, ls.Name) }) @@ -689,18 +689,18 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateOtherConfig() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-other-config-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("update other config with insert operation", func(t *testing.T) { otherConfig := map[string]string{"key1": "value1", "key2": "value2"} - err := ovnClient.LogicalSwitchUpdateOtherConfig(lsName, ovsdb.MutateOperationInsert, otherConfig) + err := nbClient.LogicalSwitchUpdateOtherConfig(lsName, ovsdb.MutateOperationInsert, otherConfig) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) require.Equal(t, otherConfig["key1"], ls.OtherConfig["key1"]) require.Equal(t, otherConfig["key2"], ls.OtherConfig["key2"]) @@ -708,10 +708,10 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateOtherConfig() { t.Run("update other config with delete operation", func(t *testing.T) { otherConfig := map[string]string{"key1": "value1"} - err := ovnClient.LogicalSwitchUpdateOtherConfig(lsName, ovsdb.MutateOperationDelete, otherConfig) + err := nbClient.LogicalSwitchUpdateOtherConfig(lsName, ovsdb.MutateOperationDelete, otherConfig) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) _, exists := ls.OtherConfig["key1"] require.False(t, exists) @@ -719,13 +719,13 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateOtherConfig() { }) t.Run("update other config with empty map", func(t *testing.T) { - err := ovnClient.LogicalSwitchUpdateOtherConfig(lsName, ovsdb.MutateOperationInsert, map[string]string{}) + err := nbClient.LogicalSwitchUpdateOtherConfig(lsName, ovsdb.MutateOperationInsert, map[string]string{}) require.NoError(t, err) }) t.Run("update other config for non-existent logical switch", func(t *testing.T) { otherConfig := map[string]string{"key3": "value3"} - err := ovnClient.LogicalSwitchUpdateOtherConfig("non-existent-ls", ovsdb.MutateOperationInsert, otherConfig) + err := nbClient.LogicalSwitchUpdateOtherConfig("non-existent-ls", ovsdb.MutateOperationInsert, otherConfig) require.Error(t, err) require.Contains(t, err.Error(), "not found logical switch") }) @@ -735,14 +735,14 @@ func (suite *OvnClientTestSuite) testLogicalSwitchUpdateOtherConfigOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-update-other-config-op-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("empty other_config map", func(t *testing.T) { - ops, err := ovnClient.LogicalSwitchUpdateOtherConfigOp(lsName, map[string]string{}, ovsdb.MutateOperationInsert) + ops, err := nbClient.LogicalSwitchUpdateOtherConfigOp(lsName, map[string]string{}, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Nil(t, ops) }) diff --git a/pkg/ovs/ovn-nb-nat_test.go b/pkg/ovs/ovn-nb-nat_test.go index c3e09e8fc9f..f55fa478e87 100644 --- a/pkg/ovs/ovn-nb-nat_test.go +++ b/pkg/ovs/ovn-nb-nat_test.go @@ -29,18 +29,18 @@ func (suite *OvnClientTestSuite) testCreateNats() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-create-nats-lr" externalIPs := []string{"192.168.30.254", "192.168.30.253"} logicalIPs := []string{"10.250.0.4", "10.250.0.5"} nats := make([]*ovnnb.NAT, 0, 5) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) // snat for _, logicalIP := range logicalIPs { - nat, err := ovnClient.newNat(lrName, "snat", externalIPs[0], logicalIP, "", "") + nat, err := nbClient.newNat(lrName, "snat", externalIPs[0], logicalIP, "", "") require.NoError(t, err) nats = append(nats, nat) @@ -48,21 +48,21 @@ func (suite *OvnClientTestSuite) testCreateNats() { // dnat_and_snat for _, externalIP := range externalIPs { - nat, err := ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0], "", "") + nat, err := nbClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0], "", "") require.NoError(t, err) nats = append(nats, nat) } - err = ovnClient.CreateNats(lrName, append(nats, nil)...) + err = nbClient.CreateNats(lrName, append(nats, nil)...) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) // snat for _, logicalIP := range logicalIPs { - nat, err := ovnClient.GetNat(lrName, "snat", externalIPs[0], logicalIP, false) + nat, err := nbClient.GetNat(lrName, "snat", externalIPs[0], logicalIP, false) require.NoError(t, err) require.Contains(t, lr.Nat, nat.UUID) @@ -70,7 +70,7 @@ func (suite *OvnClientTestSuite) testCreateNats() { // dnat_and_snat for _, externalIP := range externalIPs { - nat, err := ovnClient.GetNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0], false) + nat, err := nbClient.GetNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0], false) require.NoError(t, err) require.Contains(t, lr.Nat, nat.UUID) @@ -81,23 +81,23 @@ func (suite *OvnClientTestSuite) testUpdateSnat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-update-snat-lr" externalIP := "192.168.30.254" logicalIP := "10.250.0.4" natType := ovnnb.NATTypeSNAT - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("create snat", func(t *testing.T) { - err = ovnClient.UpdateSnat(lrName, externalIP, logicalIP) + err = nbClient.UpdateSnat(lrName, externalIP, logicalIP) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - nat, err := ovnClient.GetNat(lrName, natType, "", logicalIP, false) + nat, err := nbClient.GetNat(lrName, natType, "", logicalIP, false) require.NoError(t, err) require.Contains(t, lr.Nat, nat.UUID) @@ -105,10 +105,10 @@ func (suite *OvnClientTestSuite) testUpdateSnat() { t.Run("update snat", func(t *testing.T) { externalIP := "192.168.30.253" - err = ovnClient.UpdateSnat(lrName, externalIP, logicalIP) + err = nbClient.UpdateSnat(lrName, externalIP, logicalIP) require.NoError(t, err) - nat, err := ovnClient.GetNat(lrName, natType, "", logicalIP, false) + nat, err := nbClient.GetNat(lrName, natType, "", logicalIP, false) require.NoError(t, err) require.Equal(t, externalIP, nat.ExternalIP) }) @@ -118,7 +118,7 @@ func (suite *OvnClientTestSuite) testUpdateDnatAndSnat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-update-dnat-and-snat-lr" lspName := "test-update-dnat-and-snat-lrp" externalIP := "192.168.30.254" @@ -126,18 +126,18 @@ func (suite *OvnClientTestSuite) testUpdateDnatAndSnat() { natType := ovnnb.NATTypeDNATAndSNAT externalMac := "00:00:00:08:0a:de" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("create dnat_and_snat", func(t *testing.T) { t.Run("distributed gw", func(t *testing.T) { - err = ovnClient.UpdateDnatAndSnat(lrName, externalIP, logicalIP, lspName, externalMac, kubeovnv1.GWDistributedType) + err = nbClient.UpdateDnatAndSnat(lrName, externalIP, logicalIP, lspName, externalMac, kubeovnv1.GWDistributedType) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - nat, err := ovnClient.GetNat(lrName, natType, externalIP, "", false) + nat, err := nbClient.GetNat(lrName, natType, externalIP, "", false) require.NoError(t, err) require.Equal(t, lspName, *nat.LogicalPort) require.Equal(t, externalMac, *nat.ExternalMAC) @@ -149,13 +149,13 @@ func (suite *OvnClientTestSuite) testUpdateDnatAndSnat() { t.Run("centralized gw", func(t *testing.T) { externalIP := "192.168.30.250" - err = ovnClient.UpdateDnatAndSnat(lrName, externalIP, logicalIP, lspName, externalMac, kubeovnv1.GWCentralizedType) + err = nbClient.UpdateDnatAndSnat(lrName, externalIP, logicalIP, lspName, externalMac, kubeovnv1.GWCentralizedType) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - nat, err := ovnClient.GetNat(lrName, natType, externalIP, "", false) + nat, err := nbClient.GetNat(lrName, natType, externalIP, "", false) require.NoError(t, err) require.Empty(t, nat.Options["stateless"]) @@ -168,13 +168,13 @@ func (suite *OvnClientTestSuite) testUpdateDnatAndSnat() { lspName := "test-update-dnat-and-snat-lrp-1" externalMac := "00:00:00:08:0a:ff" - err = ovnClient.UpdateDnatAndSnat(lrName, externalIP, logicalIP, lspName, externalMac, kubeovnv1.GWDistributedType) + err = nbClient.UpdateDnatAndSnat(lrName, externalIP, logicalIP, lspName, externalMac, kubeovnv1.GWDistributedType) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - nat, err := ovnClient.GetNat(lrName, natType, externalIP, "", false) + nat, err := nbClient.GetNat(lrName, natType, externalIP, "", false) require.NoError(t, err) require.Equal(t, lspName, *nat.LogicalPort) require.Equal(t, externalMac, *nat.ExternalMAC) @@ -189,52 +189,52 @@ func (suite *OvnClientTestSuite) testDeleteNat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-del-nat-lr" externalIP := "192.168.30.254" logicalIP := "10.250.0.4" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) prepareFunc := func() { nats := make([]*ovnnb.NAT, 0) // create snat rule - nat, err := ovnClient.newNat(lrName, "snat", externalIP, logicalIP, "", "") + nat, err := nbClient.newNat(lrName, "snat", externalIP, logicalIP, "", "") require.NoError(t, err) nats = append(nats, nat) // create dnat_and_snat rule - nat, err = ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIP, "", "") + nat, err = nbClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIP, "", "") require.NoError(t, err) nats = append(nats, nat) - err = ovnClient.CreateNats(lrName, nats...) + err = nbClient.CreateNats(lrName, nats...) require.NoError(t, err) } prepareFunc() t.Run("delete snat from logical router", func(t *testing.T) { - err = ovnClient.DeleteNat(lrName, "snat", externalIP, logicalIP) + err = nbClient.DeleteNat(lrName, "snat", externalIP, logicalIP) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 1) nat := &ovnnb.NAT{UUID: lr.Nat[0]} - err = ovnClient.GetEntityInfo(nat) + err = nbClient.GetEntityInfo(nat) require.NoError(t, err) require.Equal(t, "dnat_and_snat", nat.Type) }) t.Run("delete dnat_and_snat from logical router", func(t *testing.T) { - err = ovnClient.DeleteNat(lrName, "dnat_and_snat", externalIP, logicalIP) + err = nbClient.DeleteNat(lrName, "dnat_and_snat", externalIP, logicalIP) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.Nat) }) @@ -244,45 +244,45 @@ func (suite *OvnClientTestSuite) testDeleteNats() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient 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"} - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) prepareFunc := func() { nats := make([]*ovnnb.NAT, 0) // create two snat rule for _, logicalIP := range logicalIPs { - nat, err := ovnClient.newNat(lrName, "snat", externalIPs[0], logicalIP, "", "") + nat, err := nbClient.newNat(lrName, "snat", externalIPs[0], logicalIP, "", "") require.NoError(t, err) nats = append(nats, nat) } // create two dnat_and_snat rule for _, externalIP := range externalIPs { - nat, err := ovnClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0], "", "") + nat, err := nbClient.newNat(lrName, "dnat_and_snat", externalIP, logicalIPs[0], "", "") require.NoError(t, err) nats = append(nats, nat) } - err = ovnClient.CreateNats(lrName, nats...) + err = nbClient.CreateNats(lrName, nats...) require.NoError(t, err) } t.Run("delete nats from logical router", func(t *testing.T) { prepareFunc() - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 4) - err = ovnClient.DeleteNats(lrName, "", "") + err = nbClient.DeleteNats(lrName, "", "") require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.Nat) }) @@ -290,21 +290,21 @@ func (suite *OvnClientTestSuite) testDeleteNats() { t.Run("delete snat or dnat_and_snat from logical router", func(t *testing.T) { prepareFunc() - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 4) - err = ovnClient.DeleteNats(lrName, "snat", "") + err = nbClient.DeleteNats(lrName, "snat", "") require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 2) - err = ovnClient.DeleteNats(lrName, "dnat_and_snat", "") + err = nbClient.DeleteNats(lrName, "dnat_and_snat", "") require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.Nat) }) @@ -312,22 +312,22 @@ func (suite *OvnClientTestSuite) testDeleteNats() { t.Run("delete nat with same logical ip from logical router", func(t *testing.T) { prepareFunc() - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 4) - err = ovnClient.DeleteNats(lrName, "", logicalIPs[0]) + err = nbClient.DeleteNats(lrName, "", logicalIPs[0]) require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 1) // clear - err = ovnClient.DeleteNats(lrName, "", "") + err = nbClient.DeleteNats(lrName, "", "") require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.Nat) }) @@ -335,22 +335,22 @@ func (suite *OvnClientTestSuite) testDeleteNats() { t.Run("delete snat with same logical ip from logical router", func(t *testing.T) { prepareFunc() - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 4) - err = ovnClient.DeleteNats(lrName, "snat", logicalIPs[0]) + err = nbClient.DeleteNats(lrName, "snat", logicalIPs[0]) require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 3) // clear - err = ovnClient.DeleteNats(lrName, "", "") + err = nbClient.DeleteNats(lrName, "", "") require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Empty(t, lr.Nat) }) @@ -358,14 +358,14 @@ func (suite *OvnClientTestSuite) testDeleteNats() { t.Run("delete dnat_and_snat with same logical ip from logical router", func(t *testing.T) { prepareFunc() - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 4) - err = ovnClient.DeleteNats(lrName, "dnat_and_snat", logicalIPs[0]) + err = nbClient.DeleteNats(lrName, "dnat_and_snat", logicalIPs[0]) require.NoError(t, err) - lr, err = ovnClient.GetLogicalRouter(lrName, false) + lr, err = nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) require.Len(t, lr.Nat, 2) }) @@ -375,10 +375,10 @@ func (suite *OvnClientTestSuite) testGetNat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test_get_nat_lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("snat", func(t *testing.T) { @@ -387,21 +387,21 @@ func (suite *OvnClientTestSuite) testGetNat() { externalIP := "192.168.30.254" logicalIP := "10.250.0.4" - err := ovnClient.AddNat(lrName, natType, externalIP, logicalIP, "", "", nil) + err := nbClient.AddNat(lrName, natType, externalIP, logicalIP, "", "", nil) require.NoError(t, err) t.Run("found nat", func(t *testing.T) { - _, err := ovnClient.GetNat(lrName, natType, externalIP, logicalIP, false) + _, err := nbClient.GetNat(lrName, natType, externalIP, logicalIP, false) require.NoError(t, err) }) t.Run("logical ip is different", func(t *testing.T) { - _, err := ovnClient.GetNat(lrName, natType, externalIP, "10.250.0.10", false) + _, err := nbClient.GetNat(lrName, natType, externalIP, "10.250.0.10", false) require.ErrorContains(t, err, "not found") }) t.Run("logical router name is different", func(t *testing.T) { - _, err := ovnClient.GetNat(lrName+"x", natType, externalIP, logicalIP, false) + _, err := nbClient.GetNat(lrName+"x", natType, externalIP, logicalIP, false) require.ErrorContains(t, err, "not found") }) }) @@ -412,16 +412,16 @@ func (suite *OvnClientTestSuite) testGetNat() { externalIP := "192.168.30.254" logicalIP := "10.250.0.4" - err := ovnClient.AddNat(lrName, natType, externalIP, logicalIP, "", "", nil) + err := nbClient.AddNat(lrName, natType, externalIP, logicalIP, "", "", nil) require.NoError(t, err) t.Run("found nat", func(t *testing.T) { - _, err := ovnClient.GetNat(lrName, natType, externalIP, logicalIP, false) + _, err := nbClient.GetNat(lrName, natType, externalIP, logicalIP, false) require.NoError(t, err) }) t.Run("external ip is different", func(t *testing.T) { - _, err := ovnClient.GetNat(lrName, natType, "192.168.30.255", logicalIP, false) + _, err := nbClient.GetNat(lrName, natType, "192.168.30.255", logicalIP, false) require.ErrorContains(t, err, "not found") }) }) @@ -431,13 +431,13 @@ func (suite *OvnClientTestSuite) testNewNat() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lrName := "test-new-nat-lr" natType := "snat" externalIP := "192.168.30.254" logicalIP := "10.250.0.4" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) t.Run("new snat rule", func(t *testing.T) { @@ -449,7 +449,7 @@ func (suite *OvnClientTestSuite) testNewNat() { LogicalIP: logicalIP, } - nat, err := ovnClient.newNat(lrName, natType, externalIP, logicalIP, "", "") + nat, err := nbClient.newNat(lrName, natType, externalIP, logicalIP, "", "") require.NoError(t, err) expect.UUID = nat.UUID require.Equal(t, expect, nat) @@ -475,7 +475,7 @@ func (suite *OvnClientTestSuite) testNewNat() { nat.ExternalMAC = &externalMac } - nat, err := ovnClient.newNat(lrName, natType, externalIP, logicalIP, "", "", options) + nat, err := nbClient.newNat(lrName, natType, externalIP, logicalIP, "", "", options) require.NoError(t, err) expect.UUID = nat.UUID require.Equal(t, expect, nat) diff --git a/pkg/ovs/ovn-nb-port_group_test.go b/pkg/ovs/ovn-nb-port_group_test.go index 0d3edc9ecbd..8058e80a6f6 100644 --- a/pkg/ovs/ovn-nb-port_group_test.go +++ b/pkg/ovs/ovn-nb-port_group_test.go @@ -17,7 +17,7 @@ func (suite *OvnClientTestSuite) testCreatePortGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("create new port group", func(t *testing.T) { pgName := "test-create-new-pg" @@ -26,10 +26,10 @@ func (suite *OvnClientTestSuite) testCreatePortGroup() { "key": "value", } - err := ovnClient.CreatePortGroup(pgName, externalIDs) + err := nbClient.CreatePortGroup(pgName, externalIDs) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Equal(t, pgName, pg.Name) require.Equal(t, externalIDs, pg.ExternalIDs) @@ -42,13 +42,13 @@ func (suite *OvnClientTestSuite) testCreatePortGroup() { "key": "value", } - err := ovnClient.CreatePortGroup(pgName, externalIDs) + err := nbClient.CreatePortGroup(pgName, externalIDs) require.NoError(t, err) - err = ovnClient.CreatePortGroup(pgName, map[string]string{"new": "data"}) + err = nbClient.CreatePortGroup(pgName, map[string]string{"new": "data"}) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Equal(t, pgName, pg.Name) require.Equal(t, externalIDs, pg.ExternalIDs) @@ -56,10 +56,10 @@ func (suite *OvnClientTestSuite) testCreatePortGroup() { t.Run("create port group with nil externalIDs", func(t *testing.T) { pgName := "test-create-pg-nil-externalids" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Equal(t, pgName, pg.Name) require.Empty(t, pg.ExternalIDs) @@ -67,10 +67,10 @@ func (suite *OvnClientTestSuite) testCreatePortGroup() { t.Run("create port group with empty externalIDs", func(t *testing.T) { pgName := "test-create-pg-empty-externalids" - err := ovnClient.CreatePortGroup(pgName, map[string]string{}) + err := nbClient.CreatePortGroup(pgName, map[string]string{}) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Equal(t, pgName, pg.Name) require.Empty(t, pg.ExternalIDs) @@ -81,40 +81,40 @@ func (suite *OvnClientTestSuite) testPortGroupResetPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-reset-pg-ports-ls" pgName := "test-reset-pg-ports-pg" prefix := "test-reset-pg-ports-lsp" lspNames := make([]string, 0, 3) - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) for i := 1; i <= 3; i++ { lspName := fmt.Sprintf("%s-%d", prefix, i) lspNames = append(lspNames, lspName) - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "unknown", "") require.NoError(t, err) } - err = ovnClient.CreatePortGroup(pgName, map[string]string{ + err = nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) require.NoError(t, err) - err = ovnClient.PortGroupAddPorts(pgName, lspNames...) + err = nbClient.PortGroupAddPorts(pgName, lspNames...) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.NotEmpty(t, pg.Ports) - err = ovnClient.PortGroupSetPorts(pgName, nil) + err = nbClient.PortGroupSetPorts(pgName, nil) require.NoError(t, err) - pg, err = ovnClient.GetPortGroup(pgName, false) + pg, err = nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, pg.Ports) @@ -124,16 +124,16 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-add-ports-to-pg" lsName := "test-add-ports-to-ls" prefix := "test-add-lsp" lspNames := make([]string, 0, 3) - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreatePortGroup(pgName, map[string]string{ + err = nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) @@ -142,19 +142,19 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePorts() { for i := 1; i <= 3; i++ { lspName := fmt.Sprintf("%s-%d", prefix, i) lspNames = append(lspNames, lspName) - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") require.NoError(t, err) } t.Run("add ports to port group", func(t *testing.T) { - err = ovnClient.PortGroupUpdatePorts(pgName, ovsdb.MutateOperationInsert, lspNames...) + err = nbClient.PortGroupUpdatePorts(pgName, ovsdb.MutateOperationInsert, lspNames...) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) for _, lspName := range lspNames { - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Contains(t, pg.Ports, lsp.UUID) } @@ -162,19 +162,19 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePorts() { t.Run("should no err when add non-existent ports to port group", func(t *testing.T) { // add a non-existent ports - err = ovnClient.PortGroupUpdatePorts(pgName, ovsdb.MutateOperationInsert, "test-add-lsp-non-existent") + err = nbClient.PortGroupUpdatePorts(pgName, ovsdb.MutateOperationInsert, "test-add-lsp-non-existent") require.NoError(t, err) }) t.Run("del ports from port group", func(t *testing.T) { - err = ovnClient.PortGroupUpdatePorts(pgName, ovsdb.MutateOperationDelete, lspNames[0:2]...) + err = nbClient.PortGroupUpdatePorts(pgName, ovsdb.MutateOperationDelete, lspNames[0:2]...) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) for i, lspName := range lspNames { - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) // port group contains the last ports @@ -188,7 +188,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePorts() { t.Run("del non-existent ports from port group", func(t *testing.T) { // del a non-existent ports - err = ovnClient.PortGroupUpdatePorts(pgName, ovsdb.MutateOperationDelete, "test-del-lsp-non-existent") + err = nbClient.PortGroupUpdatePorts(pgName, ovsdb.MutateOperationDelete, "test-del-lsp-non-existent") require.NoError(t, err) }) } @@ -197,24 +197,24 @@ func (suite *OvnClientTestSuite) testDeletePortGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-delete-pg" t.Run("no err when delete existent port group", func(t *testing.T) { t.Parallel() - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - err = ovnClient.DeletePortGroup(pgName) + err = nbClient.DeletePortGroup(pgName) require.NoError(t, err) - _, err = ovnClient.GetPortGroup(pgName, false) + _, err = nbClient.GetPortGroup(pgName, false) require.ErrorContains(t, err, "object not found") }) t.Run("no err when delete non-existent logical router", func(t *testing.T) { t.Parallel() - err := ovnClient.DeletePortGroup("test-delete-pg-non-existent") + err := nbClient.DeletePortGroup("test-delete-pg-non-existent") require.NoError(t, err) }) } @@ -223,10 +223,10 @@ func (suite *OvnClientTestSuite) testGetGetPortGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-get-pg" - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) @@ -234,7 +234,7 @@ func (suite *OvnClientTestSuite) testGetGetPortGroup() { t.Run("should return no err when found port group", func(t *testing.T) { t.Parallel() - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Equal(t, pgName, pg.Name) require.NotEmpty(t, pg.UUID) @@ -242,13 +242,13 @@ func (suite *OvnClientTestSuite) testGetGetPortGroup() { t.Run("should return err when not found port group", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetPortGroup("test-get-pg-non-existent", false) + _, err := nbClient.GetPortGroup("test-get-pg-non-existent", false) require.ErrorContains(t, err, "object not found") }) t.Run("no err when not found port group and ignoreNotFound is true", func(t *testing.T) { t.Parallel() - _, err := ovnClient.GetPortGroup("test-get-pg-non-existent", true) + _, err := nbClient.GetPortGroup("test-get-pg-non-existent", true) require.NoError(t, err) }) } @@ -257,15 +257,15 @@ func (suite *OvnClientTestSuite) testListPortGroups() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("result should exclude pg when externalIDs's length is not equal", func(t *testing.T) { pgName := "test-list-pg-mismatch-length" - err := ovnClient.CreatePortGroup(pgName, map[string]string{"key": "value"}) + err := nbClient.CreatePortGroup(pgName, map[string]string{"key": "value"}) require.NoError(t, err) - pgs, err := ovnClient.ListPortGroups(map[string]string{sgKey: "sg", "type": "security_group", "key": "value"}) + pgs, err := nbClient.ListPortGroups(map[string]string{sgKey: "sg", "type": "security_group", "key": "value"}) require.NoError(t, err) require.Empty(t, pgs) }) @@ -273,10 +273,10 @@ func (suite *OvnClientTestSuite) testListPortGroups() { t.Run("result should include lsp when key exists in pg column: external_ids", func(t *testing.T) { pgName := "test-list-pg-exist-key" - err := ovnClient.CreatePortGroup(pgName, map[string]string{sgKey: "sg", "type": "security_group", "key": "value"}) + err := nbClient.CreatePortGroup(pgName, map[string]string{sgKey: "sg", "type": "security_group", "key": "value"}) require.NoError(t, err) - pgs, err := ovnClient.ListPortGroups(map[string]string{"type": "security_group", "key": "value"}) + pgs, err := nbClient.ListPortGroups(map[string]string{"type": "security_group", "key": "value"}) require.NoError(t, err) require.Len(t, pgs, 1) require.Equal(t, pgName, pgs[0].Name) @@ -288,11 +288,11 @@ func (suite *OvnClientTestSuite) testListPortGroups() { for i := 0; i < 4; i++ { pgName := fmt.Sprintf("%s-%d", prefix, i) - err := ovnClient.CreatePortGroup(pgName, map[string]string{sgKey: "sg", "type": "security_group", "key": "value"}) + err := nbClient.CreatePortGroup(pgName, map[string]string{sgKey: "sg", "type": "security_group", "key": "value"}) require.NoError(t, err) } - out, err := ovnClient.ListPortGroups(nil) + out, err := nbClient.ListPortGroups(nil) require.NoError(t, err) count := 0 for _, v := range out { @@ -302,7 +302,7 @@ func (suite *OvnClientTestSuite) testListPortGroups() { } require.Equal(t, count, 4) - out, err = ovnClient.ListPortGroups(map[string]string{}) + out, err = nbClient.ListPortGroups(map[string]string{}) require.NoError(t, err) count = 0 for _, v := range out { @@ -316,20 +316,20 @@ func (suite *OvnClientTestSuite) testListPortGroups() { t.Run("result should include pg which externalIDs[key] is ''", func(t *testing.T) { pgName := "test-list-pg-no-val" - err := ovnClient.CreatePortGroup(pgName, map[string]string{"sg_test": "sg", "type": "security_group", "key": "value"}) + err := nbClient.CreatePortGroup(pgName, map[string]string{"sg_test": "sg", "type": "security_group", "key": "value"}) require.NoError(t, err) - pgs, err := ovnClient.ListPortGroups(map[string]string{"sg_test": "", "key": ""}) + pgs, err := nbClient.ListPortGroups(map[string]string{"sg_test": "", "key": ""}) require.NoError(t, err) require.Len(t, pgs, 1) require.Equal(t, pgName, pgs[0].Name) - pgs, err = ovnClient.ListPortGroups(map[string]string{"sg_test": ""}) + pgs, err = nbClient.ListPortGroups(map[string]string{"sg_test": ""}) require.NoError(t, err) require.Len(t, pgs, 1) require.Equal(t, pgName, pgs[0].Name) - pgs, err = ovnClient.ListPortGroups(map[string]string{"sg_test": "", "key": "", "key1": ""}) + pgs, err = nbClient.ListPortGroups(map[string]string{"sg_test": "", "key": "", "key1": ""}) require.NoError(t, err) require.Empty(t, pgs) }) @@ -339,11 +339,11 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePortOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-update-port-op-pg" lspUUIDs := []string{ovsclient.NamedUUID(), ovsclient.NamedUUID()} - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) @@ -352,7 +352,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePortOp() { t.Run("add new port to port group", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.portGroupUpdatePortOp(pgName, lspUUIDs, ovsdb.MutateOperationInsert) + ops, err := nbClient.portGroupUpdatePortOp(pgName, lspUUIDs, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -375,7 +375,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePortOp() { t.Run("del port from port group", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.portGroupUpdatePortOp(pgName, lspUUIDs, ovsdb.MutateOperationDelete) + ops, err := nbClient.portGroupUpdatePortOp(pgName, lspUUIDs, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -398,7 +398,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdatePortOp() { t.Run("should return err when port group does not exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.portGroupUpdatePortOp("test-port-op-pg-non-existent", lspUUIDs, ovsdb.MutateOperationInsert) + _, err := nbClient.portGroupUpdatePortOp("test-port-op-pg-non-existent", lspUUIDs, ovsdb.MutateOperationInsert) require.ErrorContains(t, err, "object not found") }) } @@ -407,11 +407,11 @@ func (suite *OvnClientTestSuite) testPortGroupUpdateACLOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-update-acl-op-pg" aclUUIDs := []string{ovsclient.NamedUUID(), ovsclient.NamedUUID()} - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) @@ -420,7 +420,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdateACLOp() { t.Run("add new acl to port group", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.portGroupUpdateACLOp(pgName, aclUUIDs, ovsdb.MutateOperationInsert) + ops, err := nbClient.portGroupUpdateACLOp(pgName, aclUUIDs, ovsdb.MutateOperationInsert) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -443,7 +443,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdateACLOp() { t.Run("del acl from port group", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.portGroupUpdateACLOp(pgName, aclUUIDs, ovsdb.MutateOperationDelete) + ops, err := nbClient.portGroupUpdateACLOp(pgName, aclUUIDs, ovsdb.MutateOperationDelete) require.NoError(t, err) require.Equal(t, []ovsdb.Mutation{ { @@ -466,7 +466,7 @@ func (suite *OvnClientTestSuite) testPortGroupUpdateACLOp() { t.Run("should return err when port group does not exist", func(t *testing.T) { t.Parallel() - _, err := ovnClient.portGroupUpdateACLOp("test-acl-op-pg-non-existent", aclUUIDs, ovsdb.MutateOperationInsert) + _, err := nbClient.portGroupUpdateACLOp("test-acl-op-pg-non-existent", aclUUIDs, ovsdb.MutateOperationInsert) require.ErrorContains(t, err, "object not found") }) } @@ -475,10 +475,10 @@ func (suite *OvnClientTestSuite) testPortGroupOp() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-port-op-pg" - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) @@ -506,7 +506,7 @@ func (suite *OvnClientTestSuite) testPortGroupOp() { return mutation } - ops, err := ovnClient.portGroupOp(pgName, lspMutation, aclMutation) + ops, err := nbClient.portGroupOp(pgName, lspMutation, aclMutation) require.NoError(t, err) require.Len(t, ops[0].Mutations, 2) @@ -540,16 +540,16 @@ func (suite *OvnClientTestSuite) testPortGroupRemovePorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-remove-ports-pg" lsName := "test-remove-ports-ls" prefix := "test-remove-lsp" lspNames := make([]string, 0, 5) - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreatePortGroup(pgName, map[string]string{ + err = nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) @@ -558,62 +558,62 @@ func (suite *OvnClientTestSuite) testPortGroupRemovePorts() { for i := 1; i <= 5; i++ { lspName := fmt.Sprintf("%s-%d", prefix, i) lspNames = append(lspNames, lspName) - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") require.NoError(t, err) } - err = ovnClient.PortGroupAddPorts(pgName, lspNames...) + err = nbClient.PortGroupAddPorts(pgName, lspNames...) require.NoError(t, err) t.Run("remove some ports from port group", func(t *testing.T) { portsToRemove := lspNames[0:3] - err = ovnClient.PortGroupRemovePorts(pgName, portsToRemove...) + err = nbClient.PortGroupRemovePorts(pgName, portsToRemove...) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) for _, lspName := range portsToRemove { - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotContains(t, pg.Ports, lsp.UUID) } for _, lspName := range lspNames[3:] { - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Contains(t, pg.Ports, lsp.UUID) } }) t.Run("remove all remaining ports from port group", func(t *testing.T) { - err = ovnClient.PortGroupRemovePorts(pgName, lspNames[3:]...) + err = nbClient.PortGroupRemovePorts(pgName, lspNames[3:]...) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, pg.Ports) }) t.Run("remove non-existent ports from port group", func(t *testing.T) { - err = ovnClient.PortGroupRemovePorts(pgName, "non-existent-lsp-1", "non-existent-lsp-2") + err = nbClient.PortGroupRemovePorts(pgName, "non-existent-lsp-1", "non-existent-lsp-2") require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, pg.Ports) }) t.Run("remove ports from non-existent port group", func(t *testing.T) { - err = ovnClient.PortGroupRemovePorts("non-existent-pg", lspNames...) + err = nbClient.PortGroupRemovePorts("non-existent-pg", lspNames...) require.ErrorContains(t, err, "object not found") }) t.Run("remove no ports from port group", func(t *testing.T) { - err = ovnClient.PortGroupRemovePorts(pgName) + err = nbClient.PortGroupRemovePorts(pgName) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, pg.Ports) }) @@ -623,18 +623,18 @@ func (suite *OvnClientTestSuite) testUpdatePortGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Run("update external_ids", func(t *testing.T) { pgName := "test-update-external" - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) newExternalIDs := map[string]string{ @@ -644,10 +644,10 @@ func (suite *OvnClientTestSuite) testUpdatePortGroup() { } pg.ExternalIDs = newExternalIDs - err = ovnClient.UpdatePortGroup(pg, &pg.ExternalIDs) + err = nbClient.UpdatePortGroup(pg, &pg.ExternalIDs) require.NoError(t, err) - updatedPg, err := ovnClient.GetPortGroup(pgName, false) + updatedPg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Equal(t, newExternalIDs, updatedPg.ExternalIDs) }) @@ -655,25 +655,25 @@ func (suite *OvnClientTestSuite) testUpdatePortGroup() { t.Run("update name", func(t *testing.T) { pgName := "test-update-name" - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) newName := "updated-" + pgName pg.Name = newName - err = ovnClient.UpdatePortGroup(pg, &pg.Name) + err = nbClient.UpdatePortGroup(pg, &pg.Name) require.NoError(t, err) - _, err = ovnClient.GetPortGroup(pgName, false) + _, err = nbClient.GetPortGroup(pgName, false) require.Error(t, err) - updatedPg, err := ovnClient.GetPortGroup(newName, false) + updatedPg, err := nbClient.GetPortGroup(newName, false) require.NoError(t, err) require.Equal(t, newName, updatedPg.Name) }) @@ -681,22 +681,22 @@ func (suite *OvnClientTestSuite) testUpdatePortGroup() { t.Run("update multiple fields", func(t *testing.T) { pgName := "test-update-multiple" - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) pg.Name = pgName pg.ExternalIDs = map[string]string{"key": "value"} - err = ovnClient.UpdatePortGroup(pg, &pg.Name, &pg.ExternalIDs) + err = nbClient.UpdatePortGroup(pg, &pg.Name, &pg.ExternalIDs) require.NoError(t, err) - updatedPg, err := ovnClient.GetPortGroup(pgName, false) + updatedPg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Equal(t, pgName, updatedPg.Name) require.Equal(t, map[string]string{"key": "value"}, updatedPg.ExternalIDs) @@ -705,19 +705,19 @@ func (suite *OvnClientTestSuite) testUpdatePortGroup() { t.Run("update port group with no changes", func(t *testing.T) { pgName := "test-update-no-changes" - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) - err = ovnClient.UpdatePortGroup(pg) + err = nbClient.UpdatePortGroup(pg) require.NoError(t, err) - updatedPg, err := ovnClient.GetPortGroup(pgName, false) + updatedPg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Equal(t, pg, updatedPg) }) @@ -725,30 +725,30 @@ func (suite *OvnClientTestSuite) testUpdatePortGroup() { t.Run("update port group with invalid field", func(t *testing.T) { pgName := "test-update-invalid-field" - err := ovnClient.CreatePortGroup(pgName, nil) + err := nbClient.CreatePortGroup(pgName, nil) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) - err = ovnClient.UpdatePortGroup(pg, "InvalidField") + err = nbClient.UpdatePortGroup(pg, "InvalidField") require.Error(t, err) }) t.Run("update port group with nil value", func(t *testing.T) { pgName := "test-update-nil-value" - err := ovnClient.CreatePortGroup(pgName, map[string]string{"key": "value"}) + err := nbClient.CreatePortGroup(pgName, map[string]string{"key": "value"}) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) pg.ExternalIDs = nil - err = ovnClient.UpdatePortGroup(pg, &pg.ExternalIDs) + err = nbClient.UpdatePortGroup(pg, &pg.ExternalIDs) require.NoError(t, err) - updatedPg, err := ovnClient.GetPortGroup(pgName, false) + updatedPg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, updatedPg.ExternalIDs) }) @@ -758,16 +758,16 @@ func (suite *OvnClientTestSuite) testPortGroupSetPorts() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient pgName := "test-set-ports-pg" lsName := "test-set-ports-ls" prefix := "test-set-lsp" lspNames := make([]string, 0, 5) - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreatePortGroup(pgName, map[string]string{ + err = nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: "test-sg", }) @@ -776,21 +776,21 @@ func (suite *OvnClientTestSuite) testPortGroupSetPorts() { for i := 1; i <= 5; i++ { lspName := fmt.Sprintf("%s-%d", prefix, i) lspNames = append(lspNames, lspName) - err := ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") + err := nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") require.NoError(t, err) } t.Run("set ports to empty port group", func(t *testing.T) { portsToSet := lspNames[0:3] - err = ovnClient.PortGroupSetPorts(pgName, portsToSet) + err = nbClient.PortGroupSetPorts(pgName, portsToSet) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.Ports, 3) for _, lspName := range portsToSet { - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Contains(t, pg.Ports, lsp.UUID) } @@ -798,58 +798,58 @@ func (suite *OvnClientTestSuite) testPortGroupSetPorts() { t.Run("set ports to non-empty port group", func(t *testing.T) { portsToSet := lspNames[2:5] - err = ovnClient.PortGroupSetPorts(pgName, portsToSet) + err = nbClient.PortGroupSetPorts(pgName, portsToSet) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.Ports, 3) for _, lspName := range portsToSet { - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Contains(t, pg.Ports, lsp.UUID) } for _, lspName := range lspNames[0:2] { - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.NotContains(t, pg.Ports, lsp.UUID) } }) t.Run("set ports to empty list", func(t *testing.T) { - err = ovnClient.PortGroupSetPorts(pgName, []string{}) + err = nbClient.PortGroupSetPorts(pgName, []string{}) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Empty(t, pg.Ports) }) t.Run("set ports with non-existent logical switch ports", func(t *testing.T) { portsToSet := append(lspNames[0:2], "non-existent-lsp") - err = ovnClient.PortGroupSetPorts(pgName, portsToSet) + err = nbClient.PortGroupSetPorts(pgName, portsToSet) require.NoError(t, err) - pg, err := ovnClient.GetPortGroup(pgName, false) + pg, err := nbClient.GetPortGroup(pgName, false) require.NoError(t, err) require.Len(t, pg.Ports, 2) for _, lspName := range lspNames[0:2] { - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Contains(t, pg.Ports, lsp.UUID) } }) t.Run("set ports to non-existent port group", func(t *testing.T) { - err = ovnClient.PortGroupSetPorts("non-existent-pg", lspNames) + err = nbClient.PortGroupSetPorts("non-existent-pg", lspNames) require.Error(t, err) }) t.Run("set ports with empty port group name", func(t *testing.T) { - err = ovnClient.PortGroupSetPorts("", lspNames) + err = nbClient.PortGroupSetPorts("", lspNames) require.Error(t, err) }) } diff --git a/pkg/ovs/ovn-nb_global_test.go b/pkg/ovs/ovn-nb_global_test.go index 0104d76dbfd..8067471c76d 100644 --- a/pkg/ovs/ovn-nb_global_test.go +++ b/pkg/ovs/ovn-nb_global_test.go @@ -21,27 +21,27 @@ func mockNBGlobal() *ovnnb.NBGlobal { func (suite *OvnClientTestSuite) testGetNbGlobal() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) t.Run("return err when not found nb_global", func(t *testing.T) { - _, err := ovnClient.GetNbGlobal() + _, err := nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) t.Run("no err when found nb_global", func(t *testing.T) { nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.NotEmpty(t, out.UUID) }) @@ -50,18 +50,18 @@ func (suite *OvnClientTestSuite) testGetNbGlobal() { func (suite *OvnClientTestSuite) testUpdateNbGlobal() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) - nbGlobal, err = ovnClient.GetNbGlobal() + nbGlobal, err = nbClient.GetNbGlobal() require.NoError(t, err) t.Run("normal update", func(t *testing.T) { @@ -70,10 +70,10 @@ func (suite *OvnClientTestSuite) testUpdateNbGlobal() { "max_tunid": "16711680", } - err = ovnClient.UpdateNbGlobal(nbGlobal) + err = nbClient.UpdateNbGlobal(nbGlobal) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "11:22:aa", out.Options["mac_prefix"]) require.Equal(t, "16711680", out.Options["max_tunid"]) @@ -84,10 +84,10 @@ func (suite *OvnClientTestSuite) testUpdateNbGlobal() { UUID: nbGlobal.UUID, } - err = ovnClient.UpdateNbGlobal(nbGlobal, &nbGlobal.Name, &nbGlobal.Options) + err = nbClient.UpdateNbGlobal(nbGlobal, &nbGlobal.Name, &nbGlobal.Options) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Empty(t, out.Name) require.Empty(t, out.Options) @@ -97,64 +97,64 @@ func (suite *OvnClientTestSuite) testUpdateNbGlobal() { func (suite *OvnClientTestSuite) testSetAzName() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) t.Run("set az name", func(t *testing.T) { - err = ovnClient.SetAzName("test-az") + err = nbClient.SetAzName("test-az") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "test-az", out.Name) }) t.Run("clear az name", func(t *testing.T) { - err = ovnClient.SetAzName("") + err = nbClient.SetAzName("") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Empty(t, out.Name) }) t.Run("set az name when it's different", func(t *testing.T) { - err = ovnClient.SetAzName("new-az") + err = nbClient.SetAzName("new-az") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "new-az", out.Name) }) t.Run("set az name when it's the same", func(t *testing.T) { - err = ovnClient.SetAzName("new-az") + err = nbClient.SetAzName("new-az") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "new-az", out.Name) }) t.Run("set az name when GetNbGlobal fails", func(t *testing.T) { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - err = ovnClient.SetAzName("test-az") + err = nbClient.SetAzName("test-az") require.Error(t, err) require.Contains(t, err.Error(), "failed to get nb global") - err = ovnClient.CreateNbGlobal(nbGlobal) + err = nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) }) } @@ -162,25 +162,25 @@ func (suite *OvnClientTestSuite) testSetAzName() { func (suite *OvnClientTestSuite) testSetICAutoRoute() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) t.Run("enable ovn-ic auto route", func(t *testing.T) { - err = ovnClient.SetICAutoRoute(true, []string{"1.1.1.1", "2.2.2.2"}) + err = nbClient.SetICAutoRoute(true, []string{"1.1.1.1", "2.2.2.2"}) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "true", out.Options["ic-route-adv"]) require.Equal(t, "true", out.Options["ic-route-learn"]) @@ -188,10 +188,10 @@ func (suite *OvnClientTestSuite) testSetICAutoRoute() { }) t.Run("disable ovn-ic auto route", func(t *testing.T) { - err = ovnClient.SetICAutoRoute(false, []string{"1.1.1.1", "2.2.2.2"}) + err = nbClient.SetICAutoRoute(false, []string{"1.1.1.1", "2.2.2.2"}) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.NotContains(t, out.Options, "ic-route-adv") require.NotContains(t, out.Options, "ic-route-learn") @@ -199,10 +199,10 @@ func (suite *OvnClientTestSuite) testSetICAutoRoute() { }) t.Run("enable ovn-ic auto route with empty blacklist", func(t *testing.T) { - err = ovnClient.SetICAutoRoute(true, []string{}) + err = nbClient.SetICAutoRoute(true, []string{}) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "true", out.Options["ic-route-adv"]) require.Equal(t, "true", out.Options["ic-route-learn"]) @@ -210,10 +210,10 @@ func (suite *OvnClientTestSuite) testSetICAutoRoute() { }) t.Run("enable ovn-ic auto route with multiple blacklist entries", func(t *testing.T) { - err = ovnClient.SetICAutoRoute(true, []string{"1.1.1.1", "2.2.2.2", "3.3.3.3"}) + err = nbClient.SetICAutoRoute(true, []string{"1.1.1.1", "2.2.2.2", "3.3.3.3"}) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "true", out.Options["ic-route-adv"]) require.Equal(t, "true", out.Options["ic-route-learn"]) @@ -221,13 +221,13 @@ func (suite *OvnClientTestSuite) testSetICAutoRoute() { }) t.Run("enable ovn-ic auto route when already enabled", func(t *testing.T) { - err = ovnClient.SetICAutoRoute(true, []string{"1.1.1.1"}) + err = nbClient.SetICAutoRoute(true, []string{"1.1.1.1"}) require.NoError(t, err) - err = ovnClient.SetICAutoRoute(true, []string{"1.1.1.1"}) + err = nbClient.SetICAutoRoute(true, []string{"1.1.1.1"}) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "true", out.Options["ic-route-adv"]) require.Equal(t, "true", out.Options["ic-route-learn"]) @@ -235,13 +235,13 @@ func (suite *OvnClientTestSuite) testSetICAutoRoute() { }) t.Run("disable ovn-ic auto route when already disabled", func(t *testing.T) { - err = ovnClient.SetICAutoRoute(false, []string{}) + err = nbClient.SetICAutoRoute(false, []string{}) require.NoError(t, err) - err = ovnClient.SetICAutoRoute(false, []string{}) + err = nbClient.SetICAutoRoute(false, []string{}) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.NotContains(t, out.Options, "ic-route-adv") require.NotContains(t, out.Options, "ic-route-learn") @@ -249,14 +249,14 @@ func (suite *OvnClientTestSuite) testSetICAutoRoute() { }) t.Run("set ovn-ic auto route when GetNbGlobal fails", func(t *testing.T) { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - err = ovnClient.SetICAutoRoute(true, []string{"1.1.1.1"}) + err = nbClient.SetICAutoRoute(true, []string{"1.1.1.1"}) require.Error(t, err) require.Contains(t, err.Error(), "failed to get nb global") - err = ovnClient.CreateNbGlobal(nbGlobal) + err = nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) }) } @@ -264,24 +264,24 @@ func (suite *OvnClientTestSuite) testSetICAutoRoute() { func (suite *OvnClientTestSuite) testSetUseCtInvMatch() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) - err = ovnClient.SetUseCtInvMatch() + err = nbClient.SetUseCtInvMatch() require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "false", out.Options["use_ct_inv_match"]) } @@ -289,25 +289,25 @@ func (suite *OvnClientTestSuite) testSetUseCtInvMatch() { func (suite *OvnClientTestSuite) testSetLBCIDR() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient serviceCIDR := "10.96.0.0/12" t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) - err = ovnClient.SetLBCIDR(serviceCIDR) + err = nbClient.SetLBCIDR(serviceCIDR) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, serviceCIDR, out.Options["svc_ipv4_cidr"]) } @@ -315,58 +315,58 @@ func (suite *OvnClientTestSuite) testSetLBCIDR() { func (suite *OvnClientTestSuite) testSetOVNIPSec() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) t.Run("enable OVN IPSec", func(t *testing.T) { - err = ovnClient.SetOVNIPSec(true) + err = nbClient.SetOVNIPSec(true) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.True(t, out.Ipsec) }) t.Run("disable OVN IPSec", func(t *testing.T) { - err = ovnClient.SetOVNIPSec(false) + err = nbClient.SetOVNIPSec(false) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.False(t, out.Ipsec) }) t.Run("set OVN IPSec when it's already set", func(t *testing.T) { - err = ovnClient.SetOVNIPSec(true) + err = nbClient.SetOVNIPSec(true) require.NoError(t, err) - err = ovnClient.SetOVNIPSec(true) + err = nbClient.SetOVNIPSec(true) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.True(t, out.Ipsec) }) t.Run("set OVN IPSec when GetNbGlobal fails", func(t *testing.T) { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - err = ovnClient.SetOVNIPSec(true) + err = nbClient.SetOVNIPSec(true) require.Error(t, err) require.Contains(t, err.Error(), "failed to get nb global") - err = ovnClient.CreateNbGlobal(nbGlobal) + err = nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) }) } @@ -374,85 +374,85 @@ func (suite *OvnClientTestSuite) testSetOVNIPSec() { func (suite *OvnClientTestSuite) testSetNbGlobalOptions() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) t.Run("set new option", func(t *testing.T) { - err := ovnClient.SetNbGlobalOptions("new_option", "new_value") + err := nbClient.SetNbGlobalOptions("new_option", "new_value") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "new_value", out.Options["new_option"]) }) t.Run("update existing option", func(t *testing.T) { - err := ovnClient.SetNbGlobalOptions("mac_prefix", "aa:bb:cc") + err := nbClient.SetNbGlobalOptions("mac_prefix", "aa:bb:cc") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "aa:bb:cc", out.Options["mac_prefix"]) }) t.Run("set option with non-string value", func(t *testing.T) { - err := ovnClient.SetNbGlobalOptions("numeric_option", 42) + err := nbClient.SetNbGlobalOptions("numeric_option", 42) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "42", out.Options["numeric_option"]) }) t.Run("set option when options map is nil", func(t *testing.T) { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) nbGlobal.Options = nil - err = ovnClient.CreateNbGlobal(nbGlobal) + err = nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) - err = ovnClient.SetNbGlobalOptions("new_option", "new_value") + err = nbClient.SetNbGlobalOptions("new_option", "new_value") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "new_value", out.Options["new_option"]) }) t.Run("set option with same value (no update)", func(t *testing.T) { - err := ovnClient.SetNbGlobalOptions("existing_option", "existing_value") + err := nbClient.SetNbGlobalOptions("existing_option", "existing_value") require.NoError(t, err) - err = ovnClient.SetNbGlobalOptions("existing_option", "existing_value") + err = nbClient.SetNbGlobalOptions("existing_option", "existing_value") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "existing_value", out.Options["existing_option"]) }) t.Run("set option when GetNbGlobal fails", func(t *testing.T) { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - err = ovnClient.SetNbGlobalOptions("test_option", "test_value") + err = nbClient.SetNbGlobalOptions("test_option", "test_value") require.Error(t, err) require.Contains(t, err.Error(), "failed to get nb global") - err = ovnClient.CreateNbGlobal(nbGlobal) + err = nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) }) } @@ -460,34 +460,34 @@ func (suite *OvnClientTestSuite) testSetNbGlobalOptions() { func (suite *OvnClientTestSuite) testSetLsDnatModDlDst() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) t.Run("enable ls_dnat_mod_dl_dst", func(t *testing.T) { - err := ovnClient.SetLsDnatModDlDst(true) + err := nbClient.SetLsDnatModDlDst(true) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "true", out.Options["ls_dnat_mod_dl_dst"]) }) t.Run("disable ls_dnat_mod_dl_dst", func(t *testing.T) { - err := ovnClient.SetLsDnatModDlDst(false) + err := nbClient.SetLsDnatModDlDst(false) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "false", out.Options["ls_dnat_mod_dl_dst"]) }) @@ -496,34 +496,34 @@ func (suite *OvnClientTestSuite) testSetLsDnatModDlDst() { func (suite *OvnClientTestSuite) testSetLsCtSkipDstLportIPs() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) t.Run("enable ls_ct_skip_dst_lport_ips", func(t *testing.T) { - err := ovnClient.SetLsCtSkipDstLportIPs(true) + err := nbClient.SetLsCtSkipDstLportIPs(true) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "true", out.Options["ls_ct_skip_dst_lport_ips"]) }) t.Run("disable ls_ct_skip_dst_lport_ips", func(t *testing.T) { - err := ovnClient.SetLsCtSkipDstLportIPs(false) + err := nbClient.SetLsCtSkipDstLportIPs(false) require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "false", out.Options["ls_ct_skip_dst_lport_ips"]) }) @@ -532,83 +532,83 @@ func (suite *OvnClientTestSuite) testSetLsCtSkipDstLportIPs() { func (suite *OvnClientTestSuite) testSetNodeLocalDNSIP() { t := suite.T() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient t.Cleanup(func() { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - _, err = ovnClient.GetNbGlobal() + _, err = nbClient.GetNbGlobal() require.ErrorContains(t, err, "not found nb_global") }) nbGlobal := mockNBGlobal() - err := ovnClient.CreateNbGlobal(nbGlobal) + err := nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) t.Run("set node local DNS IP", func(t *testing.T) { - err := ovnClient.SetNodeLocalDNSIP("192.168.0.10") + err := nbClient.SetNodeLocalDNSIP("192.168.0.10") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "192.168.0.10", out.Options["node_local_dns_ip"]) }) t.Run("update existing node local DNS IP", func(t *testing.T) { - err := ovnClient.SetNodeLocalDNSIP("192.168.0.20") + err := nbClient.SetNodeLocalDNSIP("192.168.0.20") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "192.168.0.20", out.Options["node_local_dns_ip"]) }) t.Run("remove node local DNS IP", func(t *testing.T) { - err := ovnClient.SetNodeLocalDNSIP("") + err := nbClient.SetNodeLocalDNSIP("") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) _, exists := out.Options["node_local_dns_ip"] require.False(t, exists) }) t.Run("set node local DNS IP when options is nil", func(t *testing.T) { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) nbGlobal.Options = nil - err = ovnClient.CreateNbGlobal(nbGlobal) + err = nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) - err = ovnClient.SetNodeLocalDNSIP("192.168.0.30") + err = nbClient.SetNodeLocalDNSIP("192.168.0.30") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) require.Equal(t, "192.168.0.30", out.Options["node_local_dns_ip"]) }) t.Run("remove non-existent node local DNS IP", func(t *testing.T) { - err := ovnClient.SetNodeLocalDNSIP("") + err := nbClient.SetNodeLocalDNSIP("") require.NoError(t, err) - out, err := ovnClient.GetNbGlobal() + out, err := nbClient.GetNbGlobal() require.NoError(t, err) _, exists := out.Options["node_local_dns_ip"] require.False(t, exists) }) t.Run("set node local DNS IP when GetNbGlobal fails", func(t *testing.T) { - err := ovnClient.DeleteNbGlobal() + err := nbClient.DeleteNbGlobal() require.NoError(t, err) - err = ovnClient.SetNodeLocalDNSIP("") + err = nbClient.SetNodeLocalDNSIP("") require.Error(t, err) require.Contains(t, err.Error(), "failed to get nb global") - err = ovnClient.CreateNbGlobal(nbGlobal) + err = nbClient.CreateNbGlobal(nbGlobal) require.NoError(t, err) }) } diff --git a/pkg/ovs/ovn-nb_test.go b/pkg/ovs/ovn-nb_test.go index e42048e1583..5a0600c4ebe 100644 --- a/pkg/ovs/ovn-nb_test.go +++ b/pkg/ovs/ovn-nb_test.go @@ -14,7 +14,7 @@ func (suite *OvnClientTestSuite) testCreateGatewayLogicalSwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-create-gw-ls" lrName := "test-create-gw-lr" lspName := fmt.Sprintf("%s-%s", lsName, lrName) @@ -22,27 +22,27 @@ func (suite *OvnClientTestSuite) testCreateGatewayLogicalSwitch() { localnetLspName := GetLocalnetName(lsName) chassises := []string{"5de32fcb-495a-40df-919e-f09812c4d11e", "25310674-65ce-69fd-bcfa-65b25268926b"} - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateGatewayLogicalSwitch(lsName, lrName, "test-external", "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac(), 210, chassises...) + err = nbClient.CreateGatewayLogicalSwitch(lsName, lrName, "test-external", "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac(), 210, chassises...) require.NoError(t, err) - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) - lr, err := ovnClient.GetLogicalRouter(lrName, false) + lr, err := nbClient.GetLogicalRouter(lrName, false) require.NoError(t, err) - localnetLsp, err := ovnClient.GetLogicalSwitchPort(localnetLspName, false) + localnetLsp, err := nbClient.GetLogicalSwitchPort(localnetLspName, false) require.NoError(t, err) require.Equal(t, "localnet", localnetLsp.Type) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Contains(t, lr.Ports, lrp.UUID) - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) require.Contains(t, ls.Ports, lsp.UUID) } @@ -51,31 +51,31 @@ func (suite *OvnClientTestSuite) testCreateLogicalPatchPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-create-router-ls" lrName := "test-create-router-lr" lspName := fmt.Sprintf("%s-%s", lsName, lrName) lrpName := fmt.Sprintf("%s-%s", lrName, lsName) chassises := []string{"5de32fcb-495a-40df-919e-f09812c4dffe", "25310674-65ce-41fd-bcfa-65b25268926b"} - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitch(lsName) + err = nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("create router port with chassises", func(t *testing.T) { t.Parallel() - err := ovnClient.CreateLogicalPatchPort(lsName, lrName, lspName, lrpName, "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac(), chassises...) + err := nbClient.CreateLogicalPatchPort(lsName, lrName, lspName, lrpName, "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac(), chassises...) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.ElementsMatch(t, []string{"192.168.230.1/24", "fc00::0af4:01/112"}, lrp.Networks) for _, chassisName := range chassises { gwChassisName := lrpName + "-" + chassisName - gwChassis, err := ovnClient.GetGatewayChassis(gwChassisName, false) + gwChassis, err := nbClient.GetGatewayChassis(gwChassisName, false) require.NoError(t, err) require.Contains(t, lrp.GatewayChassis, gwChassis.UUID) } @@ -88,16 +88,16 @@ func (suite *OvnClientTestSuite) testCreateLogicalPatchPort() { lspName := fmt.Sprintf("%s-%s", lsName, lrName) lrpName := fmt.Sprintf("%s-%s", lrName, lsName) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitch(lsName) + err = nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) - err = ovnClient.CreateLogicalPatchPort(lsName, lrName, lspName, lrpName, "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac()) + err = nbClient.CreateLogicalPatchPort(lsName, lrName, lspName, lrpName, "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac()) require.NoError(t, err) - lrp, err := ovnClient.GetLogicalRouterPort(lrpName, false) + lrp, err := nbClient.GetLogicalRouterPort(lrpName, false) require.NoError(t, err) require.Empty(t, lrp.GatewayChassis) }) @@ -107,28 +107,28 @@ func (suite *OvnClientTestSuite) testRemoveRouterPort() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-remove-router-type-ls" lrName := "test-remove-router-type-lr" lspName := fmt.Sprintf("%s-%s", lsName, lrName) lrpName := fmt.Sprintf("%s-%s", lrName, lsName) - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateBareLogicalSwitch(lsName) + err = nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) t.Run("normal del router type port", func(t *testing.T) { - err = ovnClient.CreateLogicalPatchPort(lsName, lrName, lspName, lrpName, "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac()) + err = nbClient.CreateLogicalPatchPort(lsName, lrName, lspName, lrpName, "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac()) require.NoError(t, err) - err = ovnClient.RemoveLogicalPatchPort(lspName, lrpName) + err = nbClient.RemoveLogicalPatchPort(lspName, lrpName) require.NoError(t, err) }) t.Run("should no err normal del router type port repeatedly", func(t *testing.T) { - err = ovnClient.RemoveLogicalPatchPort(lspName, lrpName) + err = nbClient.RemoveLogicalPatchPort(lspName, lrpName) require.NoError(t, err) }) } @@ -137,23 +137,23 @@ func (suite *OvnClientTestSuite) testDeleteLogicalGatewaySwitch() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-del-gw-ls" lrName := "test-del-gw-lr" - err := ovnClient.CreateLogicalRouter(lrName) + err := nbClient.CreateLogicalRouter(lrName) require.NoError(t, err) - err = ovnClient.CreateGatewayLogicalSwitch(lsName, lrName, "test-external", "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac(), 210) + err = nbClient.CreateGatewayLogicalSwitch(lsName, lrName, "test-external", "192.168.230.1/24,fc00::0af4:01/112", util.GenerateMac(), 210) require.NoError(t, err) // localnet port and lsp will be deleted when delete logical switch in real ovsdb, // it's different from the mock memory ovsdb, // so no need to check localnet port and lsp existence - err = ovnClient.DeleteLogicalGatewaySwitch(lsName, lrName) + err = nbClient.DeleteLogicalGatewaySwitch(lsName, lrName) require.NoError(t, err) - _, err = ovnClient.GetLogicalSwitch(lsName, false) + _, err = nbClient.GetLogicalSwitch(lsName, false) require.ErrorContains(t, err, "not found logical switch") } @@ -161,7 +161,7 @@ func (suite *OvnClientTestSuite) testDeleteSecurityGroup() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient sgName := "test_del_sg" asName := "test_del_sg_as" pgName := GetSgPortGroupName(sgName) @@ -169,31 +169,31 @@ func (suite *OvnClientTestSuite) testDeleteSecurityGroup() { match := "outport == @ovn.sg.test_del_sg && ip" /* prepate test */ - err := ovnClient.CreatePortGroup(pgName, map[string]string{ + err := nbClient.CreatePortGroup(pgName, map[string]string{ "type": "security_group", sgKey: sgName, }) require.NoError(t, err) - acl, err := ovnClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) + acl, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, priority, match, ovnnb.ACLActionAllowRelated, util.NetpolACLTier) require.NoError(t, err) - err = ovnClient.CreateAcls(pgName, portGroupKey, acl) + err = nbClient.CreateAcls(pgName, portGroupKey, acl) require.NoError(t, err) - err = ovnClient.CreateAddressSet(asName, map[string]string{ + err = nbClient.CreateAddressSet(asName, map[string]string{ sgKey: sgName, }) require.NoError(t, err) /* run test */ - err = ovnClient.DeleteSecurityGroup(sgName) + err = nbClient.DeleteSecurityGroup(sgName) require.NoError(t, err) - _, err = ovnClient.GetAddressSet(asName, false) + _, err = nbClient.GetAddressSet(asName, false) require.ErrorContains(t, err, "object not found") - _, err = ovnClient.GetPortGroup(pgName, false) + _, err = nbClient.GetPortGroup(pgName, false) require.ErrorContains(t, err, "object not found") } @@ -201,24 +201,24 @@ func (suite *OvnClientTestSuite) testGetEntityInfo() { t := suite.T() t.Parallel() - ovnClient := suite.ovnNBClient + nbClient := suite.ovnNBClient lsName := "test-get-entity-ls" - err := ovnClient.CreateBareLogicalSwitch(lsName) + err := nbClient.CreateBareLogicalSwitch(lsName) require.NoError(t, err) lspName := "test-get-entity-lsp" - err = ovnClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") + err = nbClient.CreateBareLogicalSwitchPort(lsName, lspName, "", "") require.NoError(t, err) t.Run("get logical switch by uuid", func(t *testing.T) { t.Parallel() - ls, err := ovnClient.GetLogicalSwitch(lsName, false) + ls, err := nbClient.GetLogicalSwitch(lsName, false) require.NoError(t, err) newLs := &ovnnb.LogicalSwitch{UUID: ls.UUID} - err = ovnClient.GetEntityInfo(newLs) + err = nbClient.GetEntityInfo(newLs) require.NoError(t, err) require.Equal(t, lsName, newLs.Name) }) @@ -227,18 +227,18 @@ func (suite *OvnClientTestSuite) testGetEntityInfo() { t.Parallel() ls := &ovnnb.LogicalSwitch{Name: lsName} - err = ovnClient.GetEntityInfo(ls) + err = nbClient.GetEntityInfo(ls) require.ErrorContains(t, err, "object not found") }) t.Run("get logical switch port by uuid", func(t *testing.T) { t.Parallel() - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) newLsp := &ovnnb.LogicalSwitchPort{UUID: lsp.UUID} - err = ovnClient.GetEntityInfo(newLsp) + err = nbClient.GetEntityInfo(newLsp) require.NoError(t, err) require.Equal(t, lspName, newLsp.Name) }) @@ -246,11 +246,11 @@ func (suite *OvnClientTestSuite) testGetEntityInfo() { t.Run("get logical switch port by name which is index", func(t *testing.T) { t.Parallel() - lsp, err := ovnClient.GetLogicalSwitchPort(lspName, false) + lsp, err := nbClient.GetLogicalSwitchPort(lspName, false) require.NoError(t, err) newLsp := &ovnnb.LogicalSwitchPort{Name: lspName} - err = ovnClient.GetEntityInfo(newLsp) + err = nbClient.GetEntityInfo(newLsp) require.NoError(t, err) require.Equal(t, lsp.UUID, newLsp.UUID) }) @@ -259,7 +259,7 @@ func (suite *OvnClientTestSuite) testGetEntityInfo() { t.Parallel() newLsp := ovnnb.LogicalSwitchPort{Name: lspName} - err = ovnClient.GetEntityInfo(newLsp) + err = nbClient.GetEntityInfo(newLsp) require.ErrorContains(t, err, "entity must be pointer") }) } diff --git a/pkg/ovs/ovn-sb-chassis_test.go b/pkg/ovs/ovn-sb-chassis_test.go index 4f400955e48..8210e60ac64 100644 --- a/pkg/ovs/ovn-sb-chassis_test.go +++ b/pkg/ovs/ovn-sb-chassis_test.go @@ -28,39 +28,39 @@ func (suite *OvnClientTestSuite) testGetChassis() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("chassis-name-1") + err := sbClient.DeleteChassis("chassis-name-1") require.NoError(t, err) }) chassis := newChassis(0, "host-name-1", "chassis-name-1", nil, nil, nil, nil, nil) - ops, err := ovnClient.ovsDbClient.Create(chassis) + ops, err := sbClient.ovsDbClient.Create(chassis) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops) + err = sbClient.Transact("chassis-add", ops) require.NoError(t, err) t.Run("test get chassis", func(t *testing.T) { - chassis, err := ovnClient.GetChassis("chassis-name-1", false) + chassis, err := sbClient.GetChassis("chassis-name-1", false) require.NotNil(t, chassis) require.NoError(t, err) }) t.Run("test get chassis with empty chassis name", func(t *testing.T) { - chassis, err := ovnClient.GetChassis("", false) + chassis, err := sbClient.GetChassis("", false) require.Nil(t, chassis) require.ErrorContains(t, err, "chassis name is empty") }) t.Run("test get non-existent chassis with ignoreNotFound true", func(t *testing.T) { - chassis, err := ovnClient.GetChassis("chassis-non-existent", true) + chassis, err := sbClient.GetChassis("chassis-non-existent", true) require.Nil(t, chassis) require.NoError(t, err) }) t.Run("test get non-existent chassis with ignoreNotFound false", func(t *testing.T) { - chassis, err := ovnClient.GetChassis("chassis-non-existent", false) + chassis, err := sbClient.GetChassis("chassis-non-existent", false) require.Nil(t, chassis) require.ErrorContains(t, err, "failed to get chassis") }) @@ -70,39 +70,39 @@ func (suite *OvnClientTestSuite) testDeleteChassis() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("chassis-name-2") + err := sbClient.DeleteChassis("chassis-name-2") require.NoError(t, err) }) chassis := newChassis(0, "host-name-2", "chassis-name-2", nil, nil, nil, nil, nil) - ops, err := ovnClient.ovsDbClient.Create(chassis) + ops, err := sbClient.ovsDbClient.Create(chassis) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops) + err = sbClient.Transact("chassis-add", ops) require.NoError(t, err) t.Run("test delete chassis", func(t *testing.T) { - chassis, err := ovnClient.GetChassis("chassis-name-2", false) + chassis, err := sbClient.GetChassis("chassis-name-2", false) require.NotNil(t, chassis) require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-name-2") + err = sbClient.DeleteChassis("chassis-name-2") require.NoError(t, err) - chassis, err = ovnClient.GetChassis("chassis-name-2", true) + chassis, err = sbClient.GetChassis("chassis-name-2", true) require.Nil(t, chassis) require.NoError(t, err) }) t.Run("test delete chassis with empty chassis name", func(t *testing.T) { - err := ovnClient.DeleteChassis("") + err := sbClient.DeleteChassis("") require.ErrorContains(t, err, "chassis name is empty") }) t.Run("test delete non-existent chassis", func(t *testing.T) { - err := ovnClient.DeleteChassis("chassis-non-existent") + err := sbClient.DeleteChassis("chassis-non-existent") require.NoError(t, err) }) } @@ -111,32 +111,32 @@ func (suite *OvnClientTestSuite) testUpdateChassis() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("chassis-name-3") + err := sbClient.DeleteChassis("chassis-name-3") require.NoError(t, err) }) chassis := newChassis(0, "host-name-3", "chassis-name-3", nil, nil, nil, nil, nil) - ops, err := ovnClient.ovsDbClient.Create(chassis) + ops, err := sbClient.ovsDbClient.Create(chassis) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops) + err = sbClient.Transact("chassis-add", ops) require.NoError(t, err) t.Run("test update chassis with valid fields", func(t *testing.T) { updatedHostname := "updated-host-name" chassis.Hostname = updatedHostname - err := ovnClient.UpdateChassis(chassis, &chassis.Hostname) + err := sbClient.UpdateChassis(chassis, &chassis.Hostname) require.NoError(t, err) - updatedChassis, err := ovnClient.GetChassis("chassis-name-3", false) + updatedChassis, err := sbClient.GetChassis("chassis-name-3", false) require.NoError(t, err) require.Equal(t, updatedHostname, updatedChassis.Hostname) }) t.Run("test update chassis with non-existent field", func(t *testing.T) { - err := ovnClient.UpdateChassis(chassis, "NonExistentField") + err := sbClient.UpdateChassis(chassis, "NonExistentField") require.Error(t, err) require.Contains(t, err.Error(), "failed to generate update operations for chassis") }) @@ -146,30 +146,30 @@ func (suite *OvnClientTestSuite) testListChassis() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("chassis-1") + err := sbClient.DeleteChassis("chassis-1") require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-2") + err = sbClient.DeleteChassis("chassis-2") require.NoError(t, err) }) chassis1 := newChassis(0, "host-1", "chassis-1", nil, nil, nil, nil, nil) chassis2 := newChassis(0, "host-2", "chassis-2", nil, nil, nil, nil, nil) - ops1, err := ovnClient.ovsDbClient.Create(chassis1) + ops1, err := sbClient.ovsDbClient.Create(chassis1) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops1) + err = sbClient.Transact("chassis-add", ops1) require.NoError(t, err) - ops2, err := ovnClient.ovsDbClient.Create(chassis2) + ops2, err := sbClient.ovsDbClient.Create(chassis2) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops2) + err = sbClient.Transact("chassis-add", ops2) require.NoError(t, err) t.Run("test list chassis", func(t *testing.T) { - chassisList, err := ovnClient.ListChassis() + chassisList, err := sbClient.ListChassis() require.NoError(t, err) require.NotNil(t, chassisList) @@ -182,12 +182,12 @@ func (suite *OvnClientTestSuite) testListChassis() { }) t.Run("test list chassis with no entries", func(t *testing.T) { - err := ovnClient.DeleteChassis("chassis-1") + err := sbClient.DeleteChassis("chassis-1") require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-2") + err = sbClient.DeleteChassis("chassis-2") require.NoError(t, err) - chassisList, err := ovnClient.ListChassis() + chassisList, err := sbClient.ListChassis() require.NoError(t, err) require.NotNil(t, chassisList) require.Empty(t, *chassisList) @@ -198,14 +198,14 @@ func (suite *OvnClientTestSuite) testGetAllChassisByHost() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("chassis-3") + err := sbClient.DeleteChassis("chassis-3") require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-4") + err = sbClient.DeleteChassis("chassis-4") require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-5") + err = sbClient.DeleteChassis("chassis-5") require.NoError(t, err) }) @@ -213,23 +213,23 @@ func (suite *OvnClientTestSuite) testGetAllChassisByHost() { chassis2 := newChassis(0, "host-4", "chassis-4", nil, nil, nil, nil, nil) chassis3 := newChassis(0, "host-4", "chassis-5", nil, nil, nil, nil, nil) - ops1, err := ovnClient.ovsDbClient.Create(chassis1) + ops1, err := sbClient.ovsDbClient.Create(chassis1) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops1) + err = sbClient.Transact("chassis-add", ops1) require.NoError(t, err) - ops2, err := ovnClient.ovsDbClient.Create(chassis2) + ops2, err := sbClient.ovsDbClient.Create(chassis2) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops2) + err = sbClient.Transact("chassis-add", ops2) require.NoError(t, err) - ops3, err := ovnClient.ovsDbClient.Create(chassis3) + ops3, err := sbClient.ovsDbClient.Create(chassis3) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops3) + err = sbClient.Transact("chassis-add", ops3) require.NoError(t, err) t.Run("test get all chassis by host with single chassis", func(t *testing.T) { - chassisList, err := ovnClient.GetAllChassisByHost("host-3") + chassisList, err := sbClient.GetAllChassisByHost("host-3") require.NoError(t, err) require.NotNil(t, chassisList) require.Len(t, *chassisList, 1) @@ -237,21 +237,21 @@ func (suite *OvnClientTestSuite) testGetAllChassisByHost() { }) t.Run("test get all chassis by host with multiple chassis", func(t *testing.T) { - chassisList, err := ovnClient.GetAllChassisByHost("host-4") + chassisList, err := sbClient.GetAllChassisByHost("host-4") require.Error(t, err) require.Nil(t, chassisList) require.Contains(t, err.Error(), "found more than one Chassis") }) t.Run("test get all chassis by non-existent host", func(t *testing.T) { - chassisList, err := ovnClient.GetAllChassisByHost("non-existent-host") + chassisList, err := sbClient.GetAllChassisByHost("non-existent-host") require.Error(t, err) require.Nil(t, chassisList) require.Contains(t, err.Error(), "failed to get Chassis") }) t.Run("test get all chassis by host with empty hostname", func(t *testing.T) { - chassisList, err := ovnClient.GetAllChassisByHost("") + chassisList, err := sbClient.GetAllChassisByHost("") require.Error(t, err) require.Nil(t, chassisList) require.Contains(t, err.Error(), "failed to get Chassis") @@ -262,30 +262,30 @@ func (suite *OvnClientTestSuite) testGetChassisByHost() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("chassis-6") + err := sbClient.DeleteChassis("chassis-6") require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-7") + err = sbClient.DeleteChassis("chassis-7") require.NoError(t, err) }) chassis1 := newChassis(0, "host-6", "chassis-6", nil, nil, nil, nil, nil) chassis2 := newChassis(0, "host-7", "chassis-7", nil, nil, nil, nil, nil) - ops1, err := ovnClient.ovsDbClient.Create(chassis1) + ops1, err := sbClient.ovsDbClient.Create(chassis1) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops1) + err = sbClient.Transact("chassis-add", ops1) require.NoError(t, err) - ops2, err := ovnClient.ovsDbClient.Create(chassis2) + ops2, err := sbClient.ovsDbClient.Create(chassis2) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops2) + err = sbClient.Transact("chassis-add", ops2) require.NoError(t, err) t.Run("test get chassis by host with valid hostname", func(t *testing.T) { - chassis, err := ovnClient.GetChassisByHost("host-6") + chassis, err := sbClient.GetChassisByHost("host-6") require.NoError(t, err) require.NotNil(t, chassis) require.Equal(t, "chassis-6", chassis.Name) @@ -293,14 +293,14 @@ func (suite *OvnClientTestSuite) testGetChassisByHost() { }) t.Run("test get chassis by host with non-existent hostname", func(t *testing.T) { - chassis, err := ovnClient.GetChassisByHost("non-existent-host") + chassis, err := sbClient.GetChassisByHost("non-existent-host") require.Error(t, err) require.Nil(t, chassis) require.Contains(t, err.Error(), "failed to get Chassis") }) t.Run("test get chassis by host with empty hostname", func(t *testing.T) { - chassis, err := ovnClient.GetChassisByHost("") + chassis, err := sbClient.GetChassisByHost("") require.Error(t, err) require.Nil(t, chassis) require.Contains(t, err.Error(), "failed to get Chassis") @@ -308,17 +308,17 @@ func (suite *OvnClientTestSuite) testGetChassisByHost() { t.Run("test get chassis by host with multiple chassis", func(t *testing.T) { chassis3 := newChassis(0, "host-6", "chassis-8", nil, nil, nil, nil, nil) - ops3, err := ovnClient.ovsDbClient.Create(chassis3) + ops3, err := sbClient.ovsDbClient.Create(chassis3) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops3) + err = sbClient.Transact("chassis-add", ops3) require.NoError(t, err) - chassis, err := ovnClient.GetChassisByHost("host-6") + chassis, err := sbClient.GetChassisByHost("host-6") require.Error(t, err) require.Nil(t, chassis) require.Contains(t, err.Error(), "found more than one Chassis") - err = ovnClient.DeleteChassis("chassis-8") + err = sbClient.DeleteChassis("chassis-8") require.NoError(t, err) }) } @@ -327,16 +327,16 @@ func (suite *OvnClientTestSuite) testDeleteChassisByHost() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("chassis-node1-1") + err := sbClient.DeleteChassis("chassis-node1-1") require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-node1-2") + err = sbClient.DeleteChassis("chassis-node1-2") require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-node2") + err = sbClient.DeleteChassis("chassis-node2") require.NoError(t, err) - err = ovnClient.DeleteChassis("chassis-node3") + err = sbClient.DeleteChassis("chassis-node3") require.NoError(t, err) }) @@ -345,56 +345,56 @@ func (suite *OvnClientTestSuite) testDeleteChassisByHost() { chassis3 := newChassis(0, "", "chassis-node2", nil, nil, nil, map[string]string{"node": "node2"}, nil) chassis4 := newChassis(0, "node3", "", nil, nil, nil, map[string]string{"node": "node3"}, nil) - ops1, err := ovnClient.ovsDbClient.Create(chassis1) + ops1, err := sbClient.ovsDbClient.Create(chassis1) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops1) + err = sbClient.Transact("chassis-add", ops1) require.NoError(t, err) - ops2, err := ovnClient.ovsDbClient.Create(chassis2) + ops2, err := sbClient.ovsDbClient.Create(chassis2) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops2) + err = sbClient.Transact("chassis-add", ops2) require.NoError(t, err) - ops3, err := ovnClient.ovsDbClient.Create(chassis3) + ops3, err := sbClient.ovsDbClient.Create(chassis3) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops3) + err = sbClient.Transact("chassis-add", ops3) require.NoError(t, err) - ops4, err := ovnClient.ovsDbClient.Create(chassis4) + ops4, err := sbClient.ovsDbClient.Create(chassis4) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops4) + err = sbClient.Transact("chassis-add", ops4) require.NoError(t, err) t.Run("test delete chassis by host with multiple chassis", func(t *testing.T) { - err := ovnClient.DeleteChassisByHost("node1") + err := sbClient.DeleteChassisByHost("node1") require.NoError(t, err) - chassisList, err := ovnClient.GetAllChassisByHost("node1") + chassisList, err := sbClient.GetAllChassisByHost("node1") require.ErrorContains(t, err, "failed to get Chassis with with host name") require.Nil(t, chassisList) }) t.Run("test delete chassis by host with ExternalIDs", func(t *testing.T) { - err := ovnClient.DeleteChassisByHost("node2") + err := sbClient.DeleteChassisByHost("node2") require.NoError(t, err) - chassisList, err := ovnClient.GetAllChassisByHost("node2") + chassisList, err := sbClient.GetAllChassisByHost("node2") require.ErrorContains(t, err, "failed to get Chassis with with host name") require.Nil(t, chassisList) }) t.Run("test delete chassis by non-existent host", func(t *testing.T) { - err := ovnClient.DeleteChassisByHost("non-existent-node") + err := sbClient.DeleteChassisByHost("non-existent-node") require.NoError(t, err) }) t.Run("test delete chassis by empty host name", func(t *testing.T) { - err := ovnClient.DeleteChassisByHost("") + err := sbClient.DeleteChassisByHost("") require.NoError(t, err) }) t.Run("test delete chassis by empty chassis name with ExternalIDs", func(t *testing.T) { - err := ovnClient.DeleteChassisByHost("node3") + err := sbClient.DeleteChassisByHost("node3") require.ErrorContains(t, err, "chassis name is empty") }) } @@ -403,24 +403,24 @@ func (suite *OvnClientTestSuite) testUpdateChassisTag() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("chassis-update-tag") + err := sbClient.DeleteChassis("chassis-update-tag") require.NoError(t, err) }) chassis := newChassis(0, "host-update-tag", "chassis-update-tag", nil, nil, nil, nil, nil) - ops, err := ovnClient.ovsDbClient.Create(chassis) + ops, err := sbClient.ovsDbClient.Create(chassis) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops) + err = sbClient.Transact("chassis-add", ops) require.NoError(t, err) t.Run("test update chassis tag with new node name", func(t *testing.T) { - err := ovnClient.UpdateChassisTag("chassis-update-tag", "new-node-name") + err := sbClient.UpdateChassisTag("chassis-update-tag", "new-node-name") require.NoError(t, err) - updatedChassis, err := ovnClient.GetChassis("chassis-update-tag", false) + updatedChassis, err := sbClient.GetChassis("chassis-update-tag", false) require.NoError(t, err) require.NotNil(t, updatedChassis) require.Equal(t, util.CniTypeName, updatedChassis.ExternalIDs["vendor"]) @@ -428,13 +428,13 @@ func (suite *OvnClientTestSuite) testUpdateChassisTag() { t.Run("test update chassis tag with existing ExternalIDs", func(t *testing.T) { chassis.ExternalIDs = map[string]string{"existing": "value"} - err := ovnClient.UpdateChassis(chassis, &chassis.ExternalIDs) + err := sbClient.UpdateChassis(chassis, &chassis.ExternalIDs) require.NoError(t, err) - err = ovnClient.UpdateChassisTag("chassis-update-tag", "another-node-name") + err = sbClient.UpdateChassisTag("chassis-update-tag", "another-node-name") require.NoError(t, err) - updatedChassis, err := ovnClient.GetChassis("chassis-update-tag", false) + updatedChassis, err := sbClient.GetChassis("chassis-update-tag", false) require.NoError(t, err) require.NotNil(t, updatedChassis) require.Equal(t, util.CniTypeName, updatedChassis.ExternalIDs["vendor"]) @@ -442,22 +442,22 @@ func (suite *OvnClientTestSuite) testUpdateChassisTag() { }) t.Run("test update chassis tag with non-existent chassis", func(t *testing.T) { - err := ovnClient.UpdateChassisTag("non-existent-chassis", "node-name") + err := sbClient.UpdateChassisTag("non-existent-chassis", "node-name") require.Error(t, err) require.Contains(t, err.Error(), "fail to get chassis by name=non-existent-chassis") }) t.Run("test update chassis tag with empty chassis name", func(t *testing.T) { - err := ovnClient.UpdateChassisTag("", "node-name") + err := sbClient.UpdateChassisTag("", "node-name") require.Error(t, err) require.Contains(t, err.Error(), "chassis name is empty") }) t.Run("test update chassis tag with empty node name", func(t *testing.T) { - err := ovnClient.UpdateChassisTag("chassis-update-tag", "") + err := sbClient.UpdateChassisTag("chassis-update-tag", "") require.NoError(t, err) - updatedChassis, err := ovnClient.GetChassis("chassis-update-tag", false) + updatedChassis, err := sbClient.GetChassis("chassis-update-tag", false) require.NoError(t, err) require.NotNil(t, updatedChassis) require.Equal(t, "", updatedChassis.ExternalIDs["node"]) @@ -469,14 +469,14 @@ func (suite *OvnClientTestSuite) testGetKubeOvnChassisses() { t := suite.T() t.Parallel() - ovnClient := suite.ovnSBClient + sbClient := suite.ovnSBClient t.Cleanup(func() { - err := ovnClient.DeleteChassis("kube-ovn-chassis-1") + err := sbClient.DeleteChassis("kube-ovn-chassis-1") require.NoError(t, err) - err = ovnClient.DeleteChassis("kube-ovn-chassis-2") + err = sbClient.DeleteChassis("kube-ovn-chassis-2") require.NoError(t, err) - err = ovnClient.DeleteChassis("non-kube-ovn-chassis") + err = sbClient.DeleteChassis("non-kube-ovn-chassis") require.NoError(t, err) }) @@ -484,23 +484,23 @@ func (suite *OvnClientTestSuite) testGetKubeOvnChassisses() { kubeOvnChassis2 := newChassis(0, "host-2", "kube-ovn-chassis-2", nil, nil, nil, map[string]string{"vendor": util.CniTypeName}, nil) nonKubeOvnChassis := newChassis(0, "host-3", "non-kube-ovn-chassis", nil, nil, nil, map[string]string{"vendor": "other"}, nil) - ops1, err := ovnClient.ovsDbClient.Create(kubeOvnChassis1) + ops1, err := sbClient.ovsDbClient.Create(kubeOvnChassis1) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops1) + err = sbClient.Transact("chassis-add", ops1) require.NoError(t, err) - ops2, err := ovnClient.ovsDbClient.Create(kubeOvnChassis2) + ops2, err := sbClient.ovsDbClient.Create(kubeOvnChassis2) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops2) + err = sbClient.Transact("chassis-add", ops2) require.NoError(t, err) - ops3, err := ovnClient.ovsDbClient.Create(nonKubeOvnChassis) + ops3, err := sbClient.ovsDbClient.Create(nonKubeOvnChassis) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops3) + err = sbClient.Transact("chassis-add", ops3) require.NoError(t, err) t.Run("test get kube-ovn chassisses", func(t *testing.T) { - chassisList, err := ovnClient.GetKubeOvnChassisses() + chassisList, err := sbClient.GetKubeOvnChassisses() require.NoError(t, err) require.NotNil(t, chassisList) require.Len(t, *chassisList, 2) @@ -516,12 +516,12 @@ func (suite *OvnClientTestSuite) testGetKubeOvnChassisses() { }) t.Run("test get kube-ovn chassisses with no matching entries", func(t *testing.T) { - err := ovnClient.DeleteChassis("kube-ovn-chassis-1") + err := sbClient.DeleteChassis("kube-ovn-chassis-1") require.NoError(t, err) - err = ovnClient.DeleteChassis("kube-ovn-chassis-2") + err = sbClient.DeleteChassis("kube-ovn-chassis-2") require.NoError(t, err) - chassisList, err := ovnClient.GetKubeOvnChassisses() + chassisList, err := sbClient.GetKubeOvnChassisses() require.NoError(t, err) require.NotNil(t, chassisList) require.Empty(t, *chassisList) @@ -529,12 +529,12 @@ func (suite *OvnClientTestSuite) testGetKubeOvnChassisses() { t.Run("test get kube-ovn chassisses with mixed entries", func(t *testing.T) { mixedChassis := newChassis(0, "host-4", "mixed-chassis", nil, nil, nil, map[string]string{"vendor": util.CniTypeName, "other": "value"}, nil) - ops, err := ovnClient.ovsDbClient.Create(mixedChassis) + ops, err := sbClient.ovsDbClient.Create(mixedChassis) require.NoError(t, err) - err = ovnClient.Transact("chassis-add", ops) + err = sbClient.Transact("chassis-add", ops) require.NoError(t, err) - chassisList, err := ovnClient.GetKubeOvnChassisses() + chassisList, err := sbClient.GetKubeOvnChassisses() require.NoError(t, err) require.NotNil(t, chassisList) require.Len(t, *chassisList, 1) @@ -542,7 +542,7 @@ func (suite *OvnClientTestSuite) testGetKubeOvnChassisses() { require.Equal(t, util.CniTypeName, (*chassisList)[0].ExternalIDs["vendor"]) require.Equal(t, "value", (*chassisList)[0].ExternalIDs["other"]) - err = ovnClient.DeleteChassis("mixed-chassis") + err = sbClient.DeleteChassis("mixed-chassis") require.NoError(t, err) }) } From fae5b5fc844cee192312acae7dfe35e739bac80f Mon Sep 17 00:00:00 2001 From: zcq98 Date: Tue, 24 Sep 2024 13:33:38 +0800 Subject: [PATCH 07/10] first check for err then check the resource Signed-off-by: zcq98 --- pkg/ovs/ovn-sb-chassis_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/ovs/ovn-sb-chassis_test.go b/pkg/ovs/ovn-sb-chassis_test.go index 8210e60ac64..7895e3ebf65 100644 --- a/pkg/ovs/ovn-sb-chassis_test.go +++ b/pkg/ovs/ovn-sb-chassis_test.go @@ -43,8 +43,8 @@ func (suite *OvnClientTestSuite) testGetChassis() { t.Run("test get chassis", func(t *testing.T) { chassis, err := sbClient.GetChassis("chassis-name-1", false) - require.NotNil(t, chassis) require.NoError(t, err) + require.NotNil(t, chassis) }) t.Run("test get chassis with empty chassis name", func(t *testing.T) { @@ -55,8 +55,8 @@ func (suite *OvnClientTestSuite) testGetChassis() { t.Run("test get non-existent chassis with ignoreNotFound true", func(t *testing.T) { chassis, err := sbClient.GetChassis("chassis-non-existent", true) - require.Nil(t, chassis) require.NoError(t, err) + require.Nil(t, chassis) }) t.Run("test get non-existent chassis with ignoreNotFound false", func(t *testing.T) { @@ -92,8 +92,8 @@ func (suite *OvnClientTestSuite) testDeleteChassis() { require.NoError(t, err) chassis, err = sbClient.GetChassis("chassis-name-2", true) - require.Nil(t, chassis) require.NoError(t, err) + require.Nil(t, chassis) }) t.Run("test delete chassis with empty chassis name", func(t *testing.T) { From 616cb7f244126a589398eff272b1fd9648b69b66 Mon Sep 17 00:00:00 2001 From: zcq98 Date: Tue, 24 Sep 2024 14:04:01 +0800 Subject: [PATCH 08/10] add log near error Signed-off-by: zcq98 --- pkg/ovs/ovn-nb-suite_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/ovs/ovn-nb-suite_test.go b/pkg/ovs/ovn-nb-suite_test.go index bb22bf7d114..21140f0d98f 100644 --- a/pkg/ovs/ovn-nb-suite_test.go +++ b/pkg/ovs/ovn-nb-suite_test.go @@ -20,6 +20,7 @@ import ( "github.com/ovn-org/libovsdb/server" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "k8s.io/klog/v2" "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnsb" @@ -911,6 +912,7 @@ func newOvnNbClient(t *testing.T, ovnNbAddr string, ovnNbTimeout int) (*OVNNbCli func newNbClient(addr string, timeout int) (client.Client, error) { dbModel, err := ovnnb.FullDatabaseModel() if err != nil { + klog.Error(err) return nil, err } @@ -931,10 +933,12 @@ func newNbClient(addr string, timeout int) (client.Client, error) { c, err := client.NewOVSDBClient(dbModel, options...) if err != nil { + klog.Error(err) return nil, err } if err = c.Connect(context.TODO()); err != nil { + klog.Error(err) return nil, err } @@ -957,6 +961,7 @@ func newNbClient(addr string, timeout int) (client.Client, error) { client.WithTable(&ovnnb.PortGroup{}), } if _, err = c.Monitor(context.TODO(), c.NewMonitor(monitorOpts...)); err != nil { + klog.Error(err) return nil, err } @@ -978,6 +983,7 @@ func newOvnSbClient(t *testing.T, ovnSbAddr string, ovnSbTimeout int) (*OVNSbCli func newSbClient(addr string, timeout int) (client.Client, error) { dbModel, err := ovnsb.FullDatabaseModel() if err != nil { + klog.Error(err) return nil, err } @@ -998,10 +1004,12 @@ func newSbClient(addr string, timeout int) (client.Client, error) { c, err := client.NewOVSDBClient(dbModel, options...) if err != nil { + klog.Error(err) return nil, err } if err = c.Connect(context.TODO()); err != nil { + klog.Error(err) return nil, err } @@ -1009,6 +1017,7 @@ func newSbClient(addr string, timeout int) (client.Client, error) { client.WithTable(&ovnsb.Chassis{}), } if _, err = c.Monitor(context.TODO(), c.NewMonitor(monitorOpts...)); err != nil { + klog.Error(err) return nil, err } From 43ec7e3705c3c483595d6071b09617e8492f6ff1 Mon Sep 17 00:00:00 2001 From: zcq98 Date: Tue, 24 Sep 2024 14:34:48 +0800 Subject: [PATCH 09/10] fix empty name chassis not deleted Signed-off-by: zcq98 --- pkg/ovs/ovn-sb-chassis_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/ovs/ovn-sb-chassis_test.go b/pkg/ovs/ovn-sb-chassis_test.go index 7895e3ebf65..5ae96b0c3e2 100644 --- a/pkg/ovs/ovn-sb-chassis_test.go +++ b/pkg/ovs/ovn-sb-chassis_test.go @@ -336,7 +336,11 @@ func (suite *OvnClientTestSuite) testDeleteChassisByHost() { require.NoError(t, err) err = sbClient.DeleteChassis("chassis-node2") require.NoError(t, err) - err = sbClient.DeleteChassis("chassis-node3") + chassis, err := sbClient.GetChassisByHost("node3") + require.NoError(t, err) + ops, err := sbClient.Where(chassis).Delete() + require.NoError(t, err) + err = sbClient.Transact("chassis-del", ops) require.NoError(t, err) }) From bc9aef443e415e6e7932b543d0c03f49b65cdc1d Mon Sep 17 00:00:00 2001 From: zcq98 Date: Wed, 25 Sep 2024 12:55:27 +0800 Subject: [PATCH 10/10] modify the variable names of nbClient and sbClient Signed-off-by: zcq98 --- .../ovn-nb-load_balancer_health_check_test.go | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/pkg/ovs/ovn-nb-load_balancer_health_check_test.go b/pkg/ovs/ovn-nb-load_balancer_health_check_test.go index dad1a9b82e4..9d91e7f33ed 100644 --- a/pkg/ovs/ovn-nb-load_balancer_health_check_test.go +++ b/pkg/ovs/ovn-nb-load_balancer_health_check_test.go @@ -17,29 +17,29 @@ func (suite *OvnClientTestSuite) testAddLoadBalancerHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbName = "test-create-lb-hc" vip = "1.1.1.1:80" lbhc, lbhcRepeat *ovnnb.LoadBalancerHealthCheck err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) - _, lbhc, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhc, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) require.Equal(t, vip, lbhc.Vip) require.NotEmpty(t, lbhc.UUID) // should no err create lbhc repeatedly - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) - _, lbhcRepeat, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhcRepeat, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) require.Equal(t, vip, lbhcRepeat.Vip) require.NotEmpty(t, lbhcRepeat.UUID) @@ -52,20 +52,20 @@ func (suite *OvnClientTestSuite) testUpdateLoadBalancerHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnNBClient - lbName = "test-update-lb-hc" - vip = "2.2.2.2:80" - lbhc *ovnnb.LoadBalancerHealthCheck - err error + nbClient = suite.ovnNBClient + lbName = "test-update-lb-hc" + vip = "2.2.2.2:80" + lbhc *ovnnb.LoadBalancerHealthCheck + err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) - _, lbhc, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhc, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) vip = "3.3.3.3:80" @@ -73,10 +73,10 @@ func (suite *OvnClientTestSuite) testUpdateLoadBalancerHealthCheck() { func(t *testing.T) { lbhc.Vip = vip - err = ovnClient.UpdateLoadBalancerHealthCheck(lbhc, &lbhc.Vip) + err = nbClient.UpdateLoadBalancerHealthCheck(lbhc, &lbhc.Vip) require.NoError(t, err) - _, lbhc, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhc, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) require.Equal(t, vip, lbhc.Vip) @@ -89,22 +89,22 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnNBClient - lbName = "test-del-lb-hc" - vip = "1.1.1.11:80" - err error + nbClient = suite.ovnNBClient + lbName = "test-del-lb-hc" + vip = "1.1.1.11:80" + err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) - err = ovnClient.DeleteLoadBalancerHealthCheck(lbName, vip) + err = nbClient.DeleteLoadBalancerHealthCheck(lbName, vip) require.NoError(t, err) - _, _, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, _, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.Error(t, err) } @@ -113,7 +113,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthChecks() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbNamePrefix = "test-del-lb-hcs" vipFormat = "5.5.5.%d:80" lbhc *ovnnb.LoadBalancerHealthCheck @@ -126,24 +126,24 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthChecks() { lbName = fmt.Sprintf("%s-%d", lbNamePrefix, i) vip = fmt.Sprintf(vipFormat, i+1) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) vips = append(vips, vip) - _, lbhc, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhc, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) require.NotNil(t, lbhc) require.Equal(t, vip, lbhc.Vip) - err = ovnClient.LoadBalancerDeleteHealthCheck(lbName, lbhc.UUID) + err = nbClient.LoadBalancerDeleteHealthCheck(lbName, lbhc.UUID) require.NoError(t, err) } - err = ovnClient.DeleteLoadBalancerHealthChecks( + err = nbClient.DeleteLoadBalancerHealthChecks( func(lbhc *ovnnb.LoadBalancerHealthCheck) bool { return slices.Contains(vips, lbhc.Vip) }, @@ -151,10 +151,10 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthChecks() { require.NoError(t, err) for _, ip := range vips { - _, _, err = ovnClient.GetLoadBalancerHealthCheck(lbName, ip, true) + _, _, err = nbClient.GetLoadBalancerHealthCheck(lbName, ip, true) require.NoError(t, err) - _, _, err = ovnClient.GetLoadBalancerHealthCheck(lbName, ip, false) + _, _, err = nbClient.GetLoadBalancerHealthCheck(lbName, ip, false) require.Error(t, err) } } @@ -164,23 +164,23 @@ func (suite *OvnClientTestSuite) testGetLoadBalancerHealthCheck() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbName = "test-get-lb-hc" vip = "1.1.1.22:80" vipNonExistent = "1.1.1.33:80" err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) t.Run("should return no err when found load balancer health check", func(t *testing.T) { t.Parallel() - _, lbhc, err := ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhc, err := nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) require.Equal(t, vip, lbhc.Vip) require.NotEmpty(t, lbhc.UUID) @@ -190,7 +190,7 @@ func (suite *OvnClientTestSuite) testGetLoadBalancerHealthCheck() { t.Run("should return err when not found load balancer health check", func(t *testing.T) { t.Parallel() - _, _, err := ovnClient.GetLoadBalancerHealthCheck(lbName, vipNonExistent, false) + _, _, err := nbClient.GetLoadBalancerHealthCheck(lbName, vipNonExistent, false) require.Error(t, err) }, ) @@ -198,7 +198,7 @@ func (suite *OvnClientTestSuite) testGetLoadBalancerHealthCheck() { t.Run("no err when not found load balancer health check and ignoreNotFound is true", func(t *testing.T) { t.Parallel() - _, _, err := ovnClient.GetLoadBalancerHealthCheck(lbName, vipNonExistent, true) + _, _, err := nbClient.GetLoadBalancerHealthCheck(lbName, vipNonExistent, true) require.NoError(t, err) }, ) @@ -209,7 +209,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancerHealthChecks() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbNamePrefix = "test-list-lb-hcs" vipFormat = "6.6.6.%d:80" vips []string @@ -222,10 +222,10 @@ func (suite *OvnClientTestSuite) testListLoadBalancerHealthChecks() { lbName = fmt.Sprintf("%s-%d", lbNamePrefix, i) vip = fmt.Sprintf(vipFormat, i+1) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, map[string]string{}) require.NoError(t, err) vips = append(vips, vip) @@ -235,7 +235,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancerHealthChecks() { func(t *testing.T) { t.Parallel() - lbhcs, err := ovnClient.ListLoadBalancerHealthChecks(nil) + lbhcs, err := nbClient.ListLoadBalancerHealthChecks(nil) require.NoError(t, err) require.NotEmpty(t, lbhcs) @@ -256,7 +256,7 @@ func (suite *OvnClientTestSuite) testListLoadBalancerHealthChecks() { func(t *testing.T) { t.Parallel() - lbhcs, err := ovnClient.ListLoadBalancerHealthChecks( + lbhcs, err := nbClient.ListLoadBalancerHealthChecks( func(lbhc *ovnnb.LoadBalancerHealthCheck) bool { return strings.Contains(lbhc.Vip, "6.6.6.") }, @@ -283,7 +283,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthCheckOp() { t.Parallel() var ( - ovnClient = suite.ovnNBClient + nbClient = suite.ovnNBClient lbName = "test-del-lb-hc-op" vip = "1.1.1.44:80" vipNonExistent = "1.1.1.55:80" @@ -291,24 +291,24 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthCheckOp() { err error ) - err = ovnClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") + err = nbClient.CreateLoadBalancer(lbName, "tcp", "ip_dst") require.NoError(t, err) - lb, err := ovnClient.GetLoadBalancer(lbName, false) + lb, err := nbClient.GetLoadBalancer(lbName, false) require.NoError(t, err) require.NotNil(t, lb) - err = ovnClient.AddLoadBalancerHealthCheck(lbName, vip, nil) + err = nbClient.AddLoadBalancerHealthCheck(lbName, vip, nil) require.NoError(t, err) - _, lbhc, err = ovnClient.GetLoadBalancerHealthCheck(lbName, vip, false) + _, lbhc, err = nbClient.GetLoadBalancerHealthCheck(lbName, vip, false) require.NoError(t, err) t.Run("normal delete", func(t *testing.T) { t.Parallel() - ops, err := ovnClient.DeleteLoadBalancerHealthCheckOp(lbName, vip) + ops, err := nbClient.DeleteLoadBalancerHealthCheckOp(lbName, vip) require.NoError(t, err) require.Len(t, ops, 2) @@ -362,7 +362,7 @@ func (suite *OvnClientTestSuite) testDeleteLoadBalancerHealthCheckOp() { func(t *testing.T) { t.Parallel() - ops, err := ovnClient.DeleteLoadBalancerHealthCheckOp(lbName, vipNonExistent) + ops, err := nbClient.DeleteLoadBalancerHealthCheckOp(lbName, vipNonExistent) require.NoError(t, err) require.Len(t, ops, 0) },