forked from openshift/cluster-node-tuning-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_latency_testing_suite_test.go
119 lines (102 loc) · 4.79 KB
/
5_latency_testing_suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package __latency_testing_test
import (
"context"
"encoding/json"
"reflect"
"testing"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
testutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils"
testclient "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/client"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/images"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/junit"
testlog "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/log"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/namespaces"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodes"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/profiles"
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/profilesupdate"
ginkgo_reporters "kubevirt.io/qe-tools/pkg/ginkgo-reporters"
)
var prePullNamespace = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "testing-prepull",
},
}
var profile *performancev2.PerformanceProfile
var _ = BeforeSuite(func() {
Expect(testclient.ClientsEnabled).To(BeTrue())
// update PP isolated CPUs. the new cpu set for isolated should have an even number of CPUs to avoid failing the pod on SMTAlignment error,
// and should be greater than what is requested by the test cases in the suite so the test runs properly
var err error
profile, err = profiles.GetByNodeLabels(testutils.NodeSelectorLabels)
Expect(err).ToNot(HaveOccurred())
workerNodes, err := nodes.GetByLabels(testutils.NodeSelectorLabels)
Expect(err).ToNot(HaveOccurred())
initialIsolated := profile.Spec.CPU.Isolated
initialReserved := profile.Spec.CPU.Reserved
//updated both sets to ensure there is no overlap
latencyIsolatedSet := performancev2.CPUSet("1-9")
latencyReservedSet := performancev2.CPUSet("0")
totalCpus := cpuset.MustParse(string(latencyIsolatedSet)).Size() + cpuset.MustParse(string(latencyReservedSet)).Size()
nodesWithSufficientCpu := nodes.GetByCpuAllocatable(workerNodes, totalCpus)
//before applying the changes verify that there are compute nodes with sufficient cpus
if len(nodesWithSufficientCpu) != 0 {
if *initialIsolated != latencyIsolatedSet || *initialReserved != latencyReservedSet {
testlog.Info("Update the isolated and reserved cpus sets of the profile")
err = profilesupdate.UpdateIsolatedReservedCpus(latencyIsolatedSet, latencyReservedSet)
if err != nil {
testlog.Error("could not update the profile with the desired CPUs sets")
}
}
}
if err := createNamespace(); err != nil {
testlog.Errorf("cannot create the namespace: %v", err)
}
ds, err := images.PrePull(testclient.Client, images.Test(), prePullNamespace.Name, "cnf-tests")
if err != nil {
data, _ := json.Marshal(ds) // we can safely skip errors
testlog.Infof("DaemonSet %s/%s image=%q status:\n%s", ds.Namespace, ds.Name, images.Test(), string(data))
testlog.Errorf("cannot prepull image %q: %v", images.Test(), err)
}
})
var _ = AfterSuite(func() {
prePullNamespaceName := prePullNamespace.Name
err := testclient.Client.Delete(context.TODO(), prePullNamespace)
if err != nil {
testlog.Errorf("namespace %q could not be deleted err=%v", prePullNamespace.Name, err)
}
namespaces.WaitForDeletion(prePullNamespaceName, 5*time.Minute)
currentProfile, err := profiles.GetByNodeLabels(testutils.NodeSelectorLabels)
Expect(err).ToNot(HaveOccurred())
if reflect.DeepEqual(currentProfile.Spec, profile.Spec) != true {
testlog.Info("Restore initial performance profile")
err = profilesupdate.ApplyProfile(profile)
if err != nil {
testlog.Errorf("could not restore the initial profile: %v", err)
}
}
})
func Test5LatencyTesting(t *testing.T) {
RegisterFailHandler(Fail)
rr := []Reporter{}
if ginkgo_reporters.Polarion.Run {
rr = append(rr, &ginkgo_reporters.Polarion)
}
rr = append(rr, junit.NewJUnitReporter("latency_testing"))
RunSpecsWithDefaultAndCustomReporters(t, "Performance Addon Operator latency tools testing", rr)
}
func createNamespace() error {
err := testclient.Client.Create(context.TODO(), prePullNamespace)
if errors.IsAlreadyExists(err) {
testlog.Warningf("%q namespace already exists, that is unexpected", prePullNamespace.Name)
return nil
}
testlog.Infof("created namespace %q err=%v", prePullNamespace.Name, err)
return err
}