URL: https://github.com/freeipa/freeipa/pull/882 Author: MartinBasti Title: #882: Py3 fixes Action: opened
PR body: """ """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/882/head:pr882 git checkout pr882
From 0ff7ff94e8588ccbf6b8b0b4ec98d9fe4477f6a2 Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Mon, 19 Jun 2017 19:11:10 +0200 Subject: [PATCH 1/6] py3: Remove comparison >=2 of debnug log level We have only one debug log level and it causes issues with py3. ... File "/usr/lib/python3.5/site-packages/ipaserver/rpcserver.py", line 490, in marshal response, version, pretty_print=self.api.env.debug >= 2 TypeError: unorderable types: str() >= int() https://pagure.io/freeipa/issue/4985 --- .travis.yml | 8 +------- ipaserver/rpcserver.py | 2 +- ipatests/test_ipapython/test_session_storage.py | 3 ++- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 56c230c260..6d18f90ddf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,17 +66,11 @@ env: TEST_RUNNER_CONFIG=".test_runner_config_py3_temp.yaml" TESTS_TO_RUN="test_cmdline test_ipalib + test_ipapython test_pkcs10 test_xmlrpc/test_ping_plugin.py" ### Tests which haven't been ported to py3 yet ### ## test_install - ## test_ipapython - # test_ipapython/test_cookie.py - # test_ipapython/test_dn.py - # test_ipapython/test_ipautil.py - # test_ipapython/test_ipavalidate.py - # test_ipapython/test_kerberos.py - # test_ipapython/test_ssh.py # test_ipaserver/httptest.py # test_ipaserver/test_changepw.py # test_ipaserver/test_dnssec.py diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py index 2990df2598..7d3dfc48cf 100644 --- a/ipaserver/rpcserver.py +++ b/ipaserver/rpcserver.py @@ -487,7 +487,7 @@ def marshal(self, result, error, _id=None, version=unicode(VERSION), ) dump = json_encode_binary( - response, version, pretty_print=self.api.env.debug >= 2 + response, version, pretty_print=self.api.env.debug ) return dump.encode('utf-8') diff --git a/ipatests/test_ipapython/test_session_storage.py b/ipatests/test_ipapython/test_session_storage.py index 1ae9f9c967..a2d8ab6206 100644 --- a/ipatests/test_ipapython/test_session_storage.py +++ b/ipatests/test_ipapython/test_session_storage.py @@ -23,13 +23,14 @@ def setup(self): self.principal = 'admin' self.key = 'X-IPA-test-session-storage' self.data = 'Test Data' + self.data_bytes = self.data.encode('utf-8') def test_01(self): session_storage.store_data(self.principal, self.key, self.data) def test_02(self): data = session_storage.get_data(self.principal, self.key) - assert(data == self.data) + assert(data == self.data_bytes) def test_03(self): session_storage.remove_data(self.principal, self.key) From edcdbc919012894e0511813f4bd50d74d9b7acc0 Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Mon, 19 Jun 2017 19:19:58 +0200 Subject: [PATCH 2/6] py3: rpcserver: password change must return bytes to wsgi mod_wsgi takes only bytes in py3 https://pagure.io/freeipa/issue/4985 --- .travis.yml | 3 +-- ipaserver/rpcserver.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6d18f90ddf..2d3847053c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,12 +67,11 @@ env: TESTS_TO_RUN="test_cmdline test_ipalib test_ipapython + test_ipaserver/test_changepw.py test_pkcs10 test_xmlrpc/test_ping_plugin.py" ### Tests which haven't been ported to py3 yet ### ## test_install - # test_ipaserver/httptest.py - # test_ipaserver/test_changepw.py # test_ipaserver/test_dnssec.py # test_ipaserver/test_install/test_adtrustinstance.py # test_ipaserver/test_install/test_service.py diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py index 7d3dfc48cf..a43c16477e 100644 --- a/ipaserver/rpcserver.py +++ b/ipaserver/rpcserver.py @@ -1084,7 +1084,7 @@ def __call__(self, environ, start_response): start_response(status, response_headers) output = _success_template % dict(title=str(title), message=str(message)) - return [output] + return [output.encode('utf-8')] class sync_token(Backend, HTTP_Status): content_type = 'text/plain' From cb5716c8049eb815cf8df855e439a70b62948679 Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Tue, 20 Jun 2017 10:00:59 +0200 Subject: [PATCH 3/6] py3: ipa_otptoken_import: fix lamba code inspection lambda in py3 has '__code__' attribute instead of 'func_code' https://pagure.io/freeipa/issue/4985 --- ipaserver/install/ipa_otptoken_import.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ipaserver/install/ipa_otptoken_import.py b/ipaserver/install/ipa_otptoken_import.py index 2580e2cfc9..b451a0f23b 100644 --- a/ipaserver/install/ipa_otptoken_import.py +++ b/ipaserver/install/ipa_otptoken_import.py @@ -378,7 +378,10 @@ def __parse(self, decryptor, element, prefix, table): result = fetch(element, path) if result is not None: - if getattr(getattr(v[1], "func_code", None), "co_argcount", 0) > 1: + lambda_code_attr = "__code__" if six.PY3 else "func_code" + if getattr( + getattr(v[1], lambda_code_attr, None), + "co_argcount", 0) > 1: data[v[0]] = v[1](result, decryptor) else: data[v[0]] = v[1](result) From 017dbf87c82cdc1d4e68728637aca090a898e2e7 Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Tue, 20 Jun 2017 10:16:10 +0200 Subject: [PATCH 4/6] py3: ipa_otptoken_import: fix calling unicode on bytes .decode() must be used instead https://pagure.io/freeipa/issue/4985 --- ipaserver/install/ipa_otptoken_import.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ipaserver/install/ipa_otptoken_import.py b/ipaserver/install/ipa_otptoken_import.py index b451a0f23b..4a874e8775 100644 --- a/ipaserver/install/ipa_otptoken_import.py +++ b/ipaserver/install/ipa_otptoken_import.py @@ -315,7 +315,11 @@ class PSKCKeyPackage(object): ('model', 'ipatokenmodel', lambda v, o: v.strip()), ('serial', 'ipatokenserial', lambda v, o: v.strip()), ('issueno', 'ipatokenserial', lambda v, o: o.get('ipatokenserial', '') + '-' + v.strip()), - ('key', 'ipatokenotpkey', lambda v, o: unicode(base64.b32encode(v))), + ( + 'key', + 'ipatokenotpkey', + lambda v, o: base64.b32encode(v).decode('ascii') + ), ('digits', 'ipatokenotpdigits', lambda v, o: v), ('algorithm', 'ipatokenotpalgorithm', lambda v, o: v), ('counter', 'ipatokenhotpcounter', lambda v, o: v), From f9652cf2066ffab93450414fe603964cd7a1cf1d Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Tue, 20 Jun 2017 10:21:05 +0200 Subject: [PATCH 5/6] py3: ipa_otptoken_import: fix hex decoding codecs.decode() must be used instead of .decode() method https://pagure.io/freeipa/issue/4985 --- ipatests/test_ipaserver/test_otptoken_import.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ipatests/test_ipaserver/test_otptoken_import.py b/ipatests/test_ipaserver/test_otptoken_import.py index 19dfbf74d1..43b334999a 100644 --- a/ipatests/test_ipaserver/test_otptoken_import.py +++ b/ipatests/test_ipaserver/test_otptoken_import.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import codecs import os import pytest @@ -62,7 +63,7 @@ def test_figure5(self): def test_figure6(self): doc = PSKCDocument(os.path.join(basename, "pskc-figure6.xml")) assert doc.keyname == 'Pre-shared-key' - doc.setKey('12345678901234567890123456789012'.decode('hex')) + doc.setKey(codecs.decode('12345678901234567890123456789012', 'hex')) assert [(t.id, t.options) for t in doc.getKeyPackages()] == \ [(u'12345678', { 'ipatokenotpkey': u'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ', From 254d545f335f52f94b2821d0b72e8992268e4be3 Mon Sep 17 00:00:00 2001 From: Martin Basti <mba...@redhat.com> Date: Tue, 20 Jun 2017 10:41:28 +0200 Subject: [PATCH 6/6] py3: test_otptoken_import: fix bytes usage https://pagure.io/freeipa/issue/4985 --- .travis.yml | 16 +--------------- ipatests/test_ipaserver/test_otptoken_import.py | 2 +- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2d3847053c..25c0cf081a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,24 +67,10 @@ env: TESTS_TO_RUN="test_cmdline test_ipalib test_ipapython - test_ipaserver/test_changepw.py + test_ipaserver test_pkcs10 test_xmlrpc/test_ping_plugin.py" ### Tests which haven't been ported to py3 yet ### - ## test_install - # test_ipaserver/test_dnssec.py - # test_ipaserver/test_install/test_adtrustinstance.py - # test_ipaserver/test_install/test_service.py - # test_ipaserver/test_ipap11helper.py - # test_ipaserver/test_kadmin.py - # test_ipaserver/test_ldap.py - # test_ipaserver/test_otptoken_import.py - # test_ipaserver/test_rpcserver.py - # test_ipaserver/test_secrets.py - # test_ipaserver/test_serverroles.py - # test_ipaserver/test_topology_plugin.py - # test_ipaserver/test_version_comparison.py - ## test_ipaserver ## test_xmlrpc/test_[l-z]*.py # test_xmlrpc/test_location_plugin.py # test_xmlrpc/test_nesting.py diff --git a/ipatests/test_ipaserver/test_otptoken_import.py b/ipatests/test_ipaserver/test_otptoken_import.py index 43b334999a..88353675d8 100644 --- a/ipatests/test_ipaserver/test_otptoken_import.py +++ b/ipatests/test_ipaserver/test_otptoken_import.py @@ -76,7 +76,7 @@ def test_figure6(self): def test_figure7(self): doc = PSKCDocument(os.path.join(basename, "pskc-figure7.xml")) assert doc.keyname == 'My Password 1' - doc.setKey('qwerty') + doc.setKey(b'qwerty') assert [(t.id, t.options) for t in doc.getKeyPackages()] == \ [(u'123456', { 'ipatokenotpkey': u'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ',
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org