@@ -2392,22 +2392,86 @@ 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 = [
2414+ pkg_nvr for pkg_nvr in installed_packages
2415+ if parse_nvr (pkg_nvr )['name' ] == pkg
2416+ ]
2417+
2418+ if not matching_packages :
2419+ return AssemblyIssue (
2420+ f"RHCOS consistency configuration specifies that payload tag '{ payload_tag } ' "
2421+ f"should install package '{ pkg } ', but it does not" ,
2422+ payload_tag ,
2423+ AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2424+ )
2425+
2426+ # Check if there are multiple versions of the same package installed
2427+ if len (matching_packages ) > 1 :
2428+ return AssemblyIssue (
2429+ f"Payload tag '{ payload_tag } ' has multiple versions of package '{ pkg } ' installed: "
2430+ f"{ ', ' .join (matching_packages )} . Only one version should be present." ,
2431+ payload_tag ,
2432+ AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2433+ )
2434+
2435+ # Get the single package build dict
2436+ pkg_finder = package_rpm_finder or self .package_rpm_finder
2437+ pkg_finder ._cache_packages (matching_packages )
2438+ build = pkg_finder ._packages_build_dicts [matching_packages [0 ]]
2439+
2440+ else : # Brew
2441+ # First, check for duplicate packages in Brew builds
2442+ # Although OSBS should enforce single versions, check to be safe
2443+ all_rpm_dicts = bri .get_all_installed_rpm_dicts ()
2444+ matching_package_nvrs = set ()
2445+ for rpm_dict in all_rpm_dicts :
2446+ rpm_nvr = rpm_dict ['nvr' ]
2447+ parsed = parse_nvr (rpm_nvr )
2448+ if parsed ['name' ] == pkg :
2449+ # Extract package NVR from RPM NVR (RPMs have arch suffix)
2450+ # e.g., kernel-5.14.0-427.116.1.el9_4.x86_64 -> kernel-5.14.0-427.116.1.el9_4
2451+ package_nvr = f"{ parsed ['name' ]} -{ parsed ['version' ]} -{ parsed ['release' ]} "
2452+ matching_package_nvrs .add (package_nvr )
2453+
2454+ if not matching_package_nvrs :
2455+ return AssemblyIssue (
2456+ f"RHCOS consistency configuration specifies that payload tag '{ payload_tag } ' "
2457+ f"should install package '{ pkg } ', but it does not" ,
2458+ payload_tag ,
2459+ AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2460+ )
2461+
2462+ if len (matching_package_nvrs ) > 1 :
2463+ return AssemblyIssue (
2464+ f"Payload tag '{ payload_tag } ' has multiple versions of package '{ pkg } ' installed: "
2465+ f"{ ', ' .join (sorted (matching_package_nvrs ))} . Only one version should be present." ,
2466+ payload_tag ,
2467+ AssemblyIssueCode .FAILED_CONSISTENCY_REQUIREMENT ,
2468+ )
2469+
2470+ # Get the build dict using the old method (now we know there's only one)
2471+ member_nvrs : Dict [str , Dict ] = bri .get_all_installed_package_build_dicts (
2472+ package_rpm_finder or self .package_rpm_finder
2473+ ) # by name
2474+ build = member_nvrs [pkg ] # We know this exists now
24112475
24122476 # get names of all the actual RPMs included in this package build, because that's what we
24132477 # have for comparison in the RHCOS metadata (not the package name).
0 commit comments