From 1f5192cfdc2f99dee7cebcfbec8584d5b7e6393e Mon Sep 17 00:00:00 2001 From: reederc42 Date: Wed, 26 Apr 2023 15:50:47 -0700 Subject: [PATCH] fix unmanaged import for SAN drivers maps already-mapped luns to per-node igroup --- .../mock_ontap/mock_api.go | 8 +- .../mock_ontap/mock_ontap_zapi_interface.go | 8 +- storage_drivers/ontap/api/abstraction.go | 4 +- storage_drivers/ontap/api/abstraction_rest.go | 12 +- .../ontap/api/abstraction_rest_test.go | 14 +- storage_drivers/ontap/api/abstraction_zapi.go | 6 +- storage_drivers/ontap/api/ontap_zapi.go | 6 +- .../ontap/api/ontap_zapi_interface.go | 2 +- storage_drivers/ontap/ontap_common.go | 10 +- storage_drivers/ontap/ontap_common_test.go | 6 +- storage_drivers/ontap/ontap_san_economy.go | 36 +---- .../ontap/ontap_san_economy_test.go | 146 +----------------- storage_drivers/ontap/ontap_san_test.go | 6 +- 13 files changed, 38 insertions(+), 226 deletions(-) diff --git a/mocks/mock_storage_drivers/mock_ontap/mock_api.go b/mocks/mock_storage_drivers/mock_ontap/mock_api.go index e8805886a..e5d43c1a4 100644 --- a/mocks/mock_storage_drivers/mock_ontap/mock_api.go +++ b/mocks/mock_storage_drivers/mock_ontap/mock_api.go @@ -77,18 +77,18 @@ func (mr *MockOntapAPIMockRecorder) EnsureIgroupAdded(arg0, arg1, arg2 interface } // EnsureLunMapped mocks base method. -func (m *MockOntapAPI) EnsureLunMapped(arg0 context.Context, arg1, arg2 string, arg3 bool) (int, error) { +func (m *MockOntapAPI) EnsureLunMapped(arg0 context.Context, arg1, arg2 string) (int, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EnsureLunMapped", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "EnsureLunMapped", arg0, arg1, arg2) ret0, _ := ret[0].(int) ret1, _ := ret[1].(error) return ret0, ret1 } // EnsureLunMapped indicates an expected call of EnsureLunMapped. -func (mr *MockOntapAPIMockRecorder) EnsureLunMapped(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockOntapAPIMockRecorder) EnsureLunMapped(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnsureLunMapped", reflect.TypeOf((*MockOntapAPI)(nil).EnsureLunMapped), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnsureLunMapped", reflect.TypeOf((*MockOntapAPI)(nil).EnsureLunMapped), arg0, arg1, arg2) } // ExportPolicyCreate mocks base method. diff --git a/mocks/mock_storage_drivers/mock_ontap/mock_ontap_zapi_interface.go b/mocks/mock_storage_drivers/mock_ontap/mock_ontap_zapi_interface.go index 536d5286b..db03c4e6b 100644 --- a/mocks/mock_storage_drivers/mock_ontap/mock_ontap_zapi_interface.go +++ b/mocks/mock_storage_drivers/mock_ontap/mock_ontap_zapi_interface.go @@ -950,18 +950,18 @@ func (mr *MockZapiClientInterfaceMockRecorder) LunMapGet(arg0, arg1 interface{}) } // LunMapIfNotMapped mocks base method. -func (m *MockZapiClientInterface) LunMapIfNotMapped(arg0 context.Context, arg1, arg2 string, arg3 bool) (int, error) { +func (m *MockZapiClientInterface) LunMapIfNotMapped(arg0 context.Context, arg1, arg2 string) (int, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "LunMapIfNotMapped", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "LunMapIfNotMapped", arg0, arg1, arg2) ret0, _ := ret[0].(int) ret1, _ := ret[1].(error) return ret0, ret1 } // LunMapIfNotMapped indicates an expected call of LunMapIfNotMapped. -func (mr *MockZapiClientInterfaceMockRecorder) LunMapIfNotMapped(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockZapiClientInterfaceMockRecorder) LunMapIfNotMapped(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LunMapIfNotMapped", reflect.TypeOf((*MockZapiClientInterface)(nil).LunMapIfNotMapped), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LunMapIfNotMapped", reflect.TypeOf((*MockZapiClientInterface)(nil).LunMapIfNotMapped), arg0, arg1, arg2) } // LunMapListInfo mocks base method. diff --git a/storage_drivers/ontap/api/abstraction.go b/storage_drivers/ontap/api/abstraction.go index c34d91f11..e055f2b12 100644 --- a/storage_drivers/ontap/api/abstraction.go +++ b/storage_drivers/ontap/api/abstraction.go @@ -90,7 +90,7 @@ type OntapAPI interface { LunGetByName(ctx context.Context, name string) (*Lun, error) LunRename(ctx context.Context, lunPath, newLunPath string) error LunMapInfo(ctx context.Context, initiatorGroupName, lunPath string) (int, error) - EnsureLunMapped(ctx context.Context, initiatorGroupName, lunPath string, importNotManaged bool) (int, error) + EnsureLunMapped(ctx context.Context, initiatorGroupName, lunPath string) (int, error) LunUnmap(ctx context.Context, initiatorGroupName, lunPath string) error LunSize(ctx context.Context, lunPath string) (int, error) LunSetSize(ctx context.Context, lunPath, newSize string) (uint64, error) @@ -99,7 +99,7 @@ type OntapAPI interface { IscsiInitiatorGetDefaultAuth(ctx context.Context) (IscsiInitiatorAuth, error) IscsiInitiatorSetDefaultAuth( - ctx context.Context, authType, userName, passphrase, outbountUserName, + ctx context.Context, authType, userName, passphrase, outboundUserName, outboundPassphrase string, ) error IscsiInterfaceGet(ctx context.Context, svm string) ([]string, error) diff --git a/storage_drivers/ontap/api/abstraction_rest.go b/storage_drivers/ontap/api/abstraction_rest.go index bc925c582..140cfc027 100644 --- a/storage_drivers/ontap/api/abstraction_rest.go +++ b/storage_drivers/ontap/api/abstraction_rest.go @@ -1990,7 +1990,7 @@ func (d OntapAPIREST) LunMapInfo(ctx context.Context, initiatorGroupName, lunPat } func (d OntapAPIREST) isLunMapped( - ctx context.Context, lunPath, initiatorGroupName string, importNotManaged bool, + ctx context.Context, lunPath, initiatorGroupName string, ) (bool, int, error) { alreadyMapped := false lunID := -1 @@ -2013,9 +2013,9 @@ func (d OntapAPIREST) isLunMapped( for _, record := range lunMapResponse.Payload.LunMapResponseInlineRecords { if record.Igroup != nil && record.Igroup.Name != nil { if *record.Igroup.Name != initiatorGroupName { - Logc(ctx).Debugf("LUN %s is mapped to igroup %s.", lunPath, record.Igroup.Name) + Logc(ctx).Debugf("LUN %s is mapped to igroup %s.", lunPath, *record.Igroup.Name) } - if *record.Igroup.Name == initiatorGroupName || importNotManaged { + if *record.Igroup.Name == initiatorGroupName { if record.LogicalUnitNumber != nil { lunID = int(*record.LogicalUnitNumber) alreadyMapped = true @@ -2053,10 +2053,8 @@ func (d OntapAPIREST) isLunMapped( return alreadyMapped, lunID, nil } -func (d OntapAPIREST) EnsureLunMapped( - ctx context.Context, initiatorGroupName, lunPath string, importNotManaged bool, -) (int, error) { - alreadyMapped, lunID, err := d.isLunMapped(ctx, lunPath, initiatorGroupName, importNotManaged) +func (d OntapAPIREST) EnsureLunMapped(ctx context.Context, initiatorGroupName, lunPath string) (int, error) { + alreadyMapped, lunID, err := d.isLunMapped(ctx, lunPath, initiatorGroupName) if err != nil { return -1, err } diff --git a/storage_drivers/ontap/api/abstraction_rest_test.go b/storage_drivers/ontap/api/abstraction_rest_test.go index 177441611..33f735d8e 100644 --- a/storage_drivers/ontap/api/abstraction_rest_test.go +++ b/storage_drivers/ontap/api/abstraction_rest_test.go @@ -82,13 +82,13 @@ func TestEnsureLunMapped(t *testing.T) { // lunMapInfo returning error rsi.EXPECT().LunMapInfo(ctx, "", lunPath).Return(lunMapCollection, errors.New("error")) - resultLun, err := oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath, true) + resultLun, err := oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath) assert.Errorf(t, err, "problem reading maps for LUN /dev/sda: error") assert.Equal(t, -1, resultLun) // lunMapInfo returning nil lun collection rsi.EXPECT().LunMapInfo(ctx, "", lunPath).Return(nil, nil) - resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath, true) + resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath) assert.Errorf(t, err, "problem reading maps for LUN /dev/sda") assert.Equal(t, -1, resultLun) @@ -96,14 +96,14 @@ func TestEnsureLunMapped(t *testing.T) { lun := &models.Lun{LunInlineLunMaps: []*models.LunInlineLunMapsInlineArrayItem{{LogicalUnitNumber: number}}} rsi.EXPECT().LunGetByName(ctx, lunPath).Return(lun, nil) rsi.EXPECT().LunMapInfo(ctx, "", lunPath).Return(lunMapCollection, nil) - resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath, true) + resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath) assert.Nil(t, err) assert.Equal(t, int(*number), resultLun) // record.LogicalUnitNumber == nil and lunGetByName returns error rsi.EXPECT().LunGetByName(ctx, lunPath).Return(nil, errors.New("error getting LUN by name")) rsi.EXPECT().LunMapInfo(ctx, "", lunPath).Return(lunMapCollection, nil) - resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath, true) + resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath) assert.Errorf(t, err, "error getting LUN by name") assert.Equal(t, -1, resultLun) @@ -114,7 +114,7 @@ func TestEnsureLunMapped(t *testing.T) { rsi.EXPECT().LunGetByName(ctx, lunPath).Return(nil, nil) rsi.EXPECT().LunMapInfo(ctx, "", lunPath).Return(lunMapCollection, nil) rsi.EXPECT().LunMap(ctx, initiatorGroup, lunPath, -1).Return(lunMapCreated, nil) - resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath, true) + resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath) assert.NoError(t, err) // As LogicalUnitNumber == nil currently, -1 is returned assert.Equal(t, -1, resultLun) @@ -122,7 +122,7 @@ func TestEnsureLunMapped(t *testing.T) { // positive test case where record.LogicalUnitNumber != nil lunMapCollection.Payload.LunMapResponseInlineRecords[0].LogicalUnitNumber = number rsi.EXPECT().LunMapInfo(ctx, "", lunPath).Return(lunMapCollection, nil) - resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath, true) + resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath) assert.Nil(t, err) assert.Equal(t, int(*number), resultLun) @@ -130,7 +130,7 @@ func TestEnsureLunMapped(t *testing.T) { lunMapCollection.Payload.LunMapResponseInlineRecords[0].Igroup.Name = utils.Ptr("tmp") rsi.EXPECT().LunMapInfo(ctx, "", lunPath).Return(lunMapCollection, nil) rsi.EXPECT().LunMap(ctx, initiatorGroup, lunPath, -1).Return(lunMapCreated, nil) - resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath, false) + resultLun, err = oapi.EnsureLunMapped(ctx, initiatorGroup, lunPath) assert.Nil(t, err) assert.Equal(t, int(*number), resultLun) } diff --git a/storage_drivers/ontap/api/abstraction_zapi.go b/storage_drivers/ontap/api/abstraction_zapi.go index 16e5999b5..31350c6e3 100644 --- a/storage_drivers/ontap/api/abstraction_zapi.go +++ b/storage_drivers/ontap/api/abstraction_zapi.go @@ -570,10 +570,8 @@ func (d OntapAPIZAPI) LunMapInfo(ctx context.Context, initiatorGroupName, lunPat return lunID, nil } -func (d OntapAPIZAPI) EnsureLunMapped( - ctx context.Context, initiatorGroupName, lunPath string, importNotManaged bool, -) (int, error) { - return d.api.LunMapIfNotMapped(ctx, initiatorGroupName, lunPath, importNotManaged) +func (d OntapAPIZAPI) EnsureLunMapped(ctx context.Context, initiatorGroupName, lunPath string) (int, error) { + return d.api.LunMapIfNotMapped(ctx, initiatorGroupName, lunPath) } func (d OntapAPIZAPI) LunSize(ctx context.Context, flexvolName string) (int, error) { diff --git a/storage_drivers/ontap/api/ontap_zapi.go b/storage_drivers/ontap/api/ontap_zapi.go index 0d4422ea5..3d10ef3a3 100644 --- a/storage_drivers/ontap/api/ontap_zapi.go +++ b/storage_drivers/ontap/api/ontap_zapi.go @@ -458,9 +458,7 @@ func (c Client) LunMapAutoID(initiatorGroupName, lunPath string) (*azgo.LunMapRe return response, err } -func (c Client) LunMapIfNotMapped( - ctx context.Context, initiatorGroupName, lunPath string, importNotManaged bool, -) (int, error) { +func (c Client) LunMapIfNotMapped(ctx context.Context, initiatorGroupName, lunPath string) (int, error) { // Read LUN maps to see if the LUN is already mapped to the igroup lunMapListResponse, err := c.LunMapListInfo(lunPath) if err != nil { @@ -483,7 +481,7 @@ func (c Client) LunMapIfNotMapped( if igroup.InitiatorGroupName() != initiatorGroupName { Logc(ctx).Debugf("LUN %s is mapped to igroup %s.", lunPath, igroup.InitiatorGroupName()) } - if igroup.InitiatorGroupName() == initiatorGroupName || importNotManaged { + if igroup.InitiatorGroupName() == initiatorGroupName { lunID = igroup.LunId() alreadyMapped = true diff --git a/storage_drivers/ontap/api/ontap_zapi_interface.go b/storage_drivers/ontap/api/ontap_zapi_interface.go index d9ad83583..182f3d703 100644 --- a/storage_drivers/ontap/api/ontap_zapi_interface.go +++ b/storage_drivers/ontap/api/ontap_zapi_interface.go @@ -72,7 +72,7 @@ type ZapiClientInterface interface { // LunMapAutoID maps a LUN in an initiator group, allowing ONTAP to choose an available LUN ID // equivalent to filer::> lun map -vserver iscsi_vs -path /vol/v/lun1 -igroup docker LunMapAutoID(initiatorGroupName, lunPath string) (*azgo.LunMapResponse, error) - LunMapIfNotMapped(ctx context.Context, initiatorGroupName, lunPath string, importNotManaged bool) (int, error) + LunMapIfNotMapped(ctx context.Context, initiatorGroupName, lunPath string) (int, error) // LunMapListInfo returns lun mapping information for the specified lun // equivalent to filer::> lun mapped show -vserver iscsi_vs -path /vol/v/lun0 LunMapListInfo(lunPath string) (*azgo.LunMapListInfoResponse, error) diff --git a/storage_drivers/ontap/ontap_common.go b/storage_drivers/ontap/ontap_common.go index a8ce6fe29..baa8f9ba7 100644 --- a/storage_drivers/ontap/ontap_common.go +++ b/storage_drivers/ontap/ontap_common.go @@ -431,15 +431,9 @@ func reconcileSANNodeAccess( "backendUUID": backendUUID, }).Debug("Attempting to delete unused igroups") for _, igroup := range igroups { - luns, err := clientAPI.IgroupListLUNsMapped(ctx, igroup) - if err != nil { + if err := DestroyUnmappedIgroup(ctx, clientAPI, igroup); err != nil { return err } - if len(luns) == 0 { - if err := clientAPI.IgroupDestroy(ctx, igroup); err != nil { - return err - } - } } return nil @@ -649,7 +643,7 @@ func PublishLUN( } // Map LUN (it may already be mapped) - lunID, err := clientAPI.EnsureLunMapped(ctx, igroupName, lunPath, publishInfo.Unmanaged) + lunID, err := clientAPI.EnsureLunMapped(ctx, igroupName, lunPath) if err != nil { return err } diff --git a/storage_drivers/ontap/ontap_common_test.go b/storage_drivers/ontap/ontap_common_test.go index ec7115266..70c43f435 100644 --- a/storage_drivers/ontap/ontap_common_test.go +++ b/storage_drivers/ontap/ontap_common_test.go @@ -3846,7 +3846,7 @@ func TestPublishLun(t *testing.T) { // Test1 - Positive flow mockAPI.EXPECT().LunGetFSType(ctx, lunPath).Return("fstype", nil) mockAPI.EXPECT().EnsureIgroupAdded(ctx, igroupName, publishInfo.HostIQN[0]) - mockAPI.EXPECT().EnsureLunMapped(ctx, igroupName, lunPath, publishInfo.Unmanaged).Return(1111, nil) + mockAPI.EXPECT().EnsureLunMapped(ctx, igroupName, lunPath).Return(1111, nil) mockAPI.EXPECT().LunMapGetReportingNodes(ctx, igroupName, lunPath).Return([]string{"Node1"}, nil) mockAPI.EXPECT().GetSLMDataLifs(ctx, ips, []string{"Node1"}).Return([]string{}, nil) @@ -3868,7 +3868,7 @@ func TestPublishLun(t *testing.T) { publishInfo.HostIQN = []string{"host_iqn"} mockAPI.EXPECT().LunGetFSType(ctx, lunPath).Return("", fmt.Errorf("LunGetFSType returned error")) mockAPI.EXPECT().EnsureIgroupAdded(ctx, igroupName, publishInfo.HostIQN[0]) - mockAPI.EXPECT().EnsureLunMapped(ctx, igroupName, lunPath, publishInfo.Unmanaged).Return(1111, nil) + mockAPI.EXPECT().EnsureLunMapped(ctx, igroupName, lunPath).Return(1111, nil) mockAPI.EXPECT().LunMapGetReportingNodes(ctx, igroupName, lunPath).Return([]string{"Node1"}, nil) mockAPI.EXPECT().GetSLMDataLifs(ctx, ips, []string{"Node1"}).Return([]string{}, nil) @@ -3904,7 +3904,7 @@ func TestPublishLun(t *testing.T) { // Test 6 - EnsureLunMapped returns error mockAPI.EXPECT().LunGetFSType(ctx, lunPath).Return("fstype", nil) - mockAPI.EXPECT().EnsureLunMapped(ctx, igroupName, lunPath, publishInfo.Unmanaged).Return(1111, + mockAPI.EXPECT().EnsureLunMapped(ctx, igroupName, lunPath).Return(1111, fmt.Errorf("EnsureLunMapped returned error")) mockAPI.EXPECT().EnsureIgroupAdded(ctx, igroupName, gomock.Any()).Return(nil) diff --git a/storage_drivers/ontap/ontap_san_economy.go b/storage_drivers/ontap/ontap_san_economy.go index 76ae34600..000e0709f 100644 --- a/storage_drivers/ontap/ontap_san_economy.go +++ b/storage_drivers/ontap/ontap_san_economy.go @@ -1648,41 +1648,7 @@ func (d *SANEconomyStorageDriver) CreateFollowup(ctx context.Context, volConfig } Logd(ctx, d.Name(), d.Config.DebugTraceFlags["method"]).WithFields(fields).Trace(">>>> CreateFollowup") defer Logd(ctx, d.Name(), d.Config.DebugTraceFlags["method"]).WithFields(fields).Trace("<<<< CreateFollowup") - - if d.Config.DriverContext == tridentconfig.ContextDocker { - Logc(ctx).Debug("No follow-up create actions for Docker.") - return nil - } - - // Don't map at create time if publish enforcement is enabled. - if volConfig.AccessInfo.PublishEnforcement { - Logc(ctx).Debug("No follow-up create actions for published enforced CSI volume.") - return nil - } - - return d.mapOntapSANLUN(ctx, volConfig) -} - -func (d *SANEconomyStorageDriver) mapOntapSANLUN(ctx context.Context, volConfig *storage.VolumeConfig) error { - // Determine which flexvol contains the LUN - exists, flexvol, err := d.LUNExists(ctx, volConfig.InternalName, d.FlexvolNamePrefix()) - if err != nil { - return fmt.Errorf("could not determine if LUN %s exists: %v", volConfig.InternalName, err) - } - if !exists { - return fmt.Errorf("could not find LUN %s", volConfig.InternalName) - } - // Map LUN - lunPath := GetLUNPathEconomy(flexvol, volConfig.InternalName) - lunID, err := d.API.EnsureLunMapped(ctx, d.Config.IgroupName, lunPath, volConfig.ImportNotManaged) - if err != nil { - return err - } - - err = PopulateOntapLunMapping(ctx, d.API, d.ips, volConfig, lunID, lunPath, d.Config.IgroupName) - if err != nil { - return fmt.Errorf("error mapping LUN for %s driver: %v", d.Name(), err) - } + Logc(ctx).Debug("No follow-up create actions for ontap-san-economy volume.") return nil } diff --git a/storage_drivers/ontap/ontap_san_economy_test.go b/storage_drivers/ontap/ontap_san_economy_test.go index 026a56c65..32ef5a132 100644 --- a/storage_drivers/ontap/ontap_san_economy_test.go +++ b/storage_drivers/ontap/ontap_san_economy_test.go @@ -1594,7 +1594,7 @@ func TestOntapSanEconomyVolumePublish(t *testing.T) { mockAPI.EXPECT().IscsiInterfaceGet(ctx, gomock.Any()).Return([]string{"iscsi_if"}, nil).Times(1) mockAPI.EXPECT().LunGetFSType(ctx, "/vol/volumeName/storagePrefix_lunName") mockAPI.EXPECT().EnsureIgroupAdded(ctx, gomock.Any(), gomock.Any()).Times(1) - mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(1, nil) + mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any()).Times(1).Return(1, nil) mockAPI.EXPECT().LunMapGetReportingNodes(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{"node1"}, nil) mockAPI.EXPECT().GetSLMDataLifs(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{"1.1.1.1"}, nil) @@ -1626,7 +1626,7 @@ func TestOntapSanEconomyVolumePublishSLMError(t *testing.T) { mockAPI.EXPECT().IscsiInterfaceGet(ctx, gomock.Any()).Return([]string{"iscsi_if"}, nil).Times(1) mockAPI.EXPECT().LunGetFSType(ctx, "/vol/volumeName/storagePrefix_lunName") mockAPI.EXPECT().EnsureIgroupAdded(ctx, gomock.Any(), gomock.Any()).Times(1) - mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(1, nil) + mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any()).Times(1).Return(1, nil) mockAPI.EXPECT().LunMapGetReportingNodes(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{"node1"}, nil) mockAPI.EXPECT().GetSLMDataLifs(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{}, nil) @@ -3410,148 +3410,6 @@ func TestOntapSanEconomyVolumeResize_VolumeSetSizeFailed2(t *testing.T) { assert.NoError(t, result) } -func TestOntapSanEconomyCreateFollowup(t *testing.T) { - mockAPI, d := newMockOntapSanEcoDriver(t) - d.Config.IgroupName = "igroup" - d.ips = []string{"10.2.0.1"} - volConfig := &storage.VolumeConfig{ - Size: "1g", - Encryption: "false", - FileSystem: "nfs", - InternalName: "vol1", - } - - lun := api.Lun{ - Size: "1g", Name: "lun_vol1", - VolumeName: "volumeName", - } - luns := []api.Lun{lun} - - mockAPI.EXPECT().LunList(ctx, "/vol/*/vol1").Return(luns, nil) - mockAPI.EXPECT().EnsureLunMapped(ctx, "igroup", "/vol/volumeName/vol1", false).Return(123, nil) - mockAPI.EXPECT().IscsiNodeGetNameRequest(ctx).Return("iscsiNode", nil) - mockAPI.EXPECT().LunGetByName(ctx, "/vol/volumeName/vol1").Return(&lun, nil) - mockAPI.EXPECT().LunMapGetReportingNodes(ctx, "igroup", "/vol/volumeName/vol1").Return([]string{"iscsiNode"}, nil) - mockAPI.EXPECT().GetSLMDataLifs(ctx, []string{"10.2.0.1"}, []string{"iscsiNode"}).Return([]string{"10.2.0.2"}, nil) - - result := d.CreateFollowup(ctx, volConfig) - - assert.NoError(t, result) -} - -func TestOntapSanEconomyCreateFollowup_DockerContext(t *testing.T) { - _, d := newMockOntapSanEcoDriver(t) - d.Config.DriverContext = "docker" - volConfig := &storage.VolumeConfig{ - Size: "1g", - Encryption: "false", - FileSystem: "nfs", - InternalName: "vol1", - } - - result := d.CreateFollowup(ctx, volConfig) - - assert.NoError(t, result) -} - -func TestOntapSanEconomyCreateFollowup_PublishEnforcedCSIContext(t *testing.T) { - _, d := newMockOntapSanEcoDriver(t) - d.Config.DriverContext = "csi" - volConfig := &storage.VolumeConfig{ - Size: "1g", - Encryption: "false", - FileSystem: "nfs", - InternalName: "vol1", - AccessInfo: utils.VolumeAccessInfo{ - PublishEnforcement: true, - }, - } - - result := d.CreateFollowup(ctx, volConfig) - - assert.NoError(t, result) -} - -func TestOntapSanEconomyCreateFollowup_LunDoesNotExist(t *testing.T) { - mockAPI, d := newMockOntapSanEcoDriver(t) - volConfig := &storage.VolumeConfig{ - Size: "1g", - Encryption: "false", - FileSystem: "nfs", - InternalName: "vol1", - } - - tests := []struct { - message string - expectError bool - }{ - {"error fetching info", true}, - {"no luns found", false}, - } - for _, test := range tests { - t.Run(test.message, func(t *testing.T) { - if test.expectError { - mockAPI.EXPECT().LunList(ctx, "/vol/*/vol1").Return(nil, fmt.Errorf(test.message)) - } else { - mockAPI.EXPECT().LunList(ctx, "/vol/*/vol1").Return(nil, nil) - } - - result := d.CreateFollowup(ctx, volConfig) - - assert.Error(t, result) - }) - } -} - -func TestOntapSanEconomyCreateFollowup_LunNotMapped(t *testing.T) { - mockAPI, d := newMockOntapSanEcoDriver(t) - d.Config.IgroupName = "igroup" - d.ips = []string{"10.2.0.1"} - volConfig := &storage.VolumeConfig{ - Size: "1g", - Encryption: "false", - FileSystem: "nfs", - InternalName: "vol1", - } - luns := []api.Lun{ - {Size: "1g", Name: "lun_vol1", VolumeName: "volumeName"}, - } - - mockAPI.EXPECT().LunList(ctx, "/vol/*/vol1").Return(luns, nil) - mockAPI.EXPECT().EnsureLunMapped(ctx, "igroup", "/vol/volumeName/vol1", false).Return(0, - fmt.Errorf("lun not mapped")) - - result := d.CreateFollowup(ctx, volConfig) - - assert.Error(t, result) -} - -func TestOntapSanEconomyCreateFollowup_GetLunFailed(t *testing.T) { - mockAPI, d := newMockOntapSanEcoDriver(t) - d.Config.IgroupName = "igroup" - d.ips = []string{"10.2.0.1"} - volConfig := &storage.VolumeConfig{ - Size: "1g", - Encryption: "false", - FileSystem: "nfs", - InternalName: "vol1", - } - lun := api.Lun{ - Size: "1g", Name: "lun_vol1", - VolumeName: "volumeName", - } - luns := []api.Lun{lun} - - mockAPI.EXPECT().LunList(ctx, "/vol/*/vol1").Return(luns, nil) - mockAPI.EXPECT().EnsureLunMapped(ctx, "igroup", "/vol/volumeName/vol1", false).Return(123, nil) - mockAPI.EXPECT().IscsiNodeGetNameRequest(ctx).Return("iscsiNode", nil) - mockAPI.EXPECT().LunGetByName(ctx, "/vol/volumeName/vol1").Return(&lun, fmt.Errorf("couldn't get lun")) - - result := d.CreateFollowup(ctx, volConfig) - - assert.Error(t, result) -} - func TestOntapSanEconomyInitialize(t *testing.T) { mockAPI, d := newMockOntapSanEcoDriver(t) commonConfig := &drivers.CommonStorageDriverConfig{ diff --git a/storage_drivers/ontap/ontap_san_test.go b/storage_drivers/ontap/ontap_san_test.go index b469809f2..df425dee3 100644 --- a/storage_drivers/ontap/ontap_san_test.go +++ b/storage_drivers/ontap/ontap_san_test.go @@ -542,7 +542,7 @@ func TestOntapSanVolumePublishManaged(t *testing.T) { mockAPI.EXPECT().IscsiInterfaceGet(ctx, gomock.Any()).Return([]string{"iscsi_if"}, nil).Times(1) mockAPI.EXPECT().LunGetFSType(ctx, "/vol/lunName/lun0") mockAPI.EXPECT().EnsureIgroupAdded(ctx, gomock.Any(), gomock.Any()).Times(1) - mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(1, nil) + mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any()).Times(1).Return(1, nil) mockAPI.EXPECT().LunMapGetReportingNodes(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{"node1"}, nil) mockAPI.EXPECT().GetSLMDataLifs(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{"1.1.1.1"}, nil) @@ -582,7 +582,7 @@ func TestOntapSanVolumePublishUnmanaged(t *testing.T) { mockAPI.EXPECT().IscsiInterfaceGet(ctx, gomock.Any()).Return([]string{"iscsi_if"}, nil).Times(1) mockAPI.EXPECT().LunGetFSType(ctx, "/vol/lunName/lun0") mockAPI.EXPECT().EnsureIgroupAdded(ctx, gomock.Any(), gomock.Any()).Times(1) - mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(1, nil) + mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any()).Times(1).Return(1, nil) mockAPI.EXPECT().LunMapGetReportingNodes(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{"node1"}, nil) mockAPI.EXPECT().GetSLMDataLifs(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{"1.1.1.1"}, nil) @@ -622,7 +622,7 @@ func TestOntapSanVolumePublishSLMError(t *testing.T) { mockAPI.EXPECT().IscsiInterfaceGet(ctx, gomock.Any()).Return([]string{"iscsi_if"}, nil).Times(1) mockAPI.EXPECT().LunGetFSType(ctx, "/vol/lunName/lun0") mockAPI.EXPECT().EnsureIgroupAdded(ctx, gomock.Any(), gomock.Any()).Times(1) - mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(1, nil) + mockAPI.EXPECT().EnsureLunMapped(ctx, gomock.Any(), gomock.Any()).Times(1).Return(1, nil) mockAPI.EXPECT().LunMapGetReportingNodes(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{"node1"}, nil) mockAPI.EXPECT().GetSLMDataLifs(ctx, gomock.Any(), gomock.Any()).Times(1).Return([]string{}, nil)