From b4c72dbe345df2a41dfc4dd655081af6e7bb28fd Mon Sep 17 00:00:00 2001 From: Peter Sabaini Date: Wed, 21 Feb 2024 07:49:59 +0100 Subject: [PATCH] Fix storage unit test (#302) Signed-off-by: Peter Sabaini --- microceph/common/storage.go | 2 +- microceph/common/storage_test.go | 5 ++++- microceph/constants/constants.go | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/microceph/common/storage.go b/microceph/common/storage.go index a54de661..4e1bce1d 100644 --- a/microceph/common/storage.go +++ b/microceph/common/storage.go @@ -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 diff --git a/microceph/common/storage_test.go b/microceph/common/storage_test.go index 75807dc5..b703a25e 100644 --- a/microceph/common/storage_test.go +++ b/microceph/common/storage_test.go @@ -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) } diff --git a/microceph/constants/constants.go b/microceph/constants/constants.go index 5fcdd71e..b20ef6e3 100644 --- a/microceph/constants/constants.go +++ b/microceph/constants/constants.go @@ -22,6 +22,7 @@ type PathConst struct { RunPath string DataPath string LogPath string + RootFs string ProcPath string } @@ -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"), } }