Skip to content

Commit

Permalink
Make sure vm.query does not fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 committed Aug 30, 2024
1 parent 6f33f42 commit dfbf5da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/middlewared/middlewared/plugins/vm/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def _check_connection_alive(self):
if not self._is_libvirt_connection_alive():
raise CallError('Failed to connect to libvirt')

def _check_setup_connection(self):
def _safely_check_setup_connection(self, timeout: int = 10):
if not self._is_connection_alive():
self.middleware.call_sync('vm.setup_libvirt_connection', 10)
self.middleware.call_sync('vm.setup_libvirt_connection', timeout)

def _check_setup_connection(self):
self._safely_check_setup_connection()
self._check_connection_alive()
6 changes: 4 additions & 2 deletions src/middlewared/middlewared/plugins/vm/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ def extend_context(self, rows, extra):
status = {}
kvm_supported = self._is_kvm_supported()
if rows and kvm_supported:
self._check_setup_connection()
self._safely_check_setup_connection(5)

libvirt_running = self._is_connection_alive()
for row in rows:
status[row['id']] = self.status_impl(row) if kvm_supported else get_default_status()
status[row['id']] = self.status_impl(row) if libvirt_running else get_default_status()

return {
'status': status,
Expand Down

0 comments on commit dfbf5da

Please sign in to comment.