Skip to content

Commit 875c0f0

Browse files
.
1 parent afb40f4 commit 875c0f0

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

cns/restserver/internalapi.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
230230
return len(programmedNCs), errors.Wrap(err, "failed to get nc version list from nmagent")
231231
}
232232

233-
// Get IMDS NC versions for delegated NIC scenarios
234-
imdsNCVersions, err := service.getIMDSNCs(ctx)
233+
// Get IMDS NC versions for delegated NIC scenarios. If any of the NMA API check calls, imds calls fails assume that nma build doesn't have the latest changes and create empty map
234+
imdsNCVersions := service.getIMDSNCs(ctx)
235235
if err != nil {
236236
// If any of the NMA API check calls, imds calls fails assume that nma build doesn't have the latest changes and create empty map
237237
imdsNCVersions = make(map[string]string)
@@ -687,26 +687,26 @@ func (service *HTTPRestService) isNCDetailsAPIExists(ctx context.Context) bool {
687687
}
688688

689689
// GetIMDSNCs gets NC versions from IMDS and returns them as a map
690-
func (service *HTTPRestService) getIMDSNCs(ctx context.Context) (map[string]string, error) {
690+
func (service *HTTPRestService) getIMDSNCs(ctx context.Context) map[string]string {
691691
imdsClient := service.imdsClient
692692
if imdsClient == nil {
693693
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
694694
logger.Errorf("IMDS client is not available")
695-
return make(map[string]string), nil
695+
return make(map[string]string)
696696
}
697697
// Check NC version support
698698
if !service.isNCDetailsAPIExists(ctx) {
699699
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
700700
logger.Errorf("IMDS does not support NC details API")
701-
return make(map[string]string), nil
701+
return make(map[string]string)
702702
}
703703

704704
// Get all network interfaces from IMDS
705705
networkInterfaces, err := imdsClient.GetNetworkInterfaces(ctx)
706706
if err != nil {
707707
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
708708
logger.Errorf("Failed to get network interfaces from IMDS: %v", err)
709-
return make(map[string]string), nil
709+
return make(map[string]string)
710710
}
711711

712712
// Build ncs map from the network interfaces
@@ -722,12 +722,13 @@ func (service *HTTPRestService) getIMDSNCs(ctx context.Context) (map[string]stri
722722
} else if runtime.GOOS == "windows" && service.isPrefixonNicSwiftV2() {
723723
err := service.setPrefixOnNICRegistry(true, iface.MacAddress.String())
724724
if err != nil {
725+
//nolint:staticcheck // SA1019: suppress deprecated logger.Debugf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
725726
logger.Debugf("failed to add PrefixOnNic keys to Windows registry: %w", err)
726727
}
727728
}
728729
}
729730

730-
return ncs, nil
731+
return ncs
731732
}
732733

733734
// Check whether NC is SwiftV2 NIC associated NC and prefix on nic is enabled

cns/restserver/internalapi_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,8 +1790,7 @@ func TestSyncHostNCVersionWithWindowsSwiftV2(t *testing.T) {
17901790
assert.Equal(t, "2", updatedRegularNC.HostVersion, "Regular NC host version should be updated to 2")
17911791
assert.Equal(t, "2", updatedSwiftV2NC.HostVersion, "SwiftV2 NC host version should be updated to 2")
17921792

1793-
imdsNCs, err := testSvc.getIMDSNCs(ctx)
1794-
assert.NoError(t, err, "getIMDSNCs should not return error")
1793+
imdsNCs := testSvc.getIMDSNCs(ctx)
17951794

17961795
// Verify IMDS results
17971796
assert.Contains(t, imdsNCs, "nc-with-compartment-id", "NC with compartment ID should be in results")
@@ -1807,8 +1806,4 @@ func TestSyncHostNCVersionWithWindowsSwiftV2(t *testing.T) {
18071806
// Test with no SwiftV2 NCs
18081807
delete(testSvc.state.ContainerStatus, swiftV2NCID)
18091808
assert.False(t, testSvc.isPrefixonNicSwiftV2(), "isPrefixonNicSwiftV2() should return false without SwiftV2 NCs")
1810-
1811-
// Call getIMDSNCs again to verify condition is not triggered
1812-
_, err2 := testSvc.getIMDSNCs(ctx)
1813-
assert.NoError(t, err2, "getIMDSNCs should not return error")
18141809
}

0 commit comments

Comments
 (0)