ci/lava: Add bridge function for job definition
To use the supported job definition depending on some Mesa CI job characteristics. The strategy here, is to use LAVA with a containerized SSH session to follow the job output, escaping from dumping data to the UART, which proves to be error prone in some devices. Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22870>
This commit is contained in:

committed by
Marge Bot

parent
02d07f3380
commit
8626a52637
@@ -27,20 +27,15 @@ Therefore, we have divided the job definition into four parts:
|
||||
script after sourcing "dut-env-vars.sh" again for the second SSH test case.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from ruamel.yaml.scalarstring import LiteralScalarString
|
||||
|
||||
# How many attempts should be made when a timeout happen during LAVA device boot.
|
||||
NUMBER_OF_ATTEMPTS_LAVA_BOOT = int(getenv("LAVA_NUMBER_OF_ATTEMPTS_LAVA_BOOT", 3))
|
||||
|
||||
# Supports any integers in [0, 100].
|
||||
# The scheduler considers the job priority when ordering the queue
|
||||
# to consider which job should run next.
|
||||
JOB_PRIORITY = int(getenv("LAVA_JOB_PRIORITY", 75))
|
||||
from .lava_job_definition import (
|
||||
artifact_download_steps,
|
||||
to_yaml_block,
|
||||
generate_metadata,
|
||||
NUMBER_OF_ATTEMPTS_LAVA_BOOT,
|
||||
)
|
||||
|
||||
# Very early SSH server setup. Uses /dut_ready file to flag it is done.
|
||||
SSH_SERVER_COMMANDS = {
|
||||
@@ -83,55 +78,6 @@ lava_ssh_test_case() {
|
||||
]
|
||||
|
||||
|
||||
def to_yaml_block(steps_array: list[str], escape_vars=[]) -> LiteralScalarString:
|
||||
def escape_envvar(match):
|
||||
return "\\" + match.group(0)
|
||||
|
||||
filtered_array = [s for s in steps_array if s.strip() and not s.startswith("#")]
|
||||
final_str = "\n".join(filtered_array)
|
||||
|
||||
for escape_var in escape_vars:
|
||||
# Find env vars and add '\\' before them
|
||||
final_str = re.sub(rf"\${escape_var}*", escape_envvar, final_str)
|
||||
return LiteralScalarString(final_str)
|
||||
|
||||
|
||||
def artifact_download_steps(args):
|
||||
"""
|
||||
This function is responsible for setting up the SSH server in the DUT and to
|
||||
export the first boot environment to a file.
|
||||
"""
|
||||
# Putting JWT pre-processing and mesa download, within init-stage1.sh file,
|
||||
# as we do with non-SSH version.
|
||||
download_steps = [
|
||||
"set -ex",
|
||||
"source /dut-env-vars.sh",
|
||||
"curl -L --retry 4 -f --retry-all-errors --retry-delay 60 "
|
||||
f"{args.job_rootfs_overlay_url} | tar -xz -C /",
|
||||
f"mkdir -p {args.ci_project_dir}",
|
||||
f"curl -L --retry 4 -f --retry-all-errors --retry-delay 60 {args.build_url} | "
|
||||
f"tar --zstd -x -C {args.ci_project_dir}",
|
||||
]
|
||||
|
||||
# If the JWT file is provided, we will use it to authenticate with the cloud
|
||||
# storage provider and will hide it from the job output in Gitlab.
|
||||
if args.jwt_file:
|
||||
with open(args.jwt_file) as jwt_file:
|
||||
download_steps += [
|
||||
"set +x",
|
||||
f'echo -n "{jwt_file.read()}" > "{args.jwt_file}" # HIDEME',
|
||||
"set -x",
|
||||
f'echo "export CI_JOB_JWT_FILE={args.jwt_file}" >> /set-job-env-vars.sh',
|
||||
]
|
||||
else:
|
||||
download_steps += [
|
||||
"echo Could not find jwt file, disabling S3 requests...",
|
||||
"sed -i '/MINIO_RESULTS_UPLOAD/d' /set-job-env-vars.sh",
|
||||
]
|
||||
|
||||
return download_steps
|
||||
|
||||
|
||||
def generate_dut_test(args):
|
||||
# Commands executed on DUT.
|
||||
# Trying to execute the minimal number of commands, because the console data is
|
||||
@@ -200,6 +146,7 @@ def generate_docker_test(args):
|
||||
to_yaml_block(
|
||||
(
|
||||
"lava_ssh_test_case 'artifact_download' 'bash --' << EOF",
|
||||
"source /dut-env-vars.sh",
|
||||
*artifact_download_steps(args),
|
||||
"EOF",
|
||||
)
|
||||
@@ -216,38 +163,7 @@ def generate_docker_test(args):
|
||||
|
||||
|
||||
def generate_lava_yaml_payload(args) -> dict[str, Any]:
|
||||
# General metadata and permissions
|
||||
values = {
|
||||
"job_name": f"mesa: {args.pipeline_info}",
|
||||
"device_type": args.device_type,
|
||||
"visibility": {"group": [args.visibility_group]},
|
||||
"priority": JOB_PRIORITY,
|
||||
"context": {
|
||||
"extra_nfsroot_args": " init=/init rootwait usbcore.quirks=0bda:8153:k"
|
||||
},
|
||||
"timeouts": {
|
||||
"job": {"minutes": args.job_timeout_min},
|
||||
"actions": {
|
||||
"depthcharge-retry": {
|
||||
# Could take between 1 and 1.5 min in slower boots
|
||||
"minutes": 4
|
||||
},
|
||||
"depthcharge-start": {
|
||||
# Should take less than 1 min.
|
||||
"minutes": 1,
|
||||
},
|
||||
"depthcharge-action": {
|
||||
# This timeout englobes the entire depthcharge timing,
|
||||
# including retries
|
||||
"minutes": 5
|
||||
* NUMBER_OF_ATTEMPTS_LAVA_BOOT,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if args.lava_tags:
|
||||
values["tags"] = args.lava_tags.split(",")
|
||||
values = generate_metadata(args)
|
||||
|
||||
# URLs to our kernel rootfs to boot from, both generated by the base
|
||||
# container build
|
||||
|
Reference in New Issue
Block a user