Issue with linuxcontainers ubuntu images and cloud-init option "package_upgrade" because of snap

Hello,

When using the option package_upgrade for cloud-init and Ubuntu cloud images from images.linuxcontainers.org, cloud-init fails because it is trying to do a snap refresh. But snap isn’t even installed in these images.

test profile :

config:
  user.vendor-data: |
    #cloud-config
    package_upgrade: true
description: ""
devices: {}
name: test

Script that creates the container :


CONTAINER_NAME="myname"

echo 'Creating container'
incus init images:ubuntu/22.04/cloud $CONTAINER_NAME -p default -p test
echo 'Container created'

echo 'Starting it'
incus start $CONTAINER_NAME

echo 'Waiting for cloud-init to finish up ...'

incus exec $CONTAINER_NAME -- cloud-init status --wait  > /dev/null 2>&1

[ $? -ne 0 ] && echo Cloud-init failed && incus exec $CONTAINER_NAME -- cloud-init status --long && exit 1
echo -n 'Cloud-init finished at '
echo -n `date -R`

The error :

./test.sh
Creating container
Création de myname
Container created
Starting it
Waiting for cloud-init to finish up ...
Cloud-init failed
status: error
extended_status: error
boot_status_code: enabled-by-generator
last_update: Thu, 04 Apr 2024 00:44:15 +0000
detail:
DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
errors:
	- ('package_update_upgrade_install', ProcessExecutionError("Unexpected error while running command.\nCommand: ['snap', 'refresh']\nExit code: -\nReason: [Errno 2] No such file or directory: b'snap'\nStdout: -\nStderr: -"))
recoverable_errors:
WARNING:
	- Package upgrade failed
	- 1 failed with exceptions, re-raising the last one
	- Running module package_update_upgrade_install (<module 'cloudinit.config.cc_package_update_upgrade_install' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py'>) failed
Cloud-init finished at Thu, 04 Apr 2024 11:44:16 +1100

Snap isn’t installed :

root@myname:~# dpkg -l | grep snap
root@myname:~# which snap
root@myname:~# snap
-bash: snap: command not found

Used to work for me. I tested this just now and got the same issue. Tested with debian/12/cloud and the issue is not there.

Something changed with cloud-init and ubuntu expecting snap to exist now. I would guess something done on ubuntu or cloud-init side.

pargo@bastion:~$ incus profile show default
config:
  cloud-init.vendor-data: |-
    #cloud-config
    package_update: true
    package_upgrade: true
    timezone: America/Fortaleza
  limits.memory: 28GiB
  security.nesting: "true"
description: Default Incus profile for project dedicado
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: br0
    type: nic
  root:
    path: /
    pool: local
    size: 50GiB
    type: disk
name: default
(...)
pargo@bastion:~$ incus launch images:ubuntu/22.04/cloud victor-test; incus exec victor-test -- cloud-init status --wait; incus exec victor-test -- cloud-init status --long; incus delete -f victor-test
Launching victor-test
................................
status: error
status: error
extended_status: error
boot_status_code: enabled-by-generator
last_update: Thu, 04 Apr 2024 01:05:46 +0000
detail:
DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]
errors:
	- ('package_update_upgrade_install', ProcessExecutionError("Unexpected error while running command.\nCommand: ['snap', 'refresh']\nExit code: -\nReason: [Errno 2] No such file or directory: b'snap'\nStdout: -\nStderr: -"))
recoverable_errors:
WARNING:
	- Package upgrade failed
	- 1 failed with exceptions, re-raising the last one
	- Running module package_update_upgrade_install (<module 'cloudinit.config.cc_package_update_upgrade_install' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_package_update_upgrade_install.py'>) failed
pargo@bastion:~$ incus launch images:debian/12/cloud victor-test; incus exec victor-test -- cloud-init status --wait; incus exec victor-test -- cloud-init status --long; incus delete -f victor-test
Launching victor-test
.......................
status: done
status: done
boot_status_code: enabled-by-generator
last_update: Thu, 04 Apr 2024 01:06:04 +0000
detail:
DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]

Yeah, that’s a cloud-init bug which has been reported upstream and a fix has recently been merged. fix: Fix breaking changes in package install by TheRealFalcon · Pull Request #5069 · canonical/cloud-init · GitHub

Basically cloud-init was always running snap refresh on Ubuntu systems, even if they didn’t have snapd installed…

2 Likes

Yes I did report it upstream, it is fixed in recent version of cloud-init but not yet in Ubuntu 22.04 : Option package_upgrade runs `snap refresh` even if snapd is not installed in the image · Issue #5143 · canonical/cloud-init · GitHub