Add local service check

After noticed non-root user can list devstack services in plugin's
triggered jobs, fixed past review comment to use preferred `systemctl`
instead of configurable directory existence check.

Added common local service check function to reduce repeated code.

Small code improvements along the way, like sparing second shell
call when podified setup used.

Change-Id: Idbb98765ef2020d674ed00f3b43193d0bed935d2
This commit is contained in:
Maor Blaustein
2025-07-01 17:59:15 +03:00
parent e8ec12c055
commit 6cdf917a6d
2 changed files with 15 additions and 13 deletions

View File

@@ -51,13 +51,20 @@ def is_regex_in_file(regex, filename, re_flags=0, fail_no_file=True):
return result
def _is_devstack_wsgi():
# TODO(rxiao): remove this check when/if API check exists
if shell.execute(
def is_local_service(service_name):
"""Returns if local service exists"""
return bool(
shell.execute(
"systemctl list-unit-files --type service | "
"grep devstack@neutron-api", check=False).stdout.strip():
return True
return False
f"grep '{service_name}'",
check=False
).stdout.strip())
def is_devstack_wsgi():
"""Returns if wsgi according to neutron api service name when used"""
# TODO(rxiao): remove this check when/if API check exists
return is_local_service('devstack@neutron-api')
def conf_action(

View File

@@ -56,14 +56,9 @@ ConfigOption = collections.namedtuple(
class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
credentials = ['primary', 'admin']
# NOTE(mblue): change devstack check if CI must not use /opt/stack,
# currently used commonly for devstack jobs needed by plugin.
if 'is_devstack' not in locals():
is_devstack = bool(shell.execute(
'test -d /opt/stack && echo stack',
check=False).stdout.strip())
if 'is_devstack_wsgi' not in locals():
is_devstack_wsgi = local_utils._is_devstack_wsgi()
is_devstack = local_utils.is_local_service("devstack@")
is_devstack_wsgi = is_devstack and local_utils.is_devstack_wsgi()
@classmethod
def resource_setup(cls):