@samitouri / QOSamiQemu / commits / ac84b9ec96

tests/functional: add skipWithoutSudo() decorator

To be used in the next commit: that would be a test for TAP networking, and it will need to setup TAP device. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Tested-by: Lei Yang <leiyang@redhat.com> Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru> Reviewed-by: Ben Chaney <bchaney@akamai.com> Message-ID: <20260729091334.1863155-15-vsementsov@yandex-team.ru> Signed-off-by: Thomas Huth <thuth@redhat.com>

Vladimir Sementsov-Ogievskiy committed Jul 29, 2026 at 12:12 UTC ac84b9ec9604db04a5c3a5935eff8caf85d01597
1 file changed +16
tests/functional/qemu_test/decorators.py
+16
@@ -6,6 +6,7 @@ import importlib
6 import os
7 import platform
8 import resource
9 +import subprocess
10 from unittest import skipIf, skipUnless
11
12 from .cmd import which
@@ -177,3 +178,18 @@ def skipLockedMemoryTest(locked_memory):
178 ulimit_memory == resource.RLIM_INFINITY or ulimit_memory >= locked_memory * 1024,
179 f'Test required {locked_memory} kB of available locked memory',
180 )
181 +
182 +'''
183 +Decorator to skip execution of a test if passwordless
184 +sudo command is not available.
185 +'''
186 +def skipWithoutSudo():
187 + proc = subprocess.run(["sudo", "-n", "/bin/true"],
188 + stdin=subprocess.PIPE,
189 + stdout=subprocess.PIPE,
190 + stderr=subprocess.STDOUT,
191 + universal_newlines=True,
192 + check=False)
193 +
194 + return skipUnless(proc.returncode == 0,
195 + f'requires password-less sudo access: {proc.stdout}')