Skip to contentSkip to conversation

Report problems with the first parse of a layer

PATCH New Tim Orling 1 participant 4 messages Nov 14

lore
Share & tools
lore

Tim Orling

author
#0 lore raw

cover Report problems with the first parse of a layer

These fix three bugs in how update.py reports the first parse of each layer's conf/layer.conf.

1: Bug 12130: the values from the first parse (BBFILE_COLLECTIONS,
LAYERVERSION, LAYERDEPENDS, LAYERRECOMMENDS) were printed, so they showed on the console and in every layer's update log. update_layer.py now writes them to a file that update.py names.
2: Bug 13490: errors that stop a layer being parsed (fetch failed,
subdirectory or conf/layer.conf missing, no BBFILE_COLLECTIONS, LAYERDEPENDS not satisfied) only went to the overall update log. They are now also recorded in the layer's own update history.
3: Bug 13489: the page of a layer that was never indexed said indexing
would happen within a few hours even when its update had failed. It now shows a warning with a link to the failed update's log.

On a test instance loaded with a copy of the layers.openembedded.org database, the last nightly update could not add 22 layers on master because their LAYERDEPENDS are not satisfied (e.g. meta-homeassistant, meta-kodi, meta-luneos), with nothing on their pages; 5 of them have never been indexed. The test suite passes in the Docker image at each patch (79 passed, 1 skipped at the end).

Tim Orling (3):
update: don't print the initial layer.conf values
update: record errors in a layer's first parse against the layer
templates: warn on the layer page when the first parse failed

 layerindex/update.py             | 61 +++++++++++++++++++++++---------
 layerindex/update_layer.py       | 12 ++++---
 templates/layerindex/detail.html |  8 +++++
 tests/test_first_parse_status.py | 49 +++++++++++++++++++++++++
 tests/test_update.py             | 34 ++++++++++++++++++
 5 files changed, 143 insertions(+), 21 deletions(-)
 create mode 100644 tests/test_first_parse_status.py

base-commit: 08e58cdece30019a6f9e5d14af16ebe20afa6177

Signature · 1 line
2.56.0
author
#1 lore raw

PATCH 1/3 update: don't print the initial layer.conf values

update.py gets BBFILE_COLLECTIONS, LAYERVERSION, LAYERDEPENDS and LAYERRECOMMENDS for each layer by running update_layer.py --initial, which printed them, so they appeared on the console and in the update log of every layer. Have update_layer.py write them to a file that update.py names instead; errors are still shown as before.

[YOCTO #12130]

AI-Generated: Claude Opus 5.5

---
 layerindex/update.py       | 23 +++++++++++++++--------
 layerindex/update_layer.py | 12 +++++++-----
 tests/test_update.py       | 11 +++++++++++
 3 files changed, 33 insertions(+), 13 deletions(-)
layerindex/update.py +15 -8
index ca68e3e..ccf44a3 100755
@@ -16,6 +16,8 @@ import optparse
 import codecs
 import logging
 import subprocess
+import shlex
+import tempfile
 from datetime import datetime, timedelta
 from packaging_legacy.version import parse as parse_version
 import utils
@@ -36,7 +38,7 @@ except ImportError:
     sys.exit(1)
 
 
-def prepare_update_layer_command(options, branch, layer, initial=False):
+def prepare_update_layer_command(options, branch, layer, initial=None):
     """Prepare the update_layer.py command line"""
     if branch.update_environment:
         cmdprefix = branch.update_environment.get_command()
@@ -54,7 +56,7 @@ def prepare_update_layer_command(options, branch, layer, initial=False):
     if options.dryrun:
         cmd += ' -n'
     if initial:
-        cmd += ' -i'
+        cmd += ' -i %s' % shlex.quote(initial)
     if options.loglevel == logging.DEBUG:
         cmd += ' -d'
     elif options.loglevel == logging.ERROR:
@@ -448,10 +450,15 @@ def main():
                             logger.error("conf/layer.conf not found for layer %s (branch %s) - is subdirectory set correctly?" % (layer.name, branch))
                             continue
 
-                    cmd = prepare_update_layer_command(options, branchobj, layer, initial=True)
+                    fd, initial_fn = tempfile.mkstemp(prefix='layerindex-initial-')
+                    os.close(fd)
+                    cmd = prepare_update_layer_command(options, branchobj, layer, initial=initial_fn)
                     logger.debug('Running layer update command: %s' % cmd)
                     ret, output = utils.run_command_interruptible(cmd)
                     logger.debug('output: %s' % output)
+                    with open(initial_fn) as f:
+                        initial_values = f.read()
+                    os.remove(initial_fn)
                     if ret == 254:
                         # Interrupted by user, break out of loop
                         logger.info('Update interrupted, exiting')
@@ -470,14 +477,14 @@ def main():
                             layerupdate.save()
                         continue
 
-                    col = extract_value('BBFILE_COLLECTIONS', output)
+                    col = extract_value('BBFILE_COLLECTIONS', initial_values)
                     if not col:
-                        logger.error('Unable to find BBFILE_COLLECTIONS value in initial output')
+                        logger.error('Unable to find BBFILE_COLLECTIONS value in initial values')
                         # Assume (perhaps naively) that it's an error specific to the layer
                         continue
-                    ver = extract_value('LAYERVERSION', output)
-                    deps = extract_value('LAYERDEPENDS', output)
-                    recs = extract_value('LAYERRECOMMENDS', output)
+                    ver = extract_value('LAYERVERSION', initial_values)
+                    deps = extract_value('LAYERDEPENDS', initial_values)
+                    recs = extract_value('LAYERRECOMMENDS', initial_values)
 
                     if not options.nocheckout:
                         # We need to check this out because we're using stuff from bb.utils
layerindex/update_layer.py +7 -5
index 0f49371..c11c002 100644
@@ -290,8 +290,8 @@ def main():
             help = "Stop on first parsing error",
             action="store_true", default=False, dest="stop_on_error")
     parser.add_option("-i", "--initial",
-            help = "Print initial values parsed from layer.conf only",
-            action="store_true")
+            help = "Write the initial values parsed from layer.conf to FILE, and do nothing else",
+            action="store", metavar="FILE")
     parser.add_option("-a", "--actual-branch",
             help = "Specify actual_branch for git checkout",
             action="store", dest="actual_branch", default=None)
@@ -454,9 +454,11 @@ def main():
                     sys.exit(1)
                 utils.set_layerbranch_collection_version(layerbranch, layer_config_data, logger=logger)
                 if options.initial:
-                    # Use print() rather than logger.info() since "-q" makes it print nothing.
-                    for i in ["BBFILE_COLLECTIONS", "LAYERVERSION", "LAYERDEPENDS", "LAYERRECOMMENDS"]:
-                        print('%s = "%s"' % (i, utils.get_layer_var(layer_config_data, i, logger)))
+                    # Write these to a file rather than the output, which is
+                    # shown on the console and in the update log
+                    with open(options.initial, 'w') as f:
+                        for i in ["BBFILE_COLLECTIONS", "LAYERVERSION", "LAYERDEPENDS", "LAYERRECOMMENDS"]:
+                            f.write('%s = "%s"\n' % (i, utils.get_layer_var(layer_config_data, i, logger)))
                     sys.exit(0)
 
                 # Set up for recording patch info
tests/test_update.py +11 -0
index a0ac897..1e1db0d 100644
@@ -163,6 +163,17 @@ def test_add_recipe(import_layer, repo, db_access_without_rollback_and_truncate)
     assert recipe.summary == "Brand new recipe"
     assert recipe.license == "MIT"
 
+def test_initial_values_not_in_output(import_layer):
+    # [YOCTO #12130] update.py gets the values it needs from the first parse
+    # of conf/layer.conf through a file, not from the output it shows
+    result = subprocess.run("layerindex/update.py -r -n -l meta-layerindex-test --nofetch --nocheckout",
+                            shell=True, cwd=basepath, stdout=subprocess.PIPE,
+                            stderr=subprocess.STDOUT, text=True)
+    assert result.returncode == 0, result.stdout
+    assert 'BBFILE_COLLECTIONS = ' not in result.stdout
+    assert 'Unable to find BBFILE_COLLECTIONS' not in result.stdout
+
+
 
 
 # FIXME test recipe modify
Signature · 1 line
2.56.0
author
#2 lore raw

PATCH 2/3 update: record errors in a layer's first parse against the layer

In reply to Tim Orling

When update.py could not parse a layer's conf/layer.conf in its first pass (fetch failed, subdirectory or conf/layer.conf missing, no BBFILE_COLLECTIONS, LAYERDEPENDS not satisfied), it only logged the error in the overall update log, so nothing showed in the layer's own update history. Record these as layer updates with the error, as is already done when update_layer.py itself fails.

[YOCTO #13490]

AI-Generated: Claude Opus 5.5

---
 layerindex/update.py | 40 +++++++++++++++++++++++++++++++---------
 tests/test_update.py | 23 +++++++++++++++++++++++
 2 files changed, 54 insertions(+), 9 deletions(-)
layerindex/update.py +31 -9
index ccf44a3..dd794dd 100755
@@ -124,10 +124,12 @@ def print_subdir_error(newbranch, layername, vcs_subdir, branchdesc):
     # This will error out if the directory is completely invalid or had never existed at this point
     # If it previously existed but has since been deleted, you will get the revision where it was
     # deleted - so we need to handle that case separately later
+    # Returns the error, if it is one, for the caller to record
     if newbranch:
         logger.info("Skipping update of layer %s for branch %s - subdirectory %s does not exist on this branch" % (layername, branchdesc, vcs_subdir))
     elif vcs_subdir:
-        logger.error("Subdirectory for layer %s does not exist on branch %s - if this is legitimate, the layer branch record should be deleted" % (layername, branchdesc))
+        return "Subdirectory for layer %s does not exist on branch %s - if this is legitimate, the layer branch record should be deleted" % (layername, branchdesc)
+    return None
 
 def extract_value(valuename, output):
     res = re.search("^%s = \"(.*)\"" % valuename, output, re.M)
@@ -277,6 +279,18 @@ def main():
         update.reload = False
     if not options.dryrun:
         update.save()
+
+    def record_layer_error(layer, branchobj, msg, log=True):
+        """Record an error that stops a layer being updated against the layer,
+        so that it shows in its update history, not only in this update's log"""
+        if log:
+            logger.error(msg)
+        layerupdate = LayerUpdate(update=update, layer=layer, branch=branchobj,
+                                  started=datetime.now(), finished=datetime.now(),
+                                  log='ERROR: %s' % msg, retcode=1)
+        if not options.dryrun:
+            layerupdate.save()
+
     try:
         lockfn = os.path.join(fetchdir, "layerindex.lock")
         lockfile = utils.lock_file(lockfn, options.timeout, logger)
@@ -363,7 +377,8 @@ def main():
 
                 for layer in layerquery:
                     if layer.vcs_url in failedrepos:
-                        logger.info("Skipping update of layer %s - fetch failed" % layer.name)
+                        # fetch_repo() has already logged the error
+                        record_layer_error(layer, branchobj, "Fetch of layer %s failed: %s" % (layer.name, failedrepos[layer.vcs_url]), log=False)
                         continue
 
                     layerbranch = layer.get_layerbranch(branch)
@@ -400,7 +415,7 @@ def main():
                     repodir = os.path.join(fetchdir, urldir)
                     repo = git.Repo(repodir)
                     if repo.bare:
-                        logger.error('Repository %s is bare, not supported' % repodir)
+                        record_layer_error(layer, branchobj, 'Repository %s is bare, not supported' % repodir)
                         continue
                     try:
                         # Allow stable branches to be created if actual_branch exists
@@ -425,9 +440,11 @@ def main():
                         # A bit odd to do it this way but apparently there's no other way in the GitPython API
                         topcommit = next(repo.iter_commits('origin/%s' % branchname, paths=layerbranch.vcs_subdir), None)
                         if not topcommit:
-                            print_subdir_error(newbranch, layer.name, layerbranch.vcs_subdir, branchdesc)
+                            errmsg = print_subdir_error(newbranch, layer.name, layerbranch.vcs_subdir, branchdesc)
+                            if errmsg:
+                                record_layer_error(layer, branchobj, errmsg)
                             if not (newbranch and layerbranch.vcs_subdir):
-                                logger.error("Failed to get last revision for layer %s on branch %s" % (layer.name, branchdesc))
+                                record_layer_error(layer, branchobj, "Failed to get last revision for layer %s on branch %s" % (layer.name, branchdesc))
                             continue
 
                     if layerbranch.vcs_last_rev == topcommit.hexsha and not update.reload:
@@ -443,11 +460,13 @@ def main():
                                 utils.checkout_layer_branch(layerbranch, repodir, actual_branch=options.actual_branch, logger=logger)
                         layerdir = os.path.join(repodir, layerbranch.vcs_subdir)
                         if layerbranch.vcs_subdir and not os.path.exists(layerdir):
-                            print_subdir_error(newbranch, layer.name, layerbranch.vcs_subdir, branchdesc)
+                            errmsg = print_subdir_error(newbranch, layer.name, layerbranch.vcs_subdir, branchdesc)
+                            if errmsg:
+                                record_layer_error(layer, branchobj, errmsg)
                             continue
 
                         if not os.path.exists(os.path.join(layerdir, 'conf/layer.conf')):
-                            logger.error("conf/layer.conf not found for layer %s (branch %s) - is subdirectory set correctly?" % (layer.name, branch))
+                            record_layer_error(layer, branchobj, "conf/layer.conf not found for layer %s (branch %s) - is subdirectory set correctly?" % (layer.name, branch))
                             continue
 
                     fd, initial_fn = tempfile.mkstemp(prefix='layerindex-initial-')
@@ -479,7 +498,7 @@ def main():
 
                     col = extract_value('BBFILE_COLLECTIONS', initial_values)
                     if not col:
-                        logger.error('Unable to find BBFILE_COLLECTIONS value in initial values')
+                        record_layer_error(layer, branchobj, 'Unable to find BBFILE_COLLECTIONS value for layer %s - is it set in conf/layer.conf?' % layer.name)
                         # Assume (perhaps naively) that it's an error specific to the layer
                         continue
                     ver = extract_value('LAYERVERSION', initial_values)
@@ -548,7 +567,10 @@ def main():
                         for layer, value in deps_dict_all.items():
                             logger.warn('%s: LAYERDEPENDS: %s LAYERRECOMMENDS: %s' % (layer.name, value['deps'], value['recs']))
                             if value['deps']:
-                                failed_layers[branch].append('%s: Failed to add since LAYERDEPENDS [%s ...] is not satisfied' % (layer.name, next(iter(value['deps']))))
+                                failed_msg = '%s: Failed to add since LAYERDEPENDS [%s ...] is not satisfied' % (layer.name, next(iter(value['deps'])))
+                                failed_layers[branch].append(failed_msg)
+                                # Reported with the other issues at the end
+                                record_layer_error(layer, branchobj, failed_msg, log=False)
                             else:
                                 # Should never come here
                                 logger.error("Unexpected errors when sorting layers")
tests/test_update.py +23 -0
index 1e1db0d..3266d44 100644
@@ -173,6 +173,29 @@ def test_initial_values_not_in_output(import_layer):
     assert 'BBFILE_COLLECTIONS = ' not in result.stdout
     assert 'Unable to find BBFILE_COLLECTIONS' not in result.stdout
 
+def set_layerbranch(subdir, last_rev):
+    # In a separate process, so that update.py sees the change: the tests run
+    # in a transaction
+    run_cmd('python3 manage.py shell -c "from layerindex.models import LayerBranch; '
+            'LayerBranch.objects.filter(layer__name=\'meta-layerindex-test\').update('
+            'vcs_subdir=\'%s\', vcs_last_rev=\'%s\')"' % (subdir, last_rev), cwd=basepath)
+
+def test_first_parse_error_recorded_against_layer(import_layer, repo, db_access_without_rollback_and_truncate):
+    # [YOCTO #13490] an error that stops a layer being parsed is recorded
+    # in the layer's update history, not only in the overall update log
+    from layerindex.models import LayerBranch, LayerUpdate
+    layerbranch = LayerBranch.objects.get(layer__name='meta-layerindex-test')
+    set_layerbranch('meta-layerindex-test/recipes-example', '')
+    try:
+        result = subprocess.run("layerindex/update.py -l meta-layerindex-test --nofetch --nocheckout",
+                                shell=True, cwd=basepath, stdout=subprocess.PIPE,
+                                stderr=subprocess.STDOUT, text=True)
+        layerupdate = LayerUpdate.objects.filter(layer=layerbranch.layer).order_by('-id').first()
+        assert 'conf/layer.conf not found for layer meta-layerindex-test' in layerupdate.log, result.stdout
+        assert layerupdate.errors == 1
+    finally:
+        set_layerbranch(layerbranch.vcs_subdir, layerbranch.vcs_last_rev)
+
 
 
 
Signature · 1 line
2.56.0
author
#3 lore raw

PATCH 3/3 templates: warn on the layer page when the first parse failed

In reply to Tim Orling

The page of a layer branch that has not been indexed always said that indexing should happen within a few hours, even when the update had already failed, e.g. because of a bad conf/layer.conf. Show a warning with a link to the failed update's log instead.

[YOCTO #13489]

AI-Generated: Claude Opus 5.5

---
 templates/layerindex/detail.html |  8 ++++++
 tests/test_first_parse_status.py | 49 ++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 tests/test_first_parse_status.py
templates/layerindex/detail.html +8 -0
index 6c20f47..cc86ff3 100644
@@ -193,10 +193,18 @@
         </div> <!-- end of container-fluid -->
 
         {% if not layerbranch.vcs_last_commit %}
+        {% with lastupdate=updates.first %}
+        {% if lastupdate.errors %}
+        <div class="alert alert-danger">
+            <b>Warning:</b> The content of this layer on branch {{ url_branch }} could not be indexed: the last update, on {{ lastupdate.started }}, failed. See <a href="{% url 'layerupdate' lastupdate.id %}">its log</a> for the errors.
+        </div>
+        {% else %}
         <div class="alert alert-info">
             <b>Note:</b> The content of this layer on branch {{ url_branch }} has not yet been indexed. Indexing should take place within a few hours.
         </div>
         {% endif %}
+        {% endwith %}
+        {% endif %}
 
         <ul class="nav nav-tabs" id="layertabbar">
             {% if layerbranch.recipe_set.count > 0 %}
tests/test_first_parse_status.py new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.56.0