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

Proposed by Steffen Allner
Status: Merged
Approved by: Данило Шеган
Approved revision: 971
Merged at revision: 974
Proposed branch: lp:~gocept/landscape-client/py3-user
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 131 lines (+31/-24)
7 files modified
Makefile (+1/-1)
landscape/user/changes.py (+1/-1)
landscape/user/management.py (+1/-3)
landscape/user/provider.py (+6/-1)
landscape/user/tests/test_changes.py (+13/-7)
landscape/user/tests/test_provider.py (+8/-11)
py3_ready_tests (+1/-0)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-user
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Approve
Daniel Havlik (community) Approve
Данило Шеган (community) Approve
Review via email: mp+320653@code.launchpad.net

Commit message

Make landscape.user module py2/py3 compatible.

Description of the change

This MP considers the landscape.user module and makes it py2/py3 compatible.

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: Fail
Revno: 969
Branch: lp:~gocept/landscape-client/py3-user
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3703/

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 check
Result: Fail
Revno: 969
Branch: lp:~gocept/landscape-client/py3-user
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3705/

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 check
Result: Fail
Revno: 969
Branch: lp:~gocept/landscape-client/py3-user
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3706/

review: Needs Fixing (test results)
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
Данило Шеган (danilo) wrote :

We are missing python3-passlib from depends3 rule: I've manually installed it on a few slaves, but probably best to add it to depends3 so the tests can run.

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

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

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

Looks good, a few nits inline.

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

Added some inline comments, I will change the dependencies in the Makefile though.

Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
Данило Шеган (danilo) :
review: Approve
Revision history for this message
Данило Шеган (danilo) :
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

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

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

+1

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

Attempt to merge into lp:landscape-client failed due to conflicts:

text conflict in py3_ready_tests

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

No approved revision specified.

lp:~gocept/landscape-client/py3-user updated
971. By Steffen Allner

Backmerge from trunk.

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

I resolved the conflict.

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

review: Approve (test results)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2017-03-17 09:57:31 +0000
3+++ Makefile 2017-03-23 14:26:32 +0000
4@@ -46,7 +46,7 @@
5 LC_ALL=C $(TEST_COMMAND_PY3_READY)
6
7 depends3:
8- sudo apt -y install python3-twisted python3-distutils-extra python3-mock python3-configobj
9+ sudo apt -y install python3-twisted python3-distutils-extra python3-mock python3-configobj python3-passlib
10
11 lint:
12 bzr ls-lint
13
14=== modified file 'landscape/user/changes.py'
15--- landscape/user/changes.py 2017-01-23 12:13:14 +0000
16+++ landscape/user/changes.py 2017-03-23 14:26:32 +0000
17@@ -136,6 +136,6 @@
18 members.extend(update_groups)
19
20 if deletes:
21- changes["delete-groups"] = deletes.keys()
22+ changes["delete-groups"] = sorted(deletes.keys())
23
24 return changes
25
26=== modified file 'landscape/user/management.py'
27--- landscape/user/management.py 2017-03-10 10:31:30 +0000
28+++ landscape/user/management.py 2017-03-23 14:26:32 +0000
29@@ -48,9 +48,7 @@
30 return output
31
32 def _set_password(self, username, password):
33- # XXX temporary workaround? We're getting unicode here.
34- username = username.encode("ascii")
35- password = password.encode("ascii")
36+ password = password.encode("utf-8")
37 crypted = md5_crypt.encrypt(password)
38 result, output = self.call_popen(["usermod", "-p", crypted, username])
39 if result != 0:
40
41=== modified file 'landscape/user/provider.py'
42--- landscape/user/provider.py 2017-03-10 14:39:38 +0000
43+++ landscape/user/provider.py 2017-03-23 14:26:32 +0000
44@@ -119,8 +119,13 @@
45 directory, path to the user's shell)
46 """
47 user_data = []
48+ # The DictReader takes bytes in Python 2 and unicode in Python 3 so we
49+ # have to pass Python 3 specific parameters to open() and do the
50+ # decoding for Python 2 later after we have parsed the rows. We have to
51+ # explicitly indicate the encoding as we cannot rely on the system
52+ # default encoding.
53 if _PY3:
54- open_params = dict(errors='replace')
55+ open_params = dict(encoding="utf-8", errors='replace')
56 else:
57 open_params = dict()
58 with open(self._passwd_file, "r", **open_params) as passwd_file:
59
60=== modified file 'landscape/user/tests/test_changes.py'
61--- landscape/user/tests/test_changes.py 2016-01-11 18:34:49 +0000
62+++ landscape/user/tests/test_changes.py 2017-03-23 14:26:32 +0000
63@@ -1,3 +1,5 @@
64+from twisted.python.compat import _PY3
65+
66 from landscape.lib.persist import Persist
67 from landscape.user.changes import UserChanges
68 from landscape.user.tests.helpers import FakeUserInfo, FakeUserProvider
69@@ -290,10 +292,14 @@
70 groups.append(("sales", "x", 70, ["bo"]))
71 # Remove user "jdoe"
72 users.pop(0)
73- self.assertEqual(changes.create_diff(),
74- {"create-groups": [{"gid": 50, "name": "developers"},
75- {"gid": 70, "name": "sales"}],
76- "delete-users": ["jdoe"],
77- "delete-groups": ["webdev"],
78- "create-group-members": {"developers": ["bo"],
79- "sales": ["bo"]}})
80+ if _PY3:
81+ assertion = self.assertCountEqual
82+ else:
83+ assertion = self.assertItemsEqual
84+ assertion(changes.create_diff(),
85+ {"create-groups": [{"gid": 50, "name": "developers"},
86+ {"gid": 70, "name": "sales"}],
87+ "delete-users": ["jdoe"],
88+ "delete-groups": ["webdev"],
89+ "create-group-members": {"developers": ["bo"],
90+ "sales": ["bo"]}})
91
92=== modified file 'landscape/user/tests/test_provider.py'
93--- landscape/user/tests/test_provider.py 2017-03-10 15:25:44 +0000
94+++ landscape/user/tests/test_provider.py 2017-03-23 14:26:32 +0000
95@@ -130,19 +130,16 @@
96 def test_utf8_gecos_data(self):
97 """Gecos fields should be decoded from utf-8 to unicode."""
98 name = u"Jos\N{LATIN SMALL LETTER E WITH ACUTE}"
99- location = "F\N{LATIN SMALL LETTER I WITH DIAERESIS}nland"
100- number = "N\N{LATIN SMALL LETTER AE}ver"
101- if _PY3:
102- gecos = "{},{},{},{},".format(name, location, number, number)
103- else:
104- gecos = "{},{},{},{},".format(name.encode("utf-8"),
105- location.encode("utf-8"),
106- number.encode("utf-8"),
107- number.encode("utf-8"))
108- passwd_file = self.makeFile("""\
109+ location = u"F\N{LATIN SMALL LETTER I WITH DIAERESIS}nland"
110+ number = u"N\N{LATIN SMALL LETTER AE}ver"
111+ gecos = u"{},{},{},{},".format(name, location, number, number)
112+ # We explicitly want to encode this file with utf-8 so we can write in
113+ # binary mode and do not rely on the default encoding.
114+ utf8_content = u"""\
115 jdoe:x:1000:1000:{}:/home/jdoe:/bin/zsh
116 root:x:0:0:root:/root:/bin/bash
117-""".format(gecos))
118+""".format(gecos).encode("utf-8")
119+ passwd_file = self.makeFile(utf8_content, mode="wb")
120 provider = UserProvider(passwd_file=passwd_file,
121 group_file=self.group_file)
122 users = provider.get_users()
123
124=== modified file 'py3_ready_tests'
125--- py3_ready_tests 2017-03-23 13:44:26 +0000
126+++ py3_ready_tests 2017-03-23 14:26:32 +0000
127@@ -1,5 +1,6 @@
128 landscape.lib.tests
129 landscape.sysinfo.tests
130+landscape.user.tests
131 landscape.package.tests
132
133

Subscribers

People subscribed via source and target branches

to all changes: