|
| 1 | +/* |
| 2 | +Copyright 2019 The Volcano Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package e2e |
| 18 | + |
| 19 | +import ( |
| 20 | + "bytes" |
| 21 | + "fmt" |
| 22 | + |
| 23 | + . "github.com/onsi/ginkgo" |
| 24 | + . "github.com/onsi/gomega" |
| 25 | + |
| 26 | + apierrors "k8s.io/apimachinery/pkg/api/errors" |
| 27 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 28 | + |
| 29 | + ctlJob "volcano.sh/volcano/pkg/cli/job" |
| 30 | + jobUtil "volcano.sh/volcano/pkg/controllers/job" |
| 31 | +) |
| 32 | + |
| 33 | +var _ = Describe("Job E2E Test: Test Job Command", func() { |
| 34 | + It("List running jobs", func() { |
| 35 | + var outBuffer bytes.Buffer |
| 36 | + jobName := "test-job" |
| 37 | + namespace := "test" |
| 38 | + context := initTestContext() |
| 39 | + defer cleanupTestContext(context) |
| 40 | + rep := clusterSize(context, oneCPU) |
| 41 | + |
| 42 | + job := createJob(context, &jobSpec{ |
| 43 | + namespace: namespace, |
| 44 | + name: jobName, |
| 45 | + tasks: []taskSpec{ |
| 46 | + { |
| 47 | + img: defaultNginxImage, |
| 48 | + req: oneCPU, |
| 49 | + min: rep, |
| 50 | + rep: rep, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }) |
| 54 | + //Pod is running |
| 55 | + err := waitJobReady(context, job) |
| 56 | + Expect(err).NotTo(HaveOccurred()) |
| 57 | + //Job Status is running |
| 58 | + err = waitJobStateReady(context, job) |
| 59 | + Expect(err).NotTo(HaveOccurred()) |
| 60 | + //Command outputs are identical |
| 61 | + outputs := ListJobs(namespace) |
| 62 | + jobs, err := context.vkclient.BatchV1alpha1().Jobs(namespace).List(metav1.ListOptions{}) |
| 63 | + ctlJob.PrintJobs(jobs, &outBuffer) |
| 64 | + Expect(outputs).To(Equal(outBuffer.String()), "List command result should be:\n %s", |
| 65 | + outBuffer.String()) |
| 66 | + }) |
| 67 | + |
| 68 | + It("Suspend running job&Resume aborted job", func() { |
| 69 | + jobName := "test-suspend-running-job" |
| 70 | + taskName := "long-live-task" |
| 71 | + namespace := "test" |
| 72 | + context := initTestContext() |
| 73 | + defer cleanupTestContext(context) |
| 74 | + |
| 75 | + job := createJob(context, &jobSpec{ |
| 76 | + namespace: namespace, |
| 77 | + name: jobName, |
| 78 | + tasks: []taskSpec{ |
| 79 | + { |
| 80 | + name: taskName, |
| 81 | + img: defaultNginxImage, |
| 82 | + min: 1, |
| 83 | + rep: 1, |
| 84 | + }, |
| 85 | + }, |
| 86 | + }) |
| 87 | + //Job is running |
| 88 | + err := waitJobReady(context, job) |
| 89 | + Expect(err).NotTo(HaveOccurred()) |
| 90 | + err = waitJobStateReady(context, job) |
| 91 | + Expect(err).NotTo(HaveOccurred()) |
| 92 | + |
| 93 | + //Suspend job and wait status change |
| 94 | + SuspendJob(jobName, namespace) |
| 95 | + err = waitJobStateAborted(context, job) |
| 96 | + Expect(err).NotTo(HaveOccurred()) |
| 97 | + |
| 98 | + //Pod is gone |
| 99 | + podName := jobUtil.MakePodName(jobName, taskName, 0) |
| 100 | + _, err = context.kubeclient.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{}) |
| 101 | + Expect(apierrors.IsNotFound(err)).To(BeTrue(), |
| 102 | + "Job related pod should be deleted when aborting job.") |
| 103 | + |
| 104 | + //Resume job |
| 105 | + ResumeJob(jobName, namespace) |
| 106 | + |
| 107 | + //Job is running again |
| 108 | + err = waitJobReady(context, job) |
| 109 | + Expect(err).NotTo(HaveOccurred()) |
| 110 | + err = waitJobStateReady(context, job) |
| 111 | + Expect(err).NotTo(HaveOccurred()) |
| 112 | + |
| 113 | + }) |
| 114 | + |
| 115 | + It("Suspend pending job", func() { |
| 116 | + context := initTestContext() |
| 117 | + defer cleanupTestContext(context) |
| 118 | + rep := clusterSize(context, oneCPU) * 2 |
| 119 | + |
| 120 | + jobName := "test-suspend-pending-job" |
| 121 | + namespace := "test" |
| 122 | + taskName := "long-live-task" |
| 123 | + |
| 124 | + job := createJob(context, &jobSpec{ |
| 125 | + namespace: namespace, |
| 126 | + name: jobName, |
| 127 | + tasks: []taskSpec{ |
| 128 | + { |
| 129 | + name: taskName, |
| 130 | + img: defaultNginxImage, |
| 131 | + req: cpuResource(fmt.Sprintf("%dm", 1000*rep)), |
| 132 | + min: 1, |
| 133 | + rep: 1, |
| 134 | + }, |
| 135 | + }, |
| 136 | + }) |
| 137 | + |
| 138 | + //Job is pending |
| 139 | + err := waitJobPending(context, job) |
| 140 | + Expect(err).NotTo(HaveOccurred()) |
| 141 | + err = waitJobStatePending(context, job) |
| 142 | + Expect(err).NotTo(HaveOccurred()) |
| 143 | + |
| 144 | + //Suspend job and wait status change |
| 145 | + SuspendJob(jobName, namespace) |
| 146 | + err = waitJobStateAborted(context, job) |
| 147 | + Expect(err).NotTo(HaveOccurred()) |
| 148 | + |
| 149 | + //Pod is gone |
| 150 | + podName := jobUtil.MakePodName(jobName, taskName, 0) |
| 151 | + _, err = context.kubeclient.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{}) |
| 152 | + Expect(apierrors.IsNotFound(err)).To(BeTrue(), |
| 153 | + "Job related pod should be deleted when job aborted.") |
| 154 | + }) |
| 155 | +}) |
0 commit comments