Unit test to veriy migration target is cleaned when VMI is deleted
@@ -1080,6 +1080,53 @@ var _ = Describe("VirtualMachineInstance", func() {
controller.Execute()
}, 3)
+ It("should abort target prep if VMI is deleted", func() {
+ vmi := v1.NewMinimalVMI("testvmi")
+ vmi.UID = vmiTestUUID
+ vmi.ObjectMeta.ResourceVersion = "1"
+ vmi.Status.Phase = v1.Running
+ vmi.Labels = make(map[string]string)
+ vmi.Status.NodeName = "othernode"
+ vmi.Labels[v1.MigrationTargetNodeNameLabel] = host
+ vmi.Status.MigrationState = &v1.VirtualMachineInstanceMigrationState{
+ TargetNode: host,
+ SourceNode: "othernode",
+ MigrationUID: "123",
+ }
+ now := metav1.Time{Time: time.Now()}
+ vmi.DeletionTimestamp = &now
+ vmi = addActivePods(vmi, podTestUUID, host)
+
+ mockWatchdog.CreateFile(vmi)
+ vmiFeeder.Add(vmi)
+
+ // something has to be listening to the cmd socket
+ // for the proxy to work.
+ os.MkdirAll(cmdclient.SocketDirectoryOnHost(string(podTestUUID)), os.ModePerm)
+
+ socketFile := cmdclient.SocketFilePathOnHost(string(podTestUUID))
+ os.RemoveAll(socketFile)
+ socket, err := net.Listen("unix", socketFile)
+ Expect(err).NotTo(HaveOccurred())
+ defer socket.Close()
+
+ // since a random port is generated, we have to create the proxy
+ // here in order to know what port will be in the update.
+ err = controller.handleMigrationProxy(vmi)
+ Expect(err).NotTo(HaveOccurred())
+ err = controller.handlePostSyncMigrationProxy(vmi)
+ Expect(err).NotTo(HaveOccurred())
+
+ destSrcPorts := controller.migrationProxy.GetTargetListenerPorts(string(vmi.UID))
+ fmt.Println("destSrcPorts: ", destSrcPorts)
+ updatedVmi := vmi.DeepCopy()
+ updatedVmi.Status.MigrationState.TargetNodeAddress = controller.ipAddress
+ updatedVmi.Status.MigrationState.TargetDirectMigrationNodePorts = destSrcPorts
+
+ client.EXPECT().Close()
+ controller.Execute()
+ }, 3)
+
// handles case where a failed migration to this node has left overs still on local storage
It("should clean stale clients when preparing migration target", func() {
vmi := v1.NewMinimalVMI("testvmi")
