Skip to content

Commit

Permalink
Redefine default test location for leapp-repository
Browse files Browse the repository at this point in the history
* without `-g/--git` the script was resolving the default test
  repository url poorly, user forced to specify as commandline option
* additionally user was unable to select a branch/git reference when specifying the
  leapp-tests location on the commandline
* with the fix the default leapp-tests repository is defined without the
  git argument needed
* make git option accept four args - baseurl, repo owner, repo name and
  git branch/reference to checkout
* add simple test covering the git argument
* resolves 37

* additional changes made by pre-commit hook

Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway committed Sep 14, 2023
1 parent 21f8804 commit aea6303
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.env
.idea/
Pipfile*
*/__pycache__/
*/*.egg-info/
*__pycache__/
*.egg-info/
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ and this project adheres to [Calendar Versioning](https://calver.org).<br>
### Added

### Changed

- `-g/--git` accepts 4 arguments - base (github, gitlab, gitlab.cee.redhat), repo owner, repo name, git reference (branch, etc.)
- `gitlab.cee.redhat.com/oamg/leapp-tests/-/tree/master` set as default location for tests if `-g/--git` is not specified
- git reference can be specified for leapp-repository tests
### Removed
### [2023.07.12]
### Added
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ As of now tesar is able to perform two tasks.
The goal of tesar is to make requesting test jobs as easy as possible.<br>
Instead of looking for build IDs to pass to the payload, all you need to know is a `--reference` for a pull request number associated with the build you need to test. For brew builds you just need to know the release version.<br>
In case you have the Build ID handy, you can use that instead of the reference.<br>
Use `-g/--git` to point from where the test metadata and code should be run. Specify the repository base e.g. github, repository owner and the branch from which the tests should run.<br>
Use `-g/--git` to point from where the test metadata and code should be run. Specify the repository base e.g. github, repository owner, repository name and the branch from which the tests should run.<br>
Multiple `--plans` can be specified and will be dispatched in separate jobs. The same applies to `--planfilter` and `--testfilter`.<br>
You can look for possible [targeted OS' below](#mapped-composes), multiple can be requested and will be dispatched in separate jobs.
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.
Expand Down Expand Up @@ -163,8 +163,7 @@ options:
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']'
Provide repository base (github, gitlab, gitlab.cee.redhat) owner of the repository, repository name and a branch containing the tests you want to run.
-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
Expand Down
12 changes: 6 additions & 6 deletions src/dispatch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ def get_arguments(args=None):
test.add_argument(
"-g",
"--git",
nargs="+",
default=["github", "oamg", "main"],
help="""Provide repository base (github, gitlab, gitlab.cee.redhat)\nowner of the repository\nand a branch containing the tests you want to run.
Default: '%(default)s'""",
nargs=4,
help="""Provide repository base (github, gitlab, gitlab.cee.redhat) owner of the repository, repository name and a branch containing the tests you want to run.""",
)

test.add_argument(
Expand Down Expand Up @@ -320,6 +318,8 @@ def get_compose_mapping(args=None):
"""Dynamically provide proper compose mapping depending on cli args"""
args = get_arguments(args=args or sys.argv[1:])

compose_mapping = {('test', 'c2r'): dispatch_globals.C2R_COMPOSE_MAPPING,
('test', 'leapp-repository'): dispatch_globals.LP_COMPOSE_MAPPING}
compose_mapping = {
("test", "c2r"): dispatch_globals.C2R_COMPOSE_MAPPING,
("test", "leapp-repository"): dispatch_globals.LP_COMPOSE_MAPPING,
}
return compose_mapping.get((args.action, args.package), {})
49 changes: 30 additions & 19 deletions src/dispatch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,39 @@
COMPOSE_MAPPING = get_compose_mapping()


def main():
copr_repo = PACKAGE_MAPPING[ARGS.package]
copr_package = PACKAGE_MAPPING[ARGS.package]
git_repo = PACKAGE_MAPPING.get(ARGS.package)
source_release = ""
target_release = ""
if ARGS.package == "leapp-repository":
def main(
git_base=None,
git_owner=None,
git_repo=None,
git_ref=None,
copr_repo=None,
copr_package=PACKAGE_MAPPING[ARGS.package],
):
if ARGS.package == "c2r":
git_base = "github"
git_owner = "oamg"
git_repo = PACKAGE_MAPPING.get(ARGS.package)
git_ref = "main"
copr_repo = PACKAGE_MAPPING[ARGS.package]
elif ARGS.package == "leapp-repository":
git_base = "gitlab.cee.redhat"
git_owner = "oamg"
git_repo = "leapp-tests"
git_ref = "master"
copr_repo = "leapp"

if ARGS.git:
git_base = ARGS.git[0]
if ".com" in git_base:
git_base = git_base.strip(".com")
git_owner = ARGS.git[1]
git_repo = ARGS.git[2]
git_ref = ARGS.git[3]
try:
repo_base_url = "https://{}.com/{}/{}".format(
ARGS.git[0], ARGS.git[1], git_repo
)
repo_base_url = "https://{}.com/{}/{}".format(git_base, git_owner, git_repo)
git_response = requests.get(repo_base_url)
if (
ARGS.git[0] != "gitlab"
and ARGS.git[0] != "github"
and ARGS.git[0] != "gitlab.cee.redhat"
):
if git_base not in ["gitlab", "github", "gitlab.cee.redhat"]:
LOGGER.critical(
"Bad git base reference, please provide correct values.\ngithub / gitlab"
"Bad git base reference, please provide correct values.\ngithub / gitlab / gitlab.cee.redhat"
)
sys.exit(99)
elif git_response.status_code == 404:
Expand Down Expand Up @@ -91,7 +102,7 @@ def main():
testfilter = None
item = item.rstrip("/")
# Usually the best approach is to let Testing Farm to choose the most suitable pool.
# Recently the AWS pools are releasing the guests during test execution.
# Occasionally the AWS pools are releasing the guests during test execution.
# If the pool-workaround option is passed, use the baseosci-openstack pool
pool = ""
if ARGS.pool_workaround:
Expand Down Expand Up @@ -137,7 +148,7 @@ def main():
)
submit_test(
repo_base_url,
ARGS.git[2],
git_ref,
ARGS.git_path,
plan,
planfilter,
Expand Down
23 changes: 14 additions & 9 deletions src/report/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,16 @@ def build_table():
if ARGS.split_planname:
planname_split_index = ARGS.split_planname


def _gen_row(uuid="", target="", testplan="", testcase="", result=""):
if 'UUID' in fields:
if "UUID" in fields:
yield uuid
if 'Target' in fields:
if "Target" in fields:
yield target
if 'Test Plan' in fields:
if "Test Plan" in fields:
yield testplan
if 'Test Case' in fields:
if "Test Case" in fields:
yield testcase
if 'Result' in fields:
if "Result" in fields:
yield result

def add_row(*args, **kwargs):
Expand All @@ -274,14 +273,20 @@ def add_row(*args, **kwargs):
testsuite_name_raw.remove("")
testsuite_name = "/".join(testsuite_name_raw[planname_split_index:])
testsuite_result = testsuite_data["testsuite_result"]
add_row(testplan=colorize(testsuite_result, testsuite_name), result=colorize(testsuite_result))
if 'Test Case' in fields:
add_row(
testplan=colorize(testsuite_result, testsuite_name),
result=colorize(testsuite_result),
)
if "Test Case" in fields:
for testcase in testsuite_data["testcases"]:
testcase_name_raw = testcase["testcase_name"].split("/")
testcase_name_raw.remove("")
testcase_name = "/".join(testcase_name_raw[testname_split_index:])
testcase_result = testcase["testcase_result"]
add_row(testcase=colorize(testcase_result, testcase_name), result=colorize(testcase_result))
add_row(
testcase=colorize(testcase_result, testcase_name),
result=colorize(testcase_result),
)

result_table.align = "l"

Expand Down
62 changes: 56 additions & 6 deletions tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,62 @@
def test_cmd_args_are_appended():
"""Unit test covering tesar report -c test1 -c test2 behavior for results aggregation"""
# Make sure -c are treated as list
args = get_arguments(['report',
'-c', 'http://artifacts.osci.redhat.com/testing-farm/909143cf-89ca-4d62-8f81-959bf8ab4d03/',
'-c', 'http://artifacts.osci.redhat.com/testing-farm/14612a82-002d-4a8d-a5c4-613a0a75efeb/'])
args = get_arguments(
[
"report",
"-c",
"http://artifacts.osci.redhat.com/testing-farm/909143cf-89ca-4d62-8f81-959bf8ab4d03/",
"-c",
"http://artifacts.osci.redhat.com/testing-farm/14612a82-002d-4a8d-a5c4-613a0a75efeb/",
]
)
assert len(args.cmd) == 2
# Make official the behavior that -c test1 test2 test3 is not supported anymore
with pytest.raises(SystemExit):
get_arguments(['report', '-c',
'http://artifacts.osci.redhat.com/testing-farm/909143cf-89ca-4d62-8f81-959bf8ab4d03/',
'http://artifacts.osci.redhat.com/testing-farm/14612a82-002d-4a8d-a5c4-613a0a75efeb/'])
get_arguments(
[
"report",
"-c",
"http://artifacts.osci.redhat.com/testing-farm/909143cf-89ca-4d62-8f81-959bf8ab4d03/",
"http://artifacts.osci.redhat.com/testing-farm/14612a82-002d-4a8d-a5c4-613a0a75efeb/",
]
)


def test_git_arg_four_nargs():
"""Unit test covering tesar test -g accepting four arguments."""
# Pass all four arguments to the --git arg
args = get_arguments(
[
"test",
"copr",
"c2r",
"-r",
"pr123",
"-p",
"mock_plan",
"-g",
"github",
"oamg",
"convert2rhel",
"devel",
]
)
assert len(args.git) == 4
# Pass less than 4 arguments
with pytest.raises(SystemExit):
get_arguments(
[
"test",
"copr",
"c2r",
"-r",
"pr123",
"-p",
"mock_plan",
"-g",
"github",
"oamg",
"devel",
]
)

0 comments on commit aea6303

Please sign in to comment.