Skip to content

Commit da56b37

Browse files
authored
Fix the NC ID error when get container (#1767)
* Fix nc id mismatch * Fix the nc ID prefix issue
1 parent 36757fe commit da56b37

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

cns/restserver/api_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,30 @@ func TestGetNetworkContainerByOrchestratorContext(t *testing.T) {
431431
t.Fatal(err)
432432
}
433433

434+
mnma := &fakes.NMAgentClientFake{
435+
PutNetworkContainerF: func(_ context.Context, _ *nmagent.PutNetworkContainerRequest) error {
436+
return nil
437+
},
438+
JoinNetworkF: func(_ context.Context, _ nmagent.JoinNetworkRequest) error {
439+
return nil
440+
},
441+
}
442+
443+
cleanup := setMockNMAgent(svc, mnma)
444+
defer cleanup()
445+
446+
mnma.GetNCVersionListF = func(_ context.Context) (nmagent.NCVersionList, error) {
447+
return nmagent.NCVersionList{
448+
Containers: []nmagent.NCVersion{
449+
{
450+
// Must set it as params.ncID without cns.SwiftPrefix to mock real nmagent nc format.
451+
NetworkContainerID: params.ncID,
452+
Version: params.ncVersion,
453+
},
454+
},
455+
}, nil
456+
}
457+
434458
fmt.Println("Now calling getNetworkContainerByContext")
435459
resp, err := getNetworkContainerByContext(params)
436460
if err != nil {
@@ -554,7 +578,8 @@ func TestGetNetworkContainerVersionStatus(t *testing.T) {
554578
return nmagent.NCVersionList{
555579
Containers: []nmagent.NCVersion{
556580
{
557-
NetworkContainerID: cns.SwiftPrefix + params.ncID,
581+
// Must set it as params.ncID without cns.SwiftPrefix to mock real nmagent nc format.
582+
NetworkContainerID: params.ncID,
558583
Version: params.ncVersion,
559584
},
560585
},
@@ -596,7 +621,8 @@ func TestGetNetworkContainerVersionStatus(t *testing.T) {
596621
return nmagent.NCVersionList{
597622
Containers: []nmagent.NCVersion{
598623
{
599-
NetworkContainerID: cns.SwiftPrefix + params.ncID,
624+
// Must set it as params.ncID without cns.SwiftPrefix to mock real nmagent nc format.
625+
NetworkContainerID: params.ncID,
600626
Version: "0",
601627
},
602628
},

cns/restserver/util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,8 @@ func (service *HTTPRestService) getNetworkContainerResponse(
394394
}
395395
nmaNCs := map[string]string{}
396396
for _, nc := range ncVersionListResp.Containers {
397-
nmaNCs[nc.NetworkContainerID] = nc.Version
397+
nmaNCs[cns.SwiftPrefix+nc.NetworkContainerID] = nc.Version
398398
}
399-
400399
if exists && !skipNCVersionCheck {
401400
// If the goal state is available with CNS, check if the NC is pending VFP programming
402401
waitingForUpdate, getNetworkContainerResponse.Response.ReturnCode, getNetworkContainerResponse.Response.Message = service.isNCWaitingForUpdate(

0 commit comments

Comments
 (0)