Skip to content

Commit

Permalink
Decrease priority of bisect jobs in accordance with investigation jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Dec 8, 2023
1 parent 51e0ef4 commit 1901654
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions openqa-trigger-bisect-jobs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def parse_args():
required=True,
help="The openQA test URL for which to trigger bisection investigation jobs",
)
parser.add_argument(
"--priority-add",
default=100,
help="Adds the specified value to the cloned job's priority value",
)
parser.add_argument(
"--dry-run", action="store_true", help="Do not do any action on openQA"
)
Expand Down Expand Up @@ -121,6 +126,19 @@ def openqa_comment(job, host, comment, dry_run):
]
return call(args, dry_run)

def openqa_set_job_prio(job_id, host, prio, dry_run):
prio_json = json.dumps({"priority": prio})
args = client_args + [
"--host",
host,
"--json",
"--data",
prio_json,
"-X",
"PUT",
"jobs/" + str(job_id),
]
return call(args, dry_run)

def openqa_clone(
cmds,
Expand Down Expand Up @@ -243,6 +261,7 @@ def main(args):

log.debug("Received job data: %s" % test_data)
test = job["settings"]["TEST"]
prio = int(job["priority"]) + args.priority_add
log.debug("Found test name '%s'" % test)

created = ""
Expand Down Expand Up @@ -292,6 +311,7 @@ def main(args):
for job_id in sorted(created_job_ids):
log.info(f"Created {job_id}")
created += f"* **{test_name}**: {base_url}/t{job_id}\n"
openqa_set_job_prio(job_id, args.url, prio, args.dry_run)

if len(created):
comment = "Automatic bisect jobs:\n\n" + created
Expand Down
28 changes: 28 additions & 0 deletions tests/test_trigger_bisect_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def args_factory():
args = Namespace()
args.dry_run = False
args.verbose = 1
args.priority_add = 100
return args


Expand Down Expand Up @@ -103,11 +104,34 @@ def test_comment():
openqa.call.assert_called_once_with(args, False)


def test_set_job_prio():
openqa.call = MagicMock(side_effect=mocked_call)
openqa.openqa_set_job_prio(
1234567, "https://openqa.opensuse.org", 42, dry_run=False
)
args = [
"openqa-cli",
"api",
"--header",
"User-Agent: openqa-trigger-bisect-jobs (https://github.com/os-autoinst/scripts)",
"--host",
"https://openqa.opensuse.org",
"--json",
"--data",
'{"priority": 42}',
"-X",
"PUT",
"jobs/1234567",
]
openqa.call.assert_called_once_with(args, False)


def test_triggers():
args = args_factory()
args.url = "https://openqa.opensuse.org/tests/7848818"
openqa.openqa_clone = MagicMock(return_value='{"7848818": 234567}')
openqa.openqa_comment = MagicMock(return_value='')
openqa.openqa_set_job_prio = MagicMock(return_value='')
openqa.fetch_url = MagicMock(side_effect=mocked_fetch_url)
openqa.main(args)
calls = [
Expand Down Expand Up @@ -174,6 +198,10 @@ def test_triggers():
"Automatic bisect jobs:\n\n* **foo:investigate:bisect_without_3**: https://openqa.opensuse.org/t234567\n* **foo:investigate:bisect_without_4**: https://openqa.opensuse.org/t234567\n* **foo:investigate:bisect_without_21637**: https://openqa.opensuse.org/t234567\n* **foo:investigate:bisect_without_22085**: https://openqa.opensuse.org/t234567\n* **foo:investigate:bisect_without_22192**: https://openqa.opensuse.org/t234567\n",
False,
)
prio_calls = 5 * [
call(234567, "https://openqa.opensuse.org/tests/7848818", 150, False)
]
assert prio_calls == openqa.openqa_set_job_prio.call_args_list


def test_problems():
Expand Down

0 comments on commit 1901654

Please sign in to comment.