Refactor CI scripts 83/41383/7
authorYujun Zhang <zhang.yujunz@zte.com.cn>
Fri, 8 Sep 2017 09:08:59 +0000 (17:08 +0800)
committerYujun Zhang <zhang.yujunz@zte.com.cn>
Wed, 13 Sep 2017 07:48:48 +0000 (15:48 +0800)
- Move scripts executed inside container to qtip/scripts
- tests/ci is limited to setup the environment and start services

Change-Id: I454c715890601c6c6472006c2f0f6131695c2f51
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
qtip/scripts/quickstart.sh [moved from tests/ci/run_compute_qpi.sh with 83% similarity]
tests/ci/compute/docker-compose.yaml [moved from tests/ci/storperf/containers.sh with 50% similarity, mode: 0644]
tests/ci/experimental.sh [changed mode: 0644->0755]
tests/ci/launch_containers_by_testsuite.sh [deleted file]
tests/ci/periodic.sh
tests/ci/run_storage_qpi.sh [deleted file]
tests/ci/storage/docker-compose.yaml [moved from tests/ci/storperf/qtip-storperf-docker-compose.yaml with 84% similarity]
tests/ci/utils/start_services.sh [new file with mode: 0644]

similarity index 83%
rename from tests/ci/run_compute_qpi.sh
rename to qtip/scripts/quickstart.sh
index 7b3987f..58a1245 100644 (file)
@@ -6,11 +6,14 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-set -e
+
+set -o nounset
+set -o errexit
+set -o pipefail
 set -x
 
 usage(){
-   echo "usage: $0 -t <installer_type> -i <installer_ip> -p <pod_name> -s <scenario> -r <report_url>" >&2
+   echo "usage: $0 -q <qtip_test_suite> -t <installer_type> -i <installer_ip> -p <pod_name> -s <scenario> -r <report_url>" >&2
 }
 
 verify_connectivity(){
@@ -29,6 +32,7 @@ verify_connectivity(){
 #Getoptions
 while getopts ":t:i:p:s:r:he" optchar; do
    case "${optchar}" in
+       q) test_suite=${OPTARG} ;;
        t) installer_type=${OPTARG} ;;
        i) installer_ip=${OPTARG} ;;
        p) pod_name=${OPTARG} ;;
@@ -47,6 +51,7 @@ done
 #set vars from env if not provided by user as options
 installer_type=${installer_type:-$INSTALLER_TYPE}
 installer_ip=${installer_ip:-$INSTALLER_IP}
+test_suite=${test_suite:-$TEST_SUITE}
 pod_name=${pod_name:-$NODE_NAME}
 scenario=${scenario:-$SCENARIO}
 testapi_url=${testapi_url:-$TESTAPI_URL}
@@ -70,10 +75,10 @@ esac
 
 cd /home/opnfv
 
-qtip create --pod-name ${pod_name} --installer-type ${installer_type} \
---installer-host ${installer_ip} --scenario ${scenario} workspace
+qtip create --project-template ${test_suite} --pod-name ${pod_name} --installer-type ${installer_type} \
+--installer-host ${installer_ip} --scenario ${scenario} ${test_suite}
 
-cd /home/opnfv/workspace/
+cd ${test_suite}
 
 qtip setup
 eval `ssh-agent`
@@ -92,5 +97,5 @@ case "$installer_type" in
         ;;
 esac
 
-echo "Compute QPI done!"
-exit 0
\ No newline at end of file
+echo "QTIP testing done!"
+exit 0
old mode 100755 (executable)
new mode 100644 (file)
similarity index 50%
rename from tests/ci/storperf/containers.sh
rename to tests/ci/compute/docker-compose.yaml
index 62f8d4d..f21190e
@@ -1,22 +1,17 @@
-#! /bin/bash
 ##############################################################################
-# Copyright (c) 2017 ZTE and others.
+# Copyright (c) 2017 Dell EMC, ZTE and others.
+#
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Apache License, Version 2.0
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-clean_containers()
-{
-    echo "QTIP: Cleanup existing qtip and storperf containers"
-    docker-compose -f qtip-storperf-docker-compose.yaml down
-}
+version: '2'
+services:
 
-
-launch_containers()
-{
-    echo "Launch new qtip and storperf containers"
-    docker-compose -f qtip-storperf-docker-compose.yaml pull
-    docker-compose -f qtip-storperf-docker-compose.yaml up -d
-}
\ No newline at end of file
+  qtip:
+    container_name: compute_qtip
+    image: opnfv/qtip:${DOCKER_TAG}
+    env_file: ${ENV_FILE}
+    volumes: ${SSH_CREDENTIALS}:/root/.ssh
old mode 100644 (file)
new mode 100755 (executable)
index 3dd15d5..bb9694b
@@ -12,25 +12,26 @@ set -o pipefail
 set -o nounset
 set -x
 
+script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
 export DEPLOY_SCENARIO='generic'
 export DOCKER_TAG='latest'
 export CI_DEBUG='false'
 export TEST_SUITE='storage'
 export TESTAPI_URL=''
+export SSH_CREDENTIALS='/root/.ssh'
 
 export WORKSPACE=${WORKSPACE:-$(pwd)}
 
-script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-qtip_repo='/home/opnfv/repos/qtip'
+source ${script_dir}/utils/start_services.sh
 
-source $script_dir/launch_containers_by_testsuite.sh
+cd ${WORKSPACE}
 
-container_id=$(docker ps | grep "opnfv/qtip:${DOCKER_TAG}" | awk '{print $1}' | head -1)
+qtip_repo='/home/opnfv/repos/qtip'
+docker cp . ${TEST_SUITE}_qtip:${qtip_repo}
+docker exec ${TEST_SUITE}_qtip bash -c "cd ${qtip_repo} && pip install -U -e ."
 
-echo "QTIP: Copying current submit patch to the container ${container_id}"
-cd $WORKSPACE
-docker cp . ${container_id}:${qtip_repo}
-docker exec ${container_id} bash -c "cd ${qtip_repo} && pip install -U -e ."
-docker exec -t ${container_id} bash -x ${qtip_repo}/tests/ci/run_${TEST_SUITE}_qpi.sh
+docker exec -t ${TEST_SUITE}_qtip bash -x ${qtip_repo}/qtip/scripts/quickstart.sh
 echo "QTIP: Verify ${TEST_SUITE} done!"
+
 exit 0
diff --git a/tests/ci/launch_containers_by_testsuite.sh b/tests/ci/launch_containers_by_testsuite.sh
deleted file mode 100755 (executable)
index 08b8002..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-#! /bin/bash
-##############################################################################
-# Copyright (c) 2017 ZTE and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-export ENV_FILE="${WORKSPACE}/env_file"
-
-if [[ -e $ENV_FILE ]];then
-    rm $ENV_FILE
-fi
-
-case $INSTALLER_TYPE in
-    apex)
-        INSTALLER_IP=`sudo virsh domifaddr undercloud | grep ipv4 | awk '{print $4}' | cut -d/ -f1`
-        ;;
-esac
-
-echo "INSTALLER_TYPE=$INSTALLER_TYPE" >> $ENV_FILE
-echo "INSTALLER_IP=$INSTALLER_IP" >> $ENV_FILE
-echo "NODE_NAME=$NODE_NAME" >> $ENV_FILE
-echo "SCENARIO=$DEPLOY_SCENARIO" >> $ENV_FILE
-echo "TESTAPI_URL=$TESTAPI_URL" >> $ENV_FILE
-
-if [[ "$TEST_SUITE" == 'compute' ]];then
-
-    echo "--------------------------------------------------------"
-    cat $ENV_FILE
-    echo "--------------------------------------------------------"
-
-    echo "Qtip: Pulling docker image: opnfv/qtip:${DOCKER_TAG}"
-    docker pull opnfv/qtip:$DOCKER_TAG >/dev/null
-
-    envs="--env-file $ENV_FILE"
-    vols=""
-    if [[ "$INSTALLER_TYPE" == "apex" ]];then     vols="-v /root/.ssh:/root/.ssh"
-    fi
-
-    container_name="qtip-${TEST_SUITE}"
-    if [[ -n $(docker ps -a|grep ${container_name}) ]]; then
-        echo "QTIP: cleaning existing container"
-        docker stop ${container_name}
-        docker rm ${container_name}
-    fi
-
-    cmd="sudo docker run -id --name ${container_name} ${envs} ${vols} opnfv/qtip:${DOCKER_TAG} /bin/bash"
-    echo "Qtip: Running docker command: ${cmd}"
-    ${cmd}
-
-elif [[ "$TEST_SUITE" == 'storage' ]];then
-    script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-    curl https://git.opnfv.org/releng/plain/utils/fetch_os_creds.sh | bash -s -- \
-        -i $INSTALLER_TYPE -a $INSTALLER_IP -d $WORKSPACE/openrc
-
-    grep "export" $WORKSPACE/openrc | sed "s/export //" >> $ENV_FILE
-    echo "DOCKER_TAG=$DOCKER_TAG" >> $ENV_FILE
-
-    echo "--------------------ENV_FILE----------------------------"
-    cat $ENV_FILE
-    echo "--------------------------------------------------------"
-
-    source $script_dir/storperf/containers.sh
-    cd $script_dir/storperf
-    clean_containers
-    launch_containers
-else
-    echo "QTIP: Sorry, not support test suite $TEST_SUITE!"
-    exit 1
-fi
index 5bbebb9..a0054fe 100755 (executable)
@@ -9,22 +9,12 @@
 set -e
 set -x
 
-export DOCKER_TAG=${DOCKER_TAG:-latest}
-export ENV_FILE=$WORKSPACE/env_file
-QTIP_REPO=/home/opnfv/repos/qtip
-
 script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-source $script_dir/launch_containers_by_testsuite.sh
 
-container_id=$(docker ps | grep "opnfv/qtip:${DOCKER_TAG}" | awk '{print $1}' | head -1)
+source ${script_dir}/utils/start_services.sh
 
-if [[ -z "$container_id" ]]; then
-    echo "QTIP: The container opnfv/qtip has not been properly started. Exiting..."
-    exit 1
-else
-    echo "QTIP: The container ID is: ${container_id}"
-    docker exec -t ${container_id} bash -c "bash ${QTIP_REPO}/tests/ci/run_${TEST_SUITE}_qpi.sh"
-fi
+docker exec -t ${TEST_SUITE}_qtip bash -x ${qtip_repo}/qtip/scripts/quickstart.sh
 
 echo "${TEST_SUITE} QPI done!"
-exit 0
\ No newline at end of file
+
+exit 0
diff --git a/tests/ci/run_storage_qpi.sh b/tests/ci/run_storage_qpi.sh
deleted file mode 100755 (executable)
index 275bbb5..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#! /bin/bash
-##############################################################################
-# Copyright (c) 2017 ZTE and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-cd /home/opnfv
-
-qtip create --project-template storage --pod-name ${NODE_NAME} --installer-type ${INSTALLER_TYPE} \
---installer-host ${INSTALLER_IP} --scenario ${SCENARIO} workspace
-
-cd /home/opnfv/workspace/
-
-qtip setup
-eval `ssh-agent`
-if [[ -z $testapi_url ]];then
-    qtip run
-else
-    qtip run --extra-vars "testapi_url=${TESTAPI_URL}"
-fi
-qtip teardown
similarity index 84%
rename from tests/ci/storperf/qtip-storperf-docker-compose.yaml
rename to tests/ci/storage/docker-compose.yaml
index a136020..7ffb036 100644 (file)
@@ -11,15 +11,17 @@ version: '2'
 services:
 
   storperf:
-    container_name: storperf
+    container_name: storage_storperf
     image: opnfv/storperf:${DOCKER_TAG}
     ports:
       - 5000:5000
     env_file: ${ENV_FILE}
 
   qtip:
-    container_name: qtip
+    container_name: storage_qtip
     image: opnfv/qtip:${DOCKER_TAG}
     env_file: ${ENV_FILE}
+    volumes:
+      - ${SSH_CREDENTIALS}:/root/.ssh
     links:
       - storperf
diff --git a/tests/ci/utils/start_services.sh b/tests/ci/utils/start_services.sh
new file mode 100644 (file)
index 0000000..78bc297
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+# detect installer_ip
+case ${INSTALLER_TYPE} in
+    apex)
+        export INSTALLER_IP=$(sudo virsh domifaddr undercloud | grep ipv4 | awk '{print $4}' | cut -d/ -f1)
+        ;;
+esac
+
+export ENV_FILE="${ENV_FILE:-$(pwd)/env_file}"
+cat << EOF > $ENV_FILE
+INSTALLER_TYPE=${INSTALLER_TYPE}
+INSTALLER_IP=${INSTALLER_IP}
+TEST_SUITE=${TEST_SUITE}
+NODE_NAME=${NODE_NAME:-opnfv-pod}
+SCENARIO=${DEPLOY_SCENARIO:-generic}
+TESTAPI_URL=${TESTAPI_URL:-}
+EOF
+
+TMPFILE=`mktemp /tmp/qtip.XXXXXX` || exit 1
+curl https://git.opnfv.org/releng/plain/utils/fetch_os_creds.sh | bash -s -- \
+    -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -d ${TMPFILE}
+grep "export" ${TMPFILE} | sed "s/export //" >> $ENV_FILE
+# eliminate warning message "Invalid -W option ignored: invalid action: '"ignore'"
+sed -i '/^PYTHONWARNINGS=/d' $ENV_FILE
+
+docker-compose -f $script_dir/${TEST_SUITE}/docker-compose.yaml pull
+docker-compose -f $script_dir/${TEST_SUITE}/docker-compose.yaml up -d