Skip to content

Commit 48e6cfd

Browse files
remove nmagent api check
1 parent b8e413c commit 48e6cfd

File tree

2 files changed

+9
-144
lines changed

2 files changed

+9
-144
lines changed

cns/restserver/internalapi.go

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
const (
2929
// Known API names we care about
30-
nmAgentSwiftV2API = "EnableSwiftV2NCGoalStateSupport"
3130
expectedIMDSAPIVersion = "2025-07-24"
3231
PrefixOnNicNCVersion = "1"
3332
)
@@ -665,36 +664,6 @@ func (service *HTTPRestService) SetVFForAccelnetNICs() error {
665664
return service.setVFForAccelnetNICs()
666665
}
667666

668-
func (service *HTTPRestService) getSupportedAPIsFromNMAgent(ctx context.Context) ([]string, error) {
669-
if service.nma == nil {
670-
return nil, errors.New("NMAgent client is not available")
671-
}
672-
673-
apis, err := service.nma.SupportedAPIs(ctx)
674-
if err != nil {
675-
return nil, errors.Wrap(err, "failed to get supported APIs from NMAgent client")
676-
}
677-
678-
return apis, nil
679-
}
680-
681-
func (service *HTTPRestService) isSwiftV2NCGoalStateSupported(ctx context.Context) bool {
682-
apis, err := service.getSupportedAPIsFromNMAgent(ctx)
683-
if err != nil {
684-
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
685-
logger.Errorf("Failed to get supported APIs from NMAgent: %v", err)
686-
return false
687-
}
688-
689-
for _, api := range apis {
690-
if strings.Contains(api, nmAgentSwiftV2API) {
691-
return true
692-
}
693-
}
694-
695-
return false
696-
}
697-
698667
func (service *HTTPRestService) isNCDetailsAPIExists(ctx context.Context) bool {
699668
versionsResp, err := service.imdsClient.GetIMDSVersions(ctx)
700669
if err != nil {
@@ -706,6 +675,8 @@ func (service *HTTPRestService) isNCDetailsAPIExists(ctx context.Context) bool {
706675
// Check if the expected API version exists in the response
707676
for _, version := range versionsResp.APIVersions {
708677
if version == expectedIMDSAPIVersion {
678+
//nolint:staticcheck // SA1019: suppress deprecated logger.Debugf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
679+
logger.Debugf("IMDS supports NC details API: %s", version)
709680
return true
710681
}
711682
}
@@ -720,15 +691,18 @@ func (service *HTTPRestService) GetIMDSNCs(ctx context.Context) (map[string]stri
720691
logger.Errorf("IMDS client is not available")
721692
return make(map[string]string), nil
722693
}
723-
// Check NMAgent API support for SwiftV2, if it fails return empty map assuming support might not be available in that nma build
724-
if !service.isSwiftV2NCGoalStateSupported(ctx) || !service.isNCDetailsAPIExists(ctx) {
694+
// Check NC version support
695+
if !service.isNCDetailsAPIExists(ctx) {
725696
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
726-
logger.Errorf("NMAgent does not support SwiftV2 API or IMDS does not support NC details API")
697+
logger.Errorf("IMDS does not support NC details API")
727698
return make(map[string]string), nil
728699
}
729700

730701
// Get all network interfaces from IMDS
731702
networkInterfaces, err := imdsClient.GetNetworkInterfaces(ctx)
703+
704+
//nolint:staticcheck // SA1019: suppress deprecated logger.Debugf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
705+
logger.Debugf("IMDS network interfaces: %+v", networkInterfaces)
732706
if err != nil {
733707
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
734708
logger.Errorf("Failed to get network interfaces from IMDS: %v", err)
@@ -738,6 +712,7 @@ func (service *HTTPRestService) GetIMDSNCs(ctx context.Context) (map[string]stri
738712
// Build ncs map from the network interfaces
739713
ncs := make(map[string]string)
740714
for _, iface := range networkInterfaces {
715+
logger.Debugf("Nc id: %s and mac address: %s from IMDS call", iface.InterfaceCompartmentID, iface.MacAddress.String())
741716
// IMDS returns interfaceCompartmentID, as nc id guid has different context on nma. We map these to NC ID
742717
ncID := iface.InterfaceCompartmentID
743718

cns/restserver/internalapi_test.go

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,6 @@ func TestSyncHostNCVersion(t *testing.T) {
251251
},
252252
}, nil
253253
},
254-
SupportedAPIsF: func(_ context.Context) ([]string, error) {
255-
return []string{"EnableSwiftV2NCGoalStateSupport", "OtherAPI"}, nil
256-
},
257254
}
258255
cleanup := setMockNMAgent(svc, mnma)
259256
defer cleanup()
@@ -321,9 +318,6 @@ func TestPendingIPsGotUpdatedWhenSyncHostNCVersion(t *testing.T) {
321318
},
322319
}, nil
323320
},
324-
SupportedAPIsF: func(_ context.Context) ([]string, error) {
325-
return []string{"EnableSwiftV2NCGoalStateSupport", "OtherAPI"}, nil
326-
},
327321
}
328322
cleanup := setMockNMAgent(svc, mnma)
329323
defer cleanup()
@@ -364,9 +358,6 @@ func TestSyncHostNCVersionErrorMissingNC(t *testing.T) {
364358
Containers: []nma.NCVersion{},
365359
}, nil
366360
},
367-
SupportedAPIsF: func(_ context.Context) ([]string, error) {
368-
return []string{"EnableSwiftV2NCGoalStateSupport", "OtherAPI"}, nil
369-
},
370361
}
371362
cleanup := setMockNMAgent(svc, mnma)
372363
defer cleanup()
@@ -412,9 +403,6 @@ func TestSyncHostNCVersionLocalVersionHigher(t *testing.T) {
412403
Containers: []nma.NCVersion{},
413404
}, nil
414405
},
415-
SupportedAPIsF: func(_ context.Context) ([]string, error) {
416-
return []string{"EnableSwiftV2NCGoalStateSupport", "OtherAPI"}, nil
417-
},
418406
}
419407
cleanup := setMockNMAgent(svc, mnma)
420408
defer cleanup()
@@ -456,9 +444,6 @@ func TestSyncHostNCVersionLocalHigherThanDNC(t *testing.T) {
456444
Containers: []nma.NCVersion{}, // Empty
457445
}, nil
458446
},
459-
SupportedAPIsF: func(_ context.Context) ([]string, error) {
460-
return []string{"EnableSwiftV2NCGoalStateSupport", "OtherAPI"}, nil
461-
},
462447
}
463448
cleanup := setMockNMAgent(svc, mnma)
464449
defer cleanup()
@@ -484,98 +469,6 @@ func TestSyncHostNCVersionLocalHigherThanDNC(t *testing.T) {
484469
containerStatus.HostVersion, containerStatus.CreateNetworkContainerRequest.Version)
485470
}
486471

487-
func TestSyncHostNCVersionNMAgentAPICallFailed(t *testing.T) {
488-
// Test scenario where NMAgent SupportedAPIs call fails, but outdated nc is still present in NMAgent and successfully updated
489-
req := createNCReqeustForSyncHostNCVersion(t)
490-
491-
svc.Lock()
492-
ncStatus := svc.state.ContainerStatus[req.NetworkContainerid]
493-
ncStatus.CreateNetworkContainerRequest.Version = "2"
494-
ncStatus.HostVersion = "1"
495-
svc.state.ContainerStatus[req.NetworkContainerid] = ncStatus
496-
svc.Unlock()
497-
498-
// Create IMDS mock that returns empty, as nma api call failed
499-
cleanupIMDS := setupIMDSMockAPIsWithCustomIDs(svc, []string{imdsNCID, "nc2"})
500-
defer cleanupIMDS()
501-
502-
mnma := &fakes.NMAgentClientFake{
503-
GetNCVersionListF: func(_ context.Context) (nma.NCVersionList, error) {
504-
return nma.NCVersionList{
505-
Containers: []nma.NCVersion{
506-
{
507-
NetworkContainerID: req.NetworkContainerid,
508-
Version: "2", // NMAgent has the updated version
509-
},
510-
},
511-
}, nil
512-
},
513-
SupportedAPIsF: func(_ context.Context) ([]string, error) {
514-
return nil, errors.New("failed to connect to NMAgent API endpoint")
515-
},
516-
}
517-
cleanup := setMockNMAgent(svc, mnma)
518-
defer cleanup()
519-
520-
_, err := svc.syncHostNCVersion(context.Background(), cns.KubernetesCRD)
521-
if err != nil {
522-
t.Errorf("Expected sync to succeed with NMAgent fallback when API check fails, but got error: %v", err)
523-
}
524-
525-
// Verify that the NC HostVersion was updated to 2 from NMAgent
526-
containerStatus := svc.state.ContainerStatus[req.NetworkContainerid]
527-
if containerStatus.HostVersion != "2" {
528-
t.Errorf("Expected HostVersion to be updated to 2 (from NMAgent), got %s", containerStatus.HostVersion)
529-
}
530-
}
531-
532-
func TestSyncHostNCVersionSwiftV2APINotSupported(t *testing.T) {
533-
req := createNCReqeustForSyncHostNCVersion(t)
534-
535-
svc.Lock()
536-
ncStatus := svc.state.ContainerStatus[req.NetworkContainerid]
537-
ncStatus.CreateNetworkContainerRequest.Version = "2"
538-
ncStatus.HostVersion = "1"
539-
svc.state.ContainerStatus[req.NetworkContainerid] = ncStatus
540-
svc.Unlock()
541-
542-
// Create IMDS mock - this should not be called since SwiftV2 is not supported
543-
cleanupIMDS := setupIMDSMockAPIsWithCustomIDs(svc, []string{imdsNCID, "nc2"})
544-
defer cleanupIMDS()
545-
546-
// NMAgent returns APIs but doesn't include SwiftV2
547-
mnma := &fakes.NMAgentClientFake{
548-
GetNCVersionListF: func(_ context.Context) (nma.NCVersionList, error) {
549-
return nma.NCVersionList{
550-
Containers: []nma.NCVersion{
551-
{
552-
NetworkContainerID: req.NetworkContainerid,
553-
Version: "2",
554-
},
555-
},
556-
}, nil
557-
},
558-
SupportedAPIsF: func(_ context.Context) ([]string, error) {
559-
return []string{}, nil
560-
},
561-
}
562-
cleanup := setMockNMAgent(svc, mnma)
563-
defer cleanup()
564-
565-
// Should succeed even when SwiftV2 API is not supported
566-
// because NMAgent has the updated NC version
567-
_, err := svc.syncHostNCVersion(context.Background(), cns.KubernetesCRD)
568-
if err != nil {
569-
t.Errorf("Expected sync to succeed with NMAgent only when SwiftV2 API not supported, but got error: %v", err)
570-
}
571-
572-
// Verify that the NC HostVersion was updated to "2" from NMAgent
573-
containerStatus := svc.state.ContainerStatus[req.NetworkContainerid]
574-
if containerStatus.HostVersion != "2" {
575-
t.Errorf("Expected HostVersion to be updated to 2 (from NMAgent), got %s", containerStatus.HostVersion)
576-
}
577-
}
578-
579472
func TestSyncHostNCVersionIMDSAPIVersionNotSupported(t *testing.T) {
580473
orchestratorTypes := []string{cns.Kubernetes, cns.KubernetesCRD}
581474
for _, orchestratorType := range orchestratorTypes {
@@ -594,9 +487,6 @@ func TestSyncHostNCVersionIMDSAPIVersionNotSupported(t *testing.T) {
594487
GetNCVersionListF: func(_ context.Context) (nma.NCVersionList, error) {
595488
return nma.NCVersionList{Containers: []nma.NCVersion{}}, nil
596489
},
597-
SupportedAPIsF: func(_ context.Context) ([]string, error) {
598-
return []string{"EnableSwiftV2NCGoalStateSupport", "OtherAPI"}, nil
599-
},
600490
}
601491
cleanup := setMockNMAgent(svc, mnma)
602492
defer cleanup()

0 commit comments

Comments
 (0)