scripts: add list-yp-compatible-layers.py
Please hold off on this version, there is an error in the layers set() handling. I will send a v2.
Quoted 236 lines · Tim Orling via lists.yoctoproject.org
This is a handy helper script to query the Buildbot REST API to create a list of Yocto Project Compatible 2.0 layers, as defined by successful running of the "check-layers*" jobs.
The script only considers the 'jobs' ("Builders" in Buildbot speak) you ask it to query.
The script looks at the latest -n successful builds for a branch that matches from a list. The number of builds approach was used because the
property_listcannot be queried for "branch" in the "builders" API.It looks for a "step" name pattern via a regex, with which all currently running "check-layer" and "check-layer-nightly" jobs conform.
Once a branch has successfully been queried, it is removed from the list in further iterations. The intent is to only find the latest passing list of compatible layers, for each branch.
The output is a yp_compatible_layers.json file which can be pretty printed with:
cat yp_compatible_layers.json | jq
Signed-off-by Tim Orling <[email protected]>--- scripts/list-yp-compatible-layers.py | 155 +++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 scripts/list-yp-compatible-layers.pyscripts/list-yp-compatible-layers.py new file +31
-0@@ -0,0 +1,155 @@ +#!/usr/bin/env python3 + +# Query layers that are Yocto Project Compatible (2.0) on the AutoBuilder +# and make a yp_compatible_layers.json file as an output +# +# Copyright (C) 2023 Konsulko Group +# Author: Tim Orling <[email protected]> +# +# Licensed under the MIT license, see COPYING.MIT for details +# +# SPDX-License-Identifier: MIT +# +# Variables that should be modified for your needs (could become args) +# +# api_url: +# the url for the Buildbot REST API on the AutoBuilder +# desired_branches: +# list of branches to find a matching build for +# desired_jobs: +# list of "Builders" on the AutoBuilder that perform the +# actual compatibility checks +# output_filename: +# name for the json file to output +# +# For "pretty" output: +# cat yp_compatible_layers.json | jq + +import sys +import os + +sys.path.insert(0,
os.path.realpath(os.path.join(os.path.dirname(__file__), '..')))scripts/list-yp-compatible-layers.py new file +11
-0+ +import argparse +import logging +import re +import requests +import json + + +def main(): + # Setup logging + logging.basicConfig(level=logging.INFO, format="%(levelname)s:%(message)s")
scripts/list-yp-compatible-layers.py new file +3
-0+ logger = logging.getLogger('list-yocto-project-compatible-layers') + + parser = argparse.ArgumentParser(description='query Yocto AutoBuildercheck-layer* jobs and create a json file of Yocto Compatible 2.0 layers')
scripts/list-yp-compatible-layers.py new file +7
-0+ + parser.add_argument("-n", "--num-builds", + help = "Limit the number of Auto Builder builds to query", + action="store", dest="num_builds", default=20) + parser.add_argument("-d", "--debug", + help = "Enable debug output", + action="store_const", const=logging.DEBUG, dest="loglevel",default=logging.INFO)
scripts/list-yp-compatible-layers.py new file +10
-0+ parser.add_argument("-q", "--quiet", + help = "Hide all output except error messages", + action="store_const", const=logging.ERROR, dest="loglevel") + + args = parser.parse_args() + + logger.setLevel(args.loglevel) + + api_url = 'https://autobuilder.yoctoproject.org/typhoon/api/v2' + desired_branches = {"dunfell", "kirkstone", "mickledore", "nanbield","master"}
scripts/list-yp-compatible-layers.py new file +6
-0+ desired_jobs = {"check-layer", "check-layer-nightly"} + num_builds = args.num_builds + output_filename = 'yp_compatible_layers.json' + builder_id=dict() + # get info about a builder + # curlhttps://autobuilder.yoctoproject.org/typhoon/api/v2/builders?name=check-layer
scripts/list-yp-compatible-layers.py new file +4
-0+ builder_id['check_layer']=39 + builder_id['check_layer_nightly']=121 + # get the "api" + # curlhttps://autobuilder.yoctoproject.org/typhoon/api/v2/application.spec
scripts/list-yp-compatible-layers.py new file +3
-0+ + # get a specific step raw stdio log + # curlhttps://autobuilder.yoctoproject.org/typhoon/api/v2/builders/121/builds/1651/steps/11/logs/stdio/raw
scripts/list-yp-compatible-layers.py new file +3
-0+ + # filter for strings in the name of a step + # curlhttps://autobuilder.yoctoproject.org/typhoon/api/v2/builders/check-layer-nightly/builds/1651/steps?name__contains=Test
+ # curl
https://autobuilder.yoctoproject.org/typhoon/api/v2/builders/check-layer-nightly/builds/1651/steps?name__contains=Run&field=name&field=numberscripts/list-yp-compatible-layers.py new file +2
-0+ # + # get the latest build (NOTE: - in front of 'number' does reversescripts/list-yp-compatible-layers.py new file +3
-0+ # + # get list of properties for a build + #https://autobuilder.yoctoproject.org/typhoon/api/v2/builds/453477/property_list
scripts/list-yp-compatible-layers.py new file +2
-0+ # + # get the buildid of a build from builders/ so the builds/<buildid>api can be queried for
property_listscripts/list-yp-compatible-layers.py new file +2
-0+ # otherwise, we have no way to get the 'branch' + #scripts/list-yp-compatible-layers.py new file +4
-0+ + def latest_builds(job, limit): + # limit to successful builds (however, this includes Skip) + url_str =f'{api_url}/builders/{job}/builds?state_string__contains=successful&limit={str(limit)}&order=-buildid&field=buildid&field=state_string'
scripts/list-yp-compatible-layers.py new file +4
-0+ r = requests.get(url_str) + return r + + # set objects are not JSON serializable, so we convert our set to alist
scripts/list-yp-compatible-layers.py new file +7
-0+ class YPCompatibleJSONEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, set): + return list(obj) + return json.JSONEncoder.default(self, obj) + + #latest_20 = requests.get('https://autobuilder.yoctoproject.org/typhoon/api/v2/builders/check-layer-nightly/builds?limit=20&order=-buildid&field=buildid
')
+compatible_dict= dict().fromkeys(desired_jobs,
dict().fromkeys(desired_branches,set()))scripts/list-yp-compatible-layers.py new file +2
-0+ for job in desired_jobs: + # we want a list we can decrement once a valid branch has beenfound
scripts/list-yp-compatible-layers.py new file +2
-0+ copy_desired_branches = desired_branches.copy() + logger.info(f'Processing at most {num_builds} builds forAutoBuilder job: {job}...')
scripts/list-yp-compatible-layers.py new file +4
-0+ for builds in latest_builds(job, num_builds).json()['builds']: + build_id=builds['buildid'] + logger.debug(f'\tProcessing build: {build_id}...') + url_str =f'{api_url}/builds/{build_id}/property_list?name=yp_build_branch'
+ #r = requests.get('
https://autobuilder.yoctoproject.org/typhoon/api/v2/builds/%s/property_list?name=yp_build_branch'
% builds['buildid'])scripts/list-yp-compatible-layers.py new file +9
-0+ r = requests.get(url_str) + try: + result_dict = r.json()['_properties'][0] + branch = result_dict['value'].replace('"','') + except: + pass + if branch in copy_desired_branches: + logger.info(f'\tProcessing branch: {branch}...') + url_str =f'{api_url}/builds/{build_id}/steps?name__contains=Run&field=name&field=number'
scripts/list-yp-compatible-layers.py new file +6
-0+ steps_req = requests.get(url_str) + steps_dict = steps_req.json()['steps'] + for step in steps_dict: + try: + step_num = step['number'] + # currently, meta-virtualization does not have'cmds' so use a look ahead
+repo_regex= re.compile(r"^Test (.+) YP
Compatibility: Run(?: cmds)$")scripts/list-yp-compatible-layers.py new file +5
-0+ repo = repo_regex.match(step['name']).group(1) + except: + pass + try: + url_str =f'{api_url}/builds/{build_id}/steps/{step_num}/logs/stdio/raw'
scripts/list-yp-compatible-layers.py new file +4
-0+ log_req = requests.get(url_str) + log = log_req.content.decode("utf-8") + # We only care about layers that have passed + layer_regex = re.compile(r"^INFO: (.+) ...PASS$", re.MULTILINE)
scripts/list-yp-compatible-layers.py new file +16
-1+ layers = layer_regex.findall(log) + if len(layers) > 0: + logger.info(f'\t\tDetected {layers}') + for layer in layers: + compatible_dict[job][branch].add(layer) + except: + sys.exit(1) + copy_desired_branches.remove(branch) + with open(output_filename, 'w') as f: + json.dump(compatible_dict, f, cls=YPCompatibleJSONEncoder) + + sys.exit(0) + + +if __name__ == "__main__": + main() --2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#61504):
https://lists.yoctoproject.org/g/yocto/message/61504
Mute This Topic: https://lists.yoctoproject.org/mt/102231417/924729
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-