Skip to content

Commit 85a7bda

Browse files
committed
functional tests for aws deployment
Signed-off-by: Sebastian Sch <sebassch@gmail.com>
1 parent 5e03deb commit 85a7bda

File tree

10 files changed

+324
-36
lines changed

10 files changed

+324
-36
lines changed

test/conformance/tests/fixtures.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
var sriovInfos *cluster.EnabledNodes
15+
var platformType consts.PlatformTypes
1516

1617
var _ = BeforeSuite(func() {
1718
err := clean.All()
@@ -39,13 +40,23 @@ var _ = BeforeSuite(func() {
3940
setFeatureFlag(consts.ResourceInjectorMatchConditionFeatureGate, true)
4041
}
4142

43+
platformType, err = cluster.GetPlatformType(clients, operatorNamespace)
44+
Expect(err).ToNot(HaveOccurred())
45+
4246
err = namespaces.Create(namespaces.Test, clients)
4347
Expect(err).ToNot(HaveOccurred())
4448
err = namespaces.Clean(operatorNamespace, namespaces.Test, clients, discovery.Enabled())
4549
Expect(err).ToNot(HaveOccurred())
4650
WaitForSRIOVStable()
47-
sriovInfos, err = cluster.DiscoverSriov(clients, operatorNamespace)
48-
Expect(err).ToNot(HaveOccurred())
51+
52+
switch platformType {
53+
case consts.Baremetal:
54+
sriovInfos, err = cluster.DiscoverSriov(clients, operatorNamespace)
55+
Expect(err).ToNot(HaveOccurred())
56+
case consts.AWS:
57+
sriovInfos, err = cluster.DiscoverSriovForAws(clients, operatorNamespace)
58+
Expect(err).ToNot(HaveOccurred())
59+
}
4960
})
5061

5162
var _ = AfterSuite(func() {

test/conformance/tests/init.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package tests
22

33
import (
44
"os"
5+
"strconv"
6+
"time"
57

68
testclient "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/client"
79
)
810

911
var (
12+
waitingTime = 20 * time.Minute
1013
clients *testclient.ClientSet
1114
operatorNamespace string
1215
)
@@ -21,4 +24,10 @@ func init() {
2124
if clients == nil {
2225
panic("failed package init, failed to create ClientSet")
2326
}
27+
28+
waitingEnv := os.Getenv("SRIOV_WAITING_TIME")
29+
newTime, err := strconv.Atoi(waitingEnv)
30+
if err == nil && newTime != 0 {
31+
waitingTime = time.Duration(newTime) * time.Minute
32+
}
2433
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package tests
2+
3+
import (
4+
"context"
5+
"strings"
6+
"time"
7+
8+
. "github.com/onsi/ginkgo/v2"
9+
. "github.com/onsi/gomega"
10+
. "github.com/onsi/gomega/gstruct"
11+
12+
corev1 "k8s.io/api/core/v1"
13+
"k8s.io/apimachinery/pkg/api/resource"
14+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
16+
17+
sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
18+
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
19+
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/discovery"
20+
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/namespaces"
21+
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/network"
22+
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/pod"
23+
)
24+
25+
var _ = FDescribe("[sriov] aws platform", Ordered, func() {
26+
BeforeAll(func() {
27+
if platformType != consts.AWS {
28+
Skip("AWS platform is not supported on non-AWS platforms")
29+
}
30+
Expect(len(sriovInfos.Nodes)).ToNot(BeZero())
31+
Expect(len(sriovInfos.States)).ToNot(BeZero())
32+
Expect(sriovInfos.States[sriovInfos.Nodes[0]].Status.Interfaces).ToNot(BeEmpty())
33+
Expect(sriovInfos.States[sriovInfos.Nodes[0]].Status.Interfaces[0].NetFilter).To(ContainSubstring("aws/NetworkID:"))
34+
})
35+
36+
AfterAll(func() {
37+
err := namespaces.Clean(operatorNamespace, namespaces.Test, clients, discovery.Enabled())
38+
Expect(err).ToNot(HaveOccurred())
39+
WaitForSRIOVStable()
40+
})
41+
42+
Describe("Generic SriovNetworkNodePolicy", func() {
43+
It("should configure vf in vfio-pci mode", func() {
44+
node := sriovInfos.Nodes[0]
45+
nic, err := sriovInfos.FindOneSriovDevice(node)
46+
Expect(err).ToNot(HaveOccurred())
47+
Expect(nic).ToNot(BeNil())
48+
49+
By("creating a vfio-pci node policy")
50+
resourceName := "testvfio"
51+
vfioPolicy, err := network.CreateSriovPolicyWithNetfilter(clients, "test-policy-", operatorNamespace, nic.NetFilter, node, 1, resourceName, "vfio-pci")
52+
Expect(err).ToNot(HaveOccurred())
53+
54+
By("waiting for the node state to be updated")
55+
Eventually(func() sriovv1.Interfaces {
56+
nodeState := &sriovv1.SriovNetworkNodeState{}
57+
err := clients.Get(context.Background(), runtimeclient.ObjectKey{Namespace: operatorNamespace, Name: node}, nodeState)
58+
Expect(err).ToNot(HaveOccurred())
59+
return nodeState.Spec.Interfaces
60+
}, 1*time.Minute, 1*time.Second).Should(ContainElement(MatchFields(
61+
IgnoreExtras,
62+
Fields{
63+
"Name": Equal(nic.Name),
64+
"NumVfs": Equal(1),
65+
})))
66+
67+
By("waiting the sriov to be stable on the node")
68+
WaitForSRIOVStable()
69+
70+
By("waiting for the resources to be available")
71+
Eventually(func() int64 {
72+
testedNode, err := clients.CoreV1Interface.Nodes().Get(context.Background(), node, metav1.GetOptions{})
73+
Expect(err).ToNot(HaveOccurred())
74+
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
75+
allocatable, _ := resNum.AsInt64()
76+
return allocatable
77+
}, 10*time.Minute, time.Second).Should(Equal(int64(1)))
78+
79+
By("validate the pf info exist on host")
80+
output, _, err := runCommandOnConfigDaemon(node, "/bin/bash", "-c", "ls /host/etc/sriov-operator/pci/ | wc -l")
81+
Expect(err).ToNot(HaveOccurred())
82+
Expect(output).ToNot(Equal("1"))
83+
84+
podDefinition := pod.GetDefinition()
85+
podDefinition.Spec.Containers[0].Resources = corev1.ResourceRequirements{
86+
Requests: corev1.ResourceList{
87+
corev1.ResourceName("openshift.io/" + resourceName): resource.MustParse("1"),
88+
},
89+
Limits: corev1.ResourceList{
90+
corev1.ResourceName("openshift.io/" + resourceName): resource.MustParse("1"),
91+
},
92+
}
93+
94+
firstPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
95+
Expect(err).ToNot(HaveOccurred())
96+
97+
firstPod = waitForPodRunning(firstPod)
98+
99+
By("Checking the vfio device exist inside the pod")
100+
output, errOutput, err := pod.ExecCommand(clients, firstPod, "sh", "-c", "ls /dev/vfio/ | wc -l")
101+
Expect(err).ToNot(HaveOccurred())
102+
Expect(errOutput).To(Equal(""))
103+
Expect(strings.TrimSpace(output)).To(Equal("2"))
104+
105+
By("deleting the policy")
106+
err = clients.Delete(context.Background(), vfioPolicy, &runtimeclient.DeleteOptions{})
107+
Expect(err).ToNot(HaveOccurred())
108+
WaitForSRIOVStable()
109+
110+
Eventually(func() int64 {
111+
testedNode, err := clients.CoreV1Interface.Nodes().Get(context.Background(), node, metav1.GetOptions{})
112+
Expect(err).ToNot(HaveOccurred())
113+
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
114+
allocatable, _ := resNum.AsInt64()
115+
return allocatable
116+
}, 2*time.Minute, time.Second).Should(Equal(int64(0)))
117+
118+
By("validate the pf info doesn't exist on the host anymore")
119+
output, _, err = runCommandOnConfigDaemon(node, "/bin/bash", "-c", "ls /host/etc/sriov-operator/pci/ | wc -l")
120+
Expect(err).ToNot(HaveOccurred())
121+
Expect(output).ToNot(Equal("0"))
122+
123+
By("checking the driver was reset to default")
124+
nodeState := &sriovv1.SriovNetworkNodeState{}
125+
err = clients.Get(context.Background(), runtimeclient.ObjectKey{Namespace: operatorNamespace, Name: node}, nodeState)
126+
Expect(err).ToNot(HaveOccurred())
127+
Expect(nodeState.Status.Interfaces).To(ContainElement(MatchFields(
128+
IgnoreExtras,
129+
Fields{
130+
"Name": Equal(nic.Name),
131+
"Driver": Equal("ena"),
132+
})))
133+
})
134+
})
135+
})

test/conformance/tests/test_exporter_metrics.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
11+
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
1112
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster"
1213
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/discovery"
1314
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/namespaces"
@@ -31,6 +32,10 @@ var _ = Describe("[sriov] Metrics Exporter", Ordered, ContinueOnFailure, func()
3132
var nic *sriovv1.InterfaceExt
3233

3334
BeforeAll(func() {
35+
if platformType != consts.Baremetal {
36+
Skip("Metrics exporter is not supported on non-baremetal platforms")
37+
}
38+
3439
err := namespaces.Create(namespaces.Test, clients)
3540
Expect(err).ToNot(HaveOccurred())
3641

test/conformance/tests/test_networkpool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ var _ = Describe("[sriov] NetworkPool", Ordered, func() {
3030
var resourceName = "testrdma"
3131

3232
BeforeAll(func() {
33+
if platformType != consts.Baremetal {
34+
Skip("NetworkPool is not supported on non-baremetal platforms")
35+
}
36+
3337
WaitForSRIOVStable()
3438

3539
err := namespaces.Create(namespaces.Test, clients)

test/conformance/tests/test_policy_configuration.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
1616

1717
sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
18+
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
1819
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster"
1920
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/discovery"
2021
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/namespaces"
@@ -23,6 +24,12 @@ import (
2324
)
2425

2526
var _ = Describe("[sriov] operator", Ordered, func() {
27+
BeforeEach(func() {
28+
if platformType != consts.Baremetal {
29+
Skip("Policy configuration is not supported on non-baremetal platforms")
30+
}
31+
})
32+
2633
Describe("Custom SriovNetworkNodePolicy", func() {
2734
BeforeEach(func() {
2835
err := namespaces.Clean(operatorNamespace, namespaces.Test, clients, discovery.Enabled())

test/conformance/tests/test_sriov_operator.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bufio"
55
"context"
66
"fmt"
7-
"os"
87
"strconv"
98
"strings"
109
"time"
@@ -27,6 +26,7 @@ import (
2726
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
2827

2928
sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
29+
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
3030
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster"
3131
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/discovery"
3232
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/execute"
@@ -36,7 +36,6 @@ import (
3636
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/pod"
3737
)
3838

39-
var waitingTime = 20 * time.Minute
4039
var sriovNetworkName = "test-sriovnetwork"
4140
var snoTimeoutMultiplier time.Duration = 0
4241

@@ -52,15 +51,13 @@ const (
5251
ipamIpv4 = `{"type": "host-local","ranges": [[{"subnet": "1.1.1.0/24"}]],"dataDir": "/run/my-orchestrator/container-ipam-state"}`
5352
)
5453

55-
func init() {
56-
waitingEnv := os.Getenv("SRIOV_WAITING_TIME")
57-
newTime, err := strconv.Atoi(waitingEnv)
58-
if err == nil && newTime != 0 {
59-
waitingTime = time.Duration(newTime) * time.Minute
60-
}
61-
}
62-
6354
var _ = Describe("[sriov] operator", Ordered, func() {
55+
BeforeAll(func() {
56+
if platformType != consts.Baremetal {
57+
Skip("Operator is not supported on non-baremetal platforms")
58+
}
59+
})
60+
6461
AfterAll(func() {
6562
err := namespaces.Clean(operatorNamespace, namespaces.Test, clients, discovery.Enabled())
6663
Expect(err).ToNot(HaveOccurred())

test/conformance/tests/test_switchdev.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010

1111
sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
12+
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
1213
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster"
1314
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/discovery"
1415
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/namespaces"
@@ -21,6 +22,9 @@ import (
2122
var _ = Describe("[sriov] Switchdev", Ordered, func() {
2223

2324
BeforeAll(func() {
25+
if platformType != consts.Baremetal {
26+
Skip("Switchdev is not supported on non-baremetal platforms")
27+
}
2428
if cluster.VirtualCluster() {
2529
Skip("IGB driver does not support switchdev driver model")
2630
}

0 commit comments

Comments
 (0)