diff options
author | Steve Langasek <steve.langasek@canonical.com> | 2012-11-05 12:32:27 -0800 |
---|---|---|
committer | Steve Langasek <steve.langasek@canonical.com> | 2012-11-05 12:32:27 -0800 |
commit | 08807527cb1f8ecd9883f284dad278def3175933 (patch) | |
tree | fb62abb3dd2a629c935a90c71cf3667f72b8ca7c | |
parent | 200b3080e739050c3f6c9e1b74242d9140bcbf21 (diff) | |
parent | a7e926d57fbed2e0cc1c059364191a3544ce2fe5 (diff) |
Merge test case from mvo
-rw-r--r-- | debian/apt.auto-removal.sh | 12 | ||||
-rwxr-xr-x | test/integration/test-kernel-helper-autoremove | 35 | ||||
-rw-r--r-- | test/integration/test-kernel-helper-autoremove.fake-dpkg | 13 |
3 files changed, 57 insertions, 3 deletions
diff --git a/debian/apt.auto-removal.sh b/debian/apt.auto-removal.sh index 598aee1a3..f44a11384 100644 --- a/debian/apt.auto-removal.sh +++ b/debian/apt.auto-removal.sh @@ -21,7 +21,13 @@ set -e # packages in the database because this runs from a postinst script, and apt # will overwrite the db when it exits. -config_file=/etc/apt/apt.conf.d/01autoremove-kernels + +eval $(apt-config shell APT_CONF_D Dir::Etc::parts/d) +test -n "${APT_CONF_D}" || APT_CONF_D="/etc/apt/apt.conf.d" +config_file=${APT_CONF_D}/01autoremove-kernels + +eval $(apt-config shell DPKG Dir::bin::dpkg/f) +test -n "$DPKG" || DPKG="/usr/bin/dpkg" installed_version="$1" running_version="$(uname -r)" @@ -32,11 +38,11 @@ version_test_gt () local version_test_gt_sedexp="s/[._-]\(pre\|rc\|test\|git\|old\|trunk\)/~\1/g" local version_a="`echo "$1" | sed -e "$version_test_gt_sedexp"`" local version_b="`echo "$2" | sed -e "$version_test_gt_sedexp"`" - dpkg --compare-versions "$version_a" gt "$version_b" + $DPKG --compare-versions "$version_a" gt "$version_b" return "$?" } -list=$(dpkg -l 'linux-image-[0-9]*'|awk '/^ii/ { print $2 }' | sed -e's/linux-image-//') +list=$(${DPKG} -l 'linux-image-[0-9]*'|awk '/^ii/ { print $2 }' | sed -e's/linux-image-//') latest_version="" previous_version="" diff --git a/test/integration/test-kernel-helper-autoremove b/test/integration/test-kernel-helper-autoremove new file mode 100755 index 000000000..4c0571b13 --- /dev/null +++ b/test/integration/test-kernel-helper-autoremove @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e + +# setup testdir +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +TMPDIR=$(mktemp -d) +cd $TMPDIR +addtrap "cd /; rm -rf $TMPDIR" + +# create mock environment +mkdir apt.conf.d +cat > aptconfig.conf <<EOF +Dir::Etc::parts "$TMPDIR/apt.conf.d"; +Dir::bin::dpkg "$TMPDIR/fake-dpkg"; +EOF +APT_CONFIG=aptconfig.conf +export APT_CONFIG + +# install fake-dpkg into it +install -m755 $TESTDIR/test-kernel-helper-autoremove.fake-dpkg $TMPDIR/fake-dpkg + +# run the helper +sh ${TESTDIR}/../../debian/apt.auto-removal.sh + +# and ensure its there, valid and version 10.0.0-1 is there too +test -e $TMPDIR/apt.conf.d/01autoremove-kernels +apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-10.0.0-1-generic\.\*" +# ... and also that the running kernel is exlucded +apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-$(uname -r)\.\*" + +# done +msgpass diff --git a/test/integration/test-kernel-helper-autoremove.fake-dpkg b/test/integration/test-kernel-helper-autoremove.fake-dpkg new file mode 100644 index 000000000..a365c5370 --- /dev/null +++ b/test/integration/test-kernel-helper-autoremove.fake-dpkg @@ -0,0 +1,13 @@ +#!/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 + |