| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2017 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import fnmatch |
| 9 |
import time |
| 10 |
from collections.abc import Collection |
| 11 |
|
| 12 |
import packagelib |
| 13 |
import submanlib |
| 14 |
import testlib |
| 15 |
|
| 16 |
OSesWithoutTracer = ["debian-*", "ubuntu-*", "fedora-coreos", "centos-10", "rhel-10*"] |
| 17 |
OSesWithDnfRestart = ["centos-10", "rhel-10*"] |
| 18 |
OSesWithoutKpatch = ["debian-*", "ubuntu-*", "arch", "fedora-*", "centos-*"] |
| 19 |
|
| 20 |
|
| 21 |
class NoSubManCase(packagelib.PackageCase): |
| 22 |
|
| 23 |
def setUp(self): |
| 24 |
super().setUp() |
| 25 |
|
| 26 |
# Disable Subscription Manager on RHEL for these tests; subscriptions are tested in a separate class |
| 27 |
# On other OSes (Fedora/CentOS) we expect sub-man to be disabled in dnf, so it should not get in the way there |
| 28 |
if self.machine.image.startswith("rhel") or self.machine.image.startswith("centos"): |
| 29 |
self.machine.execute("systemctl stop rhsm.service; systemctl mask rhsm.service") |
| 30 |
self.addCleanup(self.machine.execute, "systemctl unmask rhsm.service") |
| 31 |
|
| 32 |
# expected journal messages from enabling/disabling auto upgrade services |
| 33 |
self.allow_journal_messages("(Created symlink|Removed).*dnf-automatic-install.timer.*") |
| 34 |
|
| 35 |
|
| 36 |
@testlib.skipOstree("Image uses OSTree") |
| 37 |
class TestUpdates(NoSubManCase): |
| 38 |
|
| 39 |
def setUp(self): |
| 40 |
super().setUp() |
| 41 |
|
| 42 |
# apt does not support severity enhancement metadata |
| 43 |
# only PackageKit ≥ 1.2.4 dnf (https://github.com/PackageKit/PackageKit/issues/268) supports severity |
| 44 |
self.supports_severity = (self.backend != "apt") and (not self.machine.image.startswith("rhel-8")) |
| 45 |
|
| 46 |
if self.supports_severity: |
| 47 |
self.enhancement_severity = "enhancement" |
| 48 |
else: |
| 49 |
self.enhancement_severity = "bug" |
| 50 |
|
| 51 |
self.update_icon = "#page_status_notification_updates .pf-v6-svg" |
| 52 |
self.update_text = "#page_status_notification_updates" |
| 53 |
self.update_text_action = "#page_status_notification_updates a" |
| 54 |
|
| 55 |
def assertHistory(self, path: str, updates: list[str]) -> None: |
| 56 |
selector = path + " li:nth-child({0})" |
| 57 |
for index, pkg in enumerate(updates, start=1): |
| 58 |
self.browser.wait_in_text(selector.format(index), pkg) |
| 59 |
# make sure we don't have any extra ones |
| 60 |
self.assertFalse(self.browser.is_present(selector.format(len(updates) + 1))) |
| 61 |
|
| 62 |
def check_nth_update(self, index: int, pkgname: list[str] | str, version: str, severity: str = "bug", |
| 63 |
num_issues: 'int | None' = None, desc_matches: Collection[str] = (), |
| 64 |
cves: Collection[str] = (), bugs: Collection[str] = (), arch: 'str | None' = None, |
| 65 |
absent_anchor_attributes: Collection[str] = ()) -> str: |
| 66 |
"""Check the contents of the package update table row at index |
| 67 |
|
| 68 |
None properties will not be tested. |
| 69 |
""" |
| 70 |
b = self.browser |
| 71 |
if arch is None: |
| 72 |
arch = self.primary_arch |
| 73 |
row = "#available-updates table[aria-label='Available updates'] > tbody:nth-of-type(%i) " % index |
| 74 |
|
| 75 |
if isinstance(pkgname, list): |
| 76 |
for idx, pkg in enumerate(pkgname, 1): |
| 77 |
sel = row + "tr:first-child [data-label=Name] > div:nth-of-type(%i) span" % idx |
| 78 |
self.assertEqual(b.text(sel).split(', ', 1)[0], pkg) |
| 79 |
else: |
| 80 |
self.assertEqual(b.text(row + " tr:first-child [data-label=Name]"), pkgname) |
| 81 |
b.mouse(row + "tr:first-child [data-label=Name] span", "mouseenter") |
| 82 |
b.wait_text(".pf-v6-c-tooltip", f"dummy {pkgname} ({arch})") |
| 83 |
b.mouse(row + "tr:first-child [data-label=Name] span", "mouseleave") |
| 84 |
b.wait_not_present(".pf-v6-c-tooltip") |
| 85 |
self.assertEqual(b.text(row + "[data-label=Version]"), version) |
| 86 |
# verify type |
| 87 |
severity_to_aria = {"bug": "bug fix", "enhancement": "enhancement", "security": "security"} |
| 88 |
b.wait_visible(f"{row} [data-label=Severity] .severity-icon[aria-label='{severity_to_aria[severity]}']") |
| 89 |
self.assertEqual(b.text(row + "[data-label=Severity]").strip(), |
| 90 |
'' if num_issues is None else str(num_issues)) |
| 91 |
|
| 92 |
# should not be expanded by default |
| 93 |
self.assertNotIn("pf-m-expanded", b.attr(row, "class")) |
| 94 |
# expand |
| 95 |
b.click(row + "td.pf-v6-c-table__toggle button") |
| 96 |
self.assertIn("pf-m-expanded", b.attr(row, "class")) |
| 97 |
b.wait_in_text(row + "> .pf-v6-c-table__expandable-row.pf-m-expanded", "Packages") |
| 98 |
desc = b.text(row + "> .pf-v6-c-table__expandable-row.pf-m-expanded") |
| 99 |
|
| 100 |
# details should contain all description bits, CVEs and bug numbers |
| 101 |
for m in (*desc_matches, *cves, *bugs): |
| 102 |
self.assertIn(m, desc) |
| 103 |
|
| 104 |
for absent_anchor in absent_anchor_attributes: |
| 105 |
self.assertIsNone(b.attr(f"{row} [data-label='Details'] a", absent_anchor)) |
| 106 |
|
| 107 |
return row |
| 108 |
|
| 109 |
def wait_checking_updates(self): |
| 110 |
"""Wait until spinner is gone from updates icon for 3 s""" |
| 111 |
|
| 112 |
good_count = 0 |
| 113 |
for _ in range(60): |
| 114 |
classes = self.browser.attr(self.update_icon, "class") |
| 115 |
if classes is not None and "pf-v6-c-spinner" in classes: |
| 116 |
good_count = 0 |
| 117 |
else: |
| 118 |
good_count += 1 |
| 119 |
if good_count >= 3: |
| 120 |
return |
| 121 |
time.sleep(1) |
| 122 |
|
| 123 |
self.fail("Timed out waiting for updates spinner to go away") |
| 124 |
|
| 125 |
@testlib.nondestructive |
| 126 |
@testlib.skipImage("kpatch is not available", *OSesWithoutKpatch) |
| 127 |
def testKpatch(self): |
| 128 |
b = self.browser |
| 129 |
m = self.machine |
| 130 |
|
| 131 |
kernel_ver_arch = m.execute("uname -r").strip() |
| 132 |
fields = kernel_ver_arch.split("-") |
| 133 |
kpp_kernel_version = fields[0].replace(".", "_") |
| 134 |
release = fields[1].split(".")[:-2] # remove el8.x86_64 |
| 135 |
kpp_kernel_release = "_".join(release) |
| 136 |
|
| 137 |
sanitized_kernel_ver = "_".join(kernel_ver_arch.split(".")[:-2]) |
| 138 |
self.createPackage("-".join(["kpatch-patch", kpp_kernel_version, kpp_kernel_release]), "0", "0", |
| 139 |
arch=self.secondary_arch, provides=f"kpatch-patch = {kernel_ver_arch}") |
| 140 |
self.enableRepo() |
| 141 |
|
| 142 |
self.restore_file("/etc/dnf/plugins/kpatch.conf") |
| 143 |
m.execute("systemctl disable --now kpatch") |
| 144 |
|
| 145 |
self.login_and_go("/updates") |
| 146 |
with b.wait_timeout(30): |
| 147 |
b.wait_visible("#status") |
| 148 |
|
| 149 |
# on supported systems we show a spinner |
| 150 |
b.wait_visible("#kpatch-settings svg.pf-v6-c-spinner") |
| 151 |
|
| 152 |
# Enable and install kpatch |
| 153 |
with b.wait_timeout(30): |
| 154 |
b.wait_in_text("#kpatch-settings", "Disabled") |
| 155 |
b.click("#kpatch-settings button:contains('Enable')") |
| 156 |
|
| 157 |
# Apply kernel live patches for current and future kernels |
| 158 |
b.click("#apply-kpatch") |
| 159 |
b.wait_visible("#apply-kpatch:checked") |
| 160 |
b.wait_visible("#current-future:checked") |
| 161 |
|
| 162 |
b.click("button:contains('Save')") |
| 163 |
b.wait_not_present("#kpatch-setup") |
| 164 |
|
| 165 |
self.assertIn("True", m.execute("grep autoupdate /etc/dnf/plugins/kpatch.conf")) |
| 166 |
self.assertEqual(m.execute("systemctl is-enabled kpatch").strip(), "enabled") |
| 167 |
self.assertEqual(m.execute("systemctl is-active kpatch").strip(), "active") |
| 168 |
# Patches should be installed |
| 169 |
m.execute("rpm -q kpatch-patch-" + sanitized_kernel_ver) |
| 170 |
|
| 171 |
# Faking real patches is really hard, so fake `kpatch list` command |
| 172 |
# To make sure it has the same structure as we expect it to be first check the real command |
| 173 |
self.assertEqual(m.execute("kpatch list"), "Loaded patch modules:\n\nInstalled patch modules:\n") |
| 174 |
|
| 175 |
kpatch = """#!/bin/bash |
| 176 |
echo -e "Loaded patch modules:\nkpatch_3_10_0_1062_1_1 [enabled]\n\nInstalled patch modules:\nkpatch_3_10_0_1062_1_1 (3.10.0-1062.el7.x86_64)" |
| 177 |
""" |
| 178 |
|
| 179 |
self.createPackage("kpatch-patch-" + sanitized_kernel_ver, "1", "0", arch=self.secondary_arch, |
| 180 |
provides=f"kpatch-patch = {kernel_ver_arch}", |
| 181 |
content={"/usr/local/bin/kpatch": kpatch}, |
| 182 |
postinst="chmod +x /usr/local/bin/kpatch; mount -o bind /usr/local/bin/kpatch /usr/sbin/kpatch") |
| 183 |
# Mix in an normal update and ensure it's not updated |
| 184 |
self.createPackage("vanilla", "1.0", "1", install=True) |
| 185 |
self.createPackage("vanilla", "1.0", "2") |
| 186 |
self.createPackage("secdeclare", "3", "4.a1", install=True) |
| 187 |
self.createPackage("secdeclare", "3", "4.b1", severity="security", |
| 188 |
changes="Will crash your data center", cves=["CVE-2014-123456"]) |
| 189 |
self.enableRepo() |
| 190 |
self.addCleanup(m.execute, "umount /usr/sbin/kpatch") |
| 191 |
|
| 192 |
b.click("#status .pf-v6-c-card__actions button") |
| 193 |
b.wait_visible(".pf-v6-c-badge:contains('patches')") |
| 194 |
b.click("button:contains('Install kpatch updates')") |
| 195 |
b.click("button:contains('Continue')") |
| 196 |
b.wait_in_text("#status", "Kernel live patch kpatch_3_10_0_1062_1_1 is active") |
| 197 |
# Other updates are not installed |
| 198 |
self.check_nth_update(1, "secdeclare", "3-4.b1", "security", 1, |
| 199 |
desc_matches=["Will crash your data center"], cves=["CVE-2014-123456"]) |
| 200 |
self.check_nth_update(2, "vanilla", "1.0-2") |
| 201 |
self.assertEqual(m.execute("rpm -q vanilla").strip(), "vanilla-1.0-1.noarch") |
| 202 |
|
| 203 |
# Switch to 'for current kernel only' |
| 204 |
b.click("#kpatch-settings button:contains('Edit')") |
| 205 |
b.click("#current-only") |
| 206 |
b.wait_visible("#current-future:not(:checked)") |
| 207 |
b.wait_visible("#current-only:checked") |
| 208 |
|
| 209 |
b.click("button:contains('Save')") |
| 210 |
b.wait_not_present("#kpatch-setup") |
| 211 |
|
| 212 |
self.assertIn("False", m.execute("grep autoupdate /etc/dnf/plugins/kpatch.conf")) |
| 213 |
self.assertEqual(m.execute("systemctl is-enabled kpatch").strip(), "enabled") |
| 214 |
self.assertEqual(m.execute("systemctl is-active kpatch").strip(), "active") |
| 215 |
# Patches should be installed |
| 216 |
m.execute("rpm -q kpatch-patch-" + sanitized_kernel_ver) |
| 217 |
|
| 218 |
# Test disabling applying patches |
| 219 |
b.click("#kpatch-settings button:contains('Edit')") |
| 220 |
b.wait_visible("#apply-kpatch:checked") |
| 221 |
b.click("#apply-kpatch") |
| 222 |
b.wait_visible("#apply-kpatch:not(:checked)") |
| 223 |
|
| 224 |
b.click("button:contains('Save')") |
| 225 |
b.wait_not_present("#kpatch-setup") |
| 226 |
|
| 227 |
b.wait_in_text("#kpatch-settings", "Disabled") |
| 228 |
b.click("#kpatch-settings button:contains('Enable')") |
| 229 |
|
| 230 |
# Test closing of the dialog and resetting of changes |
| 231 |
b.wait_visible("#apply-kpatch:not(:checked)") |
| 232 |
b.click("#apply-kpatch") |
| 233 |
b.wait_visible("#apply-kpatch:checked") |
| 234 |
b.click("button:contains('Cancel')") |
| 235 |
b.wait_not_present("#kpatch-setup") |
| 236 |
b.click("#kpatch-settings button:contains('Enable')") |
| 237 |
b.wait_visible("#apply-kpatch:not(:checked)") |
| 238 |
|
| 239 |
# Test 'for current kernel only' from clean state |
| 240 |
m.execute("umount /usr/sbin/kpatch") |
| 241 |
m.execute("systemctl restart kpatch") |
| 242 |
m.execute("dnf -y remove kpatch-patch-" + sanitized_kernel_ver) |
| 243 |
b.reload() # Not listening on patches being removed |
| 244 |
b.enter_page("/updates") |
| 245 |
|
| 246 |
b.wait_in_text("#kpatch-settings", "Disabled") |
| 247 |
b.click("#kpatch-settings button:contains('Enable')") |
| 248 |
|
| 249 |
# Apply kernel live patches for current and future kernels |
| 250 |
b.click("#apply-kpatch") |
| 251 |
b.wait_visible("#apply-kpatch:checked") |
| 252 |
b.click("#current-only") |
| 253 |
b.wait_visible("#current-future:not(:checked)") |
| 254 |
b.wait_visible("#current-only:checked") |
| 255 |
|
| 256 |
b.click("button:contains('Save')") |
| 257 |
b.wait_not_present("#kpatch-setup") |
| 258 |
|
| 259 |
self.assertIn("False", m.execute("grep autoupdate /etc/dnf/plugins/kpatch.conf")) |
| 260 |
self.assertEqual(m.execute("systemctl is-enabled kpatch").strip(), "enabled") |
| 261 |
self.assertEqual(m.execute("systemctl is-active kpatch").strip(), "active") |
| 262 |
# Patches should be installed |
| 263 |
m.execute("rpm -q kpatch-patch-" + sanitized_kernel_ver) |
| 264 |
|
| 265 |
@testlib.nondestructive |
| 266 |
@testlib.skipImage("alpm PackageKit backend does not support cancelling", "arch") |
| 267 |
def testBasic(self): |
| 268 |
# no security updates, no changelogs |
| 269 |
b = self.browser |
| 270 |
m = self.machine |
| 271 |
|
| 272 |
def check_status(): |
| 273 |
if any(fnmatch.fnmatch(m.image, img) for img in OSesWithoutTracer): |
| 274 |
b.wait_in_text("#status p", "System is up to date") |
| 275 |
# PK starts from a blank state, thus should force refresh and set the "time since" to 0 |
| 276 |
b.wait_in_text("#last-checked", "Last checked: less than a minute ago") |
| 277 |
else: |
| 278 |
code = m.execute("tracer > /dev/null 2>&1; echo $?").rstrip() |
| 279 |
if code == "104": |
| 280 |
b.wait_in_text("#status p", "a system reboot") |
| 281 |
elif code == "102" or code == "101": |
| 282 |
b.wait_in_text("#status p", "to be restarted") |
| 283 |
else: |
| 284 |
b.wait_in_text("#status p", "System is up to date") |
| 285 |
# PK starts from a blank state, thus should force refresh and set the "time since" to 0 |
| 286 |
b.wait_in_text("#last-checked", "Last checked: less than a minute ago") |
| 287 |
|
| 288 |
self.enable_preload("packagekit", "index") |
| 289 |
|
| 290 |
# Refresh cache so cockpit does not try to reload page |
| 291 |
self.refreshMetadata() |
| 292 |
|
| 293 |
self.login_and_go("/system") |
| 294 |
# status on /system front page: no repos at all, thus no updates |
| 295 |
self.wait_checking_updates() |
| 296 |
b.wait_text(self.update_text, "System is up to date") |
| 297 |
self.assertEqual(b.attr(self.update_icon, "data-pficon"), "check") |
| 298 |
|
| 299 |
# no updates on the Software Updates page |
| 300 |
b.go("/updates") |
| 301 |
b.enter_page("/updates") |
| 302 |
|
| 303 |
# refresh |
| 304 |
b.click("#status .pf-v6-c-card__header button") |
| 305 |
check_status() |
| 306 |
|
| 307 |
install_lockfile = "/tmp/finish-pk" |
| 308 |
# create two updates; force installing chocolate before vanilla |
| 309 |
self.createPackage("vanilla", "1.0", "1", install=True) |
| 310 |
self.createPackage("vanilla", "1.0", "2", depends="chocolate", |
| 311 |
postinst=f"while [ ! -e {install_lockfile} ]; do sleep 1; done; rm -f {install_lockfile}") |
| 312 |
self.createPackage("chocolate", "2.0", "1", install=True, arch=self.secondary_arch) |
| 313 |
self.createPackage("chocolate", "2.0", "2", arch=self.secondary_arch) |
| 314 |
self.enableRepo() |
| 315 |
|
| 316 |
# check again |
| 317 |
b.click("#status .pf-v6-c-card__header button") |
| 318 |
|
| 319 |
with b.wait_timeout(30): |
| 320 |
b.wait_visible("#available-updates") |
| 321 |
b.wait_in_text("#status", "2 updates available") |
| 322 |
|
| 323 |
b.wait_in_text("table[aria-label='Available updates']", "vanilla") |
| 324 |
self.check_nth_update(1, "chocolate", "2.0-2", arch=self.secondary_arch) |
| 325 |
self.check_nth_update(2, "vanilla", "1.0-2") |
| 326 |
|
| 327 |
# updates are shown on system page |
| 328 |
b.go("/system") |
| 329 |
b.enter_page("/system") |
| 330 |
self.wait_checking_updates() |
| 331 |
b.wait_text(self.update_text, "Bug fix updates available") |
| 332 |
self.assertEqual(b.attr(self.update_icon, "data-pficon"), "bug") |
| 333 |
# should be a link, click on it to go to /updates |
| 334 |
b.click(self.update_text_action) |
| 335 |
b.enter_page("/updates") |
| 336 |
|
| 337 |
# old versions are still installed |
| 338 |
m.execute("test -f /stamp-vanilla-1.0-1; test -f /stamp-chocolate-2.0-1") |
| 339 |
|
| 340 |
# no update history yet |
| 341 |
self.assertFalse(b.is_present("table.updates-history")) |
| 342 |
|
| 343 |
# should only have one button (no security updates) |
| 344 |
self.assertEqual(b.text("#available-updates button#install-all"), "Install all updates") |
| 345 |
|
| 346 |
# update; Cancel button should eventually disappear, on some OSes |
| 347 |
b.click("#available-updates button#install-all") |
| 348 |
b.wait_visible(".progress-main-view") |
| 349 |
if m.image in ["fedora-44"]: |
| 350 |
# dnf5backend allows "Cancel" during setup |
| 351 |
pass |
| 352 |
else: |
| 353 |
b.wait_not_present(".progress-main-view button.pf-m-secondary") |
| 354 |
# gets stuck at vanilla, which needs install_lockfile |
| 355 |
b.wait_in_text("#app div.progress-description", "vanilla 1.0-2") |
| 356 |
|
| 357 |
# update log only exists in the expander, collapsed by default |
| 358 |
self.assertFalse(b.is_visible("#update-log")) |
| 359 |
# expand it |
| 360 |
b.click(".pf-v6-c-expandable-section__toggle button") |
| 361 |
# should eventually show chocolate when vanilla starts installing |
| 362 |
b.wait_in_text("#update-log", "chocolate") |
| 363 |
|
| 364 |
# finish the package installation |
| 365 |
m.execute(f"touch {install_lockfile}") |
| 366 |
|
| 367 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 368 |
# if restart checking is not present, reboot is recommended |
| 369 |
if any(fnmatch.fnmatch(m.image, img) for img in OSesWithoutTracer) and not any( |
| 370 |
fnmatch.fnmatch(m.image, img) for img in OSesWithDnfRestart): |
| 371 |
b.wait_in_text("#app .pf-v6-c-empty-state button.pf-m-primary", "Reboot system...") |
| 372 |
b.click("#ignore") |
| 373 |
|
| 374 |
# should go back to updates overview, nothing pending any more |
| 375 |
check_status() |
| 376 |
|
| 377 |
# TODO make Packagekit GetUpdates work for tests properly |
| 378 |
b.wait_not_present("#available-updates") |
| 379 |
|
| 380 |
# new versions are now installed |
| 381 |
m.execute("test -f /stamp-vanilla-1.0-2; test -f /stamp-chocolate-2.0-2") |
| 382 |
|
| 383 |
# history shows the two packages, expanded by default |
| 384 |
b.wait_text("table.updates-history tbody.pf-m-expanded td.history-pkgcount", "2 packages") |
| 385 |
b.wait_in_text("table.updates-history .pf-v6-c-table__expandable-row.pf-m-expanded", "chocolate") |
| 386 |
b.wait_in_text("table.updates-history .pf-v6-c-table__expandable-row.pf-m-expanded", "vanilla") |
| 387 |
|
| 388 |
# system page has current state as well |
| 389 |
b.go("/system") |
| 390 |
b.enter_page("/system") |
| 391 |
self.wait_checking_updates() |
| 392 |
self.assertEqual(b.attr(self.update_icon, "data-pficon"), "check") |
| 393 |
b.wait_text(self.update_text, "System is up to date") |
| 394 |
|
| 395 |
@testlib.nondestructive |
| 396 |
@testlib.skipImage("alpm PackageKit backend does not support cancelling", "arch") |
| 397 |
def testBasicTZFullHour(self): |
| 398 |
m = self.machine |
| 399 |
orig_timezone = m.execute("timedatectl show --value -p Timezone").strip() |
| 400 |
self.addCleanup(m.execute, f"timedatectl set-timezone {orig_timezone}") |
| 401 |
# UTC+1 or 2 |
| 402 |
m.execute("timedatectl set-timezone Europe/Berlin") |
| 403 |
self.testBasic() |
| 404 |
|
| 405 |
@testlib.nondestructive |
| 406 |
@testlib.skipImage("alpm PackageKit backend does not support cancelling", "arch") |
| 407 |
def testBasicTZHalfHour(self): |
| 408 |
m = self.machine |
| 409 |
orig_timezone = m.execute("timedatectl show --value -p Timezone").strip() |
| 410 |
self.addCleanup(m.execute, f"timedatectl set-timezone {orig_timezone}") |
| 411 |
# IST = UTC + 5:30 |
| 412 |
m.execute("timedatectl set-timezone Asia/Kolkata") |
| 413 |
self.testBasic() |
| 414 |
|
| 415 |
# returns ExecMainStartTimestamp |
| 416 |
def createServicePackageUpgrade(self, package: str, *, manual_proc: bool = False) -> str: |
| 417 |
m = self.machine |
| 418 |
|
| 419 |
unitContent = f"""[Service] |
| 420 |
ExecStart=/usr/local/bin/{package} infinity |
| 421 |
""" |
| 422 |
self.createPackage(package, "1", "1", install=True, changes="initial package with service and run script", |
| 423 |
content={f"/usr/local/bin/{package}": {"path": "/usr/bin/sleep"}, |
| 424 |
f"/etc/systemd/system/{package}.service": unitContent}, |
| 425 |
postinst=(f"chmod a+x /usr/local/bin/{package};" |
| 426 |
f"systemctl daemon-reload; systemctl start {package}.service"), |
| 427 |
arch=self.secondary_arch) |
| 428 |
|
| 429 |
if manual_proc: |
| 430 |
manual_pid = m.spawn(f"{package} 3600", "non-service-bin.log") |
| 431 |
self.addCleanup(m.execute, f"kill {manual_pid}") |
| 432 |
|
| 433 |
self.createPackage(package, "1", "2", |
| 434 |
content={f"/usr/local/bin/{package}": {"path": "/usr/bin/sleep"}, |
| 435 |
f"/etc/systemd/system/{package}.service": unitContent}, |
| 436 |
postinst=f"chmod a+x /usr/local/bin/{package}", |
| 437 |
arch=self.secondary_arch) |
| 438 |
|
| 439 |
startTime = m.execute(f"systemctl show {package}.service --property=ExecMainStartTimestamp") |
| 440 |
|
| 441 |
self.addCleanup(m.execute, ("pacman -R --noconfirm " if m.image == "arch" else "rpm -e ") + package) |
| 442 |
self.addCleanup(m.execute, f"systemctl stop {package}") |
| 443 |
|
| 444 |
return startTime |
| 445 |
|
| 446 |
@testlib.skipImage("tracer not available", *OSesWithoutTracer) |
| 447 |
def testTracer(self): |
| 448 |
b = self.browser |
| 449 |
m = self.machine |
| 450 |
|
| 451 |
class Tracer: |
| 452 |
def __init__(self, |
| 453 |
testObj: TestUpdates, |
| 454 |
rebootRequired: bool = False, |
| 455 |
testStatusCard: bool = False, |
| 456 |
packageName: str = "vanilla"): |
| 457 |
self.testObj = testObj |
| 458 |
self.rebootRequired = rebootRequired |
| 459 |
self.testStatusCard = testStatusCard |
| 460 |
self.packageName = packageName |
| 461 |
|
| 462 |
def execute(self): |
| 463 |
self.prepare() |
| 464 |
self.test_frontend() |
| 465 |
self.verify_backend() |
| 466 |
self.cleanup() |
| 467 |
|
| 468 |
def prepare(self): |
| 469 |
if self.rebootRequired: |
| 470 |
# setting app as static in tracer's helper file will cause it to require a reboot |
| 471 |
self.testObj.write_file("/etc/tracer/applications.xml", |
| 472 |
f""" |
| 473 |
<applications> |
| 474 |
<app name="{self.packageName}" type="static" /> |
| 475 |
</applications> |
| 476 |
""") |
| 477 |
|
| 478 |
self.serviceStartTime = self.testObj.createServicePackageUpgrade(self.packageName) |
| 479 |
self.testObj.enableRepo(refresh_repo=True) |
| 480 |
|
| 481 |
def test_frontend(self): |
| 482 |
self.testObj.login_and_go("/updates") |
| 483 |
|
| 484 |
with b.wait_timeout(30): |
| 485 |
b.wait_visible("#status") |
| 486 |
|
| 487 |
# check update is present |
| 488 |
b.wait_in_text("#status", "1 update available") |
| 489 |
b.wait_in_text("#available-updates table", self.packageName) |
| 490 |
|
| 491 |
# install updates |
| 492 |
b.wait_in_text("#install-all", "Install all updates") |
| 493 |
b.click("#install-all") |
| 494 |
with b.wait_timeout(60): |
| 495 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 496 |
|
| 497 |
b.wait_visible("#ignore") |
| 498 |
b.wait_visible(".updates-success-table") |
| 499 |
|
| 500 |
if self.rebootRequired: |
| 501 |
rowId = "#reboot-row" |
| 502 |
else: |
| 503 |
rowId = "#service-row" |
| 504 |
|
| 505 |
b.wait_visible(f"{rowId}") |
| 506 |
b.click(f"{rowId} button") |
| 507 |
b.wait_in_text(f"{rowId} + tr", self.packageName) |
| 508 |
|
| 509 |
# test the tracer functionality works also in the Status Card |
| 510 |
if self.testStatusCard: |
| 511 |
b.click("#ignore") |
| 512 |
|
| 513 |
if self.rebootRequired: |
| 514 |
b.wait_in_text("#status", "1 package needs a system reboot") |
| 515 |
b.click("#packages-need-reboot button") |
| 516 |
b.wait_visible("#shutdown-dialog") |
| 517 |
b.click("#delay") |
| 518 |
b.click("button:contains('No delay')") |
| 519 |
b.wait_text("#delay .pf-v6-c-menu-toggle__text", "No delay") |
| 520 |
b.click("#shutdown-dialog button:contains('Reboot')") |
| 521 |
b.switch_to_top() |
| 522 |
b.wait_in_text(".curtains-ct h1", "Disconnected") |
| 523 |
|
| 524 |
# ensure that rebooting actually worked |
| 525 |
self.testObj.wait_reboot() |
| 526 |
self.testObj.login_and_go("/updates") |
| 527 |
else: |
| 528 |
b.wait_in_text("#status", "1 service needs to be restarted") |
| 529 |
b.click("#services-need-restart button") |
| 530 |
b.wait_visible("#restart-services-modal") |
| 531 |
b.wait_in_text(".restart-services-modal-body", self.packageName) |
| 532 |
b.click("#restart-services-modal button:contains('Restart services')") |
| 533 |
b.wait_not_present("#restart-services-modal") |
| 534 |
|
| 535 |
# test the tracer functionality works in-page after successful update |
| 536 |
else: |
| 537 |
if self.rebootRequired: |
| 538 |
# update required a reboot |
| 539 |
b.wait_not_present("#choose-service") |
| 540 |
b.click("#reboot-system") |
| 541 |
b.wait_visible("#shutdown-dialog") |
| 542 |
b.click("#delay") |
| 543 |
b.click("button:contains('No delay')") |
| 544 |
b.wait_text("#delay .pf-v6-c-menu-toggle__text", "No delay") |
| 545 |
b.click("#shutdown-dialog button:contains('Reboot')") |
| 546 |
b.switch_to_top() |
| 547 |
b.wait_in_text(".curtains-ct h1", "Disconnected") |
| 548 |
|
| 549 |
# ensure that rebooting actually worked |
| 550 |
self.testObj.wait_reboot() |
| 551 |
self.testObj.login_and_go("/updates") |
| 552 |
else: |
| 553 |
# update required a service restart |
| 554 |
b.wait_not_present("#reboot-system") |
| 555 |
b.click("#choose-service") |
| 556 |
b.wait_visible("#restart-services-modal") |
| 557 |
b.wait_in_text(".restart-services-modal-body", self.packageName) |
| 558 |
b.click("#restart-services-modal button:contains('Restart services')") |
| 559 |
b.wait_not_present("#restart-services-modal") |
| 560 |
|
| 561 |
# check no updates are present |
| 562 |
b.wait_in_text("#status", "System is up to date") |
| 563 |
|
| 564 |
# history on "up to date" page should show the recent update (expanded by default) |
| 565 |
self.testObj.assertHistory("#expanded-content0 > td > div > ul", [self.packageName]) |
| 566 |
|
| 567 |
def verify_backend(self): |
| 568 |
if not self.rebootRequired: |
| 569 |
# Check the service was actually restarted |
| 570 |
newServiceStartTime = m.execute( |
| 571 |
f"systemctl show {self.packageName}.service --property=ExecMainStartTimestamp") |
| 572 |
self.testObj.assertGreater(newServiceStartTime, self.serviceStartTime) |
| 573 |
|
| 574 |
# check no services/processes need reboot or service restart |
| 575 |
# tracer returns non-zero exit code if any services/processes are affected |
| 576 |
m.execute("tracer --all --root") |
| 577 |
|
| 578 |
def cleanup(self): |
| 579 |
if self.rebootRequired: |
| 580 |
m.execute("rm /etc/tracer/applications.xml") |
| 581 |
|
| 582 |
Tracer( |
| 583 |
testObj=self, |
| 584 |
packageName="apple", |
| 585 |
rebootRequired=True, |
| 586 |
testStatusCard=False, |
| 587 |
).execute() |
| 588 |
|
| 589 |
Tracer( |
| 590 |
testObj=self, |
| 591 |
packageName="cherry", |
| 592 |
rebootRequired=False, |
| 593 |
testStatusCard=False, |
| 594 |
).execute() |
| 595 |
|
| 596 |
Tracer( |
| 597 |
testObj=self, |
| 598 |
packageName="pear", |
| 599 |
rebootRequired=True, |
| 600 |
testStatusCard=True, |
| 601 |
).execute() |
| 602 |
|
| 603 |
Tracer( |
| 604 |
testObj=self, |
| 605 |
packageName="banana", |
| 606 |
rebootRequired=False, |
| 607 |
testStatusCard=True, |
| 608 |
).execute() |
| 609 |
|
| 610 |
@testlib.nondestructive |
| 611 |
@testlib.onlyImage("dnf needs-restart not available", *OSesWithDnfRestart) |
| 612 |
def testDnfRestart(self): |
| 613 |
m = self.machine |
| 614 |
b = self.browser |
| 615 |
|
| 616 |
start_time = self.createServicePackageUpgrade("mydaemon") |
| 617 |
self.enableRepo() |
| 618 |
self.login_and_go("/updates") |
| 619 |
# check update is present |
| 620 |
with b.wait_timeout(30): |
| 621 |
b.wait_in_text("#status", "1 update available") |
| 622 |
b.wait_in_text("#available-updates table", "mydaemon") |
| 623 |
|
| 624 |
b.click("#install-all") |
| 625 |
with b.wait_timeout(60): |
| 626 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 627 |
|
| 628 |
# update required only a service restart |
| 629 |
b.wait_text(".update-success-table-title", "1 service needs to be restarted") |
| 630 |
b.click("[data-ouia-component-id='toggle-service']") |
| 631 |
b.wait_in_text(".updates-success-table", "mydaemon.service") |
| 632 |
b.wait_not_present("#reboot-system") |
| 633 |
b.click("#choose-service") |
| 634 |
b.wait_visible("#restart-services-modal") |
| 635 |
b.wait_in_text(".restart-services-modal-body", "mydaemon") |
| 636 |
b.click("#restart-services-modal button:contains('Restart services')") |
| 637 |
b.wait_not_present("#restart-services-modal") |
| 638 |
b.wait_in_text("#status p", "System is up to date") |
| 639 |
|
| 640 |
new_start_time = m.execute("systemctl show mydaemon.service --property=ExecMainStartTimestamp") |
| 641 |
self.assertGreater(new_start_time, start_time) |
| 642 |
|
| 643 |
# finds manual process |
| 644 |
self.createServicePackageUpgrade("manual", manual_proc=True) |
| 645 |
self.enableRepo() |
| 646 |
b.click("#status .pf-v6-c-card__header button") |
| 647 |
with b.wait_timeout(30): |
| 648 |
b.wait_visible("#available-updates") |
| 649 |
b.wait_in_text("#status", "1 update available") |
| 650 |
b.click("#install-all") |
| 651 |
with b.wait_timeout(60): |
| 652 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 653 |
|
| 654 |
b.wait_text("#service-row .update-success-table-title", "1 service needs to be restarted") |
| 655 |
b.wait_visible("#manual-row .update-success-table-title") |
| 656 |
|
| 657 |
b.click("[data-ouia-component-id='toggle-manual']") |
| 658 |
b.wait_in_text(".updates-success-table", "manual 3600") |
| 659 |
|
| 660 |
# offers both service restart and reboot |
| 661 |
b.wait_visible("#choose-service") |
| 662 |
b.wait_visible("#reboot-system") |
| 663 |
b.click("#ignore") |
| 664 |
|
| 665 |
b.wait_in_text("#status", "1 service needs to be restarted") |
| 666 |
b.wait_in_text("#status", "Some software needs to be restarted manually") |
| 667 |
b.wait_in_text("#status", "manual 3600") |
| 668 |
|
| 669 |
# kernel update for "needs reboot" |
| 670 |
self.createPackage("kernel-rt", "1.0", "1", install=True) |
| 671 |
self.createPackage("kernel-rt", "1.0", "2") |
| 672 |
self.enableRepo() |
| 673 |
b.click("#status .pf-v6-c-card__header button") |
| 674 |
with b.wait_timeout(30): |
| 675 |
b.wait_visible("#available-updates") |
| 676 |
b.wait_in_text("#status", "1 update available") |
| 677 |
b.click("#install-all") |
| 678 |
b.click("[data-ouia-component-id='toggle-reboot']") |
| 679 |
b.wait_in_text(".updates-success-table", "kernel-rt") |
| 680 |
b.wait_visible("#reboot-system") |
| 681 |
b.click("#ignore") |
| 682 |
b.wait_in_text("#status", "1 package needs a system reboot") |
| 683 |
|
| 684 |
@testlib.skipImage("Arch Linux does not start services by default", "arch") |
| 685 |
@testlib.skipImage("tracer not available", *OSesWithoutTracer) |
| 686 |
@testlib.nondestructive |
| 687 |
def testFailServiceRestart(self): |
| 688 |
b = self.browser |
| 689 |
|
| 690 |
packageName = "apple" |
| 691 |
scriptContent = "#!/bin/sh\nsleep infinity" |
| 692 |
unitContent = f""" |
| 693 |
[Service] |
| 694 |
Type=simple |
| 695 |
ExecStart=/usr/local/bin/{packageName} |
| 696 |
""" |
| 697 |
self.createPackage(packageName, "1", "1", install=True, changes="initial package with service and run script", |
| 698 |
content={f"/usr/local/bin/{packageName}": scriptContent, |
| 699 |
f"/etc/systemd/system/{packageName}.service": unitContent}, |
| 700 |
postinst=f"chmod a+x /usr/local/bin/{packageName}; systemctl daemon-reload; systemctl start {packageName}.service") |
| 701 |
|
| 702 |
scriptContent = "#!/bin/sh\nfalse" |
| 703 |
unitContent = f""" |
| 704 |
[Service] |
| 705 |
Type=oneshot |
| 706 |
RemainAfterExit=yes |
| 707 |
ExecStart=/usr/local/bin/{packageName} |
| 708 |
""" |
| 709 |
self.createPackage(packageName, "1", "2", |
| 710 |
content={f"/usr/local/bin/{packageName}": scriptContent, |
| 711 |
f"/etc/systemd/system/{packageName}.service": unitContent}) |
| 712 |
|
| 713 |
self.enableRepo() |
| 714 |
|
| 715 |
self.login_and_go("/updates") |
| 716 |
|
| 717 |
# check update is present |
| 718 |
with b.wait_timeout(30): |
| 719 |
b.wait_in_text("#status", "1 update available") |
| 720 |
b.wait_in_text("#available-updates table", packageName) |
| 721 |
|
| 722 |
# install updates |
| 723 |
b.wait_in_text("#install-all", "Install all updates") |
| 724 |
b.click("#install-all") |
| 725 |
with b.wait_timeout(60): |
| 726 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 727 |
|
| 728 |
b.wait_visible("#ignore") |
| 729 |
b.wait_visible(".updates-success-table") |
| 730 |
|
| 731 |
b.wait_visible("#service-row") |
| 732 |
b.click("#service-row button") |
| 733 |
b.wait_in_text("#service-row + tr", packageName) |
| 734 |
|
| 735 |
# update required a service restart |
| 736 |
b.wait_not_present("#reboot-system") |
| 737 |
b.click("#choose-service") |
| 738 |
b.wait_visible("#restart-services-modal") |
| 739 |
b.wait_in_text(".restart-services-modal-body", packageName) |
| 740 |
b.click("#restart-services-modal button:contains('Restart services')") |
| 741 |
b.wait_visible("#restart-services-modal") |
| 742 |
|
| 743 |
# tracer updated the list of services which need a restart, so our service is no longer present |
| 744 |
b.wait_not_in_text("#restart-services-modal .pf-v6-l-stack__item", packageName) |
| 745 |
b.wait_visible("#restart-services-modal .pf-v6-c-alert") |
| 746 |
|
| 747 |
@testlib.skipImage("No security changelog support in packagekit", "arch") |
| 748 |
def testInfoSecurity(self): |
| 749 |
b = self.browser |
| 750 |
m = self.machine |
| 751 |
|
| 752 |
# make a package available from two repositories; PackageKit dnf doesn't handle |
| 753 |
# that properly: https://issues.redhat.com/browse/RHEL-109155 |
| 754 |
self.createPackage("xeroxed", "10", "1", install=True) |
| 755 |
self.createPackage("xeroxed", "12", "1", severity="enhancement", bugs=["789"], |
| 756 |
changes="Uniqueness is boring") |
| 757 |
self.enableRepo() |
| 758 |
dupe_dir = self.vm_tmpdir + "/repo-dupe" |
| 759 |
m.execute(f"cp -r {self.repo_dir} {dupe_dir}") |
| 760 |
if self.backend.startswith("dnf"): |
| 761 |
repo = m.execute("cat /etc/yum.repos.d/cockpittest.repo") |
| 762 |
repo = repo.replace(self.repo_dir, dupe_dir) |
| 763 |
repo = repo.replace("name=cockpittest", "name=test-dupe") |
| 764 |
m.write("/etc/yum.repos.d/test-dupe.repo", repo) |
| 765 |
elif self.backend == "apt": |
| 766 |
repo = m.execute("cat /etc/apt/sources.list.d/test.list") |
| 767 |
repo = repo.replace(self.repo_dir, dupe_dir) |
| 768 |
m.write("/etc/apt/sources.list.d/dupe.list", repo) |
| 769 |
else: |
| 770 |
self.fail(f"Copy logic for backend {self.backend} needs to be written") |
| 771 |
|
| 772 |
# just changelog |
| 773 |
self.createPackage("norefs-bin", "1", "1", install=True) |
| 774 |
self.createPackage("norefs-bin", "2", "1", severity="enhancement", |
| 775 |
changes="Now 10% *more* [unicorns](http://unicorn.example.com)") |
| 776 |
|
| 777 |
# binary from same source |
| 778 |
self.createPackage("norefs-doc", "1", "1", install=True) |
| 779 |
self.createPackage("norefs-doc", "2", "1", severity="enhancement", |
| 780 |
changes="Now 10% *more* [unicorns](http://unicorn.example.com)") |
| 781 |
# bug fixes |
| 782 |
self.createPackage("buggy", "2", "1", install=True) |
| 783 |
self.createPackage("buggy", "2", "2", changes="* Fixit", bugs=["123", "456"]) |
| 784 |
# security fix with proper CVE list and severity |
| 785 |
self.createPackage("secdeclare", "3", "4.a1", install=True) |
| 786 |
self.createPackage("secdeclare", "3", "4.b1", severity="security", |
| 787 |
changes="Will crash your data center", cves=["CVE-2014-123456"]) |
| 788 |
# security fix with parsing from changes |
| 789 |
self.createPackage("secparse", "4", "1", install=True) |
| 790 |
self.createPackage("secparse", "4", "2", changes="Fix CVE-2014-54321 and CVE-2017-9999.") |
| 791 |
# security fix with RHEL severity, errata and XSS |
| 792 |
self.createPackage("sevcritical", "5", "1", install=True) |
| 793 |
self.createPackage("sevcritical", "5", "2", cves=["CVE-2014-54321"], securitySeverity="critical", |
| 794 |
errata=["RHSA-2000:0001", "RHSA-2000:0002"], |
| 795 |
invalid_cves=["javascript:alert(document.cookie)", "https://example.com"], |
| 796 |
changes='See [malicious link](https://example.invalid/"onmouseover="alert(document.domain)) for info') |
| 797 |
|
| 798 |
self.enableRepo(refresh_repo=True) |
| 799 |
|
| 800 |
self.login_and_go("/updates") |
| 801 |
with b.wait_timeout(30): |
| 802 |
b.wait_visible("#available-updates") |
| 803 |
b.wait_in_text("#status", "7 updates available, including 3 security fixes") |
| 804 |
|
| 805 |
b.wait_in_text("table[aria-label='Available updates']", "sevcritical") |
| 806 |
|
| 807 |
# security updates should get sorted on top and then alphabetically, so start with "secdeclare" |
| 808 |
sel = self.check_nth_update(1, "secdeclare", "3-4.b1", "security", 1, |
| 809 |
desc_matches=["Will crash your data center"], cves=["CVE-2014-123456"]) |
| 810 |
# should not have erratum label in details |
| 811 |
self.assertNotIn("Errat", b.text(sel)) |
| 812 |
|
| 813 |
# secparse should also be considered a security update as the changelog mentions CVEs |
| 814 |
self.check_nth_update(2, "secparse", "4-2", "security", 2, |
| 815 |
desc_matches=["Fix CVE-2014-54321 and CVE-2017-9999."], |
| 816 |
cves=["CVE-2014-54321", "CVE-2017-9999"]) |
| 817 |
apt_based = m.image.startswith(("debian-", "ubuntu-")) |
| 818 |
# We cannot insert example.com as an url in apts' changelog format only accepts cve ids or issues, |
| 819 |
# so it does not appear in the UI. |
| 820 |
sel = self.check_nth_update(3, "sevcritical", "5-2", "security", 1 if apt_based else 2, |
| 821 |
desc_matches=["See malicious link for info"], |
| 822 |
absent_anchor_attributes=["onmouseover"]) # onmouseover does not survive our sanitization |
| 823 |
# Malicious cve urls don't end up being rendered |
| 824 |
# PackageKit parses the apt changelog and constructs CVE urls from it, so we can't insert a malicious javascript: uri |
| 825 |
if apt_based: |
| 826 |
b.wait_in_text(sel, "javascript:alert") |
| 827 |
b.wait_not_present(f"{sel} a[href='javascript:alert(document.cookie)']") |
| 828 |
else: |
| 829 |
self.assertIsNone(b.attr(f"{sel} a[href='https://example.com']", "onmouseover")) |
| 830 |
b.wait_not_in_text(sel, "javascript:alert") |
| 831 |
|
| 832 |
# buggy: bug refs, no security |
| 833 |
sel = self.check_nth_update(4, "buggy", "2-2", "bug", 2, bugs=["123", "456"], desc_matches=["Fixit"]) |
| 834 |
# should filter out enumeration in overview |
| 835 |
ch = b.eval_js(f"document.querySelector(\"{sel + ' td.changelog'}\").innerHTML") |
| 836 |
self.assertNotIn("<li>", ch) |
| 837 |
self.assertNotIn("*", ch) |
| 838 |
# should show bug fix icon and pf-v6-c-tooltip |
| 839 |
self.assertEqual(b.attr(sel + " .severity-icon", "aria-label"), "bug fix") |
| 840 |
b.mouse(sel + " .severity-icon", "mouseenter") |
| 841 |
b.wait_text(".pf-v6-c-tooltip", "bug fix") |
| 842 |
b.mouse(sel + " .severity-icon", "mouseleave") |
| 843 |
b.wait_not_present(".pf-v6-c-tooltip") |
| 844 |
|
| 845 |
# norefs: just changelog, show both binary packages |
| 846 |
sel = self.check_nth_update(5, ["norefs-bin", "norefs-doc"], "2-1", self.enhancement_severity, |
| 847 |
desc_matches=["Now 10% more unicorns"]) |
| 848 |
# verify Markdown formatting in table cell |
| 849 |
self.assertEqual(b.text(sel + " td.changelog em"), "more") # *more* |
| 850 |
self.assertEqual(b.attr(sel + " td.changelog a", "href"), "http://unicorn.example.com") |
| 851 |
self.assertEqual(b.attr(sel + " td.changelog a", "target"), "_blank") |
| 852 |
# verify Markdown formatting in details |
| 853 |
self.assertEqual(b.text(sel + " .pf-v6-c-table__expandable-row.pf-m-expanded em"), "more") # *more* |
| 854 |
b.wait_visible(sel + ' .pf-v6-c-table__expandable-row.pf-m-expanded a[href="http://unicorn.example.com"][target="_blank"]') |
| 855 |
|
| 856 |
# verify that changelog is absent in mobile |
| 857 |
b.set_layout("mobile") |
| 858 |
b.wait_not_visible(sel + " td.changelog em") |
| 859 |
b.set_layout("desktop") |
| 860 |
b.wait_visible(sel + " td.changelog em") |
| 861 |
|
| 862 |
# check xeroxed |
| 863 |
if self.backend.startswith("dnf"): |
| 864 |
if "dnf5" in m.execute("pkcon backend-details"): |
| 865 |
# The new "dnf5" backend gets it right, and even uses severity "enhancement". |
| 866 |
self.check_nth_update(6, "xeroxed", "12-1", self.enhancement_severity, 1, bugs=["789"], |
| 867 |
desc_matches=["Uniqueness is boring"]) |
| 868 |
else: |
| 869 |
# see RHEL-109155 above; can't load update details, so no bugs nor description; |
| 870 |
# realistically this won't ever get fixed, but if it does, surprise us! |
| 871 |
self.check_nth_update(6, "xeroxed", "12-1", self.enhancement_severity) |
| 872 |
else: |
| 873 |
# apt works fine, except it uses severity "bug". |
| 874 |
self.check_nth_update(6, "xeroxed", "12-1", "bug", 1, bugs=["789"], |
| 875 |
desc_matches=["Uniqueness is boring"]) |
| 876 |
|
| 877 |
# updates are shown on system page |
| 878 |
b.go("/system") |
| 879 |
b.enter_page("/system") |
| 880 |
self.wait_checking_updates() |
| 881 |
b.wait_text(self.update_text, "Security updates available") |
| 882 |
b.wait_attr(self.update_icon, "data-pficon", "security") |
| 883 |
|
| 884 |
# should be a link, click on it to go to back to /updates |
| 885 |
b.click(self.update_text_action) |
| 886 |
b.enter_page("/updates") |
| 887 |
|
| 888 |
# install only security updates |
| 889 |
self.assertEqual(b.text("#available-updates button#install-security"), "Install security updates") |
| 890 |
b.wait_not_present("#available-updates button#install-kpatches") |
| 891 |
b.click("#available-updates button#install-security") |
| 892 |
with b.wait_timeout(60): |
| 893 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 894 |
|
| 895 |
# history on restart page should show the three security updates |
| 896 |
b.click(".pf-v6-c-expandable-section__toggle button") |
| 897 |
self.assertHistory(".pf-v6-c-expandable-section ul", ["secdeclare", "secparse", "sevcritical"]) |
| 898 |
|
| 899 |
# ignore restarting |
| 900 |
b.click("#ignore") |
| 901 |
|
| 902 |
# should have succeeded; 4 non-security updates left |
| 903 |
b.wait_in_text("#status", "4 updates available") |
| 904 |
b.wait_in_text("#available-updates h2", "Available updates") |
| 905 |
|
| 906 |
b.wait_in_text("#available-updates table", "norefs-doc") |
| 907 |
self.assertIn("buggy", b.text("#available-updates table")) |
| 908 |
self.assertNotIn("secdeclare", b.text("#available-updates table")) |
| 909 |
self.assertNotIn("secparse", b.text("#available-updates table")) |
| 910 |
|
| 911 |
# history should show the security updates |
| 912 |
self.assertHistory("table.updates-history #expanded-content0 ul", ["secdeclare", "secparse", "sevcritical"]) |
| 913 |
|
| 914 |
# re-drop the duplicate repo with dnf; PackageKit can't update otherwise (still RHEL-109155) |
| 915 |
if self.backend.startswith("dnf"): |
| 916 |
m.execute("rm /etc/yum.repos.d/test-dupe.repo") |
| 917 |
|
| 918 |
# stop PackageKit (e. g. idle timeout) to make sure the page survives that |
| 919 |
m.execute("systemctl stop packagekit; systemctl reset-failed packagekit || true") |
| 920 |
|
| 921 |
# new security versions are now installed |
| 922 |
m.execute("test -f /stamp-secdeclare-3-4.b1; test -f /stamp-secparse-4-2; test -f /stamp-sevcritical-5-2") |
| 923 |
# but the three others are untouched |
| 924 |
m.execute("test -f /stamp-buggy-2-1; test -f /stamp-norefs-bin-1-1; test -f /stamp-norefs-doc-1-1") |
| 925 |
|
| 926 |
# should now only have one button (no security updates left) |
| 927 |
self.assertEqual(b.text("#available-updates button#install-all"), "Install all updates") |
| 928 |
b.click("#available-updates button#install-all") |
| 929 |
|
| 930 |
# should have succeeded and show restart |
| 931 |
with b.wait_timeout(60): |
| 932 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 933 |
b.wait_visible("#ignore") |
| 934 |
|
| 935 |
# history on restart page should show the three non-security updates |
| 936 |
b.click(".pf-v6-c-expandable-section__toggle button") |
| 937 |
self.assertHistory(".pf-v6-c-expandable-section ul", ["buggy", "norefs-bin", "norefs-doc", "xeroxed"]) |
| 938 |
|
| 939 |
if any(fnmatch.fnmatch(m.image, img) for img in OSesWithoutTracer) and not any( |
| 940 |
fnmatch.fnmatch(m.image, img) for img in OSesWithDnfRestart): |
| 941 |
# do the reboot; this will disconnect the web UI |
| 942 |
b.click("#app .pf-v6-c-empty-state button.pf-m-primary") |
| 943 |
b.wait_visible("#shutdown-dialog") |
| 944 |
b.click("#delay") |
| 945 |
b.click("button:contains('No delay')") |
| 946 |
b.wait_text("#delay .pf-v6-c-menu-toggle__text", "No delay") |
| 947 |
b.click("#shutdown-dialog button:contains('Reboot')") |
| 948 |
b.switch_to_top() |
| 949 |
b.wait_in_text(".curtains-ct h1", "Disconnected") |
| 950 |
|
| 951 |
# ensure that rebooting actually worked |
| 952 |
self.wait_reboot() |
| 953 |
self.login_and_go("/updates") |
| 954 |
else: |
| 955 |
b.click("#ignore") |
| 956 |
|
| 957 |
# new versions are now installed |
| 958 |
m.execute("test -f /stamp-norefs-bin-2-1; test -f /stamp-norefs-doc-2-1") |
| 959 |
|
| 960 |
# no further updates |
| 961 |
b.wait_in_text("#status", "System is up to date") |
| 962 |
|
| 963 |
# history on "up to date" page should show the recent update (expanded by default) |
| 964 |
self.assertHistory( |
| 965 |
"table.updates-history tbody.pf-m-expanded .pf-v6-c-table__expandable-row-content ul", |
| 966 |
["buggy", "norefs-bin", "norefs-doc", "xeroxed"], |
| 967 |
) |
| 968 |
# and the previous one, not expanded |
| 969 |
b.wait_visible("table.updates-history tbody:not(.pf-m-expanded)") |
| 970 |
|
| 971 |
@testlib.skipImage("No security changelog support in packagekit", "arch") |
| 972 |
@testlib.nondestructive |
| 973 |
def testSecurityOnly(self): |
| 974 |
b = self.browser |
| 975 |
|
| 976 |
# security fix with proper CVE list and severity |
| 977 |
self.createPackage("secdeclare", "3", "4.a1", install=True) |
| 978 |
self.createPackage("secdeclare", "3", "4.b1", severity="security", |
| 979 |
changes="Will crash your data center", cves=['CVE-2014-123456']) |
| 980 |
|
| 981 |
self.enableRepo(refresh_repo=True) |
| 982 |
|
| 983 |
self.login_and_go("/updates") |
| 984 |
with b.wait_timeout(30): |
| 985 |
b.wait_visible("#available-updates") |
| 986 |
b.wait_in_text("#status", "1 security fix available") |
| 987 |
|
| 988 |
# should only have one button (only security updates) |
| 989 |
b.wait_not_present("#available-updates button#install-all") |
| 990 |
b.wait_not_present("#available-updates button#install-kpatches") |
| 991 |
self.assertEqual(b.text("#available-updates button#install-security"), "Install security updates") |
| 992 |
|
| 993 |
# security fix without CVE URLs |
| 994 |
if self.supports_severity: |
| 995 |
self.createPackage("secnocve", "1", "1", install=True) |
| 996 |
self.createPackage("secnocve", "1", "2", severity="security", changes="Fix leak") |
| 997 |
self.enableRepo() |
| 998 |
# check for updates |
| 999 |
b.click("#status .pf-v6-c-card__header button") |
| 1000 |
with b.wait_timeout(30): |
| 1001 |
b.wait_visible("#available-updates") |
| 1002 |
b.wait_in_text("#status", "2") |
| 1003 |
|
| 1004 |
b.wait_in_text("table[aria-label='Available updates']", "secnocve") |
| 1005 |
|
| 1006 |
# secnocve should be displayed properly |
| 1007 |
self.check_nth_update(2, "secnocve", "1-2", "security", desc_matches=["Fix leak"]) |
| 1008 |
|
| 1009 |
@testlib.skipImage("No changelog support in Arch Linux", "arch") |
| 1010 |
@testlib.nondestructive |
| 1011 |
def testInfoTruncation(self): |
| 1012 |
b = self.browser |
| 1013 |
|
| 1014 |
# update with not too many binary packages |
| 1015 |
for i in range(4): |
| 1016 |
self.createPackage(f"coarse{i:02}", "1", "1", install=True) |
| 1017 |
self.createPackage(f"coarse{i:02}", "1", "2", changes="make it greener") |
| 1018 |
|
| 1019 |
# update with lots of binary packages |
| 1020 |
for i in range(10): |
| 1021 |
self.createPackage(f"fine{i:02}", "1", "1", install=True) |
| 1022 |
self.createPackage(f"fine{i:02}", "1", "2", changes="make it better") |
| 1023 |
|
| 1024 |
# update with long changelog |
| 1025 |
long_changelog = "" |
| 1026 |
for i in range(30): |
| 1027 |
long_changelog += f" - Things change #{i:02}\n" |
| 1028 |
self.createPackage("verbose", "1", "1", install=True) |
| 1029 |
self.createPackage("verbose", "1", "2", changes=long_changelog) |
| 1030 |
|
| 1031 |
self.enableRepo() |
| 1032 |
|
| 1033 |
self.login_and_go("/updates") |
| 1034 |
|
| 1035 |
with b.wait_timeout(30): |
| 1036 |
b.wait_in_text("table[aria-label='Available updates']", "Things change") |
| 1037 |
|
| 1038 |
# "coarse" package list should be complete |
| 1039 |
t = b.text("#app .ct-table tbody:nth-of-type(1) tr:first-child [data-label=Name]") |
| 1040 |
self.assertIn("coarse00", t) |
| 1041 |
self.assertIn("coarse03", t) |
| 1042 |
self.assertNotIn("…", t) |
| 1043 |
|
| 1044 |
# "fine" package list should be truncated |
| 1045 |
t = b.text("#app .ct-table tbody:nth-of-type(2) tr:first-child [data-label=Name]") |
| 1046 |
self.assertIn("fine00", t) |
| 1047 |
self.assertIn("fine03", t) |
| 1048 |
self.assertNotIn("fine09", t) |
| 1049 |
self.assertIn("…", t) |
| 1050 |
# but complete in the details |
| 1051 |
self.check_nth_update(2, ["fine00", "fine01", "fine02", "fine03"], "1-2", |
| 1052 |
desc_matches=["fine07", "fine09"]) |
| 1053 |
|
| 1054 |
# changelog should be truncated |
| 1055 |
desc = b.text("#app .ct-table tbody:nth-of-type(3) [data-label=Details]") |
| 1056 |
self.assertIn("Things change #00", desc) |
| 1057 |
self.assertNotIn("#01", desc) |
| 1058 |
|
| 1059 |
# and not visible on mobile |
| 1060 |
b.set_layout("mobile") |
| 1061 |
b.wait_not_visible("#app .ct-table tbody:nth-of-type(3) [data-label=Details]") |
| 1062 |
# but complete in the details |
| 1063 |
self.check_nth_update(1, ["coarse00", "coarse01", "coarse02", "coarse03"], "1-2", |
| 1064 |
desc_matches=["make it greener"]) |
| 1065 |
|
| 1066 |
# also on desktop |
| 1067 |
b.set_layout("desktop") |
| 1068 |
b.wait_visible("#app .ct-table tbody:nth-of-type(3) [data-label=Details]") |
| 1069 |
self.check_nth_update(3, "verbose", "1-2", |
| 1070 |
desc_matches=["Things change #00", "Things change #29"]) |
| 1071 |
|
| 1072 |
# seems we can't verify that the description has a scrollbar |
| 1073 |
|
| 1074 |
def testRebootAfterSuccess(self): |
| 1075 |
b = self.browser |
| 1076 |
m = self.machine |
| 1077 |
|
| 1078 |
install_lockfile = "/tmp/finish-pk" |
| 1079 |
# create two updates; force installing chocolate before vanilla |
| 1080 |
self.createPackage("vanilla", "1.0", "1", install=True) |
| 1081 |
self.createPackage("vanilla", "1.0", "2", |
| 1082 |
postinst=f"while [ ! -e {install_lockfile} ]; do sleep 1; done; rm -f {install_lockfile}") |
| 1083 |
self.enableRepo(refresh_repo=True) |
| 1084 |
|
| 1085 |
self.login_and_go("/updates") |
| 1086 |
with b.wait_timeout(30): |
| 1087 |
b.wait_visible("#available-updates") |
| 1088 |
b.click("#available-updates button#install-all") |
| 1089 |
|
| 1090 |
b.wait_visible("#app div.pf-v6-c-progress__bar") |
| 1091 |
# auto-reboot is off by default |
| 1092 |
b.wait_visible("#reboot-after:not(:checked)") |
| 1093 |
b.click("#reboot-after") |
| 1094 |
b.wait_visible("#reboot-after:checked") |
| 1095 |
|
| 1096 |
m.execute(f"touch {install_lockfile}") |
| 1097 |
# reboots automatically |
| 1098 |
b.switch_to_top() |
| 1099 |
b.wait_in_text(".curtains-ct h1", "Disconnected") |
| 1100 |
self.wait_reboot() |
| 1101 |
|
| 1102 |
@testlib.nondestructive |
| 1103 |
def testUpdateError(self): |
| 1104 |
b = self.browser |
| 1105 |
m = self.machine |
| 1106 |
|
| 1107 |
# pretend running custom kernel without distro release for kpatch detection robustness |
| 1108 |
self.write_file("/usr/local/bin/uname", """#!/bin/sh |
| 1109 |
if [ "$1" = "-r" ]; then echo 1.2; else exec /usr/bin/uname "$@"; fi""", perm="755") |
| 1110 |
|
| 1111 |
self.createPackage("vapor", "1", "1", install=True) |
| 1112 |
self.createPackage("vapor", "1", "2") |
| 1113 |
|
| 1114 |
self.enableRepo(refresh_repo=True) |
| 1115 |
|
| 1116 |
# break the upgrade by removing the generated packages from the repo |
| 1117 |
m.execute(f"rm -f {self.repo_dir}/vapor*.deb {self.repo_dir}/vapor*.rpm {self.repo_dir}/vapor*.pkg*") |
| 1118 |
|
| 1119 |
self.login_and_go("/updates") |
| 1120 |
with b.wait_timeout(30): |
| 1121 |
b.wait_visible("#available-updates") |
| 1122 |
b.wait_in_text("#status", "1 update available") |
| 1123 |
b.wait_not_present("#kpatch-setup") |
| 1124 |
|
| 1125 |
b.click("#available-updates button#install-all") |
| 1126 |
|
| 1127 |
# error message visible |
| 1128 |
b.wait_visible("#app .pf-v6-c-page .pf-v6-c-empty-state__body") |
| 1129 |
|
| 1130 |
self.assertRegex(b.text("#app .pf-v6-c-page .pf-v6-l-stack .pf-v6-c-code-block .pf-v6-c-code-block__content .pf-v6-c-code-block__pre .pf-v6-c-code-block__code span:first-of-type"), |
| 1131 |
"missing|download|not.*available|No such file or directory|download library error") |
| 1132 |
|
| 1133 |
# not expecting any buttons |
| 1134 |
self.assertFalse(b.is_present("#app button")) |
| 1135 |
|
| 1136 |
@testlib.nondestructive |
| 1137 |
def testPackageKitCrash(self): |
| 1138 |
b = self.browser |
| 1139 |
m = self.machine |
| 1140 |
|
| 1141 |
# this tends to corrupt the rpm database, so do a backup/restore |
| 1142 |
if 'dnf' in self.backend: |
| 1143 |
# https://www.fedoraproject.org/wiki/Changes/RelocateRPMToUsr |
| 1144 |
exists = self.machine.execute("if test -e %s; then echo yes; fi" % "/usr/lib/sysimage/rpm").strip() != "" |
| 1145 |
if exists: |
| 1146 |
self.restore_dir("/usr/lib/sysimage/rpm") |
| 1147 |
else: |
| 1148 |
self.restore_dir("/var/lib/rpm") |
| 1149 |
|
| 1150 |
# make sure we have enough time to crash PK |
| 1151 |
self.createPackage("slow", "1", "1", install=True) |
| 1152 |
# we don't want this installation to finish |
| 1153 |
self.createPackage("slow", "1", "2", postinst="sleep infinity") |
| 1154 |
self.enableRepo(refresh_repo=True) |
| 1155 |
|
| 1156 |
self.login_and_go("/updates") |
| 1157 |
|
| 1158 |
with b.wait_timeout(30): |
| 1159 |
b.click("#available-updates button#install-all") |
| 1160 |
|
| 1161 |
# let updates start and zap PackageKit |
| 1162 |
b.wait_visible("#app div.pf-v6-c-progress__bar") |
| 1163 |
m.execute("systemctl kill --signal=SEGV packagekit.service") |
| 1164 |
# this crash creates so many messages from systemd-coredump, debug metadata etc. that |
| 1165 |
# trying to keep up with specific patterns is too brittle |
| 1166 |
self.allow_journal_messages(".*") |
| 1167 |
|
| 1168 |
# error message visible |
| 1169 |
b.wait_in_text("#app .pf-v6-c-page .pf-v6-l-stack .pf-v6-c-code-block__content", "PackageKit crashed") |
| 1170 |
|
| 1171 |
@testlib.nondestructive |
| 1172 |
def testNoPackageKit(self): |
| 1173 |
b = self.browser |
| 1174 |
m = self.machine |
| 1175 |
|
| 1176 |
m.execute("systemctl stop packagekit") |
| 1177 |
system_service = m.execute("systemctl show -p FragmentPath packagekit.service | cut -f2 -d=").strip() |
| 1178 |
m.execute(f"""mv {system_service} {system_service}.disabled |
| 1179 |
mv /usr/share/dbus-1/system-services/org.freedesktop.PackageKit.service /usr/share/dbus-1/system-services/org.freedesktop.PackageKit.service.disabled |
| 1180 |
systemctl daemon-reload""") |
| 1181 |
self.addCleanup(m.execute, |
| 1182 |
f"""mv {system_service}.disabled {system_service} |
| 1183 |
mv /usr/share/dbus-1/system-services/org.freedesktop.PackageKit.service.disabled /usr/share/dbus-1/system-services/org.freedesktop.PackageKit.service |
| 1184 |
systemctl daemon-reload""") |
| 1185 |
|
| 1186 |
# no bridge in beiboot mode |
| 1187 |
if not testlib.isBeibootLogin(): |
| 1188 |
self.assertNotIn("\nupdates", m.execute("cockpit-bridge --packages")) |
| 1189 |
# should not appear in the menu at all |
| 1190 |
self.login_and_go(None) |
| 1191 |
b.wait_in_text("#host-apps .pf-m-current", "Overview") |
| 1192 |
self.assertNotIn("Updates", b.text("#host-apps .pf-m-current")) |
| 1193 |
|
| 1194 |
# update status on front page should be invisible |
| 1195 |
b.go("/system") |
| 1196 |
b.enter_page("/system") |
| 1197 |
b.wait_visible(".system-health") |
| 1198 |
self.assertFalse(b.is_present(self.update_text)) |
| 1199 |
|
| 1200 |
@testlib.nondestructive |
| 1201 |
def testUnprivileged(self): |
| 1202 |
b = self.browser |
| 1203 |
|
| 1204 |
self.createPackage("vanilla", "1.0", "1", install=True) |
| 1205 |
self.createPackage("vanilla", "2.0", "2") |
| 1206 |
self.enableRepo(refresh_repo=True) |
| 1207 |
|
| 1208 |
# getting update info is allowed to all users |
| 1209 |
self.login_and_go("/updates", superuser=False) |
| 1210 |
with b.wait_timeout(30): |
| 1211 |
b.wait_in_text("#status", "1 update available") |
| 1212 |
b.wait_visible("#available-updates") |
| 1213 |
|
| 1214 |
# but applying updates is not; FIXME: this is a crappy UX |
| 1215 |
b.click("#available-updates button#install-all") |
| 1216 |
# error message visible |
| 1217 |
b.wait_in_text("#app .pf-v6-c-code-block__content", "authentication") |
| 1218 |
|
| 1219 |
# page adjusts automatically to privilege change |
| 1220 |
b.become_superuser() |
| 1221 |
b.wait_in_text("#status", "1 update available") |
| 1222 |
b.wait_visible("#available-updates") |
| 1223 |
|
| 1224 |
# applying updates works now |
| 1225 |
b.click("#available-updates button#install-all") |
| 1226 |
|
| 1227 |
with b.wait_timeout(60): |
| 1228 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 1229 |
b.click("#ignore") |
| 1230 |
|
| 1231 |
# should go back to updates overview, nothing pending any more |
| 1232 |
# TODO make Packagekit GetUpdates work for tests properly |
| 1233 |
b.wait_not_present("#available-updates") |
| 1234 |
|
| 1235 |
|
| 1236 |
@testlib.skipImage("TODO: Arch Linux has no cockpit-ws package, it's in cockpit", "arch") |
| 1237 |
@testlib.skipWsContainer("no cockpit-ws package with cockpit/ws container") |
| 1238 |
@testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed") |
| 1239 |
class TestWsUpdate(NoSubManCase): |
| 1240 |
def testBasic(self): |
| 1241 |
# The main case for this is that cockpit-ws itself gets upgraded, which |
| 1242 |
# restarts the service and terminates the connection. As we can't |
| 1243 |
# (efficiently) build a newer working cockpit-ws package, test the two |
| 1244 |
# parts (reconnect and warning about disconnect) separately. |
| 1245 |
|
| 1246 |
# no security updates, no changelogs |
| 1247 |
b = self.browser |
| 1248 |
m = self.machine |
| 1249 |
|
| 1250 |
install_lockfile = "/tmp/finish-pk" |
| 1251 |
# updating this package takes longer than a cockpit start and building the page |
| 1252 |
self.createPackage("slow", "1", "1", install=True) |
| 1253 |
self.createPackage( |
| 1254 |
"slow", "1", "2", |
| 1255 |
postinst=f"while [ ! -e {install_lockfile} ]; do sleep 1; done; rm -f {install_lockfile}") |
| 1256 |
self.enableRepo(refresh_repo=True) |
| 1257 |
|
| 1258 |
self.login_and_go("/updates") |
| 1259 |
|
| 1260 |
with b.wait_timeout(30): |
| 1261 |
b.click("#available-updates button#install-all") |
| 1262 |
|
| 1263 |
# applying updates panel present |
| 1264 |
b.wait_in_text("#app div.progress-description", "slow") |
| 1265 |
|
| 1266 |
# restarting should pick up that install progress |
| 1267 |
m.restart_cockpit() |
| 1268 |
b.login_and_go("/updates") |
| 1269 |
|
| 1270 |
b.wait_in_text("#app div.progress-description", "slow 1-2") |
| 1271 |
# progress bar has some reasonable value |
| 1272 |
progress = b.get_pf_progress_value(".progress-main-view") |
| 1273 |
self.assertGreater(progress, 20) |
| 1274 |
self.assertLess(progress, 80) |
| 1275 |
|
| 1276 |
# finish the package installation |
| 1277 |
m.execute(f"touch {install_lockfile}") |
| 1278 |
|
| 1279 |
# should have succeeded and show restart page; cancel |
| 1280 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 1281 |
b.click("#ignore") |
| 1282 |
b.wait_in_text("#status", "System is up to date") |
| 1283 |
|
| 1284 |
# now pretend that there is a newer cockpit-ws available, warn about disconnect |
| 1285 |
self.createPackage("cockpit-ws", "999", "1") |
| 1286 |
# these have strict version dependencies to cockpit-ws, don't get in the way |
| 1287 |
self.createPackage("cockpit", "999", "1") |
| 1288 |
m.execute("if type apt; then dpkg -P cockpit-ws-dbgsym; fi") |
| 1289 |
self.enableRepo() |
| 1290 |
b.click("#status .pf-v6-c-card__header button") |
| 1291 |
|
| 1292 |
with b.wait_timeout(30): |
| 1293 |
b.wait_visible("#available-updates") |
| 1294 |
b.wait_in_text("#status", "2 updates available") |
| 1295 |
b.wait_in_text("table[aria-label='Available updates']", "cockpit-ws") |
| 1296 |
|
| 1297 |
b.wait_visible(".cockpit-update-warning") |
| 1298 |
b.wait_in_text(".cockpit-update-warning-text", "Web Console will restart") |
| 1299 |
|
| 1300 |
self.allow_restart_journal_messages() |
| 1301 |
|
| 1302 |
|
| 1303 |
@testlib.skipImage("kpatch is not available", *OSesWithoutKpatch) |
| 1304 |
@testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed") |
| 1305 |
class TestKpatchInstall(NoSubManCase): |
| 1306 |
def testBasic(self): |
| 1307 |
b = self.browser |
| 1308 |
m = self.machine |
| 1309 |
|
| 1310 |
m.execute("rpm --erase --verbose kpatch kpatch-dnf") |
| 1311 |
|
| 1312 |
self.login_and_go("/updates") |
| 1313 |
with b.wait_timeout(30): |
| 1314 |
b.wait_visible("#status") |
| 1315 |
b.wait_in_text("#kpatch-settings", "Not available") |
| 1316 |
# show unavailable packages in popover |
| 1317 |
b.click("#kpatch-settings .ct-info-circle") |
| 1318 |
b.wait_in_text(".pf-v6-c-popover", "Unavailable packages") |
| 1319 |
b.wait_in_text(".pf-v6-c-popover", "kpatch-dnf") |
| 1320 |
b.click("#kpatch-settings .ct-info-circle") |
| 1321 |
b.wait_not_present(".pf-v6-c-popover") |
| 1322 |
|
| 1323 |
dummy_service = "[Service]\nExecStart=/bin/sleep infinity\n[Install]\nWantedBy=multi-user.target\n" |
| 1324 |
self.createPackage("kpatch", "999", "1", content={"/lib/systemd/system/kpatch.service": dummy_service}) |
| 1325 |
self.createPackage("kpatch-dnf", "999", "1", content={"/etc/dnf/plugins/kpatch.conf": ""}) |
| 1326 |
self.enableRepo() |
| 1327 |
|
| 1328 |
b.reload() |
| 1329 |
b.enter_page("/updates") |
| 1330 |
|
| 1331 |
b.wait_in_text("#kpatch-settings", "Not installed") |
| 1332 |
b.click("#kpatch-settings button:contains('Install')") |
| 1333 |
b.wait_in_text("#dialog", "kpatch, kpatch-dnf will be installed") |
| 1334 |
b.click("#dialog button:contains('Install')") |
| 1335 |
|
| 1336 |
b.wait_in_text("#kpatch-settings", "Disabled") |
| 1337 |
|
| 1338 |
# kpatch and kpatch-dnf should be installed |
| 1339 |
m.execute("rpm -q kpatch kpatch-dnf") |
| 1340 |
|
| 1341 |
|
| 1342 |
@testlib.onlyImage("No subscriptions", "rhel-*") |
| 1343 |
@testlib.skipBeiboot("sub-man-cockpit not contained in cockpit/ws") |
| 1344 |
class TestUpdatesSubscriptions(packagelib.PackageCase, submanlib.SubscriptionCase): |
| 1345 |
provision = { |
| 1346 |
"0": {"address": "10.111.112.1/20", "dns": "10.111.112.1"}, |
| 1347 |
"services": {"image": "services"} |
| 1348 |
} |
| 1349 |
|
| 1350 |
def setUp(self): |
| 1351 |
super().setUp() |
| 1352 |
self.setup_candlepin_service(self.machines['services']) |
| 1353 |
|
| 1354 |
self.update_icon = "#page_status_notification_updates" |
| 1355 |
self.update_text = "#page_status_notification_updates" |
| 1356 |
self.update_text_action = "#page_status_notification_updates a" |
| 1357 |
|
| 1358 |
def testNoUpdates(self): |
| 1359 |
b = self.browser |
| 1360 |
|
| 1361 |
# fresh machine, no updates available; by default our rhel-* images are not registered |
| 1362 |
self.login_and_go("/system") |
| 1363 |
# show unregistered status on system front page |
| 1364 |
with b.wait_timeout(30): |
| 1365 |
b.wait_in_text(self.update_text, "Not registered") |
| 1366 |
self.assertIn("pf-m-warning", b.attr(self.update_icon + " .pf-v6-c-icon__content", "class")) |
| 1367 |
|
| 1368 |
# software updates page also shows unregistered |
| 1369 |
b.go("/updates") |
| 1370 |
b.enter_page("/updates") |
| 1371 |
# empty state visible in main area |
| 1372 |
b.wait_visible(".pf-v6-c-empty-state button") |
| 1373 |
b.wait_in_text(".pf-v6-c-empty-state", "This system is not registered") |
| 1374 |
|
| 1375 |
# test the button to switch to Subscriptions |
| 1376 |
b.click(".pf-v6-c-empty-state button") |
| 1377 |
b.switch_to_top() |
| 1378 |
b.wait_js_cond('window.location.pathname === "/subscriptions"') |
| 1379 |
|
| 1380 |
# after registration it should show the usual "system is up to date", through the "status changed" signal |
| 1381 |
self.register_with_candlepin() |
| 1382 |
b.go("/updates") |
| 1383 |
b.enter_page("/updates") |
| 1384 |
# check updates |
| 1385 |
b.wait_visible("#status .pf-v6-c-card__header button") |
| 1386 |
b.wait_in_text("#status", "System is up to date") |
| 1387 |
|
| 1388 |
# same on system page |
| 1389 |
b.go("/system") |
| 1390 |
b.enter_page("/system") |
| 1391 |
self.assertEqual(b.attr(self.update_icon + " svg", "data-pficon"), "check") |
| 1392 |
b.wait_text(self.update_text, "System is up to date") |
| 1393 |
|
| 1394 |
def testAvailableUpdates(self): |
| 1395 |
b = self.browser |
| 1396 |
|
| 1397 |
# one available update |
| 1398 |
self.createPackage("vanilla", "1.0", "1", install=True) |
| 1399 |
self.createPackage("vanilla", "1.0", "2") |
| 1400 |
self.enableRepo() |
| 1401 |
|
| 1402 |
self.login_and_go("/system") |
| 1403 |
# by default our rhel-* images are not registered; show warning on system page |
| 1404 |
with b.wait_timeout(30): |
| 1405 |
b.wait_in_text(self.update_text, "Not registered") |
| 1406 |
self.assertIn("pf-m-warning", b.attr(self.update_icon + " .pf-v6-c-icon__content", "class")) |
| 1407 |
# should be a link leading to subscriptions page |
| 1408 |
b.click(self.update_text_action) |
| 1409 |
b.enter_page("/subscriptions") |
| 1410 |
|
| 1411 |
# software updates page also shows unregistered |
| 1412 |
b.go("/updates") |
| 1413 |
b.enter_page("/updates") |
| 1414 |
|
| 1415 |
# empty state visible in main area |
| 1416 |
b.wait_visible(".pf-v6-c-empty-state button") |
| 1417 |
b.wait_in_text(".pf-v6-c-empty-state", "This system is not registered") |
| 1418 |
|
| 1419 |
# after registration it should show available updates |
| 1420 |
self.register_with_candlepin() |
| 1421 |
b.go("/updates") |
| 1422 |
b.enter_page("/updates") |
| 1423 |
b.wait_not_present(".pf-v6-c-empty-state") |
| 1424 |
with b.wait_timeout(30): |
| 1425 |
b.wait_visible("#available-updates") |
| 1426 |
# no update history yet |
| 1427 |
self.assertFalse(b.is_present("table.updates-history")) |
| 1428 |
|
| 1429 |
# has action buttons |
| 1430 |
b.wait_visible("#status .pf-v6-c-card__header button") |
| 1431 |
self.assertEqual(b.text("#available-updates button#install-all"), "Install all updates") |
| 1432 |
|
| 1433 |
# show available updates on system page too |
| 1434 |
b.go("/system") |
| 1435 |
b.enter_page("/system") |
| 1436 |
b.wait_text(self.update_text, "Bug fix updates available") |
| 1437 |
self.assertEqual(b.attr(self.update_icon + " svg", "data-pficon"), "bug") |
| 1438 |
|
| 1439 |
def testNoSubOsRepo(self): |
| 1440 |
b = self.browser |
| 1441 |
|
| 1442 |
# pretend we have a proper OS repo that does not require subscription |
| 1443 |
self.createPackage("coreutils", "999", "1") |
| 1444 |
self.enableRepo(refresh_repo=True) |
| 1445 |
|
| 1446 |
self.login_and_go("/system") |
| 1447 |
with b.wait_timeout(30): |
| 1448 |
b.wait_text(self.update_text, "System is up to date") |
| 1449 |
|
| 1450 |
b.go("/updates") |
| 1451 |
b.enter_page("/updates") |
| 1452 |
b.wait_visible("#status .pf-v6-c-card__header button") |
| 1453 |
b.wait_in_text("#status", "System is up to date") |
| 1454 |
|
| 1455 |
|
| 1456 |
@testlib.skipOstree("Image uses OSTree") |
| 1457 |
@testlib.nondestructive |
| 1458 |
class TestAutoUpdates(NoSubManCase): |
| 1459 |
|
| 1460 |
def setUp(self): |
| 1461 |
super().setUp() |
| 1462 |
# not implemented for apt yet, only dnf |
| 1463 |
self.supported_backend = "dnf" in self.backend |
| 1464 |
if self.backend == "dnf5": |
| 1465 |
self.timer_unit = "dnf5-automatic" |
| 1466 |
self.config = "/etc/dnf/dnf5-plugins/automatic.conf" |
| 1467 |
elif self.backend == "dnf4": |
| 1468 |
self.timer_unit = "dnf-automatic-install" |
| 1469 |
self.config = "/etc/dnf/automatic.conf" |
| 1470 |
|
| 1471 |
def closeSettings(self, browser: testlib.Browser) -> None: |
| 1472 |
browser.click("#automatic-updates-dialog button:contains('Save changes')") |
| 1473 |
with browser.wait_timeout(30): |
| 1474 |
browser.wait_not_present("#automatic-updates-dialog") |
| 1475 |
|
| 1476 |
def testBasic(self): |
| 1477 |
b = self.browser |
| 1478 |
m = self.machine |
| 1479 |
|
| 1480 |
self.login_and_go("/updates") |
| 1481 |
with b.wait_timeout(30): |
| 1482 |
b.wait_visible("#status") |
| 1483 |
|
| 1484 |
if not self.supported_backend: |
| 1485 |
self.assertFalse(b.is_present("#automatic")) |
| 1486 |
self.assertFalse(b.is_present("#auto-update-type")) |
| 1487 |
return |
| 1488 |
|
| 1489 |
def assertTimerDnf(hour: str | None, dow: str | None) -> None: |
| 1490 |
out = m.execute(f"systemctl --no-legend list-timers {self.timer_unit}.timer") |
| 1491 |
if hour: |
| 1492 |
# don't test the minutes, due to RandomizedDelaySec=60m |
| 1493 |
self.assertRegex(out, f" {hour}:") |
| 1494 |
else: |
| 1495 |
self.assertEqual(out, "") |
| 1496 |
if dow: |
| 1497 |
self.assertRegex(out, r"^%s\s" % dow) |
| 1498 |
else: |
| 1499 |
# "every day" should not have a "LEFT" time > 1 day |
| 1500 |
self.assertNotIn(" day", out) |
| 1501 |
|
| 1502 |
# service should not run right away |
| 1503 |
self.assertEqual(m.execute(f"systemctl is-active {self.timer_unit}.service || true").strip(), "inactive") |
| 1504 |
|
| 1505 |
# automatic reboots should be enabled whenever timer is enabled |
| 1506 |
out = m.execute(f"systemctl cat {self.timer_unit}.service") |
| 1507 |
if hour: |
| 1508 |
if m.image.startswith("rhel-8"): |
| 1509 |
# for RHEL 8, dnf-automatic does not support reboot; we have a unit drop-in hack |
| 1510 |
self.assertRegex(out, "ExecStartPost=/.*shutdown") |
| 1511 |
# validate our assumption |
| 1512 |
self.assertNotIn("reboot", m.execute(f"cat {self.config}")) |
| 1513 |
else: |
| 1514 |
# newer dnf supports that natively |
| 1515 |
self.assertNotIn("ExecStartPost", out) |
| 1516 |
self.assertIn("reboot = when-needed", m.execute(f"cat {self.config}")) |
| 1517 |
else: |
| 1518 |
self.assertNotIn("ExecStartPost", out) |
| 1519 |
|
| 1520 |
def assertTimer(hour: str | None, dow: str | None = None) -> None: |
| 1521 |
if "dnf" in self.backend: |
| 1522 |
assertTimerDnf(hour, dow) |
| 1523 |
else: |
| 1524 |
raise NotImplementedError(self.backend) |
| 1525 |
|
| 1526 |
def assertTypeDnf(type_: str) -> None: |
| 1527 |
if type_ == "all": |
| 1528 |
match = '= default' |
| 1529 |
elif type_ == "security": |
| 1530 |
match = '= security' |
| 1531 |
else: |
| 1532 |
raise ValueError(type_) |
| 1533 |
|
| 1534 |
self.assertIn(match, m.execute(f"grep upgrade_type {self.config}")) |
| 1535 |
|
| 1536 |
def assertType(type_: str) -> None: |
| 1537 |
if "dnf" in self.backend: |
| 1538 |
assertTypeDnf(type_) |
| 1539 |
else: |
| 1540 |
raise NotImplementedError(self.backend) |
| 1541 |
|
| 1542 |
# automatic updates are supported, but off |
| 1543 |
b.wait_in_text("#autoupdates-settings", "Disabled") |
| 1544 |
assertTimer(None) |
| 1545 |
|
| 1546 |
# enable |
| 1547 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1548 |
b.wait_visible("#automatic-updates-dialog") |
| 1549 |
b.click("#all-updates") |
| 1550 |
b.wait_val("#auto-update-time-input", "06:00") |
| 1551 |
b.wait_in_text("#auto-update-day", "every day") |
| 1552 |
self.closeSettings(b) |
| 1553 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every day at 06:00") |
| 1554 |
assertTimer("06") |
| 1555 |
assertType("all") |
| 1556 |
|
| 1557 |
# change type to security |
| 1558 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1559 |
b.wait_visible("#automatic-updates-dialog") |
| 1560 |
b.click("#security-updates") |
| 1561 |
self.closeSettings(b) |
| 1562 |
b.wait_in_text("#autoupdates-settings", "Security updates will be applied every day at 06:00") |
| 1563 |
assertType("security") |
| 1564 |
assertTimer("06") |
| 1565 |
|
| 1566 |
# change it back |
| 1567 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1568 |
b.wait_visible("#automatic-updates-dialog") |
| 1569 |
b.click("#all-updates") |
| 1570 |
self.closeSettings(b) |
| 1571 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every day at 06:00") |
| 1572 |
assertType("all") |
| 1573 |
assertTimer("06") |
| 1574 |
|
| 1575 |
# change day |
| 1576 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1577 |
b.wait_visible("#automatic-updates-dialog") |
| 1578 |
b.select_from_dropdown("#auto-update-day", "thu") |
| 1579 |
self.closeSettings(b) |
| 1580 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every Thursday at 06:00") |
| 1581 |
assertType("all") |
| 1582 |
assertTimer("06", "Thu") |
| 1583 |
|
| 1584 |
# change time |
| 1585 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1586 |
b.wait_visible("#automatic-updates-dialog") |
| 1587 |
b.set_input_text("#auto-update-time-input", "21:00") |
| 1588 |
self.closeSettings(b) |
| 1589 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every Thursday at 21:00") |
| 1590 |
assertType("all") |
| 1591 |
assertTimer("21", "Thu") |
| 1592 |
|
| 1593 |
# page should parse it correctly from the timer |
| 1594 |
b.logout() |
| 1595 |
b.login_and_go("/updates") |
| 1596 |
with b.wait_timeout(30): |
| 1597 |
b.wait_visible("#status") |
| 1598 |
|
| 1599 |
with b.wait_timeout(30): |
| 1600 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every Thursday at 21:00") |
| 1601 |
|
| 1602 |
# change back to daily |
| 1603 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1604 |
b.wait_visible("#automatic-updates-dialog") |
| 1605 |
b.select_from_dropdown("#auto-update-day", "everyday") |
| 1606 |
self.closeSettings(b) |
| 1607 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every day at 21:00") |
| 1608 |
assertType("all") |
| 1609 |
assertTimer("21") |
| 1610 |
|
| 1611 |
# disable |
| 1612 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1613 |
b.wait_visible("#automatic-updates-dialog") |
| 1614 |
b.click("#no-updates") |
| 1615 |
self.closeSettings(b) |
| 1616 |
b.wait_in_text("#autoupdates-settings", "Disabled") |
| 1617 |
assertTimer(None) |
| 1618 |
|
| 1619 |
if "dnf" in self.backend: |
| 1620 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1621 |
b.wait_visible("#automatic-updates-dialog") |
| 1622 |
b.click("#all-updates") |
| 1623 |
self.closeSettings(b) |
| 1624 |
# OnCalendar= parsing: only time |
| 1625 |
m.execute(f"mkdir -p /etc/systemd/system/{self.timer_unit}.timer.d") |
| 1626 |
m.execute(r'printf "[Timer]\nOnUnitInactiveSec=\nOnCalendar=08:00\n" > ' |
| 1627 |
f'/etc/systemd/system/{self.timer_unit}.timer.d/time.conf; systemctl daemon-reload') |
| 1628 |
b.reload() |
| 1629 |
b.enter_page("/updates") |
| 1630 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every day at 8:00") |
| 1631 |
b.wait_visible("#autoupdates-settings button") |
| 1632 |
|
| 1633 |
# OnCalendar= parsing: weekday and time |
| 1634 |
m.execute(r'printf "[Timer]\nOnUnitInactiveSec=\nOnCalendar=Tue 20:00\n" > ' |
| 1635 |
f'/etc/systemd/system/{self.timer_unit}.timer.d/time.conf; systemctl daemon-reload') |
| 1636 |
b.reload() |
| 1637 |
b.enter_page("/updates") |
| 1638 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every Tuesday at 20:00") |
| 1639 |
b.wait_visible("#autoupdates-settings button") |
| 1640 |
|
| 1641 |
# OnCalendar= parsing: "every day" calendar and time |
| 1642 |
m.execute(r'printf "[Timer]\nOnUnitInactiveSec=\nOnCalendar=*-*-* 07:00\n" > ' |
| 1643 |
f'/etc/systemd/system/{self.timer_unit}.timer.d/time.conf; systemctl daemon-reload') |
| 1644 |
b.reload() |
| 1645 |
b.enter_page("/updates") |
| 1646 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every day at 7:00") |
| 1647 |
b.wait_visible("#autoupdates-settings button") |
| 1648 |
|
| 1649 |
# OnCalendar= parsing: unsupported |
| 1650 |
m.execute(r'printf "[Timer]\nOnUnitInactiveSec=\nOnCalendar=*-02-* 11:00\n" > ' |
| 1651 |
f'/etc/systemd/system/{self.timer_unit}.timer.d/time.conf; systemctl daemon-reload') |
| 1652 |
b.reload() |
| 1653 |
b.enter_page("/updates") |
| 1654 |
b.wait_visible("#settings .pf-v6-c-alert") |
| 1655 |
# don't allow stomping over unparsable custom settings |
| 1656 |
b.wait_not_present("#autoupdates-settings button") |
| 1657 |
|
| 1658 |
@testlib.skipImage("No supported auto update backend", "debian-*", "ubuntu-*", "arch") |
| 1659 |
def testWithAvailableUpdates(self): |
| 1660 |
b = self.browser |
| 1661 |
m = self.machine |
| 1662 |
|
| 1663 |
# use a package which dnf recognizes as "needs reboot" |
| 1664 |
self.createPackage("kernel-rt", "1.0", "1", install=True) |
| 1665 |
self.createPackage("kernel-rt", "1.0", "2") |
| 1666 |
self.enableRepo() |
| 1667 |
|
| 1668 |
self.login_and_go("/updates") |
| 1669 |
with b.wait_timeout(30): |
| 1670 |
b.wait_visible("#available-updates") |
| 1671 |
|
| 1672 |
b.wait_in_text("#autoupdates-settings", "Disabled") |
| 1673 |
|
| 1674 |
# enable |
| 1675 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1676 |
b.wait_visible("#automatic-updates-dialog") |
| 1677 |
b.click("#all-updates") |
| 1678 |
self.closeSettings(b) |
| 1679 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every day at 06:00") |
| 1680 |
|
| 1681 |
if "dnf" in self.backend: |
| 1682 |
# dial down the random sleep to avoid the test having to wait 5 mins |
| 1683 |
self.sed_file("/random_sleep/ s/=.*$/= 3/", self.config) |
| 1684 |
# then manually start the upgrade job like the timer would |
| 1685 |
m.execute(f"systemctl start {self.timer_unit}.service") |
| 1686 |
try: |
| 1687 |
# new kernel-rt package got installed |
| 1688 |
m.execute("test -f /stamp-kernel-rt-1.0-2") |
| 1689 |
# triggered reboot |
| 1690 |
m.execute("until test -f /run/nologin; do sleep 1; done") |
| 1691 |
# old distros don't have that yet; rely on /run/nologin to indicate scheduled shutdown |
| 1692 |
if not m.image.startswith("rhel-8"): |
| 1693 |
self.assertIn("scheduled for", m.execute("shutdown --show 2>&1")) |
| 1694 |
finally: |
| 1695 |
# always cancel the scheduled reboot |
| 1696 |
m.execute("shutdown -c; test ! -f /run/nologin") |
| 1697 |
# service should show kernel-rt upgrade |
| 1698 |
out = m.execute( |
| 1699 |
f"if systemctl status --lines=50 {self.timer_unit}.service; then echo 'expected service to be stopped'; exit 1; fi") |
| 1700 |
self.assertIn("kernel-rt", out) |
| 1701 |
|
| 1702 |
# run it again, now there are no available updates → no reboot |
| 1703 |
m.execute(f"systemctl start {self.timer_unit}.service") |
| 1704 |
m.execute("test -f /stamp-kernel-rt-1.0-2; test ! -f /run/nologin") |
| 1705 |
# service should not do much |
| 1706 |
out = m.execute( |
| 1707 |
f"if systemctl status {self.timer_unit}.service; then echo 'expected service to be stopped'; exit 1; fi") |
| 1708 |
self.assertNotIn("kernel-rt", out) |
| 1709 |
else: |
| 1710 |
raise NotImplementedError(self.backend) |
| 1711 |
|
| 1712 |
@testlib.skipImage("No supported auto update backend", "debian-*", "ubuntu-*", "arch") |
| 1713 |
def testPrivilegeChange(self): |
| 1714 |
b = self.browser |
| 1715 |
|
| 1716 |
self.refreshMetadata() |
| 1717 |
self.login_and_go("/updates", superuser=False) |
| 1718 |
b.wait_in_text("#status", "System is up to date") |
| 1719 |
|
| 1720 |
# detecting auto updates configuration works unprivileged, but changing does not |
| 1721 |
with b.wait_timeout(30): |
| 1722 |
b.wait_visible("#autoupdates-settings button:disabled") |
| 1723 |
|
| 1724 |
# become superuser, enable auto-updates |
| 1725 |
b.become_superuser() |
| 1726 |
b.wait_in_text("#autoupdates-settings", "Disabled") |
| 1727 |
b.click("#autoupdates-settings button:contains('Edit')") |
| 1728 |
b.wait_visible("#automatic-updates-dialog") |
| 1729 |
b.click("#all-updates") |
| 1730 |
self.closeSettings(b) |
| 1731 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every day at 06:00") |
| 1732 |
|
| 1733 |
# without superuser, auto-update status still visible, but disabled |
| 1734 |
b.drop_superuser() |
| 1735 |
b.wait_in_text("#autoupdates-settings", "Updates will be applied every day at 06:00") |
| 1736 |
b.wait_visible("#autoupdates-settings button:disabled") |
| 1737 |
|
| 1738 |
|
| 1739 |
@testlib.skipOstree("Image uses OSTree") |
| 1740 |
class TestAutoUpdatesInstall(NoSubManCase): |
| 1741 |
def testUnsupported(self): |
| 1742 |
b = self.browser |
| 1743 |
m = self.machine |
| 1744 |
|
| 1745 |
if self.backend == 'dnf5': |
| 1746 |
m.execute("dnf remove -y dnf5-plugin-automatic") |
| 1747 |
elif self.backend == 'dnf4': |
| 1748 |
m.execute("dnf remove -y dnf-automatic") |
| 1749 |
elif self.backend == 'apt': |
| 1750 |
m.execute("dpkg -P unattended-upgrades") |
| 1751 |
|
| 1752 |
# first test with available upgrades |
| 1753 |
self.createPackage("vanilla", "1.0", "1", install=True) |
| 1754 |
self.createPackage("vanilla", "1.0", "2") |
| 1755 |
self.enableRepo() |
| 1756 |
|
| 1757 |
self.login_and_go("/updates") |
| 1758 |
with b.wait_timeout(30): |
| 1759 |
b.wait_visible("#available-updates") |
| 1760 |
|
| 1761 |
# apply updates |
| 1762 |
b.click("#available-updates button#install-all") |
| 1763 |
# wait until installation is finished |
| 1764 |
with b.wait_timeout(60): |
| 1765 |
b.wait_in_text(".pf-v6-c-empty-state__title", "Update was successful") |
| 1766 |
b.click("#ignore") |
| 1767 |
|
| 1768 |
if "dnf" in self.backend: |
| 1769 |
b.wait_in_text("#autoupdates-settings", "Not set up") |
| 1770 |
b.wait_not_present("#settings .pf-v6-c-alert") |
| 1771 |
b.click("#autoupdates-settings button:contains('Enable')") |
| 1772 |
else: |
| 1773 |
b.wait_not_present("#settings") |
| 1774 |
b.wait_not_present("#autoupdates-settings") |
| 1775 |
|
| 1776 |
@testlib.skipImage("No supported auto update backend", "debian-*", "ubuntu-*", "arch") |
| 1777 |
def testInstall(self): |
| 1778 |
b = self.browser |
| 1779 |
m = self.machine |
| 1780 |
|
| 1781 |
# provide minimal content in order for the backend to be seen as supported |
| 1782 |
timerContent = """ |
| 1783 |
[Unit] |
| 1784 |
Description=dnf-automatic timer |
| 1785 |
# See comment in dnf-makecache.service |
| 1786 |
ConditionPathExists=!/run/ostree-booted |
| 1787 |
|
| 1788 |
[Timer] |
| 1789 |
OnBootSec=1h |
| 1790 |
OnUnitInactiveSec=1d |
| 1791 |
Unit=-.mount |
| 1792 |
|
| 1793 |
[Install] |
| 1794 |
WantedBy=basic.target |
| 1795 |
""" |
| 1796 |
|
| 1797 |
if self.backend == 'dnf5': |
| 1798 |
m.execute("dnf remove -y dnf5-plugin-automatic") |
| 1799 |
self.createPackage('dnf5-plugin-automatic', '1', '1', content={ |
| 1800 |
'/etc/dnf/dnf5-plugins/automatic.conf': '', |
| 1801 |
'/usr/lib/systemd/system/dnf5-automatic.timer': timerContent, |
| 1802 |
}) |
| 1803 |
|
| 1804 |
elif self.backend == 'dnf4': |
| 1805 |
m.execute("dnf remove -y dnf-automatic") |
| 1806 |
|
| 1807 |
self.createPackage('dnf-automatic', '1', '1', content={ |
| 1808 |
'/etc/dnf/automatic.conf': '', |
| 1809 |
'/usr/lib/systemd/system/dnf-automatic.timer': timerContent, |
| 1810 |
'/usr/lib/systemd/system/dnf-automatic-install.timer': timerContent, |
| 1811 |
}) |
| 1812 |
elif self.backend == 'apt': |
| 1813 |
m.execute("dpkg -P unattended-upgrades") |
| 1814 |
|
| 1815 |
self.enableRepo() |
| 1816 |
|
| 1817 |
self.login_and_go('/updates') |
| 1818 |
|
| 1819 |
# click through install dialog |
| 1820 |
with b.wait_timeout(30): |
| 1821 |
b.wait_in_text("#autoupdates-settings", "Not set up") |
| 1822 |
b.wait_not_present("#settings .pf-v6-c-alert") |
| 1823 |
b.click("#autoupdates-settings button:contains('Enable')") |
| 1824 |
b.wait_popup('dialog') |
| 1825 |
b.wait_visible('#dialog button.apply') |
| 1826 |
b.wait_not_attr('#dialog button.apply', 'disabled', '') |
| 1827 |
b.click('#dialog button.apply') |
| 1828 |
|
| 1829 |
# as dnf-automatic isn't actually installed DnfImpl.setConfig will fail, |
| 1830 |
# but we can check that the backend is now enabled |
| 1831 |
b.wait_visible("#automatic-updates-dialog") |
| 1832 |
|
| 1833 |
|
| 1834 |
@testlib.skipOstree("Image uses OSTree") |
| 1835 |
@testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed") |
| 1836 |
@testlib.nondestructive |
| 1837 |
class TestInstallDialog(NoSubManCase): |
| 1838 |
|
| 1839 |
def show_install_dialog(self, *packages: str): |
| 1840 |
b = self.browser |
| 1841 |
b.set_input_text("#install-packages", ",".join(packages)) |
| 1842 |
b.click("#install-button") |
| 1843 |
b.wait_in_text("#dialog", "Install software") |
| 1844 |
|
| 1845 |
def install_packages(self): |
| 1846 |
b = self.browser |
| 1847 |
b.click("#dialog button:contains('Install')") |
| 1848 |
# assert some progress |
| 1849 |
b.wait_not_present("#dialog") |
| 1850 |
|
| 1851 |
def testBasic(self): |
| 1852 |
b = self.browser |
| 1853 |
|
| 1854 |
# dummy package |
| 1855 |
self.createPackage("dummy", "1", "1") |
| 1856 |
|
| 1857 |
# package which depends on another package |
| 1858 |
self.createPackage("test-webserver", "998", "1", depends="test-webengine") |
| 1859 |
self.createPackage("test-webengine", "998", "1") |
| 1860 |
|
| 1861 |
# package which conflicts with another package |
| 1862 |
self.createPackage("ok-software", "998", "1", install=True) |
| 1863 |
self.createPackage("breaking-software", "999", "1", conflicts="ok-software") |
| 1864 |
|
| 1865 |
# package that is already installed should not prevent extra packages from showing |
| 1866 |
self.createPackage("already-installed", "998", "1", install=True) |
| 1867 |
|
| 1868 |
# Test error condition, package not being available yet |
| 1869 |
self.login_and_go('/playground/packagemanager') |
| 1870 |
b.wait_in_text("#install-card-title", "Install dialog test") |
| 1871 |
self.show_install_dialog("dummy") |
| 1872 |
b.wait_in_text("#dialog .pf-v6-c-alert__title", "dummy is not available from any repository.") |
| 1873 |
b.wait_visible("#dialog button.pf-m-primary:disabled") |
| 1874 |
b.click("#dialog button.cancel") |
| 1875 |
b.wait_not_present("#dialog") |
| 1876 |
|
| 1877 |
# Install dummy which is now available |
| 1878 |
# Also works around https://github.com/PackageKit/PackageKit/issues/893 |
| 1879 |
self.enableRepo(refresh_repo=self.backend != "dnf5") |
| 1880 |
|
| 1881 |
self.show_install_dialog("dummy") |
| 1882 |
b.wait_in_text("#dialog", "dummy will be installed.") |
| 1883 |
self.install_packages() |
| 1884 |
|
| 1885 |
# Test that additional installed packages are shown in the dialog |
| 1886 |
b.wait_in_text("#install-card-title", "Install dialog test") |
| 1887 |
self.show_install_dialog("already-installed,test-webserver") |
| 1888 |
b.wait_in_text("#dialog", "already-installed, test-webserver will be installed.") |
| 1889 |
b.wait_text("#dialog .scale-up-ct", "Additional packages:test-webengine") |
| 1890 |
self.install_packages() |
| 1891 |
|
| 1892 |
if self.backend != "dnf5": |
| 1893 |
# Test conflicting packages are shown as removed |
| 1894 |
self.show_install_dialog("breaking-software") |
| 1895 |
b.wait_in_text("#dialog", "breaking-software will be installed.") |
| 1896 |
# The svg icon creates a tiny bit of whitespace |
| 1897 |
b.wait_text("#dialog .scale-up-ct", " Removals:ok-software") |
| 1898 |
self.install_packages() |
| 1899 |
else: |
| 1900 |
# package which is replaced with another package |
| 1901 |
self.createPackage("good-software", "998", "1", install=True) |
| 1902 |
self.createPackage("awesome-software", "999", "1", provides="good-software = 999", obsoletes="good-software < 999") |
| 1903 |
self.enableRepo() |
| 1904 |
|
| 1905 |
self.show_install_dialog("awesome-software") |
| 1906 |
b.wait_in_text("#dialog", "awesome-software will be installed.") |
| 1907 |
# The svg icon creates a tiny bit of whitespace |
| 1908 |
b.wait_text("#dialog .scale-up-ct", " Removals:good-software") |
| 1909 |
self.install_packages() |
| 1910 |
|
| 1911 |
# Conflicting packages require setting `allow_erasing`. |
| 1912 |
self.show_install_dialog("breaking-software") |
| 1913 |
b.wait_in_text("#dialog", "breaking-software will be installed.") |
| 1914 |
b.wait_in_text("#dialog .pf-v6-c-alert__title", "Resolving install failed with result=2") |
| 1915 |
b.wait_in_text("#dialog .pf-v6-c-alert__title", "installed package ok-software-998-1.noarch conflicts with ok-software provided by breaking-software-999") |
| 1916 |
|
| 1917 |
|
| 1918 |
if __name__ == '__main__': |
| 1919 |
testlib.test_main() |