@@ -20,9 +20,11 @@ import (
2020 "fmt"
2121 "net/http"
2222 "testing"
23+ "time"
2324
2425 "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
2526 "github.com/Azure/go-autorest/autorest"
27+ "github.com/Azure/go-autorest/autorest/to"
2628 "github.com/stretchr/testify/assert"
2729 "github.com/stretchr/testify/mock"
2830
@@ -97,6 +99,60 @@ func TestIncreaseSize(t *testing.T) {
9799 assert .Equal (t , 5 , targetSize )
98100}
99101
102+ func TestIncreaseSizeOnVMSSUpdating (t * testing.T ) {
103+ manager := newTestAzureManager (t )
104+ vmssName := "vmss-updating"
105+ var vmssCapacity int64 = 3
106+ scaleSetClient := & VirtualMachineScaleSetsClientMock {
107+ FakeStore : map [string ]map [string ]compute.VirtualMachineScaleSet {
108+ "test" : {
109+ vmssName : {
110+ Name : & vmssName ,
111+ Sku : & compute.Sku {
112+ Capacity : & vmssCapacity ,
113+ },
114+ VirtualMachineScaleSetProperties : & compute.VirtualMachineScaleSetProperties {
115+ ProvisioningState : to .StringPtr (string (compute .ProvisioningStateUpdating )),
116+ },
117+ },
118+ },
119+ },
120+ }
121+ manager .azClient .virtualMachineScaleSetsClient = scaleSetClient
122+ registered := manager .RegisterAsg (newTestScaleSet (manager , vmssName ))
123+ assert .True (t , registered )
124+ manager .regenerateCache ()
125+
126+ provider , err := BuildAzureCloudProvider (manager , nil )
127+ assert .NoError (t , err )
128+
129+ // Scaling should fail because VMSS is still under updating.
130+ scaleSet , ok := provider .NodeGroups ()[0 ].(* ScaleSet )
131+ assert .True (t , ok )
132+ err = scaleSet .IncreaseSize (1 )
133+ assert .Equal (t , fmt .Errorf ("VMSS %q is still under updating" , scaleSet .Name ), err )
134+
135+ // Scaling should succeed after VMSS ProvisioningState changed to succeeded.
136+ scaleSetClient .FakeStore = map [string ]map [string ]compute.VirtualMachineScaleSet {
137+ "test" : {
138+ vmssName : {
139+ Name : & vmssName ,
140+ Sku : & compute.Sku {
141+ Capacity : & vmssCapacity ,
142+ },
143+ VirtualMachineScaleSetProperties : & compute.VirtualMachineScaleSetProperties {
144+ ProvisioningState : to .StringPtr (string (compute .ProvisioningStateSucceeded )),
145+ },
146+ },
147+ },
148+ }
149+ scaleSetStatusCache .mutex .Lock ()
150+ scaleSetStatusCache .lastRefresh = time .Now ().Add (- 1 * scaleSet .sizeRefreshPeriod )
151+ scaleSetStatusCache .mutex .Unlock ()
152+ err = scaleSet .IncreaseSize (1 )
153+ assert .NoError (t , err )
154+ }
155+
100156func TestBelongs (t * testing.T ) {
101157 provider := newTestProvider (t )
102158 registered := provider .azureManager .RegisterAsg (
0 commit comments