Functional test to verify VM process stops when virt-launcher crashes
@@ -184,6 +184,34 @@ var _ = Describe("Vmlifecycle", func() {
close(done)
}, 50)
})
+
+ Context("New VM when virt-launcher crashes", func() {
+ It("should stop and be in Failed phase", func(done Done) {
+ obj, err := virtClient.RestClient().Post().Resource("virtualmachines").Namespace(tests.NamespaceTestDefault).Body(vm).Do().Get()
+ Expect(err).To(BeNil())
+
+ nodeName := tests.WaitForSuccessfulVMStart(obj)
+ _, ok := obj.(*v1.VirtualMachine)
+ Expect(ok).To(BeTrue(), "Object is not of type *v1.VM")
+ Expect(err).ToNot(HaveOccurred())
+
+ time.Sleep(10 * time.Second)
+ err = pkillAllLaunchers(virtClient, nodeName, dockerTag)
+ Expect(err).To(BeNil())
+
+ tests.NewObjectEventWatcher(obj).SinceWatchedObjectResourceVersion().WaitFor(tests.WarningEvent, v1.Stopped)
+
+ Expect(func() v1.VMPhase {
+ vm := &v1.VirtualMachine{}
+ err := virtClient.RestClient().Get().Resource("virtualmachines").Namespace(tests.NamespaceTestDefault).Name(obj.(*v1.VirtualMachine).ObjectMeta.Name).Do().Into(vm)
+ Expect(err).ToNot(HaveOccurred())
+ return vm.Status.Phase
+ }()).To(Equal(v1.Failed))
+
+ close(done)
+ }, 50)
+ })
+
Context("in a non-default namespace", func() {
table.DescribeTable("Should log libvirt start and stop lifecycle events of the domain", func(namespace string) {
@@ -237,7 +265,7 @@ var _ = Describe("Vmlifecycle", func() {
})
})
-func renderPkillAllVmsJob(dockerTag string) *k8sv1.Pod {
+func renderPkillAllJob(dockerTag string, processName string) *k8sv1.Pod {
job := k8sv1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "vm-killer",
@@ -254,7 +282,7 @@ func renderPkillAllVmsJob(dockerTag string) *k8sv1.Pod {
Command: []string{
"pkill",
"-9",
- "qemu",
+ processName,
},
SecurityContext: &k8sv1.SecurityContext{
Privileged: newBool(true),
@@ -272,8 +300,16 @@ func renderPkillAllVmsJob(dockerTag string) *k8sv1.Pod {
return &job
}
+func pkillAllLaunchers(virtCli kubecli.KubevirtClient, node, dockerTag string) error {
+ job := renderPkillAllJob(dockerTag, "virt-launcher")
+ job.Spec.NodeName = node
+ _, err := virtCli.CoreV1().Pods(tests.NamespaceTestDefault).Create(job)
+
+ return err
+}
+
func pkillAllVms(virtCli kubecli.KubevirtClient, node, dockerTag string) error {
- job := renderPkillAllVmsJob(dockerTag)
+ job := renderPkillAllJob(dockerTag, "qemu")
job.Spec.NodeName = node
_, err := virtCli.CoreV1().Pods(tests.NamespaceTestDefault).Create(job)
