Skip to content

Commit

Permalink
refactor(mount): pass file path as parameter in DeviceBasicMountInfo() (
Browse files Browse the repository at this point in the history
#539)

the `Identifier.DeviceBasicMountInfo()` fetches mount attributes of a
device by reading the mounts file. The path of this file is currently
fixed. Pass the file path as a parameter to the function. This will
provide more flexibility in the code and also ease writing unit tests
for code that uses this function. The default path is exported as a
constant, and can still be used.

Signed-off-by: Aditya Jain <[email protected]>
  • Loading branch information
z0marlin authored Feb 3, 2021
1 parent ffc9652 commit 0708507
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/539-z0marlin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pass mounts file path as a parameter when fetching mount attributes using DeviceBasicMountInfo()
2 changes: 1 addition & 1 deletion cmd/ndm_daemonset/probe/mountprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (mp *mountProbe) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevic
return
}
mountProbe := newMountProbe(blockDevice.DevPath)
basicMountInfo, err := mountProbe.MountIdentifier.DeviceBasicMountInfo()
basicMountInfo, err := mountProbe.MountIdentifier.DeviceBasicMountInfo(mount.HostMountsFilePath)
if err != nil {
klog.Error(err)
return
Expand Down
8 changes: 5 additions & 3 deletions pkg/mount/mountinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ limitations under the License.
package mount

const (
hostMountFilePath = "/host/proc/1/mounts" // hostMountFilePath is the file path mounted inside container
// HostMountsFilePath is the default path of
// the mounts file mounted inside container
HostMountsFilePath = "/host/proc/1/mounts"
)

// Identifier is an identifier for the mount probe. It will be a devpath like
Expand All @@ -39,8 +41,8 @@ type DeviceMountAttr struct {
// attributes include the filesystem type, mountpoint, device path etc. These mount attributes
// are fetched by parsing a mounts file (/proc/1/mounts) and getting the relevant data. If the
// device is not mounted, then the function will return an error.
func (I *Identifier) DeviceBasicMountInfo() (DeviceMountAttr, error) {
mountUtil := NewMountUtil(hostMountFilePath, I.DevPath, "")
func (I *Identifier) DeviceBasicMountInfo(mountsFilePath string) (DeviceMountAttr, error) {
mountUtil := NewMountUtil(mountsFilePath, I.DevPath, "")
mountAttr, err := mountUtil.getDeviceMountAttr(mountUtil.getMountName)
return mountAttr, err
}

0 comments on commit 0708507

Please sign in to comment.