test-kernel-helper-autoremove 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'amd64'
  7. CURRENTKERNEL="linux-image-$(uname -r | tr '[A-Z]' '[a-z]')"
  8. insertinstalledpackage "$CURRENTKERNEL" 'amd64' '5-1'
  9. # debug packages do not need our protection
  10. insertinstalledpackage "${CURRENTKERNEL}-dbg" 'amd64' '5-1'
  11. # but other kernel flavours should be protected
  12. insertinstalledpackage "${CURRENTKERNEL}-686-pae" 'i386' '5-1'
  13. insertinstalledpackage "${CURRENTKERNEL}-rt" 'amd64' '5-1'
  14. # some more versions
  15. insertinstalledpackage 'linux-image-1.0.0-2-generic' 'amd64' '1.0.0-2'
  16. insertinstalledpackage 'linux-image-100.0.0-1-generic' 'amd64' '100.0.0-1'
  17. # kernel metapackages should be ignored
  18. insertinstalledpackage 'linux-image-amd64' 'amd64' '200-1'
  19. insertinstalledpackage 'linux-image-686-pae' 'i386' '300-1'
  20. # ensure that the '.' is really a dot and not a wildcard
  21. insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1'
  22. # ensure that the '+' is really a plus and not a regexp quantifier
  23. insertinstalledpackage "${CURRENTKERNEL}+variant" 'amd64' '5-1'
  24. testsuccess aptmark auto "$CURRENTKERNEL" "${CURRENTKERNEL}-dbg" "${CURRENTKERNEL}-686-pae:i386" "${CURRENTKERNEL}-rt" \
  25. 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic' "${CURRENTKERNEL}+variant"
  26. testsuccess aptmark hold "${CURRENTKERNEL}-rt"
  27. testprotected() {
  28. rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
  29. testsuccess runapt sh "${TESTDIR}/../../debian/apt.auto-removal.sh" "$@"
  30. testfailure test -s rootdir/tmp/testsuccess.output
  31. msgtest 'Check kernel autoremoval protection list' 'is created'
  32. testsuccess --nomsg test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels
  33. testfilestats 'rootdir/etc/apt/apt.conf.d/01autoremove-kernels' '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:444"
  34. msgtest 'Check kernel autoremoval protection list' 'can be dumped'
  35. testsuccess --nomsg aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove'
  36. cp rootdir/tmp/testsuccess.output protected.list
  37. msgtest 'Check kernel autoremoval protection list' 'can be parsed'
  38. testfailure --nomsg grep '^[A-Z]: ' protected.list
  39. msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
  40. testsuccess --nomsg grep '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list
  41. msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
  42. testsuccess --nomsg grep "^\\^linux-image-$(uname -r | tr '[A-Z]' '[a-z]' | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list
  43. msgtest 'Check kernel autoremoval protection list does not include' 'metapackages'
  44. testfailure --nomsg grep -e '^\^linux-image-amd64\$$' -e '^\^linux-image-686-pae\$$' -e ':i386' protected.list
  45. }
  46. AUTOREMOVE='apt autoremove'
  47. if [ -n "$SUDO_USER" ]; then
  48. AUTOREMOVE="sudo $AUTOREMOVE"
  49. fi
  50. testsuccessequal "Reading package lists...
  51. Building dependency tree...
  52. Reading state information...
  53. The following packages were automatically installed and are no longer required:
  54. linux-headers-1000000-1-generic (100.0.0-1)
  55. linux-image-1.0.0-2-generic (1.0.0-2)
  56. linux-image-100.0.0-1-generic (100.0.0-1)
  57. $CURRENTKERNEL (5-1)
  58. ${CURRENTKERNEL}+variant (5-1)
  59. ${CURRENTKERNEL}-686-pae:i386 (5-1)
  60. ${CURRENTKERNEL}-dbg (5-1)
  61. Use '$AUTOREMOVE' to remove them.
  62. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV
  63. testsuccessequal "Reading package lists...
  64. Building dependency tree...
  65. Reading state information...
  66. The following packages were automatically installed and are no longer required:
  67. linux-headers-1000000-1-generic (100.0.0-1)
  68. linux-image-1.0.0-2-generic (1.0.0-2)
  69. linux-image-100.0.0-1-generic (100.0.0-1)
  70. $CURRENTKERNEL (5-1)
  71. ${CURRENTKERNEL}+variant (5-1)
  72. ${CURRENTKERNEL}-686-pae:i386 (5-1)
  73. ${CURRENTKERNEL}-dbg (5-1)
  74. ${CURRENTKERNEL}-rt (5-1)
  75. Use '$AUTOREMOVE' to remove them.
  76. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV --ignore-hold
  77. testequal "Reading package lists...
  78. Building dependency tree...
  79. Reading state information...
  80. 7 packages were automatically installed and are no longer required.
  81. Use '$AUTOREMOVE' to remove them.
  82. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -s -o APT::Get::HideAutoRemove=small
  83. testequal "Reading package lists...
  84. Building dependency tree...
  85. Reading state information...
  86. The following packages will be REMOVED:
  87. linux-headers-1000000-1-generic (100.0.0-1)
  88. linux-image-1.0.0-2-generic (1.0.0-2)
  89. linux-image-100.0.0-1-generic (100.0.0-1)
  90. $CURRENTKERNEL (5-1)
  91. ${CURRENTKERNEL}+variant (5-1)
  92. ${CURRENTKERNEL}-686-pae:i386 (5-1)
  93. ${CURRENTKERNEL}-dbg (5-1)
  94. 0 upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
  95. Remv linux-headers-1000000-1-generic [100.0.0-1]
  96. Remv linux-image-1.0.0-2-generic [1.0.0-2]
  97. Remv linux-image-100.0.0-1-generic [100.0.0-1]
  98. Remv $CURRENTKERNEL [5-1]
  99. Remv ${CURRENTKERNEL}+variant [5-1]
  100. Remv ${CURRENTKERNEL}-686-pae:i386 [5-1]
  101. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -sV
  102. msgmsg "run without parameter"
  103. testprotected
  104. msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
  105. testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
  106. testsuccessequal "Reading package lists...
  107. Building dependency tree...
  108. Reading state information...
  109. The following packages will be REMOVED:
  110. linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
  111. ${CURRENTKERNEL}-dbg
  112. 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
  113. Remv linux-headers-1000000-1-generic [100.0.0-1]
  114. Remv linux-image-1.0.0-2-generic [1.0.0-2]
  115. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
  116. msgmsg "install unknown kernel"
  117. # even if installed/uname reports a kernel which we can't find via dpkg,
  118. # ensure that we still protect it just in case as these are kernels we
  119. # know for sure without complicated detection mechanisms
  120. testprotected 1.0.0-2-ungeneric
  121. msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
  122. testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
  123. msgtest 'Check kernel autoremoval protection list does include' 'unknown installed kernel'
  124. testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-ungeneric\$$' protected.list
  125. testsuccessequal "Reading package lists...
  126. Building dependency tree...
  127. Reading state information...
  128. The following packages will be REMOVED:
  129. linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
  130. ${CURRENTKERNEL}-dbg
  131. 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
  132. Remv linux-headers-1000000-1-generic [100.0.0-1]
  133. Remv linux-image-1.0.0-2-generic [1.0.0-2]
  134. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
  135. msgmsg "install an old kernel"
  136. testprotected 1.0.0-2-generic
  137. msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
  138. testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
  139. testsuccessequal "Reading package lists...
  140. Building dependency tree...
  141. Reading state information...
  142. The following packages will be REMOVED:
  143. linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
  144. 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
  145. Remv linux-headers-1000000-1-generic [100.0.0-1]
  146. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
  147. # rt kernel was put on hold while the protected list was generated
  148. testsuccess aptmark unhold "${CURRENTKERNEL}-rt"
  149. testsuccessequal "Reading package lists...
  150. Building dependency tree...
  151. Reading state information...
  152. The following packages will be REMOVED:
  153. linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
  154. 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
  155. Remv linux-headers-1000000-1-generic [100.0.0-1]
  156. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s