From 2527f55f2027ec0c5dc62fb129d13f0ef7afa25d Mon Sep 17 00:00:00 2001 From: tssushma <98810659+tssushma@users.noreply.github.com> Date: Fri, 15 Dec 2023 14:02:15 +0530 Subject: [PATCH] Fixing the linting error (#45) --- .github/workflows/linters.yaml | 2 +- base.go | 8 +- base_test.go | 175 +++++++++++++++++++---------- fc.go | 33 ++++-- fc_test.go | 16 +-- gobrick_test.go | 30 +++-- internal/logger/logger.go | 6 +- internal/mockhelper/mockhelper.go | 9 +- internal/tracer/tracer.go | 2 +- internal/wrappers/wrappers_mock.go | 11 +- inttests/fc_test.go | 5 +- inttests/iscsi_test.go | 15 +-- iscsi.go | 34 ++++-- iscsi_test.go | 6 +- nvme.go | 34 +++--- pkg/multipath/multipath_test.go | 3 +- pkg/powerpath/powerpath.go | 12 +- pkg/powerpath/powerpath_test.go | 3 +- pkg/scsi/scsi.go | 14 +-- pkg/scsi/scsi_test.go | 10 +- rdm.go | 3 +- sync_tools.go | 1 - sync_tools_test.go | 3 +- 23 files changed, 266 insertions(+), 169 deletions(-) diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index 8749402..e7aad32 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: "1.21" + go-version: "1.20" cache: false - name: Checkout the code uses: actions/checkout@v3.2.0 diff --git a/base.go b/base.go index 447a56c..7f0f392 100644 --- a/base.go +++ b/base.go @@ -87,7 +87,6 @@ func (bc *baseConnector) disconnectDevicesByDeviceName(ctx context.Context, name var wwn string if strings.HasPrefix(name, deviceMapperPrefix) { wwn, err = bc.getDMWWN(ctx, name) - } else { wwn, err = bc.scsi.GetDeviceWWN(ctx, []string{name}) } @@ -114,7 +113,6 @@ func (bc *baseConnector) disconnectNVMEDevicesByDeviceName(ctx context.Context, var wwn string if strings.HasPrefix(name, deviceMapperPrefix) { wwn, err = bc.getNVMEDMWWN(ctx, name) - } else { wwn, err = bc.scsi.GetNVMEDeviceWWN(ctx, []string{name}) } @@ -132,7 +130,8 @@ func (bc *baseConnector) disconnectNVMEDevicesByDeviceName(ctx context.Context, } func (bc *baseConnector) cleanNVMeDevices(ctx context.Context, - force bool, devices []string) error { + force bool, devices []string, +) error { defer tracer.TraceFuncCall(ctx, "baseConnector.cleanNVMeDevices")() var newDevices []string for _, device := range devices { @@ -168,7 +167,8 @@ func (bc *baseConnector) cleanNVMeDevices(ctx context.Context, } func (bc *baseConnector) cleanDevices(ctx context.Context, - force bool, devices []string) error { + force bool, devices []string, +) error { defer tracer.TraceFuncCall(ctx, "baseConnector.cleanDevices")() dm, err := bc.scsi.GetDMDeviceByChildren(ctx, devices) if err != nil { diff --git a/base_test.go b/base_test.go index 01454d0..0ad548d 100644 --- a/base_test.go +++ b/base_test.go @@ -53,284 +53,340 @@ type baseMockHelper struct { SCSIGetDMDeviceByChildrenOKReturn string SCSIGetDMChildrenOKReturn []string SCSIGetDeviceNameByHCTLOKReturn string - mh.MockHelper } func (bmh *baseMockHelper) MultipathAddWWIDCall( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return m.EXPECT().AddWWID(bmh.Ctx, bmh.MultipathAddWWIDCallWWID) } func (bmh *baseMockHelper) MultipathAddWWIDOK( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathAddWWIDCall(m).Return(nil) } func (bmh *baseMockHelper) MultipathAddWWIDErr( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathAddWWIDCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) MultipathAddPathCall( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return m.EXPECT().AddPath(bmh.Ctx, bmh.MultipathAddPathCallPath) } func (bmh *baseMockHelper) MultipathAddPathOK( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathAddPathCall(m).Return(nil) } func (bmh *baseMockHelper) MultipathAddPathErr( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathAddPathCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) MultipathDelPathCall( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return m.EXPECT().DelPath(bmh.Ctx, bmh.MultipathDelPathCallPath) } func (bmh *baseMockHelper) MultipathDelPathOK( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathDelPathCall(m).Return(nil) } func (bmh *baseMockHelper) MultipathDelPathErr( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathDelPathCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) MultipathFlushDeviceCall( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return m.EXPECT().FlushDevice(bmh.Ctx, bmh.MultipathFlushDeviceCallMapName) } func (bmh *baseMockHelper) MultipathFlushDeviceOK( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathFlushDeviceCall(m).Return(nil) } func (bmh *baseMockHelper) MultipathFlushDeviceErr( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathFlushDeviceCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) MultipathIsDaemonRunningCall( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return m.EXPECT().IsDaemonRunning(bmh.Ctx) } func (bmh *baseMockHelper) MultipathIsDaemonRunningOK( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathIsDaemonRunningCall(m).Return(bmh.MultipathIsDaemonRunningOKReturn) } func (bmh *baseMockHelper) MultipathGetDMWWIDCall( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return m.EXPECT().GetDMWWID(bmh.Ctx, bmh.MultipathGetDMWWIDCallMapName) } func (bmh *baseMockHelper) MultipathGetDMWWIDOK( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathGetDMWWIDCall(m).Return(bmh.MultipathGetDMWWIDOKReturn, nil) } func (bmh *baseMockHelper) MultipathGetDMWWIDErr( - m *intmultipath.MockMultipath) *gomock.Call { + m *intmultipath.MockMultipath, +) *gomock.Call { return bmh.MultipathGetDMWWIDCall(m).Return("", mh.ErrTest) } func (bmh *baseMockHelper) SCSIIsDeviceExistCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().IsDeviceExist(bmh.Ctx, bmh.SCSIIsDeviceExistCallDevice) } func (bmh *baseMockHelper) SCSIIsDeviceExistOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIIsDeviceExistCall(m).Return(bmh.SCSIIsDeviceExistOKReturn) } func (bmh *baseMockHelper) SCSIRescanSCSIHostByHCTLCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().RescanSCSIHostByHCTL(bmh.Ctx, bmh.SCSIRescanSCSIHostByHCTLCallH) } func (bmh *baseMockHelper) SCSIRescanSCSIHostByHCTLOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIRescanSCSIHostByHCTLCall(m).Return(nil) } func (bmh *baseMockHelper) SCSIRescanSCSIHostByHCTLErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIRescanSCSIHostByHCTLCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) SCSIRescanSCSIDeviceByHCTLCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().RescanSCSIDeviceByHCTL(bmh.Ctx, bmh.SCSIRescanSCSIDeviceByHCTLCallH) } func (bmh *baseMockHelper) SCSIRescanSCSIDeviceByHCTLOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIRescanSCSIDeviceByHCTLCall(m).Return(nil) } func (bmh *baseMockHelper) SCSIRescanSCSIDeviceByHCTLErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIRescanSCSIDeviceByHCTLCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByHCTLCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().DeleteSCSIDeviceByHCTL(bmh.Ctx, bmh.SCSIDeleteSCSIDeviceByHCTLCallH) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByHCTLOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIDeleteSCSIDeviceByHCTLCall(m).Return(nil) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByHCTLErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIDeleteSCSIDeviceByHCTLCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByNameCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().DeleteSCSIDeviceByName(bmh.Ctx, bmh.SCSIDeleteSCSIDeviceByNameCallName) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByNameOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIDeleteSCSIDeviceByNameCall(m).Return(nil) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByNameErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIDeleteSCSIDeviceByNameCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByPathCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().DeleteSCSIDeviceByPath(bmh.Ctx, bmh.SCSIDeleteSCSIDeviceByPathCallPath) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByPathOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIDeleteSCSIDeviceByPathCall(m).Return(nil) } func (bmh *baseMockHelper) SCSIDeleteSCSIDeviceByPathErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIDeleteSCSIDeviceByPathCall(m).Return(mh.ErrTest) } func (bmh *baseMockHelper) SCSIGetDeviceWWNCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().GetDeviceWWN(bmh.Ctx, bmh.SCSIGetDeviceWWNCallDevices) } func (bmh *baseMockHelper) SCSIGetDeviceWWNOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDeviceWWNCall(m).Return(bmh.SCSIGetDeviceWWNOKReturn, nil) } func (bmh *baseMockHelper) SCSIGetDeviceWWNErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDeviceWWNCall(m).Return("", mh.ErrTest) } func (bmh *baseMockHelper) SCSIGetDevicesByWWNCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().GetDevicesByWWN(bmh.Ctx, bmh.SCSIGetDevicesByWWNCallWWN) } func (bmh *baseMockHelper) SCSIGetDevicesByWWNOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDevicesByWWNCall(m).Return(bmh.SCSIGetDevicesByWWNOKReturn, nil) } func (bmh *baseMockHelper) SCSIGetDevicesByWWNErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDevicesByWWNCall(m).Return(nil, mh.ErrTest) } func (bmh *baseMockHelper) SCSIGetDMDeviceByChildrenCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().GetDMDeviceByChildren(bmh.Ctx, bmh.SCSIGetDMDeviceByChildrenCallDevices) } func (bmh *baseMockHelper) SCSIGetDMDeviceByChildrenOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDMDeviceByChildrenCall(m).Return(bmh.SCSIGetDMDeviceByChildrenOKReturn, nil) } func (bmh *baseMockHelper) SCSIGetDMDeviceByChildrenErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDMDeviceByChildrenCall(m).Return("", mh.ErrTest) } func (bmh *baseMockHelper) SCSIGetDMChildrenCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().GetDMChildren(bmh.Ctx, bmh.SCSIGetDMChildrenCallDmPath) } + func (bmh *baseMockHelper) SCSIGetDMChildrenOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDMChildrenCall(m).Return(bmh.SCSIGetDMChildrenOKReturn, nil) } + func (bmh *baseMockHelper) SCSIGetDMChildrenErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDMChildrenCall(m).Return(nil, mh.ErrTest) } func (bmh *baseMockHelper) SCSICheckDeviceIsValidCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().CheckDeviceIsValid(bmh.Ctx, bmh.SCSICheckDeviceIsValidCallDevice) } func (bmh *baseMockHelper) SCSICheckDeviceIsValidOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSICheckDeviceIsValidCall(m).Return(bmh.SCSICheckDeviceIsValidOKReturn) } func (bmh *baseMockHelper) SCSIGetDeviceNameByHCTLCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().GetDeviceNameByHCTL(bmh.Ctx, bmh.SCSIGetDeviceNameByHCTLCallH) } func (bmh *baseMockHelper) SCSIGetDeviceNameByHCTLOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDeviceNameByHCTLCall(m).Return(bmh.SCSIGetDeviceNameByHCTLOKReturn, nil) } func (bmh *baseMockHelper) SCSIGetDeviceNameByHCTLErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIGetDeviceNameByHCTLCall(m).Return("", mh.ErrTest) } func (bmh *baseMockHelper) SCSIWaitUdevSymlinkCall( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return m.EXPECT().WaitUdevSymlink( bmh.Ctx, bmh.SCSIWaitUdevSymlinkCallDevice, bmh.SCSIWaitUdevSymlinkCallWWN) } func (bmh *baseMockHelper) SCSIWaitUdevSymlinkOK( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIWaitUdevSymlinkCall(m).Return(nil) } func (bmh *baseMockHelper) SCSIWaitUdevSymlinkErr( - m *intscsi.MockSCSI) *gomock.Call { + m *intscsi.MockSCSI, +) *gomock.Call { return bmh.SCSIWaitUdevSymlinkCall(m).Return(mh.ErrTest) } func BaseConnectorCleanDeviceMock(mock *baseMockHelper, - scsi *intscsi.MockSCSI, mp *intmultipath.MockMultipath) { - + scsi *intscsi.MockSCSI, mp *intmultipath.MockMultipath, +) { mock.SCSIGetDMDeviceByChildrenCallDevices = []string{ - mh.ValidDeviceName, mh.ValidDeviceName2} + mh.ValidDeviceName, mh.ValidDeviceName2, + } mock.SCSIGetDMDeviceByChildrenOKReturn = mh.ValidDMName mock.SCSIGetDMDeviceByChildrenOK(scsi) @@ -350,7 +406,8 @@ func BaseConnectorCleanDeviceMock(mock *baseMockHelper, } func BaserConnectorDisconnectDevicesByDeviceNameMock(mock *baseMockHelper, - scsi *intscsi.MockSCSI, mp *intmultipath.MockMultipath) { + scsi *intscsi.MockSCSI, mp *intmultipath.MockMultipath, +) { mock.SCSIIsDeviceExistCallDevice = mh.ValidDMName mock.SCSIIsDeviceExistOKReturn = true mock.SCSIIsDeviceExistOK(scsi) diff --git a/fc.go b/fc.go index 4e41c02..e320627 100644 --- a/fc.go +++ b/fc.go @@ -79,7 +79,8 @@ func NewFCConnector(params FCConnectorParams) *FCConnector { baseConnectorParams{ MultipathFlushTimeout: params.MultipathFlushTimeout, MultipathFlushRetryTimeout: params.MultipathFlushRetryTimeout, - MultipathFlushRetries: params.MultipathFlushRetries}), + MultipathFlushRetries: params.MultipathFlushRetries, + }), } setTimeouts(&conn.waitDeviceRegisterTimeout, params.WaitDeviceRegisterTimeout, @@ -119,7 +120,7 @@ type FCConnector struct { powerpath intpowerpath.Powerpath scsi intscsi.SCSI - //wrappers + // wrappers filePath wrp.LimitedFilepath os wrp.LimitedOS @@ -239,7 +240,8 @@ func (fc *FCConnector) validateFCVolumeInfo(ctx context.Context, info FCVolumeIn } func (fc *FCConnector) connectDevice( - ctx context.Context, hbas []FCHBA, info FCVolumeInfo) (Device, error) { + ctx context.Context, hbas []FCHBA, info FCVolumeInfo, +) (Device, error) { defer tracer.TraceFuncCall(ctx, "FCConnector.connectDevice")() wwn, err := fc.waitForDeviceWWN(ctx, hbas, info) if err != nil { @@ -307,7 +309,8 @@ func (fc *FCConnector) waitSingleDevice(ctx context.Context, wwn string, devices } func (fc *FCConnector) waitMultipathDevice( - ctx context.Context, wwn string, devices []string) (string, error) { + ctx context.Context, wwn string, devices []string, +) (string, error) { defer tracer.TraceFuncCall(ctx, "FCConnector.waitMultipathDevice")() err := fc.multipath.AddWWID(ctx, wwn) if err != nil { @@ -345,8 +348,10 @@ func (fc *FCConnector) waitMultipathDevice( logger.Info(ctx, "multipath device for WWN %s found: %s", wwn, mpath) return mpath, nil } + func (fc *FCConnector) waitPowerpathDevice( - ctx context.Context, wwn string, devices []string) (string, error) { + ctx context.Context, wwn string, devices []string, +) (string, error) { defer tracer.TraceFuncCall(ctx, "FCConnector.waitPowerpathDevice")() var ppath string for i := 0; i < int(fc.waitDeviceRegisterTimeout.Seconds()); i++ { @@ -374,7 +379,8 @@ func (fc *FCConnector) waitPowerpathDevice( } func (fc *FCConnector) waitForDeviceWWN( - ctx context.Context, hbas []FCHBA, info FCVolumeInfo) (string, error) { + ctx context.Context, hbas []FCHBA, info FCVolumeInfo, +) (string, error) { defer tracer.TraceFuncCall(ctx, "FCConnector.waitForDeviceWWN")() var numRescans, secondsNextScan int @@ -456,7 +462,8 @@ func (fc *FCConnector) waitForDeviceWWN( } func (fc *FCConnector) findHCTLsForFCHBA( - ctx context.Context, hba FCHBA, info FCVolumeInfo) ([]scsi.HCTL, []scsi.HCTL, error) { + ctx context.Context, hba FCHBA, info FCVolumeInfo, +) ([]scsi.HCTL, []scsi.HCTL, error) { defer tracer.TraceFuncCall(ctx, "FCConnector.findHCTLsForFCHBA")() hostDev := hba.HostDevice if len(hostDev) > 4 { @@ -496,9 +503,11 @@ func (fc *FCConnector) findHCTLsForFCHBA( targetPathPart := strings.Split(pathMatch, "/")[4] ct := strings.Split(targetPathPart, ":") if len(ct) >= 3 { - hctl := scsi.HCTL{Host: hostDev, + hctl := scsi.HCTL{ + Host: hostDev, Lun: lun, - Channel: ct[1], Target: ct[2]} + Channel: ct[1], Target: ct[2], + } logger.Info(ctx, "HBA: %s FC device HCTL: %s", hba, hctl) hctlsToDiscover = append(hctlsToDiscover, hctl) } @@ -510,8 +519,10 @@ func (fc *FCConnector) findHCTLsForFCHBA( var hctlsToRescan []scsi.HCTL if needFullRescan { // at least one target port not found, do full scsi rescan - hctlsToRescan = []scsi.HCTL{{Host: hostDev, Lun: "-", - Channel: "-", Target: "-"}} + hctlsToRescan = []scsi.HCTL{{ + Host: hostDev, Lun: "-", + Channel: "-", Target: "-", + }} } else { hctlsToRescan = make([]scsi.HCTL, len(hctlsToDiscover)) copy(hctlsToRescan, hctlsToDiscover) diff --git a/fc_test.go b/fc_test.go index b6ddf5a..86a789b 100644 --- a/fc_test.go +++ b/fc_test.go @@ -79,7 +79,8 @@ func getDefaultFCFields(ctrl *gomock.Controller) fcFields { } func getFCHBASInfoMock(mock *baseMockHelper, - os *wrp.MockLimitedOS, filepath *wrp.MockLimitedFilepath) { + os *wrp.MockLimitedOS, filepath *wrp.MockLimitedFilepath, +) { isFCSupportedMock(mock, os) sysPath := "/sys/class/fc_host/host" sysPathGlob := sysPath + "*" @@ -113,7 +114,9 @@ func isFCSupportedMock(mock *baseMockHelper, os *wrp.MockLimitedOS) { func waitForDeviceWWNMock(mock *baseMockHelper, filepath *wrp.MockLimitedFilepath, - scsi *intscsi.MockSCSI) { + os *wrp.MockLimitedOS, + scsi *intscsi.MockSCSI, +) { findHCTLsForFCHBAMock(mock, filepath, os) mock.SCSIGetDeviceNameByHCTLCallH = validHCTL1 @@ -148,8 +151,8 @@ func waitForDeviceWWNMock(mock *baseMockHelper, } func findHCTLsForFCHBAMock(mock *baseMockHelper, - filepath *wrp.MockLimitedFilepath, os *wrp.MockLimitedOS) { - + filepath *wrp.MockLimitedFilepath, os *wrp.MockLimitedOS, +) { sysPath := "/sys/class/fc_transport/target" sysPathGlob1 := sysPath + validSCSIHost1 + ":*" sysPathGlob2 := sysPath + validSCSIHost2 + ":*" @@ -184,8 +187,8 @@ func cleanConnectionMock(mock *baseMockHelper, filepath *wrp.MockLimitedFilepath, os *wrp.MockLimitedOS, scsi *intscsi.MockSCSI, - multipath *intmultipath.MockMultipath) { - + multipath *intmultipath.MockMultipath, +) { getFCHBASInfoMock(mock, os, filepath) findHCTLsForFCHBAMock(mock, filepath, os) @@ -315,7 +318,6 @@ func TestFCConnector_ConnectVolume(t *testing.T) { mock.SCSICheckDeviceIsValidOK(fields.scsi) cleanConnectionMock(&mock, fields.filePath, fields.os, fields.scsi, fields.multipath) - }, args: defaultArgs, want: Device{}, diff --git a/gobrick_test.go b/gobrick_test.go index 3b57db2..9747348 100644 --- a/gobrick_test.go +++ b/gobrick_test.go @@ -39,17 +39,20 @@ var ( Host: validSCSIHost1, Channel: "0", Target: "0", - Lun: strconv.FormatInt(int64(validLunNumber), 10)} + Lun: strconv.FormatInt(int64(validLunNumber), 10), + } validHCTL1Target1 = scsi.HCTL{ Host: validSCSIHost1, Channel: "0", Target: "1", - Lun: strconv.FormatInt(int64(validLunNumber), 10)} + Lun: strconv.FormatInt(int64(validLunNumber), 10), + } validHCTL2 = scsi.HCTL{ Host: validSCSIHost2, Channel: "0", Target: "0", - Lun: strconv.FormatInt(int64(validLunNumber), 10)} + Lun: strconv.FormatInt(int64(validLunNumber), 10), + } validDevice = Device{ WWN: mockhelper.ValidWWID, Name: mockhelper.ValidDeviceName, @@ -57,7 +60,8 @@ var ( validDeviceMultipath = Device{ Name: mockhelper.ValidDMName, WWN: mockhelper.ValidWWID, - MultipathID: mockhelper.ValidWWID} + MultipathID: mockhelper.ValidWWID, + } ) const ( @@ -73,18 +77,20 @@ var ( type testLogger struct{} -func addToLogData(ctx context.Context, format string, args ...interface{}) { +func addToLogData(format string, args ...interface{}) { logData = append(logData, fmt.Sprintf(format, args...)) } -func (tl *testLogger) Info(ctx context.Context, format string, args ...interface{}) { - addToLogData(ctx, format, args...) +func (tl *testLogger) Info(_ context.Context, format string, args ...interface{}) { + addToLogData(format, args...) } -func (tl *testLogger) Debug(ctx context.Context, format string, args ...interface{}) { - addToLogData(ctx, format, args...) + +func (tl *testLogger) Debug(_ context.Context, format string, args ...interface{}) { + addToLogData(format, args...) } -func (tl *testLogger) Error(ctx context.Context, format string, args ...interface{}) { - addToLogData(ctx, format, args...) + +func (tl *testLogger) Error(_ context.Context, format string, args ...interface{}) { + addToLogData(format, args...) } func TestSetLogger(t *testing.T) { @@ -109,6 +115,6 @@ func TestSetTracer(t *testing.T) { type testTracer struct{} -func (tt *testTracer) Trace(ctx context.Context, format string, args ...interface{}) { +func (tt *testTracer) Trace(_ context.Context, format string, args ...interface{}) { traceData = append(traceData, fmt.Sprintf(format, args...)) } diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 47b67ee..ede19d5 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -45,17 +45,17 @@ type Logger interface { type DummyLogger struct{} // Info is a dummy implementation of logger Info method -func (dl *DummyLogger) Info(ctx context.Context, format string, args ...interface{}) { +func (dl *DummyLogger) Info(_ context.Context, format string, args ...interface{}) { log.Print("INFO: " + fmt.Sprintf(format, args...)) } // Debug is a dummy implementation of logger Debug method -func (dl *DummyLogger) Debug(ctx context.Context, format string, args ...interface{}) { +func (dl *DummyLogger) Debug(_ context.Context, format string, args ...interface{}) { log.Print("DEBUG: " + fmt.Sprintf(format, args...)) } // Error is a dummy implementation of logger Error method -func (dl *DummyLogger) Error(ctx context.Context, format string, args ...interface{}) { +func (dl *DummyLogger) Error(_ context.Context, format string, args ...interface{}) { log.Print("ERROR: " + fmt.Sprintf(format, args...)) } diff --git a/internal/mockhelper/mockhelper.go b/internal/mockhelper/mockhelper.go index dbba22e..0166df6 100644 --- a/internal/mockhelper/mockhelper.go +++ b/internal/mockhelper/mockhelper.go @@ -21,8 +21,10 @@ import ( "errors" "os" - wrp "github.com/dell/gobrick/internal/wrappers" "github.com/dell/goiscsi" + + wrp "github.com/dell/gobrick/internal/wrappers" + "github.com/golang/mock/gomock" ) @@ -106,7 +108,7 @@ func (mh *MockHelper) OSStatFileInfoIsDirOK(m *wrp.MockLimitedFileInfo) *gomock. func (mh *MockHelper) OSOpenFileCall(m *wrp.MockLimitedOS) *gomock.Call { return m.EXPECT().OpenFile( mh.OSOpenFileCallPath, - os.O_APPEND|os.O_WRONLY, os.FileMode(0200)) + os.O_APPEND|os.O_WRONLY, os.FileMode(0o200)) } // OSOpenFileCallErr mocks returning error from OSOpenFileCall @@ -199,7 +201,8 @@ func (mh *MockHelper) OSExecCommandContextCall(m *wrp.MockLimitedOSExec) *gomock // OSExecCommandContextOK mocks returning success from OSExecCommandContextCall func (mh *MockHelper) OSExecCommandContextOK(m *wrp.MockLimitedOSExec) ( - *gomock.Call, *wrp.MockLimitedOSExecCmd) { + *gomock.Call, *wrp.MockLimitedOSExecCmd, +) { cmdMock := wrp.NewMockLimitedOSExecCmd(mh.Ctrl) call := mh.OSExecCommandContextCall(m).Return(cmdMock) return call, cmdMock diff --git a/internal/tracer/tracer.go b/internal/tracer/tracer.go index f4bc119..29c5be7 100644 --- a/internal/tracer/tracer.go +++ b/internal/tracer/tracer.go @@ -50,7 +50,7 @@ func TraceFuncCall(ctx context.Context, funcName string) func() { type DummyTracer struct{} // Trace contains dummy implementation of trace function -func (dl *DummyTracer) Trace(ctx context.Context, format string, args ...interface{}) { +func (dl *DummyTracer) Trace(_ context.Context, format string, args ...interface{}) { fmt.Printf(format+"\n", args...) } diff --git a/internal/wrappers/wrappers_mock.go b/internal/wrappers/wrappers_mock.go index 5b28d7d..f07adc8 100644 --- a/internal/wrappers/wrappers_mock.go +++ b/internal/wrappers/wrappers_mock.go @@ -19,10 +19,11 @@ package wrappers import ( context "context" - goiscsi "github.com/dell/goiscsi" - gomock "github.com/golang/mock/gomock" os "os" reflect "reflect" + + goiscsi "github.com/dell/goiscsi" + gomock "github.com/golang/mock/gomock" ) // MockLimitedFileInfo is a mock of LimitedFileInfo interface @@ -218,7 +219,7 @@ func (m *MockLimitedIOUtil) EXPECT() *MockLimitedIOUtilMockRecorder { } // ReadFile mocks base method -func (m *MockLimitedIOUtil) ReadFile(filename string) ([]byte, error) { +func (m *MockLimitedOS) ReadFile(filename string) ([]byte, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReadFile", filename) ret0, _ := ret[0].([]byte) @@ -227,9 +228,9 @@ func (m *MockLimitedIOUtil) ReadFile(filename string) ([]byte, error) { } // ReadFile indicates an expected call of ReadFile -func (mr *MockLimitedIOUtilMockRecorder) ReadFile(filename interface{}) *gomock.Call { +func (mr *MockLimitedOSMockRecorder) ReadFile(filename interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadFile", reflect.TypeOf((*MockLimitedIOUtil)(nil).ReadFile), filename) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadFile", reflect.TypeOf((*MockLimitedOS)(nil).ReadFile), filename) } // MockLimitedFilepath is a mock of LimitedFilepath interface diff --git a/inttests/fc_test.go b/inttests/fc_test.go index 33a6aa9..6efea16 100644 --- a/inttests/fc_test.go +++ b/inttests/fc_test.go @@ -20,11 +20,12 @@ package inttests import ( "context" - "github.com/dell/gobrick" - "github.com/stretchr/testify/assert" "log" "testing" "time" + + "github.com/dell/gobrick" + "github.com/stretchr/testify/assert" ) const ( diff --git a/inttests/iscsi_test.go b/inttests/iscsi_test.go index c68d506..3addb17 100644 --- a/inttests/iscsi_test.go +++ b/inttests/iscsi_test.go @@ -21,13 +21,14 @@ package inttests import ( "context" "fmt" - "github.com/dell/gobrick" - "github.com/dell/gobrick/pkg/multipath" - "github.com/stretchr/testify/assert" "log" "sync" "testing" "time" + + "github.com/dell/gobrick" + "github.com/dell/gobrick/pkg/multipath" + "github.com/stretchr/testify/assert" ) const ( @@ -90,13 +91,13 @@ func TestISCSI_ConnectDisconnect(t *testing.T) { } log.Printf("ID: %d RETRY!", i) } - //assert.Nil(t, err) - //assert.NotEmpty(t, device.Name, device.WWN) + // assert.Nil(t, err) + // assert.NotEmpty(t, device.Name, device.WWN) wg.Done() }() } wg.Wait() - //assert.Nil(t, iscsiConnector.DisconnectVolume(ctx, volume)) + // assert.Nil(t, iscsiConnector.DisconnectVolume(ctx, volume)) } func TestISCSI_ConnectDisconnectByName(t *testing.T) { @@ -112,7 +113,7 @@ func TestISCSI_ConnectDisconnectByName(t *testing.T) { assert.Nil(t, iscsiConnector.DisconnectVolumeByDeviceName(ctx, device.Name)) } -func Test_readWWID(t *testing.T) { +func Test_readWWID(_ *testing.T) { m := multipath.NewMultipath("/noderoot") fmt.Println(m.GetDMWWID(context.Background(), "dm-80")) } diff --git a/iscsi.go b/iscsi.go index 09dede1..35fb5eb 100644 --- a/iscsi.go +++ b/iscsi.go @@ -22,7 +22,6 @@ import ( "context" "errors" "fmt" - log "github.com/sirupsen/logrus" "math" "os/exec" "path" @@ -31,6 +30,8 @@ import ( "sync" "time" + log "github.com/sirupsen/logrus" + "github.com/dell/gobrick/internal/logger" intmultipath "github.com/dell/gobrick/internal/multipath" intpowerpath "github.com/dell/gobrick/internal/powerpath" @@ -89,7 +90,8 @@ func NewISCSIConnector(params ISCSIConnectorParams) *ISCSIConnector { baseConnectorParams{ MultipathFlushTimeout: params.MultipathFlushTimeout, MultipathFlushRetryTimeout: params.MultipathFlushRetryTimeout, - MultipathFlushRetries: params.MultipathFlushRetries}), + MultipathFlushRetries: params.MultipathFlushRetries, + }), chapPassword: params.ChapPassword, chapUser: params.ChapUser, chapEnabled: params.ChapEnabled, @@ -306,7 +308,8 @@ func (c *ISCSIConnector) cleanConnection(ctx context.Context, force bool, info I } func (c *ISCSIConnector) connectSingleDevice( - ctx context.Context, sessions []goiscsi.ISCSISession, info ISCSIVolumeInfo) (Device, error) { + ctx context.Context, sessions []goiscsi.ISCSISession, info ISCSIVolumeInfo, +) (Device, error) { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.connectSingleDevice")() devCH := make(chan string, len(sessions)) wg := sync.WaitGroup{} @@ -393,7 +396,8 @@ func readDevicesFromResultCH(ch chan string, result []string) []string { } func (c *ISCSIConnector) connectPowerpathDevice( - ctx context.Context, sessions []goiscsi.ISCSISession, info ISCSIVolumeInfo) (Device, error) { + ctx context.Context, sessions []goiscsi.ISCSISession, info ISCSIVolumeInfo, +) (Device, error) { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.connectPowerpathDevice")() devCH := make(chan string, len(sessions)) wg := sync.WaitGroup{} @@ -475,7 +479,8 @@ func (c *ISCSIConnector) connectPowerpathDevice( } func (c *ISCSIConnector) connectMultipathDevice( - ctx context.Context, sessions []goiscsi.ISCSISession, info ISCSIVolumeInfo) (Device, error) { + ctx context.Context, sessions []goiscsi.ISCSISession, info ISCSIVolumeInfo, +) (Device, error) { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.connectMultipathDevice")() devCH := make(chan string, len(sessions)) wg := sync.WaitGroup{} @@ -566,6 +571,7 @@ func (c *ISCSIConnector) connectMultipathDevice( time.Sleep(time.Second) } } + func (c *ISCSIConnector) validateISCSIVolumeInfo(ctx context.Context, info ISCSIVolumeInfo) error { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.validateISCSIVolumeInfo")() if len(info.Targets) == 0 { @@ -582,7 +588,8 @@ func (c *ISCSIConnector) validateISCSIVolumeInfo(ctx context.Context, info ISCSI func (c *ISCSIConnector) discoverDevice( ctx context.Context, rescans int, wg *sync.WaitGroup, result chan string, - session goiscsi.ISCSISession, info ISCSIVolumeInfo) { + session goiscsi.ISCSISession, info ISCSIVolumeInfo, +) { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.discoverDevice")() defer wg.Done() lun := strconv.FormatInt(int64(info.Lun), 10) @@ -652,7 +659,8 @@ func (c *ISCSIConnector) discoverDevice( } func (c *ISCSIConnector) checkISCSISessions( - ctx context.Context, info ISCSIVolumeInfo) ([]goiscsi.ISCSISession, error) { + ctx context.Context, info ISCSIVolumeInfo, +) ([]goiscsi.ISCSISession, error) { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.checkISCSISessions")() var activeSessions []goiscsi.ISCSISession var targetsToLogin []ISCSITargetInfo @@ -711,7 +719,8 @@ func (c *ISCSIConnector) checkISCSISessions( } func (c *ISCSIConnector) tryISCSILogin( - ctx context.Context, targets []ISCSITargetInfo, force bool) ([]goiscsi.ISCSISession, error) { + ctx context.Context, targets []ISCSITargetInfo, force bool, +) ([]goiscsi.ISCSISession, error) { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.tryISCSILogin")() var sessions []goiscsi.ISCSISession for _, t := range targets { @@ -781,14 +790,16 @@ func (c *ISCSIConnector) tryEnableManualISCSISessionMGMT(ctx context.Context, ta } func (c *ISCSIConnector) isISCSISessionActive( - ctx context.Context, session goiscsi.ISCSISession) bool { + ctx context.Context, session goiscsi.ISCSISession, +) bool { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.isISCSISessionActive")() return session.ISCSISessionState == goiscsi.ISCSISessionStateLOGGEDIN && session.ISCSIConnectionState == goiscsi.ISCSIConnectionStateLOGGEDIN } func (c *ISCSIConnector) getSessionByTargetInfo(ctx context.Context, - target ISCSITargetInfo) (goiscsi.ISCSISession, bool, error) { + target ISCSITargetInfo, +) (goiscsi.ISCSISession, bool, error) { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.getSessionByTargetInfo")() r := goiscsi.ISCSISession{} logPrefix := fmt.Sprintf("Portal: %s, Target: %s :", target.Portal, target.Target) @@ -814,7 +825,8 @@ func (c *ISCSIConnector) getSessionByTargetInfo(ctx context.Context, } func (c *ISCSIConnector) findHCTLByISCSISessionID( - ctx context.Context, sessionID string, lun string) (scsi.HCTL, error) { + ctx context.Context, sessionID string, lun string, +) (scsi.HCTL, error) { defer tracer.TraceFuncCall(ctx, "ISCSIConnector.findHCTLByISCSISessionID")() result := scsi.HCTL{} sessionPattern := "/sys/class/iscsi_host/host*/device/session%s" diff --git a/iscsi_test.go b/iscsi_test.go index cf269aa..d293396 100644 --- a/iscsi_test.go +++ b/iscsi_test.go @@ -340,7 +340,6 @@ func TestISCSIConnector_ConnectVolume(t *testing.T) { mock.SCSICheckDeviceIsValidCallDevice = mockhelper.ValidDMPath mock.SCSICheckDeviceIsValidOKReturn = true mock.SCSICheckDeviceIsValidOK(fields.scsi) - }, args: defaultArgs, want: validDeviceMultipath, @@ -359,12 +358,12 @@ func TestISCSIConnector_ConnectVolume(t *testing.T) { mock.SCSICheckDeviceIsValidCallDevice = mockhelper.ValidDevicePath2 mock.SCSICheckDeviceIsValidOKReturn = true mock.SCSICheckDeviceIsValidOK(fields.scsi) - }, args: defaultArgs, want: Device{ WWN: mockhelper.ValidWWID, - Name: mockhelper.ValidDeviceName2}, + Name: mockhelper.ValidDeviceName2, + }, wantErr: false, }, { @@ -558,7 +557,6 @@ func TestISCSIConnector_DisconnectVolume(t *testing.T) { mock.SCSIGetDeviceNameByHCTLOK(fields.scsi) BaseConnectorCleanDeviceMock(&mock, fields.scsi, fields.multipath) - }, args: defaultArgs, wantErr: false, diff --git a/nvme.go b/nvme.go index d1c1a9c..6a0abf3 100644 --- a/nvme.go +++ b/nvme.go @@ -101,7 +101,8 @@ func NewNVMeConnector(params NVMeConnectorParams) *NVMeConnector { baseConnectorParams{ MultipathFlushTimeout: params.MultipathFlushTimeout, MultipathFlushRetryTimeout: params.MultipathFlushRetryTimeout, - MultipathFlushRetries: params.MultipathFlushRetries}), + MultipathFlushRetries: params.MultipathFlushRetries, + }), } nvmeOpts := make(map[string]string) @@ -366,7 +367,8 @@ func (c *NVMeConnector) connectSingleDevice(ctx context.Context, info NVMeVolume } func (c *NVMeConnector) connectMultipathDevice( - ctx context.Context, sessions []gonvme.NVMESession, info NVMeVolumeInfo, useFC bool) (Device, error) { + ctx context.Context, _ []gonvme.NVMESession, info NVMeVolumeInfo, useFC bool, +) (Device, error) { defer tracer.TraceFuncCall(ctx, "NVMeConnector.connectMultipathDevice")() devCH := make(chan DevicePathResult) wg := sync.WaitGroup{} @@ -433,7 +435,7 @@ func (c *NVMeConnector) connectMultipathDevice( } } if mpath != "" { - //use nguid as wwn for nvme devices + // use nguid as wwn for nvme devices var err error if err = c.scsi.WaitUdevSymlinkNVMe(ctx, mpath, nguid); err == nil { logger.Info(ctx, "multipath device found: %s", mpath) @@ -529,7 +531,6 @@ func (c *NVMeConnector) discoverDevice(ctx context.Context, wg *sync.WaitGroup, } func (c *NVMeConnector) wwnMatches(nguid, wwn string) bool { - /* Sample wwn : naa.68ccf098001111a2222b3d4444a1b23c wwn1 : 1111a2222b3d4444 @@ -568,32 +569,31 @@ func (c *NVMeConnector) tryNVMeConnect(ctx context.Context, info NVMeVolumeInfo, if err != nil { log.Errorf("Couldn't connect to NVMeFC target") continue - } else { - return nil } + return nil } } } return nil } -func readNVMeDevicesFromResultCH(ch chan DevicePathResult, result []string) ([]string, string) { - +func readNVMeDevicesFromResultCH(ch chan DevicePathResult, _ []string) ([]string, string) { devicePathResult := <-ch var devicePaths []string - for _, path := range devicePathResult.devicePaths { - // modify path /dev/nvme0n1 -> nvme0n1 - newpath := strings.ReplaceAll(path, "/dev/", "") + for _, dpath := range devicePathResult.devicePaths { + // modify dpath /dev/nvme0n1 -> nvme0n1 + newpath := strings.ReplaceAll(dpath, "/dev/", "") devicePaths = append(devicePaths, newpath) } return devicePaths, devicePathResult.nguid } func (c *NVMeConnector) checkNVMeSessions( - ctx context.Context, info NVMeVolumeInfo) ([]gonvme.NVMESession, error) { + ctx context.Context, info NVMeVolumeInfo, +) ([]gonvme.NVMESession, error) { defer tracer.TraceFuncCall(ctx, "NVMeConnector.checkNVMeSessions")() var activeSessions []gonvme.NVMESession - //var targetsToLogin []NVMeTargetInfo + // var targetsToLogin []NVMeTargetInfo for _, t := range info.Targets { logger.Info(ctx, "check NVMe session for %s %s", t.Portal, t.Target) @@ -603,9 +603,8 @@ func (c *NVMeConnector) checkNVMeSessions( logger.Error(ctx, "unable to get nvme session info: %s", err.Error()) continue - } else { - activeSessions = append(activeSessions, session) } + activeSessions = append(activeSessions, session) } errMsg := "can't find active nvme session" @@ -619,7 +618,8 @@ func (c *NVMeConnector) checkNVMeSessions( } func (c *NVMeConnector) getSessionByTargetInfo(ctx context.Context, - target NVMeTargetInfo) (gonvme.NVMESession, bool, error) { + target NVMeTargetInfo, +) (gonvme.NVMESession, bool, error) { defer tracer.TraceFuncCall(ctx, "NVMeConnector.getSessionByTargetInfo")() r := gonvme.NVMESession{} logPrefix := fmt.Sprintf("Portal: %s, Target: %s :", target.Portal, target.Target) @@ -629,7 +629,7 @@ func (c *NVMeConnector) getSessionByTargetInfo(ctx context.Context, return r, false, err } var found bool - //TODO: check if comparision needs contains check + // TODO: check if comparision needs contains check for _, s := range sessions { if s.Target == target.Target && s.Portal == target.Portal { r = s diff --git a/pkg/multipath/multipath_test.go b/pkg/multipath/multipath_test.go index 502f9fe..49f11b7 100644 --- a/pkg/multipath/multipath_test.go +++ b/pkg/multipath/multipath_test.go @@ -60,7 +60,8 @@ type t struct { } func getMultipathCommonTestCases(mocks mh.MockHelper, defaultArgs interface{}, - ctrl *gomock.Controller) []t { + ctrl *gomock.Controller, +) []t { return []t{ { name: "ok", diff --git a/pkg/powerpath/powerpath.go b/pkg/powerpath/powerpath.go index 0816e1f..11c2ab6 100644 --- a/pkg/powerpath/powerpath.go +++ b/pkg/powerpath/powerpath.go @@ -23,12 +23,13 @@ package powerpath import ( "context" "fmt" + "strings" + "github.com/dell/gobrick/internal/logger" "github.com/dell/gobrick/internal/tracer" wrp "github.com/dell/gobrick/internal/wrappers" "github.com/dell/gobrick/pkg/utils" log "github.com/sirupsen/logrus" - "strings" ) const ( @@ -95,6 +96,7 @@ func (mp *Powerpath) isDaemonRunning(ctx context.Context) bool { } return true } + func (mp *Powerpath) getPowerPathDevices(ctx context.Context, devices []string) (string, error) { logger.Info(ctx, "powerpath - trying to find powerpath emc name inside powerpath module") var match string @@ -106,10 +108,10 @@ func (mp *Powerpath) getPowerPathDevices(ctx context.Context, devices []string) return "", err } op := strings.Split(string(out), "\n") - //L#0 Pseudo name=emcpowerc - //L#1 Symmetrix ID=000197901586 - //L#3 Logical device ID=00002DCE - //L#4 Device WWN=60000970000197901586533032444345 + // L#0 Pseudo name=emcpowerc + // L#1 Symmetrix ID=000197901586 + // L#3 Logical device ID=00002DCE + // L#4 Device WWN=60000970000197901586533032444345 for _, line := range op { if strings.Contains(line, "Pseudo name") { tokens := strings.Split(line, "=") diff --git a/pkg/powerpath/powerpath_test.go b/pkg/powerpath/powerpath_test.go index c58e7de..b99ef4e 100644 --- a/pkg/powerpath/powerpath_test.go +++ b/pkg/powerpath/powerpath_test.go @@ -59,7 +59,8 @@ type t struct { } func getPowerpathCommonTestCases(mocks mh.MockHelper, defaultArgs interface{}, - ctrl *gomock.Controller) []t { + ctrl *gomock.Controller, +) []t { return []t{ { name: "ok", diff --git a/pkg/scsi/scsi.go b/pkg/scsi/scsi.go index b48273b..abcc5eb 100644 --- a/pkg/scsi/scsi.go +++ b/pkg/scsi/scsi.go @@ -205,7 +205,7 @@ func (s *Scsi) rescanSCSIHostByHCTL(ctx context.Context, addr HCTL) error { filePath := fmt.Sprintf("%s/host%s/scan", hostsDir, addr.Host) scanString := fmt.Sprintf("%s %s %s", addr.Channel, addr.Target, addr.Lun) logger.Info(ctx, "rescan scsi: %s %s", addr.Host, scanString) - scanFile, err := s.os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0200) + scanFile, err := s.os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0o200) if err != nil { logger.Error(ctx, "Failed to open %s", filePath) return err @@ -323,7 +323,7 @@ func (s *Scsi) deleteSCSIDeviceByPath(ctx context.Context, devPath string) error logger.Error(ctx, msg) return errors.New(msg) } - deleteFile, err := s.os.OpenFile(deletePath, os.O_APPEND|os.O_WRONLY, 0200) + deleteFile, err := s.os.OpenFile(deletePath, os.O_APPEND|os.O_WRONLY, 0o200) if err != nil { logger.Error(ctx, "could not open %s path", deletePath) // ignore @@ -376,8 +376,7 @@ func (s *Scsi) getDMDeviceByChildren(ctx context.Context, devices []string) (str // GetNVMEMultipathDMName finds the multipath DM mame for NVMe func (s *Scsi) GetNVMEMultipathDMName(device string, pattern string) ([]string, error) { - - var retryCount = 0 + retryCount := 0 for { matches, err := s.filePath.Glob(fmt.Sprintf(pattern, device)) if len(matches) > 0 || retryCount == maxRetryCount { @@ -474,7 +473,7 @@ func (s *Scsi) getDevicesByWWN(ctx context.Context, wwn string) ([]string, error return nil, nil } -func (s *Scsi) checkExist(ctx context.Context, device string) bool { +func (s *Scsi) checkExist(_ context.Context, device string) bool { _, err := s.os.Stat(device) return err == nil } @@ -536,7 +535,7 @@ func (s *Scsi) rescanSCSIDeviceByHCTL(ctx context.Context, h HCTL) error { } devicePath := fmt.Sprintf("/sys/class/scsi_device/%s:%s:%s:%s/device/rescan", h.Host, h.Channel, h.Target, h.Lun) - scanFile, err := s.os.OpenFile(devicePath, os.O_APPEND|os.O_WRONLY, 0200) + scanFile, err := s.os.OpenFile(devicePath, os.O_APPEND|os.O_WRONLY, 0o200) if err != nil { logger.Error(ctx, "failed to open %s: %s", devicePath, err.Error()) return err @@ -573,8 +572,7 @@ func (s *Scsi) waitUdevSymlink(ctx context.Context, deviceName string, wwn strin // GetNVMESymlink return the NVMe symlink for the given path func (s *Scsi) GetNVMESymlink(checkPath string) (string, error) { - - var retryCount = 1 + retryCount := 1 for { symlink, err := s.filePath.EvalSymlinks(checkPath) if err == nil || retryCount == maxRetryCount { diff --git a/pkg/scsi/scsi_test.go b/pkg/scsi/scsi_test.go index c7d5224..ed5e6db 100644 --- a/pkg/scsi/scsi_test.go +++ b/pkg/scsi/scsi_test.go @@ -71,7 +71,6 @@ func TestNewSCSI(t *testing.T) { } func Test_scsi_IsDeviceExist(t *testing.T) { - type args struct { ctx context.Context device string @@ -321,7 +320,8 @@ type t struct { } func getDeleteSCSIDeviceTestCases(mocks mh.MockHelper, defaultArgs interface{}, - ctrl *gomock.Controller) []t { + ctrl *gomock.Controller, +) []t { return []t{ { name: "error read state file", @@ -845,7 +845,8 @@ func Test_scsi_CheckDeviceIs_Valid(t *testing.T) { OSStatCallPath: mh.ValidDevicePath, OSEXECCommandContextName: "dd", OSEXECCommandContextArgs: []string{ - "if=" + mh.ValidDevicePath, "of=/dev/null", "bs=1k", "count=1"}, + "if=" + mh.ValidDevicePath, "of=/dev/null", "bs=1k", "count=1", + }, OSEXECCmdOKReturn: "invalid", } @@ -1032,7 +1033,8 @@ func Test_scsi_GetDMChildren(t *testing.T) { FilePathGlobCallPattern: sysPath + "*", FilePathGlobOKReturn: []string{ sysPath + mh.ValidDeviceName, - sysPath + mh.ValidDeviceName2}, + sysPath + mh.ValidDeviceName2, + }, } tests := []struct { diff --git a/rdm.go b/rdm.go index c34b1be..e66768a 100644 --- a/rdm.go +++ b/rdm.go @@ -125,7 +125,8 @@ func (fc *FCConnector) rescanAllHosts(ctx context.Context) error { Host: strconv.Itoa(host), Lun: "-", Channel: "-", - Target: "-"} + Target: "-", + } err := scsiHost.RescanSCSIHostByHCTL(ctx, hctl) if err != nil { log.Error(ctx, err.Error()) diff --git a/sync_tools.go b/sync_tools.go index 0846546..f0113f7 100644 --- a/sync_tools.go +++ b/sync_tools.go @@ -82,7 +82,6 @@ func (c *ttlCache) purge() { delete(c.entries, key) } } - } func (c *ttlCache) Stop() { diff --git a/sync_tools_test.go b/sync_tools_test.go index 474155f..36f14ea 100644 --- a/sync_tools_test.go +++ b/sync_tools_test.go @@ -22,10 +22,11 @@ package gobrick import ( - "github.com/stretchr/testify/assert" "sync" "testing" "time" + + "github.com/stretchr/testify/assert" ) func Test_rateLock(t *testing.T) {