-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtrigger-openqa_in_openqa
More file actions
executable file
·170 lines (152 loc) · 6.63 KB
/
trigger-openqa_in_openqa
File metadata and controls
executable file
·170 lines (152 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash -ex
set -euo pipefail
# configuration variables with defaults.
color=${color:-auto}
target_host="${target_host:-"openqa.opensuse.org"}"
target_host_proto="${target_host_proto:-"https"}"
dry_run="${dry_run:-"0"}"
tw_openqa_host="${tw_openqa_host:-"https://openqa.opensuse.org"}"
tw_group_id="${tw_group_id:-"1"}"
openqa_cli=${openqa_cli:-retry -e -- openqa-cli}
arch="${arch:-"x86_64"}"
machine="${machine:-"uefi"}"
build_tag=${BUILD_TAG:-}
client_prefix=${client_prefix:-}
flavor=${flavor:-"dev"}
full_run=${FULL:-}
full_run_args=${full_run_args:-}
group_id="${group_id:-"openQA"}"
osc=${osc:-retry -e -- osc}
src_project=${src_project:-devel:openQA}
staging_project=${staging_project:-${src_project}:testing}
dst_project=${dst_project:-${src_project}:tested}
submit_target=${submit_target:-openSUSE:Factory}
scenario_definitions="${scenario_definitions:-"scenario-definitions.yaml"}"
# shellcheck source=/dev/null
. "$(dirname "$0")"/_common
usage() {
cat << EOF
Usage: $0 [OPTIONS]
Triggers tests on an openQA instance testing openQA itself.
Can be configured additionally with environment variables.
Options:
-h, --help display this help
EOF
exit "$1"
}
main() {
opts=$(getopt -o h -l help -n "$0" -- "$@") || usage 1
eval set -- "$opts"
while true; do
case "$1" in
-h | --help) usage 0 ;;
--)
shift
break
;;
*) break ;;
esac
done
[[ $dry_run == 1 ]] && client_prefix="echo" osc="echo $osc"
local qcow build rc=0
download_scenario
download_latest_published_tumbleweed_image
# Only use devel:openQA:testing for the hourly runs which we monitor
# and use for submit requests
if [[ $full_run ]]; then
staging_project=$src_project
flavor="dev-full" # Note: overrides any user-provided flavor
else
create_devel_openqa_snapshot || rc=$?
if [[ $rc != 0 ]]; then
# clean staging project in case the snapshot creation failed so we don't leave the staging project in an intermediate state
# note: This is best-effort as it might fail as well if the problem is OBS being down (for long enough so retries didn't help).
cleanup-obs-project "$staging_project" 'I am sure'
return "$rc"
fi
fi
trigger
}
download_latest_published_tumbleweed_image() {
qcow=$(find_latest_published_tumbleweed_image "$tw_group_id" "$arch" "$machine" qcow)
if [ "$target_host_proto://$target_host" != "$tw_openqa_host" ]; then
url="${tw_openqa_host}/assets/hdd/${qcow}"
# instead of manual wget it should also work to provide a whitelisted url to openqa as HDD_1_URL which should then download it itself but a first experiment didn't work
${client_prefix} wget -c "$url" -O /var/lib/openqa/factory/hdd/"$qcow"
fi
# ensure the build tag conforms to coolo's unwritten rules for the openQA dashboard
build=$(echo "$build_tag" | sed -e "s/jenkins-trigger-openQA_in_openQA-/:/" -e "s/-/./g")
}
download_scenario() {
rm -f /var/tmp/sd.yaml
curl https://raw.githubusercontent.com/os-autoinst/os-autoinst-distri-openQA/master/"${scenario_definitions}" -o /var/tmp/sd.yaml
}
create_snapshots() {
local package=$1
log-info "Creating snapshots of $package"
$osc release --no-delay --target-project "$staging_project" --target-repository=openSUSE_Tumbleweed -r openSUSE_Tumbleweed -a x86_64 "$src_project" "$package"
}
sync_changesrevision() {
log-info "sync_changesrevision $*"
local dir=$1
local package=$2
local target_rev=$3
path="$dir/$package"
$client_prefix xmlstarlet ed -L -u "//param[@name='changesrevision']" -v "$target_rev" "$path"/_servicedata
if ! diff -u "$path"/.osc/_servicedata "$path"/_servicedata; then
debug_osc up "$path"
debug_osc cat "$submit_target" "$package" "$package".changes > "$path/$package".changes
debug_osc ci -m "sync changesrevision with $submit_target" "$path"
debug_osc up --server-side-source-service-files "$path"
fi
}
create_devel_openqa_snapshot() {
local auto_submit_packages staged_packages target_rev
auto_submit_packages=$(list_packages "$dst_project")
staged_packages=$(list_packages "$staging_project") || true # osc ls returns non-zero return code for empty projects
if [[ $staged_packages ]]; then
echo "+++ NOTE+++ Only triggering tests from $src_project (not overriding $staging_project and doing a submission) because $staging_project still contains packages. You might need to do a manual cleanup if no other pipeline is running. Packages: $staged_packages" \
| tee job_post_skip_submission
staging_project=$src_project
return
elif [[ -e job_post_skip_submission ]]; then
rm job_post_skip_submission
fi
log-info "Checking if all relevant packages are built and published before creating snapshot under $staging_project"
for package in $auto_submit_packages; do
local state
state=$($osc results -r openSUSE_Tumbleweed -a x86_64 --no-multibuild "$src_project" "$package")
if grep -q -v 'succeeded\|disabled' <<< "$state"; then
echo -e "Package $package is not yet ready for release\n$state" | tee job_post_skip_submission
delete_packages_from_obs_project "$staging_project"
return
fi
target_rev=$(last_revision "$submit_target" "$package")
debug_osc co --server-side-source-service-files "$src_project"/"$package"
sync_changesrevision "$src_project" "$package" "$target_rev"
create_snapshots "$package"
done
log-info "Wait until all packages are published under $staging_project"
$osc prjresults --watch --xml -r openSUSE_Tumbleweed -a x86_64 "$staging_project"
}
trigger() {
# prevent host access problem when running within o3 infrastructure
# where o3 is not reachable over https
declare -a ARGS
[[ $target_host = "openqa.opensuse.org" ]] && ARGS+=("OPENQA_HOST=http://openqa.opensuse.org")
# shellcheck disable=SC2206
[[ $full_run_args ]] && ARGS+=($full_run_args)
# shellcheck disable=SC2086
${client_prefix} ${openqa_cli} \
schedule --host "${target_host_proto}://${target_host}" \
--param-file SCENARIO_DEFINITIONS_YAML=/var/tmp/sd.yaml \
VERSION=Tumbleweed \
DISTRI=openqa FLAVOR="${flavor}" ARCH="${arch}" \
HDD_1="$qcow" BUILD="${build}" _GROUP="${group_id}" \
OPENQA_OBS_PROJECT="$staging_project" \
"${ARGS[@]}" \
| tee full_job_post_response
head -1 full_job_post_response > job_post_response
rm full_job_post_response
}
caller 0 > /dev/null || main "$@"