]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysupdate: Add tests for optional features
authorAdrian Vovk <adrianvovk@gmail.com>
Tue, 2 Jul 2024 18:56:27 +0000 (14:56 -0400)
committerAdrian Vovk <adrianvovk@gmail.com>
Fri, 18 Oct 2024 21:58:46 +0000 (17:58 -0400)
Makes sure we don't regress on #33343 and #33344

test/units/TEST-72-SYSUPDATE.sh

index 4dcdf5dced310e9bebc1ef508825af151f1102db..0598ef2c39d6b9baddbac8d219c7a135d4f740c2 100755 (executable)
@@ -72,6 +72,9 @@ new_version() {
     # Create a random extra payload
     echo $RANDOM >"$WORKDIR/source/uki-extra-$version.efi"
 
+    # Create a random optional payload
+    echo $RANDOM >"$WORKDIR/source/optional-$version.efi"
+
     # Create tarball of a directory
     mkdir -p "$WORKDIR/source/dir-$version"
     echo $RANDOM >"$WORKDIR/source/dir-$version/foo.txt"
@@ -155,7 +158,7 @@ EOF
         mkdir -p "$d"
     done
 
-    cat >"$CONFIGDIR/01-first.conf" <<EOF
+    cat >"$CONFIGDIR/01-first.transfer" <<EOF
 [Source]
 Type=regular-file
 Path=$WORKDIR/source
@@ -168,7 +171,7 @@ MatchPattern=part1-@v
 MatchPartitionType=root-x86-64
 EOF
 
-    cat >"$CONFIGDIR/02-second.conf" <<EOF
+    cat >"$CONFIGDIR/02-second.transfer" <<EOF
 [Source]
 Type=regular-file
 Path=$WORKDIR/source
@@ -181,7 +184,7 @@ MatchPattern=part2-@v
 MatchPartitionType=root-x86-64-verity
 EOF
 
-    cat >"$CONFIGDIR/03-third.conf" <<EOF
+    cat >"$CONFIGDIR/03-third.transfer" <<EOF
 [Source]
 Type=directory
 Path=$WORKDIR/source
@@ -195,7 +198,7 @@ MatchPattern=dir-@v
 InstancesMax=3
 EOF
 
-    cat >"$CONFIGDIR/04-fourth.conf" <<EOF
+    cat >"$CONFIGDIR/04-fourth.transfer" <<EOF
 [Source]
 Type=regular-file
 Path=$WORKDIR/source
@@ -214,7 +217,7 @@ TriesDone=0
 InstancesMax=2
 EOF
 
-    cat >"$CONFIGDIR/05-fifth.conf" <<EOF
+    cat >"$CONFIGDIR/05-fifth.transfer" <<EOF
 [Source]
 Type=regular-file
 Path=$WORKDIR/source
@@ -227,6 +230,29 @@ PathRelativeTo=boot
 MatchPattern=uki_@v.efi.extra.d/extra.addon.efi
 Mode=0444
 InstancesMax=2
+EOF
+
+    cat >"$CONFIGDIR/optional.feature" <<EOF
+[Feature]
+Description=Optional Feature
+EOF
+
+    cat >"$CONFIGDIR/99-optional.transfer" <<EOF
+[Transfer]
+Features=optional
+
+[Source]
+Type=regular-file
+Path=$WORKDIR/source
+MatchPattern=optional-@v.efi
+
+[Target]
+Type=regular-file
+Path=/EFI/Linux
+PathRelativeTo=boot
+MatchPattern=uki_@v.efi.extra.d/optional.efi
+Mode=0444
+InstancesMax=2
 EOF
 
     rm -rf "${WORKDIR:?}"/{esp,xbootldr,source}
@@ -276,6 +302,26 @@ EOF
     verify_version "$blockdev" "$sector_size" v3 1
     verify_version_current "$blockdev" "$sector_size" v5 2
 
+    # Now let's try enabling an optional feature
+    test ! -f "$WORKDIR/xbootldr/EFI/Linux/uki_v5.efi.extra.d/optional.efi"
+    mkdir "$CONFIGDIR/optional.feature.d"
+    echo -e "[Feature]\nEnabled=true" > "$CONFIGDIR/optional.feature.d/enable.conf"
+    "$SYSUPDATE" --offline list v5 | grep -q "incomplete"
+    update_now
+    "$SYSUPDATE" --offline list v5 | grep -qv "incomplete"
+    verify_version "$blockdev" "$sector_size" v3 1
+    verify_version_current "$blockdev" "$sector_size" v5 2
+    test -f "$WORKDIR/xbootldr/EFI/Linux/uki_v5.efi.extra.d/optional.efi"
+
+    # And now let's disable it and make sure it gets cleaned up
+    rm -r "$CONFIGDIR/optional.feature.d"
+    (! "$SYSUPDATE" --verify=no check-new)
+    "$SYSUPDATE" vacuum
+    "$SYSUPDATE" --offline list v5 | grep -qv "incomplete"
+    verify_version "$blockdev" "$sector_size" v3 1
+    verify_version_current "$blockdev" "$sector_size" v5 2
+    test ! -f "$WORKDIR/xbootldr/EFI/Linux/uki_v5.efi.extra.d/optional.efi"
+
     # Create sixth version, update using updatectl and verify it replaced the
     # correct version
     new_version "$sector_size" v6
@@ -299,7 +345,7 @@ EOF
     # component so that updatectl has multiple targets to list.
     if [[ -x "$SYSUPDATED" ]] && command -v updatectl; then
         mkdir -p /run/sysupdate.test.d/
-        cp "$CONFIGDIR/01-first.conf" /run/sysupdate.test.d/01-first.conf
+        cp "$CONFIGDIR/01-first.transfer" /run/sysupdate.test.d/01-first.transfer
         updatectl list
         updatectl list host
         updatectl list host@v6
@@ -315,7 +361,7 @@ EOF
     # see above)
     new_version "$sector_size" v7
 
-    cat >"$CONFIGDIR/02-second.conf" <<EOF
+    cat >"$CONFIGDIR/02-second.transfer" <<EOF
 [Source]
 Type=url-file
 Path=file://$WORKDIR/source
@@ -328,7 +374,7 @@ MatchPattern=part2-@v
 MatchPartitionType=root-x86-64-verity
 EOF
 
-    cat >"$CONFIGDIR/03-third.conf" <<EOF
+    cat >"$CONFIGDIR/03-third.transfer" <<EOF
 [Source]
 Type=url-tar
 Path=file://$WORKDIR/source
@@ -346,6 +392,14 @@ EOF
     verify_version "$blockdev" "$sector_size" v6 1
     verify_version_current "$blockdev" "$sector_size" v7 2
 
+    # Let's make sure that we don't break our backwards-compat for .conf files
+    # (what .transfer files were called before v257)
+    for i in "$CONFIGDIR/"*.conf; do echo mv "$i" "${i%.conf}.transfer"; done
+    new_version "$sector_size" v8
+    update_now
+    verify_version_current "$blockdev" "$sector_size" v8 1
+    verify_version "$blockdev" "$sector_size" v7 2
+
     # Cleanup
     [[ -b "$blockdev" ]] && losetup --detach "$blockdev"
     rm "$BACKING_FILE"