Skip to content

Commit e00a5b7

Browse files
handle synchostversion sync on pon swiftv2 nic
1 parent 61784dc commit e00a5b7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

cns/restserver/internalapi.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
191191
outdatedNCs := map[string]struct{}{}
192192
programmedNCs := map[string]struct{}{}
193193
for idx := range service.state.ContainerStatus {
194+
195+
// For prefix-on-NIC SwiftV2 NIC scenario, the NC details is published to different path in NMAgent and call to NMA here creates error. So Skipping nma check, synchost version logic.
196+
ncStatus := service.state.ContainerStatus[idx]
197+
if mac := ncStatus.CreateNetworkContainerRequest.NetworkInterfaceInfo.MACAddress; mac != "" {
198+
logger.Printf("NC %s has MAC address for prefix on nic swiftv2 scenario, skipping syncHostNCVersion", ncStatus.ID)
199+
continue
200+
}
194201
// Will open a separate PR to convert all the NC version related variable to int. Change from string to int is a pain.
195202
localNCVersion, err := strconv.Atoi(service.state.ContainerStatus[idx].HostVersion)
196203
if err != nil {

cns/restserver/internalapi_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,40 @@ func TestPendingIPsGotUpdatedWhenSyncHostNCVersion(t *testing.T) {
312312
}
313313
}
314314

315+
func TestSyncHostNCVersion_SkipsNCVersionForPrefixOnNICSwiftV2(t *testing.T) {
316+
orchestratorTypes := []string{cns.Kubernetes, cns.KubernetesCRD}
317+
for _, orchestratorType := range orchestratorTypes {
318+
orchestratorType := orchestratorType
319+
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
340+
svc.SyncHostNCVersion(context.Background(), orchestratorType)
341+
// 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)
345+
})
346+
}
347+
}
348+
315349
func createNCReqeustForSyncHostNCVersion(t *testing.T) cns.CreateNetworkContainerRequest {
316350
restartService()
317351
setEnv(t)

0 commit comments

Comments
 (0)