~ahasenack/landscape-client/landscape-client-1.5.5-0ubuntu0.9.04.0

« back to all changes in this revision

Viewing changes to landscape/lib/tests/test_disk.py

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-09-08 16:35:57 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080908163557-l3ixzj5dxz37wnw2
Tags: 1.0.18-0ubuntu1
New upstream release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
from landscape.lib.disk import get_filesystem_for_path
 
4
from landscape.tests.helpers import LandscapeTest
 
5
 
 
6
 
 
7
class DiskUtilitiesTest(LandscapeTest):
 
8
 
 
9
    def setUp(self):
 
10
        super(DiskUtilitiesTest, self).setUp()
 
11
        self.mount_file = self.make_path("")
 
12
        self.stat_results = {}
 
13
        self.statvfs = self.stat_results.get
 
14
 
 
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")
 
19
        f.write(content)
 
20
        f.close()
 
21
        for point in points:
 
22
            self.stat_results[point] = (4096, 0, 1000, 500, 0, 0, 0, 0, 0)
 
23
 
 
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"], "/")
 
28
 
 
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"], "/")
 
34
 
 
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")
 
39
 
 
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"], "/")
 
44
 
 
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")