Skip to content

Commit 43b15dd

Browse files
update synhost skip test scenario
fix linting error updated lint error fix linting error .
1 parent 878bfad commit 43b15dd

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

cns/restserver/internalapi_test.go

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
batchSize = 10
4343
initPoolSize = 10
4444
ncID = "6a07155a-32d7-49af-872f-1e70ee366dc0"
45+
macAddress = "00:11:22:33:44:55"
4546
)
4647

4748
var dnsservers = []string{"8.8.8.8", "8.8.4.4"}
@@ -315,38 +316,26 @@ func TestPendingIPsGotUpdatedWhenSyncHostNCVersion(t *testing.T) {
315316
func TestSyncHostNCVersion_SkipsNCVersionForPrefixOnNICSwiftV2(t *testing.T) {
316317
orchestratorTypes := []string{cns.Kubernetes, cns.KubernetesCRD}
317318
for _, orchestratorType := range orchestratorTypes {
318-
orchestratorType := orchestratorType
319319
t.Run(orchestratorType, func(t *testing.T) {
320-
restartService()
321-
setEnv(t)
322-
setOrchestratorTypeInternal(orchestratorType)
323-
324-
ncID := "swiftv2-ncid"
325-
svc.state.ContainerStatus = map[string]containerstatus{
326-
ncID: {
327-
ID: ncID,
328-
HostVersion: "2",
329-
CreateNetworkContainerRequest: cns.CreateNetworkContainerRequest{
330-
NetworkContainerid: ncID,
331-
Version: "1",
332-
NetworkInterfaceInfo: cns.NetworkInterfaceInfo{
333-
MACAddress: "00:11:22:33:44:55",
334-
},
335-
},
336-
},
337-
}
338-
339-
// Should not error, and should not attempt version check
320+
req := createNCReqeustForSyncHostNCVersion(t, macAddress)
321+
containerStatus := svc.state.ContainerStatus[req.NetworkContainerid]
322+
//// HostVersion -1 and NC Version 0 and should remain unchanged, should not error
340323
svc.SyncHostNCVersion(context.Background(), orchestratorType)
324+
341325
// HostVersion and Version should remain unchanged
342-
containerStatus := svc.state.ContainerStatus[ncID]
343-
assert.Equal(t, "2", containerStatus.HostVersion)
344-
assert.Equal(t, "1", containerStatus.CreateNetworkContainerRequest.Version)
326+
assert.Equal(t, "-1", containerStatus.HostVersion)
327+
assert.Equal(t, "0", containerStatus.CreateNetworkContainerRequest.Version)
345328
})
346329
}
347330
}
348331

349-
func createNCReqeustForSyncHostNCVersion(t *testing.T) cns.CreateNetworkContainerRequest {
332+
func createNCReqeustForSyncHostNCVersion(t *testing.T, macAddresses ...string) cns.CreateNetworkContainerRequest {
333+
var macAddress string
334+
if len(macAddresses) > 0 {
335+
macAddress = macAddresses[0]
336+
} else {
337+
macAddress = ""
338+
}
350339
restartService()
351340
setEnv(t)
352341
setOrchestratorTypeInternal(cns.KubernetesCRD)
@@ -360,7 +349,7 @@ func createNCReqeustForSyncHostNCVersion(t *testing.T) cns.CreateNetworkContaine
360349
secIPConfig := newSecondaryIPConfig(ipAddress, ncVersion)
361350
ipID := uuid.New()
362351
secondaryIPConfigs[ipID.String()] = secIPConfig
363-
req := createNCReqInternal(t, secondaryIPConfigs, ncID, strconv.Itoa(ncVersion))
352+
req := createNCReqInternal(t, secondaryIPConfigs, ncID, strconv.Itoa(ncVersion), macAddress)
364353
return req
365354
}
366355

@@ -939,7 +928,14 @@ func validateNetworkRequest(t *testing.T, req cns.CreateNetworkContainerRequest)
939928
}
940929
}
941930

942-
func generateNetworkContainerRequest(secondaryIps map[string]cns.SecondaryIPConfig, ncID, ncVersion string) *cns.CreateNetworkContainerRequest {
931+
func generateNetworkContainerRequest(secondaryIps map[string]cns.SecondaryIPConfig, ncID, ncVersion string, macAddress ...string) *cns.CreateNetworkContainerRequest {
932+
var mac string
933+
if len(macAddress) > 0 {
934+
mac = macAddress[0]
935+
} else {
936+
mac = ""
937+
}
938+
943939
var ipConfig cns.IPConfiguration
944940
ipConfig.DNSServers = dnsservers
945941
ipConfig.GatewayIPAddress = gatewayIP
@@ -953,6 +949,9 @@ func generateNetworkContainerRequest(secondaryIps map[string]cns.SecondaryIPConf
953949
NetworkContainerid: ncID,
954950
IPConfiguration: ipConfig,
955951
Version: ncVersion,
952+
NetworkInterfaceInfo: cns.NetworkInterfaceInfo{
953+
MACAddress: mac,
954+
},
956955
}
957956

958957
ncVersionInInt, _ := strconv.Atoi(ncVersion)
@@ -1079,8 +1078,14 @@ func validateIPAMStateAfterReconcile(t *testing.T, ncReqs []*cns.CreateNetworkCo
10791078
}
10801079
}
10811080

1082-
func createNCReqInternal(t *testing.T, secondaryIPConfigs map[string]cns.SecondaryIPConfig, ncID, ncVersion string) cns.CreateNetworkContainerRequest {
1083-
req := generateNetworkContainerRequest(secondaryIPConfigs, ncID, ncVersion)
1081+
func createNCReqInternal(t *testing.T, secondaryIPConfigs map[string]cns.SecondaryIPConfig, ncID, ncVersion string, macAddresses ...string) cns.CreateNetworkContainerRequest {
1082+
var macAddress string
1083+
if len(macAddresses) > 0 {
1084+
macAddress = macAddresses[0]
1085+
} else {
1086+
macAddress = ""
1087+
}
1088+
req := generateNetworkContainerRequest(secondaryIPConfigs, ncID, ncVersion, macAddress)
10841089
returnCode := svc.CreateOrUpdateNetworkContainerInternal(req)
10851090
if returnCode != 0 {
10861091
t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode)

0 commit comments

Comments
 (0)