Merge lp:~tribaal/landscape-client/fix-1045374-mount-storm-in-client-take-2 into lp:~landscape/landscape-client/trunk

Proposed by Chris Glass
Status: Merged
Approved by: Geoff Teale
Approved revision: 577
Merged at revision: 576
Proposed branch: lp:~tribaal/landscape-client/fix-1045374-mount-storm-in-client-take-2
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 155 lines (+41/-29)
3 files modified
landscape/lib/disk.py (+10/-4)
landscape/lib/tests/test_disk.py (+24/-11)
landscape/sysinfo/disk.py (+7/-14)
To merge this branch: bzr merge lp:~tribaal/landscape-client/fix-1045374-mount-storm-in-client-take-2
Reviewer Review Type Date Requested Status
Geoff Teale (community) Approve
Thomas Herve (community) Approve
Review via email: mp+123979@code.launchpad.net

Description of the change

After further testing, the filtering on device type is less interesting than filtering on filesystem type (autofs filesystems are shown as being of "autofs" type).

Filtering on device does not work since the autofs device name is actually the name of the map (as appearing in /etc/auto.master), and is therefore "auto_direct" only as a convention.

Since there was already a filesystem type whitelist in the code I refactored it to be in the right module, and made the whitelist the default choice.

To post a comment you must log in.
Revision history for this message
Thomas Herve (therve) wrote :

[1]
+ if filesystems_whitelist is None:
+ filesystems_whitelist = STABLE_FILESYSTEMS

You can directly make it the default of the function. Maybe use a frozen set to feel more comfortable.

[2]
+from landscape.lib.disk import (get_mount_info, get_filesystem_for_path,
+STABLE_FILESYSTEMS)

You don't need to pass the value anymore, so you don't have to import STABLE_FILESYSTEMS.

[3] pep8

landscape/sysinfo/disk.py:12:25: E225 missing whitespace around operator
landscape/sysinfo/disk.py:13:37: E225 missing whitespace around operator
landscape/sysinfo/disk.py:15:37: E225 missing whitespace around operator

Thanks!

review: Approve
577. By Chris Glass

Made the STABLE_FILESYSTEM list a frozenset, passed it as method default and
removed it from the various places where it was imported and used for no reason.

Also fixed some lint.

Revision history for this message
Chris Glass (tribaal) wrote :

All comments should be addressed.

Revision history for this message
Geoff Teale (tealeg) wrote :

+1 Looks Good

review: Approve
578. By Chris Glass

Removed default filesystem whitelist in get_filesystem_for_path

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/lib/disk.py'
2--- landscape/lib/disk.py 2010-06-07 18:04:31 +0000
3+++ landscape/lib/disk.py 2012-09-17 13:15:25 +0000
4@@ -4,7 +4,14 @@
5 import statvfs
6
7
8-def get_mount_info(mounts_file, statvfs_, filesystems_whitelist=None):
9+# List of filesystem types authorized when generating disk use statistics.
10+STABLE_FILESYSTEMS = frozenset(
11+ ["ext", "ext2", "ext3", "ext4", "reiserfs", "ntfs", "msdos", "dos", "vfat",
12+ "xfs", "hpfs", "jfs", "ufs", "hfs", "hfsplus"])
13+
14+
15+def get_mount_info(mounts_file, statvfs_,
16+ filesystems_whitelist=STABLE_FILESYSTEMS):
17 """
18 This is a generator that yields information about mounted filesystems.
19
20@@ -40,8 +47,7 @@
21 "free-space": free_space}
22
23
24-def get_filesystem_for_path(path, mounts_file, statvfs_,
25- filesystems_whitelist=None):
26+def get_filesystem_for_path(path, mounts_file, statvfs_):
27 """
28 Tries to determine to which of the mounted filesystem C{path} belongs to,
29 and then returns information about that filesystem or C{None} if it
30@@ -61,7 +67,7 @@
31 candidate = None
32 path = os.path.realpath(path)
33 path_segments = path.split("/")
34- for info in get_mount_info(mounts_file, statvfs_, filesystems_whitelist):
35+ for info in get_mount_info(mounts_file, statvfs_):
36 mount_segments = info["mount-point"].split("/")
37 if path.startswith(info["mount-point"]):
38 if ((not candidate)
39
40=== modified file 'landscape/lib/tests/test_disk.py'
41--- landscape/lib/tests/test_disk.py 2011-07-05 05:09:11 +0000
42+++ landscape/lib/tests/test_disk.py 2012-09-17 13:15:25 +0000
43@@ -1,6 +1,6 @@
44 import os
45
46-from landscape.lib.disk import get_filesystem_for_path
47+from landscape.lib.disk import get_filesystem_for_path, get_mount_info
48 from landscape.tests.helpers import LandscapeTest
49
50
51@@ -32,7 +32,7 @@
52 yield a permission denied error when inspected.
53 """
54 self.read_access = read_access
55- content = "\n".join("/dev/sda%d %s fsfs rw 0 0" % (i, point)
56+ content = "\n".join("/dev/sda%d %s ext4 rw 0 0" % (i, point)
57 for i, point in enumerate(points))
58 f = open(self.mount_file, "w")
59 f.write(content)
60@@ -70,15 +70,6 @@
61 self.mount_file, self.statvfs)
62 self.assertEqual(info["mount-point"], "/foo")
63
64- def test_whitelist(self):
65- self.set_mount_points(["/"])
66- info = get_filesystem_for_path(
67- "/", self.mount_file, self.statvfs, ["ext3"])
68- self.assertIdentical(info, None)
69- info = get_filesystem_for_path(
70- "/", self.mount_file, self.statvfs, ["ext3", "fsfs"])
71- self.assertNotIdentical(info, None)
72-
73 def test_ignore_unreadable_mount_point(self):
74 """
75 We should ignore mountpoints which are unreadable by the user who
76@@ -88,3 +79,25 @@
77 info = get_filesystem_for_path(
78 "/secret", self.mount_file, self.statvfs)
79 self.assertIdentical(info, None)
80+
81+ def test_ignore_unmounted_and_virtual_mountpoints(self):
82+ """
83+ Make sure autofs and virtual mountpoints are ignored. This is to
84+ ensure non-regression on bug #1045374.
85+ """
86+ self.read_access = True
87+ content = "\n".join(["auto_direct /opt/whatever autofs",
88+ "none /run/lock tmpfs",
89+ "proc /proc proc",
90+ "/dev/sda1 /home ext4"])
91+
92+ f = open(self.mount_file, "w")
93+ f.write(content)
94+ f.close()
95+
96+ self.stat_results["/home"] = (4096, 0, 1000, 500, 0, 0, 0, 0, 0)
97+
98+ result = [x for x in get_mount_info(self.mount_file, self.statvfs)]
99+ expected = {"device": "/dev/sda1", "mount-point": "/home",
100+ "filesystem": "ext4", "total-space": 3, "free-space": 1}
101+ self.assertEqual([expected], result)
102
103=== modified file 'landscape/sysinfo/disk.py'
104--- landscape/sysinfo/disk.py 2010-03-24 15:28:22 +0000
105+++ landscape/sysinfo/disk.py 2012-09-17 13:15:25 +0000
106@@ -4,20 +4,14 @@
107
108 from twisted.internet.defer import succeed
109
110-from landscape.lib.disk import get_mount_info, get_filesystem_for_path
111-
112-
113-# List of filesystem types authorized when generating disk use statistics.
114-STABLE_FILESYSTEMS = set(
115- ["ext", "ext2", "ext3", "ext4", "reiserfs", "ntfs", "msdos", "dos", "vfat",
116- "xfs", "hpfs", "jfs", "ufs", "hfs", "hfsplus"])
117+from landscape.lib.disk import (get_mount_info, get_filesystem_for_path)
118
119
120 def format_megabytes(megabytes):
121- if megabytes >= 1024*1024:
122- return "%.2fTB" % (megabytes/(1024*1024))
123+ if megabytes >= 1024 * 1024:
124+ return "%.2fTB" % (megabytes / (1024 * 1024))
125 elif megabytes >= 1024:
126- return "%.2fGB" % (megabytes/1024)
127+ return "%.2fGB" % (megabytes / 1024)
128 else:
129 return "%dMB" % (megabytes)
130
131@@ -39,12 +33,12 @@
132
133 def run(self):
134 main_info = get_filesystem_for_path("/home", self._mounts_file,
135- self._statvfs, STABLE_FILESYSTEMS)
136+ self._statvfs)
137 if main_info is not None:
138 total = main_info["total-space"]
139 if total <= 0:
140 root_main_info = get_filesystem_for_path(
141- "/", self._mounts_file, self._statvfs, STABLE_FILESYSTEMS)
142+ "/", self._mounts_file, self._statvfs)
143 if root_main_info is not None:
144 total = root_main_info["total-space"]
145 main_info = root_main_info
146@@ -59,8 +53,7 @@
147
148 seen_mounts = set()
149 seen_devices = set()
150- infos = list(get_mount_info(self._mounts_file, self._statvfs,
151- STABLE_FILESYSTEMS))
152+ infos = list(get_mount_info(self._mounts_file, self._statvfs))
153 infos.sort(key=lambda i: len(i["mount-point"]))
154 for info in infos:
155 total = info["total-space"]

Subscribers

People subscribed via source and target branches

to all changes: