forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vmi_headless_test.go
159 lines (119 loc) · 5.14 KB
/
vmi_headless_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
/*
* 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, 2018 Red Hat, Inc.
*
*/
package tests_test
import (
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
kubev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
v1 "kubevirt.io/client-go/api/v1"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/kubevirt/tests"
cd "kubevirt.io/kubevirt/tests/containerdisk"
)
var _ = Describe("[rfe_id:609]VMIheadless", func() {
var err error
var virtClient kubecli.KubevirtClient
var vmi *v1.VirtualMachineInstance
BeforeEach(func() {
virtClient, err = kubecli.GetKubevirtClient()
tests.PanicOnError(err)
tests.BeforeTestCleanup()
vmi = tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
})
Describe("[rfe_id:609]Creating a VirtualMachineInstance", func() {
Context("with headless", func() {
BeforeEach(func() {
f := false
vmi.Spec.Domain.Devices.AutoattachGraphicsDevice = &f
})
It("[test_id:707]should create headless vmi without any issue", func() {
tests.RunVMIAndExpectLaunch(vmi, 30)
})
It("[test_id:714][posneg:positive]should not have vnc graphic device in xml", func() {
tests.RunVMIAndExpectLaunch(vmi, 30)
runningVMISpec, err := tests.GetRunningVMIDomainSpec(vmi)
Expect(err).ToNot(HaveOccurred(), "should get vmi spec without problem")
Expect(len(runningVMISpec.Devices.Graphics)).To(Equal(0), "should not have any graphics devices present")
})
It("[test_id:737][posneg:positive]should match memory with overcommit enabled", func() {
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("100M"),
},
OvercommitGuestOverhead: true,
}
vmi = tests.RunVMIAndExpectLaunch(vmi, 30)
readyPod := tests.GetPodByVirtualMachineInstance(vmi, tests.NamespaceTestDefault)
computeContainer := tests.GetComputeContainerOfPod(readyPod)
Expect(computeContainer.Resources.Requests.Memory().String()).To(Equal("100M"))
})
It("[test_id:2444][posneg:negative]should not match memory with overcommit disabled", func() {
vmi.Spec.Domain.Resources = v1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceMemory: resource.MustParse("100M"),
},
}
vmi = tests.RunVMIAndExpectLaunch(vmi, 30)
readyPod := tests.GetPodByVirtualMachineInstance(vmi, tests.NamespaceTestDefault)
computeContainer := tests.GetComputeContainerOfPod(readyPod)
Expect(computeContainer.Resources.Requests.Memory().String()).ToNot(Equal("100M"))
})
It("[test_id:713]should have more memory on pod when headless", func() {
normalVmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi = tests.RunVMIAndExpectLaunch(vmi, 30)
normalVmi = tests.RunVMIAndExpectLaunch(normalVmi, 30)
readyPod := tests.GetPodByVirtualMachineInstance(vmi, tests.NamespaceTestDefault)
computeContainer := tests.GetComputeContainerOfPod(readyPod)
normalReadyPod := tests.GetPodByVirtualMachineInstance(normalVmi, tests.NamespaceTestDefault)
normalComputeContainer := tests.GetComputeContainerOfPod(normalReadyPod)
memDiff := normalComputeContainer.Resources.Requests.Memory()
memDiff.Sub(*computeContainer.Resources.Requests.Memory())
Expect(memDiff.ScaledValue(resource.Mega) > 15).To(BeTrue(), "memory difference between headless and normal should be roughly 16M")
})
It("[test_id:738][posneg:negative]should not connect to VNC", func() {
vmi = tests.RunVMIAndExpectLaunch(vmi, 30)
_, err := virtClient.VirtualMachineInstance(vmi.ObjectMeta.Namespace).VNC(vmi.ObjectMeta.Name)
Expect(err.Error()).To(Equal("No graphics devices are present."), "vnc should not connect on headless VM")
})
It("[test_id:709][posneg:positive]should connect to console", func() {
vmi = tests.RunVMIAndExpectLaunch(vmi, 30)
By("checking that console works")
expecter, err := tests.LoggedInAlpineExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
})
})
Context("without headless", func() {
It("[test_id:714][posneg:negative]should have one vnc graphic device in xml", func() {
tests.RunVMIAndExpectLaunch(vmi, 30)
runningVMISpec, err := tests.GetRunningVMIDomainSpec(vmi)
Expect(err).ToNot(HaveOccurred(), "should get vmi spec without problem")
vncCount := 0
for _, gr := range runningVMISpec.Devices.Graphics {
if strings.ToLower(gr.Type) == "vnc" {
vncCount += 1
}
}
Expect(vncCount).To(Equal(1), "should have exactly one VNC device")
})
})
})
})