Skip to content

Commit 1a19a09

Browse files
authored
Handling ONTAP REST API responses for specific cases
1 parent 4513299 commit 1a19a09

File tree

6 files changed

+59
-32
lines changed

6 files changed

+59
-32
lines changed

mocks/mock_storage_drivers/mock_ontap/mock_ontap_rest_interface.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

storage_drivers/ontap/api/abstraction_rest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,8 +2084,8 @@ func (d OntapAPIREST) LunCreate(ctx context.Context, lun Lun) error {
20842084
return err
20852085
}
20862086

2087-
creationErr := d.api.LunCreate(ctx, lun.Name, sizeBytes, lun.OsType, lun.Qos, *lun.SpaceReserved,
2088-
*lun.SpaceAllocated)
2087+
creationErr := d.api.LunCreate(ctx, lun.Name, sizeBytes, lun.OsType, lun.Qos, lun.SpaceReserved,
2088+
lun.SpaceAllocated)
20892089
if creationErr != nil {
20902090
return fmt.Errorf("error creating LUN %v: %v", lun.Name, creationErr)
20912091
}

storage_drivers/ontap/api/abstraction_rest_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,14 +3509,14 @@ func TestLunCreate(t *testing.T) {
35093509
rsi.EXPECT().ClientConfig().Return(clientConfig).AnyTimes()
35103510

35113511
// case 1: Create LUN
3512-
rsi.EXPECT().LunCreate(ctx, lun.Name, int64(2147483648), lun.OsType, lun.Qos, *lun.SpaceReserved,
3513-
*lun.SpaceAllocated).Return(nil)
3512+
rsi.EXPECT().LunCreate(ctx, lun.Name, int64(2147483648), lun.OsType, lun.Qos, lun.SpaceReserved,
3513+
lun.SpaceAllocated).Return(nil)
35143514
err := oapi.LunCreate(ctx, lun)
35153515
assert.NoError(t, err, "error returned while creating a LUN info")
35163516

35173517
// case 2: Create LUN returned error
3518-
rsi.EXPECT().LunCreate(ctx, lun.Name, int64(2147483648), lun.OsType, lun.Qos, *lun.SpaceReserved,
3519-
*lun.SpaceAllocated).
3518+
rsi.EXPECT().LunCreate(ctx, lun.Name, int64(2147483648), lun.OsType, lun.Qos, lun.SpaceReserved,
3519+
lun.SpaceAllocated).
35203520
Return(fmt.Errorf("Failed to create LUN"))
35213521
err = oapi.LunCreate(ctx, lun)
35223522
assert.Error(t, err, "no error returned while creating a LUN info")

storage_drivers/ontap/api/ontap_rest.go

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,11 +2361,11 @@ func (c RestClient) LunCloneCreate(
23612361

23622362
params.SetInfo(lunInfo)
23632363

2364-
lunCreateCreated, _, err := c.api.San.LunCreate(params, c.authInfo)
2364+
lunCreateCreated, lunCreateAccepted, err := c.api.San.LunCreate(params, c.authInfo)
23652365
if err != nil {
23662366
return err
23672367
}
2368-
if lunCreateCreated == nil {
2368+
if lunCreateCreated == nil && lunCreateAccepted == nil {
23692369
return fmt.Errorf("unexpected response from LUN create")
23702370
}
23712371

@@ -2376,7 +2376,7 @@ func (c RestClient) LunCloneCreate(
23762376
// LunCreate creates a LUN
23772377
func (c RestClient) LunCreate(
23782378
ctx context.Context, lunPath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup,
2379-
spaceReserved, spaceAllocated bool,
2379+
spaceReserved, spaceAllocated *bool,
23802380
) error {
23812381
if strings.Contains(lunPath, failureLUNCreate) {
23822382
return errors.New("injected error")
@@ -2392,24 +2392,39 @@ func (c RestClient) LunCreate(
23922392
OsType: utils.Ptr(osType),
23932393
Space: &models.LunInlineSpace{
23942394
Size: utils.Ptr(sizeInBytes),
2395-
Guarantee: &models.LunInlineSpaceInlineGuarantee{
2396-
Requested: utils.Ptr(spaceReserved),
2397-
},
2398-
ScsiThinProvisioningSupportEnabled: utils.Ptr(spaceAllocated),
23992395
},
2400-
QosPolicy: &models.LunInlineQosPolicy{
2396+
}
2397+
2398+
// Set spaceReserved if present.
2399+
if spaceReserved != nil {
2400+
lunInfo.Space.Guarantee = &models.LunInlineSpaceInlineGuarantee{
2401+
Requested: spaceReserved,
2402+
}
2403+
}
2404+
2405+
// Set spaceAllocated if present.
2406+
if spaceAllocated != nil {
2407+
lunInfo.Space.ScsiThinProvisioningSupportEnabled = spaceAllocated
2408+
}
2409+
2410+
// Set QosPolicy name if present.
2411+
if qosPolicyGroup.Name != "" {
2412+
lunInfo.QosPolicy = &models.LunInlineQosPolicy{
24012413
Name: utils.Ptr(qosPolicyGroup.Name),
2402-
},
2414+
}
24032415
}
2416+
24042417
lunInfo.Svm = &models.LunInlineSvm{UUID: utils.Ptr(c.svmUUID)}
24052418

24062419
params.SetInfo(lunInfo)
24072420

2408-
lunCreateCreated, _, err := c.api.San.LunCreate(params, c.authInfo)
2421+
lunCreateCreated, lunCreateAccepted, err := c.api.San.LunCreate(params, c.authInfo)
24092422
if err != nil {
24102423
return err
24112424
}
2412-
if lunCreateCreated == nil {
2425+
2426+
// If both response parameter is nil, then it is unexpected.
2427+
if lunCreateCreated == nil && lunCreateAccepted == nil {
24132428
return fmt.Errorf("unexpected response from LUN create")
24142429
}
24152430

@@ -2505,11 +2520,13 @@ func (c RestClient) LunDelete(
25052520
params.HTTPClient = c.httpClient
25062521
params.UUID = lunUUID
25072522

2508-
lunDeleteResult, _, err := c.api.San.LunDelete(params, c.authInfo)
2523+
lunDeleteResult, lunDeleteAccepted, err := c.api.San.LunDelete(params, c.authInfo)
25092524
if err != nil {
25102525
return fmt.Errorf("could not delete lun; %v", err)
25112526
}
2512-
if lunDeleteResult == nil {
2527+
2528+
// If both of the response parameters are nil, then it is unexpected.
2529+
if lunDeleteResult == nil && lunDeleteAccepted == nil {
25132530
return fmt.Errorf("could not delete lun: %v", "unexpected result")
25142531
}
25152532

@@ -2566,11 +2583,13 @@ func (c RestClient) LunSetComment(
25662583

25672584
params.SetInfo(lunInfo)
25682585

2569-
lunModifyOK, _, err := c.api.San.LunModify(params, c.authInfo)
2586+
lunModifyOK, lunModifyAccepted, err := c.api.San.LunModify(params, c.authInfo)
25702587
if err != nil {
25712588
return err
25722589
}
2573-
if lunModifyOK == nil {
2590+
2591+
// If both of the response parameters are nil, then it is unexpected.
2592+
if lunModifyOK == nil && lunModifyAccepted == nil {
25742593
return fmt.Errorf("unexpected response from LUN modify")
25752594
}
25762595

@@ -2645,11 +2664,13 @@ func (c RestClient) LunSetAttribute(
26452664
}
26462665
params.Info = attrInfo
26472666

2648-
lunAttrCreateOK, _, err := c.api.San.LunAttributeCreate(params, c.authInfo)
2667+
lunAttrCreateOK, lunAttrCreateAccepted, err := c.api.San.LunAttributeCreate(params, c.authInfo)
26492668
if err != nil {
26502669
return err
26512670
}
2652-
if lunAttrCreateOK == nil {
2671+
2672+
// If both the response parameters are nil, then it is unexpected.
2673+
if lunAttrCreateOK == nil && lunAttrCreateAccepted == nil {
26532674
return fmt.Errorf("unexpected response from LUN attribute create")
26542675
}
26552676
return nil
@@ -2712,11 +2733,13 @@ func (c RestClient) LunSetQosPolicyGroup(
27122733

27132734
params.SetInfo(lunInfo)
27142735

2715-
lunModifyOK, _, err := c.api.San.LunModify(params, c.authInfo)
2736+
lunModifyOK, lunModifyAccepted, err := c.api.San.LunModify(params, c.authInfo)
27162737
if err != nil {
27172738
return err
27182739
}
2719-
if lunModifyOK == nil {
2740+
2741+
// If both the response parameters are nil, then it is unexpected.
2742+
if lunModifyOK == nil && lunModifyAccepted == nil {
27202743
return fmt.Errorf("unexpected response from LUN modify")
27212744
}
27222745

@@ -2753,11 +2776,13 @@ func (c RestClient) LunRename(
27532776

27542777
params.SetInfo(lunInfo)
27552778

2756-
lunModifyOK, _, err := c.api.San.LunModify(params, c.authInfo)
2779+
lunModifyOK, lunModifyAccepted, err := c.api.San.LunModify(params, c.authInfo)
27572780
if err != nil {
27582781
return err
27592782
}
2760-
if lunModifyOK == nil {
2783+
2784+
// If both the response parameters are nil, then it is unexpected.
2785+
if lunModifyOK == nil && lunModifyAccepted == nil {
27612786
return fmt.Errorf("unexpected response from LUN modify")
27622787
}
27632788

@@ -3031,11 +3056,13 @@ func (c RestClient) LunSetSize(
30313056

30323057
params.SetInfo(lunInfo)
30333058

3034-
lunModifyOK, _, err := c.api.San.LunModify(params, c.authInfo)
3059+
lunModifyOK, lunModifyAccepted, err := c.api.San.LunModify(params, c.authInfo)
30353060
if err != nil {
30363061
return 0, err
30373062
}
3038-
if lunModifyOK == nil {
3063+
3064+
// If both the response parameters are nil, then it is unexpected.
3065+
if lunModifyOK == nil && lunModifyAccepted == nil {
30393066
return 0, fmt.Errorf("unexpected response from LUN modify")
30403067
}
30413068

storage_drivers/ontap/api/ontap_rest_interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type RestClientInterface interface {
128128
// LunCloneCreate creates a LUN clone
129129
LunCloneCreate(ctx context.Context, lunPath, sourcePath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup) error
130130
// LunCreate creates a LUN
131-
LunCreate(ctx context.Context, lunPath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup, spaceReserved, spaceAllocated bool) error
131+
LunCreate(ctx context.Context, lunPath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup, spaceReserved, spaceAllocated *bool) error
132132
// LunGet gets the LUN with the specified uuid
133133
LunGet(ctx context.Context, uuid string) (*san.LunGetOK, error)
134134
// LunGetByName gets the LUN with the specified name

storage_drivers/ontap/api/ontap_rest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ func TestOntapREST_LunCreate(t *testing.T) {
12531253
assert.NotNil(t, rs)
12541254

12551255
err := rs.LunCreate(ctx, test.lunPath, int64(2147483648), "linux",
1256-
QosPolicyGroup{Name: "qosPolicy", Kind: QosPolicyGroupKind}, false, false)
1256+
QosPolicyGroup{Name: "qosPolicy", Kind: QosPolicyGroupKind}, utils.Ptr(false), utils.Ptr(false))
12571257
if !test.isErrorExpected {
12581258
assert.NoError(t, err, "could not create LUN")
12591259
} else {

0 commit comments

Comments
 (0)