in linux/cuda_installer/os_installers/dnf_system.py [0:0]
def lock_kernel_updates(self):
"""Make sure no kernel updates are installed."""
logger.info("Attempting to update /etc/dnf/dnf.conf to block kernel updates.")
conf_parser = configparser.ConfigParser()
conf_parser.read("/etc/dnf/dnf.conf")
if "exclude" in conf_parser["main"]:
value = conf_parser["main"]["exclude"]
if "kernel*" in value:
logger.info("Kernel updates are already blocked in /etc/dnf/dnf.conf")
return
value = [s.strip() for s in value.split(",")]
value.append("kernel*")
else:
value = ["kernel*"]
conf_parser["main"]["exclude"] = ", ".join(value)
shutil.copyfile("/etc/dnf/dnf.conf", "/etc/dnf/dnf.conf_backup")
try:
with open("/etc/dnf/dnf.conf", mode="w") as dnf_conf_file:
conf_parser.write(dnf_conf_file)
except Exception as e:
logger.error(
"Failed to update /etc/dnf/dnf.conf due to {}. Restoring config file from backup.".format(
e
)
)
shutil.copyfile("/etc/dnf/dnf.conf_backup", "/etc/dnf/dnf.conf")
raise e
else:
logger.info(
"Kernel updates blocked by `exclude` entry in /etc/dnf/dnf.conf"
)