Skip to content

Commit b2963ff

Browse files
committed
Update tests to account for updated awsmachine reconciliation behavior
1 parent 8d4f47f commit b2963ff

File tree

5 files changed

+26
-66
lines changed

5 files changed

+26
-66
lines changed

controllers/awscluster_controller_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
275275
mockedDeleteVPCCallsForNonExistentVPC(m)
276276
mockedDeleteLBCalls(true, ev2, e)
277277
mockedDescribeInstanceCall(m)
278-
mockedDeleteInstanceCalls(m)
278+
mockedDeleteInstanceAndAwaitTerminationCalls(m)
279279
}
280280
expect(ec2Mock.EXPECT(), elbv2Mock.EXPECT(), elbMock.EXPECT())
281281

@@ -347,7 +347,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
347347
mockedDeleteVPCCalls(m)
348348
mockedDescribeInstanceCall(m)
349349
mockedDeleteLBCalls(true, ev2, e)
350-
mockedDeleteInstanceCalls(m)
350+
mockedDeleteInstanceAndAwaitTerminationCalls(m)
351351
mockedDeleteSGCalls(m)
352352
}
353353
expect(ec2Mock.EXPECT(), elbv2Mock.EXPECT(), elbMock.EXPECT())
@@ -497,19 +497,25 @@ func mockedDescribeInstanceCall(m *mocks.MockEC2APIMockRecorder) {
497497
}, nil)
498498
}
499499

500-
func mockedDeleteInstanceCalls(m *mocks.MockEC2APIMockRecorder) {
500+
func mockedDeleteInstanceAndAwaitTerminationCalls(m *mocks.MockEC2APIMockRecorder) {
501501
m.TerminateInstances(
502502
gomock.Eq(&ec2.TerminateInstancesInput{
503503
InstanceIds: aws.StringSlice([]string{"id-1"}),
504504
}),
505-
).
506-
Return(nil, nil)
505+
).Return(nil, nil)
507506
m.WaitUntilInstanceTerminated(
508507
gomock.Eq(&ec2.DescribeInstancesInput{
509508
InstanceIds: aws.StringSlice([]string{"id-1"}),
510509
}),
511-
).
512-
Return(nil)
510+
).Return(nil)
511+
}
512+
513+
func mockedDeleteInstanceCalls(m *mocks.MockEC2APIMockRecorder) {
514+
m.TerminateInstances(
515+
gomock.Eq(&ec2.TerminateInstancesInput{
516+
InstanceIds: aws.StringSlice([]string{"id-1"}),
517+
}),
518+
).Return(nil, nil)
513519
}
514520

515521
func mockedCreateVPCCalls(m *mocks.MockEC2APIMockRecorder) {

controllers/awsmachine_controller_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,6 @@ func mockedCreateInstanceCalls(m *mocks.MockEC2APIMockRecorder) {
581581
},
582582
},
583583
}, nil)
584-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
585-
Return(nil)
586584
m.DescribeNetworkInterfaces(gomock.Eq(&ec2.DescribeNetworkInterfacesInput{Filters: []*ec2.Filter{
587585
{
588586
Name: aws.String("attachment.instance-id"),

controllers/awsmachine_controller_unit_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ func TestAWSMachineReconciler(t *testing.T) {
391391
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).Times(1)
392392
instance.State = infrav1.InstanceStatePending
393393
_, _ = reconciler.reconcileNormal(context.Background(), ms, cs, cs, cs, cs)
394+
394395
g.Expect(ms.AWSMachine.Status.InstanceState).To(PointTo(Equal(infrav1.InstanceStatePending)))
395396
g.Expect(ms.AWSMachine.Status.Ready).To(Equal(false))
396397
g.Expect(buf.String()).To(ContainSubstring(("EC2 instance state changed")))
@@ -410,6 +411,7 @@ func TestAWSMachineReconciler(t *testing.T) {
410411
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).Times(1)
411412
instance.State = infrav1.InstanceStateRunning
412413
_, _ = reconciler.reconcileNormal(context.Background(), ms, cs, cs, cs, cs)
414+
413415
g.Expect(ms.AWSMachine.Status.InstanceState).To(PointTo(Equal(infrav1.InstanceStateRunning)))
414416
g.Expect(ms.AWSMachine.Status.Ready).To(Equal(true))
415417
g.Expect(buf.String()).To(ContainSubstring(("EC2 instance state changed")))
@@ -1081,7 +1083,7 @@ func TestAWSMachineReconciler(t *testing.T) {
10811083

10821084
instance.State = infrav1.InstanceStateRunning
10831085
secretSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(1)
1084-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1086+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
10851087
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
10861088
})
10871089

@@ -1094,7 +1096,7 @@ func TestAWSMachineReconciler(t *testing.T) {
10941096

10951097
ms.AWSMachine.Status.FailureReason = capierrors.MachineStatusErrorPtr(capierrors.UpdateMachineError)
10961098
secretSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(1)
1097-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1099+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
10981100
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
10991101
})
11001102
t.Run("should not attempt to delete the secret if InsecureSkipSecretsManager is set on CloudInit", func(t *testing.T) {
@@ -1107,7 +1109,7 @@ func TestAWSMachineReconciler(t *testing.T) {
11071109
ms.AWSMachine.Spec.CloudInit.InsecureSkipSecretsManager = true
11081110

11091111
secretSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(0)
1110-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1112+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
11111113

11121114
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
11131115
})
@@ -1167,7 +1169,7 @@ func TestAWSMachineReconciler(t *testing.T) {
11671169

11681170
instance.State = infrav1.InstanceStateRunning
11691171
secretSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(1)
1170-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1172+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
11711173
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
11721174
})
11731175

@@ -1180,7 +1182,7 @@ func TestAWSMachineReconciler(t *testing.T) {
11801182

11811183
ms.AWSMachine.Status.FailureReason = capierrors.MachineStatusErrorPtr(capierrors.UpdateMachineError)
11821184
secretSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(1)
1183-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1185+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
11841186
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
11851187
})
11861188
})
@@ -1348,7 +1350,7 @@ func TestAWSMachineReconciler(t *testing.T) {
13481350

13491351
instance.State = infrav1.InstanceStateRunning
13501352
objectStoreSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(1)
1351-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1353+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
13521354

13531355
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
13541356
})
@@ -1365,7 +1367,7 @@ func TestAWSMachineReconciler(t *testing.T) {
13651367
ms.AWSMachine.Status.FailureReason = capierrors.MachineStatusErrorPtr(capierrors.UpdateMachineError)
13661368

13671369
objectStoreSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(1)
1368-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1370+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
13691371

13701372
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
13711373
})
@@ -1429,7 +1431,7 @@ func TestAWSMachineReconciler(t *testing.T) {
14291431

14301432
instance.State = infrav1.InstanceStateRunning
14311433
objectStoreSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(1)
1432-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1434+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
14331435
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
14341436
})
14351437

@@ -1444,7 +1446,7 @@ func TestAWSMachineReconciler(t *testing.T) {
14441446
// TODO: This seems to have no effect on the test result.
14451447
ms.AWSMachine.Status.FailureReason = capierrors.MachineStatusErrorPtr(capierrors.UpdateMachineError)
14461448
objectStoreSvc.EXPECT().Delete(gomock.Any()).Return(nil).Times(1)
1447-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil).AnyTimes()
1449+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil).AnyTimes()
14481450
_, _ = reconciler.reconcileDelete(ms, cs, cs, cs, cs)
14491451
})
14501452
})
@@ -1572,7 +1574,7 @@ func TestAWSMachineReconciler(t *testing.T) {
15721574
getRunningInstance(t, g)
15731575

15741576
expected := errors.New("can't reach AWS to terminate machine")
1575-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(expected)
1577+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(expected)
15761578

15771579
buf := new(bytes.Buffer)
15781580
klog.SetOutput(buf)
@@ -1585,7 +1587,7 @@ func TestAWSMachineReconciler(t *testing.T) {
15851587
t.Run("when instance can be shut down", func(t *testing.T) {
15861588
terminateInstance := func(t *testing.T, g *WithT) {
15871589
t.Helper()
1588-
ec2Svc.EXPECT().TerminateInstanceAndWait(gomock.Any()).Return(nil)
1590+
ec2Svc.EXPECT().TerminateInstance(gomock.Any()).Return(nil)
15891591
secretSvc.EXPECT().Delete(gomock.Any()).Return(nil).AnyTimes()
15901592
}
15911593

pkg/cloud/services/ec2/bastion_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ func TestServiceReconcileBastion(t *testing.T) {
366366
},
367367
},
368368
}, nil)
369-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
370-
Return(nil)
371369
},
372370
bastionEnabled: true,
373371
expectError: false,

pkg/cloud/services/ec2/instances_test.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,6 @@ func TestCreateInstance(t *testing.T) {
385385
},
386386
},
387387
}, nil)
388-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
389-
Return(nil)
390388
m.
391389
DescribeNetworkInterfaces(gomock.Any()).
392390
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -497,9 +495,6 @@ func TestCreateInstance(t *testing.T) {
497495
},
498496
},
499497
}, nil)
500-
501-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
502-
Return(nil)
503498
m.
504499
DescribeNetworkInterfaces(gomock.Any()).
505500
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -637,9 +632,6 @@ func TestCreateInstance(t *testing.T) {
637632
},
638633
},
639634
}, nil)
640-
641-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
642-
Return(nil)
643635
m.
644636
DescribeNetworkInterfaces(gomock.Any()).
645637
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -773,9 +765,6 @@ func TestCreateInstance(t *testing.T) {
773765
},
774766
},
775767
}, nil)
776-
777-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
778-
Return(nil)
779768
m.
780769
DescribeNetworkInterfaces(gomock.Any()).
781770
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -910,9 +899,6 @@ func TestCreateInstance(t *testing.T) {
910899
},
911900
},
912901
}, nil)
913-
914-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
915-
Return(nil)
916902
m.
917903
DescribeNetworkInterfaces(gomock.Any()).
918904
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -1024,8 +1010,6 @@ func TestCreateInstance(t *testing.T) {
10241010
},
10251011
},
10261012
}, nil)
1027-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
1028-
Return(nil)
10291013
m.
10301014
DescribeNetworkInterfaces(gomock.Any()).
10311015
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -1136,8 +1120,6 @@ func TestCreateInstance(t *testing.T) {
11361120
},
11371121
},
11381122
}, nil)
1139-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
1140-
Return(nil)
11411123
m.
11421124
DescribeNetworkInterfaces(gomock.Any()).
11431125
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -1323,8 +1305,6 @@ func TestCreateInstance(t *testing.T) {
13231305
},
13241306
},
13251307
}, nil)
1326-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
1327-
Return(nil)
13281308
m.
13291309
DescribeNetworkInterfaces(gomock.Any()).
13301310
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -1585,8 +1565,6 @@ func TestCreateInstance(t *testing.T) {
15851565
},
15861566
},
15871567
}, nil)
1588-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
1589-
Return(nil)
15901568
m.
15911569
DescribeNetworkInterfaces(gomock.Any()).
15921570
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -1790,8 +1768,6 @@ func TestCreateInstance(t *testing.T) {
17901768
},
17911769
},
17921770
}, nil)
1793-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
1794-
Return(nil)
17951771
m.
17961772
DescribeNetworkInterfaces(gomock.Any()).
17971773
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -1893,8 +1869,6 @@ func TestCreateInstance(t *testing.T) {
18931869
},
18941870
},
18951871
}, nil)
1896-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
1897-
Return(nil)
18981872
m.
18991873
DescribeNetworkInterfaces(gomock.Any()).
19001874
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -2067,8 +2041,6 @@ func TestCreateInstance(t *testing.T) {
20672041
},
20682042
},
20692043
}, nil)
2070-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
2071-
Return(nil)
20722044
m.
20732045
DescribeNetworkInterfaces(gomock.Any()).
20742046
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -2208,8 +2180,6 @@ func TestCreateInstance(t *testing.T) {
22082180
},
22092181
},
22102182
}, nil)
2211-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
2212-
Return(nil)
22132183
m.
22142184
DescribeNetworkInterfaces(gomock.Any()).
22152185
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -2351,8 +2321,6 @@ func TestCreateInstance(t *testing.T) {
23512321
},
23522322
},
23532323
}, nil)
2354-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
2355-
Return(nil)
23562324
m.
23572325
DescribeNetworkInterfaces(gomock.Any()).
23582326
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -2465,8 +2433,6 @@ func TestCreateInstance(t *testing.T) {
24652433
},
24662434
}, nil
24672435
})
2468-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
2469-
Return(nil)
24702436
m.
24712437
DescribeNetworkInterfaces(gomock.Any()).
24722438
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -2580,8 +2546,6 @@ func TestCreateInstance(t *testing.T) {
25802546
},
25812547
}, nil
25822548
})
2583-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
2584-
Return(nil)
25852549
m.
25862550
DescribeNetworkInterfaces(gomock.Any()).
25872551
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -2696,8 +2660,6 @@ func TestCreateInstance(t *testing.T) {
26962660
},
26972661
}, nil
26982662
})
2699-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
2700-
Return(nil)
27012663
m.
27022664
DescribeNetworkInterfaces(gomock.Any()).
27032665
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -2809,8 +2771,6 @@ func TestCreateInstance(t *testing.T) {
28092771
},
28102772
}, nil
28112773
})
2812-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
2813-
Return(nil)
28142774
m.
28152775
DescribeNetworkInterfaces(gomock.Any()).
28162776
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -2922,8 +2882,6 @@ func TestCreateInstance(t *testing.T) {
29222882
},
29232883
}, nil
29242884
})
2925-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
2926-
Return(nil)
29272885
m.
29282886
DescribeNetworkInterfaces(gomock.Any()).
29292887
Return(&ec2.DescribeNetworkInterfacesOutput{
@@ -3035,8 +2993,6 @@ func TestCreateInstance(t *testing.T) {
30352993
},
30362994
}, nil
30372995
})
3038-
m.WaitUntilInstanceRunningWithContext(gomock.Any(), gomock.Any(), gomock.Any()).
3039-
Return(nil)
30402996
m.
30412997
DescribeNetworkInterfaces(gomock.Any()).
30422998
Return(&ec2.DescribeNetworkInterfacesOutput{

0 commit comments

Comments
 (0)