diff --git a/mocks/mock_storage_drivers/mock_ontap/mock_ontap_rest_interface.go b/mocks/mock_storage_drivers/mock_ontap/mock_ontap_rest_interface.go index 3af4eadbe..24f41dedd 100644 --- a/mocks/mock_storage_drivers/mock_ontap/mock_ontap_rest_interface.go +++ b/mocks/mock_storage_drivers/mock_ontap/mock_ontap_rest_interface.go @@ -795,7 +795,7 @@ func (mr *MockRestClientInterfaceMockRecorder) LunCloneCreate(arg0, arg1, arg2, } // LunCreate mocks base method. -func (m *MockRestClientInterface) LunCreate(arg0 context.Context, arg1 string, arg2 int64, arg3 string, arg4 api.QosPolicyGroup, arg5, arg6 bool) error { +func (m *MockRestClientInterface) LunCreate(arg0 context.Context, arg1 string, arg2 int64, arg3 string, arg4 api.QosPolicyGroup, arg5, arg6 *bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "LunCreate", arg0, arg1, arg2, arg3, arg4, arg5, arg6) ret0, _ := ret[0].(error) diff --git a/storage_drivers/ontap/api/abstraction_rest.go b/storage_drivers/ontap/api/abstraction_rest.go index 9d4b4145b..697fa10a2 100644 --- a/storage_drivers/ontap/api/abstraction_rest.go +++ b/storage_drivers/ontap/api/abstraction_rest.go @@ -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) } diff --git a/storage_drivers/ontap/api/abstraction_rest_test.go b/storage_drivers/ontap/api/abstraction_rest_test.go index 47ed31e31..9d270157b 100644 --- a/storage_drivers/ontap/api/abstraction_rest_test.go +++ b/storage_drivers/ontap/api/abstraction_rest_test.go @@ -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") diff --git a/storage_drivers/ontap/api/ontap_rest.go b/storage_drivers/ontap/api/ontap_rest.go index 14f03af20..3983351b3 100644 --- a/storage_drivers/ontap/api/ontap_rest.go +++ b/storage_drivers/ontap/api/ontap_rest.go @@ -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") } @@ -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") @@ -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") } @@ -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") } @@ -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") } @@ -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 @@ -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") } @@ -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") } @@ -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") } diff --git a/storage_drivers/ontap/api/ontap_rest_interface.go b/storage_drivers/ontap/api/ontap_rest_interface.go index fa24444f4..101212b82 100644 --- a/storage_drivers/ontap/api/ontap_rest_interface.go +++ b/storage_drivers/ontap/api/ontap_rest_interface.go @@ -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 diff --git a/storage_drivers/ontap/api/ontap_rest_test.go b/storage_drivers/ontap/api/ontap_rest_test.go index d52f55266..0eea1d3e9 100644 --- a/storage_drivers/ontap/api/ontap_rest_test.go +++ b/storage_drivers/ontap/api/ontap_rest_test.go @@ -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 {