Skip to content
Open
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions kt/data/kernels.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
common_repos:
dist-git-tree-fips: git@gitlab.com:ctrl-iq-public/fips/src/kernel.git
dist-git-tree-rlc: git@gitlab.com:ctrl-iq-public/sig-cloud-next/next/src/kernel.git
kernel-src-tree: https://github.com/ctrliq/kernel-src-tree.git
kernel-src-tree-tools: https://github.com/ctrliq/kernel-src-tree-tools.git

kernels:
cbr-7.9:
kernel_type: lts
src_tree_root: kernel-src-tree
src_tree_branch: ciqcbr7_9
dist_git_root: dist-git-tree-cbr
Expand All @@ -13,6 +15,7 @@ kernels:
automated: true

lts-8.6:
kernel_type: lts
src_tree_root: kernel-src-tree
src_tree_branch: ciqlts8_6
dist_git_root: dist-git-tree-lts
Expand All @@ -21,6 +24,7 @@ kernels:
automated: true

lts-9.2:
kernel_type: lts
src_tree_root: kernel-src-tree
src_tree_branch: ciqlts9_2
dist_git_root: dist-git-tree-lts
Expand All @@ -29,6 +33,7 @@ kernels:
automated: true

lts-9.6:
kernel_type: lts
src_tree_root: kernel-src-tree
src_tree_branch: ciqlts9_6
dist_git_root: dist-git-tree-lts
Expand All @@ -37,9 +42,34 @@ kernels:
automated: true

fipslegacy-8.6:
kernel_type: lts
src_tree_root: kernel-src-tree
src_tree_branch: fips-legacy-8-compliant/4.18.0-425.13.1
dist_git_root: dist-git-tree-fips
dist_git_branch: fips-compliant8
mock_config: rocky-lts86-fips
automated: false
rlc-8:
kernel_type: rlc
src_tree_root: kernel-src-tree
src_tree_branch: rlc-8/4.18.0-553.X.Y.el8_10
dist_git_root: dist-git-tree-rlc
dist_git_branch: next-r8
mock_config: rocky-8-sigcloud
automated: false
rlc-9:
kernel_type: rlc
src_tree_root: kernel-src-tree
src_tree_branch: rlc-9/5.14.0-611.X.Y.el9_7
dist_git_root: dist-git-tree-rlc
dist_git_branch: next-r9
mock_config: rocky-9-sigcloud
automated: false
rlc-10:
kernel_type: rlc
src_tree_root: kernel-src-tree
src_tree_branch: rlc-10/6.12.0-124.X.Y.el10_1
dist_git_root: dist-git-tree-rlc
dist_git_branch: next-r10
mock_config: rocky-10-sigcloud
automated: false
39 changes: 38 additions & 1 deletion kt/ktlib/kernel_workspace.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging
import re
from dataclasses import dataclass

from git import GitCommandError, Repo
from pathlib3x import Path

from kt.ktlib.config import Config
from kt.ktlib.kernels import KernelInfo
from kt.ktlib.kernels import KernelInfo, KernelType
from kt.ktlib.util import Constants


Expand All @@ -16,6 +17,7 @@ class RepoWorktree:
remote: str
remote_branch: str
local_branch: str
kernel_type: KernelType

@classmethod
def load_from_filepath(cls, folder: Path):
Expand All @@ -32,12 +34,18 @@ def load_from_filepath(cls, folder: Path):

local_branch = repo.active_branch.name

if KernelType.RLC in str(folder.absolute()):
kernel_type = KernelType.RLC
else:
kernel_type = KernelType.LTS

return cls(
source_root=source_root,
folder=folder,
remote=remote,
remote_branch=remote_branch,
local_branch=local_branch,
kernel_type=kernel_type,
)

def setup(self):
Expand Down Expand Up @@ -72,6 +80,10 @@ def update(self):
"""
logging.info("update")
repo = Repo(self.folder)
if self.kernel_type == KernelType.RLC:
if repo.active_branch.name != self.local_branch:
print(f"New RLC version from {repo.active_branch.name} to {self.local_branch}")
repo.git.checkout(self.local_branch)
Comment thread
roxanan1996 marked this conversation as resolved.
Comment thread
roxanan1996 marked this conversation as resolved.

repo.remotes.origin.pull(rebase=True)

Expand Down Expand Up @@ -184,8 +196,15 @@ def load(cls, name: str, config: Config, kernel_info: KernelInfo, extra: str):
remote=default_remote,
remote_branch=kernel_info.dist_git_branch,
local_branch=dist_local_branch,
kernel_type=kernel_info.kernel_type,
)

if kernel_info.kernel_type == KernelType.RLC:
print(f"{kernel_info.src_tree_branch}")
kernel_info.src_tree_branch = cls._get_newest_remote_branch(
folder=kernel_info.src_tree_root.folder, pattern=kernel_info.src_tree_branch
)
Comment thread
roxanan1996 marked this conversation as resolved.
Comment thread
roxanan1996 marked this conversation as resolved.

src_folder = folder / Path(Constants.SRC_TREE)
src_local_branch = f"{{{user}}}_{kernel_info.src_tree_branch}"
if extra:
Expand All @@ -197,6 +216,7 @@ def load(cls, name: str, config: Config, kernel_info: KernelInfo, extra: str):
remote=default_remote,
remote_branch=kernel_info.src_tree_branch,
local_branch=src_local_branch,
kernel_type=kernel_info.kernel_type,
)

return cls(
Expand All @@ -205,6 +225,23 @@ def load(cls, name: str, config: Config, kernel_info: KernelInfo, extra: str):
src_worktree=src_worktree,
)

def _get_newest_remote_branch(folder, pattern, remote="origin"):
regex = re.compile("^" + re.escape(pattern).replace("X", r"(\d+)").replace("Y", r"(\d+)") + "$")

repo = Repo(folder)
best = None # (X, Y, ref_name)

for ref in repo.remote(remote).refs:
short = ref.name.split("/", 1)[1] # strip "origin/"
m = regex.match(short)
if not m:
continue
x, y = int(m.group(1)), int(m.group(2))
if best is None or (x, y) > (best[0], best[1]):
best = (x, y, short)

return best[2] if best else None
Comment thread
roxanan1996 marked this conversation as resolved.
Comment thread
roxanan1996 marked this conversation as resolved.

def setup(self):
# Make sure the folder is created
self.folder.mkdir(parents=True, exist_ok=True)
Expand Down
7 changes: 7 additions & 0 deletions kt/ktlib/kernels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from dataclasses import dataclass
from enum import StrEnum, auto
Comment thread
roxanan1996 marked this conversation as resolved.

Comment on lines 1 to 4
import yaml
from pathlib3x import Path
Expand All @@ -12,6 +13,11 @@
KERNEL_INFO_YAML_PATH = Path(__file__).parent.parent.joinpath("data/kernels.yaml")


class KernelType(StrEnum):
LTS = auto()
RLC = auto()


@dataclass
class KernelInfo:
"""
Expand All @@ -28,6 +34,7 @@ class KernelInfo:
"""

name: str
kernel_type: KernelType

Comment thread
roxanan1996 marked this conversation as resolved.
src_tree_root: RepoInfo
src_tree_branch: str
Expand Down
1 change: 1 addition & 0 deletions kt/ktlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Constants:
KERNELS = "kernels"

BASE_URL = "https://dl.rockylinux.org/vault/rocky"
BASE_URL_RLC = "https://download.rockylinux.org/pub/rocky"
QCOW2_TRAIL = "GenericCloud.latest.x86_64.qcow2"
DEFAULT_VM_BASE = "Rocky"

Expand Down
8 changes: 7 additions & 1 deletion kt/ktlib/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from kt.ktlib.config import Config
from kt.ktlib.kernel_workspace import KernelWorkspace
from kt.ktlib.kernels import KernelType
from kt.ktlib.local import LocalCommand
from kt.ktlib.ssh import SshCommand
from kt.ktlib.util import Constants
Expand Down Expand Up @@ -140,7 +141,12 @@ def setup_and_spinup(
return vm_instance

def _get_vm_url(self):
return f"{Constants.BASE_URL}/{self.vm_major_minor_version}/images/x86_64/{Constants.DEFAULT_VM_BASE}-{self.vm_major_version}-{Constants.QCOW2_TRAIL}"
if KernelType.RLC in self.name:
base_url = Constants.BASE_URL_RLC
else:
base_url = Constants.BASE_URL
Comment thread
roxanan1996 marked this conversation as resolved.
Comment thread
roxanan1996 marked this conversation as resolved.

return f"{base_url}/{self.vm_major_minor_version}/images/x86_64/{Constants.DEFAULT_VM_BASE}-{self.vm_major_version}-{Constants.QCOW2_TRAIL}"

def _download_source_image(self, override_base: bool = False):
if self.qcow2_source_path.exists() and not override_base:
Expand Down
1 change: 1 addition & 0 deletions tests/kt/ktlib/test_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dist_git_branch": "dist-branch",
"mock_config": "test-mock-config",
"automated": True,
"kernel_type": "lts",
}
}

Expand Down