Skip to content

Commit

Permalink
Handling ONTAP REST API responses for specific cases
Browse files Browse the repository at this point in the history
  • Loading branch information
aparna0508 authored Dec 2, 2024
1 parent 4513299 commit 1a19a09
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 32 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions storage_drivers/ontap/api/abstraction_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2084,8 +2084,8 @@ func (d OntapAPIREST) LunCreate(ctx context.Context, lun Lun) error {
return err
}

creationErr := d.api.LunCreate(ctx, lun.Name, sizeBytes, lun.OsType, lun.Qos, *lun.SpaceReserved,
*lun.SpaceAllocated)
creationErr := d.api.LunCreate(ctx, lun.Name, sizeBytes, lun.OsType, lun.Qos, lun.SpaceReserved,
lun.SpaceAllocated)
if creationErr != nil {
return fmt.Errorf("error creating LUN %v: %v", lun.Name, creationErr)
}
Expand Down
8 changes: 4 additions & 4 deletions storage_drivers/ontap/api/abstraction_rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3509,14 +3509,14 @@ func TestLunCreate(t *testing.T) {
rsi.EXPECT().ClientConfig().Return(clientConfig).AnyTimes()

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

// case 2: Create LUN returned error
rsi.EXPECT().LunCreate(ctx, lun.Name, int64(2147483648), lun.OsType, lun.Qos, *lun.SpaceReserved,
*lun.SpaceAllocated).
rsi.EXPECT().LunCreate(ctx, lun.Name, int64(2147483648), lun.OsType, lun.Qos, lun.SpaceReserved,
lun.SpaceAllocated).
Return(fmt.Errorf("Failed to create LUN"))
err = oapi.LunCreate(ctx, lun)
assert.Error(t, err, "no error returned while creating a LUN info")
Expand Down
73 changes: 50 additions & 23 deletions storage_drivers/ontap/api/ontap_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2361,11 +2361,11 @@ func (c RestClient) LunCloneCreate(

params.SetInfo(lunInfo)

lunCreateCreated, _, err := c.api.San.LunCreate(params, c.authInfo)
lunCreateCreated, lunCreateAccepted, err := c.api.San.LunCreate(params, c.authInfo)
if err != nil {
return err
}
if lunCreateCreated == nil {
if lunCreateCreated == nil && lunCreateAccepted == nil {
return fmt.Errorf("unexpected response from LUN create")
}

Expand All @@ -2376,7 +2376,7 @@ func (c RestClient) LunCloneCreate(
// LunCreate creates a LUN
func (c RestClient) LunCreate(
ctx context.Context, lunPath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup,
spaceReserved, spaceAllocated bool,
spaceReserved, spaceAllocated *bool,
) error {
if strings.Contains(lunPath, failureLUNCreate) {
return errors.New("injected error")
Expand All @@ -2392,24 +2392,39 @@ func (c RestClient) LunCreate(
OsType: utils.Ptr(osType),
Space: &models.LunInlineSpace{
Size: utils.Ptr(sizeInBytes),
Guarantee: &models.LunInlineSpaceInlineGuarantee{
Requested: utils.Ptr(spaceReserved),
},
ScsiThinProvisioningSupportEnabled: utils.Ptr(spaceAllocated),
},
QosPolicy: &models.LunInlineQosPolicy{
}

// Set spaceReserved if present.
if spaceReserved != nil {
lunInfo.Space.Guarantee = &models.LunInlineSpaceInlineGuarantee{
Requested: spaceReserved,
}
}

// Set spaceAllocated if present.
if spaceAllocated != nil {
lunInfo.Space.ScsiThinProvisioningSupportEnabled = spaceAllocated
}

// Set QosPolicy name if present.
if qosPolicyGroup.Name != "" {
lunInfo.QosPolicy = &models.LunInlineQosPolicy{
Name: utils.Ptr(qosPolicyGroup.Name),
},
}
}

lunInfo.Svm = &models.LunInlineSvm{UUID: utils.Ptr(c.svmUUID)}

params.SetInfo(lunInfo)

lunCreateCreated, _, err := c.api.San.LunCreate(params, c.authInfo)
lunCreateCreated, lunCreateAccepted, err := c.api.San.LunCreate(params, c.authInfo)
if err != nil {
return err
}
if lunCreateCreated == nil {

// If both response parameter is nil, then it is unexpected.
if lunCreateCreated == nil && lunCreateAccepted == nil {
return fmt.Errorf("unexpected response from LUN create")
}

Expand Down Expand Up @@ -2505,11 +2520,13 @@ func (c RestClient) LunDelete(
params.HTTPClient = c.httpClient
params.UUID = lunUUID

lunDeleteResult, _, err := c.api.San.LunDelete(params, c.authInfo)
lunDeleteResult, lunDeleteAccepted, err := c.api.San.LunDelete(params, c.authInfo)
if err != nil {
return fmt.Errorf("could not delete lun; %v", err)
}
if lunDeleteResult == nil {

// If both of the response parameters are nil, then it is unexpected.
if lunDeleteResult == nil && lunDeleteAccepted == nil {
return fmt.Errorf("could not delete lun: %v", "unexpected result")
}

Expand Down Expand Up @@ -2566,11 +2583,13 @@ func (c RestClient) LunSetComment(

params.SetInfo(lunInfo)

lunModifyOK, _, err := c.api.San.LunModify(params, c.authInfo)
lunModifyOK, lunModifyAccepted, err := c.api.San.LunModify(params, c.authInfo)
if err != nil {
return err
}
if lunModifyOK == nil {

// If both of the response parameters are nil, then it is unexpected.
if lunModifyOK == nil && lunModifyAccepted == nil {
return fmt.Errorf("unexpected response from LUN modify")
}

Expand Down Expand Up @@ -2645,11 +2664,13 @@ func (c RestClient) LunSetAttribute(
}
params.Info = attrInfo

lunAttrCreateOK, _, err := c.api.San.LunAttributeCreate(params, c.authInfo)
lunAttrCreateOK, lunAttrCreateAccepted, err := c.api.San.LunAttributeCreate(params, c.authInfo)
if err != nil {
return err
}
if lunAttrCreateOK == nil {

// If both the response parameters are nil, then it is unexpected.
if lunAttrCreateOK == nil && lunAttrCreateAccepted == nil {
return fmt.Errorf("unexpected response from LUN attribute create")
}
return nil
Expand Down Expand Up @@ -2712,11 +2733,13 @@ func (c RestClient) LunSetQosPolicyGroup(

params.SetInfo(lunInfo)

lunModifyOK, _, err := c.api.San.LunModify(params, c.authInfo)
lunModifyOK, lunModifyAccepted, err := c.api.San.LunModify(params, c.authInfo)
if err != nil {
return err
}
if lunModifyOK == nil {

// If both the response parameters are nil, then it is unexpected.
if lunModifyOK == nil && lunModifyAccepted == nil {
return fmt.Errorf("unexpected response from LUN modify")
}

Expand Down Expand Up @@ -2753,11 +2776,13 @@ func (c RestClient) LunRename(

params.SetInfo(lunInfo)

lunModifyOK, _, err := c.api.San.LunModify(params, c.authInfo)
lunModifyOK, lunModifyAccepted, err := c.api.San.LunModify(params, c.authInfo)
if err != nil {
return err
}
if lunModifyOK == nil {

// If both the response parameters are nil, then it is unexpected.
if lunModifyOK == nil && lunModifyAccepted == nil {
return fmt.Errorf("unexpected response from LUN modify")
}

Expand Down Expand Up @@ -3031,11 +3056,13 @@ func (c RestClient) LunSetSize(

params.SetInfo(lunInfo)

lunModifyOK, _, err := c.api.San.LunModify(params, c.authInfo)
lunModifyOK, lunModifyAccepted, err := c.api.San.LunModify(params, c.authInfo)
if err != nil {
return 0, err
}
if lunModifyOK == nil {

// If both the response parameters are nil, then it is unexpected.
if lunModifyOK == nil && lunModifyAccepted == nil {
return 0, fmt.Errorf("unexpected response from LUN modify")
}

Expand Down
2 changes: 1 addition & 1 deletion storage_drivers/ontap/api/ontap_rest_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type RestClientInterface interface {
// LunCloneCreate creates a LUN clone
LunCloneCreate(ctx context.Context, lunPath, sourcePath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup) error
// LunCreate creates a LUN
LunCreate(ctx context.Context, lunPath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup, spaceReserved, spaceAllocated bool) error
LunCreate(ctx context.Context, lunPath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup, spaceReserved, spaceAllocated *bool) error
// LunGet gets the LUN with the specified uuid
LunGet(ctx context.Context, uuid string) (*san.LunGetOK, error)
// LunGetByName gets the LUN with the specified name
Expand Down
2 changes: 1 addition & 1 deletion storage_drivers/ontap/api/ontap_rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ func TestOntapREST_LunCreate(t *testing.T) {
assert.NotNil(t, rs)

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

0 comments on commit 1a19a09

Please sign in to comment.