-
Notifications
You must be signed in to change notification settings - Fork 1
/
upv.sh
executable file
·635 lines (539 loc) · 16.4 KB
/
upv.sh
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
#!/bin/bash
set -o pipefail
# Function to display usage/help
usage () {
echo "Usage: upv.sh [options] -o ver -n ver [-i file | jobnames]
Update lp interop scenarios in openshift-ci to run on new platform version.
NOTE: Must be executed from openshift-ci's top level directory 'release'.
Example: upv.sh -o 4.15 -n 4.16 periodic-ci-skupperproject-skupper-openshift-smoke-test-image-main-service-interconnect-ocp4.15-lp-interop-rhsi-interop-aws
Options:
Required:
-o|--old_ver ver - Old platform version.
-n|--new_ver ver - New platform version.
Optional:
-p|--platform str - Platform, str is ocp or hypershift. Default is ocp.
-l|--lp_tag str - Override default tag, -lp-interop for ocp and -lp-rosa-hypershift for hypershift
str is new tag. Searches for tag in config file name or its contents.
-t|--text - Flag input file format is text. Single job name per line.
-f|--force - Force job names to be of same version as inputted Old platform version.
-z|--z_stream - [Not implemented] Flag indicating to update old version config file to be z-stream, stream: stable
-i|--input_file file - Input file containing list of job names to update. JSON format.
See vault trigger file.
-h|--help - This message.
jobnames - Scenario's job name/s separated by a space.
"
}
# Generate name based on platform version supplied
# Input: name, old_ver, new_ver
# Output: Generated Name
gen_new_name() {
NAME=$1
OLDVER=$2
NEWVER=$3
# NEW_NAME using FMT1 (4.12)
NEW_NAME=${NAME//${OLDVER}/${NEWVER}}
# NEW_NAME using FMT2 (4-12)
E_OLD_VER=${OLDVER/./-}
E_NEW_VER=${NEWVER/./-}
NEW_NAME=${NEW_NAME//${E_OLD_VER}/${E_NEW_VER}}
# NEW_NAME using FMT3 (412)
E_OLD_VER=${OLDVER/./""}
E_NEW_VER=${NEWVER/./""}
NEW_NAME=${NEW_NAME//${E_OLD_VER}/${E_NEW_VER}}
# If same (Name not changed) then set to empty
if test "$NAME" = "$NEW_NAME"
then
NEW_NAME=""
fi
echo "$NEW_NAME"
}
# Get platform version from name
# Input: name, old_ver
# Output: version
get_ver() {
NAME=$1
VER=$2
# Set major version
major=${VER%.*}
# Set search string
sstr="^$major"
# Get version #.## or #-## or ###
version=`echo $NAME | grep -Eo '?[0-9]+([.-]+[0-9]+)?' | grep "$sstr" | head -1`
# Convert to proper format #.##
version=${version/-/.}
if [[ "$version" =~ ^[0-9]+\.+[0-9]+?$ ]]
then
echo $version
else
version=`echo $version | sed "s/$sstr/&./g"`
echo $version
fi
}
# Find config file for job name given
# Inputs: config_path, job_name
get_conf_file() {
# Set Args
CONFIG_FILE_PATH=$1
JOB_NAME=$2
# Intialize
FN=""
# Set token count
COUNT=`awk -F"-" '{print NF-1}' <<< "${JOB_NAME}"`
COUNT=$(( $COUNT + 1 ))
# Find config file based on jobs name
for (( i=3; i<=${COUNT} ; i+=1 )) ; do
# Build file name
if [ $i == 3 ]
then
FN=$(echo $JOB_NAME| cut -d'-' -f $i)
else
FN="$FN"-"$(echo $JOB_NAME| cut -d'-' -f $i)"
fi
# Check matches of file name in config file path
C_FILE=`ls $CONFIG_FILE_PATH | grep -i $FN`
NC=`wc -w <<< "$C_FILE"`
# No match then try with double underscore seperator
if [[ $NC -eq 0 ]]
then
FN=`echo "$FN" | sed 's/\(.*\)-/\1__/'`
C_FILE=`ls $CONFIG_FILE_PATH | grep -i $FN`
NC=`wc -w <<< "$C_FILE"`
fi
# Check for tag
FIRST=$(echo $JOB_NAME| cut -d'-' -f 1)
SECOND=$(echo $JOB_NAME| cut -d'-' -f 2)
JN=`echo "$FN" | sed 's/\(.*\)__/\1-/'`
JN=`echo "$FIRST-$SECOND-$JN-"`
TAG=`sed "s/$JN//" <<< "${JOB_NAME}"`
if [ -n "$TAG" ]
then
CONFS=($C_FILE)
for j in "${CONFS[@]}"
do
TAG_CONFIGS=`grep -l "$TAG" "$CONFIG_FILE_PATH/$j"`
if [ -n "$TAG_CONFIGS" ]
then
C_FILE=$j
NC=`wc -w <<< "$C_FILE"`
break
fi
done
fi
# Down to single match - We have the config
if [[ $NC -eq 1 ]]
then
break
fi
done
echo $C_FILE
}
# Initialize
DAY=$( date -d '-2 day' '+%-d' )
MONTH=$(date -d '-2 day' '+%-m' )
JOBS_ARRAY=()
# Default PLATFORM
PLATFORM="ocp"
# Default LP_TAG
LP_TAG="\-lp\-interop"
# default Z_STREAM
Z_STREAM="false"
# default FORCE
FORCE="false"
# Default FILE_FMT
FILE_FMT="json"
POSITIONAL_ARGS=()
# Process command line
while [[ $# -gt 0 ]]; do
case $1 in
-p|--platform)
PLATFORM="$2"
shift # past argument
shift # past value
;;
-l|--lp_tag)
LP_TAG="$2"
shift # past argument
shift # past value
;;
-o|--old_ver)
OLD_VER="$2"
shift # past argument
shift # past value
;;
-n|--new_ver)
NEW_VER="$2"
shift # past argument
shift # past value
;;
-i|--input_file)
INPUT_FILE="$2"
shift # past argument
shift # past value
;;
-t|--text)
FILE_FMT="txt"
shift # past argument
;;
-f|--force)
FORCE="true"
shift # past argument
;;
-z|--z_stream)
Z_STREAM="false"
shift # past argument
;;
-h|--help)
usage
exit 0
;;
-*|--*)
echo "Unknown option $1"
usage
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
if [ -z "$JOBS" ]
then
JOBS=`printf %"s\n" ${1}`
else
JOBS=`echo "$JOBS";printf %"s\n" ${1}`
fi
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
# Set LP_TAG for hypershift
if [[ $PLATFORM == "hypershift" ]]
then
LP_TAG="\-lp\-rosa\-hypershift"
fi
# INPUT VALUES
echo "CRON MONTH = ${MONTH}"
echo "CRON DAY = ${DAY}"
echo "OLD VERSION = ${OLD_VER}"
echo "NEW VERSION = ${NEW_VER}"
echo "INPUT FILE = ${INPUT_FILE}"
echo "JOB NAMES = ${JOBS}"
echo "PLATFORM = ${PLATFORM}"
echo "LP_TAG = ${LP_TAG}"
echo "PWD = " `pwd`
# Check that OLD_VER and NEW_VER platform versions supplied.
if [ -z "$OLD_VER" ] || [ -z "$NEW_VER" ]
then
echo ""
echo "ERROR: OLD and NEW Platform versions must be supplied"
echo ""
usage
exit 1
fi
# Check PLATFORM set to ocp or hypershift
if [[ $PLATFORM != "ocp" && $PLATFORM != "hypershift" ]]
then
echo ""
echo "ERROR: PLATFORM must be set to either 'ocp' or 'hypershift'"
echo ""
usage
exit 1
fi
# Check current directory is correct - Should be in release directory
DIR=${PWD/*\//}
if [[ $DIR != "release" ]]
then
echo ""
echo "ERROR: Must run from openshift-ci's top level directory: release"
echo ""
usage
exit 1
fi
# Set JOBS if input file supplied - Expected to be in format of vault trigger file
if [ ! -z "$INPUT_FILE" ]
then
# Check file exists
if ! test -f $INPUT_FILE
then
echo ""
echo "ERROR: Input file ${INPUT_FILE} dost not exist"
echo ""
useage
exit 1
fi
if [[ $FILE_FMT != "json" ]]
then
# Get list of jobs from text file, remove blank lines
JOBS=`grep '[^[:blank:]]' < "$INPUT_FILE"`
else
# Get list of jobs from json file, Should be in format of vault trigger file
# Check Valid json
if JOBS=`jq -re '.[] | select(.active == true) | .job_name' "$INPUT_FILE"`
then
echo "Parsed JSON file successfully."
else
echo "ERROR: Failed to parse JSON file, or got false/null"
echo ""
usage
exit 1
fi
fi
fi
# Check we have JOBS to process
if [ -z "$JOBS" ]
then
echo ""
echo "ERROR: No job name or input file given"
echo ""
usage
exit 1
fi
# For each ENTRY (JOB) perform the following
while IFS= read -r ENTRY; do
E_OLD_VER=""
CONFIG_FILE=""
NEW_CONFIG_FILE=""
# ENTRY single job name
# if empty get next
if [ -z "$ENTRY" ]
then
continue
fi
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
# Check version
JOB_VER=$(get_ver $ENTRY $OLD_VER)
if [[ $JOB_VER != $OLD_VER ]]
then
if [[ $FORCE == "true" ]]
then
echo "WARNING: Forcing JOB/ENTRY to be version:$OLD_VER"
ENTRY=$(gen_new_name $ENTRY $JOB_VER $OLD_VER)
else
echo "ERROR: Skipping: OLD_VER:$OLD_VER does not match version for JOB:$ENTRY"
continue
fi
fi
echo ""
echo "ENTRY = ${ENTRY}"
# JOB Location and file of ENTRY (job)
JOB=`grep -Rl --exclude='.*' $ENTRY ./ci-operator/jobs`
if [ -z "$JOB" ]
then
echo "ERROR: Skipping: JOB: ${ENTRY} does not exist"
continue
fi
echo "JOB FILE = ${JOB}"
# Set JOB_PATH and CONFIG_PATH
# JOB_PATH path of JOB's file
# CONFIG_PATH path of JOB's config file
JOB_PATH="$(dirname "${JOB}")"
CONFIG_PATH=${JOB_PATH/jobs/config}
echo "JOB PATH = ${JOB_PATH}"
NEW_JOB=$(gen_new_name $ENTRY $OLD_VER $NEW_VER)
echo "NEW JOB = ${NEW_JOB}"
echo "CONFIG PATH = ${CONFIG_PATH}"
# Get CONFIG_FILE using job name
CONFIG_FILE="$(get_conf_file $CONFIG_PATH $ENTRY)"
if test "$CONFIG_FILE" = ""
then
# Find CONFIG_FILE in CONFIG_PATH Searching for files with LP_TAG, PLATFORM and OLD_VER
CONFIG_FILE=`ls $CONFIG_PATH | grep -i $LP_TAG | grep -i $PLATFORM | grep -i $OLD_VER || :`
fi
# No CONFIG_FILE found Get all configs with OLD_VER FMT 4*12
# Select only ones that contain LP_TAG
if test "$CONFIG_FILE" = ""
then
E_OLD_VER=${OLD_VER/./*}
SFILES=`find $CONFIG_PATH -name *$E_OLD_VER*`
if [ -z "$SFILES" ]
then
echo "WARNING: No config file found. Verify"
continue
fi
CONFIG_FILE=`grep -l $LP_TAG $(find $CONFIG_PATH -name *$E_OLD_VER*)`
CONFIGS=($CONFIG_FILE)
for i in "${!CONFIGS[@]}"
do
CONFIGS[$i]=`basename ${CONFIGS[$i]}`
done
CONFIG_FILE=$(printf " %s" "${CONFIGS[@]}")
CONFIG_FILE=${CONFIG_FILE:1}
fi
# If more than 1 config found get PROD from scenario label
# If ENTRY contains PROD then we have our config
NUM_CONFIGS=`wc -w <<< "$CONFIG_FILE"`
if [[ $NUM_CONFIGS -gt 1 ]]
then
echo "More than one"
CONFIGS=($CONFIG_FILE)
IFS=$'\n' CONFIGS=($(sort -r <<<"${CONFIGS[*]}"))
unset IFS
CONFIG_FILE=""
for i in "${CONFIGS[@]}"
do
PROD=`sed -n -e 's/^.*scenario //p' $CONFIG_PATH/$i`
if [ -z "$PROD" ]
then
PROD=`sed "s/__/&\n/;s/.*\n//;s/-$PLATFORM/\n&/;s/\n.*//;s/.yaml/\n&/;s/\n.*//" <<< "$i"`
fi
echo "PROD = ${PROD}"
if [[ $ENTRY == *"$PROD"* ]]
then
CONFIG_FILE=$i
break
fi
# do whatever on $i
done
fi
if test "$CONFIG_FILE" = ""
then
echo "ERROR: No Config file found"
continue
fi
NEW_CONFIG_FILE=$(gen_new_name $CONFIG_FILE $OLD_VER $NEW_VER)
# Print old and new CONFIG_FILE
echo "CONFIG FILE = ${CONFIG_FILE}"
echo "NEW CONFIG FILE = ${NEW_CONFIG_FILE}"
# Check if config file exists for old version
if ! test -f $CONFIG_PATH/$CONFIG_FILE
then
echo "WARNING: ${CONFIG_PATH}/${CONFIG_FILE}. Does not exist. Verify"
continue
fi
# Check if new config file exists and give warning
if test -f $CONFIG_PATH/$NEW_CONFIG_FILE
then
echo "WARNING: ${CONFIG_PATH}/${NEW_CONFIG_FILE}. File exists. Will be overwritten and updated"
fi
# Copy config from old to new
cp $CONFIG_PATH/$CONFIG_FILE $CONFIG_PATH/$NEW_CONFIG_FILE
# Set version to be sed correct
SED_OLD_VER=${OLD_VER/./\\.}
SED_NEW_VER=${NEW_VER/./\\.}
# Update version in config file
sed -i "s/$SED_OLD_VER/$SED_NEW_VER/g" $CONFIG_PATH/$NEW_CONFIG_FILE
# Update alternate fmt2
E_OLD_VER=${OLD_VER/./-}
E_NEW_VER=${NEW_VER/./-}
# Set version to be sed correct
SED_E_OLD_VER=${E_OLD_VER/./\\.}
SED_E_NEW_VER=${E_NEW_VER/./\\.}
sed -i "s/$SED_E_OLD_VER/$SED_E_NEW_VER/g" $CONFIG_PATH/$NEW_CONFIG_FILE
# Update alternate fmt3
E_OLD_VER=${OLD_VER/./""}
E_NEW_VER=${NEW_VER/./""}
# Set version to be sed correct
SED_E_OLD_VER=${E_OLD_VER/./\\.}
SED_E_NEW_VER=${E_NEW_VER/./\\.}
sed -i "s/$SED_E_OLD_VER/$SED_E_NEW_VER/g" $CONFIG_PATH/$NEW_CONFIG_FILE
# Handle any special processing for scnearios here....
# Scenarios With Special processing
if [[ $CONFIG_PATH == *"service-binding-operator"* ]]; then
NEW_TAG=--tags=~@disable-openshift-$NEW_VER+
ADD_TAG=--tags=~@disable-openshift-$OLD_VER+
GREP_TAG="\\"
GREP_TAG+=$NEW_TAG
TAG_COUNT=`grep -o $GREP_TAG $CONFIG_PATH/$NEW_CONFIG_FILE | wc -l`
if [[ $TAG_COUNT -gt 1 ]]
then
sed -i "s/$NEW_TAG/$ADD_TAG/" $CONFIG_PATH/$NEW_CONFIG_FILE
else
sed -i "s/$NEW_TAG/$ADD_TAG $NEW_TAG/" $CONFIG_PATH/$NEW_CONFIG_FILE
fi
fi
# Find cron and update
CRON=`grep -i cron: $CONFIG_PATH/$NEW_CONFIG_FILE`
CRON="${CRON//\*}"
while IFS= read -r i; do
NEW_CRON="${i%:*}: 0 6 $(($DAY)) $MONTH "
echo "CRON = ${i}"
echo "NEW CRON = ${NEW_CRON}"
sed -i "s/$i/$NEW_CRON/g" $CONFIG_PATH/$NEW_CONFIG_FILE
done < <(echo "$CRON")
# Update old version to be z-stream stream: stable
if [[ $Z_STREAM == "true" ]]
then
sed -i "s/stream: nightly/stream: stable/g" $CONFIG_PATH/$CONFIG_FILE
git add $CONFIG_PATH/$CONFIG_FILE
fi
# Git add new config file
git add $CONFIG_PATH/$NEW_CONFIG_FILE
JOBS_ARRAY+=("${ENTRY}")
JOBS_ARRAY+=("${JOB}")
JOBS_ARRAY+=("${NEW_JOB}")
done < <(echo "$JOBS")
# Completed updating all config files perform a make update
echo ""
echo "--------------------------------------------------------------------------------"
echo ""
if [[ ${#JOBS_ARRAY[@]} > 0 ]]
then
make update
fi
# Update all JOB files new entry with NOTIFICATION
for (( i=0; i<${#JOBS_ARRAY[@]} ; i+=3 )) ; do
OLD_JOBNAME="${JOBS_ARRAY[i]}"
NEW_JOBNAME="${JOBS_ARRAY[i+2]}"
OLD_JOB="${JOBS_ARRAY[i+1]}"
NEW_JOB=$OLD_JOB
# FMT 1
TEST_JOB=${OLD_JOB//${OLD_VER}/${NEW_VER}}
if test -f $TEST_JOB
then
NEW_JOB=$TEST_JOB
PRESUBMITS=${NEW_JOB/periodics/presubmits}
else
# FMT 2
T_OLD_VER=${OLD_VER/./-}
T_NEW_VER=${NEW_VER/./-}
TEST_JOB=${OLD_JOB//${T_OLD_VER}/${T_NEW_VER}}
if test -f $TEST_JOB
then
NEW_JOB=$TEST_JOB
PRESUBMITS=${NEW_JOB/periodics/presubmits}
else
# FMT 3
T_OLD_VER=${OLD_VER/./""}
T_NEW_VER=${NEW_VER/./""}
TEST_JOB=${OLD_JOB//${T_OLD_VER}/${T_NEW_VER}}
if test -f $TEST_JOB
then
NEW_JOB=$TEST_JOB
PRESUBMITS=${NEW_JOB/periodics/presubmits}
fi
fi
fi
# Get Notification setting from old job
NOTIFICATION=`sed -n "/${OLD_JOBNAME}/,/spec:/{/${OLD_JOBNANE}/b;/spec/b;p}" $OLD_JOB`
echo "NEW JOB = ${NEW_JOB}"
echo "NOTIFICATION = ${NOTIFICATION}"
echo ""
# Save notification to tmp file
echo "$NOTIFICATION" > tmp_slack.txt
# Get Notification setting from new job
CHECK_NOTIFICATION=`sed -n "/${NEW_JOBNAME}/,/spec:/{/${NEW_JOBNAME}/b;/spec/b;p}" $NEW_JOB`
# If no Notification then add to new job
if [ -n "$NOTIFICATION" ] && [ -z "$CHECK_NOTIFICATION" ]
then
sed -i "/${NEW_JOBNAME}/r tmp_slack.txt" $NEW_JOB
fi
# Cleanup/delete tmp file
rm tmp_slack.txt
# git add new job
git add $NEW_JOB
# git add persubmits job file if exist
if test -f $PRESUBMITS
then
git add $PRESUBMITS
fi
# Update old files to be z-stream if flag set
if [[ $Z_STREAM == "true" ]]
then
git add $OLD_JOB
OLD_PRESUBMITS=${OLD_JOB/periodics/presubmits}
if test -f $OLD_PRESUBMITS
then
git add $OLD_PRESUBMITS
fi
fi
done