[SRU] cc_apt_configure does not work with python3

Bug #1463373 reported by Nicholas Van Wiggeren
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Medium
Unassigned
cloud-init (Ubuntu)
Fix Released
Medium
Unassigned
Vivid
Fix Released
Medium
Unassigned
Wily
Fix Released
Medium
Unassigned

Bug Description

The way cc_apt_configure.py writes out the script to fetch GPG keys breaks when using Python 3.

[Impact]
GPG keys specified in cloud configuration cannot be checked.

[Test Case]
Specify a key in a source in the apt_sources cloud config key, and ensure that there aren't warnings about it in /var/log/cloud-init.log after boot.

[Regression Potential]
This part of the feature is completely broken at the moment, so very little chance to regress.

Related branches

Revision history for this message
Dan Watkins (oddbloke) wrote : Re: [Bug 1463373] [NEW] cc_apt_configure does not work with python3

Hi Nicholas,

Thanks for taking the time to report this bug in cloud-init!

On 09/06/15 12:34, Nicholas Van Wiggeren wrote:
> The way cc_apt_configure.py writes out the script to fetch GPG keys
> breaks when using Python 3.
>
> * There's a constant, http://bazaar.launchpad.net/~cloud-init-dev/cloud-
> init/trunk/view/head:/cloudinit/config/cc_apt_configure.py#L39 that
> contains the script.
>
> * In getkeybyid, it's written to a temporary file:
> http://bazaar.launchpad.net/~cloud-init-dev/cloud-
> init/trunk/view/head:/cloudinit/config/cc_apt_configure.py#L113

Thanks for the breakdown, that's really helpful.

> Python 3 throws an exception: 'str' does not support the buffer
> interface when doing the write.

Could you paste the full traceback you hit, if you can get one easily?

Thanks,

Dan

Revision history for this message
Nicholas Van Wiggeren (nvanwiggeren) wrote : Re: cc_apt_configure does not work with python3

Hi Dan,

Thanks for taking the time to reply so quickly. I made a small change to cc_apt_configure.py so it would print the stack trace upon running. The full trace looks like this:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_apt_configure.py", line 208, in add_sources
    ent['key'] = getkeybyid(ent['keyid'], ks)
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_apt_configure.py", line 114, in getkeybyid
    fh.write(EXPORT_GPG_KEYID)
  File "/usr/lib/python3.4/tempfile.py", line 538, in func_wrapper
    return func(*args, **kwargs)
TypeError: 'str' does not support the buffer interface

The diff to of cc_apt_configure.py looks like this:

diff cc_apt_configure.py cc_apt_configure_stack.py
23a24
> import traceback
208c209,210
< except:
---
> except Exception:
> traceback.print_exc()

If you need anything else, let me know! I'm happy to help you get access to a machine with this configuration if you want to poke around yourself.

Revision history for this message
Dan Watkins (oddbloke) wrote :

Thanks, Nicholas! I'll take a look at this when I get a bit of time; probably towards the end of the month. :)

Changed in cloud-init:
assignee: nobody → Dan Watkins (daniel-thewatkins)
Revision history for this message
Scott Moser (smoser) wrote :

recreates easily enough:

$ python3 -c 'from cloudinit.config.cc_apt_configure import getkeybyid; import sys; getkeybyid(sys.argv[1], sys.argv[2])' 03683F77 keyserver.ubuntu.com
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_apt_configure.py", line 113, in getkeybyid
    fh.write(EXPORT_GPG_KEYID)
  File "/usr/lib/python3.4/tempfile.py", line 556, in func_wrapper
    return func(*args, **kwargs)
TypeError: 'str' does not support the buffer interface

Fixes like this:
$ ( cd /usr/lib/python3/dist-packages/ && diff -u cloudinit/config/cc_apt_configure.py.dist cloudinit/config/cc_apt_configure.py )
--- cloudinit/config/cc_apt_configure.py.dist 2015-06-15 20:51:09.109033000 +0000
+++ cloudinit/config/cc_apt_configure.py 2015-06-15 20:51:16.185033000 +0000
@@ -109,7 +109,7 @@

 # get gpg keyid from keyserver
 def getkeybyid(keyid, keyserver):
- with util.ExtendedTemporaryFile(suffix='.sh') as fh:
+ with util.ExtendedTemporaryFile(suffix='.sh', mode="w+") as fh:
         fh.write(EXPORT_GPG_KEYID)
         fh.flush()
         cmd = ['/bin/sh', fh.name, keyid, keyserver]

Changed in cloud-init:
status: New → Fix Committed
Changed in cloud-init (Ubuntu):
status: New → Fix Committed
status: Fix Committed → Confirmed
Scott Moser (smoser)
Changed in cloud-init (Ubuntu Vivid):
status: New → Confirmed
importance: Undecided → Medium
Changed in cloud-init (Ubuntu Wily):
importance: Undecided → Medium
Changed in cloud-init:
importance: Undecided → Medium
Dan Watkins (oddbloke)
Changed in cloud-init:
assignee: Dan Watkins (daniel-thewatkins) → nobody
Dan Watkins (oddbloke)
description: updated
summary: - cc_apt_configure does not work with python3
+ [SRU] cc_apt_configure does not work with python3
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 0.7.7~bzr1127-0ubuntu1

---------------
cloud-init (0.7.7~bzr1127-0ubuntu1) wily; urgency=medium

  [ Scott Moser ]
  * d/README.source, debian/cherry-pick-rev: improve packaging tool

  [ Daniel Watkins ]
  * d/cloud-init.templates: Include SmartOS data source in the default list
    and choices. (LP: #1398997)

  [ Scott Moser ]
  * New upstream snapshot.
    * check for systemd using sd_booted symantics (LP: #1461201)
    * fix importing of gpg keys in python3 (LP: #1463373)
    * fix specification of devices to growpart (LP: #1465436)
    * reliably detect and use Azure disks using udev rules (LP: #1411582)
    * support selection of Ubuntu mirrors on GCE (LP: #1470890)
    * ssh: generate ed25519 host keys if supported (LP: #1461242)
    * test fixes and cleanups
    * fix reading of availability-zone on GCE (LP: #1470880)
    * fix cloudsigma datasource with python3 (LP: #1475215)
    * fix rightscale user-data
    * fix consumption of CloudStack passwords on newer CloudStack platforms
      (LP: #1440263, #1464253)

 -- Scott Moser <email address hidden> Wed, 22 Jul 2015 17:06:18 -0400

Changed in cloud-init (Ubuntu Wily):
status: Confirmed → Fix Released
Revision history for this message
Chris J Arges (arges) wrote : Please test proposed package

Hello Nicholas, or anyone else affected,

Accepted cloud-init into vivid-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/cloud-init/0.7.7~bzr1091-0ubuntu4 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in cloud-init (Ubuntu Vivid):
status: Confirmed → Fix Committed
tags: added: verification-needed
Scott Moser (smoser)
tags: added: verification-done
removed: verification-needed
Revision history for this message
Scott Moser (smoser) wrote :

I recreated, patched, verified fixed on vivid.

- launch instance with provided user data
- ssh to instance, verify failure (no 'smello' command)
- see failure when running:
  $ sudo cloud-init single --frequency=always --name=apt_configure
  and that apt-key did not get poplated
  $ apt-key list | grep "Launchpad PPA"
- enable proposed
  $ mirror=http://archive.ubuntu.com/ubuntu ; rel=$(lsb_release -sc)
  $ echo "deb $mirror $rel-proposed main" | sudo tee /etc/apt/sources.list.d/proposed.list
  $ sudo apt-get update -q
  $ sudo apt-get install cloud-init
  $ dpkg-query --show cloud-init
  cloud-init 0.7.7~bzr1091-0ubuntu4

- re-run cloud-init apt module manually
  $ sudo cloud-init single --frequency=always --name=apt_configure
  $ apt-key list | grep "Launchpad PPA"
  uid Launchpad PPA for Scott Moser
  # note this does show a warning about renderer, that is expected
  $ sudo cloud-init single --frequency=always --name=package_update_upgrade_install
  ...
  Setting up smello (0.3~ppa1)
  $ smello
  Hi World

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 0.7.7~bzr1091-0ubuntu4

---------------
cloud-init (0.7.7~bzr1091-0ubuntu4) vivid; urgency=medium

  * d/patches/lp-1456684-eu-central-1.patch: Add central as a direction for
    EC2 availability zones (LP: #1456684).
  * d/patches/lp-1464253-handle-new-cloudstack-passwords.patch: Handle both
    old and new CloudStack password servers (LP: #1464253).
  * d/patches/lp-1475215-fix-cloudsigma-cepko.patch: Fix CloudSigma datasource
    under Python 3 (LP: #1475215).
  * d/patches/lp-1463373-fix-apt-gpg-key-fetching.patch: Fix a Python 3
    problem with the writing out of the script that fetches GPG keys for apt
    repos (LP: #1463373).

 -- Daniel Watkins <email address hidden> Mon, 29 Jun 2015 12:48:33 +0100

Changed in cloud-init (Ubuntu Vivid):
status: Fix Committed → Fix Released
Revision history for this message
Chris J Arges (arges) wrote : Update Released

The verification of the Stable Release Update for cloud-init has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Revision history for this message
Scott Moser (smoser) wrote :

This is fixed in cloud-init 0.7.7

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
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.