Ubuntu 15.04 python3 path problem when running loguserdata.py

Bug #1481614 reported by Martin Paulo
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
Medium
Oleksii Chuprykov
Kilo
Fix Released
Medium
Angus Salkeld

Bug Description

 cloud-init on Ubuntu 15.04 is now run by Python 3. However, the system Python version is 2.7.9.

Hence under Heat, when the cloud-init script

/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_user.py

attempts to sweep across all the files in the target directory:

/var/lib/cloud/instance/scripts/

and run them via an eventual call to POpen(...), it hits the file injected by Heat named:

loguserdata.py.

And tries to run it. However, the 2.7 environment is not correctly set for this file to run. The python 3 environment is the one that is correctly set for this file to run. Hence the attempted run of this script ends in tears.

(its the call pkg_resources.get_distribution('cloud-init').version that fails)

Given that this bug is at the intersection of three different projects, I wasn't sure where it to report it to :( I eventually decided that as heat injects loguserdata.py, and that loguserdata.py is making the call that fails, this was where I should report it...

Revision history for this message
Steve Baker (steve-stevebaker) wrote :

Lets assume we can fix this by changing loguserdata.py.

As a workaround you can always set user_data_format:RAW on your server resource (assuming the template doesn't actually need to run cfn-init).
http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Nova::Server

Changed in heat:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Martin Paulo (martin-paulo) wrote : Re: [Bug 1481614] Re: Ubuntu 15.04 python3 path problem when running loguserdata.py

The full stack trace is:

Traceback (most recent call last):
  File "/var/lib/cloud/instance/scripts/loguserdata.py", line 92, in
<module>
    code = main()
  File "/var/lib/cloud/instance/scripts/loguserdata.py", line 73, in main
    if not chk_ci_version():
  File "/var/lib/cloud/instance/scripts/loguserdata.py", line 30, in
chk_ci_version
    v = LooseVersion(pkg_resources.get_distribution('cloud-init').version)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
514, in get_distribution
    dist = get_provider(dist)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
394, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
920, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
807, in resolve
    raise DistributionNotFound(req)

Interestingly a command line call:
$ cloud-init --version
cloud-init 0.7.7

Returns the required version number without error on the Ubuntu 15.04
instance.

Sadly I needed to run cfn-init. Which is why I encountered this problem :(

Thanks

Martin

On 6 August 2015 at 06:58, Steve Baker <email address hidden> wrote:

> Lets assume we can fix this by changing loguserdata.py.
>
> As a workaround you can always set user_data_format:RAW on your server
> resource (assuming the template doesn't actually need to run cfn-init).
>
> http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Nova::Server
>
> ** Changed in: heat
> Status: New => Triaged
>
> ** Changed in: heat
> Importance: Undecided => Medium
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1481614
>
> Title:
> Ubuntu 15.04 python3 path problem when running loguserdata.py
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/heat/+bug/1481614/+subscriptions
>

--
=================================================================

Martin Paulo, BSc.
Software Developer

Tel : +61-3-9434 2508 (Home)
Tel : 04 205 20339 (Mobile)
Site: http://www.thepaulofamily.net

"Nobody goes there any more. It's too crowded" - Yogi Berra.

Revision history for this message
Steve Baker (steve-stevebaker) wrote :

On 06/08/15 12:42, Martin Paulo wrote:
> Interestingly a command line call:
> $ cloud-init --version
> cloud-init 0.7.7
It looks like the fix would be to Popen and execute "cloud-init
--version" instead of getting it from python packaging, or just remove
that version checking which was there to look for truly ancient versions
of cloud-init (pre 0.6.0).

tags: added: kilo-backport-potential
Revision history for this message
Martin Paulo (martin-paulo) wrote :

On our CentOs 5.5 instance cloud-init --version returns "bad command
--version" on std error and has an exit code of 1. We know that this is
cloud-init version 0.6.3... So using to Popen to execute the call might not
give the desired result.

A quick check of the cloud-init code base seems to show that --version was
introduced in revision 564 in 2012-07-06, so works with cloud-init 0.7.0
onwards.

If the version check is to be preserved, one approach would be to use the
existing working (mostly) code: if that fails with the exception, then
retry via Popen. If that fails: well, two paths have been tried. I'm not
sure what more could be done.

Or alternately, given that we are talking about 2012, the alternate idea of
getting rid of the version checking sounds appealing. But then that's easy
for me to say, as I have no idea as to what might break if its removed...

On 6 August 2015 at 12:46, Steve Baker <email address hidden> wrote:

> On 06/08/15 12:42, Martin Paulo wrote:
> > Interestingly a command line call:
> > $ cloud-init --version
> > cloud-init 0.7.7
> It looks like the fix would be to Popen and execute "cloud-init
> --version" instead of getting it from python packaging, or just remove
> that version checking which was there to look for truly ancient versions
> of cloud-init (pre 0.6.0).
>
>
> ** Tags added: kilo-backport-potential
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1481614
>
> Title:
> Ubuntu 15.04 python3 path problem when running loguserdata.py
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/heat/+bug/1481614/+subscriptions
>

--
=================================================================

Martin Paulo, BSc.
Software Developer

Tel : +61-3-9434 2508 (Home)
Tel : 04 205 20339 (Mobile)
Site: http://www.thepaulofamily.net

"Nobody goes there any more. It's too crowded" - Yogi Berra.

Changed in heat:
assignee: nobody → Oleksii Chuprykov (ochuprykov)
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/209844

Changed in heat:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/209844
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=04eedc46b824daf1439c6367775a38444004f69c
Submitter: Jenkins
Branch: master

commit 04eedc46b824daf1439c6367775a38444004f69c
Author: Oleksii Chuprykov <email address hidden>
Date: Thu Aug 6 12:36:16 2015 +0300

    Try to get the version of cloud init via popen

    Now we can fail while trying to get the version of cloud-init
    via pkg_resources. Try to get the version via ordinary cmd call
    'cloud-init --version'.

    Change-Id: I39d4d52ba1ac83183a0a46c7f3a70a14b782562a
    Closes-Bug: #1481614

Changed in heat:
status: In Progress → Fix Committed
Changed in heat:
milestone: none → liberty-3
status: Fix Committed → Fix Released
Angus Salkeld (asalkeld)
tags: removed: kilo-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (stable/kilo)

Fix proposed to branch: stable/kilo
Review: https://review.openstack.org/224961

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

Reviewed: https://review.openstack.org/224961
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=0d95270e78a8fbecc62fcd1fdaccd40591569209
Submitter: Jenkins
Branch: stable/kilo

commit 0d95270e78a8fbecc62fcd1fdaccd40591569209
Author: Oleksii Chuprykov <email address hidden>
Date: Thu Aug 6 12:36:16 2015 +0300

    Try to get the version of cloud init via popen

    Now we can fail while trying to get the version of cloud-init
    via pkg_resources. Try to get the version via ordinary cmd call
    'cloud-init --version'.

    Change-Id: I39d4d52ba1ac83183a0a46c7f3a70a14b782562a
    Closes-Bug: #1481614
    (cherry picked from commit 04eedc46b824daf1439c6367775a38444004f69c)

Thierry Carrez (ttx)
Changed in heat:
milestone: liberty-3 → 5.0.0
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.