tooling/release-process/mass-rebuilds/mass_tag.py
Jesús De Los Reyes Larraga 9802566ec9
All checks were successful
/ test (push) Successful in 2s
Refactor mass rebuild scripts to use dynamic MASSREBUILDS config (#13425) (#13045)
This PR addresses ticket #13425 by centralizing the release configuration for the mass rebuild orchestration tools, establishing a single source of truth for future Fedora release cycles.

Previously, scripts like `find_failures.py` and `need_rebuild.py` relied on hardcoded variables (e.g., `rebuildid = 'f45'`) that required manual bumps in multiple files.

**Changes Made:**

* **Centralized Configuration:** Removed hardcoded variables from `find_failures.py` and `need_rebuild.py`. They now import the `MASSREBUILDS` dictionary from `mass_rebuilds_info.py` to pull `buildtag`, `desttag`, `epoch`, and `targets`.
* **Dynamic Resolution:** By default, scripts will now dynamically calculate and target the highest release version available in the dictionary.
* **Added CLI Flag:** Introduced a `--rebuildid` argument via `argparse` to allow operators to override the default and target specific older releases (e.g., `--rebuildid f44`).
* **Documentation:** Appended a usage section to the `README.md` detailing the new flag and the centralized configuration source.

**Testing Notes:**

* Verified the scripts parse arguments and load the dictionary correctly locally via `--help`.
* *Note:* The existing `test_mass_rebuild.py` test suite only covers the network retry mechanisms in `mass_rebuild.py` and does not currently mock or cover `find_failures.py` or `need_rebuild.py`.

**Resolves:** #13425

Reviewed-on: #13045
2026-09-08 04:54:25 +00:00

164 lines
5.4 KiB
Python
Executable file

#!/usr/bin/python3
#
# mass-tag.py - A utility to tag rebuilt packages.
#
# Copyright (C) 2009-2023 Red Hat, Inc.
# SPDX-License-Identifier: GPL-2.0+
#
# Authors:
# Jesse Keating <jkeating@redhat.com>
#
from __future__ import print_function
import koji
import operator
import argparse
import rpm
from mass_rebuilds_info import get_rebuild_config
def verify_tagged(kojisession, target, build_list):
"""Verify builds appear in target tag"""
missing = []
kojisession.multicall = True
for build in build_list:
kojisession.listTagged(target, package=build['package_name'])
results = kojisession.multiCall()
for build, mc_result in zip(build_list, results):
try:
[tagged_builds] = mc_result
if not any(b['nvr'] == build['nvr'] for b in tagged_builds):
missing.append(build['nvr'])
except (KeyError, IndexError, TypeError, ValueError):
print(f"ERROR: Verification failed for {build['nvr']}: {mc_result}")
missing.append(build['nvr'])
return missing
def main():
# Set up a parser with mass_tag's specific optional arguments
parser = argparse.ArgumentParser(description="Mass Tagging Tool")
parser.add_argument('-t', '--target', help='Tag to tag the builds into (overrides MASSREBUILDS)')
parser.add_argument('-s', '--source', help='Tag holding the builds (overrides MASSREBUILDS)')
# Pass the custom parser into our helper so --rebuildid gets added to the same help menu
current_rebuild = get_rebuild_config(parser=parser)
# Parse the arguments to extract the custom -t and -s values
args, _ = parser.parse_known_args()
# Assign variables with the dictionary acting as the fallback
target = args.target or current_rebuild['desttag']
holdingtag = args.source or current_rebuild['buildtag']
newbuilds = {}
# Create a koji session
koji_module = koji.get_profile_module("fedora")
kojisession = koji_module.ClientSession(koji_module.config.server)
# Log into koji
kojisession.gssapi_login()
# Permission Verification
def verify_tag_access(tag):
"""Check user has permission for target tag"""
user = kojisession.getUser()
tag_access_info = kojisession.checkTagAccess(tag, user["id"])
if tag_access_info[0] is False:
print(f"ERROR: User {user['name']} lacks {tag} access permission. Reason: {tag_access_info[2]}")
return False
else:
return True
if not verify_tag_access(target):
exit(1)
# Generate a list of builds to iterate over, sorted by package name
builds = sorted(kojisession.listTagged(holdingtag, latest=True),
key=operator.itemgetter('package_name'))
# Generate a list of packages in the target, reduced by not blocked.
pkgs = kojisession.listPackages(target, inherited=True)
pkgs = [pkg['package_name'] for pkg in pkgs if not pkg['blocked']]
print('Checking %s builds...' % len(builds))
# Use multicall
kojisession.multicall = True
# Loop over each build
for build in builds:
# Get the latest tagged package in the target
kojisession.listTagged(target, latest=True, package=build['package_name'])
# Get the results
results = kojisession.multiCall()
# Find builds that are newer in the target tag
kojisession.multicall = True
for build, [result] in zip(builds, results):
if not build['package_name'] in pkgs:
continue
for newbuild in result:
evr1 = (str(build['epoch'] or ''), build['version'], build['release'])
evr2 = (str(newbuild['epoch'] or ''), newbuild['version'], newbuild['release'])
if rpm.labelCompare(evr1, evr2) == -1:
newbuilds.setdefault(build['package_name'], []).append(newbuild)
requests = kojisession.multiCall()
# Loop through the results and tag if necessary
kojisession.multicall = True
all_tagged_builds = []
taglist = []
all_taglist = []
pkgcount = 0
for build in builds:
if not build['package_name'] in pkgs:
print('Skipping %s, blocked in %s' % (build['package_name'], target))
continue
if build['package_name'] in newbuilds:
print('Newer build found for %s.' % build['package_name'])
else:
print('Tagging %s into %s' % (build['nvr'], target))
taglist.append(build['nvr'])
all_tagged_builds.append(build)
pkgcount += 1
if pkgcount == 1000:
print('Tagging %s builds.' % pkgcount)
kojisession.massTag(target, taglist)
all_taglist.append(taglist)
results = kojisession.multiCall()
pkgcount = 0
taglist = []
kojisession.multicall = True
kojisession.massTag(target, taglist)
results = kojisession.multiCall()
# Final verification
print("\nFinal verification for {0} builds...".format(len(all_tagged_builds)))
missing = verify_tagged(kojisession, target, all_tagged_builds)
if missing:
print(f"ERROR: {len(missing)} builds not in {target}:")
for nvr in missing:
print(f" - {nvr}")
exit(1)
else:
print(f"SUCCESS: All {len(all_tagged_builds)} builds verified in {target}")
print(f'Total tagged builds: {len(taglist)}')
if __name__ == '__main__':
main()