Skip to content

Commit 2100e0c

Browse files
author
Valeriy Khorunzhin
committed
fixes
Signed-off-by: Valeriy Khorunzhin <[email protected]>
1 parent e831db4 commit 2100e0c

File tree

2 files changed

+56
-26
lines changed

2 files changed

+56
-26
lines changed

tests/e2e/virtual_machine_restore_operation_test/vmop_restore_test_helper.go

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
25+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/types"
2728

@@ -43,17 +44,18 @@ const (
4344
)
4445

4546
type VMOPRestoreTestHelper struct {
46-
FrameworkEntity *framework.Framework
47-
VM *v1alpha2.VirtualMachine
48-
CVI *v1alpha2.ClusterVirtualImage
49-
VI *v1alpha2.VirtualImage
50-
VDRoot, VDBlank *v1alpha2.VirtualDisk
51-
VMBDA *v1alpha2.VirtualMachineBlockDeviceAttachment
52-
VMSnapshot *v1alpha2.VirtualMachineSnapshot
53-
VMOPDryRun *v1alpha2.VirtualMachineOperation
54-
VMOPStrict *v1alpha2.VirtualMachineOperation
55-
VMOPBestEffort *v1alpha2.VirtualMachineOperation
56-
GeneratedValue string
47+
FrameworkEntity *framework.Framework
48+
VM *v1alpha2.VirtualMachine
49+
CVI *v1alpha2.ClusterVirtualImage
50+
VI *v1alpha2.VirtualImage
51+
VDRoot, VDBlank *v1alpha2.VirtualDisk
52+
VMBDA *v1alpha2.VirtualMachineBlockDeviceAttachment
53+
VMSnapshot *v1alpha2.VirtualMachineSnapshot
54+
VMOPDryRun *v1alpha2.VirtualMachineOperation
55+
VMOPStrict *v1alpha2.VirtualMachineOperation
56+
VMOPBestEffort *v1alpha2.VirtualMachineOperation
57+
GeneratedValue string
58+
VMRunningObservedGenerationBeforeReboot int64
5759
}
5860

5961
func NewVMOPRestoreTestHelper(frameworkEntity *framework.Framework) *VMOPRestoreTestHelper {
@@ -121,6 +123,8 @@ func (h *VMOPRestoreTestHelper) GenerateAndCreateOriginalResources() {
121123
}
122124

123125
func (h *VMOPRestoreTestHelper) UpdateState() {
126+
GinkgoHelper()
127+
124128
var err error
125129

126130
if h.CVI != nil {
@@ -134,6 +138,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
134138
)
135139
if err == nil {
136140
h.CVI = &cvi
141+
} else {
142+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
137143
}
138144
}
139145

@@ -149,6 +155,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
149155
)
150156
if err == nil {
151157
h.VI = &vi
158+
} else {
159+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
152160
}
153161
}
154162

@@ -164,6 +172,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
164172
)
165173
if err == nil {
166174
h.VDBlank = &vdBlank
175+
} else {
176+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
167177
}
168178
}
169179

@@ -179,6 +189,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
179189
)
180190
if err == nil {
181191
h.VDRoot = &vdRoot
192+
} else {
193+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
182194
}
183195
}
184196

@@ -194,6 +206,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
194206
)
195207
if err == nil {
196208
h.VMBDA = &vmbda
209+
} else {
210+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
197211
}
198212
}
199213

@@ -209,6 +223,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
209223
)
210224
if err == nil {
211225
h.VM = &vm
226+
} else {
227+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
212228
}
213229
}
214230

@@ -224,6 +240,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
224240
)
225241
if err == nil {
226242
h.VMSnapshot = &vmSnapshot
243+
} else {
244+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
227245
}
228246
}
229247

@@ -239,6 +257,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
239257
)
240258
if err == nil {
241259
h.VMOPDryRun = &vmopDryRun
260+
} else {
261+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
242262
}
243263
}
244264

@@ -254,6 +274,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
254274
)
255275
if err == nil {
256276
h.VMOPStrict = &vmopStrict
277+
} else {
278+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
257279
}
258280
}
259281

@@ -269,6 +291,8 @@ func (h *VMOPRestoreTestHelper) UpdateState() {
269291
)
270292
if err == nil {
271293
h.VMOPBestEffort = &vmopBestEffort
294+
} else {
295+
Expect(k8serrors.IsNotFound(err)).Should(BeTrue())
272296
}
273297
}
274298
}

tests/e2e/vmop_restore_test.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ var _ = Describe("VirtualMachineOperationRestore", Serial, ginkgoutil.CommonE2ET
124124
})
125125

126126
It("Reboot VM", func() {
127+
running, _ := conditions.GetCondition(vmcondition.TypeRunning, helper.VM.Status.Conditions)
128+
helper.VMRunningObservedGenerationBeforeReboot = running.ObservedGeneration
129+
127130
Eventually(func(g Gomega) {
128131
res := d8Virtualization.SSHCommand(helper.VM.Name, "sudo reboot", d8.SSHOptions{
129132
Namespace: helper.VM.Namespace,
@@ -135,14 +138,13 @@ var _ = Describe("VirtualMachineOperationRestore", Serial, ginkgoutil.CommonE2ET
135138

136139
Eventually(func(g Gomega) {
137140
helper.UpdateState()
138-
g.Expect(helper.VM.Status.Phase).Should(Equal(v1alpha2.MachineStopped))
139-
}, 60*time.Second, time.Second).Should(Succeed())
140141

141-
Eventually(func(g Gomega) {
142-
helper.UpdateState()
142+
running, _ := conditions.GetCondition(vmcondition.TypeRunning, helper.VM.Status.Conditions)
143+
g.Expect(running.ObservedGeneration).Should(BeNumerically(">", helper.VMRunningObservedGenerationBeforeReboot))
144+
143145
agentReady, _ := conditions.GetCondition(vmcondition.TypeAgentReady, helper.VM.Status.Conditions)
144146
g.Expect(agentReady.Status).Should(Equal(metav1.ConditionTrue))
145-
}, 60*time.Second, time.Second).Should(Succeed())
147+
}, 120*time.Second, time.Second).Should(Succeed())
146148
})
147149

148150
It("VM spec should be changed", func() {
@@ -228,15 +230,17 @@ var _ = Describe("VirtualMachineOperationRestore", Serial, ginkgoutil.CommonE2ET
228230
startVMOP := resources.NewStartVMOP("start", helper.FrameworkEntity.Namespace().Name, helper.VM.Name)
229231
err := helper.FrameworkEntity.Clients.GenericClient().Create(context.Background(), startVMOP)
230232
Expect(err).ShouldNot(HaveOccurred())
231-
232-
Eventually(func(g Gomega) {
233-
helper.UpdateState()
234-
agentReady, _ := conditions.GetCondition(vmcondition.TypeAgentReady, helper.VM.Status.Conditions)
235-
g.Expect(agentReady.Status).Should(Equal(metav1.ConditionTrue))
236-
}, 60*time.Second, time.Second).Should(Succeed())
237233
}
238234
})
239235

236+
It("Virtual Machine agent should be ready", func() {
237+
Eventually(func(g Gomega) {
238+
helper.UpdateState()
239+
agentReady, _ := conditions.GetCondition(vmcondition.TypeAgentReady, helper.VM.Status.Conditions)
240+
g.Expect(agentReady.Status).Should(Equal(metav1.ConditionTrue))
241+
}, 60*time.Second, time.Second).Should(Succeed())
242+
})
243+
240244
It("File should have generated value", func() {
241245
Eventually(func(g Gomega) {
242246
res := d8Virtualization.SSHCommand(helper.VM.Name, helper.MountAndGetDiskFileContentShell(), d8.SSHOptions{
@@ -280,6 +284,9 @@ var _ = Describe("VirtualMachineOperationRestore", Serial, ginkgoutil.CommonE2ET
280284
})
281285

282286
It("Reboot VM", func() {
287+
running, _ := conditions.GetCondition(vmcondition.TypeRunning, helper.VM.Status.Conditions)
288+
helper.VMRunningObservedGenerationBeforeReboot = running.ObservedGeneration
289+
283290
Eventually(func(g Gomega) {
284291
res := d8Virtualization.SSHCommand(helper.VM.Name, "sudo reboot", d8.SSHOptions{
285292
Namespace: helper.VM.Namespace,
@@ -291,11 +298,10 @@ var _ = Describe("VirtualMachineOperationRestore", Serial, ginkgoutil.CommonE2ET
291298

292299
Eventually(func(g Gomega) {
293300
helper.UpdateState()
294-
g.Expect(helper.VM.Status.Phase).Should(Equal(v1alpha2.MachineStopped))
295-
}, 60*time.Second, time.Second).Should(Succeed())
296301

297-
Eventually(func(g Gomega) {
298-
helper.UpdateState()
302+
running, _ := conditions.GetCondition(vmcondition.TypeRunning, helper.VM.Status.Conditions)
303+
g.Expect(running.ObservedGeneration).Should(BeNumerically(">", helper.VMRunningObservedGenerationBeforeReboot))
304+
299305
agentReady, _ := conditions.GetCondition(vmcondition.TypeAgentReady, helper.VM.Status.Conditions)
300306
g.Expect(agentReady.Status).Should(Equal(metav1.ConditionTrue))
301307
}, 120*time.Second, time.Second).Should(Succeed())

0 commit comments

Comments
 (0)