9b5e8eecff47ce14153f1862cbd32f98cd9aa1f4
[releng.git] / jjb / bottlenecks / bottlenecks-run-suite.sh
1 #!/bin/bash
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 ##############################################################################
9
10 #set -e
11 [[ $GERRIT_REFSPEC_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
12 BOTTLENECKS_IMAGE=opnfv/bottlenecks
13 REPORT="True"
14
15 RELENG_REPO=${WORKSPACE}/releng
16 [ -d ${RELENG_REPO} ] && rm -rf ${RELENG_REPO}
17 git clone https://gerrit.opnfv.org/gerrit/releng ${RELENG_REPO} >${redirect}
18
19 YARDSTICK_REPO=${WORKSPACE}/yardstick
20 [ -d ${YARDSTICK_REPO} ] && rm -rf ${YARDSTICK_REPO}
21 git clone https://gerrit.opnfv.org/gerrit/yardstick ${YARDSTICK_REPO} >${redirect}
22
23 OPENRC=/tmp/admin_rc.sh
24 OS_CACERT=/tmp/os_cacert
25
26 BOTTLENECKS_CONFIG=/tmp
27 KUBESTONE_TEST_DIR=/home/opnfv/bottlenecks/testsuites/kubestone/testcases
28
29 # Pulling Bottlenecks docker and passing environment variables
30 echo "INFO: pulling Bottlenecks docker ${DOCKER_TAG}"
31 docker pull opnfv/bottlenecks:${DOCKER_TAG} >$redirect
32
33 opts="--privileged=true -id"
34 envs="-e INSTALLER_TYPE=${INSTALLER_TYPE} -e INSTALLER_IP=${INSTALLER_IP} \
35       -e NODE_NAME=${NODE_NAME} -e EXTERNAL_NET=${EXTERNAL_NETWORK} \
36       -e BRANCH=${BRANCH} -e GERRIT_REFSPEC_DEBUG=${GERRIT_REFSPEC_DEBUG} \
37       -e BOTTLENECKS_DB_TARGET=${BOTTLENECKS_DB_TARGET} -e PACKAGE_URL=${PACKAGE_URL} \
38       -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} -e BUILD_TAG=${BUILD_TAG}"
39 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp"
40
41 cmd="docker run ${opts} ${envs} --name bottlenecks-load-master ${docker_volume} opnfv/bottlenecks:${DOCKER_TAG} /bin/bash"
42 echo "BOTTLENECKS INFO: running docker run commond: ${cmd}"
43 ${cmd} >$redirect
44 sleep 5
45
46 # Run test suite
47 if [[ $SUITE_NAME == *posca* ]]; then
48     POSCA_SCRIPT=/home/opnfv/bottlenecks/testsuites/posca
49     sudo rm -f ${OPENRC}
50
51     # Preparing OpenStack RC and Cacert files
52     echo "BOTTLENECKS INFO: fetching os credentials from $INSTALLER_TYPE"
53     if [[ $INSTALLER_TYPE == 'compass' ]]; then
54         ${RELENG_REPO}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${OS_CACERT} >${redirect}
55         if [[ -f ${OS_CACERT} ]]; then
56             echo "BOTTLENECKS INFO: successfully fetching os_cacert for openstack: ${OS_CACERT}"
57         else
58             echo "BOTTLENECKS ERROR: couldn't find os_cacert file: ${OS_CACERT}, please check if the it's been properly provided."
59             exit 1
60         fi
61     fi
62
63     if [[ -f ${OPENRC} ]]; then
64         echo "BOTTLENECKS INFO: openstack credentials path is ${OPENRC}"
65         if [[ $INSTALLER_TYPE == 'compass' ]]; then
66             echo "BOTTLENECKS INFO: writing ${OS_CACERT} to ${OPENRC}"
67             echo "export OS_CACERT=${OS_CACERT}" >> ${OPENRC}
68         fi
69         cat ${OPENRC}
70     else
71         echo "BOTTLENECKS ERROR: couldn't find openstack rc file: ${OPENRC}, please check if the it's been properly provided."
72         exit 1
73     fi
74
75     # Finding and crearting POD description files from different deployments
76     ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
77
78     if [ "$INSTALLER_TYPE" == "fuel" ]; then
79         echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
80         sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${BOTTLENECKS_CONFIG}/id_rsa
81     fi
82
83     if [ "$INSTALLER_TYPE" == "apex" ]; then
84         echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
85         sudo scp $ssh_options stack@${INSTALLER_IP}:~/.ssh/id_rsa ${BOTTLENECKS_CONFIG}/id_rsa
86     fi
87
88     set +e
89
90     sudo -H pip install virtualenv
91
92     cd ${RELENG_REPO}/modules
93     sudo virtualenv venv
94     source venv/bin/activate
95     sudo -H pip install -e ./ >/dev/null
96     sudo -H pip install netaddr
97
98     if [[ ${INSTALLER_TYPE} == compass ]]; then
99         options="-u root -p root"
100     elif [[ ${INSTALLER_TYPE} == fuel ]]; then
101         options="-u root -p r00tme"
102     elif [[ ${INSTALLER_TYPE} == apex ]]; then
103         options="-u stack -k /root/.ssh/id_rsa"
104     else
105         echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
106     fi
107
108     if [[ ${INSTALLER_TYPE} != compass ]]; then
109         cmd="sudo python ${RELENG_REPO}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
110          -i ${INSTALLER_IP} ${options} -f ${BOTTLENECKS_CONFIG}/pod.yaml \
111          -s ${BOTTLENECKS_CONFIG}/id_rsa"
112         echo ${cmd}
113         ${cmd}
114     else
115         cmd="sudo cp ${YARDSTICK_REPO}/etc/yardstick/nodes/compass_sclab_virtual/pod.yaml \
116         ${BOTTLENECKS_CONFIG}"
117         echo ${cmd}
118         ${cmd}
119     fi
120
121     deactivate
122
123     sudo rm -rf ${RELENG_REPO}/modules/venv
124     sudo rm -rf ${RELENG_REPO}/modules/opnfv.egg-info
125
126     set -e
127
128     cd ${WORKSPACE}
129
130     if [ -f ${BOTTLENECKS_CONFIG}/pod.yaml ]; then
131         echo "FILE: ${BOTTLENECKS_CONFIG}/pod.yaml:"
132         cat ${BOTTLENECKS_CONFIG}/pod.yaml
133     else
134         echo "ERROR: cannot find file ${BOTTLENECKS_CONFIG}/pod.yaml. Please check if it is existing."
135         sudo ls -al ${BOTTLENECKS_CONFIG}
136     fi
137
138     # Running test cases through Bottlenecks docker
139     if [[ $SUITE_NAME == posca_stress_traffic ]]; then
140         TEST_CASE=posca_factor_system_bandwidth
141     elif [[ $SUITE_NAME == posca_stress_ping ]]; then
142         TEST_CASE=posca_factor_ping
143     else
144         TEST_CASE=$SUITE_NAME
145     fi
146     testcase_cmd="docker exec bottlenecks-load-master python ${POSCA_SCRIPT}/../run_testsuite.py testcase $TEST_CASE $REPORT"
147     echo "BOTTLENECKS INFO: running test case ${TEST_CASE} with report indicator: ${testcase_cmd}"
148     ${testcase_cmd} >$redirect
149 elif [[ $SUITE_NAME == *kubestone* ]]; then
150     if [[ $SUITE_NAME == kubestone_deployment_capacity ]]; then
151         TEST_CASE=${KUBESTONE_TEST_DIR}/deployment_capacity.yaml
152     fi
153     testcase_cmd="docker exec bottlenecks-load-master python ${KUBESTONE_TEST_DIR}/../stress_test.py -c $TEST_CASE"
154     echo "BOTTLENECKS INFO: running test case ${TEST_CASE} with report indicator: ${testcase_cmd}"
155     ${testcase_cmd} >$redirect
156 fi