images without snapd installed error on `upgrade_packages: true` user-data
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
cloud-init (Ubuntu) | Status tracked in Oracular | |||||
Focal |
Fix Released
|
Undecided
|
Unassigned | |||
Jammy |
Fix Released
|
Undecided
|
Unassigned | |||
Mantic |
Fix Released
|
Undecided
|
Unassigned | |||
Noble |
Fix Released
|
Undecided
|
Unassigned | |||
Oracular |
Fix Released
|
Critical
|
Chad Smith |
Bug Description
[ Impact ]
* SRU of cloud-init 24.1.3 to Focal, Jammy and Mantic introduced a regression where cloud-init will attempt to call `snap refresh` on new Ubuntu instance launches if the Ubuntu image does not contain snapd deb package and optional #cloud-config user-data is provided which contains `upgrade_packages: true`.
* Such optional user-data on custom ubuntu images will result in cloud-init exiting in error condition as seen from cloud-init status due to the following error message:
- ('package_
This only affects new custom Ubuntu image launches where both of the following conditions are met:
1. image is a custom ubuntu image which does not contain snapd deb package
2. At instance launch, optional #cloud-config user-data contains `package_upgrade: true`
Ubuntu cloudimages published by Canonical for Focal, Jammy and Mantic all currently have the snapd deb package installed.
Even for custom Ubuntu images without snapd deb package installed, this issue is only triggered when #cloud-config contains the optional `package_upgrade: true` during instance launch.
This error log does cause cloud-init status to exit non-zero, but it doesn't affect the integrity of the configuration applied to the system. It is just an undesirable error log message for an unsupported (snap) package manager within the environment.
[ Test Plan ]
* # launch ubuntu cloud images in LXC, remove snapd, provide "#cloud-
* confirm no snap command present in image
* check cloud-init status --format=yaml to ensure no errors
* grep snap.*refresh /var/log/
#!/bin/bash
set -ex
SERIES=$1
cat > pkg-update.yaml <<EOF
#cloud-config
package_upgrade: true
EOF
cat > setup_proposed.sh <<EOF
#/bin/bash
mirror=http://
echo deb \$mirror \$(lsb_release -sc)-proposed main | tee /etc/apt/
apt-get update -q
apt-get install -qy cloud-init
EOF
for SERIES in "focal" "jammy" "mantic"; do
echo "---------- SRU verification: $SERIES"
name=test-
if [ "$SERIES" = "focal" ]; then
LXC_CFG_
else
LXC_CFG_
fi
lxc launch ubuntu-
sleep 3
lxc exec $name -- cloud-init status --wait
# assert snap refresh is called on system with snapd
lxc exec $name -- egrep 'snap.*refresh' /var/log/
lxc exec $name -- apt remove snapd -y
lxc exec $name -- cloud-init clean --logs --reboot
sleep 3
# expect no warnings/errors
lxc exec $name -- cloud-init status --wait --format=yaml || echo "FAILED: errors or warning found"
# ensure no calls to snap refresh
lxc exec $name -- egrep 'snap.*refresh' /var/log/
done
[ Where problems could occur ]
The bug above is an unwanted error log that results in cloud-init reporting an error state and non-zero exit code. The error log doesn't erode the actual final configuration applied to the machine, it just sets a state we don't wont to see as cloud-init shouldn't be trying and failing to run snap command if it doesn't exist in the environment. Given that this fix is only performing a subp.which("snap") to assert that the snap command exists in the path before attempting to run "snap refresh" regression potential is negligible. In the unlikely event that the code paths added do fail here, the regression impact woud only result in a slightly different error log that also doesn't impact the overall config applied to the instance at launch.
[ Other Info ]
==== original description ====
In Ubuntu images that do not have snapd deb package installed, launching with the following user-data triggers cloud-init to run `snap refresh` when that command doesn't exist.
reproducer:
lxc launch ubuntu-daily:jammy test-no-snap
sleep 3
lxc exec test-no-snap -- cloud-init status --wait
lxc exec test-no-snap -- apt remove snapd -y
cat > pkg-update.yaml <<EOF
#cloud-config
package_update: true
EOF
lxc config set test-no-snap cloud-init.
lxc exec test-no-snap -- cloud-init clean --logs --reboot
sleep 3
# expect no warnings/errors
lxc exec test-no-snap -- cloud-init status --wait --format=yaml
# ensure no calls to snap refresh
lxc exec test-no-snap -- egrep 'snap.*refresh' /var/log/
description: | updated |
description: | updated |
description: | updated |
description: | updated |
summary: |
- images without snapd installed error on `update_packages: true` user- + images without snapd installed error on `upgrade_packages: true` user- data |
tags: | added: regression-proposed |
Upstream github issue re-opened representing this fix: https:/ /github. com/canonical/ cloud-init/ issues/ 5143 /github. com/canonical/ cloud-init/ pull/5224
upstream Pull request fixing this issue: https:/