2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 #the noun INSTALLER is used in community, here is just the example to run.
11 #multi-platforms are supported.
14 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
17 [[ $BUILD_TAG =~ "virtual" ]] && DEPLOY_TYPE=virt
19 DOVETAIL_HOME=${WORKSPACE}/ovp
20 [ -d ${DOVETAIL_HOME} ] && sudo rm -rf ${DOVETAIL_HOME}
22 mkdir -p ${DOVETAIL_HOME}
24 DOVETAIL_CONFIG=${DOVETAIL_HOME}/pre_config
25 mkdir -p ${DOVETAIL_CONFIG}
27 DOVETAIL_IMAGES=${DOVETAIL_HOME}/images
28 mkdir -p ${DOVETAIL_IMAGES}
30 OPENRC=${DOVETAIL_CONFIG}/env_config.sh
31 CACERT=${DOVETAIL_CONFIG}/os_cacert
32 POD=${DOVETAIL_CONFIG}/pod.yaml
34 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
38 TEST_DB_URL=http://testresults.opnfv.org/test/api/v1/results
48 get_cred_file_with_scripts() {
49 echo "INFO: clone releng repo..."
50 releng_repo=${WORKSPACE}/releng
51 [ -d ${releng_repo} ] && sudo rm -rf ${releng_repo}
52 git clone https://gerrit.opnfv.org/gerrit/releng ${releng_repo} >/dev/null
54 echo "INFO: clone pharos repo..."
55 pharos_repo=${WORKSPACE}/pharos
56 [ -d ${pharos_repo} ] && sudo rm -rf ${pharos_repo}
57 git clone https://git.opnfv.org/pharos ${pharos_repo} >/dev/null
59 echo "INFO: SUT branch is $SUT_BRANCH"
60 echo "INFO: dovetail branch is $BRANCH"
62 export BRANCH=$SUT_BRANCH
63 cmd="${releng_repo}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${CACERT} >${redirect}"
64 echo "INFO: cmd is ${cmd}"
66 export BRANCH=$BRANCH_BACKUP
69 get_apex_cred_file() {
70 instack_mac=$(sudo virsh domiflist undercloud | grep default | \
71 grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
72 INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
73 sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
74 if [[ -n $(sudo iptables -L FORWARD |grep "REJECT"|grep "reject-with icmp-port-unreachable") ]]; then
75 #note: this happens only in opnfv-lf-pod1
76 sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
77 sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
79 get_cred_file_with_scripts
82 get_compass_cred_file() {
83 get_cred_file_with_scripts
86 get_fuel_cred_file() {
87 get_cred_file_with_scripts
90 get_joid_cred_file() {
91 # If production lab then creds may be retrieved dynamically
92 # creds are on the jumphost, always in the same folder
93 sudo cp $LAB_CONFIG/admin-openrc $OPENRC
96 change_cred_file_cacert_path() {
97 if [[ ${INSTALLER_TYPE} == "apex" ]]; then
98 echo "INFO: apex doesn't need to set OS_CACERT."
101 exists=`check_file_exists ${CACERT}`
102 if [[ $exists == 0 ]]; then
103 echo "INFO: set ${INSTALLER_TYPE} openstack cacert file to be ${CACERT}"
104 if [[ ${INSTALLER_TYPE} == "compass" ]]; then
105 echo "export OS_CACERT=${CACERT}" >> ${OPENRC}
106 elif [[ ${INSTALLER_TYPE} == "fuel" ]]; then
107 sed -i "s#/etc/ssl/certs/mcp_os_cacert#${CACERT}#g" ${OPENRC}
110 echo "ERROR: cannot find file ${CACERT}. Please check if it exists."
111 sudo ls -al ${DOVETAIL_CONFIG}
116 change_cred_file_ext_net() {
117 exists=`check_file_exists ${OPENRC}`
118 if [[ $exists == 0 ]]; then
119 echo "export EXTERNAL_NETWORK=${EXTERNAL_NETWORK}" >> ${OPENRC}
121 echo "ERROR: cannot find file $OPENRC. Please check if it exists."
122 sudo ls -al ${DOVETAIL_CONFIG}
128 if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
130 elif [[ ${INSTALLER_TYPE} == 'compass' ]]; then
131 get_compass_cred_file
132 elif [[ ${INSTALLER_TYPE} == 'fuel' ]]; then
134 elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
138 exists=`check_file_exists ${OPENRC}`
139 if [[ $exists == 0 ]]; then
140 echo "INFO: original openstack credentials file is:"
142 echo "INFO: change cacert file path in credentials file"
143 change_cred_file_cacert_path
144 echo "INFO: set external network in credentials file"
145 change_cred_file_ext_net
146 echo "INFO: final openstack credentials file is:"
149 echo "ERROR: cannot find file $OPENRC. Please check if it exists."
150 sudo ls -al ${DOVETAIL_CONFIG}
155 get_compass_pod_file() {
156 compass_repo=${WORKSPACE}/compass4nfv/
157 echo "INFO: clone compass repo..."
158 git clone https://github.com/opnfv/compass4nfv.git ${compass_repo} >/dev/null
159 scenario_file=${compass_repo}/deploy/conf/hardware_environment/$NODE_NAME/os-nosdn-nofeature-ha.yml
160 ipmiIp=$(cat ${scenario_file} | shyaml get-value hosts.0.ipmiIp)
161 ipmiPass=$(cat ${scenario_file} | shyaml get-value hosts.0.ipmiPass)
163 jumpserver_ip=$(ifconfig | grep -A 5 docker0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1)
167 - {ip: ${jumpserver_ip}, name: node0, password: root, role: Jumpserver, user: root}
168 - {ip: 10.1.0.50, name: node1, password: root, role: controller, user: root,
169 ipmi_ip: ${ipmiIp}, ipmi_user: ${ipmiUser}, ipmi_password: ${ipmiPass}}
170 - {ip: 10.1.0.51, name: node2, password: root, role: controller, user: root}
171 - {ip: 10.1.0.52, name: node3, password: root, role: controller, user: root}
172 - {ip: 10.1.0.53, name: node4, password: root, role: compute, user: root}
173 - {ip: 10.1.0.54, name: node5, password: root, role: compute, user: root}
179 get_fuel_baremetal_pod_file() {
180 fuel_ctl_ssh_options="${ssh_options} -i ${SSH_KEY}"
182 fuel_ctl_ip=$(ssh 2>/dev/null ${fuel_ctl_ssh_options} "${ssh_user}@${INSTALLER_IP}" \
183 "sudo salt 'cfg*' pillar.get _param:openstack_control_address --out text| \
185 fuel_cmp_ip=$(ssh 2>/dev/null ${fuel_ctl_ssh_options} "${ssh_user}@${INSTALLER_IP}" \
186 "sudo salt 'cmp001*' pillar.get _param:openstack_control_address --out text| \
188 fuel_dbs_ip=$(ssh 2>/dev/null ${fuel_ctl_ssh_options} "${ssh_user}@${INSTALLER_IP}" \
189 "sudo salt 'dbs01*' pillar.get _param:openstack_database_node01_address --out text| \
191 fuel_msg_ip=$(ssh 2>/dev/null ${fuel_ctl_ssh_options} "${ssh_user}@${INSTALLER_IP}" \
192 "sudo salt 'msg01*' pillar.get _param:openstack_message_queue_node01_address --out text| \
194 ipmi_index=$(ssh 2>/dev/null ${fuel_ctl_ssh_options} "${ssh_user}@${INSTALLER_IP}" \
195 "sudo salt 'ctl*' network.ip_addrs cidr=${fuel_ctl_ip} --out text | grep ${fuel_ctl_ip} | cut -c 5")
197 organization="$(cut -d'-' -f1 <<< "${NODE_NAME}")"
198 pod_name="$(cut -d'-' -f2 <<< "${NODE_NAME}")"
199 pdf_file=${pharos_repo}/labs/${organization}/${pod_name}.yaml
200 ipmiIp=$(cat ${pdf_file} | shyaml get-value nodes.$[ipmi_index-1].remote_management.address)
201 ipmiIp="$(cut -d'/' -f1 <<< "${ipmiIp}")"
202 ipmiPass=$(cat ${pdf_file} | shyaml get-value nodes.$[ipmi_index-1].remote_management.pass)
203 ipmiUser=$(cat ${pdf_file} | shyaml get-value nodes.$[ipmi_index-1].remote_management.user)
204 [[ $ipmiUser == ENC* ]] && ipmiUser=$(eyaml decrypt -s ${ipmiUser//[[:blank:]]/})
205 [[ $ipmiPass == ENC* ]] && ipmiPass=$(eyaml decrypt -s ${ipmiPass//[[:blank:]]/})
209 - {ip: ${INSTALLER_IP}, name: node0, key_filename: ${DOVETAIL_CONFIG}/id_rsa,
210 role: Jumpserver, user: ${ssh_user}}
211 - {ip: ${fuel_ctl_ip}, name: node1, key_filename: ${DOVETAIL_CONFIG}/id_rsa,
212 role: controller, user: ${ssh_user}, ipmi_ip: ${ipmiIp}, ipmi_user: ${ipmiUser}, ipmi_password: ${ipmiPass}}
213 - {ip: ${fuel_msg_ip}, name: msg01, key_filename: ${DOVETAIL_CONFIG}/id_rsa, role: controller, user: ${ssh_user}}
214 - {ip: ${fuel_cmp_ip}, name: cmp01, key_filename: ${DOVETAIL_CONFIG}/id_rsa, role: controller, user: ${ssh_user}}
215 - {ip: ${fuel_dbs_ip}, name: dbs01, key_filename: ${DOVETAIL_CONFIG}/id_rsa, role: controller, user: ${ssh_user}}
219 get_pod_file_with_scripts() {
221 sudo pip install virtualenv
223 cd ${releng_repo}/modules
225 source venv/bin/activate
226 sudo pip install -e ./ >/dev/null
227 sudo pip install netaddr
229 if [[ ${INSTALLER_TYPE} == compass ]]; then
230 options="-u root -p root"
231 elif [[ ${INSTALLER_TYPE} == fuel ]]; then
232 options="-u ubuntu -k /root/.ssh/id_rsa"
233 elif [[ ${INSTALLER_TYPE} == apex ]]; then
234 options="-u stack -k /root/.ssh/id_rsa"
235 elif [[ ${INSTALLER_TYPE} == daisy ]]; then
236 options="-u root -p r00tme"
238 echo "WARNING: Don't support to generate ${POD} on ${INSTALLER_TYPE} currently."
239 echo "WARNING: HA test cases may not run properly."
242 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
243 -i ${INSTALLER_IP} ${options} -f ${POD} \
244 -s ${DOVETAIL_CONFIG}/id_rsa"
245 echo "INFO: cmd is ${cmd}"
253 change_apex_pod_file_process_info() {
256 - {testcase_name: yardstick.ha.rabbitmq, attack_process: rabbitmq_server}
257 - {testcase_name: yardstick.ha.cinder_api, attack_process: cinder_wsgi}
261 change_fuel_pod_file_process_info() {
264 - {testcase_name: yardstick.ha.cinder_api, attack_process: cinder-wsgi}
265 - {testcase_name: yardstick.ha.rabbitmq, attack_process: rabbitmq_server, attack_host: msg01}
266 - {testcase_name: yardstick.ha.neutron_l3_agent, attack_process: neutron-l3-agent, attack_host: cmp01}
267 - {testcase_name: yardstick.ha.database, attack_process: mysqld, attack_host: dbs01}
271 change_compass_pod_file_process_info() {
274 - {testcase_name: yardstick.ha.rabbitmq, attack_process: rabbitmq}
278 change_pod_file_process_info() {
279 sudo chmod 666 ${POD}
280 echo "INFO: adapt process info for $INSTALLER_TYPE ..."
281 if [ "$INSTALLER_TYPE" == "apex" ]; then
282 change_apex_pod_file_process_info
283 elif [ "$INSTALLER_TYPE" == "fuel" ]; then
284 change_fuel_pod_file_process_info
285 elif [ "$INSTALLER_TYPE" == "compass" ]; then
286 change_compass_pod_file_process_info
291 # These packages are used for parsing yaml files and decrypting ipmi user and password.
292 sudo pip install shyaml
293 sudo yum install -y rubygems || sudo apt-get install -y ruby
294 sudo gem install hiera-eyaml
295 if [[ ${INSTALLER_TYPE} == 'compass' ]]; then
297 elif [[ ${INSTALLER_TYPE} == 'fuel' && ${DEPLOY_TYPE} == 'baremetal' ]]; then
298 get_fuel_baremetal_pod_file
301 exists=`check_file_exists ${POD}`
302 if [[ $exists == 1 ]]; then
303 get_pod_file_with_scripts
306 exists=`check_file_exists ${POD}`
307 if [[ $exists == 0 ]]; then
308 change_pod_file_process_info
310 echo "ERROR: cannot find file ${POD}. Please check if it exists."
311 sudo ls -al ${DOVETAIL_CONFIG}
315 echo "INFO: file ${POD} is:"
322 if [ "$INSTALLER_TYPE" == "fuel" ]; then
323 if [[ "${SUT_BRANCH}" =~ "danube" ]]; then
324 echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
325 sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
327 cp ${SSH_KEY} ${DOVETAIL_CONFIG}/id_rsa
331 if [ "$INSTALLER_TYPE" == "apex" ]; then
332 echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
333 sudo scp $ssh_options stack@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
336 if [ "$INSTALLER_TYPE" == "daisy" ]; then
337 echo "Fetching id_dsa file from jump_server $INSTALLER_IP..."
338 sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_dsa ${DOVETAIL_CONFIG}/id_rsa
342 image_path=${HOME}/opnfv/dovetail/images
343 if [[ ! -d ${image_path} ]]; then
344 mkdir -p ${image_path}
346 # sdnvpn test case needs to download this image first before running
347 ubuntu_image=${image_path}/ubuntu-16.04-server-cloudimg-amd64-disk1.img
348 if [[ ! -f ${ubuntu_image} ]]; then
349 echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
350 wget -q -nc https://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${image_path}
352 sudo cp ${ubuntu_image} ${DOVETAIL_IMAGES}
354 # yardstick and bottlenecks need to download this image first before running
355 cirros_image=${image_path}/cirros-0.3.5-x86_64-disk.img
356 if [[ ! -f ${cirros_image} ]]; then
357 echo "Download image cirros-0.3.5-x86_64-disk.img ..."
358 wget -q -nc http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img -P ${image_path}
360 sudo cp ${cirros_image} ${DOVETAIL_IMAGES}
362 # functest needs to download this image first before running
363 cirros_image=${image_path}/cirros-0.4.0-x86_64-disk.img
364 if [[ ! -f ${cirros_image} ]]; then
365 echo "Download image cirros-0.4.0-x86_64-disk.img ..."
366 wget -q -nc http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img -P ${image_path}
368 sudo cp ${cirros_image} ${DOVETAIL_IMAGES}
370 # snaps_smoke test case needs to download this image first before running
371 ubuntu14_image=${image_path}/ubuntu-14.04-server-cloudimg-amd64-disk1.img
372 if [[ ! -f ${ubuntu14_image} ]]; then
373 echo "Download image ubuntu-14.04-server-cloudimg-amd64-disk1.img ..."
374 wget -q -nc https://cloud-images.ubuntu.com/releases/14.04/release/ubuntu-14.04-server-cloudimg-amd64-disk1.img -P ${image_path}
376 sudo cp ${ubuntu14_image} ${DOVETAIL_IMAGES}
378 # cloudify_ims test case needs to download these 2 images first before running
379 cloudify_image=${image_path}/cloudify-manager-premium-4.0.1.qcow2
380 if [[ ! -f ${cloudify_image} ]]; then
381 echo "Download image cloudify-manager-premium-4.0.1.qcow2 ..."
382 wget -q -nc http://repository.cloudifysource.org/cloudify/4.0.1/sp-release/cloudify-manager-premium-4.0.1.qcow2 -P ${image_path}
384 sudo cp ${cloudify_image} ${DOVETAIL_IMAGES}
385 trusty_image=${image_path}/trusty-server-cloudimg-amd64-disk1.img
386 if [[ ! -f ${trusty_image} ]]; then
387 echo "Download image trusty-server-cloudimg-amd64-disk1.img ..."
388 wget -q -nc http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img -P ${image_path}
390 sudo cp ${trusty_image} ${DOVETAIL_IMAGES}
392 opts="--privileged=true -id"
394 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock"
395 dovetail_home_volume="-v ${DOVETAIL_HOME}:${DOVETAIL_HOME}"
397 # Pull the image with correct tag
398 DOCKER_REPO='opnfv/dovetail'
399 if [ "$(uname -m)" = 'aarch64' ]; then
400 DOCKER_REPO="${DOCKER_REPO}_$(uname -m)"
404 echo "Dovetail: Pulling image ${DOCKER_REPO}:${DOCKER_TAG}"
405 docker pull ${DOCKER_REPO}:$DOCKER_TAG >$redirect
407 cmd="docker run ${opts} -e DOVETAIL_HOME=${DOVETAIL_HOME} -e INSTALLER_TYPE=${INSTALLER_TYPE} \
408 -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} -e NODE_NAME=${NODE_NAME} -e BUILD_TAG=${BUILD_TAG} \
409 -e TEST_DB_URL=${TEST_DB_URL} -e VERSION=${SUT_BRANCH} \
410 ${docker_volume} ${dovetail_home_volume} \
411 ${sshkey} ${DOCKER_REPO}:${DOCKER_TAG} /bin/bash"
412 echo "Dovetail: running docker run command: ${cmd}"
415 container_id=$(docker ps | grep "${DOCKER_REPO}:${DOCKER_TAG}" | awk '{print $1}' | head -1)
416 echo "Container ID=${container_id}"
417 if [ -z ${container_id} ]; then
418 echo "Cannot find ${DOCKER_REPO} container ID ${container_id}. Please check if it exists."
422 echo "Container Start: docker start ${container_id}"
423 docker start ${container_id}
425 docker ps >${redirect}
426 if [ $(docker ps | grep "${DOCKER_REPO}:${DOCKER_TAG}" | wc -l) == 0 ]; then
427 echo "The container ${DOCKER_REPO} with ID=${container_id} has not been properly started. Exiting..."
431 # Modify tempest_conf.yaml file
432 tempest_conf_file=${DOVETAIL_CONFIG}/tempest_conf.yaml
433 if [[ ${INSTALLER_TYPE} == 'compass' || ${INSTALLER_TYPE} == 'apex' ]]; then
439 cat << EOF >$tempest_conf_file
443 volume_device_name: ${volume_device}
447 echo "${tempest_conf_file}..."
448 cat ${tempest_conf_file}
450 cp_tempest_cmd="docker cp ${DOVETAIL_CONFIG}/tempest_conf.yaml $container_id:/home/opnfv/dovetail/dovetail/userconfig"
451 echo "exec command: ${cp_tempest_cmd}"
454 if [[ ${TESTSUITE} == 'default' ]]; then
457 testsuite="--testsuite ${TESTSUITE}"
460 if [[ ${TESTAREA} == 'mandatory' ]]; then
461 testarea='--mandatory'
462 elif [[ ${TESTAREA} == 'optional' ]]; then
463 testarea="--optional"
464 elif [[ ${TESTAREA} == 'all' ]]; then
467 testarea="--testarea ${TESTAREA}"
470 run_cmd="dovetail run ${testsuite} ${testarea} --deploy-scenario ${DEPLOY_SCENARIO} -d -r --opnfv-ci"
471 echo "Container exec command: ${run_cmd}"
472 docker exec $container_id ${run_cmd}
474 sudo cp -r ${DOVETAIL_HOME}/results ./
475 result_package=$(find ${DOVETAIL_HOME} -name 'logs_*')
476 echo "Results package is ${result_package}"
477 for item in ${result_package};
479 sudo mv ${item} ./results
482 # To make sure the file owner is the current user, for the copied results files in the above line
483 echo "Change owner of result files ..."
484 CURRENT_USER=${SUDO_USER:-$USER}
485 PRIMARY_GROUP=$(id -gn $CURRENT_USER)
486 echo "Current user is ${CURRENT_USER}, group is ${PRIMARY_GROUP}"
487 sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ./results
489 #remove useless files to save disk space
490 sudo rm -rf ./results/workspace
491 sudo rm -f ./results/yardstick.img
492 sudo rm -f ./results/bottlenecks/tmp*
494 echo "Dovetail: done!"