From 646ee80d8d024115b691faea8b15fb8ca20c6060 Mon Sep 17 00:00:00 2001 From: Katie Worton Date: Wed, 15 Nov 2023 13:35:23 +0000 Subject: [PATCH] squad-create-reproducer-from-testrun: Download reproducers by testrun Add support for downloading reproducers by testrun ID in the squad-create-reproducers script. This allows the user to provide the --testrun parameter to download the build or test reproducer from a specific testrun, using the get_reproducer_from_testrun function from squadutilslib. Signed-off-by: Katie Worton --- README.md | 20 +++++ squad-create-reproducer-from-testrun | 107 +++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100755 squad-create-reproducer-from-testrun diff --git a/README.md b/README.md index c60a604..e99277a 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,26 @@ options: The number of builds to fetch when searching for a reproducer. ``` +### `squad-create-reproducer-from-testrun`: Get a reproducer for a given TestRun ID. + +This script fetches the build or test reproducer for a given TestRun ID. + +``` +usage: squad-create-reproducer-from-testrun [-h] --testrun TESTRUN [--debug] + [--filename FILENAME] [--local | --plan] + +Provide a SQUAD TestRun ID to download the build or test reproducer for that TestRun. The +reproducer will be printed to the terminal and written to a file. + +optional arguments: + -h, --help show this help message and exit + --testrun TESTRUN The TestRun ID of the build or test to fetch the reproducer for. + --debug Display debug messages. + --filename FILENAME Name for the reproducer file, 'reproducer' by default. + --local Fetch a TuxRun or TuxMake reproducer rather than a TuxSuite reproducer. + --plan Fetch a TuxPlan reproducer rather than a TuxTest of TuxBuild reproducer. +``` + ### `squad-create-skipfile-reproducers`: Creating skipfile reproducers The `squad-create-skipfile-reproducers` script can be used to create TuxRun or diff --git a/squad-create-reproducer-from-testrun b/squad-create-reproducer-from-testrun new file mode 100755 index 0000000..5f9a7a0 --- /dev/null +++ b/squad-create-reproducer-from-testrun @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# vim: set ts=4 +# +# Copyright 2023-present Linaro Limited +# +# SPDX-License-Identifier: MIT + + +from argparse import ArgumentParser +from logging import INFO, basicConfig, getLogger +from os import chmod, getenv +from stat import S_IRUSR, S_IWUSR, S_IXUSR +from sys import exit + +from squad_client.core.api import SquadApi + +from squadutilslib import ( + ReproducerNotFound, + get_reproducer_from_testrun, +) + +squad_host_url = "https://qa-reports.linaro.org/" +SquadApi.configure(cache=3600, url=getenv("SQUAD_HOST", squad_host_url)) + +basicConfig(level=INFO) +logger = getLogger(__name__) + + +def parse_args(raw_args): + parser = ArgumentParser( + description="Provide a SQUAD TestRun ID to download the build or test reproducer for that TestRun." + + " The reproducer will be printed to the terminal and written to a file." + ) + + parser.add_argument( + "--testrun", + required=True, + help="The TestRun ID of the build or test to fetch the reproducer for.", + ) + + # Optional arguments: + parser.add_argument( + "--debug", + required=False, + action="store_true", + default=False, + help="Display debug messages.", + ) + + parser.add_argument( + "--filename", + required=False, + help="Name for the reproducer file, 'reproducer' by default.", + ) + + group = parser.add_mutually_exclusive_group() + + group.add_argument( + "--local", + required=False, + action="store_true", + default=False, + help="Fetch a TuxRun or TuxMake reproducer rather than a TuxSuite reproducer.", + ) + + group.add_argument( + "--plan", + required=False, + action="store_true", + default=False, + help="Fetch a TuxPlan reproducer rather than a TuxTest of TuxBuild reproducer.", + ) + + return parser.parse_args(raw_args) + + +def run(raw_args=None): + args = parse_args(raw_args) + + # If filename was not provided, set filename to "reproducer" + if not args.filename: + filename = "reproducer" + else: + filename = args.filename + + try: + reproducer, is_test_reproducer = get_reproducer_from_testrun( + args.testrun, filename, args.plan, args.local + ) + + except ReproducerNotFound as e: + logger.error(f"No reproducer could be found for TestRun {args.testrun}") + logger.error(f"{e}") + return -1 + + # If a filename was provided, don't print the reproducer to console + if not args.filename: + print(reproducer) + + # Make the script executable + chmod(filename, S_IXUSR | S_IRUSR | S_IWUSR) + logger.info(f"file created: {filename}") + + +if __name__ == "__main__": + exit(run())