Bug 13954 - Invalid layerindex data causing backtrace in `bitbake-layers layerindex-fetch`
Summary: Invalid layerindex data causing backtrace in `bitbake-layers layerindex-fetch`
Status: RESOLVED MOVED
Alias: None
Product: Layer Index
Classification: Yocto Project Subprojects
Component: Layer Index Metadata (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium+ normal
Target Milestone: 5.0 M3
Assignee: Unassigned
QA Contact: apoorv sangal
URL:
Whiteboard:
Depends on: 15365
Blocks:
  Show dependency tree
 
Reported: 2020-06-23 07:40 UTC by Paul Barker
Modified: 2024-02-22 16:22 UTC (History)
10 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Don't know


Attachments
layerBranches.json for dunfell branch (29.67 KB, text/plain)
2020-06-23 07:41 UTC, Paul Barker
no flags Details
layerDependencies.json for dunfell branch (12.39 KB, text/plain)
2020-06-23 07:41 UTC, Paul Barker
no flags Details
layerBranches.json for master branch (126.14 KB, text/plain)
2020-06-23 07:41 UTC, Paul Barker
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Barker 2020-06-23 07:40:24 UTC
On the dunfell branch I've recently updated meta-sancloud so that LAYERDEPENDS and LAYERRECOMMENDS are set as follows:

LAYERDEPENDS_meta-sancloud = " \
    core \
    meta-ti \
    "
LAYERRECOMMENDS_meta-sancloud = " \
    rtlwifi \
    "

The `rtlwifi` collection is provided by https://github.com/EmbeddedAndroid/meta-rtlwifi which only contains a master branch, it has no dunfell branch. The master branch of meta-rtlwifi indicates compatibility with dunfell so our usual process is to use the dunfell branch of meta-sancloud, oe-core, meta-ti and other layers plus the master branch of meta-rtlwifi. However, the layer index only looks at the branch names and so does not list meta-rtlwifi on the dunfell branch.

If meta-sancloud had a dependency on meta-rtlwifi, it would be dropped from the layerindex for the dunfell branch as dependencies could not be satisfied. This was previously seen before I modified the LAYERDEPENDS and LAYERRECOMMENDS values above in our layer. However, with meta-rtlwifi listed as a recommendation the meta-sancloud layer is accepted and included in the layerindex for the dunfell branch.

This results in invalid dependency information being generated. I'll attach the full json files in follow up comments as I can only add one attachment at a time but here I will just include the relevant lines. In the layerBranches list for dunfell meta-sancloud is present:

{"id":1631501,"collection":"meta-sancloud","version":null,"vcs_subdir":"","vcs_last_fetch":"2020-06-23T11:06:23+0000","vcs_last_rev":"e3117953a0213c896cc9c8559dc91fffdff41baf","vcs_last_commit":"2020-06-23T08:06:22+0000","actual_branch":"","local_path":"","updated":"2020-06-23T11:06:23+0000","layer":469,"branch":18,"yp_compatible_version":null}

In the layerDependencies list for dunfell there are 3 entries which match the ID of the meta-sancloud layer:

{"id":700743,"required":true,"layerbranch":1631501,"dependency":1}
{"id":700744,"required":true,"layerbranch":1631501,"dependency":26}
{"id":700745,"required":false,"layerbranch":1631501,"dependency":325}

These correspond to the layers oe-core, meta-ti and meta-rtlwifi. The first two are present in the layerBranches list for dunfell however meta-rtlwifi (layer 325) is not. meta-rtlwifi is present in the layerBranches list for master but the client does not look there.

This data appears to be invalid as the "dependency" value for the layerDependencies entry with ID 700745 does not refer to a layer that is present in the corresponing layerBranches list.

Bitbake fails to parse this data and prints out a backtrace:

pokyuser@86145e976448:/w/poky/build$ bitbake-layers layerindex-fetch meta-sancloud -b dunfell
NOTE: Starting bitbake server...
Loading https://layers.openembedded.org/layerindex/api/;branch=dunfell...
Traceback (most recent call last):
  File "/w/poky/bitbake/bin/bitbake-layers", line 95, in <module>
    ret = main()
  File "/w/poky/bitbake/bin/bitbake-layers", line 88, in main
    return args.func(args)
  File "/w/poky/bitbake/lib/bblayers/layerindex.py", line 119, in do_layerindex_fetch
    (dependencies, invalidnames) = lIndex.find_dependencies(names=args.layername, ignores=ignore_layers)
  File "/w/poky/bitbake/lib/layerindexlib/__init__.py", line 443, in find_dependencies
    (dependencies, invalid) = _resolve_dependencies(layerbranches, ignores, dependencies, invalid)
  File "/w/poky/bitbake/lib/layerindexlib/__init__.py", line 386, in _resolve_dependencies
    deplayerbranch = layerdependency.dependency_layerBranch
  File "/w/poky/bitbake/lib/layerindexlib/__init__.py", line 915, in __getattr__
    raise AttributeError('%s not in datastore' % name)
AttributeError: dependency_layerBranch not in datastore

I think the backtrace is also an issue - bitbake-layers should reject invalid data from the layerindex with a meaningful error message instead of a backtrace.

I've opened a bug against meta-rtlwifi to request that a dunfell branch is created: https://github.com/EmbeddedAndroid/meta-rtlwifi/issues/16

I'm also looking to work around this by temporarily dropping the LAYERRECOMMENDS setting from meta-sancloud and leaving users to add the meta-rtlwifi layer separately if they need wifi support. However that's not ideal.

For us the ideal fix would be to extend the layerindex to handle repositories which contain only the master branch but actually declare support for multiple Yocto Project release series. That would require parsing LAYERSERIES_COMPAT for the master branch of each layer, possibly with the addition of some way of indicating which branches to check when a layer is added to the index. That may not be the quickest thing to fix though, maybe it would be better to add data validation and handle layer recommendations (allowing them to fail with a warning) separately from layer dependencies.
Comment 1 Paul Barker 2020-06-23 07:41:03 UTC
Created attachment 4693 [details]
layerBranches.json for dunfell branch
Comment 2 Paul Barker 2020-06-23 07:41:25 UTC
Created attachment 4694 [details]
layerDependencies.json for dunfell branch
Comment 3 Paul Barker 2020-06-23 07:41:50 UTC
Created attachment 4695 [details]
layerBranches.json for master branch
Comment 4 Mark Hatle 2020-06-23 10:53:59 UTC
This is already supported in the index, except for the piece of parsing master and declaring it in one of the branches.

The way that you do this (from an admin point of view) is to create a new branch for an existing layer, then set the branch name (manually) to master [or any other branch name] that is compatible.  Then on the next indexing it will ignore the 'default' branch name, and use the custom one.

So in this case, you just need to request one of the admins add a layer index branch for your layer pointing to master.
Comment 5 Paul Barker 2020-06-23 11:48:00 UTC
The layer that would need the dunfell branch manually defining is meta-rtlwifi, I'm not the maintainer of that layer though so not sure if I should request that myself.
Comment 6 Paul Barker 2020-06-23 17:35:58 UTC
The meta-rtlwifi layer has now added a dunfell branch. The layerindex has been updated and now everything works as expected for the meta-sancloud layer on the dunfell branch.

However, this bug is still worth a look. The invalid json data is captured in the attachments so it can still be investigated.
Comment 7 Paul Barker 2020-07-08 09:44:47 UTC
This bug also affects meta-browser which does not have a dunfell branch - dunfell is supported on the master branch.
Comment 8 Jan-Simon Moeller 2020-08-19 02:27:13 UTC
If I might chime-in:

I ran a set of tests using the dunfell branch.
The call of   'bitbake-layers layerindex-fetch' failed here for:

meta-acrn
meta-arago-distro
meta-chromebook
meta-intel
meta-libretro
openembedded-core
Comment 9 Randy MacLeod 2021-04-29 19:13:28 UTC
Any update?
Comment 10 Randy MacLeod 2021-08-19 15:15:57 UTC
Hey Tim, were you going to work on layerindex?
Comment 11 Randy MacLeod 2023-07-26 21:21:59 UTC
Bulk move of 64 bugs to 4.3 M3 after a quick review.
If a bug is actually fixed, please add a commit link and resolve it.
-- Randy for YP bug team.
Comment 12 Trevor Gamblin 2023-09-14 16:36:13 UTC
Moved to M4.
Comment 13 Randy MacLeod 2023-10-30 15:29:11 UTC
Bulk move to 5.0 M1. -- Randy
Comment 14 Tim Orling 2023-12-14 23:29:27 UTC
If you try to run "bitbake-layers layerindex-fetch meta-sancloud -b dunfell" using current "master" you instead get:

ERROR: Variable BB_HASHBASE_WHITELIST_append file: /path/to/poky/meta-arm/meta-arm-toolchain/conf/layer.conf line: 18 contains an operation using the old override syntax. Please convert this layer/metadata before attempting to use with a newer bitbake.
ERROR: Unable to parse /path/to/poky/bitbake/lib/bb/__init__.py
Traceback (most recent call last):
  File "/path/to/poky/bitbake/lib/bb/__init__.py", line 182, in fatal:
         mainlogger.critical(''.join(args), extra=kwargs)
    >    raise BBHandledException()

bb.BBHandledException

ERROR: Parse failure with the specified layer added, exiting.
Comment 15 Tim Orling 2023-12-14 23:51:18 UTC
If you run with a "dunfell" poky, everything is fine. I'm guessing that we need some checks/conditionals in the "layerindex-fetch" code of bitbake-layers?
Comment 16 Randy MacLeod 2023-12-21 23:28:33 UTC
Bulk move of 52 5.0-M1 bugs to M2.
Comment 17 Tim Orling 2024-01-23 19:48:36 UTC
https://lore.kernel.org/bitbake-devel/e810a80d2aa60cbfbca64abd52101a8c856c80c5.1618588951.git.diego.sueiro@arm.com/ is needed to avoid args.shallow being undefined.

$ bitbake-layers layerindex-show-depends meta-dpdk
NOTE: Starting bitbake server...
Loading https://layers.openembedded.org/layerindex/api/;branch=dunfell...
Layer                                              Git repository (branch)                                 Subdirectory
=============================================================================================================================
local:HEAD:openembedded-core                       https://git.yoctoproject.org/poky.git (dunfell)         meta
  required by: meta-dpdk
layers.openembedded.org:dunfell:meta-dpdk          git://git.yoctoproject.org/meta-dpdk (dunfell)
Traceback (most recent call last):
  File "/srv/build/ttorling/workspace-dunfell/poky/bitbake/bin/bitbake-layers", line 95, in <module>
    ret = main()
  File "/srv/build/ttorling/workspace-dunfell/poky/bitbake/bin/bitbake-layers", line 88, in main
    return args.func(args)
  File "/srv/build/ttorling/workspace-dunfell/poky/bitbake/lib/bblayers/layerindex.py", line 209, in do_layerindex_show_depends
    self.do_layerindex_fetch(args)
  File "/srv/build/ttorling/workspace-dunfell/poky/bitbake/lib/bblayers/layerindex.py", line 182, in do_layerindex_fetch
    args.shallow)
AttributeError: 'Namespace' object has no attribute 'shallow'
Comment 18 Tim Orling 2024-01-23 20:10:02 UTC
Filed https://bugzilla.yoctoproject.org/show_bug.cgi?id=15365 as the backtrace is not in layerindex-web code, but rather in bitbake/lib/layerindex code.
Comment 19 Tim Orling 2024-02-22 16:22:47 UTC
Closing this bug, as the bitbake-layers bug is where the fix needs to be tracked.
That work did not make the 5.0M3 feature freeze and will have to move to 5.1.

It is also related to actual metadata being present in the layerindex, which should be filed in the Layer Index Metadata component. So moving to that component as well.