@@ -33,6 +33,11 @@ import (
3333 "github.com/tidwall/gjson"
3434)
3535
36+ const (
37+ configSaveMaxRetries = 5
38+ configSaveRetryWaitTimeout = 60
39+ )
40+
3641var _ resource.Resource = & InventoryDevicesResource {}
3742var _ resource.ResourceWithImportState = & InventoryDevicesResource {}
3843
@@ -254,7 +259,7 @@ func (r *InventoryDevicesResource) Create(ctx context.Context, req resource.Crea
254259 deleteDevicesFromInventory (ctx , r .client , & resp .Diagnostics , & stateData )
255260 return
256261 }
257- deployAndSaveWithRetry (ctx , r .client , & resp .Diagnostics , & planData , 5 , 60 )
262+ deployAndSaveWithRetry (ctx , r .client , & resp .Diagnostics , & planData )
258263 if resp .Diagnostics .HasError () {
259264 tflog .Debug (ctx , "Save and Deploy failed, deleting devices from inventory" )
260265 deleteDevicesFromInventory (ctx , r .client , & resp .Diagnostics , & planData )
@@ -1089,23 +1094,16 @@ func deployAndSave(ctx context.Context, client *ndfc.NDFC, diags *diag.Diagnosti
10891094 tflog .Debug (ctx , fmt .Sprintf ("End of %s deployAndSave" , loggingInventoryDevices ))
10901095}
10911096
1092- func deployAndSaveWithRetry (
1093- ctx context.Context ,
1094- client * ndfc.NDFC ,
1095- diags * diag.Diagnostics ,
1096- data * InventoryDevicesModel ,
1097- maxRetries int64 ,
1098- retryWaitTimeout int64 ,
1099- ) {
1097+ func deployAndSaveWithRetry (ctx context.Context , client * ndfc.NDFC , diags * diag.Diagnostics , data * InventoryDevicesModel ) {
11001098 tflog .Debug (ctx , fmt .Sprintf ("Start of %s deployAndSaveWithRetry" , loggingInventoryDevices ))
1101- // This retry mechanism is a fix for unexpected NDFC 12.2.2/ND4.1 behaviour where sometimes, recalculate (config-save) fails even if devices are reachable .
1102- for attempt := int64 ( 0 ); attempt < maxRetries ; attempt ++ {
1103- tflog . Debug ( ctx , fmt . Sprintf ( "This is attempt number: %d" , attempt + 1 ))
1099+ // This retry mechanism is a fix for unexpected NDFC 12.2.2/ND4.1 behaviour.
1100+ // Where sometimes, recalculate (config-save) fails even if the devices are reachable.
1101+ for attempt := 0 ; attempt < configSaveMaxRetries ; attempt ++ {
11041102 deployAndSave (ctx , client , diags , data )
11051103 if diags .HasError () {
1106- tflog .Debug (ctx , fmt .Sprintf ("Waiting for %v seconds before retrying config-save" , retryWaitTimeout ))
1107- time .Sleep (time .Duration (retryWaitTimeout ) * time .Second )
1108- if attempt < maxRetries - 1 {
1104+ tflog .Debug (ctx , fmt .Sprintf ("Waiting for %v seconds before retrying config-save" , configSaveRetryWaitTimeout ))
1105+ time .Sleep (time .Duration (configSaveRetryWaitTimeout ) * time .Second )
1106+ if attempt < configSaveMaxRetries - 1 {
11091107 * diags = diag.Diagnostics {}
11101108 }
11111109 continue
0 commit comments