Merge lp:~gocept/landscape-client/py3-monitor-networkactivity into lp:~landscape/landscape-client/trunk

Proposed by Steffen Allner
Status: Merged
Approved by: Eric Snow
Approved revision: 996
Merged at revision: 993
Proposed branch: lp:~gocept/landscape-client/py3-monitor-networkactivity
Merge into: lp:~landscape/landscape-client/trunk
Prerequisite: lp:~gocept/landscape-client/py3-monitor-networkdevice
Diff against target: 77 lines (+17/-8)
3 files modified
landscape/monitor/networkactivity.py (+8/-1)
landscape/monitor/tests/test_networkactivity.py (+8/-6)
py3_ready_tests (+1/-1)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-monitor-networkactivity
Reviewer Review Type Date Requested Status
Eric Snow (community) Approve
Daniel Havlik (community) Approve
Adam Collard (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+321414@code.launchpad.net

Commit message

This is the Py3 port of landscape.monitor.networkactivity.

This fixes some bytes/unicode issues as well as dict mutation while iterating.

Description of the change

This MP considers the landscape.monitor.networkactivity module.

Fixes are an iteration over a dictview while the dict can potentially change.

Furthermore, the wire protocol requires the interface name to be bytes.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: TRIAL_ARGS=-j4 make ci-check
Result: Success
Revno: 996
Branch: lp:~gocept/landscape-client/py3-monitor-networkactivity
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3819/

review: Approve (test results)
Revision history for this message
Adam Collard (adam-collard) :
review: Approve
Revision history for this message
Daniel Havlik (nilo) wrote :

+1

review: Approve
Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

LGTM

review: Approve

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 2013-07-05 12:52:40 +0000
3+++ landscape/monitor/networkactivity.py 2017-03-30 07:47:52 +0000
4@@ -46,6 +46,10 @@
5 items = 0
6 for interface, data in list(self._network_activity.items()):
7 if data:
8+ # The message schema requires the interface to be bytes, so we
9+ # encode it here right before the message is created as it is
10+ # used as string in other places.
11+ interface = interface.encode("ascii")
12 network_activity[interface] = []
13 while data and items < self.max_network_items_to_exchange:
14 item = data.pop(0)
15@@ -94,7 +98,10 @@
16 yield interface, delta_out, delta_in
17 self._last_activity[interface] = (
18 traffic["send_bytes"], traffic["recv_bytes"])
19- for interface in self._last_activity.keys():
20+
21+ # We need cast the keys to a list as the size of the dictionary changes
22+ # on delete and the .keys() generator throws an error.
23+ for interface in list(self._last_activity.keys()):
24 if interface not in new_traffic:
25 del self._last_activity[interface]
26
27
28=== modified file 'landscape/monitor/tests/test_networkactivity.py'
29--- landscape/monitor/tests/test_networkactivity.py 2011-07-05 05:09:11 +0000
30+++ landscape/monitor/tests/test_networkactivity.py 2017-03-30 07:47:52 +0000
31@@ -79,9 +79,10 @@
32 self.assertTrue(message)
33 self.assertTrue("type" in message)
34 self.assertEqual(message["type"], "network-activity")
35- self.assertEqual(message["activities"]["lo"],
36+ self.assertEqual(message["activities"][b"lo"],
37 [(300, 10, 99)])
38- self.assertNotIn("eth0", message["activities"])
39+ # Ensure that b"eth0" is not in activities
40+ self.assertEqual(len(message["activities"]), 1)
41
42 def test_proc_rollover(self):
43 """
44@@ -98,9 +99,10 @@
45 self.assertTrue(message)
46 self.assertTrue("type" in message)
47 self.assertEqual(message["type"], "network-activity")
48- self.assertEqual(message["activities"]["lo"],
49+ self.assertEqual(message["activities"][b"lo"],
50 [(300, 9010, 9099)])
51- self.assertNotIn("eth0", message["activities"])
52+ # Ensure that b"eth0" is not in activities
53+ self.assertEqual(len(message["activities"]), 1)
54
55 def test_no_message_without_traffic_delta(self):
56 """
57@@ -182,8 +184,8 @@
58 self.assertMessages(self.mstore.get_pending_messages(),
59 [{"type": "network-activity",
60 "activities": {
61- "lo": [(step_size, 0, 1000)],
62- "eth0": [(step_size, 0, 1000)]}}])
63+ b"lo": [(step_size, 0, 1000)],
64+ b"eth0": [(step_size, 0, 1000)]}}])
65
66 def test_config(self):
67 """The network activity plugin is enabled by default."""
68
69=== modified file 'py3_ready_tests'
70--- py3_ready_tests 2017-03-30 07:47:52 +0000
71+++ py3_ready_tests 2017-03-30 07:47:52 +0000
72@@ -13,4 +13,4 @@
73 landscape.monitor.tests.test_computerinfo
74 landscape.monitor.tests.test_loadaverage
75 landscape.monitor.tests.test_networkdevice
76-
77+landscape.monitor.tests.test_networkactivity

Subscribers

People subscribed via source and target branches

to all changes: