diff --git a/cns/restserver/api_test.go b/cns/restserver/api_test.go index 021f1f093a..c3a8a5bd40 100644 --- a/cns/restserver/api_test.go +++ b/cns/restserver/api_test.go @@ -431,6 +431,30 @@ func TestGetNetworkContainerByOrchestratorContext(t *testing.T) { t.Fatal(err) } + mnma := &fakes.NMAgentClientFake{ + PutNetworkContainerF: func(_ context.Context, _ *nmagent.PutNetworkContainerRequest) error { + return nil + }, + JoinNetworkF: func(_ context.Context, _ nmagent.JoinNetworkRequest) error { + return nil + }, + } + + cleanup := setMockNMAgent(svc, mnma) + defer cleanup() + + mnma.GetNCVersionListF = func(_ context.Context) (nmagent.NCVersionList, error) { + return nmagent.NCVersionList{ + Containers: []nmagent.NCVersion{ + { + // Must set it as params.ncID without cns.SwiftPrefix to mock real nmagent nc format. + NetworkContainerID: params.ncID, + Version: params.ncVersion, + }, + }, + }, nil + } + fmt.Println("Now calling getNetworkContainerByContext") resp, err := getNetworkContainerByContext(params) if err != nil { @@ -554,7 +578,8 @@ func TestGetNetworkContainerVersionStatus(t *testing.T) { return nmagent.NCVersionList{ Containers: []nmagent.NCVersion{ { - NetworkContainerID: cns.SwiftPrefix + params.ncID, + // Must set it as params.ncID without cns.SwiftPrefix to mock real nmagent nc format. + NetworkContainerID: params.ncID, Version: params.ncVersion, }, }, @@ -596,7 +621,8 @@ func TestGetNetworkContainerVersionStatus(t *testing.T) { return nmagent.NCVersionList{ Containers: []nmagent.NCVersion{ { - NetworkContainerID: cns.SwiftPrefix + params.ncID, + // Must set it as params.ncID without cns.SwiftPrefix to mock real nmagent nc format. + NetworkContainerID: params.ncID, Version: "0", }, }, diff --git a/cns/restserver/util.go b/cns/restserver/util.go index 446be88b91..cbaac7b9d3 100644 --- a/cns/restserver/util.go +++ b/cns/restserver/util.go @@ -394,9 +394,8 @@ func (service *HTTPRestService) getNetworkContainerResponse( } nmaNCs := map[string]string{} for _, nc := range ncVersionListResp.Containers { - nmaNCs[nc.NetworkContainerID] = nc.Version + nmaNCs[cns.SwiftPrefix+nc.NetworkContainerID] = nc.Version } - if exists && !skipNCVersionCheck { // If the goal state is available with CNS, check if the NC is pending VFP programming waitingForUpdate, getNetworkContainerResponse.Response.ReturnCode, getNetworkContainerResponse.Response.Message = service.isNCWaitingForUpdate(