Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cns/restserver/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ func TestNCIDCaseInSensitive(t *testing.T) {
ncVersionList := map[string]string{}
// add lower-case NCIDs to ncVersionList
for _, ncid := range ncids {
ncVersionList[lowerCaseNCGuid(ncid)] = "1"
ncVersionList[strings.TrimPrefix(lowerCaseNCGuid(ncid), cns.SwiftPrefix)] = "1"
}

for _, ncid := range ncids {
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/internalapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string,
if !skipNCVersionCheck {
nmaNCs := map[string]string{}
for _, nc := range ncVersionListResp.Containers {
nmaNCs[cns.SwiftPrefix+strings.ToLower(nc.NetworkContainerID)] = nc.Version
nmaNCs[strings.TrimPrefix(lowerCaseNCGuid(nc.NetworkContainerID), cns.SwiftPrefix)] = nc.Version
}

// check if the version is valid and save it to service state
Expand Down
18 changes: 6 additions & 12 deletions cns/restserver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ func (service *HTTPRestService) restoreState() {
}
}

func (service *HTTPRestService) saveNetworkContainerGoalState(
req cns.CreateNetworkContainerRequest,
) (types.ResponseCode, string) {
func (service *HTTPRestService) saveNetworkContainerGoalState(req cns.CreateNetworkContainerRequest) (types.ResponseCode, string) { //nolint // legacy
// we don't want to overwrite what other calls may have written
service.Lock()
defer service.Unlock()
Expand Down Expand Up @@ -414,8 +412,7 @@ func (service *HTTPRestService) getAllNetworkContainerResponses(
nmaNCs := map[string]string{}
for _, nc := range ncVersionListResp.Containers {
// store nmaNCID as lower case to allow case insensitive comparison with nc stored in CNS
nmaNCID := cns.SwiftPrefix + strings.ToLower(nc.NetworkContainerID)
nmaNCs[nmaNCID] = nc.Version
nmaNCs[strings.TrimPrefix(lowerCaseNCGuid(nc.NetworkContainerID), cns.SwiftPrefix)] = nc.Version
}

if !skipNCVersionCheck {
Expand Down Expand Up @@ -610,7 +607,7 @@ func (service *HTTPRestService) attachOrDetachHelper(req cns.ConfigureContainerN
nmaNCs := map[string]string{}
for _, nc := range ncVersionListResp.Containers {
// store nmaNCID as lower case to allow case insensitive comparison with nc stored in CNS
nmaNCs[strings.ToLower(nc.NetworkContainerID)] = nc.Version
nmaNCs[strings.TrimPrefix(lowerCaseNCGuid(nc.NetworkContainerID), cns.SwiftPrefix)] = nc.Version
}
_, returnCode, message := service.isNCWaitingForUpdate(existing.CreateNetworkContainerRequest.Version, req.NetworkContainerid, nmaNCs)
if returnCode == types.NetworkContainerVfpProgramPending {
Expand Down Expand Up @@ -846,9 +843,8 @@ func (service *HTTPRestService) populateIPConfigInfoUntransacted(ipConfigStatus
func lowerCaseNCGuid(ncid string) string {
ncidHasSwiftPrefix := strings.HasPrefix(ncid, cns.SwiftPrefix)
if ncidHasSwiftPrefix {
return cns.SwiftPrefix + strings.ToLower(strings.Split(ncid, cns.SwiftPrefix)[1])
return cns.SwiftPrefix + strings.ToLower(strings.TrimPrefix(ncid, cns.SwiftPrefix))
}

return strings.ToLower(ncid)
}

Expand All @@ -857,9 +853,7 @@ func lowerCaseNCGuid(ncid string) string {
// the VFP programming is pending
// This returns success / waitingForUpdate as false in all other cases.
// V2 is using the nmagent get nc version list api v2 which doesn't need authentication token
func (service *HTTPRestService) isNCWaitingForUpdate(
ncVersion, ncid string, ncVersionList map[string]string,
) (waitingForUpdate bool, returnCode types.ResponseCode, message string) {
func (service *HTTPRestService) isNCWaitingForUpdate(ncVersion, ncid string, ncVersionList map[string]string) (waitingForUpdate bool, returnCode types.ResponseCode, message string) {
ncStatus, ok := service.state.ContainerStatus[ncid]
if ok {
if ncStatus.VfpUpdateComplete &&
Expand All @@ -879,7 +873,7 @@ func (service *HTTPRestService) isNCWaitingForUpdate(

// get the ncVersionList with nc GUID as lower case
// when looking up if the ncid is present in ncVersionList, convert it to lowercase and then look up
nmaProgrammedNCVersionStr, ok := ncVersionList[lowerCaseNCGuid(ncid)]
nmaProgrammedNCVersionStr, ok := ncVersionList[strings.TrimPrefix(lowerCaseNCGuid(ncid), cns.SwiftPrefix)]
if !ok {
// NMA doesn't have this NC that we need programmed yet, bail out
logger.Printf("[Azure CNS] Failed to get NC %s doesn't exist in NMAgent NC version list "+
Expand Down