Jump to: navigation, search

Difference between revisions of "Python3"

(OpenStack applications (tc:approved-release))
m (Update link for oslo_serialization.jsonutils.dump_as_bytes(obj))
 
(65 intermediate revisions by 25 users not shown)
Line 1: Line 1:
 
This page tracks the progress of Python 3 effort porting for OpenStack.
 
This page tracks the progress of Python 3 effort porting for OpenStack.
  
== IRC: #openstack-python3 ==
+
== IRC: #openstack-dev ==
  
Join the #openstack-python3 IRC channel on the Freenode network to discuss Python 3.
+
Join the #openstack-dev IRC channel on the Freenode network to discuss Python 3.
  
 
== Python 3 ==
 
== Python 3 ==
Line 80: Line 80:
 
JSON:
 
JSON:
  
* [with oslo.serialization 1.10 or newer] Replace json.dumps(obj) with [http://docs.openstack.org/developer/oslo.serialization/api.html#oslo_serialization.jsonutils.dump_as_bytes oslo_serialization.jsonutils.dump_as_bytes(obj)]
+
* [with oslo.serialization 1.10 or newer] Replace json.dumps(obj) with [https://docs.openstack.org/oslo.serialization/latest/reference/index.html#oslo_serialization.jsonutils.dump_as_bytes oslo_serialization.jsonutils.dump_as_bytes(obj)]
 
* Replace json.loads(obj) with oslo_serialization.jsonutils.loads(obj): it accepts bytes and Unicode, bytes is decoded from UTF-8. It avoids "if isinstance(obj, bytes): obj = obj.decode('utf-8')" which may require a second temporary variable.
 
* Replace json.loads(obj) with oslo_serialization.jsonutils.loads(obj): it accepts bytes and Unicode, bytes is decoded from UTF-8. It avoids "if isinstance(obj, bytes): obj = obj.decode('utf-8')" which may require a second temporary variable.
  
Line 275: Line 275:
 
| [https://pypi.python.org/pypi/oslo.messaging oslo.messaging] || style="background-color: lightgreen;" | Yes ||
 
| [https://pypi.python.org/pypi/oslo.messaging oslo.messaging] || style="background-color: lightgreen;" | Yes ||
 
oslo.messaging is now fully compatible with Python 3. The old (and now removed) Qpid transport was not compatible, the AMQP driver was ported recently.
 
oslo.messaging is now fully compatible with Python 3. The old (and now removed) Qpid transport was not compatible, the AMQP driver was ported recently.
 
The py34 check job is not more voting because of [//bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1367907 ubuntu still uses Python 3.4.0 which has a severe bug].
 
 
|-
 
|-
 
| [https://pypi.python.org/pypi/oslo.middleware oslo.middleware] || style="background-color: lightgreen;" | Yes ||
 
| [https://pypi.python.org/pypi/oslo.middleware oslo.middleware] || style="background-color: lightgreen;" | Yes ||
Line 287: Line 285:
 
|-
 
|-
 
| [https://pypi.python.org/pypi/oslo.rootwrap oslo.rootwrap] || style="background-color: lightgreen;" | Yes ||
 
| [https://pypi.python.org/pypi/oslo.rootwrap oslo.rootwrap] || style="background-color: lightgreen;" | Yes ||
oslo.rootwrap 2.4 works on Python 3, but eventlet tests hangs on Python 3. It's now fixed in the development version. oslo.rootwrap has a non-voting python34 check job.
 
 
|-
 
|-
 
| [https://pypi.python.org/pypi/oslo.serialization oslo.serialization] || style="background-color: lightgreen;" | Yes ||
 
| [https://pypi.python.org/pypi/oslo.serialization oslo.serialization] || style="background-color: lightgreen;" | Yes ||
 
|-
 
|-
| [https://pypi.python.org/pypi/oslo.service oslo.service] || style="background-color: lightgreen;" | Yes ||
+
| [https://pypi.python.org/pypi/oslo.service oslo.service] || style="background-color: orange;" | Partial ||
 +
WSGI module SSL support is broken under Python 3. We want projects to support deployment without relying on that code, but not all do (see glance and designate below).
 
|-
 
|-
 
| [https://pypi.python.org/pypi/oslotest oslotest] || style="background-color: lightgreen;" | Yes ||
 
| [https://pypi.python.org/pypi/oslotest oslotest] || style="background-color: lightgreen;" | Yes ||
Line 318: Line 316:
 
| [https://pypi.python.org/pypi/cookiecutter cookiecutter] || style="background-color: lightgreen;" | yes ||
 
| [https://pypi.python.org/pypi/cookiecutter cookiecutter] || style="background-color: lightgreen;" | yes ||
 
|-
 
|-
| [https://pypi.python.org/pypi/hacking hacking] || style="background-color: lightgreen;" | yes || py33 gate is not voting
+
| [https://pypi.python.org/pypi/hacking hacking] || style="background-color: lightgreen;" | yes ||
 
|-
 
|-
 
| [https://pypi.python.org/pypi/pbr pbr] || style="background-color: lightgreen;" | yes ||
 
| [https://pypi.python.org/pypi/pbr pbr] || style="background-color: lightgreen;" | yes ||
Line 362: Line 360:
 
|-
 
|-
  
| [https://pypi.python.org/pypi/python-manilaclient python-manilaclient] || style="background-color: lightgreen;" | Yes || style="background-color:lightgreen;" | Voting || style="background-color: lightgreen;" | On PyPI || ||
+
| [https://pypi.python.org/pypi/python-manilaclient python-manilaclient] || style="background-color: lightgreen;" | Yes || style="background-color:lightgreen;" | Voting || style="background-color: lightgreen;" | On PyPI || ||
 
|-
 
|-
  
Line 368: Line 366:
 
|-
 
|-
  
| [https://pypi.python.org/pypi/python-novaclient python-novaclient]  || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | Voting || style="background-color: lightgreen;" | On PyPII || ||
+
| [https://pypi.python.org/pypi/python-masakariclient python-masakariiclient]|| style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | Voting || style="background-color: lightgreen;" | On PyPI || ||
 +
|-
 +
 
 +
| [https://pypi.python.org/pypi/python-monascaclient python-monascaclient]  || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | Voting || style="background-color: lightgreen;" | On PyPI || ||
 +
|-
 +
 
 +
| [https://pypi.python.org/pypi/python-novaclient python-novaclient]  || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | Voting || style="background-color: lightgreen;" | On PyPI || ||
 
|-
 
|-
  
 
| [https://pypi.python.org/pypi/python-neutronclient python-neutronclient] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | Voting  || style="background-color: lightgreen;" | On PyPI ||  ||
 
| [https://pypi.python.org/pypi/python-neutronclient python-neutronclient] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | Voting  || style="background-color: lightgreen;" | On PyPI ||  ||
 +
|-
 +
 +
| [https://pypi.python.org/pypi/python-octaviaclient python-octaviaclient] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | Voting  || style="background-color: lightgreen;" | On PyPI ||  ||
 
|-
 
|-
  
Line 380: Line 387:
 
|-
 
|-
  
| [https://pypi.python.org/pypi/python-saharaclient python-senlinclient]    || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen" | Voting || style="background-color: lightgreen" | On PyPI ||  ||
+
| [https://pypi.python.org/pypi/python-searchlightclient python-searchlightclient]    || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen" | Voting || style="background-color: lightgreen" | On PyPI ||  ||
 +
|-
 +
 
 +
| [https://pypi.python.org/pypi/python-senlinclient python-senlinclient]    || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen" | Voting || style="background-color: lightgreen" | On PyPI ||  ||
 
|-
 
|-
  
Line 430: Line 440:
  
 
| ldappool || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | Yes ||
 
| ldappool || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | Yes ||
 +
|-
 +
 +
| monasca-statsd || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | Yes ||
 
|-
 
|-
  
Line 438: Line 451:
 
|-
 
|-
  
 +
| octavia-lib || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | Yes ||
 +
|-
  
 
| [https://pypi.python.org/pypi/os-brick os-brick] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | Yes || os-brick 0.3.2 added Python 3 support.
 
| [https://pypi.python.org/pypi/os-brick os-brick] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | Yes || os-brick 0.3.2 added Python 3 support.
Line 458: Line 473:
 
|-
 
|-
  
| osc-placement || style="background-color: red;" | No || style="background-color: red;" | n/a || style="background-color: red;" | Yes ||
+
| osc-placement || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | Yes ||
No py35 jobs configured.
 
 
|-
 
|-
  
Line 492: Line 506:
 
=== OpenStack applications (tc:approved-release) ===
 
=== OpenStack applications (tc:approved-release) ===
  
OpenStack applications [http://governance.openstack.org/reference/tags/tc-approved-release.html approved by the OpenStack Technical Committee].
+
OpenStack applications [https://governance.openstack.org/tc/reference/tags/tc_approved-release.html#tag-tc-approved-release approved by the OpenStack Technical Committee].
  
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
 
|-
 
|-
! Project !! Unit tests pass on Python 3 !! py35 gate !! functional tests !! Comments
+
! style="width: 10%;" | Project !! style="width: 10%;" | Unit tests pass on Python 3 !! style="width: 10%;" | py35 gate !! style="width: 20%;" | functional tests !! Comments
 
|-
 
|-
  
| [https://pypi.python.org/pypi/ceilometer ceilometer] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | no integrated gate job ||
+
| [https://pypi.python.org/pypi/ceilometer ceilometer] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
|-
 
|-
  
Line 506: Line 520:
 
|-
 
|-
  
| designate || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" |designate-devstack-pdns4-py35 ||
+
| designate || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | designate-bind9-py36 designate-bind9-py35 || ! style="background-color: orange;" | Relies on oslo.service WSGI code that does not work under Python 3 with SSL. Functional tempest tests are ran on both of these jobs. [http://lists.openstack.org/pipermail/openstack-dev/2018-May/130277.html]
 
|-
 
|-
  
| [https://pypi.python.org/pypi/glance glance] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | integrated-gate-py35 ||
+
| [https://pypi.python.org/pypi/glance glance] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | integrated-gate-py35 || ! style="background-color: orange;" | Relies on oslo.service WSGI code that does not work under Python 3. [http://lists.openstack.org/pipermail/openstack-dev/2018-May/130277.html]
 
Victor Stinner is working on porting Glance to Python3. Patches: [https://review.openstack.org/#/q/status:open+project:openstack/glance+branch:master+topic:py3,n,z Patches for glance (topic: py3)].
 
Victor Stinner is working on porting Glance to Python3. Patches: [https://review.openstack.org/#/q/status:open+project:openstack/glance+branch:master+topic:py3,n,z Patches for glance (topic: py3)].
 
|-
 
|-
Line 517: Line 531:
 
|-
 
|-
  
| [https://pypi.python.org/pypi/horizon horizon] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | no integrated gate job ||
+
| [https://pypi.python.org/pypi/horizon horizon] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | horizon-openstack-tox-python3-django111,horizon-integration-tests, horizon-dsvm-tempest-plugin ||
 
George Peristerakis wrote [https://blueprints.launchpad.net/horizon/+spec/porting-python3 Make Horizon python3.4 compatible] in May 2015, the blueprint was approved. Patches: [https://review.openstack.org/#/q/topic:bp/porting-python3+project:openstack/horizon,n,z bp/porting-python3 topic].
 
George Peristerakis wrote [https://blueprints.launchpad.net/horizon/+spec/porting-python3 Make Horizon python3.4 compatible] in May 2015, the blueprint was approved. Patches: [https://review.openstack.org/#/q/topic:bp/porting-python3+project:openstack/horizon,n,z bp/porting-python3 topic].
 
|-
 
|-
Line 534: Line 548:
 
|-
 
|-
  
| neutron-lbaas || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | no integrated gate job ||
+
| neutron-lbaas || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | neutron-lbaasv2-dsvm-py3x-api and neutron-lbaasv2-dsvm-py3x-api-namespace ||
 
Patches: [https://review.openstack.org/#/q/topic:bp/neutron-python3 topic:bp/neutron-python3].
 
Patches: [https://review.openstack.org/#/q/topic:bp/neutron-python3 topic:bp/neutron-python3].
 
|-
 
|-
  
| neutron-fwaas || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | no integrated gate job ||
+
| neutron-fwaas || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | neutron-fwaas-networking-midonet-cross-py35 (non-voting) ||
 
|-
 
|-
  
| neutron-vpnaas || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | no integrated gate job ||
+
| neutron-vpnaas || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
|-
 
|-
  
| [https://pypi.python.org/pypi/nova nova] || style="background-color: orange;" | work in progress || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | integrated-gate-py35 ||
+
| [https://pypi.python.org/pypi/nova nova] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | integrated-gate-py35 ||
Status at 2016-06-22: 10,284/13,477 unit tests passed (76%), TODO: 3,193 tests
+
Status at 2019-01-24: Unit tests all running and voting under Python 3 via the use of the mox3 package. There are only 3 unit test files left that are using mox3 (nova/tests/unit/cells/test_cells_messaging.py, nova/tests/unit/network/test_neutronv2.py, nova/tests/unit/network/test_manager.py).
 
 
Status at 2016-06-28: Matt Riedemann: "Keep in mind that Thursday 6/30 is the nova non-priority blueprint feature freeze (end of day really). So the majority of review focus this week should be on non-priority blueprints." Sylvain Bauzas: "Well, IIRC we discussed in the previous year on some of those blueprints (including the Py3 effort) that are not really features (rather refactoring items) and which shouldn't be hit by the non-priority feature freeze."
 
 
 
Status at 2016-08-01: Michael Still: "Per Matt's email, the merge window for these is now closed in Newton."
 
 
 
Status at 2016-09-22: 11,221/14,298 unit tests passed (78%), TODO: 3077 tests
 
 
 
Status at 2017-01-05: 13,888/14,537 unit tests passed (96%), TODO: 649 tests
 
 
 
Links:
 
 
 
* Paches: [https://review.openstack.org/#/q/topic:bp/nova-python3-newton  bp/nova-python3-newton]
 
* [https://blueprints.launchpad.net/nova/+spec/nova-python3-newton nova-python3-newton blueprint]
 
* [http://specs.openstack.org/openstack/nova-specs/specs/liberty/approved/adding-python34-support-to-nova.html Adding Python 3.4 support to Nova] spec (by Victor Stinner) accepted for Liberty.
 
 
 
See also:
 
  
* Old patches (old topic): [https://review.openstack.org/#/q/project:openstack/nova+branch:master+topic:bp/nova-python3,n,z master (bp/nova-python3)].
+
We advised contributors not to spend time replacing mox in files testing cells v1 and nova-network (test_cells_messaging.py and test_manager.py), as both are slated for removal as soon as we're able. Progress is being tracked at: https://blueprints.launchpad.net/nova/+spec/mox-removal-stein
* dims: [https://review.openstack.org/#/c/261045/ python3: byte/string conversions and enable more tests] (abandonned after 100 revisions)
 
* dims: [https://review.openstack.org/#/c/262083/ python3: Port more code to python3] (abandonned after 45 revisions)
 
 
|-
 
|-
  
| [https://pypi.python.org//pypi/sahara sahara] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | no integrated gate job ||
+
| [https://pypi.python.org//pypi/sahara sahara] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | sahara-tests-scenario-py3 (experimental) || Status at 2018-02-23: the job fails during devstack deployment, because swift does not start. The list of its dependencies is minimal and components like keystone are optional. This was partially addressed with an extra dependency: https://review.openstack.org/#/c/544121/ but this requires  a) support in devstack (tentative support in https://review.openstack.org/#/c/544383/) b) at least another extra, or a more generic way of doing this; even with an additional extra explicitly required in devstack, the extras would be installed from pip breaking the test of depending patches.
 +
We are facing an issue with pickle library and python 3, once that gets fixed we can try to make the python 3 gate voting.
 
|-
 
|-
  
| [https://pypi.python.org/pypi/swift swift] || style="background-color: red;" | blocked || style="background-color: lightgreen;" | voting || style="background-color: red;" | no integrated gate job ||
+
| [https://pypi.python.org/pypi/swift swift] || style="background-color: red;" | blocked || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
Status at 2016-06-22: 3/4,498 unit tests (0%), TODO: 4,495 tests
 
Status at 2016-06-22: 3/4,498 unit tests (0%), TODO: 4,495 tests
  
Line 589: Line 586:
  
 
Update 2018-02-22: A list of current blockers: https://gist.github.com/tipabu/833b03a865dba96e9fa2230b82f5d075
 
Update 2018-02-22: A list of current blockers: https://gist.github.com/tipabu/833b03a865dba96e9fa2230b82f5d075
 +
 +
Update 2018-03-06: Current list of blockers with progress notes: https://etherpad.openstack.org/p/Swift_py3
  
 
|-
 
|-
  
| [https://pypi.python.org/pypi/trove trove] || style="background-color: orange;" | work in progress || style="background-color: lightgreen;" | voting || style="background-color: orange;" | no integrated gate job ||
+
| [https://pypi.python.org/pypi/trove trove] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | trove-devstack-base ||
 +
Status at 2019-01-06:
 +
Unit tests - 1708 tests, 1707 passed, 1 skipped.
 +
 
 +
Integration tests are based on trove-devstack-base job.
 +
 
 
Status at 2016-07-25: 1,155 / 2,014 (run_tests.py: 398; testr: 1,521; generate_examples: 95) unit tests (57%), TODO: 859 tests
 
Status at 2016-07-25: 1,155 / 2,014 (run_tests.py: 398; testr: 1,521; generate_examples: 95) unit tests (57%), TODO: 859 tests
  
Line 616: Line 620:
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
 
|-
 
|-
! Project !! Unit tests pass on Python 3 !! py35 gate !! Comments
+
! style="width: 10%;" |  Project !! style="width: 10%;" |  Unit tests pass on Python 3 !! style="width: 10%;" |  py35 gate || style="width: 20%;" | functional tests !! Comments
 +
|-
 +
 
 +
| adjutant || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | Partial* || (*) Adjutant's unit tests include a suite of API tests against Adjutant APIs using DRF's internal test classes. While not true functional tests, they do stand up an internal web server and process real workloads from Adjutant's perspective, with mocking for external APIs and services (Keystone, Nova, Neutron, etc) in the places we touch their clients. This tests 92% of the code, so in all likelihood covers most py3 vs py2 issues. Tempest tests are also planned for later.
 
|-
 
|-
  
| [https://pypi.python.org/pypi/aodh aodh] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://pypi.python.org/pypi/aodh aodh] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
|-
 
|-
  
| [https://pypi.python.org/pypi/barbican barbican] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||  
+
| [https://pypi.python.org/pypi/barbican barbican] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||  style="background-color: lightgreen;" | unspecified ||
 
Blueprint [https://blueprints.launchpad.net/barbican/+spec/barbican-py3 barbican-py3].
 
Blueprint [https://blueprints.launchpad.net/barbican/+spec/barbican-py3 barbican-py3].
 
|-
 
|-
  
| blazar || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| blazar || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | blazar-devstack-dsvm-py35 ||
 
|-
 
|-
  
| cloudkitty || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| cloudkitty || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | cloudkitty-tempest-full-python3 ||
 
|-
 
|-
  
| [https://pypi.python.org/pypi/congress congress] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://pypi.python.org/pypi/congress congress] || style="background-color: lightgreen;" | Yes || style="background-color: orange;" | voting* || style="background-color: lightgreen;" | congress-devstack-py35-api-mysql ||
 +
(*)py35 support required tiny modification to antlr3 package, creating debian packaging difficulty
 +
 
 
Random Stacker wrote a [https://blueprints.launchpad.net/congress/+spec/support-python3 support-python3 blueprint]. Patches: [https://review.openstack.org/#/q/project:openstack/congress+branch:master+topic:bp/support-python3,n,z search for the topic bp/support-python3].
 
Random Stacker wrote a [https://blueprints.launchpad.net/congress/+spec/support-python3 support-python3 blueprint]. Patches: [https://review.openstack.org/#/q/project:openstack/congress+branch:master+topic:bp/support-python3,n,z search for the topic bp/support-python3].
 
|-
 
|-
  
| [https://pypi.python.org/pypi/cue cue] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| cyborg || style="background-color: red;" | No job || style="background-color: red;" | No job || style="background-color: red;" | no job ||
Patches: [https://review.openstack.org/#/q/status:open+project:openstack/cue+branch:master+topic:py3,n,z search for topic py3].
 
 
|-
 
|-
  
| [https://pypi.python.org/pypi/designate designate] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://pypi.python.org/pypi/designate designate] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | designate-devstack-pdns4-py35 (check queue only) ||
 
Pradeep Kumar Singh proposed the [https://blueprints.launchpad.net/designate/+spec/designate-py3 blueprint designate-py3] which was accepted for Liberty. Patches: [https://review.openstack.org/#/q/status:open+project:openstack/designate+branch:master+topic:bp/designate-py3,n,z topic:bp/designate-py3].
 
Pradeep Kumar Singh proposed the [https://blueprints.launchpad.net/designate/+spec/designate-py3 blueprint designate-py3] which was accepted for Liberty. Patches: [https://review.openstack.org/#/q/status:open+project:openstack/designate+branch:master+topic:bp/designate-py3,n,z topic:bp/designate-py3].
 
|-
 
|-
  
| [https://pypi.python.org/pypi/freezer freezer] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://pypi.python.org/pypi/ec2-api ec2-api] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | openstack-tox-py35 ||
 +
|-
 +
 
 +
| [https://pypi.python.org/pypi/freezer freezer] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 +
|-
 +
 
 +
| karbor || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 +
|-
 +
 
 +
| [https://pypi.python.org/pypi/kuryr-kubernetes kuryr] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | openstack-tox-py35 ||
 +
|-
 +
 
 +
| [https://pypi.python.org/pypi/magnum magnum] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | (voting: magnum-functional-api) AND (non-voting: magnum-functional-k8s AND magnum-functional-swarm-mode) ||
 +
|-
 +
 
 +
| [https://github.com/openstack/manila manila] || style="background-color: lightgreen;" | Yes  || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" |  manila-tempest-minimal-dsvm-dummy || ||
 
|-
 
|-
  
| karbor || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://github.com/openstack/manila-ui manila-ui] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | horizon-openstack-tox-python3-django111 ||
 
|-
 
|-
  
| [https://pypi.python.org/pypi/magnum magnum] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| masakari || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | openstack-tox-py35 ||
 
|-
 
|-
  
| [https://github.com/openstack/manila manila] || style="background-color: lightgreen;" | Yes but... (*) || style="background-color: lightgreen;" | voting ||
+
| [https://pypi.python.org/pypi/mistral mistral] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
Valeriy Ponomaryov wrote the [https://blueprints.launchpad.net/manila/+spec/py3-compatibility py3-compatibility blueprint].
+
|-
  
(*) SSL tests are skipped because of the bug [https://bugs.launchpad.net/manila/+bug/1482633 requests to SSL wrapped sockets hang while reading using py3].
+
| monasca-agent || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | monasca-tempest-python3-influxdb || https://storyboard.openstack.org/#!/story/2000975 ||
 
|-
 
|-
  
| [https://pypi.python.org/pypi/mistral mistral] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| monasca-api || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | monasca-tempest-python3-influxdb || https://storyboard.openstack.org/#!/story/2000975 ||
 
|-
 
|-
  
| monasca-api || style="background-color: lightgreen;" | Yes || style="background-color: orange;" | non-voting ||
+
| monasca-log-api || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | monascalog-python3-tempest ||
 
|-
 
|-
  
| monasca-log-api || style="background-color: lightgreen;" | Yes || style="background-color: orange;" | voting ||
+
| monasca-ui || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job || https://storyboard.openstack.org/#!/story/2000975 ||
 
|-
 
|-
  
| [https://pypi.python.org/pypi/murano murano] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://pypi.python.org/pypi/murano murano] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
Blueprint: [https://blueprints.launchpad.net/murano/+spec/murano-python-3-support murano-python-3-support].
 
Blueprint: [https://blueprints.launchpad.net/murano/+spec/murano-python-3-support murano-python-3-support].
 
|-
 
|-
  
| murano-agent || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| murano-agent || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
Blueprint: [https://blueprints.launchpad.net/murano/+spec/murano-python-3-support murano-python-3-support].
 
Blueprint: [https://blueprints.launchpad.net/murano/+spec/murano-python-3-support murano-python-3-support].
 
|-
 
|-
  
| [https://wiki.openstack.org/wiki/Octavia octavia] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://wiki.openstack.org/wiki/Octavia octavia] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | octavia-tox-functional-py35 ||
 +
|-
 +
 
 +
| panko || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | panko-tox-py35-mysql and panko-tox-py35-postgresql ||
 
|-
 
|-
  
| panko || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| qinling || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
|-
 
|-
  
| [https://pypi.python.org/pypi/rally rally] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || A big thank to Andrey Kurilin for a lot of work in this direction
+
| [https://pypi.python.org/pypi/rally rally] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | rally-tox-functional-py3 and rally-tox-self ||
 +
A big thank to Andrey Kurilin for a lot of work in this direction
 
|-
 
|-
  
| [https://wiki.openstack.org/wiki/Searchlight searchlight] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://wiki.openstack.org/wiki/Searchlight searchlight] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | openstack-tox-py36 ||
 
|-
 
|-
  
| [https://wiki.openstack.org/wiki/Senlin senlin] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://wiki.openstack.org/wiki/Senlin senlin] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | senlin-dsvm-tempest-py35-api, senlin-dsvm-tempest-py35-functional, senlin-dsvm-tempest-py35-integration (check only, non-voting) ||
 
|-
 
|-
  
| [https://wiki.openstack.org/wiki/Solum solum] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://wiki.openstack.org/wiki/Solum solum] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | solum-devstack-py35 (check only) ||
 
Victor Stinner proposed the [https://blueprints.launchpad.net/solum/+spec/solum-python3 blueprint solum-python3] which was approved. Patches: [https://review.openstack.org/#/q/status:open+topic:bp/solum-python3,n,z search for bp/solum-python3 topic] (open reviews).
 
Victor Stinner proposed the [https://blueprints.launchpad.net/solum/+spec/solum-python3 blueprint solum-python3] which was approved. Patches: [https://review.openstack.org/#/q/status:open+topic:bp/solum-python3,n,z search for bp/solum-python3 topic] (open reviews).
 
|-
 
|-
  
| storlets || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| storlets || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job (likely blocked on swift) ||
 +
|-
 +
 
 +
| tacker || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: orange;" | tacker-functional-devstack-python3 (check only, non-voting) ||
 +
|-
 +
 
 +
| tricircle || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
|-
 
|-
  
| tacker || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| vitrage || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | vitrage-dsvm-api-py35 and vitrage-dsvm-datasources-py35 ||
 
|-
 
|-
  
| tricircle || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://wiki.openstack.org/wiki/Watcher watcher] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
|-
 
|-
  
| vitrage || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://wiki.openstack.org/wiki/Zaqar zaqar] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
|-
 
|-
  
| [https://wiki.openstack.org/wiki/Watcher watcher] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://github.com/openstack/zun zun] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: lightgreen;" | zun-tempest-py35-docker-sql ||
 
|-
 
|-
  
| [https://wiki.openstack.org/wiki/Zaqar zaqar] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| networking-l2gw || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting || style="background-color: red;" | no job ||
 
|-
 
|-
  
| [https://github.com/openstack/zun zun] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://pypi.org/project/vmware-nsx vmware-nsx] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||  style="background-color: lightgreen;" | All 3rd part CI jobs are running python 3  ||
 
|-
 
|-
  
| networking-l2gw || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||
+
| [https://pypi.org/project/vmware-nsxlib vmware-nsxlib] || style="background-color: lightgreen;" | Yes || style="background-color: lightgreen;" | voting ||  style="background-color: lightgreen;" |  tempest-api-vmware-nsxv3 is running python 3.5 and is voting ||
 
|-
 
|-
  
Line 737: Line 770:
 
  sudo python3 -m pip install python-memcached  # needed by keystonemiddleware
 
  sudo python3 -m pip install python-memcached  # needed by keystonemiddleware
  
* localrc: add the following lines
+
* localrc: add the following line
  
 
  USE_PYTHON3=True
 
  USE_PYTHON3=True
PYTHON3_VERSION=3.4
 
  
 
See [https://review.openstack.org/#/c/414176/ Switch to python 3.5].
 
See [https://review.openstack.org/#/c/414176/ Switch to python 3.5].
Line 770: Line 802:
 
* There is no Jenkins job using Python 3.5 yet
 
* There is no Jenkins job using Python 3.5 yet
 
* /usr/bin/python3 is Python 3.5 in Fedora 24, Ubuntu 16.04 LTS (Xenial Xerus) and Debian Stretch (Testing)
 
* /usr/bin/python3 is Python 3.5 in Fedora 24, Ubuntu 16.04 LTS (Xenial Xerus) and Debian Stretch (Testing)
 +
 +
=== Python 3.6 status ===
 +
 +
Python 3.6 is scheduled to be the default/only version of Python available in Ubuntu 18.04 LTS (Bionic Beaver) and Debian 10 (Buster).
 +
 +
Known issues:
 +
 +
* eventlet<0.21.0 is broken with Python 3.6, see https://github.com/eventlet/eventlet/issues/371. There is also https://github.com/eventlet/eventlet/issues/401 which is fixed in 0.22.0, so it might seem feasible to upgrade to eventlet-0.22.1 once we can do proper testing.
 +
* Horizon explicitly only claims support for Python 3.5, when running devstack with Python 3.6 one needs to set:
 +
    ENABLED_PYTHON3_PACKAGES=horizon
  
 
== Status of Python 3 in Linux distributions ==
 
== Status of Python 3 in Linux distributions ==
  
 
* ArchLinux already [https://www.archlinux.org/news/python-is-now-python-3 switched to Python 3 by default] in 2011
 
* ArchLinux already [https://www.archlinux.org/news/python-is-now-python-3 switched to Python 3 by default] in 2011
* Ubuntu wants to remove Python 2 from the default installation for Ubuntu 16.04 LTS: see [https://wiki.ubuntu.com/Python (Python) Plans for 16.04].
+
* Ubuntu wants to remove Python 2 from the default installation for Ubuntu 18.04 LTS: see [https://wiki.ubuntu.com/Python (Python) Plans for 18.04].
 
* Fedora schedules the switch in Fedora 23 (october 2015): [https://fedoraproject.org/wiki/Changes/Python_3_as_Default Python 3 as the Default Implementation]
 
* Fedora schedules the switch in Fedora 23 (october 2015): [https://fedoraproject.org/wiki/Changes/Python_3_as_Default Python 3 as the Default Implementation]
 
** [http://fedora.portingdb.xyz/ Python 3 Porting Database for Fedora] and [http://fedora.portingdb.xyz/history/ history of packages tracked by the Fedora portingdb]
 
** [http://fedora.portingdb.xyz/ Python 3 Porting Database for Fedora] and [http://fedora.portingdb.xyz/history/ history of packages tracked by the Fedora portingdb]
Line 780: Line 822:
 
* RHEL: [https://www.softwarecollections.org/en/scls/rhscl/python33/ Python 3.3] and [https://www.softwarecollections.org/en/scls/rhscl/rh-python34/ Python 3.4] are available on RHEL6 and RHEL7 using SCL.
 
* RHEL: [https://www.softwarecollections.org/en/scls/rhscl/python33/ Python 3.3] and [https://www.softwarecollections.org/en/scls/rhscl/rh-python34/ Python 3.4] are available on RHEL6 and RHEL7 using SCL.
 
* CentOS: [https://www.softwarecollections.org/en/scls/rhscl/python33/ Python 3.3] and [https://www.softwarecollections.org/en/scls/rhscl/rh-python34/ Python 3.4] are available on CentOS 6 and 7 using SCL (no Red Hat subscription needed, CentOS has its own flavor of SCL)
 
* CentOS: [https://www.softwarecollections.org/en/scls/rhscl/python33/ Python 3.3] and [https://www.softwarecollections.org/en/scls/rhscl/rh-python34/ Python 3.4] are available on CentOS 6 and 7 using SCL (no Red Hat subscription needed, CentOS has its own flavor of SCL)
* In Debian, the plan is to deprecate Python 2 in Stretch (aka: Debian 9, the next Stable Debian after Jessie) and to completely remove Python 2 for the Buster release of Debian (aka: Debian 10, to be release in approximatively 2019).
+
* In Debian, the plan is to deprecate Python 2 in Stretch (aka: Debian 9, the next Stable Debian after Jessie) and to completely remove Python 2 for the Buster release of Debian (aka: Debian 10, to be released in approximatively 2019).
 +
 
 +
Check the [https://governance.openstack.org/tc/reference/project-testing-interface.html#linux-distributions Project Testing Interface] for updates about the platforms each release is tested on.
  
 
== Status of Python 2 Support Being Dropped in Dependencies ==
 
== Status of Python 2 Support Being Dropped in Dependencies ==
Line 790: Line 834:
 
** https://github.com/Pylons/pyramid/issues/2903
 
** https://github.com/Pylons/pyramid/issues/2903
 
** This is the same team that maintains webob, but it isn't clear if they intend to also drop support there.
 
** This is the same team that maintains webob, but it isn't clear if they intend to also drop support there.
 +
 +
[https://governance.openstack.org/tc/resolutions/20180529-python2-deprecation-timeline.html OpenStack plans to start dropping Python 2 support at the start of the U cycle]
  
 
== Progress reports, meetings and sprints ==
 
== Progress reports, meetings and sprints ==

Latest revision as of 14:17, 7 March 2019

This page tracks the progress of Python 3 effort porting for OpenStack.

IRC: #openstack-dev

Join the #openstack-dev IRC channel on the Freenode network to discuss Python 3.

Python 3

Why should OpenStack move to Python 3 right now?

Python 3 is usually seen as the new Python version which breaks compatibility and raises new Unicode issues. Python 3 is much more than that. It’s a new clean language which has a more consistent syntax. It has many new features, not less than 15 new modules. Python 3 is already well supported by major Linux distributions, whereas Python 2.7 reached its end-of-life. Slowly, some bugs cannot be fixed in Python 2.7 anymore and are only fixed in the latest Python 3 release. Python 3 is now 5 years old and considered as a mature programming language.

Python 2: Python 2.6 support dropped, Python 2.7 only

OpenStack Liberty targets Python 2.7 and 3.4.

Python 2.6 support is being dropped in OpenStack since OpenStack Juno for servers. Python 2.6 support is currently kept in Oslo libraries and clients. See juno-cross-project-future-of-python etherpad.

Python 3.3 support is being dropped since OpenStack Liberty.

Python 2.6 is slowly being dropped in the whole OpenStack project, ex: Remove p26 job from DIB.

Python 2.6 support will be removed in Oslo and Clients clients for OpenStack Mitaka: Oslo libraries dropping python 2.6 compatability.

Port Python 2 code to Python 3

OpenStack project chose to use the same code base for Python 2 and Python 3. The Six: Python 2 and 3 Compatibility Library helps to write code working on both versions. OpenStack supported Python 2.6 for RHEL up to Juno, but not Python 2.5 and older. As we are targeting Python 3.4 and up, there is no need to avoid u'unicode' syntax. Do not use six.u('unicode').

Before you begin

If you're doing development with Ubuntu/Debian (and not using devstack with the USE_PYTHON flag set), then you'll need the following packages installed to run the py34 tox unit test targets in the projects:

   sudo apt-get install python3.4 python3.4-dev

sixer tool

The sixer tool helps to replace most basic patterns to add Python 3 compatibility and it respects OpenStack coding style.

Common patterns

  • Replace "for key in dict.iterkeys()" with "for key in dict"
  • Replace dict.iteritems() with dict.items()
  • Replace dict.itervalues() with dict.values()

Note: Replacing dict.iteritems()/.itervalues() with six.iteritems(dict)/six.itervalues(dict) was preferred in the past, but there was a discussion suggesting to avoid six for this. The overhead of creating a temporary list on Python 2 is negligible.

  • Replace iterator.next() with next(iterator)
  • Replace basestring with six.string_types
  • Replace unicode with six.text_type
  • Replace (str, unicode) with six.string_types
  • Replace (int, long) with six.integer_types
  • Replace func.func_name with func.__name__
  • Replace exceptions.OSError with OSError and remove "import exceptions"
  • map() and filter() if a list is needed on Python 3:
    • Replace map(func, data) with [func(item) for item in data]
    • Replace filter(lambda obj: test(obj), data) with [obj for obj in data if test(obj)]
    • Note: Usually, tests fail because map() or filter() objects have no length

Serialization: base64, JSON, etc.

  • [with oslo.serialization 1.10 or newer] Get the base64 module from oslo_serialization (from oslo_serialization import base64) to get functions:
    • oslo_serialization.base64.decode_as_bytes(encoded)
    • oslo_serialization.base64.decode_as_text(encoded, encoding='utf-8')
    • oslo_serialization.base64.encode_as_bytes(s, encoding='utf-8')
    • oslo_serialization.base64.encode_as_text(s, encoding='utf-8')
  • Replace text.encode('base64') and base64.b64encode(text) with:
    • base64.b64encode(text): only accept bytes and returns bytes,
    • or: oslo_serialization.base64.encode_as_bytes(text): accept bytes or Unicode and returns bytes
    • or: oslo_serialization.base64.encode_as_text(text): accept bytes and Unicode and returns Unicode
    • Warning: base64.encodestring(raw) adds a newline ("\n"), whereas encode_as_bytes() and encode_as_text() don't.
  • Replace raw.decode('base64') with:
    • base64.b64decode(raw): return bytes
    • oslo_serialization.base64.decode_as_bytes(encoded): accept bytes and Unicode, returns bytes
    • oslo_serialization.base64.decode_as_text(encoded): accept bytes and Unicode, returns Unicode

Hexadecimal:

  • Replace raw.decode('hex') with binascii.unhexlify(raw)
  • Replace bytes.encode('hex') with binascii.hexlify(bytes)

JSON:

  • [with oslo.serialization 1.10 or newer] Replace json.dumps(obj) with oslo_serialization.jsonutils.dump_as_bytes(obj)
  • Replace json.loads(obj) with oslo_serialization.jsonutils.loads(obj): it accepts bytes and Unicode, bytes is decoded from UTF-8. It avoids "if isinstance(obj, bytes): obj = obj.decode('utf-8')" which may require a second temporary variable.

contextlib.nested

To replaced contextlib.nested is to use contextlib.ExitStack. It's available on Python 2 using contextlib2.ExitStack. For contextlib.nested, nova/test.py defines:

if six.PY3:
    @contextlib.contextmanager
    def nested(*contexts):
        with contextlib.ExitStack() as stack:
            yield [stack.enter_context(c) for c in contexts]
else:
    nested = contextlib.nested

Another option to replaced contextlib.nested is to use the @mock.patch decorator. Example with nested function:

def test_thing(self):
   @mock.patch(...)
   @mock.patch(...)
   @mock.patch(...)
   def do_test(...):
       ...
   do_test()

More options:

oslo_utils.encodeutils.to_utf8

oslo.utils 3.5 has an oslo_utils.encodeutils.to_utf8() function to encode Unicode to UTF-8 and return bytes unchanged.

bytes.decode and unicode.encode

Python has a notion of "default encoding": sys.getdefaultencoding(). On Python 2, the default encoding is ASCII, whereas it is UTF-8 on Python 3.

Don't write data.decode() or text.encode() without parameter, because you will use a different encoding on Python 2 and Python 3.

Use an explicit encoding instead. Example: data.decode('utf-8') or text.encode('utf-8'). The right encoding depends on the use case, but UTF-8 is usually a good candidate (it is a superset of ASCII).

safe_decode

Olso Incubator has a function safe_decode() which can be used to decode a bytes string and pass text strings unchanged.

The default encoding is sys.stdin.encoding or sys.getdefaultencoding():

  • Python 3: the locale encoding, or UTF-8 if sys.stdin is "mocked" (io.StringIO instance)
  • Python 2: the locale encoding, or ASCII if stdin is not a TTY or if sys.stdin is "mocked" (StringIO.StringIO instance)

It's safer to explicit the encoding to not rely on the locale encoding and have the same behaviour even if sys.stdin is "mocked".

Safe usage:

  • safe_decode(data, 'utf-8'): decode bytes from UTF-8 or returns data unchanged if it's already a text string

Unsafe usage:

  • safe_decode(data)

By default, the decoder is strict. You can specify a different error handler using the optional errors parameter. Example: safe_decode(b'[\xff]', 'ascii', 'ignore') returns '[]'.

safe_encode

Olso Incubator has a function safe_encode() which can be used to encode a string. Its usage is tricky and you should understand how it works and which encodings are used.

  • safe_encode(text) encodes text to the output encoding
  • safe_encode(bytes) may decode the string and then reencode to a different encoding if input and output encodings are different

The default input encoding (incomding parameter) is sys.stdin.encoding or sys.getdefaultencoding():

  • Python 3: the locale encoding, or UTF-8 if sys.stdin is "mocked" (io.StringIO instance)
  • Python 2: the locale encoding, or ASCII if stdin is not a TTY or if sys.stdin is "mocked" (StringIO.StringIO instance)

The default output encoding (encoding parameter) is UTF-8.

It's safer to explicit the input encoding to not rely on the locale encoding and have the same behaviour even if sys.stdin is "mocked".

Safe usage:

  • safe_encode(data, incoming='utf-8'): encode text to UTF-8 or returns data unchanged if it's already a bytes string (since the input and output encoding are UTF-8)

Unsafe usage:

  • safe_encode(data)

Example:

  • safe_encode(b'\xe9', incoming='latin-1') returns b'\xc3\xa9'.

By default, the encoder and the decoder are strict. You can specify a different error handler using the optional errors parameter. Example: safe_encode(b'[\xff]', incoming='ascii', errors='ignore') returns b'[]'.

logging module and format exceptions

The exception_to_unicode(exc) function of oslo_utils.encodeutils is the recommanded way to format an exception to Unicode. This function works on Python 2 and Python 3 and it should avoid mojibake is most cases.

On Python 2, the logging module accepts bytes and text strings. On Python 3, it only accepts text strings. For example, logging.error(b'hello') logs b'hello' instead of 'hello'.

There is no clear rule for format exceptions yet. There are different choices depending on the project:

  • str(exc): native string, so use bytes on Python 2
  • six.text_type(exc): always use Unicode. It may raise unicode error depending on the exception, be careful. Example of such error in python 2: unicode(Exception("nonascii:\xe9")).
  • six.u(str(exc)): unsafe on Python 2 if str(exc) contains non-ASCII bytes, ex: unicode(str(Exception("\xff")))
  • LOG.exception(_LE("... %(exc)s ..."), {"exc": exc, ...})

Since logging functions expect text strings on Python 3, logged exceptions should be formatted using str(exc). Example: LOG.debug(str(exc)).

HTTP

The HTTP protocol is based on bytes:

  • HTTP body contains bytes. For example, use io.BytesIO for a stream storing an HTTP body.
  • HTTPConnection.getresponse().read() returns bytes (in Python 3, str which is bytes in Python 2)
  • On Python 3, the http.client accepts text for HTTP headers: keys are encoded to ASCII and values to ISO 8859-1 (which is only a small subset of the Unicode charset)
  • It looks like Swift encodes internally HTTP headers to UTF-8 (directly using the UTF-8 encoding, not using a MIME encoding like =?UTF-8?Q?...?=. See the HTTP [RFC 2047 http://www.ietf.org/rfc/rfc2047.txt] and HTTP header should use what character encoding?

References to port Python 2 code to Python 3

Common pitfalls

What is a string ?

You should definitely not talk about "strings" in your commit logs/reviews. In Python 2, a 'string' is bytes; in Python 3, it's a Unicode text string. The following code snippet may help in understanding the difference:

Python 2:

   >>> type('foo')
   <type 'str'>
   >>> type(u'foo')
   <type 'unicode'>
   >>> type(b'foo')
   <type 'str'>
   >>> isinstance('foo', six.text_type)
   False
   >>> isinstance(u'foo', six.text_type)
   True
   >>> bytes is str
   True
   >>> b'foo'[0]
   'f'

Python 3:

   >>> type('foo')
   <class 'str'>
   >>> type(u'foo')
   <class 'str'>
   >>> type(b'foo')
   <class 'bytes'>
   >>> isinstance('foo', six.text_type)
   True
   >>> isinstance(b'foo', six.text_type)
   False
   >>> bytes is str
   False
   >>> b'foo'[0]
   102

tox/testr error: db type could not be determined

The "db type could not be determined" error comes from .testrepository/times.dbm used by testr.

Workaround: "rm -rf .testrepository/" and then run "tox -e py34" before running "tox -e py27". You only have to do this once. The problem only occurs with "tox -e py34" when .testrepository/ was created by Python 2.

Python 3 Status of OpenStack projects

Common Libraries (Oslo Projects)

See programs.yaml for the list of Common Libraries.

Project Python 3 compatibility Comment
automaton Yes
castellan Yes
cliff Yes
debtcollector Yes
futurist Yes
oslo.cache Yes
oslo.concurrency Yes
oslo.config Yes
oslo.context Yes
oslo.db Yes

PyMySQL driver is now used by default for MySQL. setup.cfg contains the Python 3 classifier.

oslo.i18n Yes
oslo.log Yes
oslo.messaging Yes

oslo.messaging is now fully compatible with Python 3. The old (and now removed) Qpid transport was not compatible, the AMQP driver was ported recently.

oslo.middleware Yes
oslo.policy Yes
oslo.privsep Yes
oslo.reports Yes
oslo.rootwrap Yes
oslo.serialization Yes
oslo.service Partial

WSGI module SSL support is broken under Python 3. We want projects to support deployment without relying on that code, but not all do (see glance and designate below).

oslotest Yes
oslo.versionedobjects Yes
oslo.vmware Yes Supports Python 3 since oslo.vmware 0.13.0
oslo.utils Yes
pylockfile Yes
stevedore Yes
taskflow Yes
tooz Yes

Development tools

Project Python 3 compatibility Comment
cookiecutter yes
hacking yes
pbr yes
stackforge/python-jenkins yes py33 gate is voting
openstack-infra/jenkins-job-builder partial https://review.openstack.org/172238

OpenStack clients

Project Python 3 compatibility CI tests running? Python 3 classifiers ? Blocked by Comment
keystonemiddleware Yes Voting On PyPI python-memcached keystonemiddleware 1.6.1 supports Python 3.
python-barbicanclient Yes Voting On PyPI
python-ceilometerclient Yes Voting On PyPI
python-cinderclient Yes Voting On PyPI
python-fuelclient Yes voting On PyPI
python-glanceclient Yes Voting On PyPI
python-heatclient Yes Voting On PyPI
python-ironicclient Yes Voting On PyPI
python-keystoneclient Yes Voting On PyPI
python-manilaclient Yes Voting On PyPI
python-marconiclient Yes Voting On PyPI
python-masakariiclient Yes Voting On PyPI
python-monascaclient Yes Voting On PyPI
python-novaclient Yes Voting On PyPI
python-neutronclient Yes Voting On PyPI
python-octaviaclient Yes Voting On PyPI
python-openstackclient Yes Voting On PyPI As of 0.9
python-saharaclient Yes Voting On PyPI
python-searchlightclient Yes Voting On PyPI
python-senlinclient Yes Voting On PyPI
python-swiftclient Yes Voting On PyPI
python-tuskarclient Yes Voting On PyPI
python-troveclient Yes Voting On PyPI
python-watcherclient Yes Voting On PyPI
python-designateclient Yes Voting On PyPI

OpenStack Libraries

Project Python 3 compatibility CI tests running? Python 3 classifiers ? Comment
blazar-nova Yes voting Yes
ceilometermiddleware Yes voting Yes
django_openstack_auth Yes voting Yes

django_openstack_auth 2.0 is fully compatible with Python 3.

glance_store Yes voting Yes glance_store 0.7.0 added the Python 3 support.
heat-translator Yes voting Yes
ironic-lib Yes voting Yes
keystoneauth Yes voting Yes
keystonemiddleware Yes voting Yes
ldappool Yes voting Yes
monasca-statsd Yes voting Yes
mistral-lib Yes voting Yes
neutron-lib Yes voting Yes
octavia-lib Yes voting Yes
os-brick Yes voting Yes os-brick 0.3.2 added Python 3 support.
os-client-config Yes voting Yes
os-traits Yes voting Yes
os-vif Yes voting Yes
os-win Yes voting Yes
osc-lib Yes voting Yes
osc-placement Yes voting Yes
pycadf Yes voting Yes
shade Yes voting Yes
sqlalchemy-migrate Yes voting Yes
sushy Yes voting Yes
taskflow Yes voting Yes
tosca-parser Yes voting Yes

Dependencies: Environment markers

Example to not install the "futures" dependency on Python 3.3 and newer:

futures; python_version < '3.2'

OpenStack applications (tc:approved-release)

OpenStack applications approved by the OpenStack Technical Committee.

Project Unit tests pass on Python 3 py35 gate functional tests Comments
ceilometer Yes voting no job
cinder Yes voting integrated-gate-py35

cinder-python3 blueprint (written by Victor Stinner) has been accepted for Liberty. Patches: bp/cinder-python3 topic. Note: Commit message must use "Partial-Implements: blueprint cinder-python3" to be linked to the blueprint. Kendall Nelson, Ivan Kolodyazhny (core) and Eric Harney (core) prefer this syntax: see COMMIT_MSG.

designate Yes voting designate-bind9-py36 designate-bind9-py35 Relies on oslo.service WSGI code that does not work under Python 3 with SSL. Functional tempest tests are ran on both of these jobs. [1]
glance Yes voting integrated-gate-py35 Relies on oslo.service WSGI code that does not work under Python 3. [2]

Victor Stinner is working on porting Glance to Python3. Patches: Patches for glance (topic: py3).

heat Yes voting heat-functional-convg-mysql-lbaasv2-py35

Sirushti Murugesan wrote and implemented the spec Python34 Support (which was accepted for Liberty). Mitaka version will fully support Python 3. Great job Sirushti Murugesan who did almost all the work!

horizon Yes voting horizon-openstack-tox-python3-django111,horizon-integration-tests, horizon-dsvm-tempest-plugin

George Peristerakis wrote Make Horizon python3.4 compatible in May 2015, the blueprint was approved. Patches: bp/porting-python3 topic.

ironic Yes voting ironic-tempest-dsvm-ipa-partition-pxe_ipmitool-tinyipa-python3

Python 3.4 unit tests are now being run for openstack/ironic. The unit tests are a voting job. Thanks to Victor Sergeyev for all of his work to update the Ironic code to make it pass the unit tests using Python 3.4: Run tests in py34 environment

keystone Yes voting integrated-gate-py35

The move to pyldap and new ldappool were major hurdles solved in Newton. Great work by the Keystone team to get the last things through the gate in Newton.

neutron Yes voting integrated-gate-py35

Porting to Python 3 spec (by Cyril Roelandt) accepted for Liberty, port in progress. Patches of the blueprint neutron-python3

neutron-lbaas Yes voting neutron-lbaasv2-dsvm-py3x-api and neutron-lbaasv2-dsvm-py3x-api-namespace

Patches: topic:bp/neutron-python3.

neutron-fwaas Yes voting neutron-fwaas-networking-midonet-cross-py35 (non-voting)
neutron-vpnaas Yes voting no job
nova Yes voting integrated-gate-py35

Status at 2019-01-24: Unit tests all running and voting under Python 3 via the use of the mox3 package. There are only 3 unit test files left that are using mox3 (nova/tests/unit/cells/test_cells_messaging.py, nova/tests/unit/network/test_neutronv2.py, nova/tests/unit/network/test_manager.py).

We advised contributors not to spend time replacing mox in files testing cells v1 and nova-network (test_cells_messaging.py and test_manager.py), as both are slated for removal as soon as we're able. Progress is being tracked at: https://blueprints.launchpad.net/nova/+spec/mox-removal-stein

sahara Yes voting sahara-tests-scenario-py3 (experimental) Status at 2018-02-23: the job fails during devstack deployment, because swift does not start. The list of its dependencies is minimal and components like keystone are optional. This was partially addressed with an extra dependency: https://review.openstack.org/#/c/544121/ but this requires a) support in devstack (tentative support in https://review.openstack.org/#/c/544383/) b) at least another extra, or a more generic way of doing this; even with an additional extra explicitly required in devstack, the extras would be installed from pip breaking the test of depending patches.

We are facing an issue with pickle library and python 3, once that gets fixed we can try to make the python 3 gate voting.

swift blocked voting no job

Status at 2016-06-22: 3/4,498 unit tests (0%), TODO: 4,495 tests

Update (2016-06-27): master branch is currently in a soft-freeze in order to get encryption middleware merged

Python 3 bugs: https://bugs.launchpad.net/swift/+bug/1614289

Plan to add Python 3 support to Swift. Patches: Patches with the topic py3

Python 3 unit tests require liberasurecode >= 1.0.9 and PyEClib >= 1.0.9. To install liberasurecode (in /usr):

git clone https://bitbucket.org/tsg-/liberasurecode/
cd liberasurecode
/autogen.sh  && /configure --prefix=/usr && make && sudo make install

liberasurecode >= 1.0.9 is available in Ubuntu Precise, Ubuntu Trusty, Fedora 22, Fedora 23 and CentoOS 7.

Update 2018-02-22: A list of current blockers: https://gist.github.com/tipabu/833b03a865dba96e9fa2230b82f5d075

Update 2018-03-06: Current list of blockers with progress notes: https://etherpad.openstack.org/p/Swift_py3

trove Yes voting trove-devstack-base

Status at 2019-01-06: Unit tests - 1708 tests, 1707 passed, 1 skipped.

Integration tests are based on trove-devstack-base job.

Status at 2016-07-25: 1,155 / 2,014 (run_tests.py: 398; testr: 1,521; generate_examples: 95) unit tests (57%), TODO: 859 tests

Status at 2016-06-22: 839 (testtools) / 1,992 (run_tests.py: 398; testr: 1,499; generate_examples: 95) unit tests (42%), TODO: 1,153 tests

Status at 2018-02-22: It appears that only one test is in the blacklist now: guestagent.test_operating_system

run_tests.py (proboscis) failures: https://review.openstack.org/#/c/346905/1

Victor Stinner proposed the trove-python3 blueprint for Mitaka.

From Victor (3/17/2016): "I propose to discuss Python 3 before the summit. For example, prepare a concrete plan to port Trove to Python 3, list technical issues like MySQL-Python, etc."

Patches: search for the bp/trove-python3 topic.

Other OpenStack Applications and Projects

List of all OpenStack projects: projects.yaml.

Project Unit tests pass on Python 3 py35 gate functional tests Comments
adjutant Yes voting Partial* (*) Adjutant's unit tests include a suite of API tests against Adjutant APIs using DRF's internal test classes. While not true functional tests, they do stand up an internal web server and process real workloads from Adjutant's perspective, with mocking for external APIs and services (Keystone, Nova, Neutron, etc) in the places we touch their clients. This tests 92% of the code, so in all likelihood covers most py3 vs py2 issues. Tempest tests are also planned for later.
aodh Yes voting no job
barbican Yes voting unspecified

Blueprint barbican-py3.

blazar Yes voting blazar-devstack-dsvm-py35
cloudkitty Yes voting cloudkitty-tempest-full-python3
congress Yes voting* congress-devstack-py35-api-mysql

(*)py35 support required tiny modification to antlr3 package, creating debian packaging difficulty

Random Stacker wrote a support-python3 blueprint. Patches: search for the topic bp/support-python3.

cyborg No job No job no job
designate Yes voting designate-devstack-pdns4-py35 (check queue only)

Pradeep Kumar Singh proposed the blueprint designate-py3 which was accepted for Liberty. Patches: topic:bp/designate-py3.

ec2-api Yes voting openstack-tox-py35
freezer Yes voting no job
karbor Yes voting no job
kuryr Yes voting openstack-tox-py35
magnum Yes voting (voting: magnum-functional-api) AND (non-voting: magnum-functional-k8s AND magnum-functional-swarm-mode)
manila Yes voting manila-tempest-minimal-dsvm-dummy
manila-ui Yes voting horizon-openstack-tox-python3-django111
masakari Yes voting openstack-tox-py35
mistral Yes voting no job
monasca-agent Yes voting monasca-tempest-python3-influxdb https://storyboard.openstack.org/#!/story/2000975
monasca-api Yes voting monasca-tempest-python3-influxdb https://storyboard.openstack.org/#!/story/2000975
monasca-log-api Yes voting monascalog-python3-tempest
monasca-ui Yes voting no job https://storyboard.openstack.org/#!/story/2000975
murano Yes voting no job

Blueprint: murano-python-3-support.

murano-agent Yes voting no job

Blueprint: murano-python-3-support.

octavia Yes voting octavia-tox-functional-py35
panko Yes voting panko-tox-py35-mysql and panko-tox-py35-postgresql
qinling Yes voting no job
rally Yes voting rally-tox-functional-py3 and rally-tox-self

A big thank to Andrey Kurilin for a lot of work in this direction

searchlight Yes voting openstack-tox-py36
senlin Yes voting senlin-dsvm-tempest-py35-api, senlin-dsvm-tempest-py35-functional, senlin-dsvm-tempest-py35-integration (check only, non-voting)
solum Yes voting solum-devstack-py35 (check only)

Victor Stinner proposed the blueprint solum-python3 which was approved. Patches: search for bp/solum-python3 topic (open reviews).

storlets Yes voting no job (likely blocked on swift)
tacker Yes voting tacker-functional-devstack-python3 (check only, non-voting)
tricircle Yes voting no job
vitrage Yes voting vitrage-dsvm-api-py35 and vitrage-dsvm-datasources-py35
watcher Yes voting no job
zaqar Yes voting no job
zun Yes voting zun-tempest-py35-docker-sql
networking-l2gw Yes voting no job
vmware-nsx Yes voting All 3rd part CI jobs are running python 3
vmware-nsxlib Yes voting tempest-api-vmware-nsxv3 is running python 3.5 and is voting

Unsorted projects:

  • App Catalog
  • Chef OpenStack (Ruby)
  • Kolla: ~2100 lines of Python, but not "tox -e py27" target
  • OpenStack Ansible (Python): Ansible playbooks and roles for deployment
  • Puppet OpenStack (Ruby)
  • TripleO

Enable Python 3 in DevStack

  • Fedora::
sudo dnf install python3-devel
sudo python3 -m pip install python-memcached   # needed by keystonemiddleware
  • localrc: add the following line
USE_PYTHON3=True

See Switch to python 3.5.

Functional and Integration Tests

Etherpad: https://etherpad.openstack.org/p/support-python3.5-functional-tests

Doug Hellmann wrote a cross-project specification to run integration tests on Python 3: Enabling Python 3 for Application Integration Tests (spec approved for Liberty).

Patch for DevStack: Enable optional Python 3 support.

Projects wanting to run their existing functional test suite against their services on Python 3 should:-

  • Add the Python3.4 trove classifier to the setup.cfg configuration file of the respective service.
  • set USE_PYTHON3=True in Devstack's localrc config file before running stack.sh after the DevStack change is merged or cherry-pick until then.
  • set basepython = python3.5 in tox for the necessary functional/integration tests environment.

Then run tox -e<your functional test suite name>. Example:- tox -efunctional to run the functional the tests of a certain project.

Once the functional test suite is reliably passing against the service in a python 3.5 env, the trove classifiers must be updated along with a new gate job being added to the project.

Sirushti Murugesan's attempt on Heat: https://review.openstack.org/#/c/188033/

Python 3.5

Python 3.6 status

Python 3.6 is scheduled to be the default/only version of Python available in Ubuntu 18.04 LTS (Bionic Beaver) and Debian 10 (Buster).

Known issues:

   ENABLED_PYTHON3_PACKAGES=horizon

Status of Python 3 in Linux distributions

Check the Project Testing Interface for updates about the platforms each release is tested on.

Status of Python 2 Support Being Dropped in Dependencies

OpenStack plans to start dropping Python 2 support at the start of the U cycle

Progress reports, meetings and sprints

Articles

Pycon Montreal 2014: Sprint Port OpenStack to Python 3

Enovance organized a sprint to Port OpenStack to Python 3 during 4 days: between April, 14 (Monday) and April, 17 (Thursday) 2014. See the page Python3/SprintPycon2014.