Skip to content

Commit

Permalink
Test/imgtestlib: add write_build_info() and use it everywhere
Browse files Browse the repository at this point in the history
Add a new helper function `write_build_info()` to imgtestlib, to ensure
consistent way to write the build `info.json` and de-duplicate code.
Modify all remaining places which read / write `info.json` to use
functions from imgtestlib.

Signed-off-by: Tomáš Hozza <[email protected]>
  • Loading branch information
thozza authored and supakeen committed Jan 6, 2025
1 parent 0072f99 commit 5b6aa48
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 1 addition & 3 deletions test/scripts/boot-image
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ def main():
# amend build info with boot success
# search_path is the root of the build path (build/build_name)
build_info["boot-success"] = True
info_file_path = os.path.join(search_path, "info.json")
with open(info_file_path, "w", encoding="utf-8") as info_fp:
json.dump(build_info, info_fp, indent=2)
testlib.write_build_info(search_path, build_info)
if bib_image_id:
# write a separate file with the bib image ID as filename to mark the boot success with that image
bib_id_file = os.path.join(search_path, f"bib-{bib_image_id}")
Expand Down
4 changes: 1 addition & 3 deletions test/scripts/build-image
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def main():
"osbuild-commit": osbuild_commit,
"commit": os.environ.get("CI_COMMIT_SHA", "N/A")
}
info_file_path = os.path.join(build_dir, "info.json")
with open(info_file_path, "w", encoding="utf-8") as info_fp:
json.dump(build_info, info_fp, indent=2)
testlib.write_build_info(build_dir, build_info)


if __name__ == "__main__":
Expand Down
9 changes: 9 additions & 0 deletions test/scripts/imgtestlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,12 @@ def read_build_info(build_path: str) -> Dict:
info_file_path = os.path.join(build_path, "info.json")
with open(info_file_path, encoding="utf-8") as info_fp:
return json.load(info_fp)


def write_build_info(build_path: str, data: Dict):
"""
Write the data to the info.json file in the build directory.
"""
info_file_path = os.path.join(build_path, "info.json")
with open(info_file_path, "w", encoding="utf-8") as info_fp:
json.dump(data, info_fp, indent=2)
7 changes: 2 additions & 5 deletions test/scripts/upload-results
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ def main():

# add the PR number (gitlab branch name) to the info.json if available
if pr_number := os.environ.get("CI_COMMIT_BRANCH"):
info_path = os.path.join(build_dir, "info.json")
with open(info_path, "r", encoding="utf-8") as info_fp:
build_info = json.load(info_fp)
build_info = testlib.read_build_info(build_dir)
# strip the PR prefix
build_info["pr"] = pr_number.removeprefix("PR-")
with open(info_path, "w", encoding="utf-8") as info_fp:
json.dump(build_info, info_fp, indent=2)
testlib.write_build_info(build_dir, build_info)

s3url = testlib.gen_build_info_s3(distro, arch, manifest_id)

Expand Down

0 comments on commit 5b6aa48

Please sign in to comment.