946ee1acb567d531252e5b670adde36d5d2e9293
[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     brahmaputra: &brahmaputra
17         stream: brahmaputra
18         branch: 'stable/{stream}'
19         gs-pathname: '/{stream}'
20 #--------------------------------
21 # POD, INSTALLER, AND BRANCH MAPPING
22 #--------------------------------
23 #        brahmaputra
24 #--------------------------------
25     pod:
26         - opnfv-jump-2:
27             installer: fuel
28             <<: *brahmaputra
29         - intel-pod5:
30             installer: joid
31             <<: *brahmaputra
32         - huawei-us-deploy-bare-1:
33             installer: compass
34             <<: *brahmaputra
35 #--------------------------------
36 #        master
37 #--------------------------------
38         - intel-pod6:
39             installer: joid
40             <<: *master
41         - intel-pod8:
42             installer: compass
43             <<: *master
44         - opnfv-jump-1:
45             installer: apex
46             <<: *master
47         - ericsson-pod1:
48             installer: fuel
49             <<: *master
50         - ericsson-pod2:
51             installer: fuel
52             <<: *master
53         - orange-test1:
54             installer: fuel
55             <<: *master
56         - orange-pod2:
57             installer: joid
58             <<: *master
59 #--------------------------------
60
61     testsuite:
62         - 'daily'
63         - 'suite'
64
65     jobs:
66         - 'functest-{installer}-{pod}-{testsuite}-{stream}'
67
68 ################################
69 # job template
70 ################################
71 - job-template:
72     name: 'functest-{installer}-{pod}-{testsuite}-{stream}'
73
74     wrappers:
75         - build-name:
76             name: '$BUILD_NUMBER Suite: $FUNCTEST_SUITE_NAME Scenario: $DEPLOY_SCENARIO'
77
78     parameters:
79         - project-parameter:
80             project: '{project}'
81         - '{pod}-defaults'
82         - '{installer}-defaults'
83         - 'functest-{testsuite}-parameter'
84         - functest-parameter:
85             gs-pathname: '{gs-pathname}'
86
87     scm:
88         - git-scm:
89             credentials-id: '{ssh-credentials}'
90             refspec: ''
91             branch: '{branch}'
92
93     builders:
94         - 'functest-{testsuite}-builder'
95
96 ########################
97 # parameter macros
98 ########################
99 - parameter:
100     name: functest-daily-parameter
101     parameters:
102         - string:
103             name: FUNCTEST_SUITE_NAME
104             default: 'daily'
105             description: "Suite name to run"
106 - parameter:
107     name: functest-suite-parameter
108     parameters:
109         - choice:
110             name: FUNCTEST_SUITE_NAME
111             choices:
112                 - 'tempest'
113                 - 'rally'
114                 - 'odl'
115                 - 'vims'
116                 - 'vping'
117 - parameter:
118     name: functest-parameter
119     parameters:
120         - string:
121             name: GS_PATHNAME
122             default: '{gs-pathname}'
123             description: "Version directory where the opnfv documents will be stored in gs repository"
124         - string:
125             name: FUNCTEST_REPO_DIR
126             default: "/home/opnfv/repos/functest"
127             description: "Directory where the Functest repository is cloned"
128         - string:
129             name: PUSH_RESULTS_TO_DB
130             default: "true"
131             description: "Push the results of all the tests to the resultDB"
132 ########################
133 # trigger macros
134 ########################
135 - trigger:
136     name: 'functest-master'
137     triggers:
138         - pollscm:
139             cron: "H 9 * * *"
140 ########################
141 # builder macros
142 ########################
143 - builder:
144     name: functest-daily-builder
145     builders:
146         - 'functest-cleanup'
147         - 'set-functest-env'
148         - 'functest-all'
149         - 'functest-store-results'
150
151 - builder:
152     name: functest-suite-builder
153     builders:
154         - shell: |
155             #!/bin/bash
156             set +e
157             flag=""
158             if [ "${PUSH_RESULTS_TO_DB}" == "true" ]; then
159                 flag="-r"
160             fi
161             echo "Functest: run $FUNCTEST_SUITE_NAME"
162             cmd="${FUNCTEST_REPO_DIR}/docker/run_tests.sh --test $FUNCTEST_SUITE_NAME ${flag}"
163             container_id=$(docker ps -a | grep opnfv/functest | awk '{print $1}' | head -1)
164             docker exec $container_id $cmd
165
166 - builder:
167     name: functest-all
168     builders:
169         - shell: |
170             #!/bin/bash
171             set +e
172             flag=""
173             if [ "${PUSH_RESULTS_TO_DB}" == "true" ]; then
174                 flag="-r"
175             fi
176             echo "Functest: running all the tests"
177             cmd="${FUNCTEST_REPO_DIR}/docker/run_tests.sh ${flag}"
178             container_id=$(docker ps -a | grep opnfv/functest | awk '{print $1}' | head -1)
179             docker exec $container_id $cmd
180
181 - builder:
182     name: set-functest-env
183     builders:
184         - shell: |
185             #!/bin/bash
186             set +e
187             # labconfig is used only for joid
188             labconfig=""
189             if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
190                 instack_mac=$(sudo virsh domiflist instack | grep default | \
191                               grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
192                 INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
193                 sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
194                 sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
195                 sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
196             elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
197                 # If production lab then creds may be retrieved dynamically
198                 # creds are on the jumphost, always in the same folder
199                 labconfig="-v $LAB_CONFIG/admin-openrc:/home/opnfv/functest/conf/openstack.creds"
200                 # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
201                 # replace the default one by the customized one provided by jenkins config
202             fi
203             echo "Functest: Start Docker and prepare environment"
204             envs="INSTALLER_TYPE=${INSTALLER_TYPE} -e INSTALLER_IP=${INSTALLER_IP} \
205                 -e NODE_NAME=${NODE_NAME} -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO}"
206
207             dir_result="${HOME}/opnfv/functest/reports"
208             mkdir -p ${dir_result}
209             rm -rf ${dir_result}/*
210             $res_volume="-v ${dir_result}:/home/opnfv/functest/results"
211
212             docker pull opnfv/functest:latest_stable
213             cmd="sudo docker run --privileged=true -id -e $envs ${labconfig} ${sshkey} ${res_volume} opnfv/functest:latest_stable /bin/bash"
214             echo "Functest: Running docker run command: ${cmd}"
215             ${cmd}
216             docker ps -a
217             sleep 5
218             container_id=$(docker ps | grep 'opnfv/functest:latest_stable' | awk '{print $1}' | head -1)
219             echo "Container ID=${container_id}"
220             if [ -z ${container_id} ]; then
221                 echo "Cannot find opnfv/functest container ID ${container_id}. Please check if it is existing."
222                 docker ps -a
223                 exit 1
224             fi
225             echo "Starting the container: docker start ${container_id}"
226             docker start ${container_id}
227             sleep 5
228             docker ps
229             if [ $(docker ps | grep 'opnfv/functest:latest_stable' | wc -l) == 0 ]; then
230                 echo "The container opnfv/functest with ID=${container_id} has not been properly started. Exiting..."
231                 exit 1
232             fi
233             cmd="${FUNCTEST_REPO_DIR}/docker/prepare_env.sh"
234             echo "Executing command inside the docker: ${cmd}"
235             docker exec ${container_id} ${cmd}
236
237 - builder:
238     name: functest-store-results
239     builders:
240         - shell:
241             !include-raw: res-build.sh
242
243 - builder:
244     name: functest-cleanup
245     builders:
246         - shell: |
247             #!/bin/bash
248
249             echo "Cleaning up docker containers/images..."
250
251             # Remove previous running containers if exist
252             if [[ ! -z $(docker ps -a | grep opnfv/functest) ]]; then
253                 echo "Removing existing opnfv/functest containers..."
254                 docker ps | grep opnfv/functest | awk '{print $1}' | xargs docker stop
255                 docker ps -a | grep opnfv/functest | awk '{print $1}' | xargs docker rm
256             fi
257
258             # Remove existing images if exist
259             if [[ ! -z $(docker images | grep opnfv/functest) ]]; then
260                 echo "Docker images to remove:"
261                 docker images | head -1 && docker images | grep opnfv/functest
262                 image_tags=($(docker images | grep opnfv/functest | awk '{print $2}'))
263                 for tag in "${image_tags[@]}"; do
264                     echo "Removing docker image opnfv/functest:$tag..."
265                     docker rmi opnfv/functest:$tag
266                 done
267             fi