Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
squadutilslib: Add get_reproducer_from_testrun
Browse files Browse the repository at this point in the history
Add get_reproducer_from_testrun to allow downloading and returning of a
reproducer from a given testrun ID. This function downloads the
reproducer for the given testrun to a provided filename. The optional
`local` flag can be provided to download the tuxmake or tuxrun
reproducer command rather than the tuxsuite reproducer command.

This function will be used in a script to download the reproducer file
for a build or test from a TestRun, which is useful for reproducing
builds and tests.

Update get_reproducer to use the get_reproducer_from_testrun function to
download the reproducer from the testrun.

Signed-off-by: Katie Worton <[email protected]>
  • Loading branch information
katieworton authored and roxell committed Dec 11, 2023
1 parent 7036d3f commit c602628
Showing 1 changed file with 60 additions and 13 deletions.
73 changes: 60 additions & 13 deletions squadutilslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,62 @@ def get_file(path, filename=None):
raise Exception(f"Path {path} not found")


def get_reproducer_from_testrun(testrun_id, filename, plan=False, local=False):
"""Given a testrun, download its reproducer."""
testrun = TestRun(testrun_id)
is_test_reproducer = None
reproducer = None

if local and plan:
logger.error("Error: not valid to request both plan=True and local=True.")
raise ReproducerNotFound

# If there is a download_url try to treat it as a build
if testrun.metadata.download_url:
try:
if local:
reproducer_file = get_file(
testrun.metadata.download_url + "/tuxmake_reproducer.sh", filename
)
elif plan:
reproducer_file = get_file(
testrun.metadata.download_url + "/tux_plan.yaml", filename
)
else:
reproducer_file = get_file(
testrun.metadata.download_url + "/tuxsuite_reproducer.sh", filename
)
is_test_reproducer = False
with open(reproducer_file) as f:
reproducer = f.read()
except HTTPError:
pass

if not reproducer:
# If no build reproducer was found, treat it as a test
try:
if local:
reproducer_file = get_file(
testrun.metadata.job_url + "/reproducer", filename
)
elif plan:
reproducer_file = get_file(
testrun.metadata.job_url + "/tux_plan", filename
)
else:
reproducer_file = get_file(
testrun.metadata.job_url + "/tuxsuite_reproducer", filename
)
is_test_reproducer = True
with open(reproducer_file) as f:
reproducer = f.read()
except HTTPError:
logger.error("No build or test reproducer found.")
raise ReproducerNotFound

return reproducer, is_test_reproducer


def filter_projects(projects, pattern):
filtered = []
for p in projects:
Expand Down Expand Up @@ -193,20 +249,11 @@ def get_reproducer(
# In theory there should only be one of those
logger.debug(f"Testrun id: {testrun.id}")

try:
if local:
reproducer = get_file(
f"{testrun.job_url}/reproducer", filename=filename
)
else:
reproducer = get_file(
f"{testrun.job_url}/tuxsuite_reproducer", filename=filename
)
except HTTPError:
logger.error(f"Reproducer not found at {testrun.job_url}!")
raise ReproducerNotFound
reproducer, is_test_reproducer = get_reproducer_from_testrun(
testrun_id=testrun.id, filename=filename, plan=False, local=local
)
return (
Path(reproducer).read_text(encoding="utf-8"),
reproducer,
Build(getid(testrun.build)).metadata.git_describe,
testrun.metadata.build_name,
)
Expand Down

0 comments on commit c602628

Please sign in to comment.