| 1 |
# Tests for skip_broken and allowerasing |
| 2 |
# (and a bit of nobest because the test case is too good to pass up) |
| 3 |
# |
| 4 |
# There are a lot of fairly complex, corner cases we test here especially towards the end. |
| 5 |
# |
| 6 |
# The test repo is generated by the setup_rpm_repo role. |
| 7 |
# |
| 8 |
# See test/integration/targets/setup_rpm_repo/library/create_repo.py for how the repo is laid out. |
| 9 |
# |
| 10 |
# This allows us to test various upgrades, downgrades, and installs with broken dependencies. |
| 11 |
# skip_broken should usually be successful in the upgrade/downgrade case, it will just do nothing. |
| 12 |
# |
| 13 |
# There is a nobest testcase or two thrown in, simply because this organization provides a very |
| 14 |
# good test case for that behavior as well. For example, just installing "broken-a" with no version |
| 15 |
# will try to install 2.0.0 which is broken. With nobest=true, it will fall back to 1.2.4. Similar |
| 16 |
# for upgrading. |
| 17 |
- block: |
| 18 |
- name: Install two packages |
| 19 |
dnf: |
| 20 |
name: |
| 21 |
- broken-a-1.2.3 |
| 22 |
- broken-b |
| 23 |
|
| 24 |
# This will fail. We have broken-a-1.2.3, and broken-b with a strong |
| 25 |
# dependency on it. broken-c has a strong dependency on broken-a-1.2.4. |
| 26 |
# Since installing that would break broken-b, we get a conflict. |
| 27 |
- name: Try installing a third package, intentionally broken |
| 28 |
dnf: |
| 29 |
name: |
| 30 |
- broken-c |
| 31 |
ignore_errors: true |
| 32 |
register: dnf_fail |
| 33 |
|
| 34 |
- assert: |
| 35 |
that: |
| 36 |
- dnf_fail is failed |
| 37 |
- "'Depsolve Error' in dnf_fail.msg" |
| 38 |
|
| 39 |
# skip_broken should still install nothing because the conflict is |
| 40 |
# still an issue. But it should skip over the broken packages and not |
| 41 |
# fail. |
| 42 |
- name: Try installing it with skip_broken |
| 43 |
dnf: |
| 44 |
name: |
| 45 |
- broken-c |
| 46 |
skip_broken: true |
| 47 |
register: skip_broken_res |
| 48 |
|
| 49 |
- name: Assert that nothing got installed |
| 50 |
assert: |
| 51 |
that: |
| 52 |
- skip_broken_res.msg == 'Nothing to do' |
| 53 |
- skip_broken_res.rc == 0 |
| 54 |
- skip_broken_res.results == [] |
| 55 |
|
| 56 |
- name: Remove all test packages |
| 57 |
dnf: |
| 58 |
name: |
| 59 |
- broken-* |
| 60 |
state: absent |
| 61 |
|
| 62 |
# broken-d depends on (unversioned) broken-a. |
| 63 |
# broken-a-2.0.0 has a broken dependency that doesn't exist. |
| 64 |
# skip_broken should cause us to skip our explicit broken-a-2.0.0 |
| 65 |
# and bring in broken-a-1.2.4 as a dep of broken-d. |
| 66 |
- name: Ensure proper failure with explicit broken version |
| 67 |
dnf: |
| 68 |
name: |
| 69 |
- broken-a-2.0.0 |
| 70 |
- broken-d |
| 71 |
ignore_errors: true |
| 72 |
register: dnf_fail |
| 73 |
|
| 74 |
- name: Assert that nothing got installed |
| 75 |
assert: |
| 76 |
that: |
| 77 |
- dnf_fail is failed |
| 78 |
- "'Depsolve Error' in dnf_fail.msg" |
| 79 |
|
| 80 |
- name: skip_broken with explicit version |
| 81 |
dnf: |
| 82 |
name: |
| 83 |
- broken-a-2.0.0 |
| 84 |
- broken-d |
| 85 |
skip_broken: true |
| 86 |
register: skip_broken_res |
| 87 |
|
| 88 |
- name: Assert that the right things got installed |
| 89 |
assert: |
| 90 |
that: |
| 91 |
- skip_broken_res.rc == 0 |
| 92 |
- skip_broken_res.results|length == 2 |
| 93 |
# FIXME: The following assertions have always been broken. Fix the code and/or test as needed. |
| 94 |
# - 'skip_broken_res.results|select("contains", "Installed: broken-a-1.2.4")|length > 0' |
| 95 |
# - 'skip_broken_res.results|select("contains", "Installed: broken-d-1.2.5")|length > 0' |
| 96 |
|
| 97 |
- name: Remove all test packages |
| 98 |
dnf: |
| 99 |
name: |
| 100 |
- broken-* |
| 101 |
state: absent |
| 102 |
|
| 103 |
# Walk the logic of _mark_package_install() here |
| 104 |
# We need to use a full-ish NVR/wildcard. _is_newer_version_installed() |
| 105 |
# will be false otherwise, no matter what. This might be a bug. |
| 106 |
# Relatedly, the real "Case 1" in the code seemingly can't be reached: |
| 107 |
# _is_newer_version_installed wants NVR, _is_installed wants name. |
| 108 |
# Both can't be true at the same time given one pkg_spec. Thus, we start |
| 109 |
# at "Case 2" |
| 110 |
|
| 111 |
# prereq |
| 112 |
- name: Install broken-a-1.2.4 |
| 113 |
dnf: |
| 114 |
name: |
| 115 |
- broken-a-1.2.4 |
| 116 |
state: present |
| 117 |
|
| 118 |
# Case 2: newer version is installed, allow_downgrade is true, |
| 119 |
# is_installed is false since we gave full NVR. |
| 120 |
# "upgrade" to broken-a-1.2.3, allow_downgrade=true |
| 121 |
- name: Do an "upgrade" to an older version of broken-a, allow_downgrade=true |
| 122 |
dnf: |
| 123 |
name: |
| 124 |
- broken-a-1.2.3-1* |
| 125 |
state: latest |
| 126 |
allow_downgrade: true |
| 127 |
check_mode: true |
| 128 |
register: res |
| 129 |
|
| 130 |
- vars: |
| 131 |
pkg_state: '{{ "Downgrade:" if dnf5 else "Installed:" }}' |
| 132 |
assert: |
| 133 |
that: |
| 134 |
- res is changed |
| 135 |
- res.results|select("contains", pkg_state ~ " broken-a-1.2.3")|length > 0 |
| 136 |
|
| 137 |
# Still case 2, but with broken package to test skip_broken |
| 138 |
# skip_broken: false |
| 139 |
- name: Do an "upgrade" to an older known broken version of broken-a, allow_downgrade=true, skip_broken=false |
| 140 |
dnf: |
| 141 |
name: |
| 142 |
- broken-a-1.2.3.4-1* |
| 143 |
state: latest |
| 144 |
allow_downgrade: true |
| 145 |
check_mode: true |
| 146 |
ignore_errors: true |
| 147 |
register: res |
| 148 |
|
| 149 |
- assert: |
| 150 |
that: |
| 151 |
# 1.2.3.4 has non-existent dep. Fail without skip_broken. |
| 152 |
- res is failed |
| 153 |
- "'Depsolve Error' in res.msg" |
| 154 |
|
| 155 |
# skip_broken: true |
| 156 |
- name: Do an "upgrade" to an older known broken version of broken-a, allow_downgrade=true, skip_broken=true |
| 157 |
dnf: |
| 158 |
name: |
| 159 |
- broken-a-1.2.3.4-1* |
| 160 |
state: latest |
| 161 |
allow_downgrade: true |
| 162 |
skip_broken: true |
| 163 |
check_mode: true |
| 164 |
register: res |
| 165 |
|
| 166 |
- assert: |
| 167 |
that: |
| 168 |
- res is not changed |
| 169 |
- res.rc == 0 |
| 170 |
- res.msg == "Nothing to do" |
| 171 |
|
| 172 |
# Case 3: newer version installed, allow_downgrade=true, but |
| 173 |
# upgrade=false (i.e., state: present or installed) |
| 174 |
- name: Install an older version of broken-a than currently installed |
| 175 |
dnf: |
| 176 |
name: |
| 177 |
- broken-a-1.2.3-1* |
| 178 |
state: present |
| 179 |
allow_downgrade: true |
| 180 |
check_mode: true |
| 181 |
register: res |
| 182 |
|
| 183 |
- vars: |
| 184 |
pkg_state: '{{ "Downgrade:" if dnf5 else "Installed:" }}' |
| 185 |
assert: |
| 186 |
that: |
| 187 |
- res is changed |
| 188 |
- res.results|select("contains", pkg_state ~ " broken-a-1.2.3")|length > 0 |
| 189 |
|
| 190 |
# Case 3 still, with broken package and skip_broken tests like above. |
| 191 |
- name: Install an older known broken version of broken-a, allow_downgrade=true, skip_broken=false |
| 192 |
dnf: |
| 193 |
name: |
| 194 |
- broken-a-1.2.3.4-1* |
| 195 |
state: present |
| 196 |
allow_downgrade: true |
| 197 |
check_mode: true |
| 198 |
ignore_errors: true |
| 199 |
register: res |
| 200 |
|
| 201 |
- assert: |
| 202 |
that: |
| 203 |
# 1.2.3.4 has non-existent dep. Fail without skip_broken. |
| 204 |
- res is failed |
| 205 |
- "'Depsolve Error' in res.msg" |
| 206 |
|
| 207 |
# skip_broken: true |
| 208 |
- name: Install an older known broken version of broken-a, allow_downgrade=true, skip_broken=true |
| 209 |
dnf: |
| 210 |
name: |
| 211 |
- broken-a-1.2.3.4-1* |
| 212 |
state: present |
| 213 |
allow_downgrade: true |
| 214 |
skip_broken: true |
| 215 |
check_mode: true |
| 216 |
register: res |
| 217 |
|
| 218 |
- assert: |
| 219 |
that: |
| 220 |
- res is not changed |
| 221 |
- res.rc == 0 |
| 222 |
- res.msg == "Nothing to do" |
| 223 |
|
| 224 |
# Case 4: "upgrade" to broken-a-1.2.3, allow_downgrade=false |
| 225 |
# is_newer_version_installed is true, allow_downgrade is false |
| 226 |
- name: Do an "upgrade" to an older version of broken-a, allow_downgrade=false |
| 227 |
dnf: |
| 228 |
name: |
| 229 |
- broken-a-1.2.3-1.noarch |
| 230 |
state: latest |
| 231 |
allow_downgrade: false |
| 232 |
check_mode: true |
| 233 |
register: res |
| 234 |
|
| 235 |
- assert: |
| 236 |
that: |
| 237 |
- res is not changed |
| 238 |
- res.rc == 0 |
| 239 |
- res.msg == "Nothing to do" |
| 240 |
|
| 241 |
# skip_broken doesn't apply to case 5 or 6 (older version installed). |
| 242 |
# base.upgrade doesn't allow a strict= kwarg. However, nobest works here. |
| 243 |
|
| 244 |
# Case 5: older version of package is installed, we specify name, no version |
| 245 |
# otherwise we'd land in an earlier case. At this point, 1.2.4 is installed. |
| 246 |
# broken-a-2.0.0 is available as an update but has a broken dependency. |
| 247 |
- name: Update broken-a without nobest=true |
| 248 |
dnf: |
| 249 |
name: |
| 250 |
- broken-a |
| 251 |
state: latest |
| 252 |
best: true |
| 253 |
ignore_errors: true |
| 254 |
register: dnf_fail |
| 255 |
|
| 256 |
- assert: |
| 257 |
that: |
| 258 |
- dnf_fail is failed |
| 259 |
- "'Depsolve Error' in dnf_fail.msg" |
| 260 |
|
| 261 |
# With nobest: true, we will be "successful" but not actually perform |
| 262 |
# any upgrade. That is, we are content not having the "best"/latest |
| 263 |
# version. |
| 264 |
- name: Update broken-a with nobest=true |
| 265 |
dnf: |
| 266 |
name: |
| 267 |
- broken-a |
| 268 |
state: latest |
| 269 |
nobest: true |
| 270 |
register: nobest |
| 271 |
|
| 272 |
- assert: |
| 273 |
that: |
| 274 |
- nobest.rc == 0 |
| 275 |
- nobest.results == [] |
| 276 |
|
| 277 |
# Case 6: Current or older version already installed (no version specified |
| 278 |
# in our pkg_spec) and we're requesting present, not latest. |
| 279 |
# |
| 280 |
# This isn't really relevant to skip_broken or nobest, but let's test it |
| 281 |
# anyway since we're already walking the logic of the method. |
| 282 |
- name: Install broken-a (even though it is already installed) |
| 283 |
dnf: |
| 284 |
name: |
| 285 |
- broken-a |
| 286 |
state: present |
| 287 |
register: res |
| 288 |
|
| 289 |
- assert: |
| 290 |
that: |
| 291 |
- res is not changed |
| 292 |
|
| 293 |
# Case 7 is already tested quite extensively above in the earlier tests. |
| 294 |
# ###################################################################### |
| 295 |
|
| 296 |
- block: |
| 297 |
- name: Test available package is installed while unavailable one is skipped due to skip_broken=true |
| 298 |
dnf: |
| 299 |
name: |
| 300 |
- dinginessentail |
| 301 |
- not-in-repo |
| 302 |
skip_broken: true |
| 303 |
register: res |
| 304 |
|
| 305 |
- assert: |
| 306 |
that: |
| 307 |
- res is changed |
| 308 |
# There is a change in dnf5 that splits skip_broken into two options: |
| 309 |
# skip_broken and skip_unavailable. |
| 310 |
# TODO: for this test to pass on dnf5 the skip_unavailable option would have to be |
| 311 |
# added to the dnf5 module and used here instead of skip_broken. |
| 312 |
when: not dnf5 |
| 313 |
|
| 314 |
always: |
| 315 |
- name: Remove all test packages installed |
| 316 |
dnf: |
| 317 |
name: |
| 318 |
- broken-* |
| 319 |
- dinginessentail |
| 320 |
state: absent |