From fe6d1f92ca880d038b64aa03d79e1c0bcb03aeac Mon Sep 17 00:00:00 2001 From: rgayon Date: Wed, 12 Nov 2025 13:42:54 +0000 Subject: [PATCH 1/2] Add kernel module check --- openrelik_worker_common/mount_utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/openrelik_worker_common/mount_utils.py b/openrelik_worker_common/mount_utils.py index b86dede..6765a20 100644 --- a/openrelik_worker_common/mount_utils.py +++ b/openrelik_worker_common/mount_utils.py @@ -102,6 +102,9 @@ def setup(self): # Check if required tools are available self._required_tools_available() + # Check the required kernel modules are available + self._required_modules_loaded() + # Setup the block device ext = image_path.suffix.strip(".") if ext.lower() in self.supported_qcowtypes: @@ -256,6 +259,27 @@ def _nbdsetup(self): return self.blkdevice + def _required_modules_loaded(self) -> None: + """Checks if a required kernel module is loaded. + + The following modules are checked: + * nbd (For mounting qcow disk images) + + Raises: + RuntimeError: as soon as we find a module that isn't loaded. + """ + + for module in ['nbd']: + try: + subprocess.check_call( + ["/sbin/modinfo", module], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + except subprocess.CalledProcessError: + raise RuntimeError( + f"Required kernel module {module} is not loaded. " + f"Load it with '/sbin/modprobe {module}' on the Host.") + def _required_tools_available(self) -> bool: """Check if required cli tools are available. From f53288681288b9c0e2927635eda6a0484c548393 Mon Sep 17 00:00:00 2001 From: rgayon Date: Wed, 12 Nov 2025 14:04:36 +0000 Subject: [PATCH 2/2] do modules instead --- openrelik_worker_common/mount_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openrelik_worker_common/mount_utils.py b/openrelik_worker_common/mount_utils.py index 6765a20..20ac659 100644 --- a/openrelik_worker_common/mount_utils.py +++ b/openrelik_worker_common/mount_utils.py @@ -269,10 +269,10 @@ def _required_modules_loaded(self) -> None: RuntimeError: as soon as we find a module that isn't loaded. """ - for module in ['nbd']: + for module in ["nbd"]: try: subprocess.check_call( - ["/sbin/modinfo", module], + ["/usr/bin/grep", "-E", f"^{module}\\s", "/proc/modules"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) except subprocess.CalledProcessError: