forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
softreboot_test.go
179 lines (138 loc) · 7.02 KB
/
softreboot_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
/*
* 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 2019 Red Hat, Inc.
*
*/
package tests_test
import (
"context"
"fmt"
"time"
"kubevirt.io/kubevirt/tests/decorators"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
expect "github.com/google/goexpect"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"
virtctlpause "kubevirt.io/kubevirt/pkg/virtctl/pause"
virtctlsoftreboot "kubevirt.io/kubevirt/pkg/virtctl/softreboot"
"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tests/clientcmd"
"kubevirt.io/kubevirt/tests/console"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
"kubevirt.io/kubevirt/tests/framework/matcher"
"kubevirt.io/kubevirt/tests/libvmi"
"kubevirt.io/kubevirt/tests/testsuite"
)
func waitForVMIRebooted(vmi *v1.VirtualMachineInstance, login func(vmi *v1.VirtualMachineInstance) error) {
By(fmt.Sprintf("Waiting for vmi %s rebooted", vmi.Name))
if vmi.Namespace == "" {
vmi.Namespace = testsuite.GetTestNamespace(vmi)
}
time.Sleep(30 * time.Second)
Expect(login(vmi)).To(Succeed())
Expect(console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "last reboot | grep reboot | wc -l\n"},
&expect.BExp{R: "2"},
}, 300)).To(Succeed(), "expected reboot record")
}
func withoutACPI() libvmi.Option {
return func(vmi *v1.VirtualMachineInstance) {
acpiEnabled := false
vmi.Spec.Domain.Features = &v1.Features{
ACPI: v1.FeatureState{Enabled: &acpiEnabled},
}
}
}
const vmiLaunchTimeout = 360
var _ = Describe("[crit:medium][vendor:[email protected]][level:component][sig-compute]Soft reboot", decorators.SigCompute, func() {
var virtClient kubecli.KubevirtClient
BeforeEach(func() {
virtClient = kubevirt.Client()
})
Context("Soft reboot VMI", func() {
var vmi *v1.VirtualMachineInstance
When("soft reboot vmi with agent connected via API", func() {
It("should succeed", func() {
vmi = tests.RunVMIAndExpectLaunch(libvmi.NewFedora(withoutACPI()), vmiLaunchTimeout)
Eventually(matcher.ThisVMI(vmi), 12*time.Minute, 2*time.Second).Should(matcher.HaveConditionTrue(v1.VirtualMachineInstanceAgentConnected))
err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).SoftReboot(context.Background(), vmi.Name)
Expect(err).ToNot(HaveOccurred())
waitForVMIRebooted(vmi, console.LoginToFedora)
})
})
When("soft reboot vmi with ACPI feature enabled via API", func() {
It("should succeed", func() {
vmi = tests.RunVMIAndExpectLaunch(libvmi.NewCirros(), vmiLaunchTimeout)
Expect(console.LoginToCirros(vmi)).To(Succeed())
Eventually(matcher.ThisVMI(vmi), 30*time.Second, 2*time.Second).Should(matcher.HaveConditionMissingOrFalse(v1.VirtualMachineInstanceAgentConnected))
err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).SoftReboot(context.Background(), vmi.Name)
Expect(err).ToNot(HaveOccurred())
waitForVMIRebooted(vmi, console.LoginToCirros)
})
})
When("soft reboot vmi with agent connected via virtctl", func() {
It("should succeed", func() {
vmi = tests.RunVMIAndExpectLaunch(libvmi.NewFedora(withoutACPI()), vmiLaunchTimeout)
Eventually(matcher.ThisVMI(vmi), 12*time.Minute, 2*time.Second).Should(matcher.HaveConditionTrue(v1.VirtualMachineInstanceAgentConnected))
command := clientcmd.NewRepeatableVirtctlCommand(virtctlsoftreboot.COMMAND_SOFT_REBOOT, "--namespace", testsuite.GetTestNamespace(vmi), vmi.Name)
Expect(command()).To(Succeed())
waitForVMIRebooted(vmi, console.LoginToFedora)
})
})
When("soft reboot vmi with ACPI feature enabled via virtctl", func() {
It("should succeed", func() {
vmi = tests.RunVMIAndExpectLaunch(libvmi.NewCirros(), vmiLaunchTimeout)
Expect(console.LoginToCirros(vmi)).To(Succeed())
Eventually(matcher.ThisVMI(vmi), 30*time.Second, 2*time.Second).Should(matcher.HaveConditionMissingOrFalse(v1.VirtualMachineInstanceAgentConnected))
command := clientcmd.NewRepeatableVirtctlCommand(virtctlsoftreboot.COMMAND_SOFT_REBOOT, "--namespace", testsuite.GetTestNamespace(vmi), vmi.Name)
Expect(command()).To(Succeed())
waitForVMIRebooted(vmi, console.LoginToCirros)
})
})
When("soft reboot vmi neither have the agent connected nor the ACPI feature enabled via virtctl", func() {
It("should failed", func() {
vmi = tests.RunVMIAndExpectLaunch(libvmi.NewCirros(withoutACPI()), vmiLaunchTimeout)
Expect(console.LoginToCirros(vmi)).To(Succeed())
Eventually(matcher.ThisVMI(vmi), 30*time.Second, 2*time.Second).Should(matcher.HaveConditionMissingOrFalse(v1.VirtualMachineInstanceAgentConnected))
command := clientcmd.NewRepeatableVirtctlCommand(virtctlsoftreboot.COMMAND_SOFT_REBOOT, "--namespace", testsuite.GetTestNamespace(vmi), vmi.Name)
err := command()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("VMI neither have the agent connected nor the ACPI feature enabled"))
})
})
When("soft reboot vmi after paused and unpaused via virtctl", func() {
It("should failed to soft reboot a paused vmi", func() {
vmi = tests.RunVMIAndExpectLaunch(libvmi.NewFedora(), vmiLaunchTimeout)
Eventually(matcher.ThisVMI(vmi), 12*time.Minute, 2*time.Second).Should(matcher.HaveConditionTrue(v1.VirtualMachineInstanceAgentConnected))
command := clientcmd.NewRepeatableVirtctlCommand(virtctlpause.COMMAND_PAUSE, "vmi", "--namespace", testsuite.GetTestNamespace(vmi), vmi.Name)
Expect(command()).To(Succeed())
Eventually(matcher.ThisVMI(vmi), 30*time.Second, 2*time.Second).Should(matcher.HaveConditionTrue(v1.VirtualMachineInstancePaused))
command = clientcmd.NewRepeatableVirtctlCommand(virtctlsoftreboot.COMMAND_SOFT_REBOOT, "--namespace", testsuite.GetTestNamespace(vmi), vmi.Name)
err := command()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("VMI is paused"))
command = clientcmd.NewRepeatableVirtctlCommand(virtctlpause.COMMAND_UNPAUSE, "vmi", "--namespace", testsuite.GetTestNamespace(vmi), vmi.Name)
Expect(command()).To(Succeed())
Eventually(matcher.ThisVMI(vmi), 30*time.Second, 2*time.Second).Should(matcher.HaveConditionMissingOrFalse(v1.VirtualMachineInstancePaused))
Eventually(matcher.ThisVMI(vmi), 12*time.Minute, 2*time.Second).Should(matcher.HaveConditionTrue(v1.VirtualMachineInstanceAgentConnected))
command = clientcmd.NewRepeatableVirtctlCommand(virtctlsoftreboot.COMMAND_SOFT_REBOOT, "--namespace", testsuite.GetTestNamespace(vmi), vmi.Name)
Expect(command()).To(Succeed())
waitForVMIRebooted(vmi, console.LoginToFedora)
})
})
})
})