From a8edde3f24d73c00d79dac717b4b9d0f04b00573 Mon Sep 17 00:00:00 2001 From: Roxana Nicolescu Date: Fri, 22 May 2026 14:39:50 +0200 Subject: [PATCH] kt vm: Pin Rocky repos to vault to prevent minor version drift Without this, dnf resolves packages from the latest minor release instead of the one the image was built with. - Disable mirrorlist to stop dnf from redirecting to the latest minor version - Point baseurl to the Rocky vault where old minor versions are permanently hosted - Replace $releasever with the actual VERSION_ID from /etc/os-release to pin to the exact minor version - Clear dnf cache to force metadata refresh from the new vault URLs All of these were added in kt/data/cloud-init.yaml that is the base for all vms. When kt vm is run the first time for a kernel workspace, a copy of cloud-init.yaml is created. Use ruamel instead so that comments and the original formatting stays the same when the yaml file is read and then dump in python. Signed-off-by: Roxana Nicolescu --- kt/data/cloud_init.yaml | 18 +++++++++++++++--- kt/ktlib/vm.py | 11 ++++++++--- pyproject.toml | 3 ++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/kt/data/cloud_init.yaml b/kt/data/cloud_init.yaml index 77101c4..a132673 100644 --- a/kt/data/cloud_init.yaml +++ b/kt/data/cloud_init.yaml @@ -15,8 +15,14 @@ ssh_pwauth: true package_upgrade: False mounts: - - ["mount_tag_mock_scratch", "SHARED_DIR_PLACEHOLDER", "virtiofs", "rw,relatime,context=unconfined_u:object_r:mock_var_lib_t:s0"] - - ["SHARED_DIR_PLACEHOLDER", "/var/lib/mock", "bind", "defaults,bind"] + - - mount_tag_mock_scratch + - SHARED_DIR_PLACEHOLDER + - virtiofs + - rw,relatime,context=unconfined_u:object_r:mock_var_lib_t:s0 + - - SHARED_DIR_PLACEHOLDER + - /var/lib/mock + - bind + - defaults,bind # Change working directory after boot # Setting up homedir does not work without tricks, because @@ -32,4 +38,10 @@ write_files: # and then root is the owner # workaround to change the owner to user runcmd: - - [chown, USER_PLACEHOLDER:USER_PLACEHOLDER, HOMEDIR_PLACEHOLDER] + - - chown + - USER_PLACEHOLDER:USER_PLACEHOLDER + - HOMEDIR_PLACEHOLDER + - find /etc/yum.repos.d/ -iname "*.repo" -exec sed -i 's|^mirrorlist=|#mirrorlist=|g' {} \; + - find /etc/yum.repos.d/ -iname "*.repo" -exec sed -i 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://dl.rockylinux.org/vault/rocky|g' {} \; + - find /etc/yum.repos.d/ -iname "*.repo" -exec sed -i "s|\$releasever|$(. /etc/os-release && echo $VERSION_ID)|g" {} \; + - dnf clean all diff --git a/kt/ktlib/vm.py b/kt/ktlib/vm.py index e09de8d..83ddecd 100644 --- a/kt/ktlib/vm.py +++ b/kt/ktlib/vm.py @@ -5,10 +5,10 @@ import time from dataclasses import dataclass -import oyaml as yaml import wget from git import Repo from pathlib3x import Path +from ruamel.yaml import YAML from kt.ktlib.config import Config from kt.ktlib.kernel_workspace import KernelWorkspace @@ -157,9 +157,15 @@ def _download_source_image(self, override_base: bool = False): wget.download(self._get_vm_url(), out=str(self.qcow2_source_path)) def _setup_cloud_init(self, config: Config): + yaml = YAML() + yaml.preserve_quotes = True + yaml.width = 4096 + yaml.default_flow_style = False + yaml.best_sequence_indent = 2 + data = None with open(CLOUD_INIT_BASE_PATH) as f: - data = yaml.safe_load(f) + data = yaml.load(f) # replace placeholders with user data data["users"][0]["name"] = config.user @@ -189,7 +195,6 @@ def _setup_cloud_init(self, config: Config): data["runcmd"].append([str(config.base_path / Path("kernel-src-tree-tools") / Path("kernel_install_dep.sh"))]) # Write this to image cloud_init with open(self.cloud_init_path, "w") as f: - f.write("#cloud-config\n") yaml.dump(data, f) def _create_image(self, config: Config, vcpus: int = 12, memory: int = 32768): diff --git a/pyproject.toml b/pyproject.toml index 6a2805f..e52da21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,8 @@ dependencies = [ "click", "pathlib3x", "python3-wget", - "oyaml", + "ruamel.yaml", + "pyyaml", "pexpect", "jira", "requests",