From b9b0f6222c489db78331cc8be3c093538d22c70b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 10 Mar 2014 17:53:22 +0100 Subject: 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. --- debian/apt.auto-removal.sh | 21 ++--- debian/apt.conf.autoremove | 9 +++ test/integration/framework | 10 ++- .../test-bug-1078697-missing-source-hashes | 35 --------- test/integration/test-kernel-helper-autoremove | 91 ++++++++++++---------- .../test-kernel-helper-autoremove.fake-dpkg | 13 ---- .../test-ubuntu-bug-1078697-missing-source-hashes | 35 +++++++++ 7 files changed, 113 insertions(+), 101 deletions(-) delete mode 100755 test/integration/test-bug-1078697-missing-source-hashes delete mode 100644 test/integration/test-kernel-helper-autoremove.fake-dpkg create mode 100755 test/integration/test-ubuntu-bug-1078697-missing-source-hashes diff --git a/debian/apt.auto-removal.sh b/debian/apt.auto-removal.sh index d105f440a..9c4a4157d 100644 --- a/debian/apt.auto-removal.sh +++ b/debian/apt.auto-removal.sh @@ -72,22 +72,23 @@ $previous_version EOF ) -cat > "$config_file".dpkg-new <> "$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 < "${config_file}.dpkg-new" +mv "${config_file}.dpkg-new" "$config_file" diff --git a/debian/apt.conf.autoremove b/debian/apt.conf.autoremove index 9684c9c7d..ea68f88fc 100644 --- a/debian/apt.conf.autoremove +++ b/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"; diff --git a/test/integration/framework b/test/integration/framework index c623e6231..dad8c99f0 100644 --- a/test/integration/framework +++ b/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 diff --git a/test/integration/test-bug-1078697-missing-source-hashes b/test/integration/test-bug-1078697-missing-source-hashes deleted file mode 100755 index 6fcb856b5..000000000 --- a/test/integration/test-bug-1078697-missing-source-hashes +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -set -e - -TESTDIR=$(readlink -f $(dirname $0)) -. $TESTDIR/framework -setupenvironment -configarchitecture "i386" - -msgtest 'Test apt-ftparchive source with missing hashes in .dsc' - -touch aptarchive/foo_1.0.tar.gz -cat > aptarchive/foo_1.0.dsc << EOF -Format: 3.0 (native) -Source: foo -Binary: foo -Architecture: all -Version: 1.0 -Package-List: - foo deb admin extra -Files: - d41d8cd98f00b204e9800998ecf8427e 0 foo_1.0.tar.gz -EOF - -# check for the SHA hashes -aptftparchive sources aptarchive/ > aptarchive/Sources 2>/dev/null || msgfail -test -n "$(grep Checksums-Sha512 aptarchive/Sources)" && msgpass || msgfail - -for hash in sha512sum sha256sum sha1sum; do - for f in foo_1.0.tar.gz foo_1.0.dsc; do - SUM=$($hash aptarchive/$f | cut -d' ' -f1) - msgtest "Test $hash hash matches for $f" - NEEDLE="$SUM $(stat -c%s aptarchive/$f) $f" - test -n "$SUM" && test -n "$(grep "$NEEDLE" aptarchive/Sources)" && msgpass || msgfail - done -done diff --git a/test/integration/test-kernel-helper-autoremove b/test/integration/test-kernel-helper-autoremove index 2b165d100..be30c6f6e 100755 --- a/test/integration/test-kernel-helper-autoremove +++ b/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 < ./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 diff --git a/test/integration/test-kernel-helper-autoremove.fake-dpkg b/test/integration/test-kernel-helper-autoremove.fake-dpkg deleted file mode 100644 index a365c5370..000000000 --- a/test/integration/test-kernel-helper-autoremove.fake-dpkg +++ /dev/null @@ -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 - diff --git a/test/integration/test-ubuntu-bug-1078697-missing-source-hashes b/test/integration/test-ubuntu-bug-1078697-missing-source-hashes new file mode 100755 index 000000000..6fcb856b5 --- /dev/null +++ b/test/integration/test-ubuntu-bug-1078697-missing-source-hashes @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture "i386" + +msgtest 'Test apt-ftparchive source with missing hashes in .dsc' + +touch aptarchive/foo_1.0.tar.gz +cat > aptarchive/foo_1.0.dsc << EOF +Format: 3.0 (native) +Source: foo +Binary: foo +Architecture: all +Version: 1.0 +Package-List: + foo deb admin extra +Files: + d41d8cd98f00b204e9800998ecf8427e 0 foo_1.0.tar.gz +EOF + +# check for the SHA hashes +aptftparchive sources aptarchive/ > aptarchive/Sources 2>/dev/null || msgfail +test -n "$(grep Checksums-Sha512 aptarchive/Sources)" && msgpass || msgfail + +for hash in sha512sum sha256sum sha1sum; do + for f in foo_1.0.tar.gz foo_1.0.dsc; do + SUM=$($hash aptarchive/$f | cut -d' ' -f1) + msgtest "Test $hash hash matches for $f" + NEEDLE="$SUM $(stat -c%s aptarchive/$f) $f" + test -n "$SUM" && test -n "$(grep "$NEEDLE" aptarchive/Sources)" && msgpass || msgfail + done +done -- cgit v1.2.3