Skip to content

Commit 98f47f1

Browse files
committed
boot-utils: Add '--gh-json-file'
In moving the rootfs images to GitHub releases, we risk hitting GitHub's API rate limit with GITHUB_TOKEN, which is 1,000 requests per hour per repository, because each boot test within a workflow will be a separate call. It is totally possible for us to run 1,000 boots an hour during a busy workflow period, so this needs special consideration. To make it easier for CI to cache the results of a GitHub release API query, add '--gh-json-file' to both boot-qemu.py and boot-uml.py to allow the tuxsuite parent job to generate boot-utils.json and pass that along to each child job, so that at worst, each workflow will query the API three times (once for defconfigs, allconfigs, and distro configs). Signed-off-by: Nathan Chancellor <[email protected]>
1 parent 9290444 commit 98f47f1

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

boot-qemu.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(self):
4444
self.efi = False
4545
self.gdb = False
4646
self.gdb_bin = ''
47+
self.gh_json_file = None
4748
self.interactive = False
4849
self.kernel = None
4950
self.kernel_dir = None
@@ -162,7 +163,8 @@ def _have_dev_kvm_access(self):
162163
def _prepare_initrd(self):
163164
if not self._initrd_arch:
164165
raise RuntimeError('No initrd architecture specified?')
165-
return utils.prepare_initrd(self._initrd_arch)
166+
return utils.prepare_initrd(self._initrd_arch,
167+
gh_json_file=self.gh_json_file)
166168

167169
def _run_fg(self):
168170
# Pretty print and run QEMU command
@@ -740,6 +742,11 @@ def parse_arguments():
740742
'--gdb-bin',
741743
default='gdb-multiarch',
742744
help='gdb binary to use for debugging (default: gdb-multiarch)')
745+
parser.add_argument(
746+
'--gh-json-file',
747+
help=
748+
'Use file for downloading rootfs images, instead of querying GitHub API directly'
749+
)
743750
parser.add_argument(
744751
'-k',
745752
'--kernel-location',
@@ -827,6 +834,9 @@ def parse_arguments():
827834
runner.gdb = True
828835
runner.gdb_bin = args.gdb_bin
829836

837+
if args.gh_json_file:
838+
runner.gh_json_file = Path(args.gh_json_file).resolve()
839+
830840
if args.no_kvm:
831841
runner.use_kvm = False
832842

boot-uml.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# pylint: disable=invalid-name
33

44
import argparse
5+
from pathlib import Path
56
import subprocess
67

78
import utils
@@ -16,6 +17,12 @@ def parse_arguments():
1617
"""
1718
parser = argparse.ArgumentParser()
1819

20+
parser.add_argument(
21+
'-g',
22+
'--gh-json-file',
23+
help=
24+
'Use file for downloading rootfs images, instead of querying GitHub API directly'
25+
)
1926
parser.add_argument(
2027
"-i",
2128
"--interactive",
@@ -54,7 +61,12 @@ def run_kernel(kernel_image, rootfs, interactive):
5461

5562
if __name__ == '__main__':
5663
args = parse_arguments()
64+
5765
kernel = utils.get_full_kernel_path(args.kernel_location, "linux")
58-
initrd = utils.prepare_initrd('x86_64', rootfs_format='ext4')
66+
67+
initrd_args = {'rootfs_format': 'ext4'}
68+
if args.gh_json_file:
69+
initrd_args['gh_json_file'] = Path(args.gh_json_file).resolve()
70+
initrd = utils.prepare_initrd('x86_64', **initrd_args)
5971

6072
run_kernel(kernel, initrd, args.interactive)

utils.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def green(string):
172172
print(f"\n\033[01;32m{string}\033[0m", flush=True)
173173

174174

175-
def prepare_initrd(architecture, rootfs_format='cpio'):
175+
def prepare_initrd(architecture, rootfs_format='cpio', gh_json_file=None):
176176
"""
177177
Returns a decompressed initial ramdisk.
178178
@@ -189,11 +189,19 @@ def prepare_initrd(architecture, rootfs_format='cpio'):
189189
gh_json_rl = get_gh_json('https://api.github.com/rate_limit')
190190
remaining = gh_json_rl['resources']['core']['remaining']
191191

192-
# If we have API calls remaining, we can query for the latest release to
193-
# make sure that we are up to date.
194-
if remaining > 0:
195-
gh_json_rel = get_gh_json(
196-
f"https://api.github.com/repos/{REPO}/releases/latest")
192+
# If we have API calls remaining or have already queried the API previously
193+
# and cached the result, we can query for the latest release to make sure
194+
# that we are up to date.
195+
if remaining > 0 or gh_json_file:
196+
if gh_json_file:
197+
if not gh_json_file.exists():
198+
raise FileNotFoundError(
199+
f"Provided GitHub JSON file ('{gh_json_file}') does not exist!"
200+
)
201+
gh_json_rel = json.loads(gh_json_file.read_text(encoding='utf-8'))
202+
else:
203+
gh_json_rel = get_gh_json(
204+
f"https://api.github.com/repos/{REPO}/releases/latest")
197205
# Download the ramdisk if it is not already downloaded
198206
if not src.exists():
199207
download_initrd(gh_json_rel, src)

0 commit comments

Comments
 (0)