aboutsummaryrefslogtreecommitdiffstats
path: root/ci/build-auto.sh
blob: 00b67b1f6af8c7b2e4fe2122226dfa966495ebd8 (plain)
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
#!/bin/bash
#
# Copyright 2015-2018 Intel Corporation., Tieto
#
# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
#
# 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.

# CI helper script for execution of AUTO project jenkins jobs.
# This script is based on the file ci/build-vsperf.sh from OPNFV vswitchperf
# project.

# Usage:
#       build-auto.sh job_type
#
# Parameters:
#       job_type - is one of "verify", "merge" or "daily"
#
# Example:
#       ./ci/build-auto.sh verify

#
# exit codes
#
EXIT=0
EXIT_UNKNOWN_JOB_TYPE=1
EXIT_LINT_FAILED=2
EXIT_FUEL_FAILED=10

#
# configuration
#
AUTOENV_DIR="$HOME/autoenv"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
LOG_DIR=$HOME/auto_ci_daily_logs
WORKSPACE=${WORKSPACE:-$PWD}

# POD and SCENARIO details used during OPNFV deployment performed by daily job
NODE_NAME=${NODE_NAME:-"ericsson-virtual1"}
POD_LAB=$(echo $NODE_NAME | cut -d '-' -f1)
POD_NAME=$(echo $NODE_NAME | cut -d '-' -f2)
DEPLOY_SCENARIO=${DEPLOY_SCENARIO:-"os-nosdn-onap-noha"}

#
# functions
#
# execute pylint and yamllint to check code quality
function execute_auto_lint_check() {
    if ! ./check -b ; then
        EXIT=$EXIT_LINT_FAILED
    fi
}

# check and install required packages
function dependencies_check() {
    . /etc/os-release
    if [ $ID == "ubuntu" ] ; then
        echo "Dependencies check"
        echo "=================="
        # install system packages
        for PACKAGE in "virtualenv" "pylint" "yamllint" "gnuplot" ; do
            if dpkg -s $PACKAGE &> /dev/null ; then
                printf "    %-70s %-6s\n" $PACKAGE "OK"
            else
                printf "    %-70s %-6s\n" $PACKAGE "missing"
                sudo apt-get install -y $PACKAGE
            fi
        done
        echo
    fi
}

# create virtualenv if needed and enable it
function virtualenv_prepare() {
    if [ ! -e $AUTOENV_DIR ] ; then
        echo "Create AUTO environment"
        echo "======================="
        virtualenv "$AUTOENV_DIR"
        echo
    fi

    # activate and update virtualenv
    echo "Update AUTO environment"
    echo "======================="
    source "$AUTOENV_DIR"/bin/activate
    pip install -r ./requirements.txt
    echo
}

#
# main
#
echo

# enter workspace dir
cd $WORKSPACE

# check if required packages are installed
dependencies_check

# execute job based on passed parameter
case $1 in
    "verify")
        echo "==============="
        echo "AUTO verify job"
        echo "==============="

        virtualenv_prepare
        execute_auto_lint_check
        #execute_auto_doc_check

        # Everything went well, so report SUCCESS to Jenkins
        exit $EXIT
        ;;
    "merge")
        echo "=============="
        echo "AUTO merge job"
        echo "=============="

        virtualenv_prepare
        execute_auto_lint_check
        #execute_auto_doc_check

        # propagate result to the Jenkins job
        exit $EXIT
        ;;
    "daily")
        echo "=============="
        echo "AUTO daily job"
        echo "=============="
        echo
        echo "Deployment details:"
        echo "  LAB:       $POD_LAB"
        echo "  POD:       $POD_NAME"
        echo "  Scenario:  $DEPLOY_SCENARIO"
        echo "  WORKSPACE: $WORKSPACE"
        echo

        # create log dir if needed
        if [ ! -e $LOG_DIR ] ; then
            echo "Create AUTO LOG DIRECTORY"
            echo "========================="
            echo "mkdir $LOG_DIR"
            mkdir $LOG_DIR
            echo
        fi

        echo "Installation of OPNFV and ONAP"
        echo "=============================="
        # clone fuel and execute installation of ONAP scenario to install
        # ONAP on top of OPNFV deployment
        [ -e fuel ] && rm -rf fuel
        git clone https://gerrit.opnfv.org/gerrit/fuel
        cd fuel
        # Fuel master branch is currently broken; thus use stable/gambia
        # branch with recent master version of ONAP scenario
        git checkout stable/gambia
        git checkout origin/master mcp/config/states/onap \
            mcp/config/scenario/os-nosdn-onap-ha.yaml  \
            mcp/config/scenario/os-nosdn-onap-noha.yaml
        # use larger disk size for virtual nodes
        sed -i -re 's/(qemu-img resize.*)100G/\1400G/'  mcp/scripts/lib_jump_deploy.sh

        LOG_FILE="$LOG_DIR/deploy_${TIMESTAMP}.log"
        echo "ci/deploy.sh -l $POD_LAB -p $POD_NAME -s $DEPLOY_SCENARIO |&\
            tee $LOG_FILE"
        DEPLOY_START=$(date +%Y%m%d_%H%M%S)
        ci/deploy.sh -l $POD_LAB -p $POD_NAME -s $DEPLOY_SCENARIO |&\
            tee $LOG_FILE

        # report failure if fuel failed to install OPNFV or ONAP
        [ $? -ne 0 ] && exit $EXIT_FUEL_FAILED

        # process report
        DEPLOY_END=$(date +%Y%m%d_%H%M%S)
        REPORT_FILE="$LOG_DIR/deploy_report_${TIMESTAMP}.txt"
        CSV_SUMMARY="$LOG_DIR/deploy_summary_${TIMESTAMP}.csv"
        MARKER="ONAP INSTALLATION REPORT"
        # cut report from installation log file
        sed -n "/^$MARKER/,/^END OF $MARKER/p;/^END OF $MARKER/q" \
            $LOG_FILE > $REPORT_FILE
        PODS_TOTAL=$(grep "PODs Total" $REPORT_FILE | sed -e 's/[^0-9]//g')
        PODS_FAILED=$(grep "PODs Failed" $REPORT_FILE | sed -e 's/[^0-9]//g')
        TC_SUM=$(grep "tests total" $REPORT_FILE | tail -n1 |\
            sed -e 's/[^0-9,]//g')

        echo "Start Time,End Time,Total PODs,Failed PODs,Total Tests,Passed"\
            "Tests,Failed Tests" >> $CSV_SUMMARY
        echo "$DEPLOY_START,$DEPLOY_END,$PODS_TOTAL,$PODS_FAILED,$TC_SUM"\
            >> $CSV_SUMMARY

        # plot graphs from result summaries and print txt versions if possible
        cd $WORKSPACE
        ci/plot-results.sh
        for GRAPH in $(ls -1 graph*txt 2> /dev/null) ; do
            cat $GRAPH
        done

        # propagate result to the Jenkins job
        exit $EXIT
        ;;
    *)
        echo
        echo "ERRROR: Unknown job type \"$1\""
        echo
        exit $EXIT_UNKNOWN_JOB_TYPE
        ;;
esac

exit $EXIT_UNKNOWN_JOB_TYPE

#
# end
#