Skip to content

virsh_find_storage_* : fix for Failed to connect socket to '/var/run/…#6864

Open
sneh-3 wants to merge 1 commit into
autotest:masterfrom
sneh-3:fix_virtstoraged-sock
Open

virsh_find_storage_* : fix for Failed to connect socket to '/var/run/…#6864
sneh-3 wants to merge 1 commit into
autotest:masterfrom
sneh-3:fix_virtstoraged-sock

Conversation

@sneh-3
Copy link
Copy Markdown

@sneh-3 sneh-3 commented May 6, 2026

…libvirt/virtstoraged-sock'

Added virtstoraged restart i.e. Deamon restarts after polkit configuration

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for storage pool discovery with authorization and access control validation procedures, including improved setup and cleanup handling.

…libvirt/virtstoraged-sock'

Added virtstoraged restart i.e. Deamon restarts after polkit configuration

Signed-off-by: Sneh Shikha Yadav <syadav@linux.ibm.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Walkthrough

This change enhances a virsh storage pool test file by adding polkit PolicyKit ACL configuration support. When the setup_libvirt_polkit parameter is enabled, the test initializes LibvirtPolkitConfig, applies the configuration, and restarts the virtstoraged service to apply ACL rules. A corresponding cleanup step removes the polkit configuration after tests complete, with error handling and logging throughout.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the primary change: fixing a socket connection error by adding virtstoraged restart after polkit configuration changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sneh-3
Copy link
Copy Markdown
Author

sneh-3 commented May 6, 2026

before fix :
(1126/2908) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.local_host.no_srcSpec: FAIL: error: failed to connect to the hypervisor\nerror: Failed to connect socket to '/var/run/libvirt/virtstoraged-sock': Permission denied\n (13.67 s)
(1128/2908) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_source.specified_srcSpec: FAIL: error: failed to connect to the hypervisor\nerror: Failed to connect socket to '/var/run/libvirt/virtstoraged-sock': Permission denied\n (13.31 s)
(1129/2908) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_direct_source.specified_srcSpec: STARTED
(1129/2908) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_direct_source.specified_srcSpec: FAIL: error: failed to connect to the hypervisor\nerror: Failed to connect socket to '/var/run/libvirt/virtstoraged-sock': Permission denied\n (13.41 s)
(1130/2908) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.logical_source.specified_srcSpec: STARTED
(1130/2908) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.logical_source.specified_srcSpec: FAIL: error: failed to connect to the hypervisor\nerror: Failed to connect socket to '/var/run/libvirt/virtstoraged-sock': Permission denied\n (13.66 s)

after fix:
(01/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.local_host.no_srcSpec: STARTED
(01/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.local_host.no_srcSpec: FAIL: vg_create failed: Command 'vgcreate virttest_vg_0 /dev/sdf' failed.\nstdout: b''\nstderr: b' Cannot use /dev/sdf: device is a multipath component\n Command requires all devices to be found.\n'\nadditional_info: None (56.91 s)
(02/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.nfs_source.specified_srcSpec: STARTED
(02/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.nfs_source.specified_srcSpec: PASS (34.14 s)
(03/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.iscsi_source.specified_srcSpec: STARTED
(03/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.iscsi_source.specified_srcSpec: PASS (48.13 s)
(04/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.iscsi_direct_source.specified_srcSpec: STARTED
(04/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.iscsi_direct_source.specified_srcSpec: PASS (55.87 s)
(05/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.logical_source.specified_srcSpec: STARTED
(05/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.logical_source.specified_srcSpec: FAIL: vg_create failed: Command 'vgcreate virttest_vg_0 /dev/sdf' failed.\nstdout: b''\nstderr: b' Cannot use /dev/sdf: device is a multipath component\n Command requires all devices to be found.\n'\nadditional_info: None (50.56 s)
(06/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.local_host.no_srcSpec: STARTED
(06/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.local_host.no_srcSpec: FAIL: vg_create failed: Command 'vgcreate virttest_vg_0 /dev/sdf' failed.\nstdout: b''\nstderr: b' Cannot use /dev/sdf: device is a multipath component\n Command requires all devices to be found.\n'\nadditional_info: None (40.27 s)
(07/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.nfs_source.specified_srcSpec: STARTED
(07/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.nfs_source.specified_srcSpec: PASS (42.44 s)
(08/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_source.specified_srcSpec: STARTED
(08/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_source.specified_srcSpec: PASS (56.13 s)
(09/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_direct_source.specified_srcSpec: STARTED
(09/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_direct_source.specified_srcSpec: PASS (53.47 s)
(10/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.logical_source.specified_srcSpec: STARTED
(10/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.logical_source.specified_srcSpec: FAIL: vg_create failed: Command 'vgcreate virttest_vg_0 /dev/sdf' failed.\nstdout: b''\nstderr: b' Cannot use /dev/sdf: device is a multipath component\n Command requires all devices to be found.\n'\nadditional_info: None (46.67 s)
(11/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.local_host.no_srcSpec: STARTED
(11/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.local_host.no_srcSpec: FAIL: vg_create failed: Command 'vgcreate virttest_vg_0 /dev/sdf' failed.\nstdout: b''\nstderr: b' Cannot use /dev/sdf: device is a multipath component\n Command requires all devices to be found.\n'\nadditional_info: None (46.28 s)
(12/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.nfs_source.specified_srcSpec: STARTED
(12/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.nfs_source.specified_srcSpec: PASS (42.86 s)
(13/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.iscsi_source.specified_srcSpec: STARTED
(13/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.iscsi_source.specified_srcSpec: PASS (44.19 s)
(14/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.iscsi_direct_source.specified_srcSpec: STARTED
(14/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.iscsi_direct_source.specified_srcSpec: PASS (62.16 s)
(15/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.logical_source.specified_srcSpec: STARTED
(15/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.non_acl.remote_host.logical_source.specified_srcSpec: FAIL: vg_create failed: Command 'vgcreate virttest_vg_0 /dev/sdf' failed.\nstdout: b''\nstderr: b' Cannot use /dev/sdf: device is a multipath component\n Command requires all devices to be found.\n'\nadditional_info: None (63.63 s)
(16/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.local_host.no_srcSpec: STARTED
(16/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.local_host.no_srcSpec: FAIL: vg_create failed: Command 'vgcreate virttest_vg_0 /dev/sdf' failed.\nstdout: b''\nstderr: b' Cannot use /dev/sdf: device is a multipath component\n Command requires all devices to be found.\n'\nadditional_info: None (58.64 s)
(17/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.nfs_source.specified_srcSpec: STARTED
(17/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.nfs_source.specified_srcSpec: PASS (55.37 s)
(18/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_source.specified_srcSpec: STARTED
(18/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_source.specified_srcSpec: PASS (71.99 s)
(19/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_direct_source.specified_srcSpec: STARTED
(19/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.iscsi_direct_source.specified_srcSpec: PASS (80.11 s)
(20/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.logical_source.specified_srcSpec: STARTED
(20/20) type_specific.io-github-autotest-libvirt.virsh.find_storage_pool_sources.positive_test.acl_test.remote_host.logical_source.specified_srcSpec: FAIL: vg_create failed: Command 'vgcreate virttest_vg_0 /dev/sdf' failed.\nstdout: b''\nstderr: b' Cannot use /dev/sdf: device is a multipath component\n Command requires all devices to be found.\n'\nadditional_info: None (39.89 s)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libvirt/tests/src/virsh_cmd/pool/virsh_find_storage_pool_sources.py`:
- Around line 156-161: polkit.cleanup() must be followed by a restart of the
storage daemon to avoid stale ACLs; update the cleanup block that calls
polkit.cleanup() to invoke virtstoraged.restart() (mirroring the setup path
where polkit.setup() and libvirtd.restart() were used), and ensure you catch/log
exceptions from both polkit.cleanup() and virtstoraged.restart() so failures are
reported.
- Around line 74-84: The restart failure for virtstoraged is only logged
currently, which hides deterministic setup failures on split-daemon hosts;
update the try/except around service.Factory.create_service("virtstoraged") /
virtstoraged.restart() to check utils_split_daemons.is_modular_daemon() and, if
that returns True and an exception occurs, re-raise a TestError (raise
TestError("Failed to restart virtstoraged: ...")) instead of merely logging;
otherwise keep the existing logging behavior. Ensure you reference the same
symbols: service.Factory.create_service, virtstoraged.restart,
utils_split_daemons.is_modular_daemon, and TestError when implementing the
change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e92805a8-ce4c-47fd-baa5-e11ea0460064

📥 Commits

Reviewing files that changed from the base of the PR and between c96ab65 and ffa703c.

📒 Files selected for processing (1)
  • libvirt/tests/src/virsh_cmd/pool/virsh_find_storage_pool_sources.py

Comment on lines +74 to +84
# Explicitly restart virtstoraged for storage driver ACL tests
# The libvirtd.restart() in polkit.setup() doesn't always restart virtstoraged
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:
logging.warning("Failed to restart virtstoraged: %s", svc_err)
logging.warning("This may cause ACL test failures for storage operations")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail fast when the required virtstoraged restart does not happen.

This restart is the core of the fix, but on split-daemon hosts a failure is only logged and the test continues with stale storage-daemon state. That turns a deterministic setup failure into a later ACL/socket failure with a less obvious cause. Gate this on utils_split_daemons.is_modular_daemon() and raise TestError if the restart fails there.

Suggested change
-            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:
-                logging.warning("Failed to restart virtstoraged: %s", svc_err)
-                logging.warning("This may cause ACL test failures for storage operations")
+            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
🧰 Tools
🪛 Ruff (0.15.12)

[warning] 82-82: Do not catch blind exception: Exception

(BLE001)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libvirt/tests/src/virsh_cmd/pool/virsh_find_storage_pool_sources.py` around
lines 74 - 84, The restart failure for virtstoraged is only logged currently,
which hides deterministic setup failures on split-daemon hosts; update the
try/except around service.Factory.create_service("virtstoraged") /
virtstoraged.restart() to check utils_split_daemons.is_modular_daemon() and, if
that returns True and an exception occurs, re-raise a TestError (raise
TestError("Failed to restart virtstoraged: ...")) instead of merely logging;
otherwise keep the existing logging behavior. Ensure you reference the same
symbols: service.Factory.create_service, virtstoraged.restart,
utils_split_daemons.is_modular_daemon, and TestError when implementing the
change.

Comment on lines +156 to +161
if polkit:
logging.info("Cleaning up polkit configuration")
try:
polkit.cleanup()
except Exception as e:
logging.warning("Failed to cleanup polkit: %s", e)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Restart virtstoraged after removing the polkit rules too.

The setup path explicitly restarts virtstoraged because polkit.setup()/libvirtd.restart() does not reliably refresh the storage daemon. polkit.cleanup() changes the same ACL state, so skipping the matching restart here can leak stale authorization state into later storage tests.

Suggested change
         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)
🧰 Tools
🪛 Ruff (0.15.12)

[warning] 160-160: Do not catch blind exception: Exception

(BLE001)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libvirt/tests/src/virsh_cmd/pool/virsh_find_storage_pool_sources.py` around
lines 156 - 161, polkit.cleanup() must be followed by a restart of the storage
daemon to avoid stale ACLs; update the cleanup block that calls polkit.cleanup()
to invoke virtstoraged.restart() (mirroring the setup path where polkit.setup()
and libvirtd.restart() were used), and ensure you catch/log exceptions from both
polkit.cleanup() and virtstoraged.restart() so failures are reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant