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