forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration_test.go
3664 lines (2970 loc) · 149 KB
/
migration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the KubeVirt project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2018 Red Hat, Inc.
*
*/
package tests_test
import (
"context"
"crypto/tls"
"encoding/json"
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
"sync"
"kubevirt.io/api/migrations/v1alpha1"
"kubevirt.io/kubevirt/tests/framework/cleanup"
"kubevirt.io/kubevirt/pkg/virt-handler/cgroup"
"kubevirt.io/kubevirt/pkg/util/hardware"
"kubevirt.io/kubevirt/pkg/virt-controller/watch"
virtconfig "kubevirt.io/kubevirt/pkg/virt-config"
virthandler "kubevirt.io/kubevirt/pkg/virt-handler"
"kubevirt.io/kubevirt/tests/framework/checks"
"kubevirt.io/kubevirt/tests/util"
"kubevirt.io/kubevirt/tools/vms-generator/utils"
"fmt"
"time"
expect "github.com/google/goexpect"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
k8sv1 "k8s.io/api/core/v1"
"k8s.io/api/policy/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/utils/pointer"
"kubevirt.io/kubevirt/tests/libvmi"
storageframework "kubevirt.io/kubevirt/tests/framework/storage"
"k8s.io/apimachinery/pkg/util/strategicpatch"
. "kubevirt.io/kubevirt/tests/framework/matcher"
"kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/api"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/client-go/log"
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
"kubevirt.io/kubevirt/pkg/certificates/triple"
"kubevirt.io/kubevirt/pkg/certificates/triple/cert"
"kubevirt.io/kubevirt/pkg/util/cluster"
migrations "kubevirt.io/kubevirt/pkg/util/migrations"
"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tests/console"
cd "kubevirt.io/kubevirt/tests/containerdisk"
"kubevirt.io/kubevirt/tests/flags"
"kubevirt.io/kubevirt/tests/libnet"
)
const (
fedoraVMSize = "256M"
secretDiskSerial = "D23YZ9W6WA5DJ487"
stressDefaultVMSize = "100"
stressLargeVMSize = "400"
stressDefaultTimeout = 1600
)
var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system][sig-compute] VM Live Migration", func() {
var virtClient kubecli.KubevirtClient
var err error
BeforeEach(func() {
virtClient, err = kubecli.GetKubevirtClient()
Expect(err).ToNot(HaveOccurred())
})
setMastersUnschedulable := func(mode bool) {
masters, err := virtClient.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{LabelSelector: `node-role.kubernetes.io/master`})
Expect(err).ShouldNot(HaveOccurred(), "could not list master nodes")
Expect(len(masters.Items)).Should(BeNumerically(">=", 1))
for _, node := range masters.Items {
nodeCopy := node.DeepCopy()
nodeCopy.Spec.Unschedulable = mode
oldData, err := json.Marshal(node)
Expect(err).ShouldNot(HaveOccurred())
newData, err := json.Marshal(nodeCopy)
Expect(err).ShouldNot(HaveOccurred())
patch, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, node)
Expect(err).ShouldNot(HaveOccurred())
_, err = virtClient.CoreV1().Nodes().Patch(context.Background(), node.Name, types.StrategicMergePatchType, patch, metav1.PatchOptions{})
Expect(err).ShouldNot(HaveOccurred())
}
}
drainNode := func(node string) {
By(fmt.Sprintf("Draining node %s", node))
// we can't really expect an error during node drain because vms with eviction strategy can be migrated by the
// time that we call it.
vmiSelector := v1.AppLabel + "=virt-launcher"
k8sClient := tests.GetK8sCmdClient()
if k8sClient == "oc" {
tests.RunCommandWithNS("", k8sClient, "adm", "drain", node, "--delete-emptydir-data", "--pod-selector", vmiSelector,
"--ignore-daemonsets=true", "--force", "--timeout=180s")
} else {
tests.RunCommandWithNS("", k8sClient, "drain", node, "--delete-emptydir-data", "--pod-selector", vmiSelector,
"--ignore-daemonsets=true", "--force", "--timeout=180s")
}
}
confirmMigrationMode := func(vmi *v1.VirtualMachineInstance, expectedMode v1.MigrationMode) {
By("Retrieving the VMI post migration")
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
By("Verifying the VMI's migration mode")
Expect(vmi.Status.MigrationState.Mode).To(Equal(expectedMode))
}
getCurrentKv := func() v1.KubeVirtConfiguration {
kvc := util.GetCurrentKv(virtClient)
if kvc.Spec.Configuration.MigrationConfiguration == nil {
kvc.Spec.Configuration.MigrationConfiguration = &v1.MigrationConfiguration{}
}
if kvc.Spec.Configuration.DeveloperConfiguration == nil {
kvc.Spec.Configuration.DeveloperConfiguration = &v1.DeveloperConfiguration{}
}
if kvc.Spec.Configuration.NetworkConfiguration == nil {
kvc.Spec.Configuration.NetworkConfiguration = &v1.NetworkConfiguration{}
}
return kvc.Spec.Configuration
}
BeforeEach(func() {
tests.BeforeTestCleanup()
tests.SkipIfMigrationIsNotPossible()
})
runVMIAndExpectLaunch := func(vmi *v1.VirtualMachineInstance, timeout int) *v1.VirtualMachineInstance {
return tests.RunVMIAndExpectLaunchWithIgnoreWarningArg(vmi, timeout, false)
}
runVMIAndExpectLaunchIgnoreWarnings := func(vmi *v1.VirtualMachineInstance, timeout int) *v1.VirtualMachineInstance {
return tests.RunVMIAndExpectLaunchWithIgnoreWarningArg(vmi, timeout, true)
}
confirmVMIPostMigrationFailed := func(vmi *v1.VirtualMachineInstance, migrationUID string) {
By("Retrieving the VMI post migration")
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
By("Verifying the VMI's migration state")
Expect(vmi.Status.MigrationState).ToNot(BeNil())
Expect(vmi.Status.MigrationState.StartTimestamp).ToNot(BeNil())
Expect(vmi.Status.MigrationState.EndTimestamp).ToNot(BeNil())
Expect(vmi.Status.MigrationState.SourceNode).To(Equal(vmi.Status.NodeName))
Expect(vmi.Status.MigrationState.TargetNode).ToNot(Equal(vmi.Status.MigrationState.SourceNode))
Expect(vmi.Status.MigrationState.Completed).To(BeTrue())
Expect(vmi.Status.MigrationState.Failed).To(BeTrue())
Expect(vmi.Status.MigrationState.TargetNodeAddress).ToNot(Equal(""))
Expect(string(vmi.Status.MigrationState.MigrationUID)).To(Equal(migrationUID))
By("Verifying the VMI's is in the running state")
Expect(vmi.Status.Phase).To(Equal(v1.Running))
}
confirmVMIPostMigrationAborted := func(vmi *v1.VirtualMachineInstance, migrationUID string, timeout int) *v1.VirtualMachineInstance {
By("Waiting until the migration is completed")
Eventually(func() bool {
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
if vmi.Status.MigrationState != nil && vmi.Status.MigrationState.Completed &&
vmi.Status.MigrationState.AbortStatus == v1.MigrationAbortSucceeded {
return true
}
return false
}, timeout, 1*time.Second).Should(BeTrue())
By("Retrieving the VMI post migration")
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
By("Verifying the VMI's migration state")
Expect(vmi.Status.MigrationState).ToNot(BeNil())
Expect(vmi.Status.MigrationState.StartTimestamp).ToNot(BeNil())
Expect(vmi.Status.MigrationState.EndTimestamp).ToNot(BeNil())
Expect(vmi.Status.MigrationState.SourceNode).To(Equal(vmi.Status.NodeName))
Expect(vmi.Status.MigrationState.TargetNode).ToNot(Equal(vmi.Status.MigrationState.SourceNode))
Expect(vmi.Status.MigrationState.TargetNodeAddress).ToNot(Equal(""))
Expect(string(vmi.Status.MigrationState.MigrationUID)).To(Equal(migrationUID))
Expect(vmi.Status.MigrationState.Failed).To(BeTrue())
Expect(vmi.Status.MigrationState.AbortRequested).To(BeTrue())
By("Verifying the VMI's is in the running state")
Expect(vmi.Status.Phase).To(Equal(v1.Running))
return vmi
}
cancelMigration := func(migration *v1.VirtualMachineInstanceMigration, vminame string, with_virtctl bool) {
if !with_virtctl {
By("Cancelling a Migration")
Expect(virtClient.VirtualMachineInstanceMigration(migration.Namespace).Delete(migration.Name, &metav1.DeleteOptions{})).To(Succeed(), "Migration should be deleted successfully")
} else {
By("Cancelling a Migration with virtctl")
command := tests.NewRepeatableVirtctlCommand("migrate-cancel", "--namespace", migration.Namespace, vminame)
Expect(command()).To(Succeed(), "should successfully migrate-cancel a migration")
}
}
runAndCancelMigration := func(migration *v1.VirtualMachineInstanceMigration, vmi *v1.VirtualMachineInstance, with_virtctl bool, timeout int) *v1.VirtualMachineInstanceMigration {
By("Starting a Migration")
Eventually(func() error {
migration, err = virtClient.VirtualMachineInstanceMigration(migration.Namespace).Create(migration, &metav1.CreateOptions{})
return err
}, timeout, 1*time.Second).ShouldNot(HaveOccurred())
By("Waiting until the Migration is Running")
Eventually(func() bool {
migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(migration.Status.Phase).ToNot(Equal(v1.MigrationFailed))
if migration.Status.Phase == v1.MigrationRunning {
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
if vmi.Status.MigrationState.Completed != true {
return true
}
}
return false
}, timeout, 1*time.Second).Should(BeTrue())
cancelMigration(migration, vmi.Name, with_virtctl)
return migration
}
runAndImmediatelyCancelMigration := func(migration *v1.VirtualMachineInstanceMigration, vmi *v1.VirtualMachineInstance, with_virtctl bool, timeout int) *v1.VirtualMachineInstanceMigration {
By("Starting a Migration")
Eventually(func() error {
migration, err = virtClient.VirtualMachineInstanceMigration(migration.Namespace).Create(migration, &metav1.CreateOptions{})
return err
}, timeout, 1*time.Second).ShouldNot(HaveOccurred())
By("Waiting until the Migration is Running")
Eventually(func() bool {
migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return string(migration.UID) != ""
}, timeout, 1*time.Second).Should(BeTrue())
cancelMigration(migration, vmi.Name, with_virtctl)
return migration
}
runMigrationAndExpectFailure := func(migration *v1.VirtualMachineInstanceMigration, timeout int) string {
By("Starting a Migration")
Eventually(func() error {
migration, err = virtClient.VirtualMachineInstanceMigration(migration.Namespace).Create(migration, &metav1.CreateOptions{})
return err
}, timeout, 1*time.Second).ShouldNot(HaveOccurred())
By("Waiting until the Migration Completes")
uid := ""
Eventually(func() v1.VirtualMachineInstanceMigrationPhase {
migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
phase := migration.Status.Phase
Expect(phase).NotTo(Equal(v1.MigrationSucceeded))
uid = string(migration.UID)
return phase
}, timeout, 1*time.Second).Should(Equal(v1.MigrationFailed))
return uid
}
runStressTest := func(vmi *v1.VirtualMachineInstance, vmsize string, stressTimeoutSeconds int) {
By("Run a stress test to dirty some pages and slow down the migration")
stressCmd := fmt.Sprintf("stress-ng --vm 1 --vm-bytes %sM --vm-keep --timeout %ds&\n", vmsize, stressTimeoutSeconds)
Expect(console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: console.PromptExpression},
&expect.BSnd{S: stressCmd},
&expect.BExp{R: console.PromptExpression},
}, 15)).To(Succeed(), "should run a stress test")
// give stress tool some time to trash more memory pages before returning control to next steps
if stressTimeoutSeconds < 15 {
time.Sleep(time.Duration(stressTimeoutSeconds) * time.Second)
} else {
time.Sleep(15 * time.Second)
}
}
getLibvirtdPid := func(pod *k8sv1.Pod) string {
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, pod, "compute",
[]string{
"pidof",
"libvirtd",
})
errorMassageFormat := "faild after running `pidof libvirtd` with stdout:\n %v \n stderr:\n %v \n err: \n %v \n"
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(errorMassageFormat, stdout, stderr, err))
pid := strings.TrimSuffix(stdout, "\n")
return pid
}
setMigrationBandwidthLimitation := func(migrationBandwidth resource.Quantity) {
cfg := getCurrentKv()
cfg.MigrationConfiguration.BandwidthPerMigration = &migrationBandwidth
tests.UpdateKubeVirtConfigValueAndWait(cfg)
}
Describe("Starting a VirtualMachineInstance ", func() {
var pvName string
var memoryRequestSize resource.Quantity
BeforeEach(func() {
memoryRequestSize = resource.MustParse(fedoraVMSize)
pvName = "test-nfs" + rand.String(48)
})
guestAgentMigrationTestFunc := func(mode v1.MigrationMode) {
By("Creating the VMI")
vmi := tests.NewRandomVMIWithPVC(pvName)
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = memoryRequestSize
vmi.Spec.Domain.Devices.Rng = &v1.Rng{}
// add userdata for guest agent and service account mount
mountSvcAccCommands := fmt.Sprintf(`#!/bin/bash
mkdir /mnt/servacc
mount /dev/$(lsblk --nodeps -no name,serial | grep %s | cut -f1 -d' ') /mnt/servacc
`, secretDiskSerial)
tests.AddUserData(vmi, "cloud-init", mountSvcAccCommands)
tests.AddServiceAccountDisk(vmi, "default")
disks := vmi.Spec.Domain.Devices.Disks
disks[len(disks)-1].Serial = secretDiskSerial
vmi = runVMIAndExpectLaunchIgnoreWarnings(vmi, 180)
// Wait for cloud init to finish and start the agent inside the vmi.
tests.WaitAgentConnected(virtClient, vmi)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToFedora)(vmi)).To(Succeed(), "Should be able to login to the Fedora VM")
if mode == v1.MigrationPostCopy {
By("Running stress test to allow transition to post-copy")
runStressTest(vmi, stressLargeVMSize, stressDefaultTimeout)
}
// execute a migration, wait for finalized state
By("Starting the Migration for iteration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
By("Checking VMI, confirm migration state")
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
confirmMigrationMode(vmi, mode)
By("Is agent connected after migration")
tests.WaitAgentConnected(virtClient, vmi)
By("Checking that the migrated VirtualMachineInstance console has expected output")
Expect(console.OnPrivilegedPrompt(vmi, 60)).To(BeTrue(), "Should stay logged in to the migrated VM")
By("Checking that the service account is mounted")
Expect(console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "cat /mnt/servacc/namespace\n"},
&expect.BExp{R: util.NamespaceTestDefault},
}, 30)).To(Succeed(), "Should be able to access the mounted service account file")
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 120)
}
Context("with a bridge network interface", func() {
It("[test_id:3226]should reject a migration of a vmi with a bridge interface", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Devices.Interfaces = []v1.Interface{
{
Name: "default",
InterfaceBindingMethod: v1.InterfaceBindingMethod{
Bridge: &v1.InterfaceBridge{},
},
},
}
vmi = runVMIAndExpectLaunch(vmi, 240)
// Verify console on last iteration to verify the VirtualMachineInstance is still booting properly
// after being restarted multiple times
By("Checking that the VirtualMachineInstance console has expected output")
Expect(console.LoginToAlpine(vmi)).To(Succeed())
gotExpectedCondition := false
for _, c := range vmi.Status.Conditions {
if c.Type == v1.VirtualMachineInstanceIsMigratable {
Expect(c.Status).To(Equal(k8sv1.ConditionFalse))
gotExpectedCondition = true
}
}
Expect(gotExpectedCondition).Should(BeTrue())
// execute a migration, wait for finalized state
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
By("Starting a Migration")
migration, err = virtClient.VirtualMachineInstanceMigration(migration.Namespace).Create(migration, &metav1.CreateOptions{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("InterfaceNotLiveMigratable"))
// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 120)
})
})
Context("[Serial] with bandwidth limitations", func() {
var repeatedlyMigrateWithBandwidthLimitation = func(vmi *v1.VirtualMachineInstance, bandwidth string, repeat int) time.Duration {
var migrationDurationTotal time.Duration
config := getCurrentKv()
limit := resource.MustParse(bandwidth)
config.MigrationConfiguration.BandwidthPerMigration = &limit
tests.UpdateKubeVirtConfigValueAndWait(config)
for x := 0; x < repeat; x++ {
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
vmi, err := virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
migrationDuration := vmi.Status.MigrationState.EndTimestamp.Sub(vmi.Status.MigrationState.StartTimestamp.Time)
log.DefaultLogger().Infof("Migration with bandwidth %v took: %v", bandwidth, migrationDuration)
migrationDurationTotal += migrationDuration
}
return migrationDurationTotal
}
It("[test_id:6968]should apply them and result in different migration durations", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
durationLowBandwidth := repeatedlyMigrateWithBandwidthLimitation(vmi, "10Mi", 3)
durationHighBandwidth := repeatedlyMigrateWithBandwidthLimitation(vmi, "128Mi", 3)
Expect(durationHighBandwidth.Seconds() * 2).To(BeNumerically("<", durationLowBandwidth.Seconds()))
})
})
Context("with a Cirros disk", func() {
It("[test_id:6969]should be successfully migrate with a tablet device", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
vmi.Spec.Domain.Devices.Inputs = []v1.Input{
{
Name: "tablet0",
Type: "tablet",
Bus: "usb",
},
}
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})
It("should be successfully migrate with a WriteBack disk cache", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
vmi.Spec.Domain.Devices.Disks[0].Cache = v1.CacheWriteBack
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
runningVMISpec, err := tests.GetRunningVMIDomainSpec(vmi)
Expect(err).ToNot(HaveOccurred())
disks := runningVMISpec.Devices.Disks
By("checking if requested cache 'writeback' has been set")
Expect(disks[0].Alias.GetName()).To(Equal("disk0"))
Expect(disks[0].Driver.Cache).To(Equal(string(v1.CacheWriteBack)))
// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})
It("[test_id:6970]should migrate vmi with cdroms on various bus types", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddEphemeralCdrom(vmi, "cdrom-0", "sata", cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddEphemeralCdrom(vmi, "cdrom-1", "scsi", cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
// execute a migration, wait for finalized state
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
})
It("should migrate vmi and use Live Migration method with read-only disks", func() {
By("Defining a VMI with PVC disk and read-only CDRoms")
vmi, _ := tests.NewRandomVirtualMachineInstanceWithBlockDisk(cd.DataVolumeImportUrlForContainerDisk(cd.ContainerDiskCirros), util.NamespaceTestDefault, k8sv1.ReadWriteMany)
vmi.Spec.Hostname = string(cd.ContainerDiskCirros)
tests.AddEphemeralCdrom(vmi, "cdrom-0", "sata", cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddEphemeralCdrom(vmi, "cdrom-1", "scsi", cd.ContainerDiskFor(cd.ContainerDiskCirros))
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
// execute a migration, wait for finalized state
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
By("Ensuring migration is using Live Migration method")
Eventually(func() v1.VirtualMachineInstanceMigrationMethod {
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())
return vmi.Status.MigrationMethod
}, 20*time.Second, 1*time.Second).Should(Equal(v1.LiveMigration), "migration method is expected to be Live Migration")
})
It("[test_id:6971]should migrate with a downwardMetrics disk", func() {
vmi := libvmi.NewTestToolingFedora(
libvmi.WithInterface(libvmi.InterfaceDeviceWithMasqueradeBinding()),
libvmi.WithNetwork(v1.DefaultPodNetwork()),
)
tests.AddDownwardMetricsVolume(vmi, "vhostmd")
vmi = tests.RunVMIAndExpectLaunch(vmi, 180)
Expect(console.LoginToFedora(vmi)).To(Succeed())
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
By("checking if the metrics are still updated after the migration")
Eventually(func() error {
_, err := getDownwardMetrics(vmi)
return err
}, 20*time.Second, 1*time.Second).ShouldNot(HaveOccurred())
metrics, err := getDownwardMetrics(vmi)
Expect(err).ToNot(HaveOccurred())
timestamp := getTimeFromMetrics(metrics)
Eventually(func() int {
metrics, err := getDownwardMetrics(vmi)
Expect(err).ToNot(HaveOccurred())
return getTimeFromMetrics(metrics)
}, 10*time.Second, 1*time.Second).ShouldNot(Equal(timestamp))
By("checking that the new nodename is reflected in the downward metrics")
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(getHostnameFromMetrics(metrics)).To(Equal(vmi.Status.NodeName))
})
It("[test_id:6842]should migrate with TSC frequency set", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
vmi.Spec.Domain.CPU = &v1.CPU{
Features: []v1.CPUFeature{
{
Name: "invtsc",
Policy: "require",
},
},
}
// only with this strategy will the frequency be set
strategy := v1.EvictionStrategyLiveMigrate
vmi.Spec.EvictionStrategy = &strategy
vmi = tests.RunVMIAndExpectLaunch(vmi, 180)
Expect(console.LoginToCirros(vmi)).To(Succeed())
By("Checking the TSC frequency on the Domain XML")
domainSpec, err := tests.GetRunningVMIDomainSpec(vmi)
Expect(err).ToNot(HaveOccurred())
timerFrequency := ""
for _, timer := range domainSpec.Clock.Timer {
if timer.Name == "tsc" {
timerFrequency = timer.Frequency
}
}
Expect(timerFrequency).ToNot(BeEmpty())
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
By("Checking the TSC frequency on the Domain XML on the new node")
domainSpec, err = tests.GetRunningVMIDomainSpec(vmi)
Expect(err).ToNot(HaveOccurred())
timerFrequency = ""
for _, timer := range domainSpec.Clock.Timer {
if timer.Name == "tsc" {
timerFrequency = timer.Frequency
}
}
Expect(timerFrequency).ToNot(BeEmpty())
})
It("[test_id:4113]should be successfully migrate with cloud-init disk with devices on the root bus", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
vmi.Annotations = map[string]string{
v1.PlacePCIDevicesOnRootComplex: "true",
}
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
// execute a migration, wait for finalized state
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
By("checking that we really migrated a VMI with only the root bus")
domSpec, err := tests.GetRunningVMIDomainSpec(vmi)
Expect(err).ToNot(HaveOccurred())
rootPortController := []api.Controller{}
for _, c := range domSpec.Devices.Controllers {
if c.Model == "pcie-root-port" {
rootPortController = append(rootPortController, c)
}
}
Expect(rootPortController).To(HaveLen(0), "libvirt should not add additional buses to the root one")
// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})
It("[test_id:1783]should be successfully migrated multiple times with cloud-init disk", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
num := 4
for i := 0; i < num; i++ {
// execute a migration, wait for finalized state
By(fmt.Sprintf("Starting the Migration for iteration %d", i))
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
By("Check if Migrated VMI has updated IP and IPs fields")
Eventually(func() error {
newvmi, err := virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred(), "Should successfully get new VMI")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(newvmi, newvmi.Namespace)
return libnet.ValidateVMIandPodIPMatch(newvmi, vmiPod)
}, 180*time.Second, time.Second).Should(Succeed(), "Should have updated IP and IPs fields")
}
// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})
// We had a bug that prevent migrations and graceful shutdown when the libvirt connection
// is reset. This can occur for many reasons, one easy way to trigger it is to
// force libvirtd down, which will result in virt-launcher respawning it.
// Previously, we'd stop getting events after libvirt reconnect, which
// prevented things like migration. This test verifies we can migrate after
// resetting libvirt
It("[test_id:4746]should migrate even if libvirt has restarted at some point.", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
pods, err := virtClient.CoreV1().Pods(vmi.Namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: v1.CreatedByLabel + "=" + string(vmi.GetUID()),
})
Expect(err).ToNot(HaveOccurred(), "Should list pods successfully")
Expect(pods.Items).To(HaveLen(1), "There should be only one VMI pod")
// find libvirtd pid
pid := getLibvirtdPid(&pods.Items[0])
// kill libvirtd
By(fmt.Sprintf("Killing libvirtd with pid %s", pid))
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, &pods.Items[0], "compute",
[]string{
"kill",
"-9",
pid,
})
errorMassageFormat := "failed after running `kill -9 %v` with stdout:\n %v \n stderr:\n %v \n err: \n %v \n"
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(errorMassageFormat, pid, stdout, stderr, err))
// wait for both libvirt to respawn and all connections to re-establish
time.Sleep(30 * time.Second)
// ensure new pid comes online
newPid := getLibvirtdPid(&pods.Items[0])
Expect(pid).ToNot(Equal(newPid), fmt.Sprintf("expected libvirtd to be cycled. original pid %s new pid %s", pid, newPid))
// execute a migration, wait for finalized state
By(fmt.Sprintf("Starting the Migration"))
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})
It("[test_id:6972]should migrate to a persistent (non-transient) libvirt domain.", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
// execute a migration, wait for finalized state
By(fmt.Sprintf("Starting the Migration"))
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
// ensure the libvirt domain is persistent
persistent, err := tests.LibvirtDomainIsPersistent(virtClient, vmi)
Expect(err).ToNot(HaveOccurred(), "Should list libvirt domains successfully")
Expect(persistent).To(BeTrue(), "The VMI was not found in the list of libvirt persistent domains")
tests.EnsureNoMigrationMetadataInPersistentXML(vmi)
// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})
It("[test_id:6973]should be able to successfully migrate with a paused vmi", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskCirros))
tests.AddUserData(vmi, "cloud-init", "#!/bin/bash\necho 'hello'\n")
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
By("Checking that the VirtualMachineInstance console has expected output")
Expect(libnet.WithIPv6(console.LoginToCirros)(vmi)).To(Succeed())
By("Pausing the VirtualMachineInstance")
virtClient.VirtualMachineInstance(vmi.Namespace).Pause(vmi.Name, &v1.PauseOptions{})
tests.WaitForVMICondition(virtClient, vmi, v1.VirtualMachineInstancePaused, 30)
By("verifying that the vmi is still paused before migration")
isPausedb, err := tests.LibvirtDomainIsPaused(virtClient, vmi)
Expect(err).ToNot(HaveOccurred(), "Should get domain state successfully")
Expect(isPausedb).To(BeTrue(), "The VMI should be paused before migration, but it is not.")
By("starting the migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)
// check VMI, confirm migration state
tests.ConfirmVMIPostMigration(virtClient, vmi, migrationUID)
By("verifying that the vmi is still paused after migration")
isPaused, err := tests.LibvirtDomainIsPaused(virtClient, vmi)
Expect(err).ToNot(HaveOccurred(), "Should get domain state successfully")
Expect(isPaused).To(BeTrue(), "The VMI should be paused after migration, but it is not.")
By("verify that VMI can be unpaused after migration")
command := tests.NewRepeatableVirtctlCommand("unpause", "vmi", "--namespace", util.NamespaceTestDefault, vmi.Name)
Expect(command()).To(Succeed(), "should successfully unpause tthe vmi")
tests.WaitForVMIConditionRemovedOrFalse(virtClient, vmi, v1.VirtualMachineInstancePaused, 30)
By("verifying that the vmi is running")
isPaused, err = tests.LibvirtDomainIsPaused(virtClient, vmi)
Expect(err).ToNot(HaveOccurred(), "Should get domain state successfully")
Expect(isPaused).To(BeFalse(), "The VMI should be running, but it is not.")
})
})
Context("with an pending target pod", func() {
var nodes *k8sv1.NodeList
BeforeEach(func() {
tests.BeforeTestCleanup()
Eventually(func() []k8sv1.Node {
nodes = util.GetAllSchedulableNodes(virtClient)
return nodes.Items
}, 60*time.Second, 1*time.Second).ShouldNot(BeEmpty(), "There should be some compute node")
})
It("should automatically cancel unschedulable migration after a timeout period", func() {
vmi := tests.NewRandomFedoraVMIWithGuestAgent()
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse(fedoraVMSize)
// Add node affinity to ensure VMI affinity rules block target pod from being created
addNodeAffinityToVMI(vmi, nodes.Items[0].Name)
By("Starting the VirtualMachineInstance")
vmi = runVMIAndExpectLaunch(vmi, 240)
// execute a migration that is expected to fail
By("Starting the Migration")
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migration.Annotations = map[string]string{v1.MigrationUnschedulablePodTimeoutSecondsAnnotation: "130"}
var err error
Eventually(func() error {
migration, err = virtClient.VirtualMachineInstanceMigration(migration.Namespace).Create(migration, &metav1.CreateOptions{})
return err
}, 5, 1*time.Second).Should(Succeed(), "migration creation should succeed")
By("Should receive warning event that target pod is currently unschedulable")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
tests.
NewObjectEventWatcher(migration).
Timeout(60*time.Second).
SinceWatchedObjectResourceVersion().
WaitFor(ctx, tests.WarningEvent, "migrationTargetPodUnschedulable")
By("Migration should observe a timeout period before canceling unschedulable target pod")
Consistently(func() error {
migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
if err != nil {
return err
}
if migration.Status.Phase == v1.MigrationFailed {
return fmt.Errorf("Migration should observe timeout period before transitioning to failed state")
}
return nil
}, 1*time.Minute, 10*time.Second).Should(Succeed())
By("Migration should fail eventually due to pending target pod timeout")
Eventually(func() error {
migration, err := virtClient.VirtualMachineInstanceMigration(migration.Namespace).Get(migration.Name, &metav1.GetOptions{})
if err != nil {
return err
}
if migration.Status.Phase != v1.MigrationFailed {
return fmt.Errorf("Waiting on migration with phase %s to reach phase Failed", migration.Status.Phase)
}
return nil
}, 2*time.Minute, 5*time.Second).Should(Succeed(), "migration creation should fail")
// delete VMI
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(vmi.Namespace).Delete(vmi.Name, &metav1.DeleteOptions{})).To(Succeed())
By("Waiting for VMI to disappear")
tests.WaitForVirtualMachineToDisappearWithTimeout(vmi, 240)
})
It("should automatically cancel pending target pod after a catch all timeout period", func() {
vmi := tests.NewRandomFedoraVMIWithGuestAgent()
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse(fedoraVMSize)