Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-130883 / 24.10-RC.1 / Make sure vm.query does not fail (by Qubad786) #14384

Merged
merged 2 commits into from
Aug 30, 2024
Merged
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
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
Loading