test-policy-pinning 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture "i386"
  7. buildaptarchive
  8. setupflataptarchive
  9. STATUS=$(readlink -f rootdir/var/lib/dpkg/status)
  10. APTARCHIVE=$(readlink -f aptarchive)
  11. testequalpolicy() {
  12. local SP="$1"
  13. local AP="$2"
  14. shift 2
  15. testequal "Package files:
  16. $(echo "$SP" | awk '{ printf("%3s\n",$0) }') ${STATUS}
  17. release a=now
  18. $(echo "$AP" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ Packages
  19. release c=
  20. Pinned packages:" aptcache policy $*
  21. }
  22. aptget update -qq
  23. testequalpolicy 100 500
  24. testequalpolicy 990 500 -t now
  25. sed -i aptarchive/Release -e 1i"NotAutomatic: yes"
  26. aptget update -qq
  27. testequalpolicy 100 1 -o Test=NotAutomatic
  28. testequalpolicy 990 1 -o Test=NotAutomatic -t now
  29. sed -i aptarchive/Release -e 1i"ButAutomaticUpgrades: yes"
  30. aptget update -qq
  31. testequalpolicy 100 100 -o Test=ButAutomaticUpgrades
  32. testequalpolicy 990 100 -o Test=ButAutomaticUpgrades -t now
  33. sed -i aptarchive/Release -e 's#NotAutomatic: yes#NotAutomatic: no#' -e '/ButAutomaticUpgrades: / d'
  34. aptget update -qq
  35. testequalpolicy 100 500 -o Test=Automatic
  36. testequalpolicy 990 500 -o Test=Automatic -t now
  37. buildsimplenativepackage "coolstuff" "all" "1.0" "stable"
  38. buildsimplenativepackage "coolstuff" "all" "2.0~bpo1" "backports"
  39. setupaptarchive
  40. testequalpolicycoolstuff() {
  41. local INSTALLED="${1:-(none)}"
  42. local CANDIDATE="${2:-(none)}"
  43. local AB="$3"
  44. local AS="$4"
  45. local PB="$5"
  46. local PINVERSION="$6"
  47. if [ -n "$PINVERSION" ]; then
  48. PINVERSION="Package pin: $PINVERSION
  49. "
  50. fi
  51. local IS=""
  52. local IB=""
  53. local SB=""
  54. local SS=""
  55. [ "$1" = "2.0~bpo1" ] && IB="***" && SB="
  56. 100 $STATUS" || IB=" "
  57. [ "$1" = "1.0" ] && IS="***" && SS="
  58. 100 $STATUS" || IS=" "
  59. local BPO1ARCHIVE=""
  60. local BPO2ARCHIVE=""
  61. if [ ! "$7" = "2.0~bpo2" ]; then
  62. BPO1ARCHIVE=" $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ backports/main i386 Packages"
  63. else
  64. BPO2ARCHIVE="
  65. 2.0~bpo2 $PB
  66. $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ backports/main i386 Packages"
  67. SB="$(echo "$SB" | tail -n 1)"
  68. shift
  69. fi
  70. shift 6
  71. testequal "coolstuff:
  72. Installed: $INSTALLED
  73. Candidate: $CANDIDATE
  74. ${PINVERSION}Version table:${BPO2ARCHIVE}
  75. $IB 2.0~bpo1 $PB
  76. ${BPO1ARCHIVE}$SB
  77. $IS 1.0 $PB
  78. $(echo "$AS" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ stable/main i386 Packages$SS" \
  79. aptcache policy coolstuff -o Policy=${INSTALLED}-${CANDIDATE}-${AB}-${AS}-${PB} $*
  80. }
  81. testequalpolicycoolstuff "" "2.0~bpo1" 500 500 0 ""
  82. testequalpolicycoolstuff "" "1.0" 500 990 0 "" -t stable
  83. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -t backports
  84. echo "Package: *
  85. Pin: release n=backports
  86. Pin-Priority: 200" > rootdir/etc/apt/preferences
  87. testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=GlobalPin
  88. testequalpolicycoolstuff "" "1.0" 200 990 0 "" -o Test=GlobalPin -t stable
  89. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=GlobalPin -t backports
  90. echo "Package: *
  91. Pin: release n=backports
  92. Pin-Priority: 600" > rootdir/etc/apt/preferences
  93. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=GlobalPin
  94. testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=GlobalPin -t stable
  95. echo "Package: coolstuff
  96. Pin: release n=backports
  97. Pin-Priority: 200" > rootdir/etc/apt/preferences
  98. #FIXME: policy can't differentiate between two sources where one has a package specific pin in place
  99. # testequalpolicycoolstuff "" "1.0" 500 500 200 "2.0~bpo1" -o Test=PackagePin
  100. # testequalpolicycoolstuff "" "1.0" 990 500 200 "2.0~bpo1" -o Test=PackagePin -t backports
  101. testequalpolicycoolstuff "" "1.0" 500 990 200 "2.0~bpo1" -o Test=PackagePin -t stable
  102. echo "Package: coolstuff
  103. Pin: release n=backports
  104. Pin-Priority: 600" > rootdir/etc/apt/preferences
  105. testequalpolicycoolstuff "" "2.0~bpo1" 500 500 600 "2.0~bpo1" -o Test=PackagePin
  106. testequalpolicycoolstuff "" "1.0" 500 990 600 "2.0~bpo1" -o Test=PackagePin -t stable
  107. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=PackagePin -t backports
  108. echo "Package: coolstuff
  109. Pin: release n=backports
  110. Pin-Priority: -1" > rootdir/etc/apt/preferences
  111. # testequalpolicycoolstuff "" "1.0" 500 500 -1 "2.0~bpo1" -o Test=PackagePin
  112. # testequalpolicycoolstuff "" "1.0" 990 500 -1 "2.0~bpo1" -o Test=PackagePin -t backports
  113. # testequalpolicycoolstuff "" "1.0" 500 990 -1 "2.0~bpo1" -o Test=PackagePin -t stable
  114. rm rootdir/etc/apt/preferences
  115. sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
  116. signreleasefiles
  117. aptget update -qq
  118. testequalpolicycoolstuff "" "1.0" 1 500 0 "" -o Test=NotAutomatic
  119. testequalpolicycoolstuff "" "1.0" 1 990 0 "" -o Test=NotAutomatic -t stable
  120. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=NotAutomatic -t backports
  121. echo "Package: *
  122. Pin: release n=backports
  123. Pin-Priority: 200" > rootdir/etc/apt/preferences
  124. testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=NotAutomatic
  125. echo "Package: *
  126. Pin: release n=backports
  127. Pin-Priority: 600" > rootdir/etc/apt/preferences
  128. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=NotAutomatic
  129. testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=NotAutomatic -t stable
  130. echo "Package: coolstuff
  131. Pin: release n=backports
  132. Pin-Priority: 200" > rootdir/etc/apt/preferences
  133. testequalpolicycoolstuff "" "1.0" 1 500 200 "2.0~bpo1" -o Test=NotAutomatic
  134. echo "Package: coolstuff
  135. Pin: release n=backports
  136. Pin-Priority: 600" > rootdir/etc/apt/preferences
  137. testequalpolicycoolstuff "" "2.0~bpo1" 1 500 600 "2.0~bpo1" -o Test=NotAutomatic
  138. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=NotAutomatic -t backports
  139. testequalpolicycoolstuff "" "1.0" 1 990 600 "2.0~bpo1" -o Test=NotAutomatic -t stable
  140. rm rootdir/etc/apt/preferences
  141. sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
  142. signreleasefiles
  143. aptget update -qq
  144. testequalpolicycoolstuff "" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
  145. testequalpolicycoolstuff "" "1.0" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
  146. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
  147. echo "Package: *
  148. Pin: release n=backports
  149. Pin-Priority: 200" > rootdir/etc/apt/preferences
  150. testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=ButAutomaticUpgrades
  151. echo "Package: *
  152. Pin: release n=backports
  153. Pin-Priority: 600" > rootdir/etc/apt/preferences
  154. testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=ButAutomaticUpgrades
  155. testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=ButAutomaticUpgrades -t stable
  156. echo "Package: coolstuff
  157. Pin: release n=backports
  158. Pin-Priority: 200" > rootdir/etc/apt/preferences
  159. testequalpolicycoolstuff "" "1.0" 100 500 200 "2.0~bpo1" -o Test=ButAutomaticUpgrades
  160. echo "Package: coolstuff
  161. Pin: release n=backports
  162. Pin-Priority: 600" > rootdir/etc/apt/preferences
  163. testequalpolicycoolstuff "" "2.0~bpo1" 100 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades
  164. testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t backports
  165. testequalpolicycoolstuff "" "1.0" 100 990 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t stable
  166. rm rootdir/etc/apt/preferences
  167. aptget install coolstuff -qq > /dev/null 2> /dev/null
  168. testequalpolicycoolstuff "1.0" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
  169. aptget dist-upgrade -qq > /dev/null 2> /dev/null
  170. testequalpolicycoolstuff "1.0" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
  171. testequalpolicycoolstuff "1.0" "1.0" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
  172. testequalpolicycoolstuff "1.0" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
  173. aptget install coolstuff -t backports -qq > /dev/null 2> /dev/null
  174. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 0 "" -o Test=ButAutomaticUpgrades
  175. aptget dist-upgrade -qq > /dev/null 2> /dev/null
  176. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 0 "" -o Test=ButAutomaticUpgrades
  177. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
  178. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
  179. rm incoming/backports.main.pkglist incoming/backports.main.srclist
  180. buildsimplenativepackage "coolstuff" "all" "2.0~bpo2" "backports"
  181. setupaptarchive
  182. sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
  183. signreleasefiles
  184. aptget update -qq
  185. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 500 0 "" "2.0~bpo2" -o Test=NotAutomatic
  186. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 990 0 "" "2.0~bpo2" -o Test=NotAutomatic -t stable
  187. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 0 "" "2.0~bpo2" -o Test=NotAutomatic -t backports
  188. sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
  189. signreleasefiles
  190. aptget update -qq
  191. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 500 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades
  192. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 990 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t stable
  193. testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t backports