Skip to content

Commit 10dde08

Browse files
authored
Merge pull request #352 from desultory/nokmod
improve logging/checks for no_kmod systems
2 parents 00b8fd3 + 3fe7633 commit 10dde08

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/ugrd/kmod/kmod.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,28 @@ def _get_kver_from_header(self) -> str:
315315

316316

317317
def _process_kernel_version(self, kver: str) -> None:
318-
"""Sets the kerenl_version, checks that the kmod directory exits, sets the _kmod_dir variable."""
318+
"""Sets the kerenl_version, checks that the kmod directory exits, sets the _kmod_dir variable.
319+
If no_kmod is set, logs a warning because no_kmod will skip kmod functions later.
320+
321+
If the kmod directory does not exist, and no_kmod is not set, raises a ValidationError.
322+
If there is no /lib/modules directory, assumes 'no_kmod' is true and logs a critical error.
323+
"""
319324
if self["no_kmod"]:
320-
self.logger.error("kernel_version is set, but no_kmod is enabled.")
325+
# Log a warning is no_kmod is already set, but a kver is passed. Check it anyways
326+
self.logger.warning("kernel_version is set, but no_kmod is enabled.")
327+
328+
# Checks that the kmod directoty exists for the kernel version
321329
kmod_dir = Path("/lib/modules") / kver
322330
if not kmod_dir.exists():
331+
# If no_kmod is set, log a warning and continue
323332
if self["no_kmod"]:
324-
return self.logger.warning("[%s] Kernel module directory does not exist, but no_kmod is set." % kver)
333+
return self.logger.warning("[%s] Kernel module directory does not exist, but no_kmod is set, continuing." % kver)
334+
elif not Path("/lib/modules").exists(): # If /lib/modules doesn't exist, assume no_kmod is true because no kmods are installed
335+
self.logger.critical(f"/lib/modules directory does not exist, assuming {c_('no_kmod', 'blue')}=true.")
336+
self["no_kmod"] = True
337+
return
338+
339+
# If there are other kernel versions available, log them for the user
325340
self.logger.error(f"Available kernel versions: {', '.join([d.name for d in Path('/lib/modules').iterdir()])}")
326341
self.logger.info(
327342
"If kernel modules are not installed, and not required, set `no_kmod = true` to skip this check."

0 commit comments

Comments
 (0)