Merge lp:~therve/landscape-client/remove-mount-activity into lp:~landscape/landscape-client/trunk

Proposed by Thomas Herve
Status: Merged
Approved by: Björn Tillenius
Approved revision: 301
Merged at revision: 301
Proposed branch: lp:~therve/landscape-client/remove-mount-activity
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 338 lines (+38/-131)
2 files modified
landscape/monitor/mountinfo.py (+4/-24)
landscape/monitor/tests/test_mountinfo.py (+34/-107)
To merge this branch: bzr merge lp:~therve/landscape-client/remove-mount-activity
Reviewer Review Type Date Requested Status
Björn Tillenius (community) Approve
Kevin McDermott (community) Approve
Review via email: mp+43336@code.launchpad.net

Description of the change

The branch removes the generation of the message, but not the message schema itself: we need it in the server for backward compatibility.

To post a comment you must log in.
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Looks good to me, shame we can't remove the schema entry...

Is it worth while doing work to have DEPRECATED_SCHEMAs or something, which can be dropped when they're sent to the server?

Revision history for this message
Kevin McDermott (bigkevmcd) :
review: Approve
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/monitor/mountinfo.py'
2--- landscape/monitor/mountinfo.py 2010-06-22 10:51:24 +0000
3+++ landscape/monitor/mountinfo.py 2010-12-10 11:20:42 +0000
4@@ -14,7 +14,7 @@
5
6 max_free_space_items_to_exchange = 200
7
8- def __init__(self, interval=300, monitor_interval=60*60,
9+ def __init__(self, interval=300, monitor_interval=60 * 60,
10 mounts_file="/proc/mounts", create_time=time.time,
11 statvfs=None, hal_manager=None, mtab_file="/etc/mtab"):
12 self.run_interval = interval
13@@ -29,8 +29,6 @@
14 self._free_space = []
15 self._mount_info = []
16 self._mount_info_to_persist = None
17- self._mount_activity = []
18- self._prev_mount_activity = {}
19 self._hal_manager = hal_manager or HALManager()
20
21 def register(self, registry):
22@@ -50,16 +48,7 @@
23
24 def create_messages(self):
25 return filter(None, [self.create_mount_info_message(),
26- self.create_free_space_message(),
27- self.create_mount_activity_message()])
28-
29- def create_mount_activity_message(self):
30- if self._mount_activity:
31- message = {"type": "mount-activity",
32- "activities": self._mount_activity}
33- self._mount_activity = []
34- return message
35- return None
36+ self.create_free_space_message()])
37
38 def create_mount_info_message(self):
39 if self._mount_info:
40@@ -120,20 +109,11 @@
41 if mount_info not in [m for t, m in self._mount_info]:
42 self._mount_info.append((now, mount_info))
43
44- if not self._prev_mount_activity.get(mount_point, False):
45- self._mount_activity.append((now, mount_point, True))
46- self._prev_mount_activity[mount_point] = True
47-
48 current_mount_points.add(mount_point)
49
50- for mount_point in self._prev_mount_activity:
51- if mount_point not in current_mount_points:
52- self._mount_activity.append((now, mount_point, False))
53- self._prev_mount_activity[mount_point] = False
54-
55 def _get_removable_devices(self):
56- block_devices = {} # {udi: [device, ...]}
57- children = {} # {parent_udi: [child_udi, ...]}
58+ block_devices = {} # {udi: [device, ...]}
59+ children = {} # {parent_udi: [child_udi, ...]}
60 removable = set()
61
62 # We walk the list of devices building up a dictionary of all removable
63
64=== modified file 'landscape/monitor/tests/test_mountinfo.py'
65--- landscape/monitor/tests/test_mountinfo.py 2010-01-29 12:17:24 +0000
66+++ landscape/monitor/tests/test_mountinfo.py 2010-12-10 11:20:42 +0000
67@@ -18,14 +18,13 @@
68
69 def setUp(self):
70 LandscapeTest.setUp(self)
71- self.mstore.set_accepted_types(["mount-info", "mount-activity",
72- "free-space"])
73+ self.mstore.set_accepted_types(["mount-info", "free-space"])
74
75 def get_mount_info(self, *args, **kwargs):
76 hal_devices = kwargs.pop("hal_devices", [])
77 kwargs["hal_manager"] = MockHALManager(hal_devices)
78 if "statvfs" not in kwargs:
79- kwargs["statvfs"] = lambda path: (0,)*10
80+ kwargs["statvfs"] = lambda path: (0,) * 10
81 return MountInfo(*args, **kwargs)
82
83 def test_read_proc_mounts(self):
84@@ -121,9 +120,10 @@
85 {"device": "/dev/hde1", "mount-point": "/mnt/hde1",
86 "filesystem": "reiserfs", "total-space": 40960000})
87
88- self.assertEquals(mount_info[2][1],
89- {"device": "/dev/sdb2", "mount-point": "/media/Boot OSX",
90- "filesystem": "hfsplus", "total-space": 40960000})
91+ self.assertEquals(
92+ mount_info[2][1],
93+ {"device": "/dev/sdb2", "mount-point": "/media/Boot OSX",
94+ "filesystem": "hfsplus", "total-space": 40960000})
95
96 def test_read_changing_total_space(self):
97 """
98@@ -154,7 +154,8 @@
99 self.assertEquals(len(mount_info), 2)
100
101 for i, total_space in enumerate([4096000, 8192000]):
102- self.assertEquals(mount_info[i][0], (i+1) * self.monitor.step_size)
103+ self.assertEquals(mount_info[i][0],
104+ (i + 1) * self.monitor.step_size)
105 self.assertEquals(mount_info[i][1],
106 {"device": "/dev/hda1", "filesystem": "ext3",
107 "mount-point": "/", "total-space": total_space})
108@@ -236,7 +237,7 @@
109 self.monitor.exchange()
110
111 messages = self.mstore.get_pending_messages()
112- self.assertEquals(len(messages), 3)
113+ self.assertEquals(len(messages), 2)
114
115 message = [d for d in messages if d["type"] == "free-space"][0]
116 free_space = message["free-space"]
117@@ -264,7 +265,7 @@
118 self.reactor.advance(self.monitor.step_size)
119
120 messages = plugin.create_messages()
121- self.assertEquals(len(messages), 3)
122+ self.assertEquals(len(messages), 2)
123
124 messages = plugin.create_messages()
125 self.assertEquals(len(messages), 0)
126@@ -311,7 +312,8 @@
127 """
128
129 filename = self.makeFile("""\
130-ennui:/data /data nfs rw,v3,rsize=32768,wsize=32768,hard,lock,proto=udp,addr=ennui 0 0
131+ennui:/data /data nfs rw,v3,rsize=32768,wsize=32768,hard,lock,proto=udp,\
132+addr=ennui 0 0
133 """)
134 plugin = self.get_mount_info(mounts_file=filename, mtab_file=filename)
135 self.monitor.add(plugin)
136@@ -331,7 +333,7 @@
137 "storage.removable": True}),
138 MockRealHALDevice({"info.udi": "wubble0",
139 "block.device": "/dev/scd0",
140- "info.parent": "wubble"}),]
141+ "info.parent": "wubble"})]
142
143 filename = self.makeFile("""\
144 /dev/scd0 /media/Xerox_M750 iso9660 ro,nosuid,nodev,uid=1000,utf8 0 0
145@@ -351,7 +353,7 @@
146 """
147 devices = [MockRealHALDevice({"info.udi": "wubble",
148 "block.device": "/dev/scd0",
149- "storage.removable": True}),]
150+ "storage.removable": True})]
151 filename = self.makeFile("""\
152 /dev/scd0 /media/Xerox_M750 iso9660 ro,nosuid,nodev,uid=1000,utf8 0 0
153 """)
154@@ -379,8 +381,7 @@
155 "info.parent": "wubble0"}),
156 MockRealHALDevice({"info.udi": "wubble0b",
157 "block.device": "/dev/scd0b",
158- "info.parent": "wubble0"}),]
159-
160+ "info.parent": "wubble0"})]
161
162 filename = self.makeFile("""\
163 /dev/scd0a /media/Xerox_M750 iso9660 ro,nosuid,nodev,uid=1000,utf8 0 0
164@@ -451,7 +452,7 @@
165 self.monitor.exchange()
166
167 messages = self.mstore.get_pending_messages()
168- self.assertEquals(len(messages), 3)
169+ self.assertEquals(len(messages), 2)
170 self.assertEquals(messages[0].get("mount-info"),
171 [(step_size,
172 {"device": "/dev/hda2", "mount-point": "/",
173@@ -460,83 +461,6 @@
174 [(step_size, "/", 409600)])
175 self.assertTrue(isinstance(messages[1]["free-space"][0][2],
176 (int, long)))
177- self.assertEquals(messages[2].get("activities"),
178- [(step_size, "/", True)])
179-
180- def test_first_mount_activity_message(self):
181- """
182- Mount activity is only reported when a change from the
183- previous known state is detected. If mount activity has never
184- been reported, it should be.
185- """
186- filename = self.makeFile("""\
187-/dev/hda2 / xfs rw 0 0
188-""")
189- plugin = self.get_mount_info(mounts_file=filename,
190- create_time=self.reactor.time,
191- mtab_file=filename)
192- step_size = self.monitor.step_size
193- self.monitor.add(plugin)
194-
195- self.reactor.advance(step_size)
196- message = plugin.create_mount_activity_message()
197- self.assertEquals(message.get("type"), "mount-activity")
198- self.assertEquals(message.get("activities"), [(300, "/", True)])
199-
200- self.reactor.advance(step_size)
201- self.assertEquals(plugin.create_mount_activity_message(), None)
202-
203- def test_wb_umount_activity(self):
204- """Test ensures the plugin reports new umounts."""
205- filename = self.makeFile("""\
206-/dev/hda2 / xfs rw 0 0
207-""")
208- plugin = self.get_mount_info(mounts_file=filename,
209- create_time=self.reactor.time,
210- mtab_file=filename)
211- step_size = self.monitor.step_size
212- self.monitor.add(plugin)
213-
214- self.reactor.advance(step_size)
215- message = plugin.create_mount_activity_message()
216- self.assertEquals(message.get("type"), "mount-activity")
217- self.assertEquals(message.get("activities"), [(step_size, "/", True)])
218-
219- plugin._mounts_file = self.makeFile("""\
220-""")
221- self.reactor.advance(step_size)
222- message = plugin.create_mount_activity_message()
223- self.assertEquals(message.get("type"), "mount-activity")
224- self.assertEquals(message.get("activities"),
225- [(step_size * 2, "/", False)])
226-
227- def test_wb_mount_activity(self):
228- """Test ensures the plugin reports new mounts."""
229- filename = self.makeFile("""\
230-/dev/hda2 / xfs rw 0 0
231-""")
232- plugin = self.get_mount_info(mounts_file=filename,
233- create_time=self.reactor.time,
234- mtab_file=filename)
235- step_size = self.monitor.step_size
236- self.monitor.add(plugin)
237-
238- self.reactor.advance(step_size)
239- message = plugin.create_mount_activity_message()
240- self.assertEquals(message.get("type"), "mount-activity")
241- self.assertEquals(message.get("activities"), [(step_size, "/", True)])
242-
243- mount_dir = self.makeDir()
244- plugin._mounts_file = self.makeFile("""\
245-/dev/hda2 / xfs rw 0 0
246-/dev/hdb5 %s xfs rw 0 0
247-""" % mount_dir)
248- self.reactor.advance(step_size)
249- message = plugin.create_mount_activity_message()
250- self.assertEquals(message.get("type"), "mount-activity")
251- self.assertEquals(message.get("activities"),
252- [(step_size * 2, mount_dir, True)])
253-
254
255 def test_resynchronize(self):
256 """
257@@ -562,9 +486,10 @@
258 messages = [message for message in messages
259 if message["type"] == "mount-info"]
260 expected_message = {
261- 'type': 'mount-info',
262- 'mount-info': [(0, {'device': '/dev/hda1', 'mount-point': '/',
263- 'total-space': 4096000, 'filesystem': 'ext3'})]}
264+ "type": "mount-info",
265+ "mount-info": [(0, {"device": "/dev/hda1", "mount-point": "/",
266+ "total-space": 4096000,
267+ "filesystem": "ext3"})]}
268 self.assertMessages(messages, [expected_message, expected_message])
269
270 def test_bind_mounts(self):
271@@ -577,7 +502,8 @@
272 return (4096, 0, mb(1000), mb(100), 0, 0, 0, 0, 0)
273
274 # From this test data, we expect only two mount points to be returned,
275- # and the other two to be ignored (the rebound /dev/hda2 -> /mnt mounting)
276+ # and the other two to be ignored (the rebound /dev/hda2 -> /mnt
277+ # mounting)
278 filename = self.makeFile("""\
279 /dev/devices/by-uuid/12345567 / ext3 rw 0 0
280 /dev/hda2 /usr ext3 rw 0 0
281@@ -600,7 +526,7 @@
282 [(0, {"device": "/dev/devices/by-uuid/12345567",
283 "mount-point": "/", "total-space": 4096000L,
284 "filesystem": "ext3"}),
285- (0 ,{"device": "/dev/hda2",
286+ (0, {"device": "/dev/hda2",
287 "mount-point": "/usr",
288 "total-space": 4096000L,
289 "filesystem": "ext3"}),
290@@ -634,14 +560,14 @@
291 [(0, {"device": "/dev/devices/by-uuid/12345567",
292 "mount-point": "/", "total-space": 4096000L,
293 "filesystem": "ext3"}),
294- (0,{"device": "/dev/hda2",
295- "mount-point": "/usr",
296- "total-space": 4096000L,
297- "filesystem": "ext3"}),
298- (0,{"device": "/dev/devices/by-uuid/12345567",
299- "mount-point": "/mnt",
300- "total-space": 4096000L,
301- "filesystem": "ext3"}),])
302+ (0, {"device": "/dev/hda2",
303+ "mount-point": "/usr",
304+ "total-space": 4096000L,
305+ "filesystem": "ext3"}),
306+ (0, {"device": "/dev/devices/by-uuid/12345567",
307+ "mount-point": "/mnt",
308+ "total-space": 4096000L,
309+ "filesystem": "ext3"})])
310
311 def test_no_message_if_not_accepted(self):
312 """
313@@ -649,6 +575,7 @@
314 accepting their type.
315 """
316 self.mstore.set_accepted_types([])
317+
318 def statvfs(path):
319 return (4096, 0, mb(1000), mb(100), 0, 0, 0, 0, 0)
320
321@@ -683,7 +610,7 @@
322 remote_broker_mock = self.mocker.replace(self.remote)
323 remote_broker_mock.send_message(ANY, urgent=True)
324 self.mocker.result(succeed(None))
325- self.mocker.count(3)
326+ self.mocker.count(2)
327 self.mocker.replay()
328
329 self.reactor.fire(("message-type-acceptance-changed", "mount-info"),
330@@ -759,7 +686,7 @@
331 self.monitor.exchange()
332
333 messages = self.mstore.get_pending_messages()
334- self.assertEquals(len(messages), 3)
335+ self.assertEquals(len(messages), 2)
336
337 message = [d for d in messages if d["type"] == "free-space"][0]
338 free_space = message["free-space"]

Subscribers

People subscribed via source and target branches

to all changes: