@@ -20,6 +20,7 @@ import (
2020 "github.com/Azure/azure-container-networking/cns/common"
2121 "github.com/Azure/azure-container-networking/cns/configuration"
2222 "github.com/Azure/azure-container-networking/cns/fakes"
23+ "github.com/Azure/azure-container-networking/cns/imds"
2324 "github.com/Azure/azure-container-networking/cns/types"
2425 "github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
2526 nma "github.com/Azure/azure-container-networking/nmagent"
@@ -271,11 +272,14 @@ func TestSyncHostNCVersion(t *testing.T) {
271272
272273 // Create a custom IMDS mock that returns the second NC
273274 mockIMDS := & struct {
274- ncVersions func (ctx context.Context ) (map [ string ] string , error )
275+ ncVersions func (ctx context.Context ) ([]imds. NetworkInterface , error )
275276 }{
276- ncVersions : func (ctx context.Context ) (map [string ]string , error ) {
277- return map [string ]string {
278- imdsNCID : "2" ,
277+ ncVersions : func (ctx context.Context ) ([]imds.NetworkInterface , error ) {
278+ return []imds.NetworkInterface {
279+ {
280+ InterfaceCompartmentId : imdsNCID ,
281+ InterfaceCompartmentVersion : "2" ,
282+ },
279283 }, nil
280284 },
281285 }
@@ -368,11 +372,14 @@ func TestSyncHostNCVersionErrorMissingNC(t *testing.T) {
368372
369373 // Create IMDS mock that returns 1 NC but with different ID (not matching the outdated NC)
370374 mockIMDS := & struct {
371- ncVersions func (ctx context.Context ) (map [ string ] string , error )
375+ ncVersions func (ctx context.Context ) ([]imds. NetworkInterface , error )
372376 }{
373- ncVersions : func (ctx context.Context ) (map [string ]string , error ) {
374- return map [string ]string {
375- "different-nc-id" : "1" , // IMDS has a different NC, not the outdated one
377+ ncVersions : func (ctx context.Context ) ([]imds.NetworkInterface , error ) {
378+ return []imds.NetworkInterface {
379+ {
380+ InterfaceCompartmentId : "different-nc-id" ,
381+ InterfaceCompartmentVersion : "1" , // IMDS has a different NC, not the outdated one
382+ },
376383 }, nil
377384 },
378385 }
@@ -401,7 +408,7 @@ func TestSyncHostNCVersionErrorMissingNC(t *testing.T) {
401408 }
402409
403410 // Check that the error message contains the expected text
404- expectedErrorText := "unabled to update some NCs"
411+ expectedErrorText := "unable to update some NCs"
405412 if ! strings .Contains (err .Error (), expectedErrorText ) {
406413 t .Errorf ("Expected error to contain '%s', but got: %v" , expectedErrorText , err )
407414 }
@@ -427,11 +434,14 @@ func TestSyncHostNCVersionLocalVersionHigher(t *testing.T) {
427434
428435 // Create IMDS mock that returns lower version(2) than local host version(3)
429436 mockIMDS := & struct {
430- ncVersions func (ctx context.Context ) (map [ string ] string , error )
437+ ncVersions func (ctx context.Context ) ([]imds. NetworkInterface , error )
431438 }{
432- ncVersions : func (ctx context.Context ) (map [string ]string , error ) {
433- return map [string ]string {
434- req .NetworkContainerid : "1" , // IMDS has version 1, which is lower than local version 3
439+ ncVersions : func (ctx context.Context ) ([]imds.NetworkInterface , error ) {
440+ return []imds.NetworkInterface {
441+ {
442+ InterfaceCompartmentId : req .NetworkContainerid ,
443+ InterfaceCompartmentVersion : "1" , // IMDS has version 1, which is lower than local version 3
444+ },
435445 }, nil
436446 },
437447 }
@@ -482,10 +492,10 @@ func TestSyncHostNCVersionLocalHigherThanDNC(t *testing.T) {
482492 svc .Unlock ()
483493
484494 mockIMDS := & struct {
485- ncVersions func (ctx context.Context ) (map [ string ] string , error )
495+ ncVersions func (ctx context.Context ) ([]imds. NetworkInterface , error )
486496 }{
487- ncVersions : func (ctx context.Context ) (map [ string ] string , error ) {
488- return map [ string ] string {}, nil
497+ ncVersions : func (ctx context.Context ) ([]imds. NetworkInterface , error ) {
498+ return []imds. NetworkInterface {}, nil
489499 },
490500 }
491501
@@ -540,10 +550,10 @@ func TestSyncHostNCVersionNMAgentAPICallFailed(t *testing.T) {
540550
541551 // Create IMDS mock that returns empty, as nma api call failed
542552 mockIMDS := & struct {
543- ncVersions func (ctx context.Context ) (map [ string ] string , error )
553+ ncVersions func (ctx context.Context ) ([]imds. NetworkInterface , error )
544554 }{
545- ncVersions : func (ctx context.Context ) (map [ string ] string , error ) {
546- return map [ string ] string {}, nil
555+ ncVersions : func (ctx context.Context ) ([]imds. NetworkInterface , error ) {
556+ return []imds. NetworkInterface {}, nil
547557 },
548558 }
549559
@@ -595,11 +605,11 @@ func TestSyncHostNCVersionSwiftV2APINotSupported(t *testing.T) {
595605
596606 // Create IMDS mock - this should not be called since SwiftV2 is not supported
597607 mockIMDS := & struct {
598- ncVersions func (ctx context.Context ) (map [ string ] string , error )
608+ ncVersions func (ctx context.Context ) ([]imds. NetworkInterface , error )
599609 }{
600- ncVersions : func (ctx context.Context ) (map [ string ] string , error ) {
610+ ncVersions : func (ctx context.Context ) ([]imds. NetworkInterface , error ) {
601611 t .Errorf ("IMDS should not be called when SwiftV2 API is not supported" )
602- return map [ string ] string {}, nil
612+ return []imds. NetworkInterface {}, nil
603613 },
604614 }
605615
@@ -1770,14 +1780,14 @@ func TestMustEnsureNoStaleNCs_PanicsWhenIPsFromStaleNCAreAssigned(t *testing.T)
17701780// mockIMDSAdapter adapts the anonymous struct to implement the imdsClient interface
17711781type mockIMDSAdapter struct {
17721782 mock * struct {
1773- ncVersions func (ctx context.Context ) (map [ string ] string , error )
1783+ ncVersions func (ctx context.Context ) ([]imds. NetworkInterface , error )
17741784 }
17751785}
17761786
17771787func (m * mockIMDSAdapter ) GetVMUniqueID (ctx context.Context ) (string , error ) {
17781788 panic ("GetVMUniqueID should not be called in syncHostNCVersion tests, adding mockIMDSAdapter implements the full IMDS interface" )
17791789}
17801790
1781- func (m * mockIMDSAdapter ) GetNCVersionsFromIMDS (ctx context.Context ) (map [ string ] string , error ) {
1791+ func (m * mockIMDSAdapter ) GetNCVersions (ctx context.Context ) ([]imds. NetworkInterface , error ) {
17821792 return m .mock .ncVersions (ctx )
17831793}
0 commit comments