@@ -35,6 +35,20 @@ type AzureAcceleratedNetworkingSpecInput struct {
3535 ClusterName string
3636}
3737
38+ // KnownAcceleratedNetworkingSupportedVMSKUs is a manually curated dictionary that maps VM SKUS to accelerated networking capabilities
39+ // NOTE: add SKUs being tested to this lookup table.
40+ var KnownAcceleratedNetworkingSupportedVMSKUs = map [compute.VirtualMachineSizeTypes ]bool {
41+ compute .VirtualMachineSizeTypesStandardB2ms : false ,
42+ compute .VirtualMachineSizeTypesStandardD2V2 : true ,
43+ compute .VirtualMachineSizeTypesStandardD2V3 : false ,
44+ compute .VirtualMachineSizeTypesStandardD2sV3 : false ,
45+ compute .VirtualMachineSizeTypesStandardD4V2 : true ,
46+ compute .VirtualMachineSizeTypesStandardD4V3 : true ,
47+ compute .VirtualMachineSizeTypesStandardD8sV3 : true ,
48+ compute .VirtualMachineSizeTypesStandardNC6sV3 : false ,
49+ compute .VirtualMachineSizeTypesStandardNV6 : false ,
50+ }
51+
3852// AzureAcceleratedNetworkingSpec implements a test that verifies Azure VMs in a workload
3953// cluster provisioned by CAPZ have accelerated networking enabled if they're capable of it.
4054func AzureAcceleratedNetworkingSpec (ctx context.Context , inputGetter func () AzureAcceleratedNetworkingSpecInput ) {
@@ -54,22 +68,14 @@ func AzureAcceleratedNetworkingSpec(ctx context.Context, inputGetter func() Azur
5468 Expect (err ).NotTo (HaveOccurred ())
5569 vmsClient := compute .NewVirtualMachinesClient (subscriptionID )
5670 vmsClient .Authorizer = authorizer
71+ vmssClient := compute .NewVirtualMachineScaleSetsClient (subscriptionID )
72+ vmssClient .Authorizer = authorizer
73+ vmssVMsClient := compute .NewVirtualMachineScaleSetVMsClient (subscriptionID )
74+ vmssVMsClient .Authorizer = authorizer
5775 nicsClient := network .NewInterfacesClient (subscriptionID )
5876 nicsClient .Authorizer = authorizer
5977
6078 By ("verifying EnableAcceleratedNetworking for the primary NIC of each VM" )
61- // NOTE: add SKUs being tested to this lookup table.
62- acceleratedNetworking := map [compute.VirtualMachineSizeTypes ]bool {
63- compute .VirtualMachineSizeTypesStandardB2ms : false ,
64- compute .VirtualMachineSizeTypesStandardD2V2 : true ,
65- compute .VirtualMachineSizeTypesStandardD2V3 : false ,
66- compute .VirtualMachineSizeTypesStandardD2sV3 : false ,
67- compute .VirtualMachineSizeTypesStandardD4V2 : true ,
68- compute .VirtualMachineSizeTypesStandardD4V3 : true ,
69- compute .VirtualMachineSizeTypesStandardD8sV3 : true ,
70- compute .VirtualMachineSizeTypesStandardNC6sV3 : false ,
71- compute .VirtualMachineSizeTypesStandardNV6 : false ,
72- }
7379 rgName := input .ClusterName
7480 page , err := vmsClient .List (ctx , rgName )
7581 Expect (err ).NotTo (HaveOccurred ())
@@ -79,10 +85,8 @@ func AzureAcceleratedNetworkingSpec(ctx context.Context, inputGetter func() Azur
7985 sku := vm .HardwareProfile .VMSize
8086 for _ , nic := range * vm .NetworkProfile .NetworkInterfaces {
8187 if nic .Primary != nil && * nic .Primary {
82- // verify that accelerated networking is enabled if the SKU is capable
83- nicInfo , err := nicsClient .Get (ctx , rgName , filepath .Base (* nic .ID ), "" )
88+ capable , found , nicInfo , err := validateAcceleratedNetworkingCapabilityMatch (ctx , nicsClient , rgName , * nic .ID , sku )
8489 Expect (err ).NotTo (HaveOccurred ())
85- capable , found := acceleratedNetworking [sku ]
8690 if ! found {
8791 fmt .Fprintf (GinkgoWriter , "SKU %s was not found, please add to the acceleratedNetworking lookup table.\n " , sku )
8892 } else {
@@ -95,4 +99,41 @@ func AzureAcceleratedNetworkingSpec(ctx context.Context, inputGetter func() Azur
9599 err = page .NextWithContext (ctx )
96100 Expect (err ).NotTo (HaveOccurred ())
97101 }
102+ By ("verifying EnableAcceleratedNetworking for the primary NIC of each VMSS instance" )
103+ p , err := vmssClient .List (ctx , rgName )
104+ Expect (err ).NotTo (HaveOccurred ())
105+ for p .NotDone () {
106+ for _ , vmss := range p .Values () {
107+ itr , err := vmssVMsClient .ListComplete (ctx , rgName , * vmss .Name , "" , "" , "" )
108+ var instances []compute.VirtualMachineScaleSetVM
109+ for ; itr .NotDone (); err = itr .NextWithContext (ctx ) {
110+ Expect (err ).NotTo (HaveOccurred ())
111+ vm := itr .Value ()
112+ sku := vm .HardwareProfile .VMSize
113+ for _ , nic := range * vm .NetworkProfile .NetworkInterfaces {
114+ if nic .Primary != nil && * nic .Primary {
115+ capable , found , nicInfo , err := validateAcceleratedNetworkingCapabilityMatch (ctx , nicsClient , rgName , * nic .ID , sku )
116+ Expect (err ).NotTo (HaveOccurred ())
117+ if ! found {
118+ fmt .Fprintf (GinkgoWriter , "SKU %s was not found, please add to the acceleratedNetworking lookup table.\n " , sku )
119+ } else {
120+ Expect (capable ).To (Equal (* nicInfo .EnableAcceleratedNetworking ))
121+ }
122+ }
123+ }
124+ instances = append (instances , vm )
125+ }
126+ }
127+ }
128+ }
129+
130+ // validateAcceleratedNetworkingCapabilityMatch is a simple, common func to ensure that a NIC resource has the accelerated networking capability that we expect
131+ // because the NIC client is a common reference for both VM and VMSS resources, we can re-use this business logic in both above flows
132+ func validateAcceleratedNetworkingCapabilityMatch (ctx context.Context , nicsClient network.InterfacesClient , rgName , nicID string , sku compute.VirtualMachineSizeTypes ) (bool , bool , network.Interface , error ) {
133+ nicInfo , err := nicsClient .Get (ctx , rgName , filepath .Base (nicID ), "" )
134+ if err != nil {
135+ return false , false , network.Interface {}, err
136+ }
137+ capable , found := KnownAcceleratedNetworkingSupportedVMSKUs [sku ]
138+ return capable , found , nicInfo , nil
98139}
0 commit comments