Merge lp:~free.ekanayaka/landscape-client/py3-registration into lp:~landscape/landscape-client/trunk

Proposed by Free Ekanayaka
Status: Merged
Approved by: Eric Snow
Approved revision: 1004
Merged at revision: 1006
Proposed branch: lp:~free.ekanayaka/landscape-client/py3-registration
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 157 lines (+36/-16)
6 files modified
landscape/broker/exchange.py (+13/-0)
landscape/broker/transport.py (+10/-1)
landscape/lib/bpickle.py (+6/-11)
landscape/lib/tests/test_bpickle.py (+4/-0)
landscape/monitor/tests/test_networkactivity.py (+2/-2)
root-client.conf (+1/-2)
To merge this branch: bzr merge lp:~free.ekanayaka/landscape-client/py3-registration
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Approve
Simon Poirier (community) Approve
Eric Snow (community) Approve
Review via email: mp+321986@code.launchpad.net

Commit message

Adjust wire-to-language type conversions in order to have Landscape registration work.

Description of the change

Adjust wire-to-language type conversions in order to have Landscape registration work.

Testing:

# spawn a local advice dog
sudo ./scripts/landscape-client -c root-client.conf

Accept the pending computer and see that it reports a few basic things (e.g. the Ubuntu version).

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 :
review: Needs Fixing (test results)
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: Fail
Revno: 1001
Branch: lp:~free.ekanayaka/landscape-client/py3-registration
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3844/

review: Needs Fixing (test results)
Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

Other than a few minor points, LGTM. The code is correct, but it would be nice if there were a bit less ambiguity about the wire format (e.g. dict keys, exchange payload). However, I realize that we are coping with Python 3 clients dealing with Python 2 servers, so I'm not going to stress over it too much.

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

FYI, I was able to follow the testing instructions successfully. I was also able to run a script.

1002. By Free Ekanayaka

Fix failing test

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: 1002
Branch: lp:~free.ekanayaka/landscape-client/py3-registration
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3845/

review: Approve (test results)
Revision history for this message
Free Ekanayaka (free.ekanayaka) :
1003. By Free Ekanayaka

Address review comments

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: 1003
Branch: lp:~free.ekanayaka/landscape-client/py3-registration
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3846/

review: Approve (test results)
Revision history for this message
Simon Poirier (simpoir) wrote :

+1 looks good and tested successfully. See minor things to address inline

review: Approve
1004. By Free Ekanayaka

Address review comments

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: 1004
Branch: lp:~free.ekanayaka/landscape-client/py3-registration
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3848/

review: Approve (test results)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/broker/exchange.py'
2--- landscape/broker/exchange.py 2017-03-23 10:13:55 +0000
3+++ landscape/broker/exchange.py 2017-04-06 14:56:21 +0000
4@@ -347,6 +347,7 @@
5 from landscape.lib.hashlib import md5
6
7 from twisted.internet.defer import Deferred, succeed
8+from twisted.python.compat import _PY3
9
10 from landscape.lib.fetch import HTTPCodeError, PyCurlError
11 from landscape.lib.message import got_next_expected, ANCIENT
12@@ -773,6 +774,12 @@
13 # be 3.2, because it's the one that didn't have this field.
14 server_api = result.get("server-api", b"3.2")
15
16+ if _PY3 and not isinstance(server_api, bytes):
17+ # The "server-api" field in the bpickle payload sent by the server
18+ # is a string, however in Python 3 we need to convert it to bytes,
19+ # since that's what the rest of the code expects.
20+ server_api = server_api.encode()
21+
22 if is_version_higher(server_api, message_store.get_server_api()):
23 # The server can handle a message API that is higher than the one
24 # we're currently using. If the highest server API is greater than
25@@ -787,6 +794,12 @@
26
27 sequence = message_store.get_server_sequence()
28 for message in result.get("messages", ()):
29+ # The wire format of the 'type' field is bytes, but our handlers
30+ # actually expect it to be a string. Some unit tests set it to
31+ # a regular string (since there is no difference between strings
32+ # and bytes in Python 2), so we check the type before converting.
33+ if _PY3 and isinstance(message["type"], bytes):
34+ message["type"] = message["type"].decode("ascii")
35 self.handle_message(message)
36 sequence += 1
37 message_store.set_server_sequence(sequence)
38
39=== modified file 'landscape/broker/transport.py'
40--- landscape/broker/transport.py 2017-03-17 09:26:45 +0000
41+++ landscape/broker/transport.py 2017-04-06 14:56:21 +0000
42@@ -6,7 +6,7 @@
43
44 import pycurl
45
46-from twisted.python.compat import unicode
47+from twisted.python.compat import unicode, _PY3
48
49 from landscape.lib import bpickle
50 from landscape.lib.fetch import fetch
51@@ -35,12 +35,21 @@
52 self._url = url
53
54 def _curl(self, payload, computer_id, exchange_token, message_api):
55+ # There are a few "if _PY3" checks below, because for Python 3 we
56+ # want to convert a number of values from bytes to string, before
57+ # assigning them to the headers.
58+ if _PY3 and isinstance(message_api, bytes):
59+ message_api = message_api.decode("ascii")
60 headers = {"X-Message-API": message_api,
61 "User-Agent": "landscape-client/%s" % VERSION,
62 "Content-Type": "application/octet-stream"}
63 if computer_id:
64+ if _PY3 and isinstance(computer_id, bytes):
65+ computer_id = computer_id.decode("ascii")
66 headers["X-Computer-ID"] = computer_id
67 if exchange_token:
68+ if _PY3 and isinstance(exchange_token, bytes):
69+ exchange_token = exchange_token.decode("ascii")
70 headers["X-Exchange-Token"] = str(exchange_token)
71 curl = pycurl.Curl()
72 return (curl, fetch(self._url, post=True, data=payload,
73
74=== modified file 'landscape/lib/bpickle.py'
75--- landscape/lib/bpickle.py 2017-04-05 14:19:27 +0000
76+++ landscape/lib/bpickle.py 2017-04-06 14:56:21 +0000
77@@ -32,7 +32,7 @@
78 wire compatible and behave the same way (bugs notwithstanding).
79 """
80
81-import logging
82+from twisted.python.compat import _PY3
83
84 dumps_table = {}
85 loads_table = {}
86@@ -94,11 +94,6 @@
87 append = res.append
88 for key in keys:
89 val = obj[key]
90- if (bytes is not str) and isinstance(key, str):
91- try:
92- key.encode("ascii")
93- except UnicodeError as e:
94- logging.warning(e)
95 append(_dt[type(key)](key))
96 append(_dt[type(val)](val))
97 return b"d%s;" % b"".join(res)
98@@ -160,11 +155,11 @@
99 while bytestring[pos:pos+1] != b";":
100 key, pos = _lt[bytestring[pos:pos+1]](bytestring, pos)
101 val, pos = _lt[bytestring[pos:pos+1]](bytestring, pos)
102- if (bytes is not str) and isinstance(key, bytes):
103- try:
104- key.decode("ascii")
105- except UnicodeError as e:
106- logging.warning(e)
107+ if _PY3 and isinstance(key, bytes):
108+ # Although the wire format of dictionary keys is ASCII bytes, the
109+ # code actually expects them to be strings, so we convert them
110+ # here.
111+ key = key.decode("ascii")
112 res[key] = val
113 return res, pos+1
114
115
116=== modified file 'landscape/lib/tests/test_bpickle.py'
117--- landscape/lib/tests/test_bpickle.py 2017-03-17 09:26:45 +0000
118+++ landscape/lib/tests/test_bpickle.py 2017-04-06 14:56:21 +0000
119@@ -45,6 +45,10 @@
120 self.assertEqual(bpickle.loads(dumped_tobool),
121 {True: False})
122
123+ def test_dict_bytes_keys(self):
124+ data = bpickle.dumps({b"hello": True})
125+ self.assertEqual(bpickle.loads(data), {"hello": True})
126+
127 def test_long(self):
128 long = 99999999999999999999999999999
129 self.assertEqual(bpickle.loads(bpickle.dumps(long)), long)
130
131=== modified file 'landscape/monitor/tests/test_networkactivity.py'
132--- landscape/monitor/tests/test_networkactivity.py 2017-03-30 07:43:32 +0000
133+++ landscape/monitor/tests/test_networkactivity.py 2017-04-06 14:56:21 +0000
134@@ -184,8 +184,8 @@
135 self.assertMessages(self.mstore.get_pending_messages(),
136 [{"type": "network-activity",
137 "activities": {
138- b"lo": [(step_size, 0, 1000)],
139- b"eth0": [(step_size, 0, 1000)]}}])
140+ "lo": [(step_size, 0, 1000)],
141+ "eth0": [(step_size, 0, 1000)]}}])
142
143 def test_config(self):
144 """The network activity plugin is enabled by default."""
145
146=== modified file 'root-client.conf'
147--- root-client.conf 2013-03-21 12:46:40 +0000
148+++ root-client.conf 2017-04-06 14:56:21 +0000
149@@ -9,7 +9,6 @@
150 log_dir = /tmp/landscape-root
151 log_level = debug
152 pid_file = /tmp/landscape-root/landscape-client.pid
153-ping_url = http://localhost:8081/ping
154+ping_url = http://localhost:8080/ping
155 include_manager_plugins = ScriptExecution
156 script_users = www-data, nobody, root
157-

Subscribers

People subscribed via source and target branches

to all changes: