From 3610697c063985099d9192d8eb04e38c0dfed0e1 Mon Sep 17 00:00:00 2001 From: ybonatakis Date: Tue, 23 Jan 2024 17:35:28 +0100 Subject: [PATCH] Make last_good_test+last_good_build jobs run on the same worker Assign the WORKER_CLASS used in the settings if this is present in the vars.json. https://progress.opensuse.org/issues/152853 Signed-off-by: ybonatakis --- openqa-investigate | 37 +++++++++++++++++++++++++++++++++++++ test/02-investigate.t | 31 +++++++++++++++++++------------ 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/openqa-investigate b/openqa-investigate index 205c65be..22bfa697 100755 --- a/openqa-investigate +++ b/openqa-investigate @@ -58,6 +58,15 @@ clone() { [[ $casedir == null ]] && casedir='' repo=${casedir:-'https://github.com/os-autoinst/os-autoinst-distri-opensuse.git'} clone_settings+=("CASEDIR=${repo%#*}#${refspec}") + if [[ $name_suffix =~ (last_good_tests_and_build) ]]; then + get_worker_settings worker_settings + if [[ "$worker_settings" != null ]]; then + clone_settings+=("WORKER_CLASS=${worker_settings}") + name+="(worker:${worker_settings})" + else + name+="(unidentified worker class)" + fi + fi fi [[ -n ${*:5} ]] && clone_settings+=("${@:5}") # clear "PUBLISH_" settings to avoid overriding production assets @@ -83,6 +92,34 @@ clone() { done } +get_worker_settings() { + declare -n worker=$1 + local ret + worker_vars_json=$(echo "$vars_json" | runjq -r '.WORKER_CLASS') || return $? + # Nothing to do if worker_class is not defined + if [[ $worker_vars_json == null ]]; then + ret=$? + fi + # get worker_class from settings to compare with vars.json + workerclass_in_settings=$(echo "$clone_job_data" | runjq -r '.job.settings.WORKER_CLASS') || return $? + # if workers from settings has more than one worker iterate and verify existence + if (echo "${workerclass_in_settings}" | grep -q ','); then + mapfile -td ',' workers_settings < <(echo "${workerclass_in_settings}") + mapfile -td ',' workers < <(echo "${worker_vars_json}") + for worker_item in "${workers_settings[@]}"; do + # check if worker is in the vars.json + if [[ "${workers[*]}" =~ $worker_item ]]; then + worker+=" ${worker_item}" && ret=$? + else + worker+=" unidentified worker ${worker_item}" && ret=$? + fi + done + else + worker="${workerclass_in_settings}" && ret=$? + fi + return "$ret" +} + trigger_jobs() { id="${1:?"Need 'job_id'"}" # for 1. current job/build + current test -> check if reproducible/sporadic diff --git a/test/02-investigate.t b/test/02-investigate.t index ab3d3860..c79d3a01 100644 --- a/test/02-investigate.t +++ b/test/02-investigate.t @@ -3,7 +3,7 @@ source test/init bpan:source bashplus +err +fs +sym -plan tests 79 +plan tests 81 host=localhost url=https://localhost @@ -17,6 +17,16 @@ openqa-cli() { } client_call=(openqa-cli) +fetch-vars-json() { + local tid=$1 + if [[ $tid -eq 10020 ]]; then + echo '{"TEST_GIT_URL": "https://github.com/os-autoinst/os-autoinst-distri-openQA.git"}' + elif [[ $tid -eq 10022 ]]; then + echo '{"WORKER_CLASS": "foo,duh,bar"}' + else + echo '{}' + fi +} rc=0 out=$(clone 41 42 2>&1 > /dev/null) || rc=$? is "$rc" 1 'fails when unable to query job data' @@ -32,8 +42,10 @@ openqa-cli() { # GET jobs/id if [[ "$1 $2" == "--json jobs/10024" ]]; then echo '{"job": { "test": "vim", "priority": 50, "settings" : {} } }' + elif [[ "$1 $2" == "--json jobs/10022" ]]; then + echo '{"job": { "test": "vim", "priority": "50", "settings": { "WORKER_CLASS": "duh"} } }' elif [[ "$1 $2" == "--json jobs/10030" ]]; then - echo '{"job": { "test": "vim", "priority": "50", "settings":{"CASEDIR": "https://github.com/os-autoinst/os-autoinst-testrepo.git"} } }' + echo '{"job": { "test": "vim", "priority": "50", "settings":{"CASEDIR": "https://github.com/os-autoinst/os-autoinst-testrepo.git", "WORKER_CLASS": "duh"} } }' elif [[ "$1 $2" == "--json jobs/10027" ]]; then echo '{"job": { "test": "vim", "clone_id" : 10028 } }' elif [[ "$1 $2" == "--json jobs/3000" ]]; then @@ -135,15 +147,6 @@ _clone_call() { echo "$@" >&2 } -fetch-vars-json() { - local tid=$1 - if [[ $tid -eq 10020 ]]; then - echo '{"TEST_GIT_URL": "https://github.com/os-autoinst/os-autoinst-distri-openQA.git"}' - else - echo '{}' - fi -} - clone_call=_clone_call try clone 10023 10024 is "$rc" 0 "Successful clone" @@ -159,10 +162,14 @@ try clone 10020 10024 foo refspec is "$rc" 0 "Successful clone" like "$got" 'CASEDIR=.*/os-autoinst-distri-openQA.git#refspec' "job is cloned with sets CASEDIR from TEST_GIT_URL" -try clone 10023 10030 foo refspec +try clone 10024 10030 foo refspec is "$rc" 0 "Successful clone" like "$got" 'CASEDIR=.*/os-autoinst-testrepo.git#refspec' "job is cloned and CASEDIR is set correctly" +try clone 10022 10030 last_good_tests_and_build:123 refspec +has "$got" 'WORKER_CLASS=duh' "job assigns the same WORKER_CLASS" +has "$got" "last_good_tests_and_build:123(worker:duh)*" "worker appears in last_good_tests name" + clone_call=echo try investigate 10027 is "$rc" 0 'success regardless of actually triggered jobs'