Heat assumes that Python on booted servers is 2.6+

Bug #1375864 reported by Wilfred Hughes
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
Medium
Zane Bitter
Icehouse
Fix Released
Undecided
Unassigned
Juno
Fix Released
Undecided
Unassigned

Bug Description

Heat assumes that the system Python is 2.6+, which breaks on RHEL 5 (it has Python 2.4 as the system python).

When trying to deploy a VM with heat, /var/log/cloud-init-output.log contains:

---------------

  File "/var/lib/cloud/instance/scripts/loguserdata.py", line 39
    os.chmod(fh.baseFilename, 0o600)
                                  ^
SyntaxError: invalid syntax
/var/lib/cloud/instance/scripts/loguserdata.py failed; code 1
2014-09-30 14:06:57,296 - cc_scripts_user.py[WARNING]: failed to run-parts in /var/lib/cloud/instance/scripts
2014-09-30 14:06:57,625 - __init__.py[WARNING]: Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/cloudinit/CloudConfig/__init__.py", line 118, in run_cc_modules
    cc.handle(name, run_args, freq=freq)
  File "/usr/lib/python2.6/site-packages/cloudinit/CloudConfig/__init__.py", line 79, in handle
    [name, self.cfg, self.cloud, cloudinit.log, args])
  File "/usr/lib/python2.6/site-packages/cloudinit/__init__.py", line 324, in sem_and_run
    func(*args)
  File "/usr/lib/python2.6/site-packages/cloudinit/CloudConfig/cc_scripts_user.py", line 31, in handle
    util.runparts(runparts_path)
  File "/usr/lib/python2.6/site-packages/cloudinit/util.py", line 222, in runparts
    raise RuntimeError('runparts: %i failures' % failed)
RuntimeError: runparts: 1 failures

2014-09-30 14:06:57,625 - __init__.py[ERROR]: config handling of scripts-user, None, [] failed

------------------

loguserdata.py was introduced in January 2013: https://github.com/openstack/heat/commit/93c3d93ec481d81e97d4b120384b5e1d93ca6532

and I believe it can be fixed by changing the first line to:

#!/usr/bin/env python2.6

since Python 2.6 is available on RHEL 5, just not the default.

Revision history for this message
Pavlo Shchelokovskyy (pshchelo) wrote :

I do not think that would be an appropriate fix, as RHEL 5 is not the only guest supported by OpenStack and some other quite popular distros don't even have py26 installed by default.

summary: - Heat assumes that Python is 2.6+
+ Heat assumes that Python on booted servers is 2.6+
Changed in heat:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

However cloud-init on RHEL5 is getting its python2.6 is probably the way loguserdata.py should as well. If that is done via explicit shebang, then we may want to allow a property on servers to change this shebang.

Revision history for this message
Zane Bitter (zaneb) wrote :

If this is the only issue then it would be pretty easy to rewrite that one file to work on Python 2.4.

The trickier part would be to find a way to test that so it doesn't break again.

A bigger question might be why anyone is launching brand new RHEL 5 VMs ;)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (master)

Fix proposed to branch: master
Review: https://review.openstack.org/125469

Changed in heat:
assignee: nobody → Zane Bitter (zaneb)
status: Triaged → In Progress
Revision history for this message
Zane Bitter (zaneb) wrote :

Looks like this was what broke it:

http://git.openstack.org/cgit/openstack/heat/commit/?id=ede21a2688241db05a48b0c7e6f810cd8969b7e4

The assumption that we only need to support 2.6 and up is normally valid, but not in this particular case since the code in question runs on the user's server.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/125469
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=95ec13c5725ccc19dfe910fe83eb9bc6799d482e
Submitter: Jenkins
Branch: master

commit 95ec13c5725ccc19dfe910fe83eb9bc6799d482e
Author: Zane Bitter <email address hidden>
Date: Wed Oct 1 15:16:45 2014 -0400

    Fix cloud-init Python syntax for Python < 2.6

    The loguserdata.py file gets uploaded to the servers created by Heat to run
    under cloud-init. Since the default versions of Python installed on the
    user's server may be very old (e.g. RHEL 5 defaults to Python 2.4), avoid
    using the octal syntax introduced for Python 3.0 and backported only as far
    as Python 2.6. (Also avoid the old syntax, which will break on Python 3.x.)

    Also remove use of the "with" statement from loguserdata.py and
    part-handler.py. This statement is only available from Python 2.6 on (or in
    Python 2.5 via "from __future__ import with_statement").

    Finally, remove use of the "except ExceptionType as value" syntax for
    catching exceptions. Again, this was only backported to Python 2.6.

    Change-Id: I89e86d00993d51e2514b1e589503c6d966909403
    Partial-Bug: #1375864

Qiming Teng (tengqim)
Changed in heat:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (stable/juno)

Fix proposed to branch: stable/juno
Review: https://review.openstack.org/188875

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (stable/juno)

Reviewed: https://review.openstack.org/188875
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=140d66e587bce27523ee7ebbeaecbced83082949
Submitter: Jenkins
Branch: stable/juno

commit 140d66e587bce27523ee7ebbeaecbced83082949
Author: Zane Bitter <email address hidden>
Date: Wed Oct 1 15:16:45 2014 -0400

    Fix cloud-init Python syntax for Python < 2.6

    The loguserdata.py file gets uploaded to the servers created by Heat to run
    under cloud-init. Since the default versions of Python installed on the
    user's server may be very old (e.g. RHEL 5 defaults to Python 2.4), avoid
    using the octal syntax introduced for Python 3.0 and backported only as far
    as Python 2.6. (Also avoid the old syntax, which will break on Python 3.x.)

    Also remove use of the "with" statement from loguserdata.py and
    part-handler.py. This statement is only available from Python 2.6 on (or in
    Python 2.5 via "from __future__ import with_statement").

    Finally, remove use of the "except ExceptionType as value" syntax for
    catching exceptions. Again, this was only backported to Python 2.6.

    Change-Id: I89e86d00993d51e2514b1e589503c6d966909403
    Partial-Bug: #1375864
    (cherry picked from commit 95ec13c5725ccc19dfe910fe83eb9bc6799d482e)

tags: added: in-stable-juno
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (stable/icehouse)

Fix proposed to branch: stable/icehouse
Review: https://review.openstack.org/189174

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (stable/icehouse)

Reviewed: https://review.openstack.org/189174
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=eb22b015f5491e03e4a96bfa8c3b3d2d7f011ba0
Submitter: Jenkins
Branch: stable/icehouse

commit eb22b015f5491e03e4a96bfa8c3b3d2d7f011ba0
Author: Zane Bitter <email address hidden>
Date: Wed Oct 1 15:16:45 2014 -0400

    Fix cloud-init Python syntax for Python < 2.6

    The loguserdata.py file gets uploaded to the servers created by Heat to run
    under cloud-init. Since the default versions of Python installed on the
    user's server may be very old (e.g. RHEL 5 defaults to Python 2.4), avoid
    using the octal syntax introduced for Python 3.0 and backported only as far
    as Python 2.6. (Also avoid the old syntax, which will break on Python 3.x.)

    Also remove use of the "with" statement from loguserdata.py and
    part-handler.py. This statement is only available from Python 2.6 on (or in
    Python 2.5 via "from __future__ import with_statement").

    Finally, remove use of the "except ExceptionType as value" syntax for
    catching exceptions. Again, this was only backported to Python 2.6.

    Change-Id: I89e86d00993d51e2514b1e589503c6d966909403
    Partial-Bug: #1375864
    (cherry picked from commit 95ec13c5725ccc19dfe910fe83eb9bc6799d482e)
    (cherry picked from commit 140d66e587bce27523ee7ebbeaecbced83082949)

tags: added: in-stable-icehouse
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.