oai-ci-vm-tool 12.9 KB
Newer Older
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
#!/bin/bash
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# *      http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */

function top_usage {
    echo "OAI CI VM script"
    echo "   Original Author: Raphael Defosseux"
    echo "   Requirements:"
    echo "     -- uvtool uvtool-libvirt apt-cacher"
    echo "     -- xenial image already synced"
    echo ""
    echo "Usage:"
    echo "------"
    echo "    oai-ci-vm-tool (-h|--help) {create,destroy,build,wait,test,report-build,report-test} ..."
    echo ""
}

function variant_usage {
    echo "    --variant enb-usrp     OR -v1"
    echo "    --variant basic-sim    OR -v2"
    echo "    --variant phy-sim      OR -v3"
    echo "    --variant cppcheck     OR -v4"
    echo "    --variant gnb-usrp     OR -v5"
Raphael Defosseux's avatar
Raphael Defosseux committed
42
    echo "    --variant nr-ue-usrp   OR -v6"
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
    echo "    --variant enb-ethernet OR -v7"
    echo "    --variant ue-ethernet  OR -v8"
}

MY_DIR=$(dirname $(readlink -f $0))
. $MY_DIR/createVM.sh
. $MY_DIR/buildOnVM.sh
. $MY_DIR/waitBuildOnVM.sh
. $MY_DIR/destroyAllRunningVM.sh
. $MY_DIR/runTestOnVM.sh
. $MY_DIR/reportBuildLocally.sh
. $MY_DIR/reportTestLocally.sh

if [ $# -lt 1 ]
then
    echo "Syntax Error: too few arguments"
    echo ""
    top_usage
    exit 1
fi

VM_TEMPLATE=ci-
JOB_NAME=XX
BUILD_ID=XX
VM_NAME=ci-enb-usrp
VM_MEMORY=2048
VM_CPU=4
ARCHIVES_LOC=enb_usrp
LOG_PATTERN=.Rel15.txt
NB_PATTERN_FILES=4
BUILD_OPTIONS="--eNB -w USRP"
KEEP_VM_ALIVE=0
RUN_OPTIONS="none"
DAEMON=0
MR_TRIG=0
PU_TRIG=0

HELP_CMD=0
CREATE_CMD=0
BUILD_CMD=0
WAIT_CMD=0
DESTROY_CMD=0
TEST_CMD=0
REPORT_BUILD_CMD=0
REPORT_TEST_CMD=0
NBARGS=0

while [[ $# -gt 0 ]]
do
key="$1"

case $key in
    -h|--help)
    HELP_CMD=1
    shift
    ;;
    create)
    CREATE_CMD=1
    # It is implied to keep the VM when creating it
    KEEP_VM_ALIVE=1
    shift
    ;;
    build)
    BUILD_CMD=1
    shift
    ;;
    wait)
    WAIT_CMD=1
    shift
    ;;
    test)
    TEST_CMD=1
    shift
    ;;
    destroy)
    DESTROY_CMD=1
    shift
    ;;
    report-build)
    REPORT_BUILD_CMD=1
    shift
    ;;
    report-test)
    REPORT_TEST_CMD=1
    shift
    ;;
    -jn|--job-name)
    JOB_NAME="$2"
    NBARGS=$[$NBARGS+1]
    shift
    shift
    ;;
    -id|--build-id)
    BUILD_ID="$2"
    NBARGS=$[$NBARGS+2]
    shift
    shift
    ;;
    -ws|--workspace)
    JENKINS_WKSP="$2"
    NBARGS=$[$NBARGS+4]
    shift
    shift
    ;;
    -k|--keep-vm-alive)
    KEEP_VM_ALIVE=1
    NBARGS=$[$NBARGS+8]
    shift
    ;;
    -D|--daemon)
    DAEMON=1
    NBARGS=$[$NBARGS+16]
    shift
    ;;
    -gu|--git-url)
    GIT_URL="$2"
    NBARGS=$[$NBARGS+32]
    shift
    shift
    ;;
    --trigger)
    TRIG="$2"
    case $TRIG in
        merge-request)
        MR_TRIG=1
        ;;
        push)
        PU_TRIG=1
        ;;
        *)
        echo ""
        echo "Syntax Error: Invalid Trigger option -> $TRIG"
        echo ""
        trigger_usage
        exit
        ;;
    esac
    NBARGS=$[$NBARGS+64]
    shift
    shift
    ;;
    -mr)
    MR_TRIG=1
    NBARGS=$[$NBARGS+64]
    shift
    ;;
    -pu)
    PU_TRIG=1
    NBARGS=$[$NBARGS+64]
    shift
    ;;
    -sb|--src-branch)
    SOURCE_BRANCH="$2"
    NBARGS=$[$NBARGS+1024]
    shift
    shift
    ;;
    -sc|--src-commit)
    SOURCE_COMMIT_ID="$2"
    NBARGS=$[$NBARGS+2048]
    shift
    shift
    ;;
    -tb|--target-branch)
    TARGET_BRANCH="$2"
    NBARGS=$[$NBARGS+4096]
    shift
    shift
    ;;
    -tc|--target-commit)
    TARGET_COMMIT_ID="$2"
    NBARGS=$[$NBARGS+8192]
    shift
    shift
    ;;
    -br|--branch)
    SOURCE_BRANCH="$2"
    NBARGS=$[$NBARGS+16384]
    shift
    shift
    ;;
    -co|--commit)
    SOURCE_COMMIT_ID="$2"
    NBARGS=$[$NBARGS+32768]
    shift
    shift
    ;;
    -v1)
    VM_NAME=ci-enb-usrp
    ARCHIVES_LOC=enb_usrp
    LOG_PATTERN=.Rel15.txt
    NB_PATTERN_FILES=4
    BUILD_OPTIONS="--eNB -w USRP --mu"
    NBARGS=$[$NBARGS+256]
    shift
    ;;
    -v2)
    VM_NAME=ci-basic-sim
    ARCHIVES_LOC=basic_sim
    LOG_PATTERN=basic_simulator
    NB_PATTERN_FILES=2
    BUILD_OPTIONS="--basic-simulator"
    VM_MEMORY=8192
    VM_CPU=4
    RUN_OPTIONS="complex"
    NBARGS=$[$NBARGS+256]
    shift
    ;;
    -v3)
    VM_NAME=ci-phy-sim
    ARCHIVES_LOC=phy_sim
    LOG_PATTERN=.Rel15.txt
Padarthi Naga Prasanth 's avatar
CI fix    
Padarthi Naga Prasanth committed
255
    NB_PATTERN_FILES=11
256
    BUILD_OPTIONS="--phy_simulators"
257
    VM_MEMORY=8192
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
    RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b"
    NBARGS=$[$NBARGS+256]
    shift
    ;;
    -v4)
    VM_NAME=ci-cppcheck
    VM_MEMORY=8192
    ARCHIVES_LOC=cppcheck
    LOG_PATTERN=cppcheck.xml
    NB_PATTERN_FILES=1
    BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2 -i openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c"
    NBARGS=$[$NBARGS+256]
    shift
    ;;
    -v5)
    VM_NAME=ci-gnb-usrp
    ARCHIVES_LOC=gnb_usrp
    LOG_PATTERN=.Rel15.txt
    NB_PATTERN_FILES=4
    BUILD_OPTIONS="--gNB -w USRP"
    NBARGS=$[$NBARGS+256]
    shift
    ;;
    -v6)
    VM_NAME=ci-ue-nr-usrp
    ARCHIVES_LOC=nrue_usrp
    LOG_PATTERN=.Rel15.txt
    NB_PATTERN_FILES=4
    BUILD_OPTIONS="--nrUE -w USRP"
    NBARGS=$[$NBARGS+256]
    shift
    ;;
    -v7)
    VM_NAME=ci-enb-ethernet
    ARCHIVES_LOC=enb_eth
    LOG_PATTERN=.Rel15.txt
    NB_PATTERN_FILES=6
    BUILD_OPTIONS="--eNB -t ETHERNET --noS1"
    NBARGS=$[$NBARGS+256]
    shift
    ;;
    -v8)
    VM_NAME=ci-ue-ethernet
    ARCHIVES_LOC=ue_eth
    LOG_PATTERN=.Rel15.txt
    NB_PATTERN_FILES=6
    BUILD_OPTIONS="--UE -t ETHERNET --noS1"
    NBARGS=$[$NBARGS+256]
    shift
    ;;
    --variant)
    variant="$2"
    case $variant in
        enb-usrp)
        VM_NAME=ci-enb-usrp
        ARCHIVES_LOC=enb_usrp
        LOG_PATTERN=.Rel15.txt
        NB_PATTERN_FILES=4
        BUILD_OPTIONS="--eNB -w USRP --mu"
        NBARGS=$[$NBARGS+256]
        ;;
        basic-sim)
        VM_NAME=ci-basic-sim
        ARCHIVES_LOC=basic_sim
        LOG_PATTERN=basic_simulator
        NB_PATTERN_FILES=2
        BUILD_OPTIONS="--basic-simulator"
        VM_MEMORY=8192
        VM_CPU=4
        RUN_OPTIONS="complex"
        NBARGS=$[$NBARGS+256]
        ;;
        phy-sim)
        VM_NAME=ci-phy-sim
        ARCHIVES_LOC=phy_sim
        LOG_PATTERN=.Rel15.txt
Padarthi Naga Prasanth 's avatar
CI fix    
Padarthi Naga Prasanth committed
334
        NB_PATTERN_FILES=11
335
        BUILD_OPTIONS="--phy_simulators"
336
	VM_MEMORY=8192
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
        RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b"
        NBARGS=$[$NBARGS+256]
        ;;
        cppcheck)
        VM_NAME=ci-cppcheck
        VM_MEMORY=8192
        ARCHIVES_LOC=cppcheck
        LOG_PATTERN=cppcheck.xml
        NB_PATTERN_FILES=1
        BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2 -i openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c"
        NBARGS=$[$NBARGS+256]
        ;;
        gnb-usrp)
        VM_NAME=ci-gnb-usrp
        ARCHIVES_LOC=gnb_usrp
        LOG_PATTERN=.Rel15.txt
        NB_PATTERN_FILES=4
        BUILD_OPTIONS="--gNB -w USRP"
        NBARGS=$[$NBARGS+256]
        ;;
Raphael Defosseux's avatar
Raphael Defosseux committed
357
        nr-ue-usrp)
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
        VM_NAME=ci-ue-nr-usrp
        ARCHIVES_LOC=nrue_usrp
        LOG_PATTERN=.Rel15.txt
        NB_PATTERN_FILES=4
        BUILD_OPTIONS="--nrUE -w USRP"
        NBARGS=$[$NBARGS+256]
        ;;
        enb-ethernet)
        VM_NAME=ci-enb-ethernet
        ARCHIVES_LOC=enb_eth
        LOG_PATTERN=.Rel15.txt
        NB_PATTERN_FILES=6
        BUILD_OPTIONS="--eNB -t ETHERNET --noS1"
        NBARGS=$[$NBARGS+256]
        ;;
        ue-ethernet)
        VM_NAME=ci-ue-ethernet
        ARCHIVES_LOC=ue_eth
        LOG_PATTERN=.Rel15.txt
        NB_PATTERN_FILES=6
        BUILD_OPTIONS="--UE -t ETHERNET --noS1"
        NBARGS=$[$NBARGS+256]
        ;;
        *)
        echo ""
        echo "Syntax Error: Invalid Variant option -> $variant"
        echo ""
        variant_usage
        exit 1
    esac
    shift
    shift
    ;;
    *)
    echo "Syntax Error: unknown option: $key"
    echo ""
    top_usage
    exit 1
esac
done

MANY_CMDS=$[$CREATE_CMD+$BUILD_CMD+$WAIT_CMD+$DESTROY_CMD+$TEST_CMD+$REPORT_BUILD_CMD+$REPORT_TEST_CMD]
if [ $MANY_CMDS -gt 1 ]
then
    echo "Syntax Error: too many commands"
    top_usage
    exit 1
fi

if [ $HELP_CMD -eq 1 ]
then
    if [ $MANY_CMDS -eq 0 ]
    then
        top_usage
        exit 0
    fi
    if [ $CREATE_CMD -eq 1 ]
    then
        create_usage
        exit 0
    fi
    if [ $BUILD_CMD -eq 1 ]
    then
        build_usage
        exit 0
    fi
    if [ $WAIT_CMD -eq 1 ]
    then
        wait_usage
        exit 0
    fi
    if [ $TEST_CMD -eq 1 ]
    then
        run_test_usage
        exit 0
    fi
    if [ $DESTROY_CMD -eq 1 ]
    then
        destroy_usage
        exit 0
    fi
    if [ $REPORT_BUILD_CMD -eq 1 ]
    then
        report_build_usage
        exit 0
    fi
    if [ $REPORT_TEST_CMD -eq 1 ]
    then
        report_test_usage
        exit 0
    fi
else
    if [ $MANY_CMDS -eq 0 ]
    then
        echo "Syntax Error: no command"
        top_usage
        exit 1
    fi
    # For create, mandatory options: jn, id. Optional: variant
    if [ $CREATE_CMD -eq 1 ] && [ $NBARGS -ne 3 ] && [ $NBARGS -ne 259 ]
    then
        echo "Syntax Error: unsupported option(s) for create command"
        create_usage
        exit 1
    fi
    # For build, mandatory options: jn, id, ws. Optional: variant, k, D
    if [ $BUILD_CMD -eq 1 ] && [ $NBARGS -ne 7 ] && [ $NBARGS -ne 263 ] && [ $NBARGS -ne 15 ] && [ $NBARGS -ne 271 ] && [ $NBARGS -ne 23 ] && [ $NBARGS -ne 279 ] && [ $NBARGS -ne 31 ] && [ $NBARGS -ne 287 ]
    then
        echo "Syntax Error: unsupported option(s) for build command"
        build_usage
        exit 1
    fi
    # For wait, mandatory options: jn, id, ws. Optional: variant, k
    if [ $WAIT_CMD -eq 1 ] && [ $NBARGS -ne 7 ] && [ $NBARGS -ne 263 ] && [ $NBARGS -ne 15 ] && [ $NBARGS -ne 271 ]
    then
        echo "Syntax Error: unsupported option(s) for wait command"
        wait_usage
        exit 1
    fi
    # For test, mandatory options: jn, id, ws. Optional: variant, k
    if [ $TEST_CMD -eq 1 ] && [ $NBARGS -ne 7 ] && [ $NBARGS -ne 263 ] && [ $NBARGS -ne 15 ] && [ $NBARGS -ne 271 ]
    then
        echo "Syntax Error: unsupported option(s) for test command"
        run_test_usage
        exit 1
    fi
    # For destroy, mandatory options: jn, id.
    if [ $DESTROY_CMD -eq 1 ] && [ $NBARGS -ne 3 ]
    then
        echo "Syntax Error: unsupported option(s) for destroy command"
        destroy_usage
        exit 1
    fi
    # For report-build, mandatory options: jn, id, ws, gu, pu, br,co.
    #                                  or: jn, id, ws, gu, mr, sb, sc, tb, tc.
    if [ $REPORT_BUILD_CMD -eq 1 ] && [ $NBARGS -ne 15463 ] && [ $NBARGS -ne 49255 ]
    then
        echo "Syntax Error: unsupported option(s) for report-build command"
        report_build_usage
        exit 1
    fi
    # For report-test, mandatory options: jn, id, ws, gu, pu, br,co.
    #                                 or: jn, id, ws, gu, mr, sb, sc, tb, tc.
    if [ $REPORT_TEST_CMD -eq 1 ] && [ $NBARGS -ne 15463 ] && [ $NBARGS -ne 49255 ]
    then
        echo "Syntax Error: unsupported option(s) for report-test command"
        report_test_usage
        exit 1
    fi
fi

# Checking uvt-kvm is installed
UVT_KVM_PATH=`which uvt-kvm | grep -c uvt-kvm`
if [ $UVT_KVM_PATH -eq 0 ]
then
    echo "Error: uvt-kvm is not installed"
    top_usage
    exit 1
fi

if [ "$JOB_NAME" == "XX" ] || [ "$BUILD_ID" == "XX" ]
then
    VM_TEMPLATE=ci-
else
    VM_TEMPLATE=${JOB_NAME}-b${BUILD_ID}-
fi

VM_NAME=`echo $VM_NAME | sed -e "s#ci-#$VM_TEMPLATE#"`
VM_CMDS=${VM_NAME}_cmds.txt
ARCHIVES_LOC=${JENKINS_WKSP}/archives/${ARCHIVES_LOC}

STATUS=0
if [ $CREATE_CMD -eq 1 ]
then
    create_vm
fi
if [ $BUILD_CMD -eq 1 ]
then
    build_on_vm
    if [ $DAEMON -eq 0 ] && [ $STATUS -eq 0 ]
    then
        check_on_vm_build
    fi
fi
if [ $WAIT_CMD -eq 1 ]
then
    wait_on_vm_build
    if [ $STATUS -eq 0 ]
    then
        check_on_vm_build
    fi
fi
if [ $TEST_CMD -eq 1 ]
then
    ARCHIVES_LOC=${ARCHIVES_LOC}/test
    run_test_on_vm
fi
if [ $DESTROY_CMD -eq 1 ]
then
    destroy_vm
fi
if [ $REPORT_BUILD_CMD -eq 1 ]
then
    report_build
fi
if [ $REPORT_TEST_CMD -eq 1 ]
then
    report_test
fi

# Did command pass or fail?
if [ $STATUS -eq 0 ]
then
    echo "STATUS seems OK"
else
    echo "STATUS failed?"
fi
exit $STATUS