Merge "Update jenkins-job-builder to 2.2.1"
[releng.git] / jjb / dovetail / dovetail-run.sh
index c92ebba..5fe3d36 100755 (executable)
@@ -16,7 +16,7 @@ set -e
 DEPLOY_TYPE=baremetal
 [[ $BUILD_TAG =~ "virtual" ]] && DEPLOY_TYPE=virt
 
-DOVETAIL_HOME=${WORKSPACE}/cvp
+DOVETAIL_HOME=${WORKSPACE}/ovp
 [ -d ${DOVETAIL_HOME} ] && sudo rm -rf ${DOVETAIL_HOME}
 
 mkdir -p ${DOVETAIL_HOME}
@@ -27,13 +27,43 @@ mkdir -p ${DOVETAIL_CONFIG}
 DOVETAIL_IMAGES=${DOVETAIL_HOME}/images
 mkdir -p ${DOVETAIL_IMAGES}
 
+OPENRC=${DOVETAIL_CONFIG}/env_config.sh
+CACERT=${DOVETAIL_CONFIG}/os_cacert
+
 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
 
 sshkey=""
-# The path of openrc.sh is defined in fetch_os_creds.sh
-OPENRC=${DOVETAIL_CONFIG}/env_config.sh
-CACERT=${DOVETAIL_CONFIG}/os_cacert
-if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
+
+check_file_exists() {
+    if [[ -f $1 ]]; then
+        return 0
+    else
+        return 1
+    fi
+}
+
+get_cred_file_with_scripts() {
+    echo "INFO: clone releng repo..."
+    releng_repo=${WORKSPACE}/releng
+    [ -d ${releng_repo} ] && sudo rm -rf ${releng_repo}
+    git clone https://gerrit.opnfv.org/gerrit/releng ${releng_repo} >/dev/null
+
+    echo "INFO: clone pharos repo..."
+    pharos_repo=${WORKSPACE}/pharos
+    [ -d ${pharos_repo} ] && sudo rm -rf ${pharos_repo}
+    git clone https://git.opnfv.org/pharos ${pharos_repo} >/dev/null
+
+    echo "INFO: SUT branch is $SUT_BRANCH"
+    echo "INFO: dovetail branch is $BRANCH"
+    BRANCH_BACKUP=$BRANCH
+    export BRANCH=$SUT_BRANCH
+    cmd="${releng_repo}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${CACERT} >${redirect}"
+    echo "INFO: cmd is ${cmd}"
+    ${cmd}
+    export BRANCH=$BRANCH_BACKUP
+}
+
+get_apex_cred_file() {
     instack_mac=$(sudo virsh domiflist undercloud | grep default | \
                   grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
     INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
@@ -43,59 +73,79 @@ if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
         sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
         sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
     fi
-elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
-    # If production lab then creds may be retrieved dynamically
-    # creds are on the jumphost, always in the same folder
-    sudo cp $LAB_CONFIG/admin-openrc $OPENRC
-    # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
-    # replace the default one by the customized one provided by jenkins config
-fi
+    get_cred_file_with_scripts
+}
 
-# Set iptables rule to allow forwarding return traffic for container
-if ! sudo iptables -C FORWARD -j RETURN 2> ${redirect} || ! sudo iptables -L FORWARD | awk 'NR==3' | grep RETURN 2> ${redirect}; then
-    sudo iptables -I FORWARD -j RETURN
-fi
+get_compass_cred_file() {
+    get_cred_file_with_scripts
+}
 
-releng_repo=${WORKSPACE}/releng
-[ -d ${releng_repo} ] && sudo rm -rf ${releng_repo}
-git clone https://gerrit.opnfv.org/gerrit/releng ${releng_repo} >/dev/null
+get_fuel_cred_file() {
+    get_cred_file_with_scripts
+}
 
-pharos_repo=${WORKSPACE}/pharos
-[ -d ${pharos_repo} ] && sudo rm -rf ${pharos_repo}
-git clone https://git.opnfv.org/pharos ${pharos_repo} >/dev/null
-
-if [[ ${INSTALLER_TYPE} != 'joid' ]]; then
-    echo "SUT branch is $SUT_BRANCH"
-    echo "dovetail branch is $BRANCH"
-    BRANCH_BACKUP=$BRANCH
-    export BRANCH=$SUT_BRANCH
-    ${releng_repo}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${CACERT} >${redirect}
-    export BRANCH=$BRANCH_BACKUP
-fi
+get_joid_cred_file() {
+    # If production lab then creds may be retrieved dynamically
+    # creds are on the jumphost, always in the same folder
+    sudo cp $LAB_CONFIG/admin-openrc $OPENRC
+}
 
-if [[ -f $OPENRC ]]; then
-    echo "INFO: openstack credentials path is $OPENRC"
-    if [[ ! "${SUT_BRANCH}" =~ "danube" && ${INSTALLER_TYPE} == "compass" ]]; then
-        if [[ -f ${CACERT} ]]; then
-            echo "INFO: ${INSTALLER_TYPE} openstack cacert file is ${CACERT}"
+change_cred_file_cacert_path() {
+    check_file_exists ${CACERT}
+    if [[ $? == 0 ]]; then
+        echo "INFO: set ${INSTALLER_TYPE} openstack cacert file to be ${CACERT}"
+        if [[ ${INSTALLER_TYPE} == "compass" ]]; then
             echo "export OS_CACERT=${CACERT}" >> ${OPENRC}
-        else
-            echo "ERROR: Can't find ${INSTALLER_TYPE} openstack cacert file. Please check if it is existing."
-            sudo ls -al ${DOVETAIL_CONFIG}
-            exit 1
+        elif [[ ${INSTALLER_TYPE} == "fuel" ]]; then
+            sed -i "s#/etc/ssl/certs/mcp_os_cacert#${CACERT}#g" ${OPENRC}
         fi
+    else
+        echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
+        sudo ls -al ${DOVETAIL_CONFIG}
+        exit 1
     fi
-    echo "export EXTERNAL_NETWORK=${EXTERNAL_NETWORK}" >> ${OPENRC}
-else
-    echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
-    sudo ls -al ${DOVETAIL_CONFIG}
-    exit 1
-fi
+}
 
-if [[ ! "${SUT_BRANCH}" =~ "danube" && ${INSTALLER_TYPE} == "fuel" ]]; then
-    sed -i "s#/etc/ssl/certs/mcp_os_cacert#${CACERT}#g" ${OPENRC}
-fi
-cat $OPENRC
+change_cred_file_ext_net() {
+    check_file_exists ${OPENRC}
+    if [[ $? == 0 ]]; then
+        echo "export EXTERNAL_NETWORK=${EXTERNAL_NETWORK}" >> ${OPENRC}
+    else
+        echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
+        sudo ls -al ${DOVETAIL_CONFIG}
+        exit 1
+    fi
+}
+
+get_cred_file() {
+    if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
+        get_apex_cred_file
+    elif [[ ${INSTALLER_TYPE} == 'compass' ]]; then
+        get_compass_cred_file
+    elif [[ ${INSTALLER_TYPE} == 'fuel' ]]; then
+        get_fuel_cred_file
+    elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
+        get_joid_cred_file
+    fi
+
+    check_file_exists ${OPENRC}
+    if [[ $? == 0 ]]; then
+        echo "INFO: original openstack credentials file is"
+        cat $OPENRC
+        echo "INFO: change cacert file path in credentials file"
+        change_cred_file_cacert_path
+        echo "INFO: set external network in credentials file"
+        change_cred_file_ext_net
+        echo "INFO: final openstack credentials file is"
+        cat $OPENRC
+    else
+        echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
+        sudo ls -al ${DOVETAIL_CONFIG}
+        exit 1
+    fi
+}
+
+get_cred_file
 
 # These packages are used for parsing yaml files and decrypting ipmi user and password.
 sudo pip install shyaml
@@ -134,10 +184,10 @@ if [[ ! "${SUT_BRANCH}" =~ "danube" && ${INSTALLER_TYPE} == 'fuel' && ${DEPLOY_T
             "sudo salt 'cmp001*' pillar.get _param:openstack_control_address --out text| \
                 cut -f2 -d' '")
     fuel_dbs_ip=$(ssh 2>/dev/null ${fuel_ctl_ssh_options} "${ssh_user}@${INSTALLER_IP}" \
-            "sudo salt 'dbs01*' pillar.get _param:openstack_control_address --out text| \
+            "sudo salt 'dbs01*' pillar.get _param:openstack_database_node01_address --out text| \
                 cut -f2 -d' '")
     fuel_msg_ip=$(ssh 2>/dev/null ${fuel_ctl_ssh_options} "${ssh_user}@${INSTALLER_IP}" \
-            "sudo salt 'msg01*' pillar.get _param:openstack_control_address --out text| \
+            "sudo salt 'msg01*' pillar.get _param:openstack_message_queue_node01_address --out text| \
                 cut -f2 -d' '")
     ipmi_index=$(ssh 2>/dev/null ${fuel_ctl_ssh_options} "${ssh_user}@${INSTALLER_IP}" \
             "sudo salt 'ctl*' network.ip_addrs cidr=${fuel_ctl_ip} --out text | grep ${fuel_ctl_ip} | cut -c 5")
@@ -207,15 +257,21 @@ if [ -f ${DOVETAIL_CONFIG}/pod.yaml ]; then
     if [ "$INSTALLER_TYPE" == "apex" ]; then
         cat << EOF >> ${DOVETAIL_CONFIG}/pod.yaml
 process_info:
-- {testcase_name: dovetail.ha.rabbitmq, attack_process: rabbitmq_server}
+- {testcase_name: yardstick.ha.rabbitmq, attack_process: rabbitmq_server}
+- {testcase_name: yardstick.ha.cinder_api, attack_process: cinder_wsgi}
 EOF
     elif [ "$INSTALLER_TYPE" == "fuel" ]; then
         cat << EOF >> ${DOVETAIL_CONFIG}/pod.yaml
 process_info:
-- {testcase_name: dovetail.ha.cinder_api, attack_process: cinder_wsgi}
-- {testcase_name: dovetail.ha.rabbitmq, attack_process: rabbitmq-server, attack_host: msg01}
-- {testcase_name: dovetail.ha.neutron_l3_agent, attack_process: neutron-l3-agent, attack_host: cmp01}
-- {testcase_name: dovetail.ha.database, attack_process: mysqld, attack_host: dbs01}
+- {testcase_name: yardstick.ha.cinder_api, attack_process: cinder-wsgi}
+- {testcase_name: yardstick.ha.rabbitmq, attack_process: rabbitmq_server, attack_host: msg01}
+- {testcase_name: yardstick.ha.neutron_l3_agent, attack_process: neutron-l3-agent, attack_host: cmp01}
+- {testcase_name: yardstick.ha.database, attack_process: mysqld, attack_host: dbs01}
+EOF
+    elif [ "$INSTALLER_TYPE" == "compass" ]; then
+        cat << EOF >> ${DOVETAIL_CONFIG}/pod.yaml
+process_info:
+- {testcase_name: yardstick.ha.rabbitmq, attack_process: rabbitmq}
 EOF
     fi
 
@@ -255,7 +311,7 @@ fi
 ubuntu_image=${image_path}/ubuntu-16.04-server-cloudimg-amd64-disk1.img
 if [[ ! -f ${ubuntu_image} ]]; then
     echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
-    wget -q -nc http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${image_path}
+    wget -q -nc https://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${image_path}
 fi
 sudo cp ${ubuntu_image} ${DOVETAIL_IMAGES}
 
@@ -372,11 +428,18 @@ else
     testarea="--testarea ${TESTAREA}"
 fi
 
-run_cmd="dovetail run ${testsuite} ${testarea} -d"
+run_cmd="dovetail run ${testsuite} ${testarea} --deploy-scenario ${DEPLOY_SCENARIO} -d -r"
 echo "Container exec command: ${run_cmd}"
 docker exec $container_id ${run_cmd}
 
 sudo cp -r ${DOVETAIL_HOME}/results ./
+result_package=$(find ${DOVETAIL_HOME} -name 'logs_*')
+echo "Results package is ${result_package}"
+for item in ${result_package};
+do
+  sudo mv ${item} ./results
+done
+
 # To make sure the file owner is the current user, for the copied results files in the above line
 echo "Change owner of result files ..."
 CURRENT_USER=${SUDO_USER:-$USER}
@@ -387,7 +450,7 @@ sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ./results
 #remove useless files to save disk space
 sudo rm -rf ./results/workspace
 sudo rm -f ./results/yardstick.img
-sudo rm -f ./results/tmp*
+sudo rm -f ./results/bottlenecks/tmp*
 
 echo "Dovetail: done!"