Merge lp:~gocept/landscape-client/py3-broker-exchange into lp:~landscape/landscape-client/trunk

Proposed by Steffen Allner
Status: Merged
Approved by: Eric Snow
Approved revision: 975
Merged at revision: 977
Proposed branch: lp:~gocept/landscape-client/py3-broker-exchange
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 216 lines (+49/-47)
4 files modified
landscape/broker/exchange.py (+1/-1)
landscape/broker/tests/test_exchange.py (+44/-44)
landscape/tests/helpers.py (+3/-0)
py3_ready_tests (+1/-2)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-broker-exchange
Reviewer Review Type Date Requested Status
Eric Snow (community) Approve
🤖 Landscape Builder test results Approve
Daniel Havlik (community) Approve
Adam Collard (community) Approve
Review via email: mp+320782@code.launchpad.net

Commit message

Port landscape/broker/exchange.py to Python 3.

This mostly involved bytes/unicode fixes.

This patch also switches to using Unittest.assertCouldEqual (from assertItemsEqual).

Description of the change

As the diff for the landscape.broker module would be to large, I MP the submodules separately.

Here we have landscape.broker.exchange, where the tests were failing because bytes were not uses as input when required by a schema ("api") and the fact that digests were attempted on unicodes.

Additionally, I needed assertCountEqual to adjust the a test for non-deterministic sets in Python 3 so I added an alias to LandscapeTest.

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 check
Result: Success
Revno: 973
Branch: lp:~gocept/landscape-client/py3-broker-exchange
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3713/

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

Looks good, one suggestion in-line for a small clean-up. +1

review: Approve
Revision history for this message
Daniel Havlik (nilo) wrote :

+1

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

It seems not to be so easy, see inline comment.

Revision history for this message
Adam Collard (adam-collard) wrote :

Reply to inline comment with fixed code.

974. By Steffen Allner

Directly use an alias instead of a wrapping method.

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

Pushed a new revision to reduce code.

975. By Steffen Allner

Backmerge from trunk

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 check
Result: Success
Revno: 975
Branch: lp:~gocept/landscape-client/py3-broker-exchange
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3783/

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

LGTM

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

> LGTM

Thanks for reviewing. Danilo used to adapt the commit message to a way that suites your needs in the landscape project, and then starts the merging process. I would be happy, if we could keep it like that, as I am still quite unfamiliar with launchpad an the workflow.

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-21 13:00:17 +0000
3+++ landscape/broker/exchange.py 2017-03-27 06:59:04 +0000
4@@ -715,7 +715,7 @@
5 return payload
6
7 def _hash_types(self, types):
8- accepted_types_str = ";".join(types)
9+ accepted_types_str = ";".join(types).encode("ascii")
10 return md5(accepted_types_str).digest()
11
12 def _handle_result(self, payload, result):
13
14=== modified file 'landscape/broker/tests/test_exchange.py'
15--- landscape/broker/tests/test_exchange.py 2016-06-15 17:33:13 +0000
16+++ landscape/broker/tests/test_exchange.py 2017-03-27 06:59:04 +0000
17@@ -104,7 +104,7 @@
18 messages = self.transport.payloads[0]["messages"]
19 self.assertEqual(messages, [{"type": "empty",
20 "timestamp": 0,
21- "api": "3.2"}])
22+ "api": b"3.2"}])
23
24 def test_send_urgent(self):
25 """
26@@ -149,7 +149,7 @@
27 """
28 payload = self.exchanger._make_payload()
29 self.assertIn("accepted-types", payload)
30- self.assertEqual(payload["accepted-types"], md5("").digest())
31+ self.assertEqual(payload["accepted-types"], md5(b"").digest())
32
33 def test_handle_message_sets_accepted_types(self):
34 """
35@@ -170,8 +170,8 @@
36 {"type": "accepted-types", "types": ["a", "b"]})
37 self.exchanger.handle_message(
38 {"type": "accepted-types", "types": ["b", "c"]})
39- self.assertEqual(stash, [("a", True), ("b", True),
40- ("a", False), ("c", True)])
41+ self.assertCountEqual(stash, [("a", True), ("b", True),
42+ ("a", False), ("c", True)])
43
44 def test_wb_accepted_types_roundtrip(self):
45 """
46@@ -183,7 +183,7 @@
47 payload = self.exchanger._make_payload()
48 self.assertIn("accepted-types", payload)
49 self.assertEqual(payload["accepted-types"],
50- md5("ack;bar").digest())
51+ md5(b"ack;bar").digest())
52
53 def test_accepted_types_causes_urgent_if_held_messages_exist(self):
54 """
55@@ -523,33 +523,33 @@
56 payload = self.transport.payloads[-1]
57 self.assertMessages(payload["messages"], [])
58 self.assertEqual(payload.get("client-api"), CLIENT_API)
59- self.assertEqual(payload.get("server-api"), "3.2")
60- self.assertEqual(self.transport.message_api, "3.2")
61-
62- self.mstore.add({"type": "a", "api": "1.0"})
63- self.mstore.add({"type": "b", "api": "1.0"})
64- self.mstore.add({"type": "c", "api": "1.1"})
65- self.mstore.add({"type": "d", "api": "1.1"})
66-
67- self.exchanger.exchange()
68-
69- payload = self.transport.payloads[-1]
70- self.assertMessages(payload["messages"],
71- [{"type": "a", "api": "1.0"},
72- {"type": "b", "api": "1.0"}])
73- self.assertEqual(payload.get("client-api"), CLIENT_API)
74- self.assertEqual(payload.get("server-api"), "1.0")
75- self.assertEqual(self.transport.message_api, "1.0")
76-
77- self.exchanger.exchange()
78-
79- payload = self.transport.payloads[-1]
80- self.assertMessages(payload["messages"],
81- [{"type": "c", "api": "1.1"},
82- {"type": "d", "api": "1.1"}])
83- self.assertEqual(payload.get("client-api"), CLIENT_API)
84- self.assertEqual(payload.get("server-api"), "1.1")
85- self.assertEqual(self.transport.message_api, "1.1")
86+ self.assertEqual(payload.get("server-api"), b"3.2")
87+ self.assertEqual(self.transport.message_api, b"3.2")
88+
89+ self.mstore.add({"type": "a", "api": b"1.0"})
90+ self.mstore.add({"type": "b", "api": b"1.0"})
91+ self.mstore.add({"type": "c", "api": b"1.1"})
92+ self.mstore.add({"type": "d", "api": b"1.1"})
93+
94+ self.exchanger.exchange()
95+
96+ payload = self.transport.payloads[-1]
97+ self.assertMessages(payload["messages"],
98+ [{"type": "a", "api": b"1.0"},
99+ {"type": "b", "api": b"1.0"}])
100+ self.assertEqual(payload.get("client-api"), CLIENT_API)
101+ self.assertEqual(payload.get("server-api"), b"1.0")
102+ self.assertEqual(self.transport.message_api, b"1.0")
103+
104+ self.exchanger.exchange()
105+
106+ payload = self.transport.payloads[-1]
107+ self.assertMessages(payload["messages"],
108+ [{"type": "c", "api": b"1.1"},
109+ {"type": "d", "api": b"1.1"}])
110+ self.assertEqual(payload.get("client-api"), CLIENT_API)
111+ self.assertEqual(payload.get("server-api"), b"1.1")
112+ self.assertEqual(self.transport.message_api, b"1.1")
113
114 def test_exchange_token(self):
115 """
116@@ -827,27 +827,27 @@
117 """
118 self.transport.extra.pop("server-api", None)
119 self.exchanger.exchange()
120- self.assertEqual("3.2", self.mstore.get_server_api())
121+ self.assertEqual(b"3.2", self.mstore.get_server_api())
122
123 def test_wb_client_with_older_api_and_server_with_newer(self):
124 """
125 If a server notifies us that it case use a very new API, but we
126 don't know how to speak it, we keep using ours.
127 """
128- self.exchanger._api = "3.3"
129- self.transport.extra["server-api"] = "3.4"
130+ self.exchanger._api = b"3.3"
131+ self.transport.extra["server-api"] = b"3.4"
132 self.exchanger.exchange()
133- self.assertEqual("3.3", self.mstore.get_server_api())
134+ self.assertEqual(b"3.3", self.mstore.get_server_api())
135
136 def test_wb_client_with_newer_api_and_server_with_older(self):
137 """
138 If a server notifies us that it can use an API which is older
139 than the one we support, we'll just use the server API.
140 """
141- self.exchanger._api = "3.4"
142- self.transport.extra["server-api"] = "3.3"
143+ self.exchanger._api = b"3.4"
144+ self.transport.extra["server-api"] = b"3.3"
145 self.exchanger.exchange()
146- self.assertEqual("3.3", self.mstore.get_server_api())
147+ self.assertEqual(b"3.3", self.mstore.get_server_api())
148
149 def test_server_uuid_is_stored_on_message_store(self):
150 self.transport.extra["server-uuid"] = "first-uuid"
151@@ -1078,10 +1078,10 @@
152 """
153 If we get a 404, we try to donwgrade our server API version.
154 """
155- self.mstore.set_server_api("3.3")
156+ self.mstore.set_server_api(b"3.3")
157 self.transport.responses.append(HTTPCodeError(404, ""))
158 self.exchanger.exchange()
159- self.assertEqual("3.2", self.mstore.get_server_api())
160+ self.assertEqual(b"3.2", self.mstore.get_server_api())
161
162
163 class AcceptedTypesMessageExchangeTest(LandscapeTest):
164@@ -1120,7 +1120,7 @@
165 self.exchanger.register_client_accepted_message_type("type-A")
166 self.exchanger.register_client_accepted_message_type("type-B")
167 types = sorted(["type-A", "type-B"] + DEFAULT_ACCEPTED_TYPES)
168- accepted_types_digest = md5(";".join(types)).digest()
169+ accepted_types_digest = md5(";".join(types).encode("ascii")).digest()
170 self.transport.extra["client-accepted-types-hash"] = \
171 accepted_types_digest
172 self.exchanger.exchange()
173@@ -1146,7 +1146,7 @@
174 client will send a new list to the server.
175 """
176 self.exchanger.register_client_accepted_message_type("type-A")
177- types_hash = md5("type-A").digest()
178+ types_hash = md5(b"type-A").digest()
179 self.transport.extra["client-accepted-types-hash"] = types_hash
180 self.exchanger.exchange()
181 self.exchanger.register_client_accepted_message_type("type-B")
182@@ -1162,7 +1162,7 @@
183 send a new list of types.
184 """
185 self.exchanger.register_client_accepted_message_type("type-A")
186- types_hash = md5("type-A").digest()
187+ types_hash = md5(b"type-A").digest()
188 self.transport.extra["client-accepted-types-hash"] = types_hash
189 self.exchanger.exchange()
190 self.transport.extra["client-accepted-types-hash"] = "lol"
191
192=== modified file 'landscape/tests/helpers.py'
193--- landscape/tests/helpers.py 2017-03-21 17:57:12 +0000
194+++ landscape/tests/helpers.py 2017-03-27 06:59:04 +0000
195@@ -148,6 +148,9 @@
196 else:
197 return result[0]
198
199+ if not _PY3:
200+ assertCountEqual = TestCase.assertItemsEqual
201+
202 def assertNoResult(self, deferred):
203 """See C{twisted.trial._synctest._Assertions.assertNoResult}.
204
205
206=== modified file 'py3_ready_tests'
207--- py3_ready_tests 2017-03-23 14:26:11 +0000
208+++ py3_ready_tests 2017-03-27 06:59:04 +0000
209@@ -9,6 +9,5 @@
210
211
212
213-
214-
215+landscape.broker.tests.test_exchange
216 landscape.broker.tests.test_store

Subscribers

People subscribed via source and target branches

to all changes: