waitBuildOnVM.sh 5.85 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
#!/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
# */

23 24
function wait_usage {
    echo "OAI CI VM script"
25 26 27 28 29 30 31 32 33
    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 "------"
34
    echo "    oai-ci-vm-tool wait [OPTIONS]"
35
    echo ""
36
    echo "Mandatory Options:"
37 38 39 40 41 42 43 44 45 46
    echo "--------"
    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 ""
    echo "    --workspace #### OR -ws ####"
    echo "    Specify the workspace."
    echo ""
47
    variant_usage
48 49
    echo "    Specify the variant to build."
    echo ""
50 51
    echo "Options:"
    echo "--------"
52 53 54 55 56 57 58 59
    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 ""
}

60 61 62 63
function wait_on_vm_build {
    echo "############################################################"
    echo "OAI CI VM script"
    echo "############################################################"
64

65 66 67 68 69
    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"
70

71
    IS_VM_ALIVE=`uvt-kvm list | grep -c $VM_NAME`
72

73 74 75 76 77 78 79 80
    if [ $IS_VM_ALIVE -eq 0 ]
    then
        echo "############################################################"
        echo "You should have created the VM before doing anything"
        echo "############################################################"
        STATUS=1
        return
    fi
81

82 83
    echo "Waiting for VM to be started"
    uvt-kvm wait $VM_NAME --insecure
84

85 86
    VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
    echo "$VM_NAME has for IP addr = $VM_IP_ADDR"
87 88

    echo "############################################################"
89
    echo "Waiting build process to end on VM ($VM_NAME)"
90 91
    echo "############################################################"

92 93 94 95 96 97 98 99
    if [[ "$VM_NAME" == *"-cppcheck"* ]]
    then
        echo "echo \"ps -aux | grep cppcheck \"" >> $VM_CMDS
        echo "while [ \$(ps -aux | grep --color=never cppcheck | grep -v grep | wc -l) -gt 0 ]; do sleep 3; done" >> $VM_CMDS
    else
        echo "echo \"ps -aux | grep build \"" >> $VM_CMDS
        echo "while [ \$(ps -aux | grep --color=never build_oai | grep -v grep | wc -l) -gt 0 ]; do sleep 3; done" >> $VM_CMDS
    fi
100

101 102 103
    ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS
    rm -f $VM_CMDS
}
104

105 106 107 108 109 110 111 112
function check_on_vm_build {
    echo "############################################################"
    echo "Creating a tmp folder to store results and artifacts"
    echo "############################################################"
    if [ ! -d $JENKINS_WKSP/archives ]
    then
        mkdir $JENKINS_WKSP/archives
    fi
113

114 115 116 117
    if [ ! -d $ARCHIVES_LOC ]
    then
        mkdir $ARCHIVES_LOC
    fi
118

119 120 121 122 123
    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.txt $ARCHIVES_LOC
    if [[ "$VM_NAME" == *"-cppcheck"* ]]
    then
        scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.xml $ARCHIVES_LOC
    fi
124

125 126 127 128 129 130 131 132 133
    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
134 135

    echo "############################################################"
136
    echo "Checking build status" 
137 138
    echo "############################################################"

139 140 141
    LOG_FILES=`ls $ARCHIVES_LOC/*.txt $ARCHIVES_LOC/*.xml`
    STATUS=0
    NB_FOUND_FILES=0
142

143 144 145
    for FULLFILE in $LOG_FILES 
    do
        if [[ $FULLFILE == *"$LOG_PATTERN"* ]]
146
        then
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
            filename=$(basename -- "$FULLFILE")
            if [ "$LOG_PATTERN" == ".Rel14.txt" ]
            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))
165
        fi
166
    done
167

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

170
}