Skip to content

Commit da86834

Browse files
committed
Revert "Enhance machine clean-up"
This reverts commit 7f93e96.
1 parent a021da4 commit da86834

13 files changed

+165
-46
lines changed

internal/controllers/controllers_suite_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,22 +268,18 @@ func updateMachine(machine *api.Machine) (*api.Machine, error) {
268268

269269
func cleanupMachine(machineID string) func(SpecContext) {
270270
return func(ctx SpecContext) {
271-
By(fmt.Sprintf("Cleaning up machine ID=%s", machineID))
272-
Eventually(func(g Gomega) error {
273-
err := deleteMachine(machineID)
274-
GinkgoWriter.Printf("Deleting machine ID=%s: err=%v\n", machineID, err)
275-
if success, _ := MatchError(ContainSubstring("no such file or directory")).Match(err); success {
276-
return nil
277-
}
278-
return err
279-
}).Should(Succeed())
280-
271+
By(fmt.Sprintf("cleaning up machine ID=%s", machineID))
272+
err := deleteMachine(machineID)
273+
Expect(err).To(SatisfyAny(
274+
BeNil(),
275+
MatchError(ContainSubstring("NotFound")),
276+
))
281277
Eventually(func(g Gomega) bool {
282-
_, err := libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(machineID))
278+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(machineID))
283279
if err != nil {
284280
GinkgoWriter.Printf("Checking if domain still exists for machine ID=%s: err=%v\n", machineID, err)
285281
}
286282
return libvirt.IsNotFound(err)
287-
}).WithPolling(time.Second).Should(BeTrue())
283+
}).Should(BeTrue())
288284
}
289285
}

internal/server/integration/event_list_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ var _ = Describe("ListEvents", func() {
3636
Expect(err).NotTo(HaveOccurred())
3737
Expect(createResp).NotTo(BeNil())
3838

39-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
39+
DeferCleanup(func(ctx SpecContext) {
40+
Eventually(func(g Gomega) bool {
41+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
42+
g.Expect(err).To(SatisfyAny(
43+
BeNil(),
44+
MatchError(ContainSubstring("NotFound")),
45+
))
46+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
47+
return libvirt.IsNotFound(err)
48+
}).Should(BeTrue())
49+
})
4050

4151
By("ensuring domain and domain XML is created for machine")
4252
var domain libvirt.Domain

internal/server/integration/exec_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ var _ = Describe("Exec", func() {
3737
Expect(err).NotTo(HaveOccurred())
3838
Expect(createResp).NotTo(BeNil())
3939

40-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
40+
DeferCleanup(func(ctx SpecContext) {
41+
Eventually(func(g Gomega) bool {
42+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
43+
g.Expect(err).To(SatisfyAny(
44+
BeNil(),
45+
MatchError(ContainSubstring("NotFound")),
46+
))
47+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
48+
return libvirt.IsNotFound(err)
49+
}).Should(BeTrue())
50+
})
4151

4252
By("ensuring domain and domain XML is created for machine")
4353
var domain libvirt.Domain

internal/server/integration/machine_annotations_update_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ var _ = Describe("UpdateMachineAnnotations", func() {
3535
Expect(err).NotTo(HaveOccurred())
3636
Expect(createResp).NotTo(BeNil())
3737

38-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
38+
DeferCleanup(func(ctx SpecContext) {
39+
Eventually(func(g Gomega) bool {
40+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
41+
g.Expect(err).To(SatisfyAny(
42+
BeNil(),
43+
MatchError(ContainSubstring("NotFound")),
44+
))
45+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
46+
return libvirt.IsNotFound(err)
47+
}).Should(BeTrue())
48+
})
3949

4050
By("ensuring domain and domain XML is created for machine")
4151
var domain libvirt.Domain

internal/server/integration/machine_create_test.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ var _ = Describe("CreateMachine", func() {
3333
Expect(err).NotTo(HaveOccurred())
3434
Expect(createResp).NotTo(BeNil())
3535

36-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
37-
3836
By("ensuring the correct creation response")
3937
Expect(createResp).Should(SatisfyAll(
4038
HaveField("Machine.Metadata.Id", Not(BeEmpty())),
@@ -50,6 +48,18 @@ var _ = Describe("CreateMachine", func() {
5048
HaveField("Machine.Status.NetworkInterfaces", BeNil()),
5149
))
5250

51+
DeferCleanup(func(ctx SpecContext) {
52+
Eventually(func(g Gomega) bool {
53+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
54+
g.Expect(err).To(SatisfyAny(
55+
BeNil(),
56+
MatchError(ContainSubstring("NotFound")),
57+
))
58+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
59+
return libvirt.IsNotFound(err)
60+
}).Should(BeTrue())
61+
})
62+
5363
By("ensuring domain and domain XML is created for machine")
5464
var domain libvirt.Domain
5565
Eventually(func() error {
@@ -142,7 +152,17 @@ var _ = Describe("CreateMachine", func() {
142152
HaveField("Machine.Status.NetworkInterfaces", BeNil()),
143153
))
144154

145-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
155+
DeferCleanup(func(ctx SpecContext) {
156+
Eventually(func(g Gomega) bool {
157+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
158+
g.Expect(err).To(SatisfyAny(
159+
BeNil(),
160+
MatchError(ContainSubstring("NotFound")),
161+
))
162+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
163+
return libvirt.IsNotFound(err)
164+
}).Should(BeTrue())
165+
})
146166

147167
By("ensuring domain and domain XML is created for machine")
148168
var domain libvirt.Domain
@@ -231,8 +251,6 @@ var _ = Describe("CreateMachine", func() {
231251
Expect(err).NotTo(HaveOccurred())
232252
Expect(createResp).NotTo(BeNil())
233253

234-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
235-
236254
By("ensuring the correct creation response")
237255
Expect(createResp).Should(SatisfyAll(
238256
HaveField("Machine.Metadata.Id", Not(BeEmpty())),
@@ -267,6 +285,18 @@ var _ = Describe("CreateMachine", func() {
267285
HaveField("Machine.Status.NetworkInterfaces", BeNil()),
268286
))
269287

288+
DeferCleanup(func(ctx SpecContext) {
289+
Eventually(func(g Gomega) bool {
290+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
291+
g.Expect(err).To(SatisfyAny(
292+
BeNil(),
293+
MatchError(ContainSubstring("NotFound")),
294+
))
295+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
296+
return libvirt.IsNotFound(err)
297+
}).Should(BeTrue())
298+
})
299+
270300
By("ensuring domain and domain XML is created for machine")
271301
var domain libvirt.Domain
272302
Eventually(func() error {
@@ -360,8 +390,6 @@ var _ = Describe("CreateMachine", func() {
360390
Expect(err).NotTo(HaveOccurred())
361391
Expect(createResp).NotTo(BeNil())
362392

363-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
364-
365393
By("ensuring the correct creation response")
366394
Expect(createResp).Should(SatisfyAll(
367395
HaveField("Machine.Metadata.Id", Not(BeEmpty())),
@@ -402,6 +430,18 @@ var _ = Describe("CreateMachine", func() {
402430
HaveField("Machine.Status.NetworkInterfaces", BeNil()),
403431
))
404432

433+
DeferCleanup(func(ctx SpecContext) {
434+
Eventually(func(g Gomega) bool {
435+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
436+
g.Expect(err).To(SatisfyAny(
437+
BeNil(),
438+
MatchError(ContainSubstring("NotFound")),
439+
))
440+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
441+
return libvirt.IsNotFound(err)
442+
}).Should(BeTrue())
443+
})
444+
405445
By("ensuring domain and domain XML is created for machine")
406446
var domain libvirt.Domain
407447
Eventually(func() error {

internal/server/integration/machine_list_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ var _ = Describe("ListMachine", func() {
4141
Expect(err).NotTo(HaveOccurred())
4242
Expect(createResp).NotTo(BeNil())
4343

44-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
44+
DeferCleanup(func(ctx SpecContext) {
45+
Eventually(func(g Gomega) bool {
46+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
47+
g.Expect(err).To(SatisfyAny(
48+
BeNil(),
49+
MatchError(ContainSubstring("NotFound")),
50+
))
51+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
52+
return libvirt.IsNotFound(err)
53+
}).Should(BeTrue())
54+
})
4555

4656
By("ensuring domain and domain XML is created for machine")
4757
var domain libvirt.Domain

internal/server/integration/machine_networkinterface_attach_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ var _ = Describe("AttachNetworkInterface", func() {
4545
Expect(err).NotTo(HaveOccurred())
4646
Expect(createResp).NotTo(BeNil())
4747

48-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
48+
DeferCleanup(func(ctx SpecContext) {
49+
Eventually(func(g Gomega) bool {
50+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
51+
g.Expect(err).To(SatisfyAny(
52+
BeNil(),
53+
MatchError(ContainSubstring("NotFound")),
54+
))
55+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
56+
return libvirt.IsNotFound(err)
57+
}).Should(BeTrue())
58+
})
4959

5060
By("ensuring domain and domain XML is created for machine")
5161
var domain libvirt.Domain

internal/server/integration/machine_networkinterface_detach_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,17 @@ var _ = Describe("DetachNetworkInterface", func() {
6363
Expect(err).NotTo(HaveOccurred())
6464
Expect(createResp).NotTo(BeNil())
6565

66-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
66+
DeferCleanup(func(ctx SpecContext) {
67+
Eventually(func(g Gomega) bool {
68+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
69+
g.Expect(err).To(SatisfyAny(
70+
BeNil(),
71+
MatchError(ContainSubstring("NotFound")),
72+
))
73+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
74+
return libvirt.IsNotFound(err)
75+
}).Should(BeTrue())
76+
})
6777

6878
By("ensuring domain and domain XML is created for machine")
6979
var domain libvirt.Domain

internal/server/integration/machine_powerstate_update_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ var _ = Describe("UpdateMachinePower", func() {
3636
Expect(err).NotTo(HaveOccurred())
3737
Expect(createResp).NotTo(BeNil())
3838

39-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
39+
DeferCleanup(func(ctx SpecContext) {
40+
Eventually(func(g Gomega) bool {
41+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
42+
g.Expect(err).To(SatisfyAny(
43+
BeNil(),
44+
MatchError(ContainSubstring("NotFound")),
45+
))
46+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
47+
return libvirt.IsNotFound(err)
48+
}).Should(BeTrue())
49+
})
4050

4151
By("ensuring domain and domain XML is created for machine")
4252
var domain libvirt.Domain

internal/server/integration/machine_volume_attach_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ var _ = Describe("AttachVolume", func() {
4646
Expect(err).NotTo(HaveOccurred())
4747
Expect(createResp).NotTo(BeNil())
4848

49-
DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id))
49+
DeferCleanup(func(ctx SpecContext) {
50+
Eventually(func(g Gomega) bool {
51+
_, err := machineClient.DeleteMachine(ctx, &iri.DeleteMachineRequest{MachineId: createResp.Machine.Metadata.Id})
52+
g.Expect(err).To(SatisfyAny(
53+
BeNil(),
54+
MatchError(ContainSubstring("NotFound")),
55+
))
56+
_, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(createResp.Machine.Metadata.Id))
57+
return libvirt.IsNotFound(err)
58+
}).Should(BeTrue())
59+
})
5060

5161
By("ensuring domain and domain XML is created for machine")
5262
var domain libvirt.Domain

0 commit comments

Comments
 (0)