From e7cfb6da8cedb17c89f1432b0e4f77deb3a70ce6 Mon Sep 17 00:00:00 2001 From: Luna Xu Date: Fri, 1 Mar 2024 12:29:05 -0500 Subject: [PATCH] fix linting --- service/controller.go | 4 +- service/csi_extension_server.go | 22 ++-- service/csi_extension_test.go | 100 +++++++++--------- service/identity.go | 4 +- service/mount.go | 19 ++-- service/node.go | 4 +- service/node_test.go | 2 +- service/service.go | 24 ++--- service/utils/emcutils.go | 2 +- .../integration-test/integration_main_test.go | 12 +-- test/integration-test/integration_test.go | 44 ++++---- test/unit-test/unit_main_test.go | 12 +-- test/unit-test/unit_test.go | 80 +++++++------- 13 files changed, 164 insertions(+), 165 deletions(-) diff --git a/service/controller.go b/service/controller.go index 1c46c0f4..0e59791f 100644 --- a/service/controller.go +++ b/service/controller.go @@ -495,7 +495,7 @@ func (s *service) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valid return resp, status.Error(codes.Unknown, utils.GetMessageWithRunID(rid, "Unsupported capability")) } -func (s *service) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { +func (s *service) ListVolumes(_ context.Context, _ *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { return nil, status.Error(codes.Unimplemented, "Not implemented") } @@ -1596,7 +1596,7 @@ func (s *service) exportFilesystem(ctx context.Context, volID, hostID, nodeID, a } // exportVolume - Method to export volume with idempotency -func (s *service) exportVolume(ctx context.Context, protocol, volID, hostID, nodeID, arrayID string, unity *gounity.Client, pinfo map[string]string, host *types.Host, vc *csi.VolumeCapability) (*csi.ControllerPublishVolumeResponse, error) { +func (s *service) exportVolume(ctx context.Context, protocol, volID, hostID, _, _ string, unity *gounity.Client, pinfo map[string]string, host *types.Host, vc *csi.VolumeCapability) (*csi.ControllerPublishVolumeResponse, error) { ctx, log, rid := GetRunidLog(ctx) pinfo["lun"] = volID am := vc.GetAccessMode() diff --git a/service/csi_extension_server.go b/service/csi_extension_server.go index d9fd1cee..da1011d8 100644 --- a/service/csi_extension_server.go +++ b/service/csi_extension_server.go @@ -120,7 +120,7 @@ func (s *service) ValidateVolumeHostConnectivity(ctx context.Context, req *podmo if systemID == "" { log.Infof("No arrayId passed in, extracting it using other methods") // Try to extract the arrayID from the volumes - foundOne := s.getArrayIdsFromVolumes(ctx, systemIDs, req.GetVolumeIds()) + foundOne := s.getArrayIDsFromVolumes(ctx, systemIDs, req.GetVolumeIds()) // If no arrayIDs found in volumes (possibly because they weren't provided), then try the default array if !foundOne { // Lookup the default array @@ -232,12 +232,12 @@ func (s *service) ValidateVolumeHostConnectivity(ctx context.Context, req *podmo // getArrayIdsFromVolumes iterates the requestVolumeIds list, extracting the arrayId and adding them to 'systemIDs' // returns true if there was at least one arrayId found -func (s *service) getArrayIdsFromVolumes(ctx context.Context, systemIDs map[string]bool, requestVolumeIds []string) bool { +func (s *service) getArrayIDsFromVolumes(ctx context.Context, systemIDs map[string]bool, requestVolumeIDs []string) bool { ctx, log, _ := GetRunidLog(ctx) var err error var systemID string var foundAtLeastOne bool - for _, volumeID := range requestVolumeIds { + for _, volumeID := range requestVolumeIDs { // Extract arrayID from the volume ID (if any volumes in the request) if systemID, err = GetArrayIDFromVolumeContext(s, volumeID); err != nil { log.Warnf("Error getting arrayID for %s - %s", volumeID, err.Error()) @@ -312,9 +312,9 @@ func (s *service) checkIfNodeIsConnected(ctx context.Context, arrayID string, no rep.Connected = true fcConnectivity = true break - } else { - log.Infof("FC Health is bad for array:%s, Health:%s", arrayID, healthContent.DescriptionIDs[0]) } + log.Infof("FC Health is bad for array:%s, Health:%s", arrayID, healthContent.DescriptionIDs[0]) + } } } @@ -336,9 +336,9 @@ func (s *service) checkIfNodeIsConnected(ctx context.Context, arrayID string, no rep.Messages = append(rep.Messages, message) rep.Connected = true break - } else { - log.Infof("iSCSI Health is bad for array:%s, Health:%s", arrayID, healthContent.DescriptionIDs[0]) } + log.Infof("iSCSI Health is bad for array:%s, Health:%s", arrayID, healthContent.DescriptionIDs[0]) + } } } @@ -347,7 +347,7 @@ func (s *service) checkIfNodeIsConnected(ctx context.Context, arrayID string, no } // doesAnyVolumeHaveIO will determine if any of the given volumes on array has IOs. -func (s *service) doesAnyVolumeHaveIO(ctx context.Context, rep *podmon.ValidateVolumeHostConnectivityResponse, arrayID string, volumeIds []string) (bool, error) { +func (s *service) doesAnyVolumeHaveIO(ctx context.Context, rep *podmon.ValidateVolumeHostConnectivityResponse, arrayID string, volumeIDs []string) (bool, error) { ctx, log, _ := GetRunidLog(ctx) // Retrieve the latest currentIO metrics for all the array's volumes @@ -357,7 +357,7 @@ func (s *service) doesAnyVolumeHaveIO(ctx context.Context, rep *podmon.ValidateV } foundVolumeWithIO := false - for _, volumeID := range volumeIds { + for _, volumeID := range volumeIDs { // As an example, the results should look like this if printed out as a string: // sp.*.storage.lun.*.currentIOCount [spa = map[sv_108:0 sv_18:0 sv_19:0 sv_22:0 sv_23:0 sv_24:0 sv_25:0 sv_26:0]] // @@ -391,7 +391,7 @@ func (s *service) doesAnyVolumeHaveIO(ctx context.Context, rep *podmon.ValidateV } // doesAnyFileSystemHaveIO returns true if any of the file systems in 'fsIds' shows active IOs -func (s *service) doesAnyFileSystemHaveIO(ctx context.Context, rep *podmon.ValidateVolumeHostConnectivityResponse, arrayID string, fsIds []string) (bool, error) { +func (s *service) doesAnyFileSystemHaveIO(ctx context.Context, rep *podmon.ValidateVolumeHostConnectivityResponse, arrayID string, fsIDs []string) (bool, error) { ctx, log, _ := GetRunidLog(ctx) // Get two samples over the interval period and get a difference between the values @@ -417,7 +417,7 @@ func (s *service) doesAnyFileSystemHaveIO(ctx context.Context, rep *podmon.Valid } foundVolumeWithIO := false - for _, fsID := range fsIds { + for _, fsID := range fsIDs { firstSample, getValueErr = s.getMetricValues(ctx, first, arrayID, fsID) if getValueErr != nil { return false, getValueErr diff --git a/service/csi_extension_test.go b/service/csi_extension_test.go index 8618de4a..fbc458d4 100644 --- a/service/csi_extension_test.go +++ b/service/csi_extension_test.go @@ -172,7 +172,7 @@ func TestValidateVolumeHostConnectivityHost(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -204,7 +204,7 @@ func TestValidateVolumeHostConnectivityVolumeIds(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -231,7 +231,7 @@ func TestValidateVolumeHostConnectivityVolumeIds(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -258,7 +258,7 @@ func TestValidateVolumeHostConnectivityVolumeIds(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -293,7 +293,7 @@ func TestValidateVolumeHostConnectivityVolumeIds(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -333,7 +333,7 @@ func TestValidateVolumeHostConnectivityISCSI(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -355,7 +355,7 @@ func TestValidateVolumeHostConnectivityISCSI(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -379,7 +379,7 @@ func TestValidateVolumeHostConnectivityISCSI(t *testing.T) { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) mockHost := mockAHost("name", 1, 0) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { return mockHost, nil } mockBadInitiator = mockHost.HostContent.IscsiInitiators[0].ID @@ -402,7 +402,7 @@ func TestValidateVolumeHostConnectivityISCSI(t *testing.T) { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) mockHost := mockAHost("name", 2, 0) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { return mockHost, nil } mockBadInitiator = mockHost.HostContent.IscsiInitiators[0].ID @@ -425,7 +425,7 @@ func TestValidateVolumeHostConnectivityISCSI(t *testing.T) { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) mockHost := mockAHost("name", 1, 0) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { return mockHost, nil } mockFindInitatorFail = mockHost.HostContent.IscsiInitiators[0].ID @@ -460,7 +460,7 @@ func TestValidateVolumeHostConnectivityFC(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 0, 1) return mockHost, nil } @@ -483,7 +483,7 @@ func TestValidateVolumeHostConnectivityFC(t *testing.T) { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) mockHost := mockAHost("name", 0, 1) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { return mockHost, nil } mockBadInitiator = mockHost.HostContent.FcInitiators[0].ID @@ -506,7 +506,7 @@ func TestValidateVolumeHostConnectivityFC(t *testing.T) { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) mockHost := mockAHost("name", 0, 2) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { return mockHost, nil } mockBadInitiator = mockHost.HostContent.FcInitiators[0].ID @@ -529,7 +529,7 @@ func TestValidateVolumeHostConnectivityFC(t *testing.T) { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) mockHost := mockAHost("name", 0, 1) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { return mockHost, nil } mockFindInitatorFail = mockHost.HostContent.FcInitiators[0].ID @@ -564,7 +564,7 @@ func TestVolumeIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -597,7 +597,7 @@ func TestVolumeIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -630,7 +630,7 @@ func TestVolumeIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -670,7 +670,7 @@ func TestVolumeIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -713,7 +713,7 @@ func TestVolumeIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -795,7 +795,7 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -828,7 +828,7 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -861,12 +861,12 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } metricsCollectionCache.Store("array1:sp.*.storage.filesystem.*.clientReads,sp.*.storage.filesystem.*.clientWrites", 1) - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { read := map[string]interface{}{ "spa": map[string]interface{}{ "fs_1": "0.0", // Bad data: value is float, expecting integer @@ -911,7 +911,7 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } @@ -939,13 +939,13 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } // Return mock data that does not include any of // the volumes that we're checking against - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { read := map[string]interface{}{ "spa": map[string]interface{}{ "fs_10": "0", @@ -992,13 +992,13 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } metricsCollectionCache.Store("array1:sp.*.storage.filesystem.*.clientReads,sp.*.storage.filesystem.*.clientWrites", 1) times := 0 - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { times++ // Return a different metric once if times > 1 { @@ -1075,13 +1075,13 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } metricsCollectionCache.Store("array1:sp.*.storage.filesystem.*.clientReads,sp.*.storage.filesystem.*.clientWrites", 1) times := 0 - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { times++ // Return a different metric once if times == 1 { @@ -1132,13 +1132,13 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } metricsCollectionCache.Store("array1:sp.*.storage.filesystem.*.clientReads,sp.*.storage.filesystem.*.clientWrites", 1) times := 0 - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { times++ // Return a different metric once if times == 1 { @@ -1195,13 +1195,13 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } metricsCollectionCache.Store("array1:sp.*.storage.filesystem.*.clientReads,sp.*.storage.filesystem.*.clientWrites", 1) times := 0 - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { times++ // Return a different metric once if times == 1 { @@ -1259,12 +1259,12 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } times := 0 - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { times++ var read, write map[string]interface{} if times == 1 { @@ -1338,13 +1338,13 @@ func TestFileSystemIOCheck(t *testing.T) { setup: func() { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } times := 0 // This simulates getting metrics results where the filesystems are associated with different SPs - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { times++ var read, write map[string]interface{} if times == 1 { @@ -1431,12 +1431,12 @@ func TestParallelIOCheck(t *testing.T) { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } - CreateMetricsCollection = func(ctx context.Context, s *service, arrayId string, metricPaths []string, interval int) (*types.MetricQueryCreateResponse, error) { + CreateMetricsCollection = func(_ context.Context, _ *service, _ string, metricPaths []string, interval int) (*types.MetricQueryCreateResponse, error) { return &types.MetricQueryCreateResponse{ Base: "Mock", Updated: time.Now().String(), @@ -1453,7 +1453,7 @@ func TestParallelIOCheck(t *testing.T) { // Fill cache metricsCollectionCache.Store("array2", 1) - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { if id == 1 { log.Infof("FileSystem metrics") read := map[string]interface{}{ @@ -1540,12 +1540,12 @@ func TestMetricsRefresher(t *testing.T) { testConf.service.opts.AutoProbe = true testConf.service.arrays.Store("array1", mockStorage(ctx)) - GetHostID = func(ctx context.Context, s *service, arrayId, shortHostname, longHostname string) (*types.Host, error) { + GetHostID = func(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { mockHost := mockAHost("name", 1, 0) return mockHost, nil } - CreateMetricsCollection = func(ctx context.Context, s *service, arrayId string, metricPaths []string, interval int) (*types.MetricQueryCreateResponse, error) { + CreateMetricsCollection = func(_ context.Context, _ *service, _ string, metricPaths []string, interval int) (*types.MetricQueryCreateResponse, error) { return &types.MetricQueryCreateResponse{ Base: "Mock", Updated: time.Now().String(), @@ -1559,7 +1559,7 @@ func TestMetricsRefresher(t *testing.T) { }, nil } - GetMetricsCollection = func(ctx context.Context, s *service, arrayId string, id int) (*types.MetricQueryResult, error) { + GetMetricsCollection = func(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { log.Infof("Volume Metrics") currentIOs := map[string]interface{}{ "spa": map[string]interface{}{ @@ -1736,15 +1736,15 @@ func mockGetProtocolFromVolumeContext(_ *service, contextVolID string) (string, return "", errors.New("invalid volume context id") } -func mockRequireProbe(ctx context.Context, s *service, arrayID string) error { +func mockRequireProbe(_ context.Context, _ *service, _ string) error { return mockRequireProbeErr } -func mockGetHostID(ctx context.Context, s *service, arrayID, shortHostname, longHostname string) (*types.Host, error) { +func mockGetHostID(_ context.Context, _ *service, _, _, _ string) (*types.Host, error) { return mockGetHost, mockGetHostErr } -func mockGetUnityClient(ctx context.Context, s *service, arrayID string) (*gounity.Client, error) { +func mockGetUnityClient(_ context.Context, _ *service, _ string) (*gounity.Client, error) { return mockGetUnity, mockGetUnityErr } @@ -1814,15 +1814,15 @@ func mockAnInitiator(id string) *types.HostInitiator { } } -func mockFindHostInitiatorByID(ctx context.Context, unity *gounity.Client, wwnOrIqn string) (*types.HostInitiator, error) { +func mockFindHostInitiatorByID(_ context.Context, _ *gounity.Client, wwnOrIqn string) (*types.HostInitiator, error) { return mockAnInitiator(wwnOrIqn), mockFindHostInitiatorErr } -func mockGetMetricsCollection(ctx context.Context, s *service, arrayID string, id int) (*types.MetricQueryResult, error) { +func mockGetMetricsCollection(_ context.Context, _ *service, _ string, id int) (*types.MetricQueryResult, error) { return mockVolMetricResult(id, mockMetricValueMap), mockGetMetricsCollectionError } -func mockCreateMetricsCollection(ctx context.Context, s *service, arrayID string, metricPaths []string, interval int) (*types.MetricQueryCreateResponse, error) { +func mockCreateMetricsCollection(_ context.Context, _ *service, _ string, metricPaths []string, interval int) (*types.MetricQueryCreateResponse, error) { mockCollection := &types.MetricQueryCreateResponse{ Base: "Mock", Updated: time.Now().String(), diff --git a/service/identity.go b/service/identity.go index 589f0097..3ee04d72 100644 --- a/service/identity.go +++ b/service/identity.go @@ -46,8 +46,8 @@ func (s *service) Probe( } func (s *service) GetPluginInfo( - ctx context.Context, - req *csi.GetPluginInfoRequest) ( + _ context.Context, + _ *csi.GetPluginInfoRequest) ( *csi.GetPluginInfoResponse, error, ) { return &csi.GetPluginInfoResponse{ diff --git a/service/mount.go b/service/mount.go index ca67bd73..82c10809 100644 --- a/service/mount.go +++ b/service/mount.go @@ -190,13 +190,12 @@ func publishNFS(ctx context.Context, req *csi.NodePublishVolumeRequest, exportPa return status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Target path: %s is already mounted to export path: %s with conflicting access modes", targetPath, stageExportPathURL)) } else if m.Path == stagingTargetPath || m.Path == chroot+stagingTargetPath { continue - } else { - if accMode.Mode == csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER || (accMode.Mode == csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER && !allowRWOmultiPodAccess) { - return status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Export path: %s is already mounted to different target path: %s", stageExportPathURL, m.Path)) - } - // For multi-node access modes and when allowRWOmultiPodAccess is true for single-node access, target mount will be executed - continue } + if accMode.Mode == csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER || (accMode.Mode == csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER && !allowRWOmultiPodAccess) { + return status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Export path: %s is already mounted to different target path: %s", stageExportPathURL, m.Path)) + } + // For multi-node access modes and when allowRWOmultiPodAccess is true for single-node access, target mount will be executed + continue } } } @@ -324,9 +323,9 @@ func stageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest, stagingPa if utils.ArrayContains(m.Opts, rwo) { log.Warn("staging mount already in place") break - } else { - return status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "access mode conflicts with existing mounts")) } + return status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "access mode conflicts with existing mounts")) + } // It is ok if the device is mounted elsewhere - could be targetPath. If not this will be caught during NodePublish } @@ -581,9 +580,9 @@ func unstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest, devic if m.Path == stagingTarget || m.Path == chroot+stagingTarget { stgMnt = true break - } else { - log.Infof("Device %s has been mounted outside staging target on %s", sysDevice.FullPath, m.Path) } + log.Infof("Device %s has been mounted outside staging target on %s", sysDevice.FullPath, m.Path) + } else if (m.Path == stagingTarget || m.Path == chroot+stagingTarget) && !(m.Source == sysDevice.FullPath || m.Device == sysDevice.FullPath) { log.Infof("Staging path %s has been mounted by foreign device %s", stagingTarget, m.Device) } diff --git a/service/node.go b/service/node.go index def854e2..a8d8a6de 100644 --- a/service/node.go +++ b/service/node.go @@ -1763,7 +1763,7 @@ func (s *service) syncNodeInfoRoutine(ctx context.Context) { case <-time.After(time.Duration(s.opts.SyncNodeInfoTimeInterval) * time.Minute): log.Debug("Checking if host information is added to array") allHostsAdded := true - s.arrays.Range(func(key, value interface{}) bool { + s.arrays.Range(func(_, value interface{}) bool { array := value.(*StorageArrayConfig) if !array.IsHostAdded { allHostsAdded = false @@ -1794,7 +1794,7 @@ func (s *service) syncNodeInfo(ctx context.Context) { ctx, log := incrementLogID(ctx, "node") log.Debug("Synchronizing Node Info") // Add a count of three, one for each goroutine. - s.arrays.Range(func(key, value interface{}) bool { + s.arrays.Range(func(_, value interface{}) bool { array := value.(*StorageArrayConfig) if !array.IsHostAdded { go func() { diff --git a/service/node_test.go b/service/node_test.go index aa1f452e..ded8ec61 100644 --- a/service/node_test.go +++ b/service/node_test.go @@ -18,7 +18,7 @@ import ( "testing" ) -func TestNodeGetInfo(t *testing.T) { +func TestNodeGetInfo(_ *testing.T) { // fmt.Println(testConf.service.arrays) // testConf.service.nodeProbe(testConf.ctx, "") // testConf.service.discoverNodes(testConf.ctx, "1") diff --git a/service/service.go b/service/service.go index 970914ec..cfde6712 100644 --- a/service/service.go +++ b/service/service.go @@ -170,7 +170,7 @@ func (s StorageArrayConfig) String() string { // modify the SP's interceptors, server options, or prevent the // server from starting by returning a non-nil error. func (s *service) BeforeServe( - ctx context.Context, sp *gocsi.StoragePlugin, lis net.Listener, + ctx context.Context, _ *gocsi.StoragePlugin, _ net.Listener, ) error { ctx, log := setRunIDContext(ctx, "start") var err error @@ -322,7 +322,7 @@ func (s *service) getStorageArrayLength() (length int) { // Get storage array list from sync Map func (s *service) getStorageArrayList() []*StorageArrayConfig { list := make([]*StorageArrayConfig, 0) - s.arrays.Range(func(key interface{}, value interface{}) bool { + s.arrays.Range(func(_ interface{}, value interface{}) bool { list = append(list, value.(*StorageArrayConfig)) return true }) @@ -399,7 +399,7 @@ func (s *service) loadDynamicConfig(ctx context.Context, secretFile, configFile // Watch for changes to driver config params file vc.WatchConfig() - vc.OnConfigChange(func(e fsnotify.Event) { + vc.OnConfigChange(func(_ fsnotify.Event) { log.Infof("Driver config params file changed") s.syncDriverConfig(ctx, vc) }) @@ -473,7 +473,7 @@ func (s *service) syncDriverSecret(ctx context.Context) error { log.Info("*************Synchronizing driver secret**************") syncMutex.Lock() defer syncMutex.Unlock() - s.arrays.Range(func(key interface{}, value interface{}) bool { + s.arrays.Range(func(key interface{}, _ interface{}) bool { s.arrays.Delete(key) return true }) @@ -496,7 +496,7 @@ func (s *service) syncDriverSecret(ctx context.Context) error { return errors.New("Arrays details are not provided in unity-creds secret") } - s.arrays.Range(func(key interface{}, value interface{}) bool { + s.arrays.Range(func(key interface{}, _ interface{}) bool { s.arrays.Delete(key) return true }) @@ -533,15 +533,15 @@ func (s *service) syncDriverSecret(ctx context.Context) error { } secret.UnityClient = unityClient - copy := StorageArrayConfig{} - copy = secret + copyStorage := StorageArrayConfig{} + copyStorage = secret _, ok := s.arrays.Load(secret.ArrayID) if ok { return fmt.Errorf("Duplicate ArrayID [%s] found in storageArrayList parameter", secret.ArrayID) } - s.arrays.Store(secret.ArrayID, ©) + s.arrays.Store(secret.ArrayID, ©Storage) fields := logrus.Fields{ "ArrayId": secret.ArrayID, @@ -739,14 +739,14 @@ func (s *service) initFCConnector(chroot string) { } } -func setupGobrick(srv *service) { +func setupGobrick(_ *service) { gobrick.SetLogger(&customLogger{}) gobrick.SetTracer(&emptyTracer{}) } type emptyTracer struct{} -func (dl *emptyTracer) Trace(ctx context.Context, format string, args ...interface{}) { +func (dl *emptyTracer) Trace(_ context.Context, _ string, _ ...interface{}) { } type customLogger struct{} @@ -821,9 +821,9 @@ func (s *service) probe(ctx context.Context, probeType string, arrayID string) e if err == nil { atleastOneArraySuccess = true break - } else { - log.Errorf("Probe failed for array %s error:%v", array, err) } + log.Errorf("Probe failed for array %s error:%v", array, err) + } if !atleastOneArraySuccess { diff --git a/service/utils/emcutils.go b/service/utils/emcutils.go index 729433cf..70e491d6 100644 --- a/service/utils/emcutils.go +++ b/service/utils/emcutils.go @@ -285,7 +285,7 @@ func ipListContains(ipArray []net.IP, value string) bool { } // GetIPsFromInferfaces - Method to extract ip as string from ipInterface object -func GetIPsFromInferfaces(ctx context.Context, ipInterfaces []types.IPInterfaceEntries) []string { +func GetIPsFromInferfaces(_ context.Context, ipInterfaces []types.IPInterfaceEntries) []string { ips := make([]string, 0) for _, ipInterface := range ipInterfaces { diff --git a/test/integration-test/integration_main_test.go b/test/integration-test/integration_main_test.go index 2518616d..7be33a74 100644 --- a/test/integration-test/integration_main_test.go +++ b/test/integration-test/integration_main_test.go @@ -39,7 +39,7 @@ type StorageArrayList struct { } type StorageArrayConfig struct { - ArrayId string `json:"arrayId"` + ArrayID string `json:"arrayId"` } func TestMain(m *testing.M) { @@ -50,14 +50,14 @@ func TestMain(m *testing.M) { if err != nil { panic("Driver Config missing") } - arrayIdList := StorageArrayList{} - _ = json.Unmarshal([]byte(file), &arrayIdList) - if len(arrayIdList.StorageArrayList) == 0 { + arrayIDList := StorageArrayList{} + _ = json.Unmarshal([]byte(file), &arrayIDList) + if len(arrayIDList.StorageArrayList) == 0 { panic("Array Info not provided") } - for i := 0; i < len(arrayIdList.StorageArrayList); i++ { + for i := 0; i < len(arrayIDList.StorageArrayList); i++ { arrayIdvar := "Array" + strconv.Itoa(i+1) + "-Id" - os.Setenv(arrayIdvar, arrayIdList.StorageArrayList[i].ArrayId) + os.Setenv(arrayIdvar, arrayIDList.StorageArrayList[i].ArrayID) } ctx := context.Background() diff --git a/test/integration-test/integration_test.go b/test/integration-test/integration_test.go index eec4051c..8dcf6973 100644 --- a/test/integration-test/integration_test.go +++ b/test/integration-test/integration_test.go @@ -89,7 +89,7 @@ func (f *feature) aCSIService() error { } // aBasicBlockVolumeRequest method to buils a Create volume request -func (f *feature) aBasicBlockVolumeRequest(volumeName, arrayId, protocol string, size int) error { +func (f *feature) aBasicBlockVolumeRequest(volumeName, arrayID, protocol string, size int) error { f.createVolumeRequest = nil req := new(csi.CreateVolumeRequest) params := make(map[string]string) @@ -98,7 +98,7 @@ func (f *feature) aBasicBlockVolumeRequest(volumeName, arrayId, protocol string, params["isDataReductionEnabled"] = "false" params["tieringPolicy"] = "0" params["description"] = "CSI Volume Unit Test" - params["arrayId"] = os.Getenv(arrayId) + params["arrayId"] = os.Getenv(arrayID) params["protocol"] = protocol params["nasServer"] = os.Getenv("NAS_SERVER") req.Parameters = params @@ -123,12 +123,12 @@ func (f *feature) aBasicBlockVolumeRequest(volumeName, arrayId, protocol string, } // aBasicBlockVolumeRequest method with volume content source -func (f *feature) aBasicBlockVolumeRequestWithVolumeContentSource(volumeName, arrayId, protocol string, size int) error { +func (f *feature) aBasicBlockVolumeRequestWithVolumeContentSource(volumeName, arrayID, protocol string, size int) error { f.createVolumeRequest = nil req := new(csi.CreateVolumeRequest) params := make(map[string]string) params["storagePool"] = os.Getenv("STORAGE_POOL") - params["arrayId"] = os.Getenv(arrayId) + params["arrayId"] = os.Getenv(arrayID) params["protocol"] = protocol req.Parameters = params req.Name = volumeName @@ -147,12 +147,12 @@ func (f *feature) aBasicBlockVolumeRequestWithVolumeContentSource(volumeName, ar capabilities := make([]*csi.VolumeCapability, 0) capabilities = append(capabilities, capability) req.VolumeCapabilities = capabilities - volumeContentSource_SnapshotSource := new(csi.VolumeContentSource_SnapshotSource) - volumeContentSource_SnapshotSource.SnapshotId = f.createSnapshotResponse.GetSnapshot().GetSnapshotId() - volumeContentSource_Snapshot := new(csi.VolumeContentSource_Snapshot) - volumeContentSource_Snapshot.Snapshot = volumeContentSource_SnapshotSource + volumeContentSourceSnapshotSource := new(csi.VolumeContentSource_SnapshotSource) + volumeContentSourceSnapshotSource.SnapshotId = f.createSnapshotResponse.GetSnapshot().GetSnapshotId() + volumeContentSourceSnapshot := new(csi.VolumeContentSource_Snapshot) + volumeContentSourceSnapshot.Snapshot = volumeContentSourceSnapshotSource volumeContentSource := new(csi.VolumeContentSource) - volumeContentSource.Type = volumeContentSource_Snapshot + volumeContentSource.Type = volumeContentSourceSnapshot req.VolumeContentSource = volumeContentSource f.createVolumeRequest = req return nil @@ -295,11 +295,11 @@ func (f *feature) theErrorMessageShouldContain(expected string) error { if expected == "none" { if len(f.errs) == 0 { return nil - } else { - err := f.errs[0] - f.errs = make([]error, 0) - return fmt.Errorf("Unexpected error(s): %s", err) } + err := f.errs[0] + f.errs = make([]error, 0) + return fmt.Errorf("Unexpected error(s): %s", err) + } // We expect an error... if len(f.errs) == 0 { @@ -308,7 +308,7 @@ func (f *feature) theErrorMessageShouldContain(expected string) error { err0 := f.errs[0] f.errs = make([]error, 0) if !strings.Contains(err0.Error(), expected) { - return errors.New(fmt.Sprintf("Error %s does not contain the expected message: %s", err0.Error(), expected)) + return fmt.Errorf("Error %s does not contain the expected message: %s", err0.Error(), expected) } return nil } @@ -362,10 +362,10 @@ func (f *feature) aDeleteSnapshotRequest() error { } // aDeleteSnapshotRequestWithID method is used to build a Delete Snapshot request with ID -func (f *feature) aDeleteSnapshotRequestWithID(snap_id string) error { +func (f *feature) aDeleteSnapshotRequestWithID(snapID string) error { f.deleteSnapshotRequest = nil req := new(csi.DeleteSnapshotRequest) - req.SnapshotId = snap_id + req.SnapshotId = snapID f.deleteSnapshotRequest = req return nil } @@ -504,13 +504,13 @@ func (f *feature) iCallControllerGetCapabilities() error { } // iCallControllerExpandVolume - Test case for controller expand volume -func (f *feature) iCallControllerExpandVolume(new_size int) error { +func (f *feature) iCallControllerExpandVolume(newSize int) error { f.controllerExpandVolumeRequest = nil req := new(csi.ControllerExpandVolumeRequest) req.VolumeId = f.volID capRange := new(csi.CapacityRange) - capRange.RequiredBytes = int64(new_size * 1024 * 1024 * 1024) - capRange.LimitBytes = int64(new_size * 1024 * 1024 * 1024) + capRange.RequiredBytes = int64(newSize * 1024 * 1024 * 1024) + capRange.LimitBytes = int64(newSize * 1024 * 1024 * 1024) req.CapacityRange = capRange f.controllerExpandVolumeRequest = req @@ -527,13 +527,13 @@ func (f *feature) iCallControllerExpandVolume(new_size int) error { } // iCallControllerExpandVolume - Test case for controller expand volume with volume id as parameter -func (f *feature) iCallControllerExpandVolumeWithVolume(new_size int, volID string) error { +func (f *feature) iCallControllerExpandVolumeWithVolume(newSize int, volID string) error { f.controllerExpandVolumeRequest = nil req := new(csi.ControllerExpandVolumeRequest) req.VolumeId = volID capRange := new(csi.CapacityRange) - capRange.RequiredBytes = int64(new_size * 1024 * 1024 * 1024) - capRange.LimitBytes = int64(new_size * 1024 * 1024 * 1024) + capRange.RequiredBytes = int64(newSize * 1024 * 1024 * 1024) + capRange.LimitBytes = int64(newSize * 1024 * 1024 * 1024) req.CapacityRange = capRange f.controllerExpandVolumeRequest = req diff --git a/test/unit-test/unit_main_test.go b/test/unit-test/unit_main_test.go index 49bbd278..a5940c67 100644 --- a/test/unit-test/unit_main_test.go +++ b/test/unit-test/unit_main_test.go @@ -43,7 +43,7 @@ type StorageArrayList struct { } type StorageArrayConfig struct { - ArrayId string `yaml:"ArrayId"` + ArrayID string `yaml:"ArrayId"` } func TestMain(m *testing.M) { @@ -53,14 +53,14 @@ func TestMain(m *testing.M) { if err != nil { panic("Driver Config missing") } - arrayIdList := StorageArrayList{} - _ = yaml.Unmarshal([]byte(file), &arrayIdList) - if len(arrayIdList.StorageArrayList) == 0 { + arrayIDList := StorageArrayList{} + _ = yaml.Unmarshal([]byte(file), &arrayIDList) + if len(arrayIDList.StorageArrayList) == 0 { panic("Array Info not provided") } - for i := 0; i < len(arrayIdList.StorageArrayList); i++ { + for i := 0; i < len(arrayIDList.StorageArrayList); i++ { arrayIdvar := "Array" + strconv.Itoa(i+1) + "-Id" - os.Setenv(arrayIdvar, arrayIdList.StorageArrayList[i].ArrayId) + os.Setenv(arrayIdvar, arrayIDList.StorageArrayList[i].ArrayID) } ctx := context.Background() diff --git a/test/unit-test/unit_test.go b/test/unit-test/unit_test.go index 9d486c69..960a37ac 100644 --- a/test/unit-test/unit_test.go +++ b/test/unit-test/unit_test.go @@ -57,7 +57,7 @@ type feature struct { volID string volIDList []string maxRetryCount int - nodeId string + nodeID string ephemeral bool } @@ -332,12 +332,12 @@ func (f *feature) aBasicBlockVolumeRequestWithVolumeContentSource(volumeName, pr capabilities := make([]*csi.VolumeCapability, 0) capabilities = append(capabilities, capability) req.VolumeCapabilities = capabilities - volumeContentSource_SnapshotSource := new(csi.VolumeContentSource_SnapshotSource) - volumeContentSource_SnapshotSource.SnapshotId = f.createSnapshotResponse.GetSnapshot().GetSnapshotId() - volumeContentSource_Snapshot := new(csi.VolumeContentSource_Snapshot) - volumeContentSource_Snapshot.Snapshot = volumeContentSource_SnapshotSource + volumeContentSourceSnapshotSource := new(csi.VolumeContentSource_SnapshotSource) + volumeContentSourceSnapshotSource.SnapshotId = f.createSnapshotResponse.GetSnapshot().GetSnapshotId() + volumeContentSourceSnapshot := new(csi.VolumeContentSource_Snapshot) + volumeContentSourceSnapshot.Snapshot = volumeContentSourceSnapshotSource volumeContentSource := new(csi.VolumeContentSource) - volumeContentSource.Type = volumeContentSource_Snapshot + volumeContentSource.Type = volumeContentSourceSnapshot req.VolumeContentSource = volumeContentSource f.createVolumeRequest = req return nil @@ -368,12 +368,12 @@ func (f *feature) aBasicBlockVolumeRequestWithVolumeContentSourceAsVolume(volume capabilities := make([]*csi.VolumeCapability, 0) capabilities = append(capabilities, capability) req.VolumeCapabilities = capabilities - volumeContentSource_VolumeSource := new(csi.VolumeContentSource_VolumeSource) - volumeContentSource_VolumeSource.VolumeId = f.createVolumeResponse.GetVolume().GetVolumeId() - volumeContentSource_Volume := new(csi.VolumeContentSource_Volume) - volumeContentSource_Volume.Volume = volumeContentSource_VolumeSource + volumeContentSourceVolumeSource := new(csi.VolumeContentSource_VolumeSource) + volumeContentSourceVolumeSource.VolumeId = f.createVolumeResponse.GetVolume().GetVolumeId() + volumeContentSourceVolume := new(csi.VolumeContentSource_Volume) + volumeContentSourceVolume.Volume = volumeContentSourceVolumeSource volumeContentSource := new(csi.VolumeContentSource) - volumeContentSource.Type = volumeContentSource_Volume + volumeContentSource.Type = volumeContentSourceVolume req.VolumeContentSource = volumeContentSource f.createVolumeRequest = req return nil @@ -451,7 +451,7 @@ func (f *feature) whenICallPublishVolume() error { req := new(csi.ControllerPublishVolumeRequest) req.VolumeId = f.volID req.NodeId = os.Getenv("X_CSI_UNITY_NODENAME") + "," + os.Getenv("X_CSI_UNITY_LONGNODENAME") - f.nodeId = req.NodeId + f.nodeID = req.NodeId req.Readonly = false req.VolumeCapability = f.capability req.VolumeContext = f.volumeContext @@ -470,11 +470,11 @@ func (f *feature) whenICallPublishVolume() error { } // whenICallPublishVolumeWithParam - Test case to Publish volume to the given host with readonly as parameter -func (f *feature) whenICallPublishVolumeWithParam(hostName, readonly string) error { +func (f *feature) whenICallPublishVolumeWithParam(_, readonly string) error { req := new(csi.ControllerPublishVolumeRequest) req.VolumeId = f.volID req.NodeId = os.Getenv("X_CSI_UNITY_NODENAME") + "," + os.Getenv("X_CSI_UNITY_LONGNODENAME") - f.nodeId = req.NodeId + f.nodeID = req.NodeId read, _ := strconv.ParseBool(readonly) req.Readonly = read req.VolumeCapability = f.capability @@ -494,11 +494,11 @@ func (f *feature) whenICallPublishVolumeWithParam(hostName, readonly string) err } // whenICallPublishVolumeWithVolumeId - Test case to Publish volume to the given host with volumeID as parameter -func (f *feature) whenICallPublishVolumeWithVolumeId(volId string) error { +func (f *feature) whenICallPublishVolumeWithVolumeID(volID string) error { req := new(csi.ControllerPublishVolumeRequest) - req.VolumeId = volId + req.VolumeId = volID req.NodeId = os.Getenv("X_CSI_UNITY_NODENAME") + "," + os.Getenv("X_CSI_UNITY_LONGNODENAME") - f.nodeId = req.NodeId + f.nodeID = req.NodeId req.Readonly = false req.VolumeCapability = f.capability req.VolumeContext = f.volumeContext @@ -535,9 +535,9 @@ func (f *feature) whenICallUnpublishVolume() error { } // iCallUnpublishVolumeWithVolumeId - Test case to unpublish volume with volume ID as parameter -func (f *feature) iCallUnpublishVolumeWithVolumeId(volId string) error { +func (f *feature) iCallUnpublishVolumeWithVolumeID(volID string) error { req := new(csi.ControllerUnpublishVolumeRequest) - req.VolumeId = volId + req.VolumeId = volID req.NodeId = os.Getenv("X_CSI_UNITY_NODENAME") + "," + os.Getenv("X_CSI_UNITY_LONGNODENAME") ctx := context.Background() client := csi.NewControllerClient(grpcClient) @@ -558,11 +558,11 @@ func (f *feature) theErrorMessageShouldContain(expected string) error { if expected == "none" { if len(f.errs) == 0 { return nil - } else { - err := f.errs[0] - f.errs = make([]error, 0) - return fmt.Errorf("Unexpected error(s): %s", err) } + err := f.errs[0] + f.errs = make([]error, 0) + return fmt.Errorf("Unexpected error(s): %s", err) + } // We expect an error... if len(f.errs) == 0 { @@ -571,7 +571,7 @@ func (f *feature) theErrorMessageShouldContain(expected string) error { err0 := f.errs[0] f.errs = make([]error, 0) if !strings.Contains(err0.Error(), expected) { - return errors.New(fmt.Sprintf("Error %s does not contain the expected message: %s", err0.Error(), expected)) + return fmt.Errorf("Error %s does not contain the expected message: %s", err0.Error(), expected) } return nil } @@ -625,10 +625,10 @@ func (f *feature) aDeleteSnapshotRequest() error { } // aDeleteSnapshotRequestWithID method is used to build a Delete Snapshot request with ID -func (f *feature) aDeleteSnapshotRequestWithID(snap_id string) error { +func (f *feature) aDeleteSnapshotRequestWithID(snapID string) error { f.deleteSnapshotRequest = nil req := new(csi.DeleteSnapshotRequest) - req.SnapshotId = snap_id + req.SnapshotId = snapID f.deleteSnapshotRequest = req return nil } @@ -767,13 +767,13 @@ func (f *feature) iCallControllerGetCapabilities() error { } // iCallControllerExpandVolume - Test case for controller expand volume -func (f *feature) iCallControllerExpandVolume(new_size int) error { +func (f *feature) iCallControllerExpandVolume(newSize int) error { f.controllerExpandVolumeRequest = nil req := new(csi.ControllerExpandVolumeRequest) req.VolumeId = f.volID capRange := new(csi.CapacityRange) - capRange.RequiredBytes = int64(new_size * 1024 * 1024 * 1024) - capRange.LimitBytes = int64(new_size * 1024 * 1024 * 1024) + capRange.RequiredBytes = int64(newSize * 1024 * 1024 * 1024) + capRange.LimitBytes = int64(newSize * 1024 * 1024 * 1024) req.CapacityRange = capRange f.controllerExpandVolumeRequest = req @@ -790,13 +790,13 @@ func (f *feature) iCallControllerExpandVolume(new_size int) error { } // iCallControllerExpandVolume - Test case for controller expand volume with volume id as parameter -func (f *feature) iCallControllerExpandVolumeWithVolume(new_size int, volID string) error { +func (f *feature) iCallControllerExpandVolumeWithVolume(newSize int, volID string) error { f.controllerExpandVolumeRequest = nil req := new(csi.ControllerExpandVolumeRequest) req.VolumeId = volID capRange := new(csi.CapacityRange) - capRange.RequiredBytes = int64(new_size * 1024 * 1024 * 1024) - capRange.LimitBytes = int64(new_size * 1024 * 1024 * 1024) + capRange.RequiredBytes = int64(newSize * 1024 * 1024 * 1024) + capRange.LimitBytes = int64(newSize * 1024 * 1024 * 1024) req.CapacityRange = capRange f.controllerExpandVolumeRequest = req @@ -929,7 +929,7 @@ func (f *feature) whenICallEphemeralNodePublishVolume(volName, fsType, am, size, } // whenICallNodePublishVolumeWithTargetPath - Test case for node publish volume with target path -func (f *feature) whenICallNodePublishVolumeWithTargetPath(target_path, fsType string) error { +func (f *feature) whenICallNodePublishVolumeWithTargetPath(targetPath, fsType string) error { f.nodePublishVolumeRequest = nil req := new(csi.NodePublishVolumeRequest) if f.createVolumeResponse != nil || f.ephemeral == true { @@ -939,7 +939,7 @@ func (f *feature) whenICallNodePublishVolumeWithTargetPath(target_path, fsType s } fmt.Println("========================", req.VolumeId) req.StagingTargetPath = path.Join(os.Getenv("X_CSI_STAGING_TARGET_PATH"), f.volID) - req.TargetPath = target_path + req.TargetPath = targetPath capability := new(csi.VolumeCapability) mount := new(csi.VolumeCapability_MountVolume) mount.FsType = fsType @@ -1028,7 +1028,7 @@ func (f *feature) whenICallNodeUnPublishVolume() error { } // whenICallNodeUnPublishVolumeWithTargetPath - Test case for node unpublish volume with target path -func (f *feature) whenICallNodeUnPublishVolumeWithTargetPath(target_path string) error { +func (f *feature) whenICallNodeUnPublishVolumeWithTargetPath(targetPath string) error { f.nodeUnpublishVolumeRequest = nil req := new(csi.NodeUnpublishVolumeRequest) if f.nodePublishVolumeRequest != nil { @@ -1037,7 +1037,7 @@ func (f *feature) whenICallNodeUnPublishVolumeWithTargetPath(target_path string) req.VolumeId = "" } - req.TargetPath = target_path + req.TargetPath = targetPath f.nodeUnpublishVolumeRequest = req ctx := context.Background() @@ -1090,14 +1090,14 @@ func (f *feature) whenICallNodeStageVolume(fsType string) error { } // whenICallNodeStageVolumeWithTargetPath - Test case for node stage volume with target path as parameter -func (f *feature) whenICallNodeStageVolumeWithTargetPath(fsType, target_path string) error { +func (f *feature) whenICallNodeStageVolumeWithTargetPath(fsType, targetPath string) error { f.nodeStageVolumeRequest = nil req := new(csi.NodeStageVolumeRequest) req.VolumeId = f.volID if f.createVolumeResponse == nil { req.VolumeId = "NoID" } - req.StagingTargetPath = target_path + req.StagingTargetPath = targetPath capability := new(csi.VolumeCapability) mount := new(csi.VolumeCapability_MountVolume) mount.FsType = fsType @@ -1301,9 +1301,9 @@ func FeatureContext(s *godog.Suite) { s.Step(`^there are no errors$`, f.thereAreNoErrors) s.Step(`^when I call PublishVolume$`, f.whenICallPublishVolume) s.Step(`^when I call PublishVolume with host "([^"]*)" readonly "([^"]*)"$`, f.whenICallPublishVolumeWithParam) - s.Step(`^when I call PublishVolume with volumeId "([^"]*)"$`, f.whenICallPublishVolumeWithVolumeId) + s.Step(`^when I call PublishVolume with volumeId "([^"]*)"$`, f.whenICallPublishVolumeWithVolumeID) s.Step(`^when I call UnpublishVolume$`, f.whenICallUnpublishVolume) - s.Step(`^I call UnpublishVolume with volumeId "([^"]*)"$`, f.iCallUnpublishVolumeWithVolumeId) + s.Step(`^I call UnpublishVolume with volumeId "([^"]*)"$`, f.iCallUnpublishVolumeWithVolumeID) s.Step(`^the error message should contain "([^"]*)"$`, f.theErrorMessageShouldContain) s.Step(`^a create snapshot request "([^"]*)"$`, f.aCreateSnapshotRequest) s.Step(`^I call CreateSnapshot$`, f.iCallCreateSnapshot)