summaryrefslogtreecommitdiffstats
path: root/src/build/citest/auto-release
blob: ba5105c31e789296460a5df17b51026a93f52af3 (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
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
#!/bin/bash
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/citest/auto-release $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2016,2018
# [+] International Business Machines Corp.
#
#
# 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.
#
# IBM_PROLOG_END_TAG

function setup {
    cd $HOSTBOOT_WORKSPACE

    # Set up environment
    source "$HOSTBOOT_WORKSPACE/env.bash" || exit -1

    # Create cmvc checkout directory
    if [ -n "$CMVC_DIR" ]; then
        mkdir -p $CMVC_DIR || exit -1
    fi
}

function build {
    ### Define and setup release branch
    export PATH=${PATH}:$HOSTBOOT_WORKSPACE/src/build/tools
    hbRelease define --level $RELEASE_NAME --released $PREVIOUS_RELEASE --base $BASE --branch $GIT_BRANCH || exit -1
    hbRelease release --level $RELEASE_NAME || exit -1

    export SANDBOXROOT=$WORKSPACE
    export SANDBOXNAME=$RELEASE_NAME
    export SANDBOXBASE=$SANDBOXROOT/$SANDBOXNAME
    mkdir -p $SANDBOXBASE || exit -1
    mkdir -p $CMVC_DIR/src/hbfw/nimbus || exit -1
    mkdir -p $CMVC_DIR/src/hbfw/cumulus || exit -1
    mkdir -p $CMVC_DIR/src/hbfw/cumulus_cdimm || exit -1

    ### Compile and provide binaries
    setup
    if echo $FIPS_RELEASE | grep -q fips9; then
        # First bulid the standalone
        BUILD_MINIMAL=1 nice -+20 make -j16 || exit -1
        # With PNOR env var not set, hb prime will make all of the pnor images
        unset PNOR
        # prime will put the files into expected locations
        hb simsetup || exit -1
        hb prime || exit -1
        cp $SANDBOXBASE/obj/ppc/hbfw/img/nimbus.pnor $CMVC_DIR/src/hbfw/nimbus || exit -1
        cp $SANDBOXBASE/src/hbfw/simics.tar $CMVC_DIR/src/hbfw/nimbus || exit -1
        cp $SANDBOXBASE/obj/ppc/hbfw/img/cumulus.pnor $CMVC_DIR/src/hbfw/cumulus || exit -1
        cp $SANDBOXBASE/src/hbfw/simics.tar $CMVC_DIR/src/hbfw/cumulus || exit -1
        cp $SANDBOXBASE/obj/ppc/hbfw/img/cumulus_cdimm.pnor $CMVC_DIR/src/hbfw/cumulus_cdimm || exit -1
        cp $SANDBOXBASE/src/hbfw/simics.tar $CMVC_DIR/src/hbfw/cumulus_cdimm || exit -1

        make clean
        # Now build the FSP-based images
        export CONFIG_FILE="$HOSTBOOT_WORKSPACE/src/build/configs/fsprelease.config"
        BUILD_MINIMAL=1 nice -+20 make -j16 || exit -1
    else
        BUILD_MINIMAL=1 nice -+20 make -j16 || exit -1
    fi

    # Run hb distribute to put binaries in cmvc checkout directory
    hb prime --release $SANDBOXBASE || exit -1
    cp -rf $SANDBOXBASE/fsp/* $CMVC_DIR/src/hbfw || exit -1
    rm -rf $SANDBOXBASE/fsp || exit -1

    ### Push tag to gerrit, create track and checkin files
    git push ssh://hostboot-us@gerrit-server/hostboot $RELEASE_NAME || exit -1
    git checkout gerrit/master || exit -1
    hbRelease pre-release --level $RELEASE_NAME --release $FIPS_RELEASE --checkInDir $CMVC_DIR --released $PREVIOUS_RELEASE --track $EXISTING_TRACK || exit -1
    # Check if feature was successfully created and if so set $FEATURE
    if [ -f $CMVC_FEATURE_FILE ]; then
        FEATURE=`cat $CMVC_FEATURE_FILE`;
    else
        echo "No feature created"
        exit -1
    fi

    ### @todo RTC:171143
    ### Sleep for 5 minutes to allow time for CMVC req's to take effect
    echo "Waiting for fspCI requirements to take effect. 5 minutes..."
    sleep 5m
}

function fsp-ci-wait {
    joburl=$1
    build_result="unknown"
    rc=1

    if [ -z "$joburl" ];
    then
        echo "Invalid or empty job URL."
        exit -1
    fi

    # No timeout is implemented here.  Timeout would happen at the Jenkins
    # project level
    echo "Waiting for $joburl build status..."
    while true;
    do
        sleep 10
        # use silent flag (-s) to omit progress meter output
        curl -s ${joburl}/api/json | grep building\":false >/dev/null 2>&1
        if [ $? -eq 0 ];
        then
            break
        fi
    done

    # The job is not building anymore.  Check the build result.
    CURL_OUT="$(curl -s ${joburl}/api/json)"
    if [ $? -ne 0 ];
    then
        echo "Error verifying build result..."
        echo "curl returned $?\n$CURL_OUT"
        exit -1
    fi

    echo $CURL_OUT | grep result\":\"SUCCESS
    if [ $? -eq 0 ];
    then
        echo "Build $joburl passed"
        build_result="passed"
        rc=0
    fi

    echo $CURL_OUT | grep result\":\"FAILURE
    if [ $? -eq 0 ];
    then
        echo "Build $joburl failed."
        build_result="failed"
        rc=1
    fi

    echo $CURL_OUT | grep result\":\"ABORTED
    if [ $? -eq 0 ];
    then
        echo "Build $joburl aborted."
        build_result="aborted"
        rc=1
    fi

    if [ "$build_result" == "unknown" ];
    then
        echo "Build result for $joburl: unknown."
        echo "curl output: $CURL_OUT"
        rc=1
    fi

    return $rc
}

function run_fsp_ci {
    ### Call fsp-ci to test hostboot release
    # Start fsp-CI job and set URL
    retries=3

    # Retry loop for fsp-CI-jenkins
    while true;
    do
        ((retries--))
        OUTPUT="$(fsp-CI-jenkins -r $FIPS_RELEASE -t $FEATURE --test_on_hardware=1 --force)";

        # Check if fsp-CI-jenkins failed to start
        if [ $? -eq 0 ]; then
            URL="$(echo $OUTPUT | grep -o "Check status at .*" | sed -e "s/Check status at//")"
            break
        else
            if [ $retries -lt 1 ]; then
                exit -1
            fi
            echo "fsp-CI-jenkins command failed returned $?, retrying..."
            sleep 66
        fi
    done

    ### Wait on fsp-CI job to complete, whether pass or fail
    fsp-ci-wait $URL || exit -1

}

function release {
    ### Handle cmvc final commands to integrate track, post notes to BQ
    hbRelease post-release --level $RELEASE_NAME --released $PREVIOUS_RELEASE --feature $FEATURE --release $FIPS_RELEASE || exit -1
}

function usage {
    echo "Usage: auto-release.sh [OPTIONS]"
    echo "Runs the steps for Hostboot automated releases"
    echo "OPTIONS:"
    echo " -b   Run build phase"
    echo " -t   Run test and release phase"
    echo " -c   Run test phase only (fsp-ci)"
    echo " -h   Help"
    exit 1
}

# make sure arguments are provided
if [ $# -eq 0 ]
then
    echo "No arguments provided."
    usage
    exit 1
fi

while getopts "btch" opt; do
    case $opt in
        b)
            build
            ;;
        t)
            setup
            run_fsp_ci
            release
            ;;
        c)
            run_fsp_ci
            ;;
        h)
            usage
            ;;
        \?)
            echo "Invalid option: -$OPTARG" >&2
            exit 1
            ;;
        :)
            echo "Option -$OPTARG requires an argument." >&2
            exit 1
            ;;
    esac
done
OpenPOWER on IntegriCloud