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

Proposed by Steffen Allner
Status: Merged
Approved by: Данило Шеган
Approved revision: 963
Merged at revision: 955
Proposed branch: lp:~gocept/landscape-client/py3-twisted-util
Merge into: lp:~landscape/landscape-client/trunk
Prerequisite: lp:~gocept/landscape-client/py3-fs
Diff against target: 146 lines (+19/-23)
2 files modified
landscape/lib/tests/test_twisted_util.py (+10/-14)
landscape/lib/twisted_util.py (+9/-9)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-twisted-util
Reviewer Review Type Date Requested Status
Daniel Havlik (community) Approve
🤖 Landscape Builder test results Approve
Данило Шеган (community) Approve
Steffen Allner (community) Approve
Landscape Pending
Landscape Pending
Review via email: mp+319673@code.launchpad.net

This proposal supersedes a proposal from 2017-03-06.

Commit message

Support python 2 and 3 in code which receives data from the stdout and stderr and therefore handles with Bytes and not with Stings in Python 3. To reduce the amount of compat code, the code has been changed to use the same `io.BytesIO()` in Python 2 and 3.

Description of the change

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

This MP considers the part of code which receives data from the stdout and stderr and therefore handles with Bytes and not with Stings in Python 3. To reduce the amount of compat code, the code has been changed to use the same `io.BytesIO()` in Python 2 and 3.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) : Posted in a previous version of this proposal
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote : Posted in a previous version of this proposal

Command: TRIAL_ARGS=-j4 make check
Result: Fail
Revno: 959
Branch: lp:~gocept/landscape-client/py3-twisted-util
Jenkins: https://ci.lscape.net/job/latch-test-precise/887/

review: Needs Fixing (test results)
Revision history for this message
Adam Collard (adam-collard) : Posted in a previous version of this proposal
review: Abstain
Revision history for this message
David Britton (dpb) wrote : Posted in a previous version of this proposal

Hi Daniel -- Please add 'landscape' on these in the future. Otherwise only Adam will be able to review. :)

I've taken care of this one.

Thanks!

Revision history for this message
Данило Шеган (danilo) wrote : Posted in a previous version of this proposal

I've just noticed that the dependency branch is still missing the second Landscape dev reviewer: I've added myself there and will be reviewing that first. We also require Adam to approve the changes there too.

I'll get back to this after I am done with that branch.

Revision history for this message
Данило Шеган (danilo) wrote : Posted in a previous version of this proposal

FWIW, you should fix the test failure as well: http://paste.ubuntu.com/24136946/

(test builder is still running on Ubuntu 12.04 [precise], so maybe that's to blame, but I haven't looked deeper: if it's easy, it's nice to get a fix for that too, but if not, we can probably move to supporting only 14.04 and later since 12.04 is EOLin this April)

Revision history for this message
Steffen Allner (sallner) wrote : Posted in a previous version of this proposal

I am currently developing on an Ubuntu 16.04.1 and cannot reproduce this test failure. But I agree, we should at least test it on 14.04.

Revision history for this message
Steffen Allner (sallner) wrote : Posted in a previous version of this proposal

I am actually surprised that there should be only one test failure. I tried to test it on an Ubuntu 12.04. and 14.04. and failed both times. For 12.04 I already failed to install bzr as python-bzrlib depends on python-configobj, which in turn is a virtual-package now and did not install anything.

On 14.04. executing the tests led to some ImportErrors out of `twisted.python.compat` as some of the compat code we took is not available in twisted 13.2 (which is in the repos in 14.04.). For 12.04. twisted 11.1 is in the repos with even less compat code. So this is a bit unclear to me. Or is the landscape-builder using any kind of virtualenv to do the testing?

Revision history for this message
🤖 Landscape Builder (landscape-builder) : Posted in a previous version of this proposal
review: Abstain (executing tests)
Revision history for this message
Данило Шеган (danilo) wrote : Posted in a previous version of this proposal

Yeah, we are definitely missing some development setup bits for landscape-client: I've done an "apt-get build-dep landscape-client", and as you noted, bzr was still missing, but also python-mock and xvfb. xvfb is probably not really needed anymore with our GUI component retired, but I'll need to double check that. However, the problem with python-mock on 12.04 is that it seems to be very old (0.7.2) and the tests already use features from a newer version (1.0.1, eg. by adding "deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/cloud-tools main" to your /etc/apt/sources.list). Updating python-twisted-core to the version from that archive (13.02) also made trial accept -j4 parameter so "make check" fully passed for me. Perhaps the failed test is failing intermittently: if so, I'll file a separate bug about that (retrying the test run right now).

I'll now look if 14.04 as-is has all the deps needed at sufficiently new versions and update our infrastructure to run the tests on that instead.

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote : Posted in a previous version of this proposal

Command: TRIAL_ARGS=-j4 make check
Result: Success
Revno: 959
Branch: lp:~gocept/landscape-client/py3-twisted-util
Jenkins: https://ci.lscape.net/job/latch-test-precise/893/

review: Approve (test results)
Revision history for this message
Steffen Allner (sallner) wrote : Posted in a previous version of this proposal

At least that one worked. Thanks, Danilo! Apart from that, I recall that we agreed on compatibility with 16.04. for the new version of landscape client. So if those problems persist or occur more frequently, we have to find a different mode.

Revision history for this message
Данило Шеган (danilo) wrote : Posted in a previous version of this proposal

Righto: please do focus on what the agreement specifies, we can deal with compatibility in that case (sorry if I overstepped).

Revision history for this message
🤖 Landscape Builder (landscape-builder) : Posted in a previous version of this proposal
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote : Posted in a previous version of this proposal

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

review: Approve (test results)
Revision history for this message
🤖 Landscape Builder (landscape-builder) : Posted in a previous version of this proposal
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote : Posted in a previous version of this proposal

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

review: Approve (test results)
Revision history for this message
Данило Шеган (danilo) wrote : Posted in a previous version of this proposal

Looks good, +1 (we do need to wait for the prereq to land, of course)

review: Approve
Revision history for this message
Daniel Havlik (nilo) wrote : Posted in a previous version of this proposal

+1

review: Approve
Revision history for this message
Steffen Allner (sallner) wrote : Posted in a previous version of this proposal

If we merge the py3-fs branch first, we will get some failing tests. So I will merge py3-fs into this branch and update the proposal to have it as prerequisite.

review: Needs Fixing
Revision history for this message
🤖 Landscape Builder (landscape-builder) : Posted in a previous version of this proposal
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote : Posted in a previous version of this proposal

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

review: Approve (test results)
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
Steffen Allner (sallner) wrote :

I updated the tests of landscape.lib.twisted_util to work with the optional encoding of landscape.lib.fs.

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

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

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

+1

review: Approve
963. By Steffen Allner

Merge in current l.l.fs and use create_text_file().

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: 963
Branch: lp:~gocept/landscape-client/py3-twisted-util
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3618/

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

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/lib/tests/test_twisted_util.py'
2--- landscape/lib/tests/test_twisted_util.py 2017-03-14 09:54:21 +0000
3+++ landscape/lib/tests/test_twisted_util.py 2017-03-14 09:54:21 +0000
4@@ -1,8 +1,5 @@
5 import os
6
7-from twisted.python.compat import _PY3
8-from unittest import skipIf
9-
10 from landscape.lib.fs import create_text_file
11 from landscape.lib.twisted_util import spawn_process
12 from landscape.tests.helpers import LandscapeTest
13@@ -23,8 +20,8 @@
14
15 def callback(args):
16 out, err, code = args
17- self.assertEqual(out, "")
18- self.assertEqual(err, "")
19+ self.assertEqual(out, b"")
20+ self.assertEqual(err, b"")
21 self.assertEqual(code, 2)
22
23 result = spawn_process(self.command)
24@@ -37,8 +34,8 @@
25 """
26 def callback(args):
27 out, err, code = args
28- self.assertEqual(out, "a b")
29- self.assertEqual(err, "")
30+ self.assertEqual(out, b"a b")
31+ self.assertEqual(err, b"")
32 self.assertEqual(code, 0)
33
34 result = spawn_process(self.command, args=("a", "b"))
35@@ -53,8 +50,8 @@
36
37 def callback(args):
38 out, err, code = args
39- self.assertEqual(out, "")
40- self.assertEqual(err, "a b")
41+ self.assertEqual(out, b"")
42+ self.assertEqual(err, b"a b")
43 self.assertEqual(code, 0)
44
45 result = spawn_process(self.command, args=("a", "b"))
46@@ -68,7 +65,7 @@
47 """
48 create_text_file(self.command, "#!/bin/sh\n/bin/echo -ne $@")
49 param = r"some text\nanother line\nok, last one\n"
50- expected = ["some text", "another line", "ok, last one"]
51+ expected = [b"some text", b"another line", b"ok, last one"]
52 lines = []
53
54 def line_received(line):
55@@ -89,7 +86,7 @@
56 """
57 create_text_file(self.command, "#!/bin/sh\n/bin/echo -ne $@")
58 param = r"some text\nanother line\n\n\n"
59- expected = ["some text", "another line", "", ""]
60+ expected = [b"some text", b"another line", b"", b""]
61 lines = []
62
63 def line_received(line):
64@@ -111,7 +108,7 @@
65 """
66 create_text_file(self.command, "#!/bin/sh\n/bin/echo -ne $@")
67 param = r"some text\nanother line\nok, last one"
68- expected = ["some text", "another line", "ok, last one"]
69+ expected = [b"some text", b"another line", b"ok, last one"]
70 lines = []
71
72 def line_received(line):
73@@ -126,7 +123,6 @@
74 result.addCallback(callback)
75 return result
76
77- @skipIf(_PY3, 'Takes long with Python3, probably unclean Reactor')
78 def test_spawn_process_with_stdin(self):
79 """
80 Optionally C{spawn_process} accepts a C{stdin} argument.
81@@ -135,7 +131,7 @@
82
83 def callback(args):
84 out, err, code = args
85- self.assertEqual("hello", out)
86+ self.assertEqual(b"hello", out)
87
88 result = spawn_process(self.command, stdin="hello")
89 result.addCallback(callback)
90
91=== modified file 'landscape/lib/twisted_util.py'
92--- landscape/lib/twisted_util.py 2017-01-10 16:12:53 +0000
93+++ landscape/lib/twisted_util.py 2017-03-14 09:54:21 +0000
94@@ -1,10 +1,10 @@
95+import io
96+
97 from twisted.internet.defer import DeferredList, Deferred
98 from twisted.internet.protocol import ProcessProtocol
99 from twisted.internet.process import Process, ProcessReader
100 from twisted.internet import reactor
101-from twisted.python.compat import itervalues
102-
103-from landscape.compat import StringIO
104+from twisted.python.compat import itervalues, networkString
105
106
107 def gather_results(deferreds, consume_errors=False):
108@@ -20,16 +20,16 @@
109
110 def __init__(self, deferred, stdin=None, line_received=None):
111 self.deferred = deferred
112- self.outBuf = StringIO()
113- self.errBuf = StringIO()
114+ self.outBuf = io.BytesIO()
115+ self.errBuf = io.BytesIO()
116 self.errReceived = self.errBuf.write
117 self.stdin = stdin
118 self.line_received = line_received
119- self._partial_line = ""
120+ self._partial_line = b""
121
122 def connectionMade(self):
123 if self.stdin is not None:
124- self.transport.write(self.stdin)
125+ self.transport.write(networkString(self.stdin))
126 self.transport.closeStdin()
127
128 def outReceived(self, data):
129@@ -41,7 +41,7 @@
130 # data may contain more than one line, so we split the output and save
131 # the last line. If it's an empty string nothing happens, otherwise it
132 # will be returned once complete
133- lines = data.split("\n")
134+ lines = data.split(b"\n")
135 lines[0] = self._partial_line + lines[0]
136 self._partial_line = lines.pop()
137
138@@ -51,7 +51,7 @@
139 def processEnded(self, reason):
140 if self._partial_line:
141 self.line_received(self._partial_line)
142- self._partial_line = ""
143+ self._partial_line = b""
144 out = self.outBuf.getvalue()
145 err = self.errBuf.getvalue()
146 e = reason.value

Subscribers

People subscribed via source and target branches

to all changes: