Merge lp:~benji/landscape-client/try-unicode into lp:~landscape/landscape-client/trunk

Proposed by Benji York
Status: Rejected
Rejected by: Benji York
Proposed branch: lp:~benji/landscape-client/try-unicode
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 255 lines (+49/-13)
18 files modified
landscape/log.py (+3/-0)
landscape/manager/aptsources.py (+2/-0)
landscape/manager/config.py (+2/-0)
landscape/manager/customgraph.py (+13/-9)
landscape/manager/fakepackagemanager.py (+2/-0)
landscape/manager/hardwareinfo.py (+2/-0)
landscape/manager/haservice.py (+2/-0)
landscape/manager/keystonetoken.py (+2/-0)
landscape/manager/manager.py (+2/-0)
landscape/manager/packagemanager.py (+2/-0)
landscape/manager/plugin.py (+2/-0)
landscape/manager/processkiller.py (+2/-0)
landscape/manager/scriptexecution.py (+2/-2)
landscape/manager/service.py (+2/-0)
landscape/manager/shutdownmanager.py (+2/-0)
landscape/manager/store.py (+4/-1)
landscape/manager/tests/test_usermanager.py (+1/-1)
landscape/manager/usermanager.py (+2/-0)
To merge this branch: bzr merge lp:~benji/landscape-client/try-unicode
Reviewer Review Type Date Requested Status
Adam Collard (community) Disapprove
Chad Smith Pending
Review via email: mp+296360@code.launchpad.net

Description of the change

This branch begins chipping away at converting the client codebase to
using unicode and byte strings so as to be compatible with Python 3.

This branch converts all of the modules in the landscape/managers
directory. Many survived with only a one-line change to add a from
__future__ import, but others required more work.

Testing instructions:

make check
start the client and register it

To post a comment you must log in.
Revision history for this message
Adam Collard (adam-collard) wrote :

Hmm, toggling unicode_literals feels a bit dangerous.

There is some discussion about the pro's and con's at http://python-future.org/unicode_literals.html .

Can we put some words on paper (read: Google doc) as to why we took this approach, what the risks are etc.? Just make the case for unicode_literals as opposed to string-by-string u"" or b""

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

FWIW I think it's a safe approach because afaict landscape.schema will make sure that expectations on the data format that gets transferred on the wire are met.

Revision history for this message
Benji York (benji) wrote :
Revision history for this message
Chad Smith (chad.smith) wrote :

Hrm, well something may be falling over I was unable to see package reports coming from a registered client with these changes against advicedog. I'll try to see if I can get a second registration against an OnPremises deployment in bstack to confirm.

Revision history for this message
Chad Smith (chad.smith) wrote :

Code changes themselves look clean. And I appreciate the Gdoc thank you.

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

This branch makes me super uncomfortable. I'm doubling down on my "this feels a bit dangerous". We are changing the code without touching the tests: which means that our tests are using bytes (AKA Python2's str) but our real code is using unicode (AKA Python3's str).

The code in landscape-client was not written with the expectation that string literals are Unicode. This doesn't just affect the on-the-wire format (as Free mentions above) but all interactions with the filesystem, sub-processes, etc.

I think we have to bite the bullet and just accept that we have to take the time to identify what is textual data and what is binary (and mark up literals with u"" and b"" as necessary)

review: Disapprove

Unmerged revisions

844. By Benji York

fix lint

843. By Benji York

checkpoint - tests passing

842. By Benji York

checkpoint - tests passing

841. By Benji York

checkpoint - tests passing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'landscape/log.py'
--- landscape/log.py 2008-06-10 10:56:01 +0000
+++ landscape/log.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import inspect3import inspect
2import logging4import logging
35
@@ -31,6 +33,7 @@
31 percent = 0.033 percent = 0.0
32 return "%.02f%%" % float(percent)34 return "%.02f%%" % float(percent)
3335
36
34def rotate_logs():37def rotate_logs():
35 """38 """
36 This closes and reopens the underlying files in the logging module's39 This closes and reopens the underlying files in the logging module's
3740
=== modified file 'landscape/manager/aptsources.py'
--- landscape/manager/aptsources.py 2013-04-01 09:25:31 +0000
+++ landscape/manager/aptsources.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import glob3import glob
2import os4import os
3import pwd5import pwd
46
=== modified file 'landscape/manager/config.py'
--- landscape/manager/config.py 2013-10-24 01:54:07 +0000
+++ landscape/manager/config.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import os3import os
24
3from landscape.deployment import Configuration5from landscape.deployment import Configuration
46
=== modified file 'landscape/manager/customgraph.py'
--- landscape/manager/customgraph.py 2013-05-21 14:18:29 +0000
+++ landscape/manager/customgraph.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import os3import os
2import time4import time
3import logging5import logging
@@ -84,9 +86,9 @@
84 def register(self, registry):86 def register(self, registry):
85 super(CustomGraphPlugin, self).register(registry)87 super(CustomGraphPlugin, self).register(registry)
86 registry.register_message(88 registry.register_message(
87 "custom-graph-add", self._handle_custom_graph_add)89 b"custom-graph-add", self._handle_custom_graph_add)
88 registry.register_message(90 registry.register_message(
89 "custom-graph-remove", self._handle_custom_graph_remove)91 b"custom-graph-remove", self._handle_custom_graph_remove)
90 self._persist = StoreProxy(self.registry.store)92 self._persist = StoreProxy(self.registry.store)
91 self._accumulate = Accumulator(self._persist, self.run_interval)93 self._accumulate = Accumulator(self._persist, self.run_interval)
9294
@@ -153,15 +155,17 @@
153 if os.path.isfile(filename):155 if os.path.isfile(filename):
154 script_hash = self._get_script_hash(filename)156 script_hash = self._get_script_hash(filename)
155 self._data[graph_id] = {157 self._data[graph_id] = {
156 "values": [], "error": u"", "script-hash": script_hash}158 b"values": [],
159 b"error": u"",
160 b"script-hash": script_hash}
157161
158 message = {"type": self.message_type, "data": self._data}162 message = {b"type": self.message_type, b"data": self._data}
159163
160 new_data = {}164 new_data = {}
161 for graph_id, item in self._data.iteritems():165 for graph_id, item in self._data.iteritems():
162 script_hash = item["script-hash"]166 script_hash = item[b"script-hash"]
163 new_data[graph_id] = {167 new_data[graph_id] = {
164 "values": [], "error": u"", "script-hash": script_hash}168 b"values": [], b"error": u"", b"script-hash": script_hash}
165 self._data = new_data169 self._data = new_data
166170
167 self.registry.broker.send_message(message, self._session_id,171 self.registry.broker.send_message(message, self._session_id,
@@ -227,12 +231,12 @@
227 if os.path.isfile(filename):231 if os.path.isfile(filename):
228 script_hash = self._get_script_hash(filename)232 script_hash = self._get_script_hash(filename)
229 else:233 else:
230 script_hash = ""234 script_hash = b""
231 if graph_id not in self._data:235 if graph_id not in self._data:
232 self._data[graph_id] = {236 self._data[graph_id] = {
233 "values": [], "error": u"", "script-hash": script_hash}237 b"values": [], b"error": u"", b"script-hash": script_hash}
234 else:238 else:
235 self._data[graph_id]["script-hash"] = script_hash239 self._data[graph_id][b"script-hash"] = script_hash
236 try:240 try:
237 uid, gid, path = get_user_info(user)241 uid, gid, path = get_user_info(user)
238 except UnknownUserError, e:242 except UnknownUserError, e:
239243
=== modified file 'landscape/manager/fakepackagemanager.py'
--- landscape/manager/fakepackagemanager.py 2013-05-21 14:18:29 +0000
+++ landscape/manager/fakepackagemanager.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import random3import random
24
3from landscape.manager.plugin import ManagerPlugin5from landscape.manager.plugin import ManagerPlugin
46
=== modified file 'landscape/manager/hardwareinfo.py'
--- landscape/manager/hardwareinfo.py 2013-05-17 22:48:40 +0000
+++ landscape/manager/hardwareinfo.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import os3import os
24
3from twisted.internet.utils import getProcessOutput5from twisted.internet.utils import getProcessOutput
46
=== modified file 'landscape/manager/haservice.py'
--- landscape/manager/haservice.py 2013-07-23 10:00:52 +0000
+++ landscape/manager/haservice.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import logging3import logging
2import os4import os
35
46
=== modified file 'landscape/manager/keystonetoken.py'
--- landscape/manager/keystonetoken.py 2013-07-11 20:27:10 +0000
+++ landscape/manager/keystonetoken.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import os3import os
2import logging4import logging
3from ConfigParser import ConfigParser, NoOptionError5from ConfigParser import ConfigParser, NoOptionError
46
=== modified file 'landscape/manager/manager.py'
--- landscape/manager/manager.py 2010-04-23 14:42:21 +0000
+++ landscape/manager/manager.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1from landscape.manager.store import ManagerStore3from landscape.manager.store import ManagerStore
2from landscape.broker.client import BrokerClient4from landscape.broker.client import BrokerClient
35
46
=== modified file 'landscape/manager/packagemanager.py'
--- landscape/manager/packagemanager.py 2013-03-05 02:53:38 +0000
+++ landscape/manager/packagemanager.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import logging3import logging
2import os4import os
35
46
=== modified file 'landscape/manager/plugin.py'
--- landscape/manager/plugin.py 2013-05-08 22:18:47 +0000
+++ landscape/manager/plugin.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1from twisted.internet.defer import maybeDeferred3from twisted.internet.defer import maybeDeferred
24
3from landscape.lib.log import log_failure5from landscape.lib.log import log_failure
46
=== modified file 'landscape/manager/processkiller.py'
--- landscape/manager/processkiller.py 2010-04-26 15:19:55 +0000
+++ landscape/manager/processkiller.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import os3import os
2import signal4import signal
3import logging5import logging
46
=== modified file 'landscape/manager/scriptexecution.py'
--- landscape/manager/scriptexecution.py 2013-05-17 22:32:49 +0000
+++ landscape/manager/scriptexecution.py 2016-06-02 19:46:38 +0000
@@ -1,8 +1,8 @@
1"""1"""Functionality for running arbitrary shell scripts.
2Functionality for running arbitrary shell scripts.
32
4@var ALL_USERS: A token indicating all users should be allowed.3@var ALL_USERS: A token indicating all users should be allowed.
5"""4"""
5
6import os6import os
7import pwd7import pwd
8import tempfile8import tempfile
99
=== modified file 'landscape/manager/service.py'
--- landscape/manager/service.py 2013-05-07 22:47:06 +0000
+++ landscape/manager/service.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1from twisted.python.reflect import namedClass3from twisted.python.reflect import namedClass
24
3from landscape.service import LandscapeService, run_landscape_service5from landscape.service import LandscapeService, run_landscape_service
46
=== modified file 'landscape/manager/shutdownmanager.py'
--- landscape/manager/shutdownmanager.py 2013-05-17 22:45:29 +0000
+++ landscape/manager/shutdownmanager.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import logging3import logging
24
3from twisted.internet.defer import Deferred5from twisted.internet.defer import Deferred
46
=== modified file 'landscape/manager/store.py'
--- landscape/manager/store.py 2008-10-22 16:54:38 +0000
+++ landscape/manager/store.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1try:3try:
2 import sqlite34 import sqlite3
3except ImportError:5except ImportError:
@@ -35,7 +37,8 @@
35 (filename, user, graph_id))37 (filename, user, graph_id))
36 else:38 else:
37 cursor.execute(39 cursor.execute(
38 "INSERT INTO graph (graph_id, filename, user) VALUES (?, ?, ?)",40 "INSERT INTO graph (graph_id, filename, user) "
41 "VALUES (?, ?, ?)",
39 (graph_id, filename, user))42 (graph_id, filename, user))
4043
41 @with_cursor44 @with_cursor
4245
=== modified file 'landscape/manager/tests/test_usermanager.py'
--- landscape/manager/tests/test_usermanager.py 2013-07-19 09:12:16 +0000
+++ landscape/manager/tests/test_usermanager.py 2016-06-02 19:46:38 +0000
@@ -175,7 +175,7 @@
175 self.assertMessages(messages,175 self.assertMessages(messages,
176 [{"type": "operation-result", "status": FAILED,176 [{"type": "operation-result", "status": FAILED,
177 "operation-id": 123, "timestamp": 0,177 "operation-id": 123, "timestamp": 0,
178 "result-text": "KeyError: 'username'"}])178 "result-text": "KeyError: u'username'"}])
179179
180 self.setup_environment([], [], None)180 self.setup_environment([], [], None)
181181
182182
=== modified file 'landscape/manager/usermanager.py'
--- landscape/manager/usermanager.py 2013-05-07 23:06:56 +0000
+++ landscape/manager/usermanager.py 2016-06-02 19:46:38 +0000
@@ -1,3 +1,5 @@
1from __future__ import unicode_literals
2
1import logging3import logging
24
3from landscape.lib.encoding import encode_dict_if_needed5from landscape.lib.encoding import encode_dict_if_needed

Subscribers

People subscribed via source and target branches

to all changes: