github.com/Equinix-Metal/virtlet@v1.5.2-0.20210807010419-342346535dc5/tests/e2e/stop_qemu_test.go (about) 1 /* 2 Copyright 2017 Mirantis 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 "fmt" 21 "strings" 22 "time" 23 24 . "github.com/onsi/gomega" 25 26 "github.com/Equinix-Metal/virtlet/tests/e2e/framework" 27 . "github.com/Equinix-Metal/virtlet/tests/e2e/ginkgo-ext" 28 ) 29 30 var _ = Describe("QEMU Process", func() { 31 var ( 32 vm *framework.VMInterface 33 ssh framework.Executor 34 containerId string 35 vmsContainer framework.Executor 36 ) 37 38 BeforeAll(func() { 39 vm = controller.VM("kill-qemu-vm") 40 Expect(vm.CreateAndWait(VMOptions{}.ApplyDefaults(), time.Minute*5, nil)).To(Succeed()) 41 var err error 42 vmPod, err := vm.Pod() 43 Expect(err).NotTo(HaveOccurred()) 44 containerId = vmPod.Pod.Status.ContainerStatuses[0].ContainerID 45 p := strings.LastIndex(containerId, "__") 46 if p >= 0 { 47 containerId = containerId[p+2:] 48 } 49 virtletPod, err := vm.VirtletPod() 50 Expect(err).NotTo(HaveOccurred()) 51 // The container doesn't matter much here because Virtlet pod 52 // uses host PID namespace, but let's use vms because that's 53 // where the VMs live, and we want to look for QEMU processes. 54 // This way this will work even if hostPID is turned off for 55 // Virtlet pod. 56 vmsContainer, err = virtletPod.Container("vms") 57 Expect(err).NotTo(HaveOccurred()) 58 }) 59 60 scheduleWaitSSH(&vm, &ssh) 61 62 It("Must be active while VM is running and gone after it's deleted [Conformance]", func() { 63 qemuRunning := func() bool { 64 _, _, err := framework.Run(vmsContainer, "", 65 "pgrep", "-f", fmt.Sprintf("qemu-system-x86_64.* %s", containerId), 66 ) 67 if ce, ok := err.(framework.CommandError); ok { 68 return ce.ExitCode == 0 69 } 70 Expect(err).NotTo(HaveOccurred()) 71 return true 72 } 73 Expect(qemuRunning()).To(BeTrue()) 74 deleteVM(vm) 75 Expect(qemuRunning()).To(BeFalse()) 76 }) 77 })