ci/lava: Use lava-test-case to run custom scripts in LAVA

The exit code is automatically parsed to fail/pass the job, so this
commit removes the `hwci.*pass|fail` regex and printings.

Add mesa-job-name parameter to get the CI_JOB_NAME easily to serve as
test name.

Besides, there is the treatment for the mesa job naeme, as LAVA does not
like whitespace character inside the test case/suite name, since it
interprets it as a LAVA signal parameter and it can make the job fail
when the script looks for the results from the LAVA RPC.

And the slash character seems to break gitlab log sectioning, so
removing every character after the first whitespace.

Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15938>
This commit is contained in:
Guilherme Gallo 2022-03-22 22:39:31 -03:00 committed by Marge Bot
parent 33a1c51e3e
commit 09236d9607
2 changed files with 20 additions and 11 deletions

View File

@ -45,4 +45,6 @@ artifacts/lava/lava_job_submitter.py \
--kernel-image-type "${KERNEL_IMAGE_TYPE}" \
--boot-method ${BOOT_METHOD} \
--visibility-group ${VISIBILITY_GROUP} \
--lava-tags "${LAVA_TAGS}" >> results/lava.log
--lava-tags "${LAVA_TAGS}" \
--mesa-job-name "$CI_JOB_NAME" \
>> results/lava.log

View File

@ -26,6 +26,7 @@
import argparse
import pathlib
import re
import sys
import time
import traceback
@ -117,6 +118,7 @@ def generate_lava_yaml(args):
# skeleton test definition: only declaring each job as a single 'test'
# since LAVA's test parsing is not useful to us
run_steps = []
test = {
'timeout': { 'minutes': args.job_timeout },
'failure_retry': 1,
@ -133,10 +135,8 @@ def generate_lava_yaml(args):
'scope': [ 'functional' ],
'format': 'Lava-Test Test Definition 1.0',
},
'parse': {
'pattern': r'hwci: (?P<test_case_id>\S*):\s+(?P<result>(pass|fail))'
},
'run': {
"steps": run_steps
},
},
} ],
@ -147,26 +147,25 @@ def generate_lava_yaml(args):
# - fetch and unpack per-pipeline build artifacts from build job
# - fetch and unpack per-job environment from lava-submit.sh
# - exec .gitlab-ci/common/init-stage2.sh
init_lines = []
run_steps = []
with open(args.first_stage_init, 'r') as init_sh:
init_lines += [ x.rstrip() for x in init_sh if not x.startswith('#') and x.rstrip() ]
run_steps += [ x.rstrip() for x in init_sh if not x.startswith('#') and x.rstrip() ]
with open(args.jwt_file) as jwt_file:
init_lines += [
run_steps += [
"set +x",
f'echo -n "{jwt_file.read()}" > "{args.jwt_file}" # HIDEME',
"set -x",
]
init_lines += [
run_steps += [
'mkdir -p {}'.format(args.ci_project_dir),
'wget -S --progress=dot:giga -O- {} | tar -xz -C {}'.format(args.build_url, args.ci_project_dir),
'wget -S --progress=dot:giga -O- {} | tar -xz -C /'.format(args.job_rootfs_overlay_url),
f'echo "export CI_JOB_JWT_FILE={args.jwt_file}" >> /set-job-env-vars.sh',
'exec /init-stage2.sh',
]
test['definitions'][0]['repository']['run']['steps'] = init_lines
values['actions'] = [
{ 'deploy': deploy },
@ -376,6 +375,11 @@ def retriable_follow_job(proxy, job_definition):
)
def treat_mesa_job_name(args):
# Remove mesa job names with spaces, which breaks the lava-test-case command
args.mesa_job_name = args.mesa_job_name.split(" ")[0]
def main(args):
proxy = setup_lava_proxy()
@ -393,8 +397,9 @@ def main(args):
if args.validate_only:
return
ret = retriable_follow_job(proxy, job_definition)
sys.exit(ret)
has_job_passed = retriable_follow_job(proxy, job_definition)
exit_code = 0 if has_job_passed else 1
sys.exit(exit_code)
def create_parser():
@ -418,6 +423,7 @@ def create_parser():
parser.add_argument("--validate-only", action='store_true')
parser.add_argument("--dump-yaml", action='store_true')
parser.add_argument("--visibility-group")
parser.add_argument("--mesa-job-name")
return parser
@ -432,4 +438,5 @@ if __name__ == "__main__":
parser.set_defaults(func=main)
args = parser.parse_args()
treat_mesa_job_name(args)
args.func(args)