| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2015 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import os.path |
| 9 |
import subprocess |
| 10 |
import tarfile |
| 11 |
|
| 12 |
import testlib |
| 13 |
|
| 14 |
|
| 15 |
@testlib.skipOstree("No sosreport") |
| 16 |
@testlib.skipImage("No sosreport", "arch", "opensuse-tumbleweed") |
| 17 |
@testlib.nondestructive |
| 18 |
class TestSOS(testlib.MachineCase): |
| 19 |
|
| 20 |
def setUp(self) -> None: |
| 21 |
super().setUp() |
| 22 |
m = self.machine |
| 23 |
|
| 24 |
# Older Debian and Ubuntu systems have sosreport in /tmp |
| 25 |
# Newer versions of sosreport changed to /var/tmp |
| 26 |
# https://github.com/sosreport/sos/pull/4090 |
| 27 |
if m.image in ["debian-trixie"]: |
| 28 |
self.report_dir = "/tmp" |
| 29 |
else: |
| 30 |
self.report_dir = "/var/tmp" |
| 31 |
|
| 32 |
m.execute(f"rm -rf {self.report_dir}/*sos*") |
| 33 |
|
| 34 |
self.restore_file("/etc/sos/sos.conf") |
| 35 |
m.execute(r"sed -i -e '/\[global\]/a threads=1' " |
| 36 |
r"-e '/\[report\]/a only-plugins=release,date,host,cgroups,networking' " |
| 37 |
r"/etc/sos/sos.conf") |
| 38 |
|
| 39 |
def testBasic(self, urlroot: str = "") -> None: |
| 40 |
b = self.browser |
| 41 |
m = self.machine |
| 42 |
|
| 43 |
if urlroot != "": |
| 44 |
m.write("/etc/cockpit/cockpit.conf", f"[WebService]\nUrlRoot={urlroot}") |
| 45 |
|
| 46 |
self.login_and_go("/sosreport", urlroot=urlroot, superuser=False) |
| 47 |
|
| 48 |
b.wait_in_text("#app", "Administrative access required") |
| 49 |
if urlroot == "": |
| 50 |
b.assert_pixels("#app", "limited") |
| 51 |
|
| 52 |
b.become_superuser() |
| 53 |
|
| 54 |
b.wait_in_text("#app", "No system reports.") |
| 55 |
if urlroot == "": |
| 56 |
b.assert_pixels("#app", "empty") |
| 57 |
|
| 58 |
b.click("button:contains('Run report')") |
| 59 |
b.wait_visible("#sos-dialog") |
| 60 |
b.set_input_text("#sos-dialog #sos-dialog-ti-1", "mylabel") |
| 61 |
b.set_input_text("#sos-dialog #sos-dialog-ti-2", "foobar") |
| 62 |
b.set_checked("#sos-dialog #sos-dialog-cb-1", val=True) |
| 63 |
if urlroot == "": |
| 64 |
b.assert_pixels("#sos-dialog", "dialog") |
| 65 |
b.click("#sos-dialog button:contains('Run report')") |
| 66 |
with b.wait_timeout(120): |
| 67 |
b.wait_not_present("#sos-dialog") |
| 68 |
|
| 69 |
b.wait_in_text("tr td[data-label='Report']", "mylabel") |
| 70 |
b.allow_download() |
| 71 |
|
| 72 |
def downloaded_sosreports(): |
| 73 |
return [str(p) for p in b.driver.download_dir.glob("*sosreport-*.xz.gpg")] |
| 74 |
|
| 75 |
b.click("tr button:contains('Download')") |
| 76 |
# while the download is ongoing, it will have an *.xz.tmpsuffix name, gets renamed to *.xz when done |
| 77 |
testlib.wait(lambda: len(downloaded_sosreports()) > 0) |
| 78 |
report_gpg = downloaded_sosreports()[0] |
| 79 |
report = report_gpg.removesuffix(".gpg") |
| 80 |
base_report_gpg = os.path.basename(report_gpg) |
| 81 |
base_report = base_report_gpg.removesuffix(".gpg") |
| 82 |
|
| 83 |
m.execute(f"test -f {self.report_dir}/{base_report_gpg}") |
| 84 |
|
| 85 |
# Check that /etc/release was saved. It the files does not exist, getmember raises KeyError |
| 86 |
# Sometimes it takes a bit of time until the file can be opened. Try it 3 times. |
| 87 |
subprocess.call(["gpg", "--batch", "--yes", "--passphrase", "foobar", |
| 88 |
"--output", report, "--decrypt", report_gpg]) |
| 89 |
with tarfile.open(report) as tar: |
| 90 |
# the tarball contains a single subdirectory, get its name |
| 91 |
names = tar.getnames() |
| 92 |
topdir = names[0].split("/")[0] |
| 93 |
tar.getmember(os.path.join(topdir, "etc/os-release")) |
| 94 |
|
| 95 |
b.click("tr button.pf-v6-c-menu-toggle") |
| 96 |
b.click(".pf-v6-c-menu__list-item:contains('Delete')") |
| 97 |
b.click("#sos-remove-dialog button:contains('Delete')") |
| 98 |
# ensure it removes the report itself, and auxiliary files like .gpg |
| 99 |
m.execute(f"while ls {self.report_dir}/{base_report}*; do sleep 1; done", stdout=None, timeout=10) |
| 100 |
|
| 101 |
# error reporting |
| 102 |
self.write_file("/usr/sbin/sos", """#!/bin/sh |
| 103 |
echo "EssOhEss is kaputt" >&2 |
| 104 |
exit 1""", perm="755") |
| 105 |
b.click("button:contains('Run report')") |
| 106 |
b.wait_visible("#sos-dialog") |
| 107 |
b.click("#sos-dialog button:contains('Run report')") |
| 108 |
b.wait_in_text("#sos-dialog .pf-v6-c-alert", "sos report failed") |
| 109 |
b.wait_in_text("#sos-dialog .pf-v6-c-alert", "EssOhEss is kaputt") |
| 110 |
b.click("#sos-dialog button:contains('Cancel')") |
| 111 |
b.wait_not_present("#sos-dialog") |
| 112 |
|
| 113 |
self.allow_journal_messages('.*comm="sosreport".*') |
| 114 |
self.allow_browser_errors( |
| 115 |
'error: Failed to call sos report: {"problem":null,"exit_status":1,"exit_signal":null') |
| 116 |
|
| 117 |
def testWithUrlRoot(self) -> None: |
| 118 |
self.testBasic(urlroot="/webcon") |
| 119 |
|
| 120 |
def testVerbose(self) -> None: |
| 121 |
b = self.browser |
| 122 |
m = self.machine |
| 123 |
|
| 124 |
self.login_and_go("/sosreport") |
| 125 |
|
| 126 |
b.wait_in_text("#app", "No system reports.") |
| 127 |
|
| 128 |
b.click("button:contains('Run report')") |
| 129 |
b.wait_visible("#sos-dialog") |
| 130 |
b.set_input_text("#sos-dialog #sos-dialog-ti-1", "mylabel") |
| 131 |
b.set_checked("#sos-dialog #sos-dialog-cb-2", val=True) |
| 132 |
b.click("#sos-dialog button:contains('Run report')") |
| 133 |
with b.wait_timeout(120): |
| 134 |
b.wait_not_present("#sos-dialog") |
| 135 |
|
| 136 |
# There should be one archive and it should contain a bunch of debug messages |
| 137 |
self.assertEqual(m.execute(f"ls -l {self.report_dir}/sosreport*mylabel*.tar.xz | wc -l").strip(), "1") |
| 138 |
messages = m.execute(f"tar --wildcards -xaOf {self.report_dir}/sosreport*mylabel*.tar.xz '*/sos_logs/sos.log'" |
| 139 |
"| grep -c 'DEBUG: \\[plugin:release\\]'") |
| 140 |
self.assertGreater(int(messages), 5) |
| 141 |
|
| 142 |
def testCancel(self) -> None: |
| 143 |
m = self.machine |
| 144 |
b = self.browser |
| 145 |
|
| 146 |
self.login_and_go("/sosreport") |
| 147 |
b.click("button:contains('Run report')") |
| 148 |
b.click("#sos-dialog button:contains('Run report')") |
| 149 |
m.execute("until pgrep -x sos >/dev/null; do sleep 1; done") |
| 150 |
|
| 151 |
b.click("button:contains('Stop report')") |
| 152 |
b.wait_not_present("#sos-dialog") |
| 153 |
# cleans up properly; unfortunately closing the process is async, so need to retry a few times |
| 154 |
m.execute("while pgrep -a -x sos; do sleep 1; done", timeout=10) |
| 155 |
self.assertEqual(m.execute(f"ls {self.report_dir}/sosreport* 2>/dev/null || true"), "") |
| 156 |
|
| 157 |
@testlib.skipBeiboot("apps not available in beiboot mode") |
| 158 |
def testAppStream(self) -> None: |
| 159 |
b = self.browser |
| 160 |
m = self.machine |
| 161 |
|
| 162 |
self.allow_journal_messages("invalid or unusable locale.*") |
| 163 |
# chromium rpm has broken appstream data, which causes various parser errors |
| 164 |
self.allow_journal_messages(".*xml.*") |
| 165 |
|
| 166 |
self.login_and_go("/apps") |
| 167 |
b.wait_not_present(".pf-v6-c-empty-state") |
| 168 |
image_os = m.image.split('-')[0] |
| 169 |
if image_os in ['fedora', 'debian', 'ubuntu']: |
| 170 |
b.wait_visible(".app-list .pf-v6-c-data-list__item-row div[rowId='Diagnostic reports'] " |
| 171 |
"button:contains('Remove')") |
| 172 |
else: |
| 173 |
b.wait_not_present(".app-list .pf-v6-c-data-list__item-row div[rowId='Diagnostic reports']") |
| 174 |
|
| 175 |
|
| 176 |
if __name__ == '__main__': |
| 177 |
testlib.test_main() |