Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from virttest import utils_test
from virttest import virsh
from virttest.staging import lv_utils
from virttest import test_setup

from virttest import libvirt_version

Expand Down Expand Up @@ -60,6 +61,34 @@ def run(test, params, env):
cleanup_nfs = False
cleanup_iscsi = False
cleanup_logical = False
polkit = None

# Setup polkit if ACL test
if params.get('setup_libvirt_polkit') == 'yes':
logging.info("Setting up polkit for ACL test")
polkit = test_setup.LibvirtPolkitConfig(params)
try:
polkit.setup()
logging.info("Polkit setup completed successfully")

# Explicitly restart virtstoraged for storage driver ACL tests
# The libvirtd.restart() in polkit.setup() doesn't always restart virtstoraged
if utils_split_daemons.is_modular_daemon():
from virttest.staging import service
try:
virtstoraged = service.Factory.create_service("virtstoraged")
logging.info("Restarting virtstoraged to apply polkit rules")
virtstoraged.restart()
logging.info("virtstoraged restarted successfully")
except Exception as svc_err:
raise exceptions.TestError(
"Failed to restart virtstoraged after polkit setup: %s" % svc_err
) from svc_err
except exceptions.TestError:
raise
except Exception as e:
logging.error("Failed to setup polkit: %s", e)
raise exceptions.TestError("Polkit setup failed: %s" % e)

# Prepare source storage
if source_host == "127.0.0.1":
Expand Down Expand Up @@ -128,3 +157,14 @@ def run(test, params, env):
if cleanup_nfs:
utils_test.libvirt.setup_or_cleanup_nfs(
False, restore_selinux=selinux_bak)
if polkit:
logging.info("Cleaning up polkit configuration")
try:
polkit.cleanup()
if utils_split_daemons.is_modular_daemon():
from virttest.staging import service
virtstoraged = service.Factory.create_service("virtstoraged")
logging.info("Restarting virtstoraged after polkit cleanup")
virtstoraged.restart()
except Exception as e:
logging.warning("Failed to cleanup polkit: %s", e)
17 changes: 17 additions & 0 deletions libvirt/tests/src/virsh_cmd/pool/virsh_pool_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ def run(test, params, env):
test.cancel("API acl test not supported in current"
" libvirt version.")

# Polkit is already set up by the test framework when setup_libvirt_polkit=yes
# We just need to ensure virtstoraged is restarted after polkit rules are created
if params.get('setup_libvirt_polkit') == 'yes':
logging.info("ACL test detected - ensuring virtstoraged is restarted")
from virttest.staging import service
try:
virtstoraged = service.Factory.create_service("virtstoraged")
logging.info("Restarting virtstoraged to apply polkit rules")
virtstoraged.restart()
logging.info("virtstoraged restarted successfully")
import time
time.sleep(2)
logging.info("virtstoraged should now have loaded polkit rules")
except Exception as svc_err:
logging.warning("Failed to restart virtstoraged: %s", svc_err)


acl_dargs = {'uri': uri, 'unprivileged_user': unprivileged_user,
'debug': True}

Expand Down