canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization

Home Page:https://cloud-init.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option package_upgrade runs `snap refresh` even if snapd is not installed in the image

loxK opened this issue · comments

Bug report

I use images.linuxcontainers.org cloud images. If using the option package_upgrade, cloud_init fails because snap isn't installed in these images.

Steps to reproduce the problem

test LXD/Incus profile :

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

Script that creates the container :

#!/bin/bash

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

Environment details

  • Cloud-init version: 23.4.4-0ubuntu0~22.04.1
  • Operating System Distribution: Ubuntu
  • Cloud provider, platform or installer type: Incus

cloud-init logs

cloud-init.tar.gz

Thanks so much @loxK for filing the issues and helping make cloud-init better. This bug is valid against cloud-init 23.4.4 but should also already be fixed per commit cbe5f3a. This commit is included in upstream release 24.1 which has already been published upstream but is not yet published to Ubuntu 22.04 via the StableReleaseUpdates(SRU) process. We have SRU uploads in the unapproved queued that should publish to jammy within 2 weeks I'd guess https://launchpad.net/ubuntu/jammy/+queue?queue_state=1&queue_text=cloud-init

We'll close the issue here for upstream as it will be resolved once 24.1 releases. Please feel free to re-open if this problem persists after v. 24.1

The issue persist in my end using /usr/bin/cloud-init 24.1.3-0ubuntu1~22.04.1

('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: -"))

Seems to work for me given this procedure:

cat > 1.yaml <<EOF
#cloud-config
packages: [sl]
EOF
lxc launch ubuntu-daily:jammy j-t -c cloud-init.user-data="$(cat 1.yaml)"
sleep 3
lxc exec j-t  -- cloud-init status --wait --format=yaml

it works with your

#cloud-config
packages: [sl]

but the error persists with

#cloud-config
package_upgrade: true

hold on, I've recreated the linux machine(I'm using orbstack) and the cloudinit version is now different: /usr/bin/cloud-init 23.4.4-0ubuntu0~22.04.1, I'll figure this out first.

@jbalatero. I see the use-case failed here given your example. This is a different facet of the same type of original issue which looks like we only fixed for package installs, but not package upgrade paths.

I can reproduce this issue by providing the user-data you referenced on an lxc Ubuntu image where I have removed snapd package, yet provided the following user-data:

#cloud-config
package_update: true

The former commit cbe5f3a fixed this issue for generial package installs, but not the generic package_upgrade/update path.

I've put up this PR to address this issue. Thanks @jbalatero for the ping here. #5224

Upload enqueud for Focal, Jammy, Mantic and Noble per https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/2064132