From 98a7be509995273cf997bc68b602bec108de4f96 Mon Sep 17 00:00:00 2001 From: 27149chen <7991675+27149chen@users.noreply.github.com> Date: Thu, 14 Mar 2019 15:33:45 +0800 Subject: [PATCH] change LunNumber from float64 to int Signed-off-by: 27149chen <7991675+27149chen@users.noreply.github.com> --- .../block_device_utils_mounter_test.go | 2 +- .../mounter/block_device_utils/block_device_utils_test.go | 2 +- remote/mounter/initiator/connectors/fibre_channel_test.go | 2 +- remote/mounter/initiator/linuxfc.go | 5 ++--- remote/mounter/initiator/linuxfc_test.go | 4 ++-- remote/mounter/scbe.go | 8 ++++++-- remote/mounter/scbe_test.go | 2 +- resources/resources.go | 2 +- 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/remote/mounter/block_device_mounter_utils/block_device_utils_mounter_test.go b/remote/mounter/block_device_mounter_utils/block_device_utils_mounter_test.go index 2c220d7e..da8eda5a 100644 --- a/remote/mounter/block_device_mounter_utils/block_device_utils_mounter_test.go +++ b/remote/mounter/block_device_mounter_utils/block_device_utils_mounter_test.go @@ -37,7 +37,7 @@ var _ = Describe("block_device_mounter_utils_test", func() { err error callErr error = errors.New("error") ) - volumeMountProperties := &resources.VolumeMountProperties{WWN: "wwn", LunNumber: float64(1)} + volumeMountProperties := &resources.VolumeMountProperties{WWN: "wwn", LunNumber: 1} BeforeEach(func() { fakeBlockDeviceUtils = new(fakes.FakeBlockDeviceUtils) diff --git a/remote/mounter/block_device_utils/block_device_utils_test.go b/remote/mounter/block_device_utils/block_device_utils_test.go index 67d38441..adce3cbb 100644 --- a/remote/mounter/block_device_utils/block_device_utils_test.go +++ b/remote/mounter/block_device_utils/block_device_utils_test.go @@ -44,7 +44,7 @@ var _ = Describe("block_device_utils_test", func() { err error cmdErr error = errors.New("command error") ) - volumeMountProperties := &resources.VolumeMountProperties{WWN: "wwn", LunNumber: float64(1)} + volumeMountProperties := &resources.VolumeMountProperties{WWN: "wwn", LunNumber: 1} BeforeEach(func() { fakeExec = new(fakes.FakeExecutor) diff --git a/remote/mounter/initiator/connectors/fibre_channel_test.go b/remote/mounter/initiator/connectors/fibre_channel_test.go index aa74f0cb..dd9f998d 100644 --- a/remote/mounter/initiator/connectors/fibre_channel_test.go +++ b/remote/mounter/initiator/connectors/fibre_channel_test.go @@ -33,7 +33,7 @@ var _ = Describe("Test Fibre Channel Connector", func() { fakeInitiator *fakeinitiator.FakeInitiator fcConnector initiator.Connector ) - volumeMountProperties := &resources.VolumeMountProperties{WWN: fakeWwn, LunNumber: float64(1)} + volumeMountProperties := &resources.VolumeMountProperties{WWN: fakeWwn, LunNumber: 1} BeforeEach(func() { fakeExec = new(fakes.FakeExecutor) diff --git a/remote/mounter/initiator/linuxfc.go b/remote/mounter/initiator/linuxfc.go index dd57ca05..8c428cf0 100644 --- a/remote/mounter/initiator/linuxfc.go +++ b/remote/mounter/initiator/linuxfc.go @@ -53,11 +53,10 @@ func (lfc *linuxFibreChannel) hasFCSupport() bool { // may be '-' wildcards if unable to determine them. func (lfc *linuxFibreChannel) getHBAChannelScsiTarget(volumeMountProperties *resources.VolumeMountProperties) string { //TODO: get channel and target - if volumeMountProperties.LunNumber == float64(-1) { + if volumeMountProperties.LunNumber == -1 { return "- - -" } - // use %g to print a float64 to int - return fmt.Sprintf("- - %g", volumeMountProperties.LunNumber) + return fmt.Sprintf("- - %d", volumeMountProperties.LunNumber) } // GetHBAs return all the FC HBAs in the system diff --git a/remote/mounter/initiator/linuxfc_test.go b/remote/mounter/initiator/linuxfc_test.go index 9b468ea0..9a4f743a 100644 --- a/remote/mounter/initiator/linuxfc_test.go +++ b/remote/mounter/initiator/linuxfc_test.go @@ -83,7 +83,7 @@ var _ = Describe("Test FC Initiator", func() { realSysBlockPath string cmdErr error = errors.New("command error") ) - volumeMountProperties := &resources.VolumeMountProperties{WWN: "wwn", LunNumber: float64(1)} + volumeMountProperties := &resources.VolumeMountProperties{WWN: "wwn", LunNumber: 1} BeforeEach(func() { err := os.MkdirAll(FAKE_FC_HOST_SYSFS_PATH, os.ModePerm) @@ -187,7 +187,7 @@ var _ = Describe("Test FC Initiator", func() { Ω(err).ShouldNot(HaveOccurred()) data, err := ioutil.ReadFile(scanFile) Ω(err).ShouldNot(HaveOccurred()) - Expect(string(data)).To(Equal(fmt.Sprintf("- - %g", volumeMountProperties.LunNumber))) + Expect(string(data)).To(Equal(fmt.Sprintf("- - %d", volumeMountProperties.LunNumber))) }) It("should write '1' to the hba lip file", func() { diff --git a/remote/mounter/scbe.go b/remote/mounter/scbe.go index 19b5f2a2..d924bf7a 100644 --- a/remote/mounter/scbe.go +++ b/remote/mounter/scbe.go @@ -53,9 +53,13 @@ func NewScbeMounterWithExecuter(blockDeviceMounterUtils block_device_mounter_uti func (s *scbeMounter) prepareVolumeMountProperties(vcGetter resources.VolumeConfigGetter) *resources.VolumeMountProperties { volumeConfig := vcGetter.GetVolumeConfig() volumeWWN := volumeConfig["Wwn"].(string) - volumeLunNumber := float64(-1) + volumeLunNumber := -1 if volumeLunNumberInterface, exists := volumeConfig[resources.ScbeKeyVolAttachLunNumToHost]; exists { - volumeLunNumber = volumeLunNumberInterface.(float64) + + // LunNumber is int, but after json.Marshal and json.UNmarshal it will become float64. + // see https://stackoverflow.com/questions/39152481/unmarshaling-a-json-integer-to-an-empty-interface-results-in-wrong-type-assertio + // but LunNumber should be int, so convert it here. + volumeLunNumber = int(volumeLunNumberInterface.(float64)) } return &resources.VolumeMountProperties{WWN: volumeWWN, LunNumber: volumeLunNumber} } diff --git a/remote/mounter/scbe_test.go b/remote/mounter/scbe_test.go index bc839e2f..bb5c1b9c 100644 --- a/remote/mounter/scbe_test.go +++ b/remote/mounter/scbe_test.go @@ -40,7 +40,7 @@ var _ = Describe("scbe_mounter_test", func() { "LogicalCapacity": fakeLogicalCapacity, "LunNumber": float64(1), "PoolName": "pool", "StorageName": "IBM.2706", "fstype": "ext4"}} mountRequestForDS8kLun2 = resources.MountRequest{Mountpoint: "test_mountpointDS8k", VolumeConfig: map[string]interface{}{"Name": "u_vol", "PhysicalCapacity": fakePhysicalCapacity, "Profile": fakeProfile, "UsedCapacity": fakeUsedCapacity, "Wwn": "wwn", "attach-to": "node1", - "LogicalCapacity": fakeLogicalCapacity, "LunNumber": float64(1), "PoolName": "pool", "StorageName": "IBM.2107", "fstype": "ext4"}} + "LogicalCapacity": fakeLogicalCapacity, "LunNumber": float64(1074741264), "PoolName": "pool", "StorageName": "IBM.2107", "fstype": "ext4"}} mountRequestForDS8kLun3 = resources.MountRequest{Mountpoint: "test_mountpointDS8k", VolumeConfig: map[string]interface{}{"Name": "u_vol", "PhysicalCapacity": fakePhysicalCapacity, "Profile": fakeProfile, "StorageType": fakeDS8kStoragetType, "UsedCapacity": fakeUsedCapacity, "Wwn": "wwn", "attach-to": "node1", "LogicalCapacity": fakeLogicalCapacity, "PoolName": "pool", "StorageName": "IBM.2107", "fstype": "ext4"}} diff --git a/resources/resources.go b/resources/resources.go index 24187e38..f6b55ff9 100644 --- a/resources/resources.go +++ b/resources/resources.go @@ -358,5 +358,5 @@ type RequestContext struct { type VolumeMountProperties struct { WWN string - LunNumber float64 + LunNumber int }