forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vmi_configuration_test.go
2519 lines (2138 loc) · 100 KB
/
vmi_configuration_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 2017 Red Hat, Inc.
*
*/
package tests_test
import (
"encoding/json"
"fmt"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
expect "github.com/google/goexpect"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
kubev1 "k8s.io/api/core/v1"
"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"
"kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/api"
v1 "kubevirt.io/client-go/api/v1"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/client-go/log"
cmdv1 "kubevirt.io/kubevirt/pkg/handler-launcher-com/cmd/v1"
kubevirt_hooks_v1alpha2 "kubevirt.io/kubevirt/pkg/hooks/v1alpha2"
hw_utils "kubevirt.io/kubevirt/pkg/util/hardware"
virtconfig "kubevirt.io/kubevirt/pkg/virt-config"
"kubevirt.io/kubevirt/tests"
cd "kubevirt.io/kubevirt/tests/containerdisk"
"kubevirt.io/kubevirt/tests/flags"
)
var _ = Describe("Configurations", func() {
var err error
var virtClient kubecli.KubevirtClient
BeforeEach(func() {
virtClient, err = kubecli.GetKubevirtClient()
tests.PanicOnError(err)
tests.BeforeTestCleanup()
})
Context("with all devices on the root PCI bus", func() {
It("should start run the guest as usual", func() {
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(cd.ContainerDiskFor(cd.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
vmi.Annotations = map[string]string{
v1.PlacePCIDevicesOnRootComplex: "true",
}
vmi.Spec.Domain.Devices.Rng = &v1.Rng{}
vmi.Spec.Domain.Devices.Inputs = []v1.Input{{Name: "tablet", Bus: "virtio", Type: "tablet"}, {Name: "tablet1", Bus: "usb", Type: "tablet"}}
vmi.Spec.Domain.Devices.Watchdog = &v1.Watchdog{Name: "watchdog", WatchdogDevice: v1.WatchdogDevice{I6300ESB: &v1.I6300ESBWatchdog{Action: v1.WatchdogActionPoweroff}}}
vmi = tests.RunVMIAndExpectLaunch(vmi, 60)
expecter, err := tests.LoggedInCirrosExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
domSpec, err := tests.GetRunningVMIDomainSpec(vmi)
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")
})
})
Context("[rfe_id:897][crit:medium][vendor:[email protected]][level:component]for CPU and memory limits should", func() {
It("[test_id:3110]lead to get the burstable QOS class assigned when limit and requests differ", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi = tests.RunVMIAndExpectScheduling(vmi, 60)
Eventually(func() kubev1.PodQOSClass {
vmi, err := virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(vmi.IsFinal()).To(BeFalse())
if vmi.Status.QOSClass == nil {
return ""
}
return *vmi.Status.QOSClass
}, 10*time.Second, 1*time.Second).Should(Equal(kubev1.PodQOSBurstable))
})
It("[test_id:3111]lead to get the guaranteed QOS class assigned when limit and requests are identical", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
By("specifying identical limits and requests")
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("1"),
kubev1.ResourceMemory: resource.MustParse("64M"),
},
Limits: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("1"),
kubev1.ResourceMemory: resource.MustParse("64M"),
},
}
By("adding a sidecar to ensure it gets limits assigned too")
vmi.ObjectMeta.Annotations = RenderSidecar(kubevirt_hooks_v1alpha2.Version)
vmi = tests.RunVMIAndExpectScheduling(vmi, 60)
Eventually(func() kubev1.PodQOSClass {
vmi, err := virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(vmi.IsFinal()).To(BeFalse())
if vmi.Status.QOSClass == nil {
return ""
}
return *vmi.Status.QOSClass
}, 10*time.Second, 1*time.Second).Should(Equal(kubev1.PodQOSGuaranteed))
})
It("[test_id:3112]lead to get the guaranteed QOS class assigned when only limits are set", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
By("specifying identical limits and requests")
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{},
Limits: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("1"),
kubev1.ResourceMemory: resource.MustParse("64M"),
},
}
By("adding a sidecar to ensure it gets limits assigned too")
vmi.ObjectMeta.Annotations = RenderSidecar(kubevirt_hooks_v1alpha2.Version)
vmi = tests.RunVMIAndExpectScheduling(vmi, 60)
Eventually(func() kubev1.PodQOSClass {
vmi, err := virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(vmi.IsFinal()).To(BeFalse())
if vmi.Status.QOSClass == nil {
return ""
}
return *vmi.Status.QOSClass
}, 10*time.Second, 1*time.Second).Should(Equal(kubev1.PodQOSGuaranteed))
vmi, err = virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(vmi.Spec.Domain.Resources.Requests.Cpu().Cmp(*vmi.Spec.Domain.Resources.Limits.Cpu())).To(BeZero())
Expect(vmi.Spec.Domain.Resources.Requests.Memory().Cmp(*vmi.Spec.Domain.Resources.Limits.Memory())).To(BeZero())
})
})
Describe("VirtualMachineInstance definition", func() {
Context("[rfe_id:2065][crit:medium][vendor:[email protected]][level:component]with 3 CPU cores", func() {
var availableNumberOfCPUs int
var vmi *v1.VirtualMachineInstance
tests.BeforeAll(func() {
availableNumberOfCPUs = tests.GetHighestCPUNumberAmongNodes(virtClient)
})
BeforeEach(func() {
requiredNumberOfCpus := 3
Expect(availableNumberOfCPUs).ToNot(BeNumerically("<", requiredNumberOfCpus),
fmt.Sprintf("Test requires %d cpus, but only %d available!", requiredNumberOfCpus, availableNumberOfCPUs))
vmi = tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
})
It("[test_id:1659]should report 3 cpu cores under guest OS", func() {
vmi.Spec.Domain.CPU = &v1.CPU{
Cores: 3,
}
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should start console")
defer expecter.Close()
By("Checking the number of CPU cores under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "grep -c ^processor /proc/cpuinfo\n"},
&expect.BExp{R: "3"},
}, 15*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report number of cores")
By("Checking the requested amount of memory allocated for a guest")
Expect(vmi.Spec.Domain.Resources.Requests.Memory().String()).To(Equal("64M"))
readyPod := tests.GetRunningPodByVirtualMachineInstance(vmi, tests.NamespaceTestDefault)
var computeContainer *kubev1.Container
for _, container := range readyPod.Spec.Containers {
if container.Name == "compute" {
computeContainer = &container
break
}
}
if computeContainer == nil {
tests.PanicOnError(fmt.Errorf("could not find the compute container"))
}
Expect(computeContainer.Resources.Requests.Memory().ToDec().ScaledValue(resource.Mega)).To(Equal(int64(243)))
Expect(err).ToNot(HaveOccurred())
})
It("should set a correct memory units", func() {
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("512Mi"),
},
}
expectedMemoryInKiB := 512 * 1024
expectedMemoryXMLStr := fmt.Sprintf("unit='KiB'>%d", expectedMemoryInKiB)
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).To(ContainSubstring(expectedMemoryXMLStr))
})
It("[test_id:1660]should report 3 sockets under guest OS", func() {
vmi.Spec.Domain.CPU = &v1.CPU{
Sockets: 3,
Cores: 2,
}
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should start console")
defer expecter.Close()
By("Checking the number of sockets under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "grep '^physical id' /proc/cpuinfo | uniq | wc -l\n"},
&expect.BExp{R: "3"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report number of sockets")
})
It("[test_id:1661]should report 2 sockets from spec.domain.resources.requests under guest OS ", func() {
vmi.Spec.Domain.CPU = nil
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("1200m"),
kubev1.ResourceMemory: resource.MustParse("64M"),
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should start console")
defer expecter.Close()
By("Checking the number of sockets under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "grep '^physical id' /proc/cpuinfo | uniq | wc -l\n"},
&expect.BExp{R: "2"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report number of sockets")
})
It("[test_id:1662]should report 2 sockets from spec.domain.resources.limits under guest OS ", func() {
vmi.Spec.Domain.CPU = nil
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
},
Limits: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("1200m"),
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should start console")
defer expecter.Close()
By("Checking the number of sockets under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "grep '^physical id' /proc/cpuinfo | uniq | wc -l\n"},
&expect.BExp{R: "2"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report number of sockets")
})
It("[test_id:1663]should report 4 vCPUs under guest OS", func() {
vmi.Spec.Domain.CPU = &v1.CPU{
Threads: 2,
Sockets: 2,
Cores: 1,
}
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should start console")
defer expecter.Close()
By("Checking the number of vCPUs under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "grep -c ^processor /proc/cpuinfo\n"},
&expect.BExp{R: "4"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report number of threads")
})
It("[test_id:1664]should map cores to virtio block queues", func() {
_true := true
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
kubev1.ResourceCPU: resource.MustParse("3"),
},
}
vmi.Spec.Domain.Devices.BlockMultiQueue = &_true
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).To(ContainSubstring("queues='3'"))
})
It("[test_id:1665]should map cores to virtio net queues", func() {
if shouldUseEmulation(virtClient) {
Skip("Software emulation should not be enabled for this test to run")
}
_true := true
_false := false
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
kubev1.ResourceCPU: resource.MustParse("3"),
},
}
vmi.Spec.Domain.Devices.NetworkInterfaceMultiQueue = &_true
vmi.Spec.Domain.Devices.BlockMultiQueue = &_false
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).To(ContainSubstring("driver name='vhost' queues='3'"))
// make sure that there are not block queues configured
Expect(domXml).ToNot(ContainSubstring("cache='none' queues='3'"))
})
It("[test_id:1667]should not enforce explicitly rejected virtio block queues without cores", func() {
_false := false
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
},
}
vmi.Spec.Domain.Devices.BlockMultiQueue = &_false
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).ToNot(ContainSubstring("queues='"))
})
})
Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with no memory requested", func() {
It("[test_id:3113]should failed to the VMI creation", func() {
vmi := tests.NewRandomVMI()
vmi.Spec.Domain.Resources = v1.ResourceRequirements{}
By("Starting a VirtualMachineInstance")
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).To(HaveOccurred())
})
})
Context("[rfe_id:609][crit:medium][vendor:[email protected]][level:component]with cluster memory overcommit being applied", func() {
BeforeEach(func() {
tests.UpdateClusterConfigValueAndWait("memory-overcommit", "200")
})
It("[test_id:3114]should set requested amount of memory according to the specified virtual memory", func() {
vmi := tests.NewRandomVMI()
guestMemory := resource.MustParse("4096M")
vmi.Spec.Domain.Memory = &v1.Memory{Guest: &guestMemory}
vmi.Spec.Domain.Resources = v1.ResourceRequirements{}
runningVMI := tests.RunVMI(vmi, 30)
Expect(runningVMI.Spec.Domain.Resources.Requests.Memory().String()).To(Equal("2048M"))
})
})
Context("[rfe_id:2262][crit:medium][vendor:[email protected]][level:component]with EFI bootloader method", func() {
It("[test_id:1668]should use EFI", func() {
vmi := tests.NewRandomVMIWithEFIBootloader()
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitUntilVMIReady(vmi, tests.LoggedInAlpineExpecter)
By("Checking if UEFI is enabled")
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).To(ContainSubstring("OVMF_CODE.fd"))
})
It("[test_id:4437]should enable EFI secure boot", func() {
vmi := tests.NewRandomVMIWithSecureBoot()
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
By("Checking if SecureBoot is enabled in Linux")
tests.WaitUntilVMIReady(vmi, tests.SecureBootExpecter)
By("Checking if SecureBoot is enabled in the libvirt XML")
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).To(ContainSubstring("OVMF_CODE.secboot.fd"))
})
})
Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with diverging guest memory from requested memory", func() {
It("[test_id:1669]should show the requested guest memory inside the VMI", func() {
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(cd.ContainerDiskFor(cd.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
vmi.Spec.Domain.Resources.Requests[kubev1.ResourceMemory] = resource.MustParse("64M")
guestMemory := resource.MustParse("128M")
vmi.Spec.Domain.Memory = &v1.Memory{
Guest: &guestMemory,
}
vmi, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)
expecter, err := tests.LoggedInCirrosExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
res, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "free -m | grep Mem: | tr -s ' ' | cut -d' ' -f2\n"},
&expect.BExp{R: "104"},
}, 10*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
})
})
Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with diverging memory limit from memory request and no guest memory", func() {
It("[test_id:3115]should show the memory limit inside the VMI", func() {
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(cd.ContainerDiskFor(cd.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
vmi.Spec.Domain.Resources.Requests[kubev1.ResourceMemory] = resource.MustParse("64M")
vmi.Spec.Domain.Resources.Limits = kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("128M"),
}
vmi, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)
expecter, err := tests.LoggedInCirrosExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
res, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "free -m | grep Mem: | tr -s ' ' | cut -d' ' -f2\n"},
&expect.BExp{R: "104"},
}, 10*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
})
})
Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with support memory over commitment", func() {
It("[test_id:755]should show the requested memory different than guest memory", func() {
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(cd.ContainerDiskFor(cd.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
guestMemory := resource.MustParse("256Mi")
vmi.Spec.Domain.Resources.Requests[kubev1.ResourceMemory] = resource.MustParse("64Mi")
vmi.Spec.Domain.Resources.OvercommitGuestOverhead = true
vmi.Spec.Domain.Memory = &v1.Memory{
Guest: &guestMemory,
}
vmi, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)
expecter, err := tests.LoggedInCirrosExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
res, err := tests.ExpectBatchWithValidatedSend(expecter, []expect.Batcher{
&expect.BSnd{S: "[ $(free -m | grep Mem: | tr -s ' ' | cut -d' ' -f2) -gt 200 ] && echo 'pass'\n"},
&expect.BExp{R: tests.RetValue("pass")},
&expect.BSnd{S: "swapoff -a && dd if=/dev/zero of=/dev/shm/test bs=1k count=118k\n"},
&expect.BExp{R: "\\$ "},
&expect.BSnd{S: "echo $?\n"},
&expect.BExp{R: tests.RetValue("0")},
}, 15*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
pod := tests.GetRunningPodByVirtualMachineInstance(vmi, tests.NamespaceTestDefault)
podMemoryUsage, err := tests.ExecuteCommandOnPod(
virtClient,
pod,
"compute",
[]string{"/usr/bin/bash", "-c", "cat /sys/fs/cgroup/memory/memory.usage_in_bytes"},
)
Expect(err).ToNot(HaveOccurred())
By("Converting pod memory usage")
m, err := strconv.Atoi(strings.Trim(podMemoryUsage, "\n"))
Expect(err).ToNot(HaveOccurred())
By("Checking if pod memory usage is > 64Mi")
Expect(m > 67108864).To(BeTrue(), "67108864 B = 64 Mi")
})
})
Context("[rfe_id:609][crit:medium][vendor:[email protected]][level:component]Support memory over commitment test", func() {
var vmi *v1.VirtualMachineInstance
BeforeEach(func() {
vmi = tests.NewRandomVMIWithEphemeralDiskAndUserdata(cd.ContainerDiskFor(cd.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
vmi.Spec.Domain.Resources.Requests[kubev1.ResourceMemory] = resource.MustParse("128M")
vmi.Spec.Domain.Resources.OvercommitGuestOverhead = true
vmi, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)
})
It("[test_id:730]Check OverCommit VM Created and Started", func() {
overcommitVmi, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(overcommitVmi)
})
It("[test_id:731]Check OverCommit status on VMI", func() {
overcommitVmi, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Get(vmi.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(overcommitVmi.Spec.Domain.Resources.OvercommitGuestOverhead).To(BeTrue())
})
It("[test_id:732]Check Free memory on the VMI", func() {
By("Expecting console")
expecter, err := tests.LoggedInCirrosExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
// Check on the VM, if the Free memory is roughly what we expected
res, err := tests.ExpectBatchWithValidatedSend(expecter, []expect.Batcher{
&expect.BSnd{S: "[ $(free -m | grep Mem: | tr -s ' ' | cut -d' ' -f2) -gt 95 ] && echo 'pass'\n"},
&expect.BExp{R: tests.RetValue("pass")},
}, 15*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
})
})
Context("[rfe_id:3078][crit:medium][vendor:[email protected]][level:component]with usb controller", func() {
It("[test_id:3117]should start the VMI with usb controller when usb device is present", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Devices.Inputs = []v1.Input{
{
Name: "tablet0",
Type: "tablet",
Bus: "usb",
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should get console")
defer expecter.Close()
By("Checking the number of usb under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "ls -l /sys/bus/usb/devices/usb* | wc -l\n"},
&expect.BExp{R: "2"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report number of usb")
})
It("[test_id:3117]should start the VMI with usb controller when input device doesn't have bus", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Devices.Inputs = []v1.Input{
{
Name: "tablet0",
Type: "tablet",
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should get console")
defer expecter.Close()
By("Checking the number of usb under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "ls -l /sys/bus/usb/devices/usb* | wc -l\n"},
&expect.BExp{R: "2"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report number of usb")
})
It("[test_id:3118]should start the VMI without usb controller", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should start console")
defer expecter.Close()
By("Checking the number of usb under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "ls -l /sys/bus/usb/devices/usb* 2>/dev/null | wc -l\n"},
&expect.BExp{R: "0"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report number of usb")
})
})
Context("[rfe_id:3077][crit:medium][vendor:[email protected]][level:component]with input devices", func() {
It("[test_id:2642]should failed to start the VMI with wrong type of input device", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskFedora))
vmi.Spec.Domain.Devices.Inputs = []v1.Input{
{
Name: "tablet0",
Type: "keyboard",
Bus: "virtio",
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).To(HaveOccurred(), "should not start vmi")
})
It("[test_id:3074]should failed to start the VMI with wrong bus of input device", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskFedora))
vmi.Spec.Domain.Devices.Inputs = []v1.Input{
{
Name: "tablet0",
Type: "tablet",
Bus: "ps2",
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).To(HaveOccurred(), "should not start vmi")
})
It("[test_id:3072]should start the VMI with tablet input device with virtio bus", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Devices.Inputs = []v1.Input{
{
Name: "tablet0",
Type: "tablet",
Bus: "virtio",
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should start console")
defer expecter.Close()
By("Checking the tablet input under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "grep -rs '^QEMU Virtio Tablet' /sys/devices | wc -l\n"},
&expect.BExp{R: "1"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report input device")
})
It("[test_id:3073]should start the VMI with tablet input device with usb bus", func() {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Devices.Inputs = []v1.Input{
{
Name: "tablet0",
Type: "tablet",
Bus: "usb",
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
By("Expecting the VirtualMachineInstance console")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred(), "should start console")
defer expecter.Close()
By("Checking the tablet input under guest OS")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "grep -rs '^QEMU USB Tablet' /sys/devices | wc -l\n"},
&expect.BExp{R: "1"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred(), "should report input device")
})
})
Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with namespace memory limits lower than VMI required memory", func() {
var vmi *v1.VirtualMachineInstance
It("[test_id:1670]should failed to start the VMI", func() {
// create a namespace default limit
limitRangeObj := kubev1.LimitRange{
ObjectMeta: metav1.ObjectMeta{Name: "abc1", Namespace: tests.NamespaceTestDefault},
Spec: kubev1.LimitRangeSpec{
Limits: []kubev1.LimitRangeItem{
{
Type: kubev1.LimitTypeContainer,
Default: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("32Mi"),
},
},
},
},
}
_, err := virtClient.CoreV1().LimitRanges(tests.NamespaceTestDefault).Create(&limitRangeObj)
Expect(err).ToNot(HaveOccurred())
By("Starting a VirtualMachineInstance")
// Retrying up to 5 sec, then if you still succeeds in VMI creation, things must be going wrong.
Eventually(func() error {
vmi = tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
},
}
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(vmi.Name, &metav1.DeleteOptions{})
return err
}, 5*time.Second, 1*time.Second).Should(MatchError("admission webhook \"virtualmachineinstances-create-validator.kubevirt.io\" denied the request: spec.domain.resources.requests.memory '64M' is greater than spec.domain.resources.limits.memory '32Mi'"))
})
})
Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with namespace cpu limits lower than VMI required cpu", func() {
var vmi *v1.VirtualMachineInstance
It("[test_id:3119]should fail to start the VMI", func() {
// create a namespace default limit
limitRangeObj := kubev1.LimitRange{
ObjectMeta: metav1.ObjectMeta{Name: "abc1", Namespace: tests.NamespaceTestDefault},
Spec: kubev1.LimitRangeSpec{
Limits: []kubev1.LimitRangeItem{
{
Type: kubev1.LimitTypeContainer,
Default: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("500m"),
},
},
},
},
}
_, err := virtClient.CoreV1().LimitRanges(tests.NamespaceTestDefault).Create(&limitRangeObj)
Expect(err).ToNot(HaveOccurred())
By("Starting a VirtualMachineInstance")
// Retrying up to 5 sec, then if you still succeeds in VMI creation, things must be going wrong.
Eventually(func() error {
vmi = tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("800m"),
kubev1.ResourceMemory: resource.MustParse("512M"),
},
}
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(vmi.Name, &metav1.DeleteOptions{})
return err
}, 5*time.Second, 1*time.Second).Should(MatchError("admission webhook \"virtualmachineinstances-create-validator.kubevirt.io\" denied the request: spec.domain.resources.requests.cpu '800m' is greater than spec.domain.resources.limits.cpu '500m'"))
})
})
Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with namespace limits higher than VMI requests", func() {
var vmi *v1.VirtualMachineInstance
It("[test_id:3120]should start the VMI with the right default settings from namespace limits", func() {
// create a namespace default limit
limitRangeObj := kubev1.LimitRange{
ObjectMeta: metav1.ObjectMeta{Name: "abc1", Namespace: tests.NamespaceTestDefault},
Spec: kubev1.LimitRangeSpec{
Limits: []kubev1.LimitRangeItem{
{
Type: kubev1.LimitTypeContainer,
Default: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("2000m"),
kubev1.ResourceMemory: resource.MustParse("512M"),
},
DefaultRequest: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("500m"),
},
},
},
},
}
_, err := virtClient.CoreV1().LimitRanges(tests.NamespaceTestDefault).Create(&limitRangeObj)
Expect(err).ToNot(HaveOccurred())
vmi = tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("64M"),
},
Limits: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("1000m"),
},
}
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred(), "should start vmi")
tests.WaitForSuccessfulVMIStart(vmi)
Expect(vmi.Spec.Domain.Resources.Requests.Memory().ToDec().ScaledValue(resource.Mega)).To(Equal(int64(64)))
Expect(vmi.Spec.Domain.Resources.Limits.Memory().ToDec().ScaledValue(resource.Mega)).To(Equal(int64(512)))
Expect(vmi.Spec.Domain.Resources.Requests.Cpu().MilliValue()).To(Equal(int64(500)))
Expect(vmi.Spec.Domain.Resources.Limits.Cpu().MilliValue()).To(Equal(int64(1000)))
Expect(err).ToNot(HaveOccurred())
})
})
Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]with hugepages", func() {
var hugepagesVmi *v1.VirtualMachineInstance
verifyHugepagesConsumption := func() {
// TODO: we need to check hugepages state via node allocated resources, but currently it has the issue
// https://github.com/kubernetes/kubernetes/issues/64691
pods, err := virtClient.CoreV1().Pods(tests.NamespaceTestDefault).List(tests.UnfinishedVMIPodSelector(hugepagesVmi))
Expect(err).ToNot(HaveOccurred())
Expect(len(pods.Items)).To(Equal(1))
hugepagesSize := resource.MustParse(hugepagesVmi.Spec.Domain.Memory.Hugepages.PageSize)
hugepagesDir := fmt.Sprintf("/sys/kernel/mm/hugepages/hugepages-%dkB", hugepagesSize.Value()/int64(1024))
// Get a hugepages statistics from virt-launcher pod
output, err := tests.ExecuteCommandOnPod(
virtClient,
&pods.Items[0],
pods.Items[0].Spec.Containers[0].Name,
[]string{"cat", fmt.Sprintf("%s/nr_hugepages", hugepagesDir)},
)
Expect(err).ToNot(HaveOccurred())
totalHugepages, err := strconv.Atoi(strings.Trim(output, "\n"))
Expect(err).ToNot(HaveOccurred())
output, err = tests.ExecuteCommandOnPod(
virtClient,
&pods.Items[0],
pods.Items[0].Spec.Containers[0].Name,
[]string{"cat", fmt.Sprintf("%s/free_hugepages", hugepagesDir)},
)
Expect(err).ToNot(HaveOccurred())
freeHugepages, err := strconv.Atoi(strings.Trim(output, "\n"))
Expect(err).ToNot(HaveOccurred())
// Verify that the VM memory equals to a number of consumed hugepages
vmHugepagesConsumption := int64(totalHugepages-freeHugepages) * hugepagesSize.Value()
vmMemory := hugepagesVmi.Spec.Domain.Resources.Requests[kubev1.ResourceMemory]
if hugepagesVmi.Spec.Domain.Memory != nil && hugepagesVmi.Spec.Domain.Memory.Guest != nil {
vmMemory = *hugepagesVmi.Spec.Domain.Memory.Guest
}
Expect(vmHugepagesConsumption).To(Equal(vmMemory.Value()))
}
BeforeEach(func() {
hugepagesVmi = tests.NewRandomVMIWithEphemeralDiskAndUserdata(cd.ContainerDiskFor(cd.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
})
table.DescribeTable("should consume hugepages ", func(hugepageSize string, memory string, guestMemory string) {
hugepageType := kubev1.ResourceName(kubev1.ResourceHugePagesPrefix + hugepageSize)
nodeWithHugepages := tests.GetNodeWithHugepages(virtClient, hugepageType)
if nodeWithHugepages == nil {
Skip(fmt.Sprintf("No node with hugepages %s capacity", hugepageType))
}
// initialHugepages := nodeWithHugepages.Status.Capacity[resourceName]
hugepagesVmi.Spec.Affinity = &kubev1.Affinity{
NodeAffinity: &kubev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &kubev1.NodeSelector{
NodeSelectorTerms: []kubev1.NodeSelectorTerm{
{
MatchExpressions: []kubev1.NodeSelectorRequirement{
{Key: "kubernetes.io/hostname", Operator: kubev1.NodeSelectorOpIn, Values: []string{nodeWithHugepages.Name}},
},
},
},
},
},
}
hugepagesVmi.Spec.Domain.Resources.Requests[kubev1.ResourceMemory] = resource.MustParse(memory)
hugepagesVmi.Spec.Domain.Memory = &v1.Memory{
Hugepages: &v1.Hugepages{PageSize: hugepageSize},
}
if guestMemory != "None" {
guestMemReq := resource.MustParse(guestMemory)
hugepagesVmi.Spec.Domain.Memory.Guest = &guestMemReq
}
By("Starting a VM")
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(hugepagesVmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(hugepagesVmi)
By("Checking that the VM memory equals to a number of consumed hugepages")
verifyHugepagesConsumption()