Skip to content

Commit e983f94

Browse files
committed
Used cpu.parse and deleteTestPod
1 parent e3fb051 commit e983f94

File tree

1 file changed

+27
-69
lines changed

1 file changed

+27
-69
lines changed

test/e2e/performanceprofile/functests/1_performance/cpu_management.go

Lines changed: 27 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -776,16 +776,26 @@ var _ = Describe("[rfe_id:27363][performance] CPU Management", Ordered, func() {
776776
AfterEach(func() {
777777
cmd := []string{"rm", "-f", "/rootfs/var/roothome/create"}
778778
nodes.ExecCommand(ctx, workerRTNode, cmd)
779-
deletePod(ctx, guaranteedPod)
780-
deletePod(ctx, secondPod)
779+
deleteTestPod(ctx, guaranteedPod)
780+
deleteTestPod(ctx, secondPod)
781781
})
782782

783783
It("[test_id: 74461] Verify that runc excludes the cpus used by guaranteed pod", func() {
784-
guaranteedPod = getGuaranteedPod(ctx, workerRTNode)
785-
secondPod = getNonGuaranteedPod(ctx, workerRTNode)
784+
guaranteedPod, err := getGuaranteedPod(ctx, workerRTNode)
785+
err = testclient.Client.Create(ctx, guaranteedPod)
786+
Expect(err).ToNot(HaveOccurred())
787+
_, err = pods.WaitForCondition(ctx, client.ObjectKeyFromObject(guaranteedPod), corev1.PodReady, corev1.ConditionTrue, 5*time.Minute)
788+
Expect(err).ToNot(HaveOccurred())
789+
Expect(guaranteedPod.Status.QOSClass).To(Equal(corev1.PodQOSGuaranteed))
790+
791+
secondPod, err := getNonGuaranteedPod(ctx, workerRTNode)
792+
err = testclient.Client.Create(ctx, secondPod)
793+
Expect(err).ToNot(HaveOccurred())
794+
_, err = pods.WaitForCondition(ctx, client.ObjectKeyFromObject(secondPod), corev1.PodReady, corev1.ConditionTrue, 5*time.Minute)
795+
Expect(err).ToNot(HaveOccurred())
796+
786797
containerIDs := make([]string, 2)
787798

788-
var err error
789799
containerIDs[0], err = pods.GetContainerIDByName(guaranteedPod, "test")
790800
Expect(err).ToNot(HaveOccurred())
791801
containerIDs[1], err = pods.GetContainerIDByName(secondPod, "test")
@@ -805,9 +815,8 @@ var _ = Describe("[rfe_id:27363][performance] CPU Management", Ordered, func() {
805815

806816
hostnameMatches := hostnameRe.FindAllStringSubmatch(out, -1)
807817
cpusMatches := cpusRe.FindAllStringSubmatch(out, -1)
808-
if len(hostnameMatches) == 0 || len(cpusMatches) == 0 {
809-
Fail("Failed to extract hostname or cpus information")
810-
}
818+
Expect(len(hostnameMatches)).ToNot(Equal(0), "Failed to extract hostname information")
819+
Expect(len(cpusMatches)).ToNot(Equal(0), "Failed to extract cpus information")
811820
uniqueCombinations := make(map[string]struct{})
812821
zippedMatches := make([]map[string]string, 0)
813822
for i := 0; i < len(hostnameMatches) && i < len(cpusMatches); i++ {
@@ -820,47 +829,18 @@ var _ = Describe("[rfe_id:27363][performance] CPU Management", Ordered, func() {
820829
})
821830
}
822831
}
823-
824-
parseCPUs := func(cpuStr string) []int {
825-
var cpus []int
826-
for _, part := range strings.Split(cpuStr, ",") {
827-
if strings.Contains(part, "-") {
828-
bounds := strings.Split(part, "-")
829-
min, _ := strconv.Atoi(bounds[0])
830-
max, _ := strconv.Atoi(bounds[1])
831-
for i := min; i <= max; i++ {
832-
cpus = append(cpus, i)
833-
}
834-
} else {
835-
val, _ := strconv.Atoi(part)
836-
cpus = append(cpus, val)
837-
}
838-
}
839-
return cpus
840-
}
841-
842-
guaranteedPodCpus := parseCPUs(zippedMatches[0]["cpus"])
843-
runcCpus := parseCPUs(zippedMatches[1]["cpus"])
844-
overlapFound := false
845-
for _, guaranteedCpu := range guaranteedPodCpus {
846-
for _, runcCpu := range runcCpus {
847-
if guaranteedCpu == runcCpu {
848-
overlapFound = true
849-
break
850-
}
851-
}
852-
if overlapFound {
853-
break
854-
}
855-
}
856-
Expect(overlapFound).ToNot(BeTrue(), "Overlap of cpus found, not expected behaviour")
832+
guaranteedPodCpus, err := cpuset.Parse(zippedMatches[0]["cpus"])
833+
Expect(err).ToNot(HaveOccurred())
834+
runcCpus, err := cpuset.Parse(zippedMatches[1]["cpus"])
835+
Expect(err).ToNot(HaveOccurred())
836+
overlapFound := !guaranteedPodCpus.Intersection(runcCpus).IsEmpty()
837+
Expect(overlapFound).ToNot(BeTrue(), "Overlap found between guaranteedPod cpus and runtime Cpus, not expected behaviour")
857838
})
858839
})
859840

860841
})
861842

862-
func getGuaranteedPod(ctx context.Context, workerRTNode *corev1.Node) *corev1.Pod {
863-
var err error
843+
func getGuaranteedPod(ctx context.Context, workerRTNode *corev1.Node) (*corev1.Pod, error) {
864844
testpod1 := pods.GetTestPod()
865845
testpod1.Namespace = testutils.NamespaceTesting
866846
testpod1.Spec.Containers[0].Resources = corev1.ResourceRequirements{
@@ -875,16 +855,10 @@ func getGuaranteedPod(ctx context.Context, workerRTNode *corev1.Node) *corev1.Po
875855
runtimeClass := components.GetComponentName(profile.Name, components.ComponentNamePrefix)
876856
testpod1.Spec.RuntimeClassName = &runtimeClass
877857

878-
err = testclient.Client.Create(ctx, testpod1)
879-
Expect(err).ToNot(HaveOccurred())
880-
_, err = pods.WaitForCondition(ctx, client.ObjectKeyFromObject(testpod1), corev1.PodReady, corev1.ConditionTrue, 5*time.Minute)
881-
Expect(err).ToNot(HaveOccurred())
882-
Expect(testpod1.Status.QOSClass).To(Equal(corev1.PodQOSGuaranteed))
883-
return testpod1
858+
return testpod1, nil
884859
}
885860

886-
func getNonGuaranteedPod(ctx context.Context, workerRTNode *corev1.Node) *corev1.Pod {
887-
var err error
861+
func getNonGuaranteedPod(ctx context.Context, workerRTNode *corev1.Node) (*corev1.Pod, error) {
888862
testpod2 := pods.GetTestPod()
889863
testpod2.Namespace = testutils.NamespaceTesting
890864
testpod2.Spec.NodeSelector = map[string]string{testutils.LabelHostname: workerRTNode.Name}
@@ -893,23 +867,7 @@ func getNonGuaranteedPod(ctx context.Context, workerRTNode *corev1.Node) *corev1
893867
runtimeClass := components.GetComponentName(profile.Name, components.ComponentNamePrefix)
894868
testpod2.Spec.RuntimeClassName = &runtimeClass
895869

896-
err = testclient.Client.Create(ctx, testpod2)
897-
Expect(err).ToNot(HaveOccurred())
898-
_, err = pods.WaitForCondition(ctx, client.ObjectKeyFromObject(testpod2), corev1.PodReady, corev1.ConditionTrue, 5*time.Minute)
899-
Expect(err).ToNot(HaveOccurred())
900-
return testpod2
901-
}
902-
903-
func deletePod(ctx context.Context, pod *corev1.Pod) {
904-
err := testclient.Client.Delete(ctx, pod)
905-
if err != nil {
906-
testlog.Errorf("Failed to delete Pod %s/%s: %v", pod.Namespace, pod.Name, err)
907-
}
908-
909-
err = pods.WaitForDeletion(ctx, pod, pods.DefaultDeletionTimeout*time.Second)
910-
if err != nil {
911-
testlog.Errorf("Timed out waiting for deletion of Pod %s/%s: %v", pod.Namespace, pod.Name, err)
912-
}
870+
return testpod2, nil
913871
}
914872

915873
func checkForWorkloadPartitioning(ctx context.Context) bool {

0 commit comments

Comments
 (0)