Skip to content

Commit 2e88813

Browse files
authored
test: add uts for cni add function (#3069)
* add dualnic windows multitenancy test * add linux multitenancy test * add linux swiftv2 multi nic ep info test * add windows swiftv2 infra with delegated ep info test * add check to ensure epInfo.ifName is overwritten in add endpoint for linux swiftv2 * test options set in invoker propagate to all endpoint infos * test dns in nwCfg propagates to all endpoint infos * test options and data are created for each endpoint info * address linter issues
1 parent b5046a0 commit 2e88813

File tree

7 files changed

+803
-8
lines changed

7 files changed

+803
-8
lines changed

cni/network/invoker_mock.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type MockIpamInvoker struct {
3131
delegatedVMNIC bool
3232
delegatedVMNICFail bool
3333
ipMap map[string]bool
34-
customReturn map[string]network.InterfaceInfo
34+
add func(opt IPAMAddConfig) (ipamAddResult IPAMAddResult, err error)
3535
}
3636

3737
func NewMockIpamInvoker(ipv6, v4Fail, v6Fail, delegatedVMNIC, delegatedVMNICFail bool) *MockIpamInvoker {
@@ -47,8 +47,11 @@ func NewMockIpamInvoker(ipv6, v4Fail, v6Fail, delegatedVMNIC, delegatedVMNICFail
4747

4848
func NewCustomMockIpamInvoker(customReturn map[string]network.InterfaceInfo) *MockIpamInvoker {
4949
return &MockIpamInvoker{
50-
customReturn: customReturn,
51-
50+
add: func(_ IPAMAddConfig) (ipamAddResult IPAMAddResult, err error) {
51+
ipamAddResult = IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
52+
ipamAddResult.interfaceInfo = customReturn
53+
return ipamAddResult, nil
54+
},
5255
ipMap: make(map[string]bool),
5356
}
5457
}
@@ -112,9 +115,8 @@ func (invoker *MockIpamInvoker) Add(opt IPAMAddConfig) (ipamAddResult IPAMAddRes
112115
}
113116
}
114117

115-
if invoker.customReturn != nil {
116-
ipamAddResult.interfaceInfo = invoker.customReturn
117-
return ipamAddResult, nil
118+
if invoker.add != nil {
119+
return invoker.add(opt)
118120
}
119121

120122
return ipamAddResult, nil

cni/network/network_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func setNetworkOptions(cnsNwConfig *cns.GetNetworkContainerResponse, nwInfo *net
4646
}
4747
}
4848

49+
// update epInfo data field, allow host to nc, allow nc to host, and network container id
4950
func setEndpointOptions(cnsNwConfig *cns.GetNetworkContainerResponse, epInfo *network.EndpointInfo, vethName string) {
5051
if cnsNwConfig != nil && cnsNwConfig.MultiTenancyInfo.ID != 0 {
5152
logger.Info("Setting Endpoint Options")

0 commit comments

Comments
 (0)