Skip to content
Merged
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
24 changes: 24 additions & 0 deletions openrelik_worker_common/mount_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
["/usr/bin/grep", "-E", f"^{module}\\s", "/proc/modules"],
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.

Expand Down