3
from landscape.lib.disk import get_filesystem_for_path
4
from landscape.tests.helpers import LandscapeTest
7
class DiskUtilitiesTest(LandscapeTest):
10
super(DiskUtilitiesTest, self).setUp()
11
self.mount_file = self.make_path("")
12
self.stat_results = {}
13
self.statvfs = self.stat_results.get
15
def set_mount_points(self, points):
16
content = "\n".join("/dev/sda%d %s fsfs rw 0 0" % (i, point)
17
for i, point in enumerate(points))
18
f = open(self.mount_file, "w")
22
self.stat_results[point] = (4096, 0, 1000, 500, 0, 0, 0, 0, 0)
24
def test_get_filesystem_for_path(self):
25
self.set_mount_points(["/"])
26
info = get_filesystem_for_path("/", self.mount_file, self.statvfs)
27
self.assertEquals(info["mount-point"], "/")
29
def test_get_filesystem_subpath(self):
30
self.set_mount_points(["/"])
31
self.stat_results["/"] = (4096, 0, 1000, 500, 0, 0, 0, 0, 0)
32
info = get_filesystem_for_path("/home", self.mount_file, self.statvfs)
33
self.assertEquals(info["mount-point"], "/")
35
def test_get_filesystem_subpath_closest(self):
36
self.set_mount_points(["/", "/home"])
37
info = get_filesystem_for_path("/home", self.mount_file, self.statvfs)
38
self.assertEquals(info["mount-point"], "/home")
40
def test_get_filesystem_subpath_not_stupid(self):
41
self.set_mount_points(["/", "/ho"])
42
info = get_filesystem_for_path("/home", self.mount_file, self.statvfs)
43
self.assertEquals(info["mount-point"], "/")
45
def test_symlink_home(self):
46
symlink_path = self.make_path()
47
os.symlink("/foo/bar", symlink_path)
48
self.set_mount_points(["/", "/foo"])
49
info = get_filesystem_for_path(symlink_path,
50
self.mount_file, self.statvfs)
51
self.assertEquals(info["mount-point"], "/foo")