Skip to content

Commit 4affc90

Browse files
committed
Use correct Copr chroot for 0-day Z-Streams
Signed-off-by: Nikola Forró <[email protected]>
1 parent 051d7e3 commit 4affc90

File tree

5 files changed

+48
-19
lines changed

5 files changed

+48
-19
lines changed

agents/tools/version_mapper.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ async def _run(
5858

5959
config = await load_rhel_config()
6060

61-
z_streams = config.get("current_z_streams", {})
62-
y_streams = config.get("current_y_streams", {})
61+
upcoming_z_streams = config.get("upcoming_z_streams", {})
62+
current_z_streams = config.get("current_z_streams", {})
63+
current_y_streams = config.get("current_y_streams", {})
6364

64-
y_stream = y_streams.get(major_version_str)
65-
z_stream = z_streams.get(major_version_str)
65+
y_stream = current_y_streams.get(major_version_str)
66+
# 0-day Z-Stream during stabilization phase, regular Z-Stream otherwise
67+
z_stream = upcoming_z_streams.get(major_version_str) or current_z_streams.get(major_version_str)
6668
is_maintenance_version = y_stream is None
6769

6870
return VersionMapperOutput(VersionMapperResult(

mcp_server/copr_tools.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from fastmcp.exceptions import ToolError
1414
from pydantic import BaseModel, Field
1515

16-
from common.utils import init_kerberos_ticket, KerberosError, is_cs_branch
16+
from common import load_rhel_config
17+
from common.utils import init_kerberos_ticket, KerberosError
1718
from common.validators import AbsolutePath
1819

1920
COPR_CONFIG = {
@@ -56,13 +57,22 @@ def read_header():
5657
return (COPR_ARCHES - exclude_arches) & exclusive_arches
5758

5859

59-
def _branch_to_chroot(dist_git_branch: str) -> str:
60-
m = re.match(r"^c(\d+)s|rhel-(\d+)-main|rhel-(\d+)\.\d+.*$", dist_git_branch)
61-
if not m:
60+
async def _branch_to_chroot(dist_git_branch: str) -> str:
61+
if not (m := re.match(r"^(?:c(\d+)s|rhel-(\d+)-main|rhel-(\d+)\.(\d+).*)$", dist_git_branch)):
6262
raise ValueError(f"Unsupported branch name: {dist_git_branch}")
63-
majorver = next(g for g in m.groups() if g is not None)
64-
# build only cNs against target with .dev suffix
65-
suffix = ".dev" if is_cs_branch(dist_git_branch) else ""
63+
majorver, minorver = m.group(1) or m.group(2) or m.group(3), m.group(4)
64+
rhel_config = await load_rhel_config()
65+
upcoming_z_streams = rhel_config.get("upcoming_z_streams", {})
66+
# build Y-Streams and 0-day Z-Streams against the dev chroot
67+
if minorver is not None:
68+
if (ver := upcoming_z_streams.get(majorver)) and ver.startswith(
69+
f"rhel-{majorver}.{minorver}"
70+
):
71+
suffix = ".dev"
72+
else:
73+
suffix = ""
74+
else:
75+
suffix = ".dev"
6676
return f"rhel-{majorver}{suffix}"
6777

6878

@@ -85,7 +95,7 @@ async def build_package(
8595
# in such case build for either of them
8696
build_arch = exclusive_arches.pop() if exclusive_arches else "x86_64"
8797
try:
88-
chroot = _branch_to_chroot(dist_git_branch) + f"-{build_arch}"
98+
chroot = (await _branch_to_chroot(dist_git_branch)) + f"-{build_arch}"
8999
except ValueError as e:
90100
raise ToolError(f"Failed to deduce Copr chroot: {e}") from e
91101
project_proxy = ProjectProxy({"username": copr_user, **COPR_CONFIG})

mcp_server/jira_tools.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,17 @@ async def check_cve_triage_eligibility(
229229
)
230230

231231
rhel_config = await load_rhel_config()
232+
upcoming_z_streams = rhel_config.get("upcoming_z_streams", {})
232233
current_z_streams = rhel_config.get("current_z_streams", {})
234+
latest_z_streams = current_z_streams | upcoming_z_streams
233235

234236
needs_internal_fix = False
235237
severity = fields.get(SEVERITY_CUSTOM_FIELD, {}).get("value", "")
236238

237-
# Check if z-stream is not in current z-streams - always needs internal fix
238-
if target_version.lower() not in [v.lower() for v in current_z_streams.values()]:
239+
# Check if z-stream is not in latest z-streams - always needs internal fix
240+
if target_version.lower() not in [v.lower() for v in latest_z_streams.values()]:
239241
needs_internal_fix = True
240-
reason = f"Z-stream CVE ({target_version}) not in current z-streams, needs RHEL fix first"
242+
reason = f"Z-stream CVE ({target_version}) not in latest z-streams, needs RHEL fix first"
241243
# Determine if internal fix is needed based on severity
242244
elif severity not in [Severity.LOW.value, Severity.MODERATE.value]:
243245
needs_internal_fix = True

mcp_server/tests/unit/test_copr.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,28 @@
2626
"exclusive_arch",
2727
[None, "ppc64le"],
2828
)
29+
@pytest.mark.parametrize(
30+
"dist_git_branch",
31+
["c10s", "rhel-10.1", "rhel-10.0"],
32+
)
2933
@pytest.mark.asyncio
30-
async def test_build_package(build_failure, exclusive_arch):
34+
async def test_build_package(build_failure, exclusive_arch, dist_git_branch):
3135
ownername = "jotnar-bot"
3236
srpm_path = Path("test.src.rpm")
33-
dist_git_branch = "c10s"
3437
jira_issue = "RHEL-12345"
35-
chroot = f"rhel-10.dev-{exclusive_arch or 'x86_64'}"
36-
existing_chroot = f"rhel-9.dev-{exclusive_arch or 'x86_64'}"
38+
suffix = "" if dist_git_branch == "rhel-10.0" else ".dev"
39+
chroot = f"rhel-10{suffix}-{exclusive_arch or 'x86_64'}"
40+
existing_chroot = "rhel-9.dev-x86_64"
3741

3842
async def init_kerberos_ticket():
3943
return f"{ownername}@EXAMPLE.COM"
4044

45+
async def load_rhel_config():
46+
return {
47+
"current_z_streams": {"10": "rhel-10.0.z"},
48+
"upcoming_z_streams": {"10": "rhel-10.1.z"},
49+
}
50+
4151
async def _get_exclusive_arches(*_):
4252
return {exclusive_arch} if exclusive_arch else set()
4353

@@ -46,6 +56,7 @@ async def sleep(*_):
4656
return
4757

4858
flexmock(copr_tools).should_receive("init_kerberos_ticket").replace_with(init_kerberos_ticket).once()
59+
flexmock(copr_tools).should_receive("load_rhel_config").replace_with(load_rhel_config).once()
4960
flexmock(copr_tools).should_receive("_get_exclusive_arches").replace_with(_get_exclusive_arches).once()
5061
flexmock(asyncio).should_receive("sleep").replace_with(sleep)
5162

templates/rhel-config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
},
66
"current_z_streams": {
77
"8": "rhel-8.10.z",
8+
"9": "rhel-9.6.z",
9+
"10": "rhel-10.0.z"
10+
},
11+
"upcoming_z_streams": {
812
"9": "rhel-9.7.z",
913
"10": "rhel-10.1.z"
1014
},

0 commit comments

Comments
 (0)