Skip to content

Commit 07e2cca

Browse files
authored
Merge pull request #764 from mboersma/accelerated-networking-e2e-spec
💚 add test to validate accelerated networking for VMs
2 parents cb9b07f + 100a9e5 commit 07e2cca

File tree

3 files changed

+107
-3
lines changed

3 files changed

+107
-3
lines changed

cloud/services/agentpools/agentpools_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func TestReconcile(t *testing.T) {
229229
Name: "my-agent-pool",
230230
ResourceGroup: "my-rg",
231231
Cluster: "my-cluster",
232-
SKU: "Standard_A1",
232+
SKU: "Standard_D2s_v3",
233233
Version: to.StringPtr("9.99.9999"),
234234
Replicas: 2,
235235
OSDiskSizeGB: 100,
@@ -240,7 +240,7 @@ func TestReconcile(t *testing.T) {
240240
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
241241
Count: to.Int32Ptr(2),
242242
OsDiskSizeGB: to.Int32Ptr(100),
243-
VMSize: containerservice.VMSizeTypesStandardA1,
243+
VMSize: containerservice.VMSizeTypesStandardD2sV3,
244244
OrchestratorVersion: to.StringPtr("9.99.9999"),
245245
ProvisioningState: to.StringPtr("Succeeded"),
246246
},

test/e2e/azure_accelnet.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// +build e2e
2+
3+
/*
4+
Copyright 2020 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package e2e
20+
21+
import (
22+
"context"
23+
"fmt"
24+
"path/filepath"
25+
26+
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
27+
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
28+
"github.com/Azure/go-autorest/autorest/azure/auth"
29+
. "github.com/onsi/ginkgo"
30+
. "github.com/onsi/gomega"
31+
)
32+
33+
// AzureAcceleratedNetworkingSpecInput is the input for AzureAcceleratedNetworkingSpec.
34+
type AzureAcceleratedNetworkingSpecInput struct {
35+
ClusterName string
36+
}
37+
38+
// AzureAcceleratedNetworkingSpec implements a test that verifies Azure VMs in a workload
39+
// cluster provisioned by CAPZ have accelerated networking enabled if they're capable of it.
40+
func AzureAcceleratedNetworkingSpec(ctx context.Context, inputGetter func() AzureAcceleratedNetworkingSpecInput) {
41+
var (
42+
specName = "azure-accelerated-networking"
43+
input AzureAcceleratedNetworkingSpecInput
44+
)
45+
46+
input = inputGetter()
47+
Expect(input.ClusterName).NotTo(BeEmpty(), "Invalid argument. input.ClusterName can't be empty when calling %s spec", specName)
48+
49+
By("creating Azure clients with the workload cluster's subscription")
50+
settings, err := auth.GetSettingsFromEnvironment()
51+
Expect(err).NotTo(HaveOccurred())
52+
subscriptionID := settings.GetSubscriptionID()
53+
authorizer, err := settings.GetAuthorizer()
54+
Expect(err).NotTo(HaveOccurred())
55+
vmsClient := compute.NewVirtualMachinesClient(subscriptionID)
56+
vmsClient.Authorizer = authorizer
57+
nicsClient := network.NewInterfacesClient(subscriptionID)
58+
nicsClient.Authorizer = authorizer
59+
60+
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+
}
71+
rgName := input.ClusterName
72+
page, err := vmsClient.List(ctx, rgName)
73+
Expect(err).NotTo(HaveOccurred())
74+
Expect(len(page.Values())).To(BeNumerically(">", 0))
75+
for page.NotDone() {
76+
for _, vm := range page.Values() {
77+
sku := vm.HardwareProfile.VMSize
78+
for _, nic := range *vm.NetworkProfile.NetworkInterfaces {
79+
if nic.Primary != nil && *nic.Primary {
80+
// verify that accelerated networking is enabled if the SKU is capable
81+
nicInfo, err := nicsClient.Get(ctx, rgName, filepath.Base(*nic.ID), "")
82+
Expect(err).NotTo(HaveOccurred())
83+
capable, found := acceleratedNetworking[sku]
84+
if !found {
85+
fmt.Fprintf(GinkgoWriter, "SKU %s was not found, please add to the acceleratedNetworking lookup table.\n", sku)
86+
} else {
87+
Expect(capable).To(Equal(*nicInfo.EnableAcceleratedNetworking))
88+
}
89+
break
90+
}
91+
}
92+
}
93+
err = page.NextWithContext(ctx)
94+
Expect(err).NotTo(HaveOccurred())
95+
}
96+
}

test/e2e/azure_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ var _ = Describe("Workload cluster creation", func() {
125125
})
126126
})
127127

128-
Context("Creating a accessible load balancer", func() {
128+
Context("Creating an accessible load balancer", func() {
129129
AzureLBSpec(ctx, func() AzureLBSpecInput {
130130
return AzureLBSpecInput{
131131
BootstrapClusterProxy: bootstrapClusterProxy,
@@ -146,6 +146,14 @@ var _ = Describe("Workload cluster creation", func() {
146146
}
147147
})
148148
})
149+
150+
Context("Validating accelerated networking", func() {
151+
AzureAcceleratedNetworkingSpec(ctx, func() AzureAcceleratedNetworkingSpecInput {
152+
return AzureAcceleratedNetworkingSpecInput{
153+
ClusterName: clusterName,
154+
}
155+
})
156+
})
149157
})
150158
})
151159
})

0 commit comments

Comments
 (0)