Merge lp:~gocept/landscape-client/py3-manager-customgraph into lp:~landscape/landscape-client/trunk

Proposed by Steffen Allner
Status: Superseded
Proposed branch: lp:~gocept/landscape-client/py3-manager-customgraph
Merge into: lp:~landscape/landscape-client/trunk
Prerequisite: lp:~gocept/landscape-client/py3-broker-ping
Diff against target: 378 lines (+63/-58)
5 files modified
landscape/lib/scriptcontent.py (+4/-2)
landscape/lib/tests/test_scriptcontent.py (+2/-3)
landscape/manager/customgraph.py (+2/-2)
landscape/manager/tests/test_customgraph.py (+48/-39)
py3_ready_tests (+7/-12)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-manager-customgraph
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Approve
Gocept Pending
Eric Snow Pending
Review via email: mp+321158@code.launchpad.net

Description of the change

This MP considers the landscape.manager.customgraph module, where the main change was the use of bytes as hashes, which is required by the message schema. md5().hexdigest() returns bytes in Py2 and unicode in Py3, so we have to encode on time with "ascii".

Other changes are minor and consider opening the script_file handler in binary mode as already changed in l.manager.scriptexecution. Furthermore, the generator result of range() does not support .pop() in Python 3.

To post a comment you must log in.
Revision history for this message
Steffen Allner (sallner) wrote :

We have to wait for other branches to land, as it is dependend on py3-broker-ping _and_ py3-manager-scriptexecution.

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: 985
Branch: lp:~gocept/landscape-client/py3-manager-customgraph
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3803/

review: Approve (test results)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/lib/scriptcontent.py'
2--- landscape/lib/scriptcontent.py 2017-03-13 07:48:18 +0000
3+++ landscape/lib/scriptcontent.py 2017-03-29 07:05:08 +0000
4@@ -12,5 +12,7 @@
5 """
6 Return a hash for a given script.
7 """
8- encoded_script = script.encode('utf-8')
9- return md5(encoded_script).hexdigest()
10+ encoded_script = script.encode("utf-8")
11+ # As this hash is sent in message which requires bytes in the schema, we
12+ # have to encode here.
13+ return md5(encoded_script).hexdigest().encode("ascii")
14
15=== modified file 'landscape/lib/tests/test_scriptcontent.py'
16--- landscape/lib/tests/test_scriptcontent.py 2011-07-05 05:09:11 +0000
17+++ landscape/lib/tests/test_scriptcontent.py 2017-03-29 07:05:08 +0000
18@@ -1,7 +1,6 @@
19 import unittest
20
21-from landscape.lib.scriptcontent import (build_script,
22- generate_script_hash)
23+from landscape.lib.scriptcontent import (build_script, generate_script_hash)
24
25
26 class ScriptContentTest(unittest.TestCase):
27@@ -21,4 +20,4 @@
28
29 self.assertEqual(hash1, hash2)
30 self.assertNotEqual(hash1, hash3)
31- self.assertTrue(isinstance(hash1, str))
32+ self.assertTrue(isinstance(hash1, bytes))
33
34=== modified file 'landscape/manager/customgraph.py'
35--- landscape/manager/customgraph.py 2017-01-23 12:14:33 +0000
36+++ landscape/manager/customgraph.py 2017-03-29 07:05:08 +0000
37@@ -131,7 +131,7 @@
38 logging.error(u"Attempt to add graph with unknown user %s" %
39 user)
40 else:
41- script_file = open(filename, "w")
42+ script_file = open(filename, "wb")
43 # file is closed in write_script_file
44 self.write_script_file(
45 script_file, filename, shell, code, uid, gid)
46@@ -229,7 +229,7 @@
47 if os.path.isfile(filename):
48 script_hash = self._get_script_hash(filename)
49 else:
50- script_hash = ""
51+ script_hash = b""
52 if graph_id not in self._data:
53 self._data[graph_id] = {
54 "values": [], "error": u"", "script-hash": script_hash}
55
56=== modified file 'landscape/manager/tests/test_customgraph.py'
57--- landscape/manager/tests/test_customgraph.py 2017-01-10 14:33:40 +0000
58+++ landscape/manager/tests/test_customgraph.py 2017-03-29 07:05:08 +0000
59@@ -29,7 +29,7 @@
60 os.makedirs(os.path.join(self.data_path, "custom-graph-scripts"))
61 self.manager.config.script_users = "ALL"
62 self.graph_manager = CustomGraphPlugin(
63- create_time=range(1500, 0, -300).pop)
64+ create_time=list(range(1500, 0, -300)).pop)
65 self.manager.add(self.graph_manager)
66
67 def _exit_process_protocol(self, protocol, stdout):
68@@ -128,7 +128,7 @@
69
70 def check(ignore):
71 self.graph_manager.exchange()
72- script_hash = "483f2304b49063680c75e3c9e09cf6d0"
73+ script_hash = b"483f2304b49063680c75e3c9e09cf6d0"
74 self.assertMessages(
75 self.broker_service.message_store.get_pending_messages(),
76 [{"data": {123: {"error": u"",
77@@ -153,11 +153,11 @@
78 [{"data":
79 {123: {"error": u"",
80 "values": [(300, 1.0)],
81- "script-hash": "483f2304b49063680c75e3c9e09cf6d0"
82+ "script-hash": b"483f2304b49063680c75e3c9e09cf6d0"
83 },
84 124: {"error": u"",
85 "values": [(300, 2.0)],
86- "script-hash": "73a74b1530b2256db7edacb9b9cc385e"
87+ "script-hash": b"73a74b1530b2256db7edacb9b9cc385e"
88 }
89 },
90 "type": "custom-graph"}])
91@@ -175,7 +175,7 @@
92 [{"data":
93 {123: {"error": u" (process exited with code 1)",
94 "values": [],
95- "script-hash": "eaca3ba1a3bf1948876eba320148c5e9"
96+ "script-hash": b"eaca3ba1a3bf1948876eba320148c5e9"
97 }
98 },
99 "type": "custom-graph"}])
100@@ -192,7 +192,7 @@
101 spawn = factory.spawns[0]
102 self.assertEqual(spawn[1], filename)
103
104- self._exit_process_protocol(spawn[0], "foobar")
105+ self._exit_process_protocol(spawn[0], b"foobar")
106
107 def check(ignore):
108 self.graph_manager.exchange()
109@@ -203,7 +203,7 @@
110 u"InvalidFormatError: Failed to convert to "
111 "number: 'foobar'",
112 "values": [], "script-hash":
113- "baab6c16d9143523b7865d46896e4596"}},
114+ b"baab6c16d9143523b7865d46896e4596"}},
115 "type": "custom-graph"}])
116 return result.addCallback(check)
117
118@@ -218,7 +218,7 @@
119 spawn = factory.spawns[0]
120 self.assertEqual(spawn[1], filename)
121
122- self._exit_process_protocol(spawn[0], "")
123+ self._exit_process_protocol(spawn[0], b"")
124
125 def check(ignore):
126 self.graph_manager.exchange()
127@@ -228,7 +228,7 @@
128 {123: {"error": u"NoOutputError: Script did not output "
129 "any value",
130 "values": [], "script-hash":
131- "baab6c16d9143523b7865d46896e4596"}},
132+ b"baab6c16d9143523b7865d46896e4596"}},
133 "type": "custom-graph"}])
134 return result.addCallback(check)
135
136@@ -243,9 +243,9 @@
137
138 self.assertEqual(len(factory.spawns), 2)
139 spawn = factory.spawns[0]
140- self._exit_process_protocol(spawn[0], "")
141+ self._exit_process_protocol(spawn[0], b"")
142 spawn = factory.spawns[1]
143- self._exit_process_protocol(spawn[0], "0.5")
144+ self._exit_process_protocol(spawn[0], b"0.5")
145
146 def check(ignore):
147 self.graph_manager.exchange()
148@@ -254,10 +254,12 @@
149 [{"data":
150 {123: {"error": u"NoOutputError: Script did not output "
151 "any value",
152- "script-hash": "baab6c16d9143523b7865d46896e4596",
153+ "script-hash":
154+ b"baab6c16d9143523b7865d46896e4596",
155 "values": []},
156 124: {"error": u"",
157- "script-hash": "baab6c16d9143523b7865d46896e4596",
158+ "script-hash":
159+ b"baab6c16d9143523b7865d46896e4596",
160 "values": [(300, 0.5)]}},
161 "type": "custom-graph"}])
162 return result.addCallback(check)
163@@ -273,9 +275,9 @@
164
165 self.assertEqual(len(factory.spawns), 2)
166 spawn = factory.spawns[0]
167- self._exit_process_protocol(spawn[0], "foo")
168+ self._exit_process_protocol(spawn[0], b"foo")
169 spawn = factory.spawns[1]
170- self._exit_process_protocol(spawn[0], "")
171+ self._exit_process_protocol(spawn[0], b"")
172
173 def check(ignore):
174 self.graph_manager.exchange()
175@@ -284,11 +286,13 @@
176 [{"data":
177 {123: {"error": u"InvalidFormatError: Failed to convert "
178 "to number: 'foo'",
179- "script-hash": "baab6c16d9143523b7865d46896e4596",
180+ "script-hash":
181+ b"baab6c16d9143523b7865d46896e4596",
182 "values": []},
183 124: {"error": u"NoOutputError: Script did not output "
184 "any value",
185- "script-hash": "baab6c16d9143523b7865d46896e4596",
186+ "script-hash":
187+ b"baab6c16d9143523b7865d46896e4596",
188 "values": []}},
189 "type": "custom-graph"}])
190 return result.addCallback(check)
191@@ -319,7 +323,7 @@
192 self.assertEqual(spawn[6], 5678)
193 mock_getpwnam.assert_called_with("bar")
194
195- self._exit_process_protocol(spawn[0], "spam")
196+ self._exit_process_protocol(spawn[0], b"spam")
197
198 return result
199
200@@ -344,7 +348,7 @@
201 {"error":
202 u"ProhibitedUserError: Custom graph cannot be run as "
203 "user %s" % (username,),
204- "script-hash": "",
205+ "script-hash": b"",
206 "values": []}},
207 "type": "custom-graph"}])
208
209@@ -369,7 +373,7 @@
210 self.broker_service.message_store.get_pending_messages(),
211 [{"data": {123:
212 {"error": u"UnknownUserError: Unknown user 'foo'",
213- "script-hash": "",
214+ "script-hash": b"",
215 "values": []}},
216 "type": "custom-graph"}])
217 mock_getpwnam.assert_called_with("foo")
218@@ -399,7 +403,7 @@
219 [{"data": {123: {"error":
220 u"Process exceeded the 10 seconds limit",
221 "script-hash":
222- "9893532233caff98cd083a116b013c0b",
223+ b"9893532233caff98cd083a116b013c0b",
224 "values": []}},
225 "type": "custom-graph"}])
226
227@@ -420,7 +424,7 @@
228 self.graph_manager.exchange()
229 self.assertMessages(
230 self.broker_service.message_store.get_pending_messages(),
231- [{"data": {123: {"error": u"", "script-hash": "", "values": []}},
232+ [{"data": {123: {"error": u"", "script-hash": b"", "values": []}},
233 "type": "custom-graph"}])
234
235 def test_send_message_add_stored_graph(self):
236@@ -440,9 +444,10 @@
237 self.graph_manager.exchange()
238 self.assertMessages(
239 self.broker_service.message_store.get_pending_messages(),
240- [{"api": "3.2",
241+ [{"api": b"3.2",
242 "data": {123: {"error": u"",
243- "script-hash": "e00a2f44dbc7b6710ce32af2348aec9b",
244+ "script-hash":
245+ b"e00a2f44dbc7b6710ce32af2348aec9b",
246 "values": []}},
247 "timestamp": 0,
248 "type": "custom-graph"}])
249@@ -463,7 +468,7 @@
250 self.graph_manager.exchange()
251 self.assertMessages(
252 self.broker_service.message_store.get_pending_messages(),
253- [{"api": "3.2",
254+ [{"api": b"3.2",
255 "data": {},
256 "timestamp": 0,
257 "type": "custom-graph"}])
258@@ -488,15 +493,17 @@
259 self.graph_manager.exchange()
260 self.assertMessages(
261 self.broker_service.message_store.get_pending_messages(),
262- [{"api": "3.2",
263+ [{"api": b"3.2",
264 "data": {123: {"error": u"",
265- "script-hash": "e00a2f44dbc7b6710ce32af2348aec9b",
266+ "script-hash":
267+ b"e00a2f44dbc7b6710ce32af2348aec9b",
268 "values": []}},
269 "timestamp": 0,
270 "type": "custom-graph"},
271- {"api": "3.2",
272+ {"api": b"3.2",
273 "data": {123: {"error": u"",
274- "script-hash": "e00a2f44dbc7b6710ce32af2348aec9b",
275+ "script-hash":
276+ b"e00a2f44dbc7b6710ce32af2348aec9b",
277 "values": []}},
278 "timestamp": 0,
279 "type": "custom-graph"}])
280@@ -522,15 +529,17 @@
281 self.graph_manager.exchange()
282 self.assertMessages(
283 self.broker_service.message_store.get_pending_messages(),
284- [{"api": "3.2",
285+ [{"api": b"3.2",
286 "data": {123: {"error": u"",
287- "script-hash": "e00a2f44dbc7b6710ce32af2348aec9b",
288+ "script-hash":
289+ b"e00a2f44dbc7b6710ce32af2348aec9b",
290 "values": []}},
291 "timestamp": 0,
292 "type": "custom-graph"},
293- {"api": "3.2",
294+ {"api": b"3.2",
295 "data": {123: {"error": u"",
296- "script-hash": "d483816dc0fbb51ede42502a709b0e2a",
297+ "script-hash":
298+ b"d483816dc0fbb51ede42502a709b0e2a",
299 "values": []}},
300 "timestamp": 0,
301 "type": "custom-graph"}])
302@@ -565,16 +574,16 @@
303 "username": username,
304 "graph-id": 123})
305
306- self._exit_process_protocol(spawn[0], "1.0")
307+ self._exit_process_protocol(spawn[0], b"1.0")
308
309 def check(ignore):
310 self.graph_manager.exchange()
311 self.assertMessages(
312 self.broker_service.message_store.get_pending_messages(),
313- [{"api": "3.2",
314+ [{"api": b"3.2",
315 "data": {123: {"error": u"",
316 "script-hash":
317- "991e15a81929c79fe1d243b2afd99c62",
318+ b"991e15a81929c79fe1d243b2afd99c62",
319 "values": []}},
320 "timestamp": 0,
321 "type": "custom-graph"}])
322@@ -607,13 +616,13 @@
323 {"type": "custom-graph-remove",
324 "graph-id": 123})
325
326- self._exit_process_protocol(spawn[0], "1.0")
327+ self._exit_process_protocol(spawn[0], b"1.0")
328
329 def check(ignore):
330 self.graph_manager.exchange()
331 self.assertMessages(
332 self.broker_service.message_store.get_pending_messages(),
333- [{"api": "3.2", "data": {}, "timestamp": 0, "type":
334+ [{"api": b"3.2", "data": {}, "timestamp": 0, "type":
335 "custom-graph"}])
336 return result.addCallback(check)
337
338@@ -682,7 +691,7 @@
339 [{"data": {123:
340 {"error":
341 u"UnknownUserError: Unknown user '%s'" % username,
342- "script-hash": "9893532233caff98cd083a116b013c0b",
343+ "script-hash": b"9893532233caff98cd083a116b013c0b",
344 "values": []}},
345 "type": "custom-graph"}])
346
347
348=== modified file 'py3_ready_tests'
349--- py3_ready_tests 2017-03-28 22:58:59 +0000
350+++ py3_ready_tests 2017-03-29 07:05:08 +0000
351@@ -1,20 +1,15 @@
352 landscape.lib.tests
353 landscape.sysinfo.tests
354 landscape.user.tests
355+landscape.broker.tests
356+landscape.package.tests
357 landscape.tests.test_configuration
358 landscape.tests.test_watchdog
359-landscape.broker.tests.test_registration
360-landscape.broker.tests.test_amp
361-landscape.broker.tests.test_server
362-landscape.package.tests
363-
364-
365 landscape.tests.test_reactor
366 landscape.tests.test_schema
367+
368 landscape.manager.tests.test_scriptexecution
369-
370-
371-landscape.broker.tests.test_ping
372-
373-landscape.broker.tests.test_exchange
374-landscape.broker.tests.test_store
375+landscape.manager.tests.test_customgraph
376+
377+
378+

Subscribers

People subscribed via source and target branches

to all changes: