-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace lr/ls/lrp/lsp function call with ovnClient (#2477)
Co-authored-by: liguo <li.guo@99cloud.net>
- Loading branch information
Showing
24 changed files
with
736 additions
and
1,262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package controller | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/require" | ||
"k8s.io/client-go/util/workqueue" | ||
|
||
mockovs "github.com/kubeovn/kube-ovn/mocks/pkg/ovs" | ||
"github.com/kubeovn/kube-ovn/pkg/client/clientset/versioned/fake" | ||
informerfactory "github.com/kubeovn/kube-ovn/pkg/client/informers/externalversions" | ||
kubeovninformer "github.com/kubeovn/kube-ovn/pkg/client/informers/externalversions/kubeovn/v1" | ||
) | ||
|
||
type fakeControllerInformers struct { | ||
vpcInformer kubeovninformer.VpcInformer | ||
sbunetInformer kubeovninformer.SubnetInformer | ||
} | ||
|
||
type fakeController struct { | ||
fakeController *Controller | ||
fakeinformers *fakeControllerInformers | ||
mockOvnClient *mockovs.MockOvnClient | ||
} | ||
|
||
func alwaysReady() bool { return true } | ||
|
||
func newFakeController(t *testing.T) *fakeController { | ||
/* kube ovn fake client */ | ||
kubeovnClient := fake.NewSimpleClientset() | ||
kubeovnInformerFactory := informerfactory.NewSharedInformerFactory(kubeovnClient, 0) | ||
vpcInformer := kubeovnInformerFactory.Kubeovn().V1().Vpcs() | ||
sbunetInformer := kubeovnInformerFactory.Kubeovn().V1().Subnets() | ||
|
||
fakeInformers := &fakeControllerInformers{ | ||
vpcInformer: vpcInformer, | ||
sbunetInformer: sbunetInformer, | ||
} | ||
|
||
/* ovn fake client */ | ||
mockOvnClient := mockovs.NewMockOvnClient(gomock.NewController(t)) | ||
|
||
ctrl := &Controller{ | ||
vpcsLister: vpcInformer.Lister(), | ||
vpcSynced: alwaysReady, | ||
subnetsLister: sbunetInformer.Lister(), | ||
subnetSynced: alwaysReady, | ||
ovnClient: mockOvnClient, | ||
syncVirtualPortsQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), ""), | ||
} | ||
|
||
return &fakeController{ | ||
fakeController: ctrl, | ||
fakeinformers: fakeInformers, | ||
mockOvnClient: mockOvnClient, | ||
} | ||
} | ||
|
||
func Test_allSubnetReady(t *testing.T) { | ||
t.Parallel() | ||
|
||
fakeController := newFakeController(t) | ||
ctrl := fakeController.fakeController | ||
mockOvnClient := fakeController.mockOvnClient | ||
|
||
subnets := []string{"ovn-default", "join"} | ||
|
||
t.Run("all subnet ready", func(t *testing.T) { | ||
mockOvnClient.EXPECT().LogicalSwitchExists(gomock.Any()).Return(true, nil).Times(2) | ||
|
||
ready, err := ctrl.allSubnetReady(subnets...) | ||
require.NoError(t, err) | ||
require.True(t, ready) | ||
}) | ||
|
||
t.Run("some subnet are not ready", func(t *testing.T) { | ||
mockOvnClient.EXPECT().LogicalSwitchExists(subnets[0]).Return(true, nil) | ||
mockOvnClient.EXPECT().LogicalSwitchExists(subnets[1]).Return(false, nil) | ||
|
||
ready, err := ctrl.allSubnetReady(subnets...) | ||
require.NoError(t, err) | ||
require.False(t, ready) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func newLogicalRouterPort(lrName, lrpName, mac string, networks []string) *ovnnb.LogicalRouterPort { | ||
return &ovnnb.LogicalRouterPort{ | ||
Name: lrpName, | ||
MAC: mac, | ||
Networks: networks, | ||
ExternalIDs: map[string]string{ | ||
"lr": lrName, | ||
}, | ||
} | ||
} | ||
|
||
func Test_logicalRouterPortFilter(t *testing.T) { | ||
t.Parallel() | ||
|
||
exceptPeerPorts := map[string]struct{}{ | ||
"except-lrp-0": {}, | ||
"except-lrp-1": {}, | ||
} | ||
|
||
lrpNames := []string{"other-0", "other-1", "other-2", "except-lrp-0", "except-lrp-1"} | ||
lrps := make([]*ovnnb.LogicalRouterPort, 0) | ||
for _, lrpName := range lrpNames { | ||
lrp := newLogicalRouterPort("", lrpName, "", nil) | ||
peer := fmt.Sprintf("%s-peer", lrpName) | ||
lrp.Peer = &peer | ||
lrps = append(lrps, lrp) | ||
} | ||
|
||
filterFunc := logicalRouterPortFilter(exceptPeerPorts) | ||
|
||
for _, lrp := range lrps { | ||
if _, ok := exceptPeerPorts[lrp.Name]; ok { | ||
require.False(t, filterFunc(lrp)) | ||
} else { | ||
require.True(t, filterFunc(lrp)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.