Merge lp:~therve/landscape-client/network-traffic-unmount-interface into lp:~landscape/landscape-client/trunk

Proposed by Thomas Herve
Status: Merged
Approved by: Kevin McDermott
Approved revision: 295
Merged at revision: 294
Proposed branch: lp:~therve/landscape-client/network-traffic-unmount-interface
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 93 lines (+17/-9)
2 files modified
landscape/monitor/networkactivity.py (+10/-3)
landscape/monitor/tests/test_networkactivity.py (+7/-6)
To merge this branch: bzr merge lp:~therve/landscape-client/network-traffic-unmount-interface
Reviewer Review Type Date Requested Status
Kevin McDermott (community) Approve
Jamu Kakar (community) Approve
Review via email: mp+35830@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Hi Thomas,

as discussed on IRC, I believe this works as long as the device is not unmounted and re-mounted during two subsequent plugin runs. Not sure if it's something we have to worry about.

295. By Thomas Herve

Disable rollover on 64 bits

Revision history for this message
Jamu Kakar (jkakar) wrote :

This looks fine to me, but comments would help explain some of the trickery going on, +1!

review: Approve
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Like Jamu, I think this is fine to go, perhaps a timeline explaining what we do in each "problem" case might clarify the intent?

review: Approve
296. By Thomas Herve

Add comments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/monitor/networkactivity.py'
2--- landscape/monitor/networkactivity.py 2010-08-30 14:06:39 +0000
3+++ landscape/monitor/networkactivity.py 2010-09-20 15:08:45 +0000
4@@ -28,7 +28,8 @@
5 # our last traffic sample for calculating a traffic delta
6 self._last_activity = {}
7 self._create_time = create_time
8- self._rollover_maxint = pow(2, 64) if is_64() else pow(2, 32)
9+ # We don't rollover on 64 bits, as 16 exabytes is a lot.
10+ self._rollover_maxint = 0 if is_64() else pow(2, 32)
11
12 def register(self, registry):
13 super(NetworkActivity, self).register(registry)
14@@ -65,16 +66,22 @@
15 previous_out, previous_in = self._last_activity[interface]
16 delta_out = traffic["send_bytes"] - previous_out
17 delta_in = traffic["recv_bytes"] - previous_in
18- if not delta_out and not delta_in:
19- continue
20 if delta_out < 0:
21 delta_out += self._rollover_maxint
22 if delta_in < 0:
23 delta_in += self._rollover_maxint
24+ # If it's still zero or less, we discard the value. The next
25+ # value will be compared to the current traffic, and
26+ # hopefully things will catch up.
27+ if delta_out <= 0 and delta_in <= 0:
28+ continue
29
30 yield interface, delta_out, delta_in
31 self._last_activity[interface] = (
32 traffic["send_bytes"], traffic["recv_bytes"])
33+ for interface in self._last_activity.keys():
34+ if interface not in new_traffic:
35+ del self._last_activity[interface]
36
37 def run(self):
38 """
39
40=== modified file 'landscape/monitor/tests/test_networkactivity.py'
41--- landscape/monitor/tests/test_networkactivity.py 2010-08-30 14:06:39 +0000
42+++ landscape/monitor/tests/test_networkactivity.py 2010-09-20 15:08:45 +0000
43@@ -20,8 +20,8 @@
44 self.activity_file = open(self.makeFile(), "w+")
45 self.write_activity()
46 self.plugin = NetworkActivity(
47- network_activity_file = self.activity_file.name,
48- create_time = self.reactor.time)
49+ network_activity_file=self.activity_file.name,
50+ create_time=self.reactor.time)
51 self.monitor.add(self.plugin)
52
53 def tearDown(self):
54@@ -38,6 +38,7 @@
55 eth0_in = eth0_in,
56 eth0_out = eth0_out,
57 extra=extra))
58+ self.activity_file.seek(0, 0)
59 self.activity_file.truncate()
60 self.activity_file.write(self.stats_template % kw)
61 self.activity_file.flush()
62@@ -50,7 +51,7 @@
63 that messages are in the expected format and contain data with
64 expected datatypes.
65 """
66- plugin = NetworkActivity(create_time = self.reactor.time)
67+ plugin = NetworkActivity(create_time=self.reactor.time)
68 self.monitor.add(plugin)
69 plugin.run()
70 self.reactor.advance(self.monitor.step_size)
71@@ -128,7 +129,7 @@
72 def test_interface_temporarily_disappears(self):
73 """
74 When an interface is removed (ie usb hotplug) and then activated again
75- its delta will be retained.
76+ its delta will not be retained, because the values may have been reset.
77 """
78 self.write_activity(extra="wlan0: 2222 0 0 0 2222 0 0 0 0")
79 self.plugin.run()
80@@ -137,11 +138,11 @@
81 self.plugin.run()
82 message = self.plugin.create_message()
83 self.assertFalse(message)
84- self.write_activity(extra="wlan0: 3333 0 0 0 3333 0 0 0 0")
85+ self.write_activity(extra="wlan0: 1000 0 0 0 1000 0 0 0 0")
86 self.reactor.advance(self.monitor.step_size)
87 self.plugin.run()
88 message = self.plugin.create_message()
89- self.assertTrue(message)
90+ self.assertFalse(message)
91
92 def test_messaging_flushes(self):
93 """

Subscribers

People subscribed via source and target branches

to all changes: