Skip to content

Commit

Permalink
Make last_good_test+last_good_build jobs run on the same worker
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
b10n1k committed Jan 26, 2024
1 parent e817747 commit 3610697
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
37 changes: 37 additions & 0 deletions openqa-investigate
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
31 changes: 19 additions & 12 deletions test/02-investigate.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source test/init
bpan:source bashplus +err +fs +sym

plan tests 79
plan tests 81

host=localhost
url=https://localhost
Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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'
Expand Down

0 comments on commit 3610697

Please sign in to comment.