lava-submit.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: MIT
  3. # shellcheck disable=SC2086 # we want word splitting
  4. # shellcheck disable=SC1091 # paths only become valid at runtime
  5. # If we run in the fork (not from mesa or Marge-bot), reuse mainline kernel and rootfs, if exist.
  6. _check_artifact_path() {
  7. _url="https://${1}/${2}"
  8. if curl -s -o /dev/null -I -L -f --retry 4 --retry-delay 15 "${_url}"; then
  9. echo -n "${_url}"
  10. fi
  11. }
  12. get_path_to_artifact() {
  13. _mainline_artifact="$(_check_artifact_path ${BASE_SYSTEM_MAINLINE_HOST_PATH} ${1})"
  14. if [ -n "${_mainline_artifact}" ]; then
  15. echo -n "${_mainline_artifact}"
  16. return
  17. fi
  18. _fork_artifact="$(_check_artifact_path ${BASE_SYSTEM_FORK_HOST_PATH} ${1})"
  19. if [ -n "${_fork_artifact}" ]; then
  20. echo -n "${_fork_artifact}"
  21. return
  22. fi
  23. set +x
  24. error "Sorry, I couldn't find a viable built path for ${1} in either mainline or a fork." >&2
  25. echo "" >&2
  26. echo "If you're working on CI, this probably means that you're missing a dependency:" >&2
  27. echo "this job ran ahead of the job which was supposed to upload that artifact." >&2
  28. echo "" >&2
  29. echo "If you aren't working on CI, please ping @mesa/ci-helpers to see if we can help." >&2
  30. echo "" >&2
  31. echo "This job is going to fail, because I can't find the resources I need. Sorry." >&2
  32. set -x
  33. exit 1
  34. }
  35. . "${SCRIPTS_DIR}/setup-test-env.sh"
  36. section_start prepare_rootfs "Preparing root filesystem"
  37. set -ex
  38. ROOTFS_URL="$(get_path_to_artifact lava-rootfs.tar.zst)"
  39. [ $? != 1 ] || exit 1
  40. rm -rf results
  41. mkdir -p results/job-rootfs-overlay/
  42. artifacts/ci-common/export-gitlab-job-env-for-dut.sh \
  43. > results/job-rootfs-overlay/set-job-env-vars.sh
  44. cp artifacts/ci-common/init-*.sh results/job-rootfs-overlay/
  45. cp "$SCRIPTS_DIR"/setup-test-env.sh results/job-rootfs-overlay/
  46. tar zcf job-rootfs-overlay.tar.gz -C results/job-rootfs-overlay/ .
  47. ci-fairy s3cp --token-file "${S3_JWT_FILE}" job-rootfs-overlay.tar.gz "https://${JOB_ROOTFS_OVERLAY_PATH}"
  48. # Prepare env vars for upload.
  49. section_switch variables "Environment variables passed through to device:"
  50. cat results/job-rootfs-overlay/set-job-env-vars.sh
  51. section_switch lava_submit "Submitting job for scheduling"
  52. touch results/lava.log
  53. tail -f results/lava.log &
  54. # Ensure that we are printing the commands that are being executed,
  55. # making it easier to debug the job in case it fails.
  56. set -x
  57. PYTHONPATH=artifacts/ artifacts/lava/lava_job_submitter.py \
  58. --farm "${FARM}" \
  59. --device-type "${DEVICE_TYPE}" \
  60. --boot-method "${BOOT_METHOD}" \
  61. --job-timeout-min $((CI_JOB_TIMEOUT/60 - 5)) \
  62. --dump-yaml \
  63. --pipeline-info "$CI_JOB_NAME: $CI_PIPELINE_URL on $CI_COMMIT_REF_NAME ${CI_NODE_INDEX}/${CI_NODE_TOTAL}" \
  64. --rootfs-url "${ROOTFS_URL}" \
  65. --kernel-url-prefix "https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}" \
  66. --kernel-external "${EXTERNAL_KERNEL_TAG}" \
  67. --first-stage-init artifacts/ci-common/init-stage1.sh \
  68. --dtb-filename "${DTB}" \
  69. --jwt-file "${S3_JWT_FILE}" \
  70. --kernel-image-name "${KERNEL_IMAGE_NAME}" \
  71. --kernel-image-type "${KERNEL_IMAGE_TYPE}" \
  72. --visibility-group "${VISIBILITY_GROUP}" \
  73. --lava-tags "${LAVA_TAGS}" \
  74. --mesa-job-name "$CI_JOB_NAME" \
  75. --structured-log-file "results/lava_job_detail.json" \
  76. --ssh-client-image "${LAVA_SSH_CLIENT_IMAGE}" \
  77. --project-name "${CI_PROJECT_NAME}" \
  78. --starting-section "${CURRENT_SECTION}" \
  79. --job-submitted-at "${CI_JOB_STARTED_AT}" \
  80. - append-overlay \
  81. --name=kernel-build \
  82. --url="${FDO_HTTP_CACHE_URI:-}https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}/kernel-files.tar.zst" \
  83. --compression=zstd \
  84. --path="${CI_PROJECT_DIR}" \
  85. --format=tar \
  86. - append-overlay \
  87. --name=job-overlay \
  88. --url="https://${JOB_ROOTFS_OVERLAY_PATH}" \
  89. --compression=gz \
  90. --path="/" \
  91. --format=tar \
  92. - submit \
  93. >> results/lava.log