Skip to content

Commit a1a97d6

Browse files
Merge pull request #366 from huali9/machinemigration
OCPCLOUD-2992: machine migration round trip test
2 parents 140a1fa + 3967370 commit a1a97d6

File tree

3 files changed

+241
-4
lines changed

3 files changed

+241
-4
lines changed

e2e/machine_migration_capi_authoritative_test.go

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
131131
})
132132
It("should verify the AWS machine is deleted", func() {
133133
verifyResourceRemoved(&awsv1.AWSMachine{
134-
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
134+
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
135135
ObjectMeta: metav1.ObjectMeta{Name: mapiMachineAuthCAPINameDeletion, Namespace: capiframework.CAPINamespace},
136136
})
137137
})
@@ -161,11 +161,141 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
161161
})
162162
It("should verify the AWS machine is deleted", func() {
163163
verifyResourceRemoved(&awsv1.AWSMachine{
164-
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
164+
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
165165
ObjectMeta: metav1.ObjectMeta{Name: mapiMachineAuthCAPINameDeletion, Namespace: capiframework.CAPINamespace},
166166
})
167167
})
168168
})
169169
})
170170
})
171+
172+
var _ = Describe("Machine Migration Round Trip Tests", Ordered, func() {
173+
var capiMapiCapiRoundTripName = "machine-capi-mapi-capi-roundtrip"
174+
var newMapiMachine *mapiv1beta1.Machine
175+
var newCapiMachine *clusterv1.Machine
176+
177+
Context("CAPI (and no existing CAPI Machine with same name) -> MAPI -> CAPI round trip", func() {
178+
BeforeAll(func() {
179+
By("Creating a MAPI machine with spec.authoritativeAPI: ClusterAPI and no existing CAPI Machine with same name")
180+
newMapiMachine = createMAPIMachineWithAuthority(ctx, cl, capiMapiCapiRoundTripName, mapiv1beta1.MachineAuthorityClusterAPI)
181+
DeferCleanup(func() {
182+
By("Cleaning up machine resources")
183+
cleanupMachineResources(
184+
ctx,
185+
cl,
186+
[]*clusterv1.Machine{newCapiMachine},
187+
[]*mapiv1beta1.Machine{newMapiMachine},
188+
)
189+
})
190+
})
191+
192+
It("should create a CAPI mirror machine", func() {
193+
newCapiMachine = capiframework.GetMachine(cl, capiMapiCapiRoundTripName, capiframework.CAPINamespace)
194+
verifyMachineRunning(cl, newCapiMachine)
195+
})
196+
197+
It("should set the paused conditions and synchronised generation correctly", func() {
198+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
199+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
200+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
201+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
202+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
203+
})
204+
205+
It("should set the paused conditions and synchronised generation correctly after changing spec.authoritativeAPI: MachineAPI", func() {
206+
By("Updating spec.authoritativeAPI: MachineAPI")
207+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
208+
verifyMachineRunning(cl, newMapiMachine)
209+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
210+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
211+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
212+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
213+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
214+
})
215+
216+
It("should set the paused conditions and synchronised generation correctly after changing back spec.authoritativeAPI: ClusterAPI", func() {
217+
By("Updating spec.authoritativeAPI: ClusterAPI")
218+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
219+
verifyMachineRunning(cl, newCapiMachine)
220+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
221+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
222+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
223+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
224+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
225+
})
226+
227+
It("should verify mirror machines are deleted when deleting CAPI machine", func() {
228+
By("Deleting CAPI machine")
229+
capiframework.DeleteMachines(ctx, cl, capiframework.CAPINamespace, newCapiMachine)
230+
verifyResourceRemoved(newMapiMachine)
231+
verifyResourceRemoved(newCapiMachine)
232+
verifyResourceRemoved(&awsv1.AWSMachine{
233+
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
234+
ObjectMeta: metav1.ObjectMeta{Name: capiMapiCapiRoundTripName, Namespace: capiframework.CAPINamespace},
235+
})
236+
})
237+
})
238+
239+
//The bug https://issues.redhat.com/browse/OCPBUGS-63183 cause instance leak on AWS so I have to comment all the code out.
240+
/*
241+
Context("CAPI (and already existing CAPI Machine with same name) -> MAPI -> CAPI round trip", func() {
242+
BeforeAll(func() {
243+
capiMapiCapiRoundTripName = "machine-capi-mapi-capi-roundtrip2"
244+
By("Creating a MAPI machine with spec.authoritativeAPI: ClusterAPI and already existing CAPI Machine with same name")
245+
newCapiMachine = createCAPIMachine(ctx, cl, capiMapiCapiRoundTripName)
246+
newMapiMachine = createMAPIMachineWithAuthority(ctx, cl, capiMapiCapiRoundTripName, mapiv1beta1.MachineAuthorityClusterAPI)
247+
DeferCleanup(func() {
248+
By("Cleaning up machine resources")
249+
cleanupMachineResources(
250+
ctx,
251+
cl,
252+
[]*clusterv1.Machine{newCapiMachine},
253+
[]*mapiv1beta1.Machine{newMapiMachine},
254+
)
255+
})
256+
})
257+
258+
It("should set the paused conditions and synchronised generation correctly", func() {
259+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
260+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
261+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
262+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
263+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
264+
})
265+
266+
//MAPI machine phase is null https://issues.redhat.com/browse/OCPBUGS-63183
267+
PIt("should set the paused conditions and synchronised generation correctly after changing spec.authoritativeAPI: MachineAPI", func() {
268+
By("Updating spec.authoritativeAPI: MachineAPI")
269+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
270+
verifyMachineRunning(cl, newMapiMachine)
271+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
272+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
273+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
274+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
275+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
276+
})
277+
278+
It("should set the paused conditions and synchronised generation correctly after changing back spec.authoritativeAPI: ClusterAPI", func() {
279+
By("Updating spec.authoritativeAPI: ClusterAPI")
280+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
281+
verifyMachineRunning(cl, newCapiMachine)
282+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
283+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
284+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
285+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
286+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
287+
})
288+
289+
It("should verify mirror machines are deleted when deleting CAPI machine", func() {
290+
By("Deleting CAPI machine")
291+
capiframework.DeleteMachines(ctx, cl, capiframework.CAPINamespace, newCapiMachine)
292+
verifyResourceRemoved(newMapiMachine)
293+
verifyResourceRemoved(newCapiMachine)
294+
verifyResourceRemoved(&awsv1.AWSMachine{
295+
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
296+
ObjectMeta: metav1.ObjectMeta{Name: capiMapiCapiRoundTripName, Namespace: capiframework.CAPINamespace},
297+
})
298+
})
299+
})*/
300+
})
171301
})

e2e/machine_migration_helpers.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,40 @@ func cleanupMachineResources(ctx context.Context, cl client.Client, capiMachines
287287
mapiframework.WaitForMachinesDeleted(cl, m)
288288
}
289289
}
290+
291+
func updateMachineAuthoritativeAPI(mapiMachine *mapiv1beta1.Machine, newAuthority mapiv1beta1.MachineAuthority) {
292+
Eventually(komega.Update(mapiMachine, func() {
293+
mapiMachine.Spec.AuthoritativeAPI = newAuthority
294+
}), capiframework.WaitShort, capiframework.RetryShort).Should(Succeed(), "Failed to update MAPI Machine AuthoritativeAPI to %s", newAuthority)
295+
}
296+
297+
func verifyMachineSynchronizedGeneration(cl client.Client, mapiMachine *mapiv1beta1.Machine, authority mapiv1beta1.MachineAuthority) {
298+
Eventually(komega.Object(mapiMachine), capiframework.WaitMedium, capiframework.RetryMedium).Should(
299+
HaveField("Status.SynchronizedGeneration", Not(BeZero())),
300+
"MAPI Machine SynchronizedGeneration should not be zero",
301+
)
302+
303+
var expectedGeneration int64
304+
var authoritativeMachineType string
305+
306+
switch authority {
307+
case mapiv1beta1.MachineAuthorityMachineAPI:
308+
authoritativeMachineType = "MAPI"
309+
expectedGeneration = mapiMachine.Generation
310+
case mapiv1beta1.MachineAuthorityClusterAPI:
311+
authoritativeMachineType = "CAPI"
312+
capiMachine := capiframework.GetMachine(cl, mapiMachine.Name, capiframework.CAPINamespace)
313+
Eventually(komega.Object(capiMachine)).Should(HaveField("Generation", Not(BeZero())))
314+
expectedGeneration = capiMachine.Generation
315+
default:
316+
Fail(fmt.Sprintf("unknown authoritativeAPI type: %v", authority))
317+
}
318+
319+
By(fmt.Sprintf("Verifying MAPI Machine SynchronizedGeneration (%d) equals %s Machine Generation (%d)",
320+
mapiMachine.Status.SynchronizedGeneration, authoritativeMachineType, expectedGeneration))
321+
322+
Eventually(komega.Object(mapiMachine), capiframework.WaitMedium, capiframework.RetryMedium).Should(
323+
HaveField("Status.SynchronizedGeneration", Equal(expectedGeneration)),
324+
fmt.Sprintf("MAPI Machine SynchronizedGeneration should equal %s Machine Generation (%d)", authoritativeMachineType, expectedGeneration),
325+
)
326+
}

e2e/machine_migration_mapi_authoritative_test.go

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
9595
})
9696
It("should verify the AWS machine is deleted", func() {
9797
verifyResourceRemoved(&awsv1.AWSMachine{
98-
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
98+
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
9999
ObjectMeta: metav1.ObjectMeta{Name: mapiMachineAuthMAPINameDeleteMAPIMachine, Namespace: capiframework.CAPINamespace},
100100
})
101101
})
@@ -125,11 +125,81 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
125125
})
126126
It("should verify the AWS machine is deleted", func() {
127127
verifyResourceRemoved(&awsv1.AWSMachine{
128-
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
128+
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
129129
ObjectMeta: metav1.ObjectMeta{Name: mapiMachineAuthMAPINameDeleteCAPIMachine, Namespace: capiframework.CAPINamespace},
130130
})
131131
})
132132
})
133133
})
134134
})
135+
136+
var _ = Describe("Machine Migration Round Trip Tests", Ordered, func() {
137+
var mapiCapiMapiRoundTripName = "machine-mapi-capi-mapi-roundtrip"
138+
var newMapiMachine *mapiv1beta1.Machine
139+
var newCapiMachine *clusterv1.Machine
140+
141+
Context("MAPI -> CAPI -> MAPI round trip", func() {
142+
BeforeAll(func() {
143+
By("Creating a MAPI machine with spec.authoritativeAPI: MachineAPI")
144+
newMapiMachine = createMAPIMachineWithAuthority(ctx, cl, mapiCapiMapiRoundTripName, mapiv1beta1.MachineAuthorityMachineAPI)
145+
verifyMachineRunning(cl, newMapiMachine)
146+
147+
DeferCleanup(func() {
148+
By("Cleaning up machine resources")
149+
cleanupMachineResources(
150+
ctx,
151+
cl,
152+
[]*clusterv1.Machine{newCapiMachine},
153+
[]*mapiv1beta1.Machine{newMapiMachine},
154+
)
155+
})
156+
})
157+
158+
It("should create a CAPI mirror machine", func() {
159+
newCapiMachine = capiframework.GetMachine(cl, mapiCapiMapiRoundTripName, capiframework.CAPINamespace)
160+
})
161+
162+
It("should set the paused conditions and synchronised generation correctly", func() {
163+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
164+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
165+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
166+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
167+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
168+
})
169+
170+
It("should set the paused conditions and synchronised generation correctly after changing spec.authoritativeAPI: ClusterAPI", func() {
171+
By("Updating spec.authoritativeAPI: ClusterAPI")
172+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
173+
verifyMachineRunning(cl, newCapiMachine)
174+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
175+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
176+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
177+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
178+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
179+
})
180+
181+
It("should set the paused conditions and synchronised generation correctly after changing back spec.authoritativeAPI: MachineAPI", func() {
182+
By("Updating spec.authoritativeAPI: MachineAPI")
183+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
184+
verifyMachineRunning(cl, newMapiMachine)
185+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
186+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
187+
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
188+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
189+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
190+
})
191+
192+
It("should verify mirror machines are deleted when deleting MAPI machine", func() {
193+
By("Deleting MAPI machine")
194+
mapiframework.DeleteMachines(ctx, cl, newMapiMachine)
195+
mapiframework.WaitForMachinesDeleted(cl, newMapiMachine)
196+
verifyResourceRemoved(newMapiMachine)
197+
verifyResourceRemoved(newCapiMachine)
198+
verifyResourceRemoved(&awsv1.AWSMachine{
199+
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
200+
ObjectMeta: metav1.ObjectMeta{Name: mapiCapiMapiRoundTripName, Namespace: capiframework.CAPINamespace},
201+
})
202+
})
203+
})
204+
})
135205
})

0 commit comments

Comments
 (0)