pbacsko commented on code in PR #608:
URL: https://github.com/apache/yunikorn-k8shim/pull/608#discussion_r1219837721


##########
test/e2e/preemption/preemption_test.go:
##########
@@ -0,0 +1,321 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package preemption_test
+
+import (
+       "fmt"
+       "strconv"
+       "strings"
+       "time"
+
+       "github.com/onsi/ginkgo/v2"
+       "github.com/onsi/gomega"
+       v1 "k8s.io/api/core/v1"
+
+       "github.com/apache/yunikorn-k8shim/pkg/common/constants"
+       tests "github.com/apache/yunikorn-k8shim/test/e2e"
+       "github.com/apache/yunikorn-k8shim/test/e2e/framework/configmanager"
+       "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/common"
+       "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s"
+       "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/yunikorn"
+)
+
+var kClient k8s.KubeCtl
+var restClient yunikorn.RClient
+var ns *v1.Namespace
+var dev = "dev" + common.RandSeq(5)
+var oldConfigMap = new(v1.ConfigMap)
+var annotation = "ann-" + common.RandSeq(10)
+
+// Nodes
+var Worker = ""
+var WorkerMemRes int64
+var sleepPodMemLimit int64
+var taintKey = "e2e_test_preemption"
+var nodesToTaint []string
+
+// Queues
+var preemptionQueueYamlFormat = `
+partitions:
+  - name: default
+    queues:
+      - name: root
+        submitacl: '*'
+        queues:
+          - name: sandbox1
+            submitacl: '*'
+            properties:
+              preemption.delay: 1s
+            resources:
+              guaranteed:
+                memory: %dM
+          - name: sandbox2
+            submitacl: '*'
+            properties:
+              preemption.policy: %s
+              preemption.delay: 1s
+            resources:
+              guaranteed:
+                memory: %dM
+`
+
+var _ = ginkgo.BeforeSuite(func() {
+       // Initializing kubectl client
+       kClient = k8s.KubeCtl{}
+       Ω(kClient.SetClient()).To(gomega.BeNil())
+       // Initializing rest client
+       restClient = yunikorn.RClient{}
+       Ω(restClient).NotTo(gomega.BeNil())
+
+       annotation = "ann-" + common.RandSeq(10)
+       yunikorn.EnsureYuniKornConfigsPresent()
+       yunikorn.UpdateConfigMapWrapper(oldConfigMap, "", annotation)
+
+       ginkgo.By("Port-forward the scheduler pod")
+       var err = kClient.PortForwardYkSchedulerPod()
+       Ω(err).NotTo(gomega.HaveOccurred())
+
+       ginkgo.By("create development namespace")
+       ns, err = kClient.CreateNamespace(dev, nil)
+       gomega.Ω(err).NotTo(gomega.HaveOccurred())
+       gomega.Ω(ns.Status.Phase).To(gomega.Equal(v1.NamespaceActive))
+
+       var nodes *v1.NodeList
+       nodes, err = kClient.GetNodes()
+       Ω(err).NotTo(gomega.HaveOccurred())
+       Ω(len(nodes.Items)).NotTo(gomega.BeZero(), "Nodes cant be empty")
+
+       // Extract node allocatable resources
+       for _, node := range nodes.Items {
+               // skip master if it's marked as such
+               node := node
+               if k8s.IsMasterNode(&node) || !k8s.IsComputeNode(&node) {
+                       continue
+               }
+               if Worker == "" {
+                       Worker = node.Name
+               } else {
+                       nodesToTaint = append(nodesToTaint, node.Name)
+               }
+       }
+       Ω(Worker).NotTo(gomega.BeEmpty(), "Worker node not found")
+
+       ginkgo.By("Tainting some nodes..")
+       err = kClient.TaintNodes(nodesToTaint, taintKey, "value", 
v1.TaintEffectNoSchedule)
+       Ω(err).NotTo(gomega.HaveOccurred())
+
+       nodesDAOInfo, err := restClient.GetNodes(constants.DefaultPartition)
+       Ω(err).NotTo(gomega.HaveOccurred())
+       Ω(nodesDAOInfo).NotTo(gomega.BeNil())
+
+       for _, node := range *nodesDAOInfo {
+               if node.NodeID == Worker {
+                       WorkerMemRes = node.Available["memory"]
+               }
+       }
+       WorkerMemRes /= (1000 * 1000) // change to M
+       fmt.Fprintf(ginkgo.GinkgoWriter, "Worker node %s available memory 
%dM\n", Worker, WorkerMemRes)
+
+       sleepPodMemLimit = int64(float64(WorkerMemRes) / 3)
+       Ω(sleepPodMemLimit).NotTo(gomega.BeZero(), "Sleep pod memory limit 
cannot be zero")
+       fmt.Fprintf(ginkgo.GinkgoWriter, "Sleep pod limit memory %dM\n", 
sleepPodMemLimit)
+})
+
+var _ = ginkgo.AfterSuite(func() {
+
+       ginkgo.By("Untainting some nodes")
+       err := kClient.UntaintNodes(nodesToTaint, taintKey)
+       Ω(err).NotTo(gomega.HaveOccurred(), "Could not remove taint from nodes 
"+strings.Join(nodesToTaint, ","))
+
+       ginkgo.By("Check Yunikorn's health")
+       checks, err := yunikorn.GetFailedHealthChecks()
+       Ω(err).NotTo(gomega.HaveOccurred())
+       Ω(checks).To(gomega.Equal(""), checks)
+
+       testDescription := ginkgo.CurrentSpecReport()
+       if testDescription.Failed() {
+               
tests.LogTestClusterInfoWrapper(testDescription.FailureMessage(), 
[]string{ns.Name})
+               tests.LogYunikornContainer(testDescription.FailureMessage())
+       }
+       ginkgo.By("Tearing down namespace: " + ns.Name)
+       err = kClient.TearDownNamespace(ns.Name)
+       Ω(err).NotTo(gomega.HaveOccurred())
+
+       yunikorn.RestoreConfigMapWrapper(oldConfigMap, annotation)
+})
+
+var _ = ginkgo.Describe("Preemption", func() {
+       ginkgo.It("Verify_basic_preemption", func() {
+               ginkgo.By("A queue uses resource more than the guaranteed value 
even after removing one of the pods. The cluster doesn't have enough resource 
to deploy a pod in another queue which uses resource less than the guaranteed 
value.")
+               // update config

Review Comment:
   Either update config in BeforeSuite and reset in AfterSuite, or do it 
BeforeEach/AfterEach. If you want to do this in every test case, then perform a 
reset step also.
   
   Right now, it's problematic because you don't perform restoration. If the 
config is the same for every test, then I suggest BeforeSuite/AfterSuite. There 
are examples for config saving/restoration in different suites, check those out.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to