test: Use systemctl mask --now where possible

systemd supports stopping the unit before masking it, this gracefully
handles units which are not running or available on the system.
This commit is contained in:
Jelle van der Waa 2026-09-28 14:45:06 +02:00 committed by Jelle van der Waa
parent 55b3948dda
commit acde760e23
7 changed files with 10 additions and 11 deletions

View file

@ -1400,7 +1400,7 @@ until pgrep -f '^(/usr/[^ ]+/[^ /]*python[^ /]* )?/usr/bin/cockpit-bridge'; do s
m.stop_cockpit()
# make sure that this doesn't use the session socket
m.execute('systemctl stop cockpit-session.socket; systemctl mask cockpit-session.socket')
m.execute('systemctl mask --now cockpit-session.socket')
self.addCleanup(m.execute, 'systemctl unmask cockpit-session.socket')
m.write('/etc/cockpit/cockpit.conf', f"""
[Negotiate]

View file

@ -26,7 +26,7 @@ class NoSubManCase(packagelib.PackageCase):
# Disable Subscription Manager on RHEL for these tests; subscriptions are tested in a separate class
# On other OSes (Fedora/CentOS) we expect sub-man to be disabled in dnf, so it should not get in the way there
if self.machine.image.startswith("rhel") or self.machine.image.startswith("centos"):
self.machine.execute("systemctl stop rhsm.service; systemctl mask rhsm.service")
self.machine.execute("systemctl mask --now rhsm.service")
self.addCleanup(self.machine.execute, "systemctl unmask rhsm.service")
# expected journal messages from enabling/disabling auto upgrade services

View file

@ -670,7 +670,7 @@ OnCalendar=daily
# settroubleshootd eats memory in an unpredictable manner, silence it to reduce test flakes
if m.image.startswith(("fedora-", "rhel-")):
self.addCleanup(m.execute, "systemctl unmask setroubleshootd")
m.execute("systemctl stop setroubleshootd; systemctl mask setroubleshootd")
m.execute("systemctl mask --now setroubleshootd")
# packagekit/dnf often eats a lot of CPU/Memory; silence it to have better control over memory usage
packagekitd = "/usr/lib/packagekitd" if m.image == "arch" else "/usr/libexec/packagekitd"

View file

@ -991,7 +991,7 @@ matchrule = <SUBJECT>^DC=LAN,DC=COCKPIT,CN=alice$
# sssd-dbus not available
self.allow_journal_messages("cockpit-session: Failed to map .* Could not activate remote peer.*")
self.allow_journal_messages("cockpit-session: Failed to map .* Unit sssd-ifp.service is masked.")
m.execute("systemctl mask sssd-ifp; systemctl stop sssd-ifp")
m.execute("systemctl mask --now sssd-ifp")
do_test(alice_cert_key, ["HTTP/1.1 401 Authentication failed"],
not_expected=["crsf-token"])
m.execute("systemctl unmask sssd-ifp")

View file

@ -170,7 +170,7 @@ class TestStorageLegacyVDO(storagelib.StorageCase):
def setUp(self):
super().setUp()
# packagekit eats too much CPU/memory in the background
self.machine.execute("systemctl mask packagekit; systemctl stop packagekit")
self.machine.execute("systemctl mask --now packagekit")
def testVdo(self):
m = self.machine

View file

@ -629,7 +629,7 @@ fi
m.execute('[ ! -f /usr/sbin/grubby ] || mount --bind /tmp/grubby /usr/sbin/grubby')
m.write('/tmp/update-bootloader', '#!/bin/sh\necho 0')
m.execute('[ ! -f /usr/sbin/update-bootloader ] || mount --bind /tmp/update-bootloader /usr/sbin/update-bootloader')
m.execute('systemctl stop rpm-ostreed.service || true; systemctl mask rpm-ostreed.service')
m.execute('systemctl mask --now rpm-ostreed.service')
self.login_and_go('/system/hwinfo')
b.click('#hwinfo button:contains("Mitigations")')
b.click('#cpu-mitigations-dialog #nosmt-switch input')
@ -1107,9 +1107,8 @@ class TestSystemInfoTime(packagelib.PackageCase):
b = self.browser
m.execute("! systemctl is-active chronyd || systemctl stop chronyd")
m.execute("! systemctl is-active systemd-timesyncd || systemctl stop systemd-timesyncd")
m.execute("systemctl mask chronyd.service || systemctl mask chrony.service")
m.execute("systemctl mask systemd-timesyncd.service")
m.execute("systemctl mask --now systemd-timesyncd.service")
self.login_and_go("/system")

View file

@ -1168,8 +1168,8 @@ class TestPackageInstall(packagelib.PackageCase):
# case 1: disable package backend
if self.backend == 'dnf5':
m.execute("systemctl mask dnf5daemon-server; systemctl stop dnf5daemon-server.service || true")
m.execute("systemctl mask packagekit; systemctl stop packagekit.service || true")
m.execute("systemctl mask --now dnf5daemon-server")
m.execute("systemctl mask --now packagekit")
self.allow_browser_errors('checkRealm failed.*"problem":"not-found"')
self.login_and_go("/system")
b.wait_text(self.domain_sel, "Join domain")
@ -1222,7 +1222,7 @@ class TestPackageInstall(packagelib.PackageCase):
# disable the realmd package's service, so that we can restore it, but
# the package install code path will be triggered
m.execute("systemctl stop realmd; systemctl mask realmd")
m.execute("systemctl mask --now realmd")
self.login_and_go("/system")