Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Jan 10, 2024
1 parent aeedcf3 commit 3af1015
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func newTestAzureManager(t *testing.T) *AzureManager {
VMType: vmTypeVMSS,
MaxDeploymentsCount: 2,
Deployment: "deployment",
EnableForceDelete: true,
},
azClient: &azClient{
virtualMachineScaleSetsClient: mockVMSSClient,
Expand Down
3 changes: 1 addition & 2 deletions cluster-autoscaler/cloudprovider/azure/azure_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,7 @@ func (scaleSet *ScaleSet) DeleteInstances(instances []*azureRef, hasUnregistered
resourceGroup := scaleSet.manager.config.ResourceGroup

scaleSet.instanceMutex.Lock()
klog.V(3).Infof("Calling virtualMachineScaleSetsClient.DeleteInstancesAsync(%v)", requiredIds.InstanceIds)
klog.Infof("ForceDelete option is set to %v", scaleSet.enableForceDelete)
klog.V(3).Infof("Calling virtualMachineScaleSetsClient.DeleteInstancesAsync(%v), force delete set to %v", requiredIds.InstanceIds, scaleSet.enableForceDelete)
future, rerr := scaleSet.manager.azClient.virtualMachineScaleSetsClient.DeleteInstancesAsync(ctx, resourceGroup, commonAsg.Id(), *requiredIds, scaleSet.enableForceDelete)

if scaleSet.enableForceDelete && isOperationNotAllowed(rerr) {
Expand Down
41 changes: 35 additions & 6 deletions cluster-autoscaler/cloudprovider/azure/azure_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,18 +406,48 @@ func TestDeleteNodes(t *testing.T) {

vmssName := "test-asg"
var vmssCapacity int64 = 3
orchestrationModes := [2]compute.OrchestrationMode{compute.Uniform, compute.Flexible}
expectedVMSSVMs := newTestVMSSVMList(3)
expectedVMs := newTestVMList(3)
cases := []struct {
name string
orchestrationMode compute.OrchestrationMode
enableForceDelete bool
}{
{
name: "uniform, force delete enabled",
orchestrationMode: compute.Uniform,
enableForceDelete: true,
},
{
name: "uniform, force delete disabled",
orchestrationMode: compute.Uniform,
enableForceDelete: false,
},
{
name: "flexible, force delete enabled",
orchestrationMode: compute.Flexible,
enableForceDelete: true,
},
{
name: "flexible, force delete disabled",
orchestrationMode: compute.Flexible,
enableForceDelete: false,
},
}

for _, orchMode := range orchestrationModes {
for _, tc := range cases {
orchMode := tc.orchestrationMode
enableForceDelete := tc.enableForceDelete

expectedVMSSVMs := newTestVMSSVMList(3)
expectedVMs := newTestVMList(3)

manager := newTestAzureManager(t)
manager.config.EnableForceDelete = enableForceDelete
expectedScaleSets := newTestVMSSList(vmssCapacity, vmssName, "eastus", orchMode)
fmt.Printf("orchMode: %s, enableForceDelete: %t\n", orchMode, enableForceDelete)

mockVMSSClient := mockvmssclient.NewMockInterface(ctrl)
mockVMSSClient.EXPECT().List(gomock.Any(), manager.config.ResourceGroup).Return(expectedScaleSets, nil).Times(2)
mockVMSSClient.EXPECT().DeleteInstancesAsync(gomock.Any(), manager.config.ResourceGroup, gomock.Any(), gomock.Any(), false).Return(nil, nil)
mockVMSSClient.EXPECT().DeleteInstancesAsync(gomock.Any(), manager.config.ResourceGroup, gomock.Any(), gomock.Any(), enableForceDelete).Return(nil, nil)
mockVMSSClient.EXPECT().WaitForDeleteInstancesResult(gomock.Any(), gomock.Any(), manager.config.ResourceGroup).Return(&http.Response{StatusCode: http.StatusOK}, nil).AnyTimes()
manager.azClient.virtualMachineScaleSetsClient = mockVMSSClient

Expand Down Expand Up @@ -498,7 +528,6 @@ func TestDeleteNodes(t *testing.T) {
instance2, found := scaleSet.getInstanceByProviderID(nodesToDelete[1].Spec.ProviderID)
assert.True(t, found, true)
assert.Equal(t, instance2.Status.State, cloudprovider.InstanceDeleting)

}
}

Expand Down

0 comments on commit 3af1015

Please sign in to comment.