Skip to content

Commit 1948382

Browse files
committed
Fix DS & Add Retry
1 parent aaea760 commit 1948382

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed

powerflex/helper/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
func GetFirstSystem(rc *goscaleio.Client) (*goscaleio.System, error) {
4444
allSystems, err := rc.GetSystems()
4545
if err != nil {
46-
return nil, fmt.Errorf("Error in goscaleio GetSystems")
46+
return nil, fmt.Errorf("Error in goscaleio GetSystems %s", err.Error())
4747
}
4848
if numSys := len((allSystems)); numSys == 0 {
4949
return nil, fmt.Errorf("no systems found")

powerflex/provider/provider.go

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"context"
2222
"os"
2323
"strconv"
24+
"strings"
25+
"time"
2426

2527
"github.com/dell/goscaleio"
2628
"github.com/hashicorp/terraform-plugin-framework/datasource"
@@ -102,7 +104,7 @@ func (p *powerflexProvider) Schema(_ context.Context, _ provider.SchemaRequest,
102104
// Configure - provider pre-initiate calle function.
103105
func (p *powerflexProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
104106
tflog.Info(ctx, "Configuring powerflex client")
105-
107+
retryEOFCounter := 5
106108
var config powerflexProviderModel
107109
var timeout int
108110
diags := req.Config.Get(ctx, &config)
@@ -233,30 +235,50 @@ func (p *powerflexProvider) Configure(ctx context.Context, req provider.Configur
233235
goscaleioConf.Password = password
234236
goscaleioConf.Insecure = insecure
235237

236-
// Create a new PowerFlex gateway client using the configuration values
237-
gatewayClient, err := goscaleio.NewGateway(goscaleioConf.Endpoint, goscaleioConf.Username, goscaleioConf.Password, goscaleioConf.Insecure, true)
238-
if err != nil {
239-
resp.Diagnostics.AddError(
240-
"Unable to Create gateway API Client",
241-
"An unexpected error occurred when creating the gateway API client. "+
242-
"If the error is not clear, please contact the provider developers.\n\n"+
243-
"gateway Client Error: "+err.Error(),
244-
)
245-
return
246-
}
247-
248-
p.gatewayClient = gatewayClient
238+
for i := 0; i < retryEOFCounter; i++ {
239+
// Create a new PowerFlex gateway client using the configuration values
240+
gatewayClient, err := goscaleio.NewGateway(goscaleioConf.Endpoint, goscaleioConf.Username, goscaleioConf.Password, goscaleioConf.Insecure, true)
241+
if err != nil {
242+
// Sometimes the Powerflex Gateway gets inidated with requests
243+
// In these cases just wait 5 seconds and try again
244+
// We will retry up to 5 times before just failing
245+
if strings.Contains(err.Error(), "EOF") {
246+
time.Sleep(2 * time.Second)
247+
continue
248+
}
249+
resp.Diagnostics.AddError(
250+
"Unable to Create gateway API Client",
251+
"An unexpected error occurred when creating the gateway API client. "+
252+
"If the error is not clear, please contact the provider developers.\n\n"+
253+
"gateway Client Error: "+err.Error(),
254+
)
255+
return
256+
}
249257

250-
_, err = Client.Authenticate(&goscaleioConf)
258+
p.gatewayClient = gatewayClient
259+
break
260+
}
251261

252-
if err != nil {
262+
for i := 0; i < retryEOFCounter; i++ {
263+
// Create a new PowerFlex gateway client using the configuration values
264+
_, err = Client.Authenticate(&goscaleioConf)
253265

254-
p.clientError = "An unexpected error occurred when authenticating the Goscaleio API Client. " +
255-
"Unable to Authenticate Goscaleio API Client.\n\n" +
256-
"powerflex Client Error: " + err.Error()
266+
if err != nil {
267+
// Sometimes the Powerflex Gateway gets inidated with request
268+
// In these cases just wait 2 seconds and try again
269+
// We will retry up to 5 times before just failing
270+
if strings.Contains(err.Error(), "EOF") {
271+
time.Sleep(2 * time.Second)
272+
continue
273+
}
274+
p.clientError = "An unexpected error occurred when authenticating the Goscaleio API Client. " +
275+
"Unable to Authenticate Goscaleio API Client.\n\n" +
276+
"powerflex Client Error: " + err.Error()
277+
return
278+
}
257279

258-
} else {
259280
p.client = Client
281+
break
260282
}
261283

262284
resp.DataSourceData = p

powerflex/provider/sdc_datasource.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package provider
1919

2020
import (
2121
"context"
22+
"strings"
2223

2324
"terraform-provider-powerflex/powerflex/helper"
2425
"terraform-provider-powerflex/powerflex/models"
@@ -96,16 +97,20 @@ func (d *sdcDataSource) Read(ctx context.Context, req datasource.ReadRequest, re
9697
)
9798
return
9899
}
99-
100-
// SDC endpoints returns both SDC and NVMe host. Need to filter out NVMe host
101-
n := 0
102-
for _, sdc := range sdcs {
103-
if sdc.HostType == "SdcHost" {
104-
sdcs[n] = sdc
105-
n++
100+
tflog.Info(ctx, "system Version"+system.System.SystemVersionName)
101+
102+
// If it is < 4_0 there is no NVME/HostType value so we should skip this filter
103+
if !strings.Contains(system.System.SystemVersionName, "3_6") {
104+
// SDC endpoints returns both SDC and NVMe host. Need to filter out NVMe host
105+
n := 0
106+
for _, sdc := range sdcs {
107+
if sdc.HostType == "SdcHost" {
108+
sdcs[n] = sdc
109+
n++
110+
}
106111
}
112+
sdcs = sdcs[:n]
107113
}
108-
sdcs = sdcs[:n]
109114

110115
// Set state
111116
searchFilter := helper.SdcFilterType.All

0 commit comments

Comments
 (0)