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

Proposed by Steffen Allner
Status: Merged
Approved by: Данило Шеган
Approved revision: 960
Merged at revision: 949
Proposed branch: lp:~gocept/landscape-client/py3-amp
Merge into: lp:~landscape/landscape-client/trunk
Prerequisite: lp:~gocept/landscape-client/python3
Diff against target: 90 lines (+10/-10)
2 files modified
landscape/lib/amp.py (+6/-1)
landscape/lib/tests/test_amp.py (+4/-9)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-amp
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Approve
Daniel Havlik (community) Approve
Free Ekanayaka (community) Approve
Данило Шеган (community) Approve
Review via email: mp+319452@code.launchpad.net

Commit message

Update code in the landscape.lib.amp module to support Python2/3 which provides the basic functionality to execute methods on remote Python objects via amp. As such it provides an integral part of the system.

As all information is sent via unix sockets, it has to be serializable, so we also have to convert the method name to bytes.

Additionally a flaky test due to the unstable sorting of dictionary keys was made more robust.

Re-enable skipped tests.

Description of the change

We are on the journey to get the Bytes / String story solved for Python 2/3 compatibility.

This MP considers code in the landscape.lib.amp module which provides the basic functionality to execute methods on remote Python objects via amp. As such it provides an integral part of the system.

As all information are send via unix sockets, they have to be serializable, so we also have to convert the method name to bytes.

Additionally a flaky test due to the unstable sorting of dictionary keys was made more robust.

Finally, the skipped tests could be run without problems now.

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: 959
Branch: lp:~gocept/landscape-client/py3-amp
Jenkins: https://ci.lscape.net/job/latch-test-xenial/1470/

review: Approve (test results)
Revision history for this message
Данило Шеган (danilo) wrote :

Looks good, thanks for making the test more stable along the way. +1

review: Approve
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Nice, +1

review: Approve
lp:~gocept/landscape-client/py3-amp updated
960. By Steffen Allner

Comply with coding style.

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

I updated to landscape coding style.

Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
Daniel Havlik (nilo) wrote :

+1

review: Approve
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

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

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/lib/amp.py'
2--- landscape/lib/amp.py 2017-03-06 10:38:07 +0000
3+++ landscape/lib/amp.py 2017-03-13 09:02:34 +0000
4@@ -163,10 +163,13 @@
5 if chunks is not None:
6 # We got some L{MethodCallChunk}s before, this is the last.
7 chunks.append(arguments)
8- arguments = "".join(chunks)
9+ arguments = b"".join(chunks)
10
11 args, kwargs = bpickle.loads(arguments)
12
13+ # We encoded the method name in `send_method_call` and have to decode
14+ # it here again.
15+ method = method.decode("utf-8")
16 if not method in self._methods:
17 raise MethodCallError("Forbidden method '%s'" % method)
18
19@@ -263,6 +266,8 @@
20 """
21 arguments = bpickle.dumps((args, kwargs))
22 sequence = uuid4().int
23+ # As we send the method name to remote, we need bytes.
24+ method = method.encode("utf-8")
25
26 # Split the given arguments in one or more chunks
27 chunks = [arguments[i:i + self._chunk_size]
28
29=== modified file 'landscape/lib/tests/test_amp.py'
30--- landscape/lib/tests/test_amp.py 2017-01-10 09:31:30 +0000
31+++ landscape/lib/tests/test_amp.py 2017-03-13 09:02:34 +0000
32@@ -10,9 +10,6 @@
33 MethodCallSender)
34 from landscape.tests.helpers import LandscapeTest
35
36-from unittest import skipIf
37-from twisted.python.compat import _PY3
38-
39
40 class FakeTransport(object):
41 """Accumulate written data into a list."""
42@@ -207,12 +204,14 @@
43 """
44 Method arguments passed to a L{MethodCall} can be dictionaries.
45 """
46- self.object.method = lambda d: "".join(d.keys()) * sum(d.values())
47+ # Sort the keys to ensure stable test outcome.
48+ self.object.method = lambda d: "".join(
49+ sorted(d.keys()) * sum(d.values()))
50 deferred = self.sender.send_method_call(method="method",
51 args=[{"foo": 1, "bar": 2}],
52 kwargs={})
53 self.connection.flush()
54- self.assertEqual("foobarfoobarfoobar", self.successResultOf(deferred))
55+ self.assertEqual("barfoobarfoobarfoo", self.successResultOf(deferred))
56
57 def test_with_non_serializable_return_value(self):
58 """
59@@ -622,7 +621,6 @@
60 self.client.stopTrying()
61 connector.disconnect()
62
63- @skipIf(_PY3, 'Takes long with Python3, probably unclean Reactor')
64 @inlineCallbacks
65 def test_retry(self):
66 """
67@@ -644,7 +642,6 @@
68 self.client.stopTrying()
69 connector.disconnect()
70
71- @skipIf(_PY3, 'Takes long with Python3, probably unclean Reactor')
72 @inlineCallbacks
73 def test_retry_with_method_call_error(self):
74 """
75@@ -666,7 +663,6 @@
76 self.client.stopTrying()
77 connector.disconnect()
78
79- @skipIf(_PY3, 'Takes long with Python3, probably unclean Reactor')
80 @inlineCallbacks
81 def test_wb_retry_with_while_still_disconnected(self):
82 """
83@@ -710,7 +706,6 @@
84 self.client.stopTrying()
85 connector.disconnect()
86
87- @skipIf(_PY3, 'Takes long with Python3, probably unclean Reactor')
88 @inlineCallbacks
89 def test_retry_with_many_method_calls(self):
90 """

Subscribers

People subscribed via source and target branches

to all changes: