Skip to content

Commit

Permalink
Add specfile and packit.yaml
Browse files Browse the repository at this point in the history
* Fix broken requirements
 * remove envparse listed as requirement, but not used anywhere
* Refactor dir hierarchy
* Push devel builds to the devel repository
* Fix imports
* fix tests
* changelog, readme modifications
* try krb5 as dependency

Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway committed Mar 19, 2024
1 parent e121f68 commit 3c8c7b0
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 141 deletions.
46 changes: 46 additions & 0 deletions .packit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# See the documentation for more information:
# https://packit.dev/docs/configuration/

specfile_path: tesar.spec

# add or remove files that should be synced
files_to_sync:
- tesar.spec
- .packit.yaml

# name in upstream package repository or registry (e.g. in PyPI)
upstream_package_name: tesar
# downstream (Fedora) RPM package name
downstream_package_name: tesar

jobs:
# Build for pull request push
- job: copr_build
owner: danmyway
project: tesar-devel
trigger: pull_request
targets:
- fedora-stable
actions:
# Get the version from the spec file
get-current-version:
- echo devel
# Build for merge to devel
- job: copr_build
owner: danmyway
project: tesar-devel
trigger: commit
branch: devel
targets:
- fedora-stable
actions:
# Get the version from the spec file
get-current-version:
- echo devel
# Build for release tagged on main
- job: copr_build
owner: danmyway
project: tesar
trigger: release
targets:
- fedora-stable
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Calendar Versioning](https://calver.org).<br>
- Report command option for downloading logs only for non-passed tests
- Test results comparison mode introduced, can be controlled by the `--compare` option of `tesar report`.
- `--showarch` option in `report` command displaying architecture in the table
- make builds available in the copr.fedorainfracloud.org repositories tesar and tesar-devel respectively

### Changed
- `-c/--compose` to `-t/--target`
Expand Down
133 changes: 20 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
1. [Testing farm API key](#testing-farm-api-key)
2. [Cloud Resources Tag](#cloud-resources-tag)
3. [Package dependencies](#package-dependencies)
3. [Setup](#setup)
3. [Setting up](#setting-up)
1. [Installation](#installation)
1. [Clone](#clone)
2. [Install](#install)
3. [Set up configuration file](#set-up-configuration-file)
3. [Set up the configuration file](#set-up-configuration-file)
4. [Config file template](#config-file-template)
2. [Usage](#usage)
1. [Commands](#commands)
Expand Down Expand Up @@ -39,7 +39,7 @@ That is IMHO **exactly six times more**, than it should be.
With this script, you will be able to do all of the above with just one command!

```shell
```
tesar test copr c2r -ref pr123 -g github oamg main -p /plans/tier0/basic_sanity_checks /plans/tier1/rhsm -c cos84 cos7 ol8
```

Expand All @@ -60,54 +60,35 @@ Each team using the Testing Farm to run test efforts has a BusinessUnit tag assi
Those are important to use for correct reporting efforts of a cloud spend for each team.<br>
Ask peers in your team for the tag value.

### Package dependencies
# Setting up

To be able to get information for brew-builds and copr-builds this script uses the `brewkoji` and
`python-copr` packages. <br>
If needed, install `python-copr-doc` for code documentation for the python-copr package.<br>
Documentation then will be available at `/usr/share/doc/python-copr/html/ClientV3.html`
It is also recommended to install `python-kerberos`, `python-requests`, `python-requests-kerberos`, `make`, `krb5-devel`, `gcc`, `python3-devel`, `redhat-rpm-config` to be able to run the script.
### Installation

Before installing the packages, it is advised to download the `rcm-tools-fedora.repo` to be able to install `brewkoji`
#### Enable the copr repository

```shell
sudo su
curl -L https://download.devel.redhat.com/rel-eng/RCMTOOLS/rcm-tools-fedora.repo -o /etc/yum.repos.d/rcm-tools-fedora.repo
```
sudo dnf copr enable danmyway/tesar
```

Installing the packages
If you are brave enough, though not advised, you can try out the development repository.

```shell
dnf install brewkoji python-copr python-copr-doc python-kerberos python-requests python-requests-kerberos make krb5-devel gcc python3-devel redhat-rpm-config
```
sudo dnf copr enable danmyway/tesar-devel
```

# Setup

### Installation
#### Install

#### Clone
Clone repository to your local machine.
```shell
# ssh
git clone [email protected]:danmyway/tesar.git
# https
git clone https://github.com/danmyway/tesar.git
```
#### Install
Change directory to the cloned folder, run virtual environment and install the package.
```shell
cd ~/tesar
pipenv --site-packages shell
pip install .
sudo dnf install tesar
```
#### Set up configuration file
#### Set up the configuration file
Set up config file with obtained Testing Farm API key and Cloud Resources Tag that helps with tracking cloud spend.

```shell
```
touch ~/.config/tesar && printf "[testing-farm]\nAPI_KEY={your testing farm api key}\n[cloud-resources-tag]\nCLOUD_RESOURCES_TAG={tag}" > ~/.config/tesar
```
or copy provided file and edit with your favourite editor, e.g.
```shell
```
cp ./tesar.temp ~/.config/tesar
vim ~/.config/tesar
```
Expand All @@ -120,8 +101,6 @@ API_KEY=
CLOUD_RESOURCES_TAG=
```
### Usage
If you installed the script via `pip install .` you should be able to run the script by running `tesar` command.<br>
Otherwise run with `python3 __main__.py` from the `tesar/tesar` directory.

#### Commands
As of now tesar is able to perform two tasks.
Expand All @@ -140,50 +119,7 @@ You can look for possible [targeted OS' below](#mapped-composes), multiple can b
Use `-w/--wait` to override the default 20 seconds waiting time for successful response from the endpoint, or `-nw/--no-wait` to skip the wait time.
If for any reason you would need the raw payload, use `--dry-run` to get it printed to the command line or use `--dry-run-cli` to print out the full usable `http POST` command.
When no `-t/--target` option is specified, the request is sent for all mapped target composes for their respective tested packages.
```shell
❯ tesar test --help
usage: tesar test [-h] (-ref REFERENCE [REFERENCE ...] | -id TASK_ID [TASK_ID ...]) [-g GIT [GIT ...]] [-gp GIT_PATH] [-a ARCHITECTURE] (-p PLANS [PLANS ...] | -pf PLANFILTER [PLANFILTER ...] | -tf TESTFILTER [TESTFILTER ...])
[-t TARGET [TARGET ...]] [-pw] [-w WAIT] [-nw] [-l] [--dry-run] [--dry-run-cli] [--debug]
artifact_type package

Send requests to the Testing Farm conveniently.

positional arguments:
artifact_type Choose which type of artifact to test. Choices: brew, copr
package Choose package to test. Choices: c2r, leapp-repository

options:
-h, --help show this help message and exit
-ref REFERENCE [REFERENCE ...], --reference REFERENCE [REFERENCE ...]
Mutually exclusive with respect to --task-id. For brew: Specify the reference version to find the correct artifact (e.g. 0.1-2, 0.1.2). For copr: Specify the pull request reference to find the correct
artifact (e.g. pr123, main, master, ...).
-id TASK_ID [TASK_ID ...], --task-id TASK_ID [TASK_ID ...]
Mutually exclusive with respect to --reference. For brew: Specify the TASK ID for required brew build. NOTE: Double check, that you are passing TASK ID for copr builds, not BUILD ID otherwise
testing farm will not install the package. For copr: Specify the BUILD ID for required copr build.
-g GIT [GIT ...], --git GIT [GIT ...]
Provide repository base (github, gitlab, gitlab.cee.redhat) owner of the repository and a branch containing the tests you want to run. Default: '['github', 'oamg', 'main']'
-gp GIT_PATH, --git-path GIT_PATH
Path to the metadata tree root. Should be relative to the git repository root provided in the url parameter. Default: '.'
-a ARCHITECTURE, --architecture ARCHITECTURE
Choose suitable architecture. Default: 'x86_64'.
-p PLANS [PLANS ...], --plans PLANS [PLANS ...]
Specify a test plan or multiple plans to request at testing farm. To run whole set of tiers use /plans/tier*/ Accepts multiple space separated values, sends as a separate request.
-pf PLANFILTER [PLANFILTER ...], --planfilter PLANFILTER [PLANFILTER ...]
Filter plans. The specified plan filter will be used in tmt plan ls --filter <YOUR-FILTER> command. By default enabled: true filter is applied. Accepts multiple space separated values, sends as a separate
request.
-tf TESTFILTER [TESTFILTER ...], --testfilter TESTFILTER [TESTFILTER ...]
Filter tests. The specified plan filter will be used in tmt run discover plan test --filter <YOUR-FILTER> command. Accepts multiple space separated values, sends as a separate request.
-t TARGET [TARGET ...], --target TARGET [TARGET ...]
Choose targeted test run. For c2r targeted OS, for leapp targeted upgrade path.
-pw, --pool-workaround
Workarounds the AWS spot instances release.
-w WAIT, --wait WAIT Provide number of seconds to wait for successful response. Default: 20 seconds.
-nw, --no-wait Don't wait for successful response and get the artifact link ASAP.
-l, --log Log test links or dry run output to a file.
--dry-run Print out just the payload that would be sent to the testing farm. Do not actually send any request.
--dry-run-cli Print out https shell command with requested payload. Do not actually send any request.
--debug Print out additional information for each request.
```


##### Report
With the report command you are able to get the results of the requested jobs straight to the command line.<br>
Expand All @@ -206,42 +142,13 @@ Corresponding return code is set based on the results with following logic:

The default way to show results is by showing each run details as a separate table. In order to combine test results of several different tft runs you can use comparison mode which is triggered by the `--compare` flag of `tesar report`.

```shell
❯ tesar report -c 8f4e2e3e-beb4-4d3a-9b0a-68a2f428dd1b -c c3726a72-8e6b-4c51-88d8-612556df7ac1 --short --unify-results=tier2=tier2_7to8 --compare
```
```shell
❯ tesar report --help
usage: tesar report [-h] [--showarch] [-l2] [-s] [-stn SPLIT_TESTNAME] [-spn SPLIT_PLANNAME] [-w] [-d] [--skip-pass] [--compare] [-u UNIFY_RESULTS] [-lt | -f FILE | -c CMD]
Parses task IDs, Testing Farm artifact URLs or Testing Farm API request URLs from multiple sources.
options:
-h, --help show this help message and exit
--showarch Display architecture. By default the architecture is not shown.
-l2, --level2 Display test view detail. By default the report shows only plan view.
-s, --short Display short test and plan names.
-stn SPLIT_TESTNAME, --split-testname SPLIT_TESTNAME
Specify an index from which will the test name be shown. Passed to testname.split('/')[index:]
-spn SPLIT_PLANNAME, --split-planname SPLIT_PLANNAME
Specify an index from which will the plan name be shown. Passed to planname.split('/')[index:]
-w, --wait Wait for the job to complete. Print the table afterwards
-d, --download-logs Download logs for requested run(s).
--skip-pass Skip PASSED results while showing table and while downloading logs.
--compare Build a comparison table for several runs results
-u UNIFY_RESULTS, --unify-results UNIFY_RESULTS
Plans name to be treated as one in plan1=plan2 format, useful for runs comparison in case of renaming.
-lt, --latest Mutually exclusive with respect to --file and --cmd. Report latest jobs from /tmp/tesar_latest_jobs.
-f FILE, --file FILE Mutually exclusive with respect to --latest and --cmd. Specify a different location than the default ./report_jobs of the file containing request_id's, artifact URLs
or request URLs.
-c CMD, --cmd CMD Mutually exclusive with respect to --file and --latest. Parse request_ids, artifact URLs or request URLs from the command line.
❯ tesar report -c 8f4e2e3e-beb4-4d3a-9b0a-68a2f428dd1b -c c3726a72-8e6b-4c51-88d8-612556df7ac1 --short --unify-results=tier2=tier2_7to8 --compare
```

#### Examples

```shell
```
# Test copr build for PR#123 with plan basic_sanity_check on CentOS 8.4
$ tesar test copr c2r -ref pr123 -g github oamg main -p /plans/tier0/basic_sanity_checks -c cos84
Expand All @@ -256,7 +163,7 @@ $ tesar test brew c2r -ref 0.12-3 -git github oamg main -p /plans/tier0/basic_sa
```

```shell
```
# Get results for the requests in the default file ./latest_jobs
$ tesar report
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package_dir =
packages = find:
python_requires = >=3.6
install_requires =
envparse
requests
copr
koji
prettytable
lxml
pygments
krb5

[options.packages.find]
where = src
Expand Down
16 changes: 8 additions & 8 deletions src/tesar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import contextlib
import sys

from dispatch import get_arguments, get_datetime

ARGS = get_arguments()
from .dispatch import get_arguments, get_datetime


def main():
if ARGS.action == "test":
from dispatch.__main__ import main as dispatch
args = get_arguments()

if args.action == "test":
from .dispatch.__main__ import main as dispatch

if ARGS.log:
if args.log:
datetime_str = get_datetime()
with open(f"./artifactlog_{datetime_str}", "a") as log:
with contextlib.redirect_stdout(log):
sys.exit(dispatch())
else:
sys.exit(dispatch())
elif ARGS.action == "report":
from report.__main__ import main as report
elif args.action == "report":
from .report.__main__ import main as report

sys.exit(report())
8 changes: 5 additions & 3 deletions src/dispatch/__init__.py → src/tesar/dispatch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,21 @@ def get_arguments(args=None):
help="""Download logs for requested run(s).""",
)
report.add_argument(
'--skip-pass',
"--skip-pass",
action="store_true",
help="Skip PASSED results while showing table and while downloading logs.",
)
report.add_argument(
"--compare",
action="store_true",
help="""Build a comparison table for several runs results""")
help="""Build a comparison table for several runs results""",
)
report.add_argument(
"-u",
"--unify-results",
action="append",
help="""Plans name to be treated as one in plan1=plan2 format, useful for runs comparison in case of renaming.""")
help="""Plans name to be treated as one in plan1=plan2 format, useful for runs comparison in case of renaming.""",
)
tasks_source = report.add_mutually_exclusive_group()
tasks_source.add_argument(
"-lt",
Expand Down
12 changes: 7 additions & 5 deletions src/dispatch/__main__.py → src/tesar/dispatch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import requests

from dispatch import (
from .__init__ import (
get_arguments,
get_compose_mapping,
get_logging,
)
from dispatch.dispatch_globals import ARTIFACT_MAPPING, PACKAGE_MAPPING
from dispatch.tf_send_request import submit_test
from .dispatch_globals import ARTIFACT_MAPPING, PACKAGE_MAPPING
from .tf_send_request import submit_test

LOGGER = get_logging()
ARGS = get_arguments()
Expand Down Expand Up @@ -59,10 +59,12 @@ def main():
LOGGER.critical(index_err)
sys.exit(99)
try:
artifact_module_name = ARGS.artifact_type + "_api"
artifact_module = importlib.import_module(
"dispatch." + ARGS.artifact_type + "_api"
"tesar.dispatch." + artifact_module_name
)
except ImportError:
except ImportError as ie:
LOGGER.debug(ie)
LOGGER.error("Artifact_module could not be loaded!")
return 99

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import koji

from dispatch import get_compose_mapping, get_arguments, get_logging
from .__init__ import get_compose_mapping, get_arguments, get_logging

LOGGER = get_logging()
ARGS = get_arguments()
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/copr_api.py → src/tesar/dispatch/copr_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from copr.v3 import BuildProxy

from dispatch import dispatch_globals
from dispatch import get_arguments, get_compose_mapping, get_logging
from . import dispatch_globals
from . import get_arguments, get_compose_mapping, get_logging

SESSION = BuildProxy(dispatch_globals.COPR_CONFIG)
LOGGER = get_logging()
Expand Down
File renamed without changes.
Loading

0 comments on commit 3c8c7b0

Please sign in to comment.