ubuntu: fix snap components pulled from the wrong model

We have a mechanism in place to override a snap when building an image.
Unfortunately, we didn't factor this in when forcing optional components to be
included in the image.

This was okay before because the stable model and the dangerous model had the
same components declared.

But now that pc-kernel has different components in the stable and the dangerous
model, things are broken.

Indeed, when building the stable image, we tried to include the pc-kernel from
the stable model with the pc-kernel components from the dangerous model. But
they are not compatible.

Fixed by including components from the right model. If we're overriding a snap
with a definition from a different model, then pull the components from that
same model.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2025-12-16 14:08:33 +01:00
parent 72511a0381
commit 01c80d8d0a
2 changed files with 58 additions and 7 deletions

5
debian/changelog vendored
View File

@ -1,6 +1,11 @@
livecd-rootfs (26.04.12) UNRELEASED; urgency=medium
* desktop: add variables pointing to the different models (stable & dangerous).
* desktop: fix snap components taken from original model when overriding a
snap with another model.
- if we decide to override the definition of a snap (i.e., by taking in
from a different model), we also need to override the definition of its
components.
-- Olivier Gayot <olivier.gayot@canonical.com> Tue, 16 Dec 2025 14:54:17 +0100

View File

@ -42,13 +42,19 @@ get_snaps_args()
| jq --raw-output '.snaps[] | "--snap=" + .name + "=" + .["default-channel"]'
}
get_all_components()
_get_components_filtered()
{
# Get list of all components in every snaps
local model=$1
local excluded=$1
local model=$2
local jq_filter='
# Find all snaps that have components
.snaps[] | select(.components)
# Find all snaps that are either filtered in or filtered out
# The filtered in (or out) snaps are passed as positional arguments so they end up in
# the $ARGS.positional array. The excluded variable is passed separately and
# tells if we want to filter in (i.e., excluded=false) or filter out (i.e.,
# excluded=true).
.snaps[] | select(.name | IN($ARGS.positional[]) | if $excluded then not else . end)
# and have components
| select(.components)
# Then save the name of each snap in a variable
| .name as $snap
# Then for each entry that has "optional"
@ -56,9 +62,35 @@ get_all_components()
# Output its name with the snap name prepended
| "\($snap)" + "+" + .[].key'
shift 2
sed '/^$/,$d' -- "$model" \
| yaml_to_json \
| jq --raw-output "$jq_filter"
| jq --raw-output "$jq_filter" --argjson excluded "$excluded" --args "$@"
}
# Get list of all components for all snaps
get_all_components()
{
local model=$1
# Provide an exclusion list but empty
_get_components_filtered true "$model"
}
# Get list of all components for all snaps except the ones specified.
get_components_excluding()
{
local model=$1
shift
_get_components_filtered true "$model" "$@"
}
# Get list of all components for the snaps specified.
get_components()
{
local model=$1
shift
_get_components_filtered false "$model" "$@"
}
# Generation of the model:
@ -83,6 +115,8 @@ stable_model=/usr/share/livecd-rootfs/live-build/${PROJECT}/ubuntu-classic-amd64
prepare_args=()
components=()
# for the dangerous subproject, we need the dangerous model!
if [ "$SUBPROJECT" = "dangerous" ]; then
# As with the "classically" seeded snaps, snaps from the edge channel may
@ -93,6 +127,10 @@ if [ "$SUBPROJECT" = "dangerous" ]; then
while read snap; do
prepare_args+=("--snap=${snap}=edge")
done < config/missing-providers
for comp in $(get_all_components "$model"); do
components+=("$comp")
done
else
# Normally we use the stable model here. Use the dangerous one for now
# until we get snaps on stable 26.04 tracks and channels.
@ -104,13 +142,21 @@ else
# * snapd (for TPM/FDE)
# * firmware-updater (for TPM/FDE)
# * desktop-security-center (for TPM/FDE)
snaps_from_dangerous=(snapd firmware-updater desktop-security-center)
while read -r snap_arg; do
prepare_args+=("$snap_arg")
done < <(get_snaps_args "$stable_model" \
| grep -v -F -e snapd -e firmware-updater -e desktop-security-center)
for comp in $(get_components_excluding "$stable_model" "${snaps_from_dangerous[@]}"); do
components+=("$comp")
done
for comp in $(get_components "$dangerous_model" "${snaps_from_dangerous[@]}"); do
components+=("$comp")
done
fi
for comp in $(get_all_components "$model"); do
for comp in "${components[@]}"; do
prepare_args+=(--comp "$comp")
done