Repository: dell/csi-baremetal
Pull request #542 (2021-09-21 14:12:48)

[ISSUE-539] skip SN check
## Purpose
### Issue #539 

- Drive manager reports block device name to the node. No need to double check serial number and block device name.
- Interfacer linter plugin is deprecated - https://github.com/mvdan/interfacer and reports false positive errors periodically. Removed from the configuration.

## PR checklist
- [ ] Add link to the issue
- [ ] Choose PR label
- [ ] New unit tests added
- [ ] Modified code has meaningful comments
- [ ] All TODOs are linked with the issues
- [ ] All comments are resolved

## Testing
Tested manually:
```
$ volumes
Namespace   Id                                         Size            Type   Health   OpStatus    CSIStatus   Usage    Location                               Node
default     pvc-b0fcb881-96e6-4e6f-8a50-fd07826af76e   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   6a299be8-1f01-4309-abbf-5932f999ac34   0c3158ff-9472-4f6d-b248-dbf44736687e
default     pvc-e6530b2a-b786-4074-bc83-58dbc500ac58   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   616846b6-16ce-4443-aacb-c96a974e8ad2   0c3158ff-9472-4f6d-b248-dbf44736687e
default     pvc-ea6e4b33-092b-4588-bbba-b9465f276eca   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   ca30712a-a5e6-443d-9a2c-4d3602a16a38   0c3158ff-9472-4f6d-b248-dbf44736687e
default     pvc-adf96290-bb1c-4233-acb5-919903c3181e   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   bb277b5c-b014-4ec8-af0d-7066bcfd5bf0   0570d757-3ad6-49c7-b004-f5bce3c949cf
default     pvc-f4498933-c2e6-4a79-8a75-c74da4ff5d19   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   6e087e0c-ab66-4009-8fef-83a3ebcdc7b5   0570d757-3ad6-49c7-b004-f5bce3c949cf
default     pvc-71b6941d-b0f2-494b-adc9-ef92403edaa7   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   3bf3bec6-3179-44fb-b0bb-97ac9203333b   0570d757-3ad6-49c7-b004-f5bce3c949cf
default     pvc-3f8ca2f2-462b-4314-9970-c02efb7203c0   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   2df03603-7a6d-4259-bb0b-6b3158230dcd   57313d87-3b44-4fb6-bddd-37e90b0e4ca0
default     pvc-5700b194-6bd8-4141-be44-2d47248092ff   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   c6c91fa9-cf49-4486-934f-57f03975212e   57313d87-3b44-4fb6-bddd-37e90b0e4ca0
default     pvc-a24c568f-7cf2-4f21-8c34-431290d9b527   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   30f1aba0-44f4-457e-bb0b-c2ab2beb1885   57313d87-3b44-4fb6-bddd-37e90b0e4ca0
default     pvc-089642dd-7159-45d1-9f8f-868531bda5cf   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   f974471c-becd-4974-8e35-1404b2e448e3   dd99472d-a94a-4ee9-aa9d-4bc4174224dc
default     pvc-0f6a60a5-2a0f-4826-8f06-0e97269391fb   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   65a94c06-022c-4e04-85e4-933a1121a863   dd99472d-a94a-4ee9-aa9d-4bc4174224dc
default     pvc-decfebc7-345f-4c86-9b08-535ef01a9088   4000000000000   xfs    GOOD     OPERATIVE   PUBLISHED   IN_USE   8ba5711b-bfd1-46ad-ad2b-9e38f07f3112   dd99472d-a94a-4ee9-aa9d-4bc4174224dc
```


Patch:
diff --git a/.golangci.yml b/.golangci.yml
index a76cd53..d8a3e78 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -39,7 +39,6 @@ linters:
     - gosimple
     - govet
     - ineffassign
-    - interfacer
     - lll
     - megacheck
     - misspell
diff --git a/pkg/base/capacityplanner/node_capacity.go b/pkg/base/capacityplanner/node_capacity.go
index 6b1266a..d7a5d34 100644
--- a/pkg/base/capacityplanner/node_capacity.go
+++ b/pkg/base/capacityplanner/node_capacity.go
@@ -17,6 +17,7 @@
 package capacityplanner
 
 import (
+	"fmt"
 	"sort"
 
 	genV1 "github.com/dell/csi-baremetal/api/generated/v1"
@@ -45,6 +46,11 @@ type nodeCapacity struct {
 	acsOrder scToACOrder
 }
 
+// String is pretty print function for nodeCapacity
+func (nc *nodeCapacity) String() string {
+	return fmt.Sprintf("ACs: %+v", nc.acsOrder)
+}
+
 func newNodeCapacity(node string, acs []accrd.AvailableCapacity, acrs []acrcrd.AvailableCapacityReservation) *nodeCapacity {
 	// Check for no capacity on node
 	if len(acs) == 0 {
diff --git a/pkg/base/linuxutils/datadiscover/datadiscover.go b/pkg/base/linuxutils/datadiscover/datadiscover.go
index a817ea9..efbc61a 100644
--- a/pkg/base/linuxutils/datadiscover/datadiscover.go
+++ b/pkg/base/linuxutils/datadiscover/datadiscover.go
@@ -71,7 +71,7 @@ func (w *WrapDataDiscoverImpl) DiscoverData(device, serialNumber string) (*types
 		}, nil
 	}
 
-	if hasData, err = w.partHelper.DeviceHasPartitions(device, serialNumber); err != nil {
+	if hasData, err = w.partHelper.DeviceHasPartitions(device); err != nil {
 		return nil, err
 	}
 	if hasData {
diff --git a/pkg/base/linuxutils/partitionhelper/partition_helper.go b/pkg/base/linuxutils/partitionhelper/partition_helper.go
index 00017fa..2ab9605 100644
--- a/pkg/base/linuxutils/partitionhelper/partition_helper.go
+++ b/pkg/base/linuxutils/partitionhelper/partition_helper.go
@@ -42,7 +42,7 @@ type WrapPartition interface {
 	SyncPartitionTable(device string) error
 	GetPartitionNameByUUID(device, partUUID string) (string, error)
 	DeviceHasPartitionTable(device string) (bool, error)
-	DeviceHasPartitions(device, serialNumber string) (bool, error)
+	DeviceHasPartitions(device string) (bool, error)
 }
 
 const (
@@ -355,9 +355,9 @@ func (p *WrapPartitionImpl) DeviceHasPartitionTable(device string) (bool, error)
 }
 
 // DeviceHasPartitions calls lsblk and determine if device has partitions (children)
-// Receive device path and serial number
+// Receive device path
 // Return true if device has partitions, false in opposite, error if something went wrong
-func (p *WrapPartitionImpl) DeviceHasPartitions(device, serialNumber string) (bool, error) {
+func (p *WrapPartitionImpl) DeviceHasPartitions(device string) (bool, error) {
 	blockDevices, err := p.lsblkUtil.GetBlockDevices(device)
 	if len(blockDevices) != 1 {
 		return false, fmt.Errorf("wrong output of lsblk for %s, block devices: %v", device, blockDevices)
@@ -367,13 +367,8 @@ func (p *WrapPartitionImpl) DeviceHasPartitions(device, serialNumber string) (bo
 		return false, err
 	}
 
-	bdev := blockDevices[0]
-
-	if !strings.EqualFold(bdev.Serial, serialNumber) {
-		return false, fmt.Errorf("serial numbers for block device %s don't match: %s != %s", bdev.Name, bdev.Serial,
-			serialNumber)
-	}
-	if len(bdev.Children) > 0 {
+	// check number of partitions
+	if len(blockDevices[0].Children) > 0 {
 		return true, nil
 	}
 
diff --git a/pkg/mocks/linuxutils/partitionhelper.go b/pkg/mocks/linuxutils/partitionhelper.go
index 4027eff..ca22d42 100644
--- a/pkg/mocks/linuxutils/partitionhelper.go
+++ b/pkg/mocks/linuxutils/partitionhelper.go
@@ -33,8 +33,8 @@ func (m *MockWrapPartition) DeviceHasPartitionTable(device string) (bool, error)
 }
 
 // DeviceHasPartitions is a mock implementations
-func (m *MockWrapPartition) DeviceHasPartitions(device, serialNumber string) (bool, error) {
-	args := m.Mock.Called(device, serialNumber)
+func (m *MockWrapPartition) DeviceHasPartitions(device string) (bool, error) {
+	args := m.Mock.Called(device)
 
 	return args.Bool(0), args.Error(1)
 }


Test patch:
diff --git a/pkg/base/linuxutils/datadiscover/datadiscover_test.go b/pkg/base/linuxutils/datadiscover/datadiscover_test.go
index ad3d0e5..7e5b808 100644
--- a/pkg/base/linuxutils/datadiscover/datadiscover_test.go
+++ b/pkg/base/linuxutils/datadiscover/datadiscover_test.go
@@ -49,7 +49,7 @@ func Test_DiscoverData(t *testing.T) {
 		)
 		fs.On("DeviceFs", device).Return("", nil).Times(1)
 		part.On("DeviceHasPartitionTable", device).Return(false, nil).Times(1)
-		part.On("DeviceHasPartitions", device, serialNumber).Return(true, nil).Times(1)
+		part.On("DeviceHasPartitions", device).Return(true, nil).Times(1)
 		discoverResult, err := discoverData.DiscoverData(device, serialNumber)
 		assert.Nil(t, err)
 		assert.True(t, discoverResult.HasData)
@@ -64,7 +64,7 @@ func Test_DiscoverData(t *testing.T) {
 		)
 		fs.On("DeviceFs", device).Return("", nil).Times(1)
 		part.On("DeviceHasPartitionTable", device).Return(false, nil).Times(1)
-		part.On("DeviceHasPartitions", device, serialNumber).Return(false, nil).Times(1)
+		part.On("DeviceHasPartitions", device).Return(false, nil).Times(1)
 		discoverResult, err := discoverData.DiscoverData(device, serialNumber)
 		assert.Nil(t, err)
 		fmt.Println(discoverResult.HasData)
@@ -104,7 +104,7 @@ func Test_DiscoverData(t *testing.T) {
 		)
 		fs.On("DeviceFs", device).Return("", nil).Times(1)
 		part.On("DeviceHasPartitionTable", device).Return(false, nil).Times(1)
-		part.On("DeviceHasPartitions", device, serialNumber).Return(false, errors.New("error")).Times(1)
+		part.On("DeviceHasPartitions", device).Return(false, errors.New("error")).Times(1)
 		discoverResult, err := discoverData.DiscoverData(device, serialNumber)
 		assert.NotNil(t, err)
 		assert.Nil(t, discoverResult)
diff --git a/pkg/base/linuxutils/partitionhelper/partitionhelper_test.go b/pkg/base/linuxutils/partitionhelper/partitionhelper_test.go
index 5c1188f..b4c29dc 100644
--- a/pkg/base/linuxutils/partitionhelper/partitionhelper_test.go
+++ b/pkg/base/linuxutils/partitionhelper/partitionhelper_test.go
@@ -252,7 +252,7 @@ func TestLinuxUtils_DeviceHasPartitions(t *testing.T) {
 		}}
 		mockLsblk.On("GetBlockDevices", device).
 			Return([]lsblk.BlockDevice{blkDev1}, nil).Times(1)
-		hasPart, err := p.DeviceHasPartitions(device, serialNumber)
+		hasPart, err := p.DeviceHasPartitions(device)
 		assert.Nil(t, err)
 		assert.True(t, hasPart)
 	})
@@ -261,7 +261,7 @@ func TestLinuxUtils_DeviceHasPartitions(t *testing.T) {
 		blkDev1 := lsblk.BlockDevice{Serial: serialNumber}
 		mockLsblk.On("GetBlockDevices", device).
 			Return([]lsblk.BlockDevice{blkDev1}, nil).Times(1)
-		hasPart, err := p.DeviceHasPartitions(device, serialNumber)
+		hasPart, err := p.DeviceHasPartitions(device)
 		assert.Nil(t, err)
 		assert.False(t, hasPart)
 	})
@@ -269,22 +269,14 @@ func TestLinuxUtils_DeviceHasPartitions(t *testing.T) {
 	t.Run("Command failed", func(t *testing.T) {
 		mockLsblk.On("GetBlockDevices", device).
 			Return(nil, errors.New("error")).Times(1)
-		hasPart, err := p.DeviceHasPartitions(device, serialNumber)
+		hasPart, err := p.DeviceHasPartitions(device)
 		assert.NotNil(t, err)
 		assert.False(t, hasPart)
 	})
 	t.Run("Bad output", func(t *testing.T) {
 		mockLsblk.On("GetBlockDevices", device).
 			Return(nil, nil).Times(1)
-		hasPart, err := p.DeviceHasPartitions(device, serialNumber)
-		assert.NotNil(t, err)
-		assert.False(t, hasPart)
-	})
-	t.Run("Different serial numbers", func(t *testing.T) {
-		blkDev1 := lsblk.BlockDevice{Serial: serialNumber}
-		mockLsblk.On("GetBlockDevices", device).
-			Return([]lsblk.BlockDevice{blkDev1}, nil).Times(1)
-		hasPart, err := p.DeviceHasPartitions(device, "test2")
+		hasPart, err := p.DeviceHasPartitions(device)
 		assert.NotNil(t, err)
 		assert.False(t, hasPart)
 	})