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

Proposed by Steffen Allner
Status: Merged
Approved by: Eric Snow
Approved revision: 990
Merged at revision: 989
Proposed branch: lp:~gocept/landscape-client/py3-monitor-computeruptime
Merge into: lp:~landscape/landscape-client/trunk
Prerequisite: lp:~gocept/landscape-client/py3-monitor-activeprocessinfo
Diff against target: 69 lines (+15/-8)
3 files modified
landscape/monitor/computeruptime.py (+9/-5)
landscape/monitor/tests/test_computeruptime.py (+5/-2)
py3_ready_tests (+1/-1)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-monitor-computeruptime
Reviewer Review Type Date Requested Status
Eric Snow (community) Approve
Michael Howitz (community) Approve
🤖 Landscape Builder test results Approve
Alberto Donato (community) Approve
Review via email: mp+321264@code.launchpad.net

Commit message

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

It is strictly bytes/unicode fixes.

Description of the change

This MP ensures that the values gathered from wtmp/utmp are properly decoded and encoded in the test setup.

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: 989
Branch: lp:~gocept/landscape-client/py3-monitor-computeruptime
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3812/

review: Approve (test results)
Revision history for this message
Alberto Donato (ack) wrote :

+1

review: Approve
990. By Steffen Allner

Make LoginInfo._strip_and_decode() a non-static method.

Revision history for this message
Steffen Allner (sallner) wrote :

I switched to a non static method.

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: 990
Branch: lp:~gocept/landscape-client/py3-monitor-computeruptime
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3813/

review: Approve (test results)
Revision history for this message
Michael Howitz (mh-gocept) wrote :

LGTM.

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/computeruptime.py'
2--- landscape/monitor/computeruptime.py 2017-03-10 12:11:58 +0000
3+++ landscape/monitor/computeruptime.py 2017-03-29 11:21:20 +0000
4@@ -32,10 +32,10 @@
5 info = struct.unpack(self.RAW_FORMAT, raw_data)
6 self.login_type = info[0]
7 self.pid = info[1]
8- self.tty_device = info[2].strip("\0")
9- self.id = info[3].strip("\0")
10- self.username = info[4].strip("\0")
11- self.hostname = info[5].strip("\0")
12+ self.tty_device = self._strip_and_decode(info[2])
13+ self.id = self._strip_and_decode(info[3])
14+ self.username = self._strip_and_decode(info[4])
15+ self.hostname = self._strip_and_decode(info[5])
16 self.termination_status = info[6]
17 self.exit_status = info[7]
18 self.session_id = info[8]
19@@ -43,6 +43,10 @@
20 # FIXME Convert this to a dotted decimal string. -jk
21 self.remote_ip_address = info[11]
22
23+ def _strip_and_decode(self, bytestring):
24+ """Helper method to strip b"\0" and return a utf-8 decoded string."""
25+ return bytestring.strip(b"\0").decode("utf-8")
26+
27
28 class LoginInfoReader(object):
29 """Reader parses C{/var/log/wtmp} and/or C{/var/run/utmp} files.
30@@ -87,7 +91,7 @@
31 def get_times(self):
32 reboot_times = []
33 shutdown_times = []
34- with open(self._filename) as login_info_file:
35+ with open(self._filename, "rb") as login_info_file:
36 reader = LoginInfoReader(login_info_file)
37 self._last_boot = self._boots_newer_than
38 self._last_shutdown = self._shutdowns_newer_than
39
40=== modified file 'landscape/monitor/tests/test_computeruptime.py'
41--- landscape/monitor/tests/test_computeruptime.py 2016-06-15 16:45:39 +0000
42+++ landscape/monitor/tests/test_computeruptime.py 2017-03-29 11:21:20 +0000
43@@ -17,11 +17,14 @@
44 file = open(filename, "ab")
45 try:
46 file.write(struct.pack(LoginInfo.RAW_FORMAT, login_type, pid,
47- tty_device, id, username, hostname,
48+ tty_device.encode("utf-8"), id.encode("utf-8"),
49+ username.encode("utf-8"),
50+ hostname.encode("utf-8"),
51 termination_status, exit_status, session_id,
52 entry_time_seconds, entry_time_milliseconds,
53 remote_ip_address[0], remote_ip_address[1],
54- remote_ip_address[2], remote_ip_address[3], ""))
55+ remote_ip_address[2], remote_ip_address[3],
56+ b""))
57 finally:
58 file.close()
59
60
61=== modified file 'py3_ready_tests'
62--- py3_ready_tests 2017-03-29 11:21:20 +0000
63+++ py3_ready_tests 2017-03-29 11:21:20 +0000
64@@ -8,7 +8,7 @@
65
66
67 landscape.monitor.tests.test_activeprocessinfo
68-
69+landscape.monitor.tests.test_computeruptime
70
71
72

Subscribers

People subscribed via source and target branches

to all changes: