Get the RRS update scripts working again
cover Get the RRS update scripts working again
The RRS data on layers.openembedded.org has not been updated for a long
time: in a copy of its database the latest upstream history is 2024-12-28 and the latest recipe upgrade 2025-06-16, so every milestone since 5.3 M1 shows 0%. These fix the problems that stopped each RRS script, found by running them on a test instance loaded with that database copy (layers.moto-timo.net).
1: Bug 16499: every RRS script crashed at startup in the Docker image,
where TOOLS_LOG_DIR is empty.
2: Bug 16501: load_recipes() imported bb.fetch before init_parser() had
checked out the right BitBake revision.
3: Bug 16500: upgrade history hung for ever on the OE-Core commit that
changed the addfragments syntax (8dca5305); use a BitBake from before that change for older commits.
4: Bug 16502: upstream history and distros parsed each layer at
whatever branch the layer index update had left it on (e.g. meta-openembedded at dunfell), so most of its recipes failed to parse.
5: Bug 16504: upgrade history hung on OE-Core 3c00ad5d3b, the one
commit where OEEquivHash is the default but BB_HASHSERVE is not set. Parsing doesn't need hash equivalence, so use OEBasicHash.
6: Bug 16506: rrs_distros.py failed on the second layer branch, because
OE-Core's distro_check leaves the build's PATH in the environment.
With these on the test instance, upgrade history has caught up on OE-Core and meta-intel, upstream history has run for all eight layer branches (0 recipes that couldn't be parsed, against 2051 before), and rrs_distros.py has completed for all eight. The test suite passes in the Docker image.
rrs_distros.py also needs the OE-Core distro_check fixes for bug 16503, sent separately to openembedded-core:
https://lore.kernel.org/all/[email protected]/
Tim Orling (6):
rrs/tools/common.py: don't write a log file without TOOLS_LOG_DIR rrs/tools/common.py: import BitBake after checking out its revision
rrs_upgrade_history: use the right BitBake around the 2025 fragments
change
rrs/tools/common.py: check out the layer branch before parsing it conf/local.conf: use OEBasicHash for parsing
rrs_distros: keep the environment when fetching distro package lists
conf/local.conf | 4 ++ docker/settings.py | 2 +- rrs/tools/common.py | 49 ++++++++++++++++--- rrs/tools/rrs_distros.py | 5 +- rrs/tools/rrs_upgrade_history.py | 32 ++++++++++--- settings.py | 2 +- tests/test_rrs_distros_environ.py | 45 +++++++++++++++++ tests/test_rrs_load_recipes.py | 80 +++++++++++++++++++++++++++++++ tests/test_rrs_logger.py | 38 +++++++++++++++ tests/test_rrs_upgrade_history.py | 43 +++++++++++++++++ 10 files changed, 282 insertions(+), 18 deletions(-) create mode 100644 tests/test_rrs_distros_environ.py create mode 100644 tests/test_rrs_load_recipes.py create mode 100644 tests/test_rrs_logger.py create mode 100644 tests/test_rrs_upgrade_history.py
Signature · 1 line
2.56.1
PATCH 1/6 rrs/tools/common.py: don't write a log file without TOOLS_LOG_DIR
get_logger() always added a log file at TOOLS_LOG_DIR/<name>, but TOOLS_LOG_DIR is empty by default, so the file was created in the current directory. In the Docker image that is /opt/layerindex, which the layers user can't write to, so every RRS update script failed as soon as it started. Only log to the console when TOOLS_LOG_DIR is not set.
[YOCTO #16499]
AI-Generated: Claude Opus 5.5
--- docker/settings.py | 2 +- rrs/tools/common.py | 16 ++++++++++------ settings.py | 2 +- tests/test_rrs_logger.py | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 tests/test_rrs_logger.py
docker/settings.py +1 -1
@@ -309,7 +309,7 @@ AXES_COOLOFF_TIME = 1 # Full path to directory to store logs for dynamically executed tasks TASK_LOG_DIR = "/opt/layerindex-task-logs" -# Full path to directory where rrs tools stores logs +# Full path to a directory where the rrs tools also write their logs, if any TOOLS_LOG_DIR = "" USE_X_FORWARDED_HOST = True
rrs/tools/common.py +10 -6
@@ -34,12 +34,16 @@ def get_logger(name, settings): handler.setFormatter(formatter) logger.addHandler(handler) - filename = os.path.join(settings.TOOLS_LOG_DIR, name) - maxBytes = 8388608 # 8MB - handler = RotatingFileHandler(filename, maxBytes=maxBytes) - - handler.setFormatter(formatter) - logger.addHandler(handler) + # Also log to a file if a directory is set for it; otherwise the console + # output is all there is (as collected by cron, systemd or docker) + log_dir = getattr(settings, 'TOOLS_LOG_DIR', '') + if log_dir: + filename = os.path.join(log_dir, name) + maxBytes = 8388608 # 8MB + handler = RotatingFileHandler(filename, maxBytes=maxBytes) + + handler.setFormatter(formatter) + logger.addHandler(handler) logger.setLevel(logging.INFO)
settings.py +1 -1
@@ -298,5 +298,5 @@ AXES_COOLOFF_TIME = 1 # Full path to directory to store logs for dynamically executed tasks TASK_LOG_DIR = "/tmp/layerindex-task-logs" -# Full path to directory where rrs tools stores logs +# Full path to a directory where the rrs tools also write their logs, if any TOOLS_LOG_DIR = ""
tests/test_rrs_logger.py new file +38 -0
@@ -0,0 +1,38 @@ +# layerindex-web - tests for the RRS tools' logger +# +# Licensed under the MIT license, see COPYING.MIT for details +# +# SPDX-License-Identifier: MIT + +import logging +import os +import sys +import types + +import pytest + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'rrs', 'tools')) +from common import get_logger + + [email protected] +def readonly_cwd(tmp_path, monkeypatch): + os.chmod(tmp_path, 0o555) + monkeypatch.chdir(tmp_path) + yield tmp_path + os.chmod(tmp_path, 0o755) + + +def test_no_log_file_without_tools_log_dir(readonly_cwd): + # [YOCTO #16499] the scripts run in a directory they can't write to + logger = get_logger('RRSTestNoDir', types.SimpleNamespace(TOOLS_LOG_DIR='')) + assert not [h for h in logger.handlers if isinstance(h, logging.FileHandler)] + assert os.listdir(readonly_cwd) == [] + + +def test_log_file_in_tools_log_dir(tmp_path): + logger = get_logger('RRSTestDir', types.SimpleNamespace(TOOLS_LOG_DIR=str(tmp_path))) + logger.info('hello') + for h in logger.handlers: + h.flush() + assert 'hello' in (tmp_path / 'RRSTestDir').read_text()
Signature · 1 line
2.56.1
PATCH 2/6 rrs/tools/common.py: import BitBake after checking out its revision
In reply to Tim Orlingload_recipes() imported bb.fetch before recipeparse.init_parser() checks out the BitBake revision for the branch, so the bb package came from whichever revision was checked out before, e.g. an old one left by rrs_upgrade_history.py, while the rest of BitBake came from the new one. rrs_upstream_history.py then failed with "cannot import name 'multiprocessing' from 'bb'". Import it after init_parser().
[YOCTO #16501]
AI-Generated: Claude Opus 5.5
--- rrs/tools/common.py | 4 +++- tests/test_rrs_load_recipes.py | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/test_rrs_load_recipes.py
rrs/tools/common.py +3 -1
@@ -93,7 +93,6 @@ def get_recipe_files(layerdir): def load_recipes(layerbranch, bitbakepath, fetchdir, settings, logger, recipe_files=None, nocheckout=False): from layerindex import recipeparse - from bb.fetch import FetchError try: (tinfoil, tempdir) = recipeparse.init_parser(settings,
@@ -102,6 +101,9 @@ def load_recipes(layerbranch, bitbakepath, fetchdir, settings, logger, except recipeparse.RecipeParseError as e: logger.error(str(e)) sys.exit(1) + # Only now that init_parser() has checked out the BitBake revision for the + # branch, or bb would be loaded from whichever one was checked out before + from bb.fetch import FetchError layer = layerbranch.layer urldir = str(layer.get_fetch_dir())
tests/test_rrs_load_recipes.py new file +35 -0
@@ -0,0 +1,35 @@ +# layerindex-web - tests for load_recipes() in rrs/tools/common.py +# +# Licensed under the MIT license, see COPYING.MIT for details +# +# SPDX-License-Identifier: MIT + +import os +import sys +import types + +import pytest + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'rrs', 'tools')) + + +def test_load_recipes_checks_out_bitbake_before_importing_it(monkeypatch): + # [YOCTO #16501] bb must come from the revision init_parser() checks out + import common + # As common_setup() does for the scripts: recipeparse imports utils + monkeypatch.syspath_prepend(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'layerindex')) + from layerindex import recipeparse + + class Stop(Exception): + pass + + def fake_init_parser(*args, **kwargs): + assert 'bb.fetch' not in sys.modules + raise Stop() + + for name in [m for m in sys.modules if m == 'bb' or m.startswith('bb.')]: + monkeypatch.delitem(sys.modules, name) + monkeypatch.setattr(recipeparse, 'init_parser', fake_init_parser) + with pytest.raises(Stop): + common.load_recipes(types.SimpleNamespace(branch=None), '/nonexistent', '/nonexistent', + types.SimpleNamespace(), None)
Signature · 1 line
2.56.1
PATCH 3/6 rrs_upgrade_history: use the right BitBake around the 2025 fragments change
In reply to Tim OrlingBitBake 3b9d7bea9 ("parse/ast: add support for 'built-in' fragments", 2025-06-18) changed the addfragments syntax, which OE-Core only followed in e959f916b4 (2025-06-20). The OE-Core commits in between got that BitBake, could not be parsed with it, and the BitBake server then waited for ever, so the upgrade history never got past them.
Use the BitBake revision before the change for those commits. The table of BitBake ranges to replace only matched on the BitBake revision, so let an entry apply only to commits before a given date, since OE-Core commits from e959f916b4 on need the new revision.
[YOCTO #16500]
AI-Generated: Claude Opus 5.5
--- rrs/tools/rrs_upgrade_history.py | 32 ++++++++++++++++++----- tests/test_rrs_upgrade_history.py | 43 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 tests/test_rrs_upgrade_history.py
rrs/tools/rrs_upgrade_history.py +25 -7
@@ -16,7 +16,7 @@ import sys import os.path import optparse import logging -from datetime import date, datetime, timedelta +from datetime import date, datetime, timedelta, timezone sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__)))) from common import common_setup, get_logger
@@ -42,6 +42,16 @@ bitbakepath = os.path.join(fetchdir, bitbakeitem.get_fetch_dir()) if getattr(settings, 'BITBAKE_PATH', ''): bitbakepath = os.path.join(bitbakepath, settings.BITBAKE_PATH) +def remapped_bitbake_rev(bitbake_rev, commitdate, bitbake_map, logger): + """The bitbake revision to use for a layer commit made at commitdate + (local time), given the latest bitbake revision before it""" + check_rev, until = bitbake_map.get(bitbake_rev, (None, None)) + # until is timezone-aware, so compare as timestamps + if check_rev and (until is None or commitdate.timestamp() < until.timestamp()): + logger.debug('Preferring bitbake revision %s over %s' % (check_rev, bitbake_rev)) + return check_rev + return bitbake_rev + def run_internal(maintplanlayerbranch, commit, commitdate, options, logger, bitbake_map, initial=False): from layerindex.models import PythonEnvironment from rrs.models import Release
@@ -63,10 +73,7 @@ def run_internal(maintplanlayerbranch, commit, commitdate, options, logger, bitb bitbake_rev = utils.runcmd(['git', 'rev-list', '-1', '--before=%s' % str(commitdate), 'origin/master'], bitbakepath, logger=logger) - check_rev = bitbake_map.get(bitbake_rev, None) - if check_rev: - logger.debug('Preferring bitbake revision %s over %s' % (check_rev, bitbake_rev)) - bitbake_rev = check_rev + bitbake_rev = remapped_bitbake_rev(bitbake_rev, commitdate, bitbake_map, logger) cmd = '%s upgrade_history_internal.py %s %s' % (cmdprefix, maintplanlayerbranch.layerbranch.id, commit) if initial:
@@ -174,7 +181,10 @@ def upgrade_history(options, logger): commit_list = commits.split('\n') bitbake_map = {} - def remap_range(start, end, replacewith=None): + def remap_range(start, end, replacewith=None, until=None): + """Use replacewith (by default end) instead of the + bitbake revisions from start up to end, for layer + commits before until (all if None)""" if replacewith is None: replacewith = end bitbake_commits = utils.runcmd(['git', 'rev-list', '%s^..%s^' % (start, end)],
@@ -182,12 +192,20 @@ def upgrade_history(options, logger): logger=logger) bitbake_commit_list = bitbake_commits.splitlines() for commit in bitbake_commit_list: - bitbake_map[commit] = replacewith + bitbake_map[commit] = (replacewith, until) # Filter out some bad commits remap_range('fef18b445c0cb6b266cd939b9c78d7cbce38663f', '39780b1ccbd76579db0fc6fb9369c848a3bafa9d') remap_range('5796ed550d127853808f38257f8dcc8c1cf59342', '547128731e62b36d2271c4390b3fee2b16c535dc') remap_range('a06619951a43acb80b80d92e0caac560657ca249', '2117db3146ce38bb4a6e2df40b6cd2ab11b514d5') + # "parse/ast: add support for 'built-in' fragments" changed the + # addfragments syntax, which OE-Core only followed in + # e959f916b4 "bitbake.conf: enable built-in fragments for MACHINE + # and DISTRO" (2025-06-20 11:03:34 UTC); before that use the + # bitbake revision before the change + remap_range('3b9d7bea915dc7f10e845854f1dae325743f9456', 'f1175778108a559e1dd0d55cb68f42816c86f393', + replacewith='378db0fdd95f8704fccd852452555bfddcad384d', + until=datetime(2025, 6, 20, 11, 3, 34, tzinfo=timezone.utc)) if options.stop_commit and (options.stop_commit not in [x.split()[0] for x in commit_list]): logger.error('Stop commit %s is not in repository %s' % (options.stop_commit, repodir))
tests/test_rrs_upgrade_history.py new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 4/6 rrs/tools/common.py: check out the layer branch before parsing it
In reply to Tim Orlingload_recipes() let init_parser() check out BitBake and the core layer, but not the layer itself or the layers it depends on, so rrs_upstream_history.py and rrs_distros.py parsed whichever branch the layer index updates had left them on, e.g. meta-openembedded at dunfell while working on master. Check out the layer branch and its dependencies' unless nocheckout is set.
[YOCTO #16502]
AI-Generated: Claude Opus 5.5
--- rrs/tools/common.py | 13 +++++++++- tests/test_rrs_load_recipes.py | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-)
rrs/tools/common.py +12 -1
@@ -92,7 +92,7 @@ def get_recipe_files(layerdir): def load_recipes(layerbranch, bitbakepath, fetchdir, settings, logger, recipe_files=None, nocheckout=False): - from layerindex import recipeparse + from layerindex import recipeparse, utils try: (tinfoil, tempdir) = recipeparse.init_parser(settings,
@@ -110,6 +110,17 @@ def load_recipes(layerbranch, bitbakepath, fetchdir, settings, logger, repodir = os.path.join(fetchdir, urldir) layerdir = os.path.join(repodir, str(layerbranch.vcs_subdir)) + if not nocheckout: + # The repositories are left on whichever branch was updated last; + # check out this branch of the layer and of the layers it depends on + # (init_parser() has done BitBake and the core layer) + utils.checkout_layer_branch(layerbranch, repodir, logger=logger) + for dep in layerbranch.dependencies_set.all(): + deplayerbranch = dep.dependency.get_layerbranch(layerbranch.branch.name) + if deplayerbranch: + utils.checkout_layer_branch(deplayerbranch, + os.path.join(fetchdir, dep.dependency.get_fetch_dir()), logger=logger) + d = recipeparse.setup_layer(tinfoil.config_data, fetchdir, layerdir, layer, layerbranch, logger)
tests/test_rrs_load_recipes.py +45 -0
48 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 5/6 conf/local.conf: use OEBasicHash for parsing
In reply to Tim OrlingOE-Core 5596ea156d made OEEquivHash the default but BB_HASHSERVE was only set in the following commit, so parsing 3c00ad5d3b fails with "OEEquivHash requires BB_HASHSERVE to be set" and the BitBake of the time hangs instead of exiting, stalling rrs_upgrade_history.py. Parsing doesn't need hash equivalence, so select OEBasicHash; this also avoids starting a hashserv for every parse on current master.
[YOCTO #16504]
AI-Generated: Claude Opus 5.5
--- conf/local.conf | 4 ++++ 1 file changed, 4 insertions(+)
conf/local.conf +4 -0
@@ -18,6 +18,10 @@ HOSTTOOLS_NONFATAL := "${@d.getVar('HOSTTOOLS', True) or ''} ${@d.getVar('HOSTTO # oe.utils.get_gcc_version() in a python expression HOSTTOOLS = "gcc" +# Parsing doesn't need hash equivalence; OEEquivHash would also need +# BB_HASHSERVE, which some OE-Core revisions don't set +BB_SIGNATURE_HANDLER = "OEBasicHash" + # Recipe reporting system configuration #require conf/distro/include/maintainers.inc #require conf/distro/include/distro_alias.inc
Signature · 1 line
2.56.1
PATCH 6/6 rrs_distros: keep the environment when fetching distro package lists
In reply to Tim OrlingOE-Core's distro_check calls bb.utils.export_proxies(), which also exports the datastore's PATH and HOME. OE-Core's PATH puts its scripts/git wrapper first with no python3 beside it, so once the package lists were fetched for the first layer branch, every git command for the next one failed with "/usr/bin/env: 'python3': No such file or directory". Restore the environment after fetching the lists.
[YOCTO #16506]
AI-Generated: Claude Opus 5.5
--- rrs/tools/common.py | 18 +++++++++++++ rrs/tools/rrs_distros.py | 5 ++-- tests/test_rrs_distros_environ.py | 45 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 tests/test_rrs_distros_environ.py
rrs/tools/common.py +18 -0
@@ -24,6 +24,24 @@ def common_setup(): os.environ['GIT_ASKPASS'] = '' os.environ['GIT_TERMINAL_PROMPT'] = '0' +def create_distro_packages_list(distro_check, fetchdir, d): + """ + Download the distros' package lists with OE-Core's oe.distro_check, + keeping this process's environment as it was. + + distro_check's create_socket() calls bb.utils.export_proxies(), which + exports PATH and HOME from the datastore along with the proxy + variables. OE-Core's PATH puts its scripts/git wrapper first, with no + python3 beside it, so left in place it breaks every later git command + in this process. + """ + saved_environ = os.environ.copy() + try: + distro_check.create_distro_packages_list(fetchdir, d) + finally: + os.environ.clear() + os.environ.update(saved_environ) + def get_logger(name, settings): from logging.handlers import RotatingFileHandler
rrs/tools/rrs_distros.py +3 -2
@@ -17,7 +17,8 @@ from datetime import datetime sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__)))) from common import common_setup, load_recipes, \ - get_pv_type, get_logger, DryRunRollbackException + get_pv_type, get_logger, DryRunRollbackException, \ + create_distro_packages_list common_setup() from layerindex import utils
@@ -138,7 +139,7 @@ if __name__=="__main__": # Only need to do this once from oe import distro_check logger.debug("Downloading distro's package information ...") - distro_check.create_distro_packages_list(fetchdir, d) + create_distro_packages_list(distro_check, fetchdir, d) pkglst_dir = os.path.join(fetchdir, "package_lists") RecipeDistro.objects.filter(recipe__layerbranch = layerbranch).delete()
tests/test_rrs_distros_environ.py new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.56.1