buildOnVM.sh 12.2 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#/*
# * 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
# */
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

function usage {
    echo "OAI VM Build Check script"
    echo "   Original Author: Raphael Defosseux"
    echo "   Requirements:"
    echo "     -- uvtool uvtool-libvirt apt-cacher"
    echo "     -- xenial image already synced"
    echo "   Default:"
    echo "     -- eNB with USRP"
    echo ""
    echo "Usage:"
    echo "------"
    echo "    buildOnVM.sh [OPTIONS]"
    echo ""
    echo "Options:"
    echo "--------"
38 39 40 41 42 43
    echo "    --job-name #### OR -jn ####"
    echo "    Specify the name of the Jenkins job."
    echo ""
    echo "    --build-id #### OR -id ####"
    echo "    Specify the build ID of the Jenkins job."
    echo ""
44 45 46
    echo "    --workspace #### OR -ws ####"
    echo "    Specify the workspace."
    echo ""
47 48 49 50 51 52 53 54
    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"
    echo "    --variant nu-ue-usrp   OR -v6"
    echo "    --variant enb-ethernet OR -v7"
    echo "    --variant ue-ethernet  OR -v8"
55 56 57 58 59 60 61 62 63 64 65 66 67 68
    echo "    Specify the variant to build."
    echo ""
    echo "    --keep-vm-alive OR -k"
    echo "    Keep the VM alive after the build."
    echo ""
    echo "    --help OR -h"
    echo "    Print this help message."
    echo ""
}

function variant_usage {
    echo "OAI VM Build Check script"
    echo "   Original Author: Raphael Defosseux"
    echo ""
69 70 71 72 73 74 75 76
    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"
    echo "    --variant nu-ue-usrp   OR -v6"
    echo "    --variant enb-ethernet OR -v7"
    echo "    --variant ue-ethernet  OR -v8"
77 78 79
    echo ""
}

80
if [ $# -lt 1 ] || [ $# -gt 9 ]
81 82 83 84 85 86 87
then
    echo "Syntax Error: not the correct number of arguments"
    echo ""
    usage
    exit 1
fi

88 89 90
VM_TEMPLATE=ci-
JOB_NAME=XX
BUILD_ID=XX
91
VM_NAME=ci-enb-usrp
Raphael Defosseux's avatar
Raphael Defosseux committed
92
VM_MEMORY=2048
93
VM_CPU=4
94
ARCHIVES_LOC=enb_usrp
95
LOG_PATTERN=.Rel15.txt
96 97 98 99 100 101 102 103 104 105 106 107 108 109
NB_PATTERN_FILES=4
BUILD_OPTIONS="--eNB -w USRP"
KEEP_VM_ALIVE=0

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

case $key in
    -h|--help)
    shift
    usage
    exit 0
    ;;
110 111 112 113 114 115 116 117 118 119
    -jn|--job-name)
    JOB_NAME="$2"
    shift
    shift
    ;;
    -id|--build-id)
    BUILD_ID="$2"
    shift
    shift
    ;;
120 121 122 123 124 125 126 127 128 129 130 131
    -ws|--workspace)
    JENKINS_WKSP="$2"
    shift
    shift
    ;;
    -k|--keep-vm-alive)
    KEEP_VM_ALIVE=1
    shift
    ;;
    -v1)
    VM_NAME=ci-enb-usrp
    ARCHIVES_LOC=enb_usrp
132
    LOG_PATTERN=.Rel15.txt
133 134 135 136 137 138 139 140 141 142
    NB_PATTERN_FILES=4
    BUILD_OPTIONS="--eNB -w USRP"
    shift
    ;;
    -v2)
    VM_NAME=ci-basic-sim
    ARCHIVES_LOC=basic_sim
    LOG_PATTERN=basic_simulator
    NB_PATTERN_FILES=2
    BUILD_OPTIONS="--basic-simulator"
143 144
    VM_MEMORY=8192
    VM_CPU=4
145 146 147 148 149
    shift
    ;;
    -v3)
    VM_NAME=ci-phy-sim
    ARCHIVES_LOC=phy_sim
150
    LOG_PATTERN=.Rel15.txt
151
    NB_PATTERN_FILES=5
152 153 154 155 156
    BUILD_OPTIONS="--phy_simulators"
    shift
    ;;
    -v4)
    VM_NAME=ci-cppcheck
Raphael Defosseux's avatar
Raphael Defosseux committed
157
    VM_MEMORY=8192
158 159 160
    ARCHIVES_LOC=cppcheck
    LOG_PATTERN=cppcheck.xml
    NB_PATTERN_FILES=1
161
    BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2 -i openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c"
162 163 164 165 166
    shift
    ;;
    -v5)
    VM_NAME=ci-gnb-usrp
    ARCHIVES_LOC=gnb_usrp
167
    LOG_PATTERN=.Rel15.txt
168 169 170 171 172 173 174
    NB_PATTERN_FILES=4
    BUILD_OPTIONS="--gNB -w USRP"
    shift
    ;;
    -v6)
    VM_NAME=ci-ue-nr-usrp
    ARCHIVES_LOC=nrue_usrp
175
    LOG_PATTERN=.Rel15.txt
176 177 178 179
    NB_PATTERN_FILES=4
    BUILD_OPTIONS="--nrUE -w USRP"
    shift
    ;;
180 181 182
    -v7)
    VM_NAME=ci-enb-ethernet
    ARCHIVES_LOC=enb_eth
183
    LOG_PATTERN=.Rel15.txt
184 185 186 187 188 189 190
    NB_PATTERN_FILES=6
    BUILD_OPTIONS="--eNB -t ETHERNET --noS1"
    shift
    ;;
    -v8)
    VM_NAME=ci-ue-ethernet
    ARCHIVES_LOC=ue_eth
191
    LOG_PATTERN=.Rel15.txt
192 193 194 195
    NB_PATTERN_FILES=6
    BUILD_OPTIONS="--UE -t ETHERNET --noS1"
    shift
    ;;
196 197 198 199 200 201
    --variant)
    variant="$2"
    case $variant in
        enb-usrp)
        VM_NAME=ci-enb-usrp
        ARCHIVES_LOC=enb_usrp
202
        LOG_PATTERN=.Rel15.txt
203 204 205 206 207 208 209 210 211
        NB_PATTERN_FILES=4
        BUILD_OPTIONS="--eNB -w USRP"
        ;;
        basic-sim)
        VM_NAME=ci-basic-sim
        ARCHIVES_LOC=basic_sim
        LOG_PATTERN=basic_simulator
        NB_PATTERN_FILES=2
        BUILD_OPTIONS="--basic-simulator"
212 213
        VM_MEMORY=8192
        VM_CPU=4
214 215 216 217
        ;;
        phy-sim)
        VM_NAME=ci-phy-sim
        ARCHIVES_LOC=phy_sim
218
        LOG_PATTERN=.Rel15.txt
219
        NB_PATTERN_FILES=5
220 221 222 223
        BUILD_OPTIONS="--phy_simulators"
        ;;
        cppcheck)
        VM_NAME=ci-cppcheck
Raphael Defosseux's avatar
Raphael Defosseux committed
224
        VM_MEMORY=8192
225 226 227
        ARCHIVES_LOC=cppcheck
        LOG_PATTERN=cppcheck.xml
        NB_PATTERN_FILES=1
228
        BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2 -i openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c"
229 230 231 232
        ;;
        gnb-usrp)
        VM_NAME=ci-gnb-usrp
        ARCHIVES_LOC=gnb_usrp
233
        LOG_PATTERN=.Rel15.txt
234 235 236 237 238 239
        NB_PATTERN_FILES=4
        BUILD_OPTIONS="--gNB -w USRP"
        ;;
        nu-ue-usrp)
        VM_NAME=ci-ue-nr-usrp
        ARCHIVES_LOC=nrue_usrp
240
        LOG_PATTERN=.Rel15.txt
241 242 243
        NB_PATTERN_FILES=4
        BUILD_OPTIONS="--nrUE -w USRP"
        ;;
244 245 246
        enb-ethernet)
        VM_NAME=ci-enb-ethernet
        ARCHIVES_LOC=enb_eth
247
        LOG_PATTERN=.Rel15.txt
248 249 250 251 252 253
        NB_PATTERN_FILES=6
        BUILD_OPTIONS="--eNB -t ETHERNET --noS1"
        ;;
        ue-ethernet)
        VM_NAME=ci-ue-ethernet
        ARCHIVES_LOC=ue_eth
254
        LOG_PATTERN=.Rel15.txt
255 256 257
        NB_PATTERN_FILES=6
        BUILD_OPTIONS="--UE -t ETHERNET --noS1"
        ;;
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
        *)
        echo ""
        echo "Syntax Error: Invalid Variant option -> $variant"
        echo ""
        variant_usage
        exit 1
    esac
    shift
    shift
    ;;
    *)
    echo "Syntax Error: unknown option: $key"
    echo ""
    usage
    exit 1
esac
done

if [ ! -f $JENKINS_WKSP/localZip.zip ]
then
    echo "Missing localZip.zip file!"
    exit 1
fi
if [ ! -f /etc/apt/apt.conf.d/01proxy ]
then
    echo "Missing /etc/apt/apt.conf.d/01proxy file!"
    echo "Is apt-cacher installed and configured?"
    exit 1
fi

288 289 290 291 292 293 294 295
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#"`
296 297 298 299 300 301 302 303 304
VM_CMDS=${VM_NAME}_cmds.txt
ARCHIVES_LOC=${JENKINS_WKSP}/archives/${ARCHIVES_LOC}

echo "VM_NAME             = $VM_NAME"
echo "VM_CMD_FILE         = $VM_CMDS"
echo "JENKINS_WKSP        = $JENKINS_WKSP"
echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
echo "BUILD_OPTIONS       = $BUILD_OPTIONS"

305 306 307 308 309 310 311
IS_VM_ALIVE=`uvt-kvm list | grep -c $VM_NAME`

if [ $IS_VM_ALIVE -eq 0 ]
then
    echo "############################################################"
    echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base"
    echo "############################################################"
312
    uvt-kvm create $VM_NAME release=xenial --memory $VM_MEMORY --cpu $VM_CPU --unsafe-caching --template ci-scripts/template-host.xml
313 314
fi

315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
echo "Waiting for VM to be started"
uvt-kvm wait $VM_NAME --insecure

VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
echo "$VM_NAME has for IP addr = $VM_IP_ADDR"

echo "############################################################"
echo "Copying GIT repo into VM ($VM_NAME)" 
echo "############################################################"
scp -o StrictHostKeyChecking=no localZip.zip ubuntu@$VM_IP_ADDR:/home/ubuntu
scp -o StrictHostKeyChecking=no /etc/apt/apt.conf.d/01proxy ubuntu@$VM_IP_ADDR:/home/ubuntu

echo "############################################################"
echo "Running install and build script on VM ($VM_NAME)"
echo "############################################################"
echo "sudo cp 01proxy /etc/apt/apt.conf.d/" > $VM_CMDS
331
echo "touch /home/ubuntu/.hushlogin" >> $VM_CMDS
332
if [[ "$VM_NAME" == *"-cppcheck"* ]]
333 334 335 336 337 338
then
    echo "echo \"sudo apt-get --yes --quiet install zip cppcheck \"" >> $VM_CMDS
    echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
    echo "sudo apt-get --yes install zip cppcheck >> zip-install.txt 2>&1" >> $VM_CMDS
else
    echo "echo \"sudo apt-get --yes --quiet install zip subversion libboost-dev \"" >> $VM_CMDS
Raphael Defosseux's avatar
Raphael Defosseux committed
339 340
    echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
    echo "sudo apt-get --yes install zip subversion libboost-dev >> zip-install.txt 2>&1" >> $VM_CMDS
341 342 343 344 345
fi
echo "mkdir tmp" >> $VM_CMDS
echo "cd tmp" >> $VM_CMDS
echo "echo \"unzip -qq -DD ../localZip.zip\"" >> $VM_CMDS
echo "unzip -qq -DD ../localZip.zip" >> $VM_CMDS
346
if [[ "$VM_NAME" == *"-cppcheck"* ]]
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
then
    echo "mkdir cmake_targets/log" >> $VM_CMDS
    echo "cp /home/ubuntu/zip-install.txt cmake_targets/log" >> $VM_CMDS
    echo "echo \"cppcheck $BUILD_OPTIONS . \"" >> $VM_CMDS
    echo "cppcheck $BUILD_OPTIONS . 2> cmake_targets/log/cppcheck.xml 1> cmake_targets/log/cppcheck_build.txt" >> $VM_CMDS
else
    echo "echo \"source oaienv\"" >> $VM_CMDS
    echo "source oaienv" >> $VM_CMDS
    echo "cd cmake_targets/" >> $VM_CMDS
    echo "mkdir log" >> $VM_CMDS
    echo "cp /home/ubuntu/zip-install.txt log" >> $VM_CMDS
    echo "echo \"./build_oai -I $BUILD_OPTIONS \"" >> $VM_CMDS
    echo "./build_oai -I $BUILD_OPTIONS > log/install-build.txt 2>&1" >> $VM_CMDS
fi
ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS

echo "############################################################"
echo "Creating a tmp folder to store results and artifacts"
echo "############################################################"
if [ ! -d $JENKINS_WKSP/archives ]
then
    mkdir $JENKINS_WKSP/archives
fi

if [ ! -d $ARCHIVES_LOC ]
then
    mkdir $ARCHIVES_LOC
fi

scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.txt $ARCHIVES_LOC
377
if [[ "$VM_NAME" == *"-cppcheck"* ]]
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
then
    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.xml $ARCHIVES_LOC
fi

if [ $KEEP_VM_ALIVE -eq 0 ]
then
    echo "############################################################"
    echo "Destroying VM"
    echo "############################################################"
    uvt-kvm destroy $VM_NAME
    ssh-keygen -R $VM_IP_ADDR
fi
rm -f $VM_CMDS

echo "############################################################"
echo "Checking build status" 
echo "############################################################"

LOG_FILES=`ls $ARCHIVES_LOC/*.txt $ARCHIVES_LOC/*.xml`
STATUS=0
NB_FOUND_FILES=0

for FULLFILE in $LOG_FILES 
do
    if [[ $FULLFILE == *"$LOG_PATTERN"* ]]
    then
        filename=$(basename -- "$FULLFILE")
405
        if [ "$LOG_PATTERN" == ".Rel15.txt" ]
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
        then
            PASS_PATTERN=`echo $filename | sed -e "s#$LOG_PATTERN##"`
        fi
        if [ "$LOG_PATTERN" == "basic_simulator" ]
        then
            PASS_PATTERN="lte-"
        fi
        if [ "$LOG_PATTERN" == "cppcheck.xml" ]
        then
            PASS_PATTERN="results version"
            LOCAL_STAT=`egrep -c "$PASS_PATTERN" $FULLFILE`
        else
            LOCAL_STAT=`egrep -c "Built target $PASS_PATTERN" $FULLFILE`
        fi
        if [ $LOCAL_STAT -eq 0 ]; then STATUS=-1; fi
        NB_FOUND_FILES=$((NB_FOUND_FILES + 1))
    fi
done

if [ $NB_PATTERN_FILES -ne $NB_FOUND_FILES ]; then STATUS=-1; fi

if [ $STATUS -eq 0 ]
then
    echo "STATUS seems OK"
else
    echo "STATUS failed?"
fi
exit $STATUS