Browse Source

use a configurable list of versioned kernel packages

With APT::VersionedKernelPackages users have the option of adding
packages like pre-build out-of-tree modules to the list of automatically
protected from being autoremoved.
David Kalnischkies 10 years ago
parent
commit
b9b0f6222c

+ 11 - 10
debian/apt.auto-removal.sh

@@ -72,22 +72,23 @@ $previous_version
 EOF
 )
 
-cat > "$config_file".dpkg-new <<EOF
+generateconfig() {
+	cat <<EOF
 // File autogenerated by $0, do not edit
 APT
 {
   NeverAutoRemove
   {
 EOF
-for kernel in $kernels; do
-	echo "    \"^linux-image-${kernel}$\";" >> "$config_file".dpkg-new
-	echo "    \"^linux-image-extra-${kernel}$\";" >> "$config_file".dpkg-new
-	echo "    \"^linux-signed-image-${kernel}$\";" >> "$config_file".dpkg-new
-	echo "    \"^linux-backports-modules-.*-${kernel}$\";" >> "$config_file".dpkg-new
-	echo "    \"^linux-headers-${kernel}$\";" >> "$config_file".dpkg-new
-done
-cat >> "$config_file".dpkg-new <<EOF
+	apt-config dump --no-empty --format '%v%n' 'APT::VersionedKernelPackages' | while read package; do
+		for kernel in $kernels; do
+			echo "    \"^${package}-${kernel}$\";"
+		done
+	done
+	cat <<EOF
   };
 };
 EOF
-mv "$config_file".dpkg-new "$config_file"
+}
+generateconfig > "${config_file}.dpkg-new"
+mv "${config_file}.dpkg-new" "$config_file"

+ 9 - 0
debian/apt.conf.autoremove

@@ -9,6 +9,15 @@ APT
 	"^gnumach-image.*";
   };
 
+  VersionedKernelPackages
+  {
+	"linux-image";
+	"linux-image-extra";
+	"linux-signed-image";
+	"linux-backports-modules-.*";
+	"linux-headers";
+  };
+
   Never-MarkAuto-Sections
   {
 	"metapackages";

+ 6 - 4
test/integration/framework

@@ -93,14 +93,15 @@ msgdone() {
 
 runapt() {
 	msgdebug "Executing: ${CCMD}$*${CDEBUG} "
-	local CMD="$1"
+	local CMD="${BUILDDIRECTORY}/$1"
+	if [ "$1" = 'sh' ]; then CMD='sh'; fi
 	shift
 	if [ -f ./aptconfig.conf ]; then
-		MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
+		MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@"
 	elif [ -f ../aptconfig.conf ]; then
-		MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
+		MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@"
 	else
-		MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
+		MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@"
 	fi
 }
 aptconfig() { runapt apt-config "$@"; }
@@ -198,6 +199,7 @@ setupenvironment() {
 	touch var/lib/dpkg/available
 	mkdir -p usr/lib/apt
 	ln -s ${METHODSDIR} usr/lib/apt/methods
+	ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
 	cd ..
 	local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
 	if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then

+ 52 - 39
test/integration/test-kernel-helper-autoremove

@@ -1,55 +1,68 @@
 #!/bin/sh
-
 set -e
 
-# setup testdir
 TESTDIR=$(readlink -f $(dirname $0))
 . $TESTDIR/framework
+setupenvironment
+configarchitecture 'native'
 
-TMPDIR=$(mktemp -d)
-cd $TMPDIR
-addtrap "cd /; rm -rf $TMPDIR"
+# the executed script would use the installed apt-config,
+# which is outside of our control
+msgtest 'Check that the installed apt-config supports' '--no-empty'
+if apt-config dump --no-empty >/dev/null 2>&1; then
+	msgpass
+else
+	msgskip
+	exit 0
+fi
 
-# create mock environment
-mkdir apt.conf.d
-cat > aptconfig.conf <<EOF
-Dir::Etc::parts "$TMPDIR/apt.conf.d";
-Dir::bin::dpkg "$TMPDIR/fake-dpkg";
+# install fake-dpkg into it
+cat > ./fake-dpkg <<EOF
+#!/bin/sh
+set -e
+if [ "\$1" = "-l" ]; then
+    echo "ii  linux-image-1.0.0-2-generic  1.0.0-2  amd64"
+    echo "ii  linux-image-\$(uname -r)  not-used  amd64"
+    echo "ii linux-image-100.0.0-1-generic  100.0.0.1-1  amd64"
+else
+    dpkg "\$@"
+fi
 EOF
-APT_CONFIG=aptconfig.conf
-export APT_CONFIG
+chmod +x ./fake-dpkg
+echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg
 
-# install fake-dpkg into it
-install -m755 $TESTDIR/test-kernel-helper-autoremove.fake-dpkg $TMPDIR/fake-dpkg
+catfail() {
+	echo >&2
+	echo >&2 '### List of protected kernels:'
+	cat >&2 protected.list
+	msgfail
+}
 
-# run the helper
-sh ${TESTDIR}/../../debian/apt.auto-removal.sh
+testprotected() {
+	rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
 
-msgtest 'Check that kernel autoremoval list is correctly created'
-# and ensure its there, valid and version 10.0.0-1 is there too
-test -e $TMPDIR/apt.conf.d/01autoremove-kernels && msgpass || msgfail
+	testsuccess runapt sh ${TESTDIR}/../../debian/apt.auto-removal.sh "$@"
 
-msgtest 'Check that most recent kernel is saved from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-10.0.0-1-generic" && msgpass || msgfail
+	msgtest 'Check kernel autoremoval protection list' 'is created'
+	test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels && msgpass || msgfail
 
-# ... and also that the running kernel is excluded
-msgtest 'Check that running kernel is saved from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-$(uname -r)" && msgpass || msgfail
+	msgtest 'Check kernel autoremoval protection list' 'can be dumped'
+	aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove' >protected.list 2>&1 && msgpass || catfail
 
-# and that the old kernel is *not* excluded from autoremoval
-msgtest 'Check that older kernels are not excluded from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-1\.0\.01-2-generic" && msgfail || msgpass
+	msgtest 'Check kernel autoremoval protection list' 'can be parsed'
+	grep -q '^[A-Z]: ' protected.list && catfail || msgpass
 
-msgtest "Check that the older kernel is retained when it's being installed"
-sh ${TESTDIR}/../../debian/apt.auto-removal.sh 1.0.01-2-generic
-test -e $TMPDIR/apt.conf.d/01autoremove-kernels
-if ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-10.0.0-1-generic" \
-   || ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-$(uname -r)" \
-   || ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-1\.0\.01-2-generic"
-then
-	msgfail
-else
-	msgpass
-fi
+	msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
+	grep -q '^\^linux-image-100\.0\.0-1-generic\$$' protected.list && msgpass || catfail
+
+	msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
+	grep -q "^\\^linux-image-$(uname -r)\\\$\$" protected.list && msgpass || catfail
+}
+
+testprotected
+msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
+grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && catfail || msgpass
 
-# done
+testprotected 1.0.0-2-generic
+msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
+grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && msgpass || catfail

+ 0 - 13
test/integration/test-kernel-helper-autoremove.fake-dpkg

@@ -1,13 +0,0 @@
-#!/bin/sh
-set -e
-
-if [ "$1" = "-l" ]; then
-    echo "ii  linux-image-1.0.0-2-generic  1.0.01-2  amd64"
-    echo "ii  linux-image-$(uname -r)  not-used  amd64"
-    echo "ii linux-image-10.0.0-1-generic  10.0.0.1-1  amd64"
-elif [ "$1" = "--compare-versions" ]; then
-    dpkg "$1" "$2" "$3" "$4"
-else
-    dpkg $@
-fi
-

test/integration/test-bug-1078697-missing-source-hashes → test/integration/test-ubuntu-bug-1078697-missing-source-hashes