@@ -776,16 +776,26 @@ var _ = Describe("[rfe_id:27363][performance] CPU Management", Ordered, func() {
776
776
AfterEach (func () {
777
777
cmd := []string {"rm" , "-f" , "/rootfs/var/roothome/create" }
778
778
nodes .ExecCommand (ctx , workerRTNode , cmd )
779
- deletePod (ctx , guaranteedPod )
780
- deletePod (ctx , secondPod )
779
+ deleteTestPod (ctx , guaranteedPod )
780
+ deleteTestPod (ctx , secondPod )
781
781
})
782
782
783
783
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
+
786
797
containerIDs := make ([]string , 2 )
787
798
788
- var err error
789
799
containerIDs [0 ], err = pods .GetContainerIDByName (guaranteedPod , "test" )
790
800
Expect (err ).ToNot (HaveOccurred ())
791
801
containerIDs [1 ], err = pods .GetContainerIDByName (secondPod , "test" )
@@ -805,9 +815,8 @@ var _ = Describe("[rfe_id:27363][performance] CPU Management", Ordered, func() {
805
815
806
816
hostnameMatches := hostnameRe .FindAllStringSubmatch (out , - 1 )
807
817
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" )
811
820
uniqueCombinations := make (map [string ]struct {})
812
821
zippedMatches := make ([]map [string ]string , 0 )
813
822
for i := 0 ; i < len (hostnameMatches ) && i < len (cpusMatches ); i ++ {
@@ -820,47 +829,18 @@ var _ = Describe("[rfe_id:27363][performance] CPU Management", Ordered, func() {
820
829
})
821
830
}
822
831
}
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" )
857
838
})
858
839
})
859
840
860
841
})
861
842
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 ) {
864
844
testpod1 := pods .GetTestPod ()
865
845
testpod1 .Namespace = testutils .NamespaceTesting
866
846
testpod1 .Spec .Containers [0 ].Resources = corev1.ResourceRequirements {
@@ -875,16 +855,10 @@ func getGuaranteedPod(ctx context.Context, workerRTNode *corev1.Node) *corev1.Po
875
855
runtimeClass := components .GetComponentName (profile .Name , components .ComponentNamePrefix )
876
856
testpod1 .Spec .RuntimeClassName = & runtimeClass
877
857
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
884
859
}
885
860
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 ) {
888
862
testpod2 := pods .GetTestPod ()
889
863
testpod2 .Namespace = testutils .NamespaceTesting
890
864
testpod2 .Spec .NodeSelector = map [string ]string {testutils .LabelHostname : workerRTNode .Name }
@@ -893,23 +867,7 @@ func getNonGuaranteedPod(ctx context.Context, workerRTNode *corev1.Node) *corev1
893
867
runtimeClass := components .GetComponentName (profile .Name , components .ComponentNamePrefix )
894
868
testpod2 .Spec .RuntimeClassName = & runtimeClass
895
869
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
913
871
}
914
872
915
873
func checkForWorkloadPartitioning (ctx context.Context ) bool {
0 commit comments