Skip to content

Commit

Permalink
Fix storage unit test (canonical#302)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Sabaini <[email protected]>
  • Loading branch information
sabaini authored Feb 21, 2024
1 parent a6c8001 commit b4c72db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion microceph/common/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func IsMounted(device string) (bool, error) {
// Resolve any symlink and get the absolute path of the device.
// Note /proc/mounts contains the absolute path of the device as well.
resolvedPath, err := filepath.EvalSymlinks(device)
resolvedPath, err := filepath.EvalSymlinks(filepath.Join(constants.GetPathConst().RootFs, device))
if err != nil {
// Handle errors other than not existing differently as EvalSymlinks takes care of symlink resolution
return false, err
Expand Down
5 changes: 4 additions & 1 deletion microceph/common/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ func (s *StorageDeviceTestSuite) SetupTest() {
// create a temp file to use as a device
s.devicePath = filepath.Join(s.Tmp, "device")
os.Create(s.devicePath)
os.MkdirAll(filepath.Join(s.Tmp, "dev"), 0775)
os.Create(filepath.Join(s.Tmp, "dev", "sdb"))
os.Create(filepath.Join(s.Tmp, "dev", "sdc"))

// create a /proc/mounts like file
mountsFile := filepath.Join(s.Tmp, "proc", "mounts")
mountsContent := "/dev/root / ext4 rw,relatime,discard,errors=remount-ro 0 0\n"
mountsContent += "/dev/sdb /mnt ext2 rw,relatime 0 0\n"
mountsContent += filepath.Join(s.Tmp, "dev", "sdb") + " /mnt ext2 rw,relatime 0 0\n"
_ = os.WriteFile(mountsFile, []byte(mountsContent), 0644)

}
Expand Down
2 changes: 2 additions & 0 deletions microceph/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type PathConst struct {
RunPath string
DataPath string
LogPath string
RootFs string
ProcPath string
}

Expand All @@ -33,6 +34,7 @@ func GetPathConst() PathConst {
RunPath: filepath.Join(os.Getenv("SNAP_DATA"), "run"),
DataPath: filepath.Join(os.Getenv("SNAP_COMMON"), "data"),
LogPath: filepath.Join(os.Getenv("SNAP_COMMON"), "logs"),
RootFs: filepath.Join(os.Getenv("TEST_ROOT_PATH"), "/"),
ProcPath: filepath.Join(os.Getenv("TEST_ROOT_PATH"), "/proc"),
}
}
Expand Down

0 comments on commit b4c72db

Please sign in to comment.