Skip to content

Commit

Permalink
NAS-130883 / 24.10-RC.1 / Make sure vm.query does not fail (by Qubad7…
Browse files Browse the repository at this point in the history
…86) (#14384)

* Make sure vm.query does not fail

(cherry picked from commit dfbf5da)

* Optimize getting counts of vms and pools in system

(cherry picked from commit e938d8b)

---------

Co-authored-by: M. Rehan <[email protected]>
  • Loading branch information
bugclerk and Qubad786 authored Aug 30, 2024
1 parent 1e34e38 commit 3d4a287
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/middlewared/middlewared/plugins/reporting/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from middlewared.service import accepts, Service
from middlewared.schema import Str, Dict, Int
from middlewared.utils.cpu import cpu_info
from middlewared.utils.zfs import query_imported_fast_impl

from .netdata import ClientConnectError, Netdata
from .utils import calculate_disk_space_for_netdata, get_metrics_approximation, TIER_0_POINT_SIZE, TIER_1_POINT_SIZE
Expand Down Expand Up @@ -52,8 +53,8 @@ def calculated_metrics_count(self):
len(self.middleware.call_sync('device.get_disks', False, True)),
cpu_info()['core_count'],
self.middleware.call_sync('interface.query', [], {'count': True}),
self.middleware.call_sync('zfs.pool.query', [], {'count': True}),
self.middleware.call_sync('vm.query', [], {'count': True}),
len(query_imported_fast_impl()),
self.middleware.call_sync('datastore.query', 'vm.vm', [], {'count': True}),
len(glob.glob('/sys/fs/cgroup/**/*.service')),
)

Expand Down
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 3d4a287

Please sign in to comment.