Merge "[compass4nfv] enable opencontrail ci jobs in compass"
[releng.git] / jjb / functest / functest-ci-jobs.yml
1 ###################################
2 # job configuration for functest
3 ###################################
4 - project:
5     name: functest
6
7     project: '{name}'
8
9 #--------------------------------
10 # BRANCH ANCHORS
11 #--------------------------------
12     master: &master
13         stream: master
14         branch: '{stream}'
15         gs-pathname: ''
16         docker-tag: 'latest'
17     brahmaputra: &brahmaputra
18         stream: brahmaputra
19         branch: 'stable/{stream}'
20         gs-pathname: '/{stream}'
21         docker-tag: 'stable'
22 #--------------------------------
23 # POD, INSTALLER, AND BRANCH MAPPING
24 #--------------------------------
25 #        brahmaputra
26 #--------------------------------
27     pod:
28         - lf-pod1:
29             installer: apex
30             <<: *brahmaputra
31         - intel-pod5:
32             installer: joid
33             <<: *brahmaputra
34         - orange-pod2:
35             installer: joid
36             <<: *brahmaputra
37         - huawei-pod1:
38             installer: compass
39             <<: *brahmaputra
40         - ericsson-pod1:
41             installer: fuel
42             <<: *brahmaputra
43         - ericsson-pod2:
44             installer: fuel
45             <<: *brahmaputra
46         - lf-pod2:
47             installer: fuel
48             <<: *brahmaputra
49         - virtual:
50             installer: fuel
51             <<: *brahmaputra
52         - huawei-virtual:
53             installer: compass
54             <<: *brahmaputra
55         - virtual:
56             installer: joid
57             <<: *brahmaputra
58         - arm-pod1:
59             installer: fuel
60             <<: *brahmaputra
61 #--------------------------------
62 #        master
63 #--------------------------------
64         - lf-pod2:
65             installer: fuel
66             <<: *master
67         - intel-pod6:
68             installer: joid
69             <<: *master
70         - intel-pod8:
71             installer: compass
72             <<: *master
73         - intel-pod7:
74             installer: apex
75             <<: *master
76         - ericsson-pod1:
77             installer: fuel
78             <<: *master
79         - orange-pod5:
80             installer: fuel
81             <<: *master
82         - orange-pod2:
83             installer: joid
84             <<: *master
85         - virtual:
86             installer: fuel
87             <<: *master
88         - huawei-virtual:
89             installer: compass
90             <<: *master
91         - virtual:
92             installer: joid
93             <<: *master
94         - huawei-pod2:
95             installer: compass
96             <<: *master
97         - nokia-pod1:
98             installer: apex
99             <<: *master
100         - arm-pod1:
101             installer: fuel
102             <<: *master
103         - zte-pod1:
104             installer: fuel
105             <<: *master
106 #--------------------------------
107
108     testsuite:
109         - 'daily'
110         - 'suite'
111
112     jobs:
113         - 'functest-{installer}-{pod}-{testsuite}-{stream}'
114
115 ################################
116 # job template
117 ################################
118 - job-template:
119     name: 'functest-{installer}-{pod}-{testsuite}-{stream}'
120
121     concurrent: true
122
123     properties:
124         - throttle:
125             enabled: true
126             max-per-node: 1
127
128     wrappers:
129         - build-name:
130             name: '$BUILD_NUMBER Suite: $FUNCTEST_SUITE_NAME Scenario: $DEPLOY_SCENARIO'
131         - timeout:
132             timeout: 400
133             abort: true
134
135     parameters:
136         - project-parameter:
137             project: '{project}'
138         - '{pod}-defaults'
139         - '{installer}-defaults'
140         - 'functest-{testsuite}-parameter'
141         - string:
142             name: DEPLOY_SCENARIO
143             default: 'os-odl_l2-nofeature-ha'
144         - string:
145             name: DOCKER_TAG
146             default: '{docker-tag}'
147             description: 'Tag to pull docker image'
148         - functest-parameter:
149             gs-pathname: '{gs-pathname}'
150
151     scm:
152         - git-scm:
153             credentials-id: '{ssh-credentials}'
154             refspec: ''
155             branch: '{branch}'
156
157     builders:
158         - 'functest-{testsuite}-builder'
159
160 ########################
161 # parameter macros
162 ########################
163 - parameter:
164     name: functest-daily-parameter
165     parameters:
166         - string:
167             name: FUNCTEST_SUITE_NAME
168             default: 'daily'
169             description: "Suite name to run"
170 - parameter:
171     name: functest-suite-parameter
172     parameters:
173         - choice:
174             name: FUNCTEST_SUITE_NAME
175             choices:
176                 - 'tempest'
177                 - 'rally'
178                 - 'odl'
179                 - 'onos'
180                 - 'ovno'
181                 - 'promise'
182                 - 'doctor'
183                 - 'vims'
184                 - 'vping_userdata'
185                 - 'vping_ssh'
186 - parameter:
187     name: functest-parameter
188     parameters:
189         - string:
190             name: GS_PATHNAME
191             default: '{gs-pathname}'
192             description: "Version directory where the opnfv documents will be stored in gs repository"
193         - string:
194             name: FUNCTEST_REPO_DIR
195             default: "/home/opnfv/repos/functest"
196             description: "Directory where the Functest repository is cloned"
197         - string:
198             name: PUSH_RESULTS_TO_DB
199             default: "true"
200             description: "Push the results of all the tests to the resultDB"
201         - string:
202             name: CI_DEBUG
203             default: 'true'
204             description: "Show debug output information"
205 ########################
206 # trigger macros
207 ########################
208 - trigger:
209     name: 'functest-master'
210     triggers:
211         - pollscm:
212             cron: "H 9 * * *"
213 ########################
214 # builder macros
215 ########################
216 - builder:
217     name: functest-daily-builder
218     builders:
219         - 'functest-cleanup'
220         - 'set-functest-env'
221         - 'functest-daily'
222         - 'functest-store-results'
223
224 - builder:
225     name: functest-suite-builder
226     builders:
227         - 'functest-cleanup'
228         - 'set-functest-env'
229         - 'functest-suite'
230
231
232 - builder:
233     name: functest-suite
234     builders:
235         - shell: |
236             #!/bin/bash
237             set -e
238             branch=${GIT_BRANCH##*/}
239             echo "Functest: run $FUNCTEST_SUITE_NAME on branch ${branch}"
240             if [[ ${branch} == *"brahmaputra"* ]]; then
241                 cmd="${FUNCTEST_REPO_DIR}/docker/run_tests.sh --test $FUNCTEST_SUITE_NAME"
242             else
243                 cmd="python ${FUNCTEST_REPO_DIR}/ci/run_tests.py -t $FUNCTEST_SUITE_NAME"
244             fi
245             container_id=$(docker ps -a | grep opnfv/functest | awk '{print $1}' | head -1)
246             docker exec $container_id $cmd
247
248
249 - builder:
250     name: functest-daily
251     builders:
252         - shell: |
253             #!/bin/bash
254             set +e
255             branch=${GIT_BRANCH##*/}
256             [[ "$PUSH_RESULTS_TO_DB" == "true" ]] && flags+="-r"
257             if [[ ${branch} == *"brahmaputra"* ]]; then
258                 cmd="${FUNCTEST_REPO_DIR}/docker/run_tests.sh -s ${flags}"
259             else
260                 cmd="python ${FUNCTEST_REPO_DIR}/ci/run_tests.py -t all ${flags}"
261             fi
262             container_id=$(docker ps -a | grep opnfv/functest | awk '{print $1}' | head -1)
263             docker exec $container_id $cmd
264
265 - builder:
266     name: set-functest-env
267     builders:
268         - shell: |
269             #!/bin/bash
270             set -e
271             [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
272             # labconfig is used only for joid
273             labconfig=""
274             if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
275                 if sudo virsh list | grep instack; then
276                     instack_mac=$(sudo virsh domiflist instack | grep default | \
277                                   grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
278                 elif sudo virsh list | grep undercloud; then
279                     instack_mac=$(sudo virsh domiflist undercloud | grep default | \
280                                   grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
281                 else
282                     echo "No available installer VM exists...exiting"
283                     exit 1
284                 fi
285                 INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
286                 sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
287                 if sudo iptables -C FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable 2> ${redirect}; then
288                     sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
289                 fi
290                 if sudo iptables -C FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable 2> ${redirect}; then
291                     sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
292                 fi
293             elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
294                 # If production lab then creds may be retrieved dynamically
295                 # creds are on the jumphost, always in the same folder
296                 labconfig="-v $LAB_CONFIG/admin-openrc:/home/opnfv/functest/conf/openstack.creds"
297                 # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
298                 # replace the default one by the customized one provided by jenkins config
299             fi
300             echo "Functest: Start Docker and prepare environment"
301             envs="-e INSTALLER_TYPE=${INSTALLER_TYPE} -e INSTALLER_IP=${INSTALLER_IP} \
302                 -e NODE_NAME=${NODE_NAME} -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} \
303                 -e BUILD_TAG=${BUILD_TAG} -e CI_DEBUG=${CI_DEBUG}"
304             branch=${GIT_BRANCH##*/}
305             dir_result="${HOME}/opnfv/functest/results/${branch}"
306             mkdir -p ${dir_result}
307             sudo rm -rf ${dir_result}/*
308             res_volume="-v ${dir_result}:/home/opnfv/functest/results"
309             custom_params=
310             test -f ${HOME}/opnfv/functest/custom/params_${DOCKER_TAG} && custom_params=$(cat ${HOME}/opnfv/functest/custom/params_${DOCKER_TAG})
311
312             echo "Functest: Pulling image opnfv/functest:${DOCKER_TAG}"
313             docker pull opnfv/functest:$DOCKER_TAG >/dev/null
314
315             cmd="sudo docker run --privileged=true -id ${envs} ${labconfig} ${sshkey} ${res_volume} ${custom_params} opnfv/functest:${DOCKER_TAG} /bin/bash"
316             echo "Functest: Running docker run command: ${cmd}"
317             ${cmd} >${redirect}
318             sleep 5
319             container_id=$(docker ps | grep "opnfv/functest:${DOCKER_TAG}" | awk '{print $1}' | head -1)
320             echo "Container ID=${container_id}"
321             if [ -z ${container_id} ]; then
322                 echo "Cannot find opnfv/functest container ID ${container_id}. Please check if it is existing."
323                 docker ps -a
324                 exit 1
325             fi
326             echo "Starting the container: docker start ${container_id}"
327             docker start ${container_id}
328             sleep 5
329             docker ps >${redirect}
330             if [ $(docker ps | grep "opnfv/functest:${DOCKER_TAG}" | wc -l) == 0 ]; then
331                 echo "The container opnfv/functest with ID=${container_id} has not been properly started. Exiting..."
332                 exit 1
333             fi
334             if [[ ${branch} == *"brahmaputra"* ]]; then
335                 cmd="${FUNCTEST_REPO_DIR}/docker/prepare_env.sh"
336             else
337                 cmd="python ${FUNCTEST_REPO_DIR}/ci/prepare_env.py start"
338             fi
339             echo "Executing command inside the docker: ${cmd}"
340             docker exec ${container_id} ${cmd}
341
342 - builder:
343     name: functest-store-results
344     builders:
345         - shell:
346             !include-raw: ../../utils/push-test-logs.sh
347
348 - builder:
349     name: functest-cleanup
350     builders:
351         - shell: |
352             #!/bin/bash
353             [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
354
355             echo "Cleaning up docker containers/images..."
356             # Remove previous running containers if exist
357             if [[ ! -z $(docker ps -a | grep opnfv/functest) ]]; then
358                 echo "Removing existing opnfv/functest containers..."
359                 docker ps -a | grep opnfv/functest | awk '{print $1}' | xargs docker rm -f >${redirect}
360             fi
361
362             # Remove existing images if exist
363             if [[ ! -z $(docker images | grep opnfv/functest) ]]; then
364                 echo "Docker images to remove:"
365                 docker images | head -1 && docker images | grep opnfv/functest >${redirect}
366                 image_tags=($(docker images | grep opnfv/functest | awk '{print $2}'))
367                 for tag in "${image_tags[@]}"; do
368                     echo "Removing docker image opnfv/functest:$tag..."
369                     docker rmi opnfv/functest:$tag >/dev/null
370                 done
371             fi