@@ -2392,22 +2392,83 @@ def validate_pkg_consistency_req(
23922392 rhcos_build_id : str ,
23932393 package_rpm_finder = None ,
23942394 ) -> Optional [AssemblyIssue ]:
2395- """check that the specified package in the member is consistent with the RHCOS build"""
2395+ """
2396+ Check that the specified package in the member is consistent with the RHCOS build.
2397+
2398+ For Konflux builds, this also detects when multiple versions of the same package
2399+ are installed (e.g., two different kernel versions), which should never happen.
2400+ """
23962401 logger = bri .runtime .logger
23972402 payload_tag_nvr : str = bri .get_nvr ()
23982403 logger .debug (f"Checking consistency of { pkg } for { payload_tag_nvr } against { rhcos_build_id } " )
2399- member_nvrs : Dict [str , Dict ] = bri .get_all_installed_package_build_dicts (
2400- package_rpm_finder or self .package_rpm_finder
2401- ) # by name
2402- try :
2403- build = member_nvrs [pkg ]
2404- except KeyError :
2405- return AssemblyIssue (
2406- f"RHCOS consistency configuration specifies that payload tag '{ payload_tag } ' "
2407- f"should install package '{ pkg } ', but it does not" ,
2408- payload_tag ,
2409- AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2410- )
2404+
2405+ # For Konflux, get ALL installed package NVRs to detect duplicates
2406+ # For Brew, use the old method (only one version per package is expected)
2407+ if self .runtime .build_system == 'konflux' :
2408+ # Access the build record directly to get all installed packages
2409+ build_record = bri .get_build_obj () # Returns KonfluxBuildRecord
2410+ installed_packages = build_record .installed_packages # List of package NVRs
2411+
2412+ # Filter for packages matching the name we're checking
2413+ matching_packages = [pkg_nvr for pkg_nvr in installed_packages if parse_nvr (pkg_nvr )['name' ] == pkg ]
2414+
2415+ if not matching_packages :
2416+ return AssemblyIssue (
2417+ f"RHCOS consistency configuration specifies that payload tag '{ payload_tag } ' "
2418+ f"should install package '{ pkg } ', but it does not" ,
2419+ payload_tag ,
2420+ AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2421+ )
2422+
2423+ # Check if there are multiple versions of the same package installed
2424+ if len (matching_packages ) > 1 :
2425+ return AssemblyIssue (
2426+ f"Payload tag '{ payload_tag } ' has multiple versions of package '{ pkg } ' installed: "
2427+ f"{ ', ' .join (matching_packages )} . Only one version should be present." ,
2428+ payload_tag ,
2429+ AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2430+ )
2431+
2432+ # Get the single package build dict
2433+ pkg_finder = package_rpm_finder or self .package_rpm_finder
2434+ pkg_finder ._cache_packages (matching_packages )
2435+ build = pkg_finder ._packages_build_dicts [matching_packages [0 ]]
2436+
2437+ else : # Brew
2438+ # First, check for duplicate packages in Brew builds
2439+ # Although OSBS should enforce single versions, check to be safe
2440+ all_rpm_dicts = bri .get_all_installed_rpm_dicts ()
2441+ matching_package_nvrs = set ()
2442+ for rpm_dict in all_rpm_dicts :
2443+ rpm_nvr = rpm_dict ['nvr' ]
2444+ parsed = parse_nvr (rpm_nvr )
2445+ if parsed ['name' ] == pkg :
2446+ # Extract package NVR from RPM NVR (RPMs have arch suffix)
2447+ # e.g., kernel-5.14.0-427.116.1.el9_4.x86_64 -> kernel-5.14.0-427.116.1.el9_4
2448+ package_nvr = f"{ parsed ['name' ]} -{ parsed ['version' ]} -{ parsed ['release' ]} "
2449+ matching_package_nvrs .add (package_nvr )
2450+
2451+ if not matching_package_nvrs :
2452+ return AssemblyIssue (
2453+ f"RHCOS consistency configuration specifies that payload tag '{ payload_tag } ' "
2454+ f"should install package '{ pkg } ', but it does not" ,
2455+ payload_tag ,
2456+ AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2457+ )
2458+
2459+ if len (matching_package_nvrs ) > 1 :
2460+ return AssemblyIssue (
2461+ f"Payload tag '{ payload_tag } ' has multiple versions of package '{ pkg } ' installed: "
2462+ f"{ ', ' .join (sorted (matching_package_nvrs ))} . Only one version should be present." ,
2463+ payload_tag ,
2464+ AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2465+ )
2466+
2467+ # Get the build dict using the old method (now we know there's only one)
2468+ member_nvrs : Dict [str , Dict ] = bri .get_all_installed_package_build_dicts (
2469+ package_rpm_finder or self .package_rpm_finder
2470+ ) # by name
2471+ build = member_nvrs [pkg ] # We know this exists now
24112472
24122473 # get names of all the actual RPMs included in this package build, because that's what we
24132474 # have for comparison in the RHCOS metadata (not the package name).
0 commit comments