additional virt-handler unit tests
@@ -102,7 +102,8 @@ var _ = Describe("VM", func() {
shareDir,
vmInformer,
domainInformer,
- gracefulShutdownInformer)
+ gracefulShutdownInformer,
+ 1)
client = cmdclient.NewMockLauncherClient(ctrl)
sockFile := cmdclient.SocketFromNamespaceName(shareDir, "default", "testvm")
@@ -283,14 +284,39 @@ var _ = Describe("VM", func() {
controller.Execute()
})
- It("should detect a missing watchdog file and report the error on the VM", func() {
+ It("should move VM from Scheduled to Failed if watchdog file is missing", func() {
vm := v1.NewMinimalVM("testvm")
vm.ObjectMeta.ResourceVersion = "1"
vm.Status.Phase = v1.Scheduled
vmFeeder.Add(vm)
vmInterface.EXPECT().Update(gomock.Any()).Do(func(vm *v1.VirtualMachine) {
- Expect(vm.Status.Conditions).To(HaveLen(1))
+ Expect(vm.Status.Phase).To(Equal(v1.Failed))
+ })
+ controller.Execute()
+ })
+ It("should move VM from Scheduled to Failed if watchdog file is expired", func() {
+ vm := v1.NewMinimalVM("testvm")
+ vm.ObjectMeta.ResourceVersion = "1"
+ vm.Status.Phase = v1.Scheduled
+
+ mockWatchdog.CreateFile(vm)
+ vmFeeder.Add(vm)
+ vmInterface.EXPECT().Update(gomock.Any()).Do(func(vm *v1.VirtualMachine) {
+ Expect(vm.Status.Phase).To(Equal(v1.Failed))
+ })
+ time.Sleep(1500 * time.Millisecond)
+ controller.Execute()
+ }, 2)
+
+ It("should move VM from Running to Failed if domain does not exist in cache", func() {
+ vm := v1.NewMinimalVM("testvm")
+ vm.ObjectMeta.ResourceVersion = "1"
+ vm.Status.Phase = v1.Running
+
+ vmFeeder.Add(vm)
+ vmInterface.EXPECT().Update(gomock.Any()).Do(func(vm *v1.VirtualMachine) {
+ Expect(vm.Status.Phase).To(Equal(v1.Failed))
})
controller.Execute()
})
