From 2bf95e68a19fc3a7c1e3236a977b1d3b6db1c05c Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Fri, 8 Sep 2017 17:08:59 +0800 Subject: Refactor CI scripts - 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 --- qtip/scripts/quickstart.sh | 101 +++++++++++++++++++++ tests/ci/compute/docker-compose.yaml | 17 ++++ tests/ci/experimental.sh | 19 ++-- tests/ci/launch_containers_by_testsuite.sh | 73 --------------- tests/ci/periodic.sh | 18 +--- tests/ci/run_compute_qpi.sh | 96 -------------------- tests/ci/run_storage_qpi.sh | 26 ------ tests/ci/storage/docker-compose.yaml | 27 ++++++ tests/ci/storperf/containers.sh | 22 ----- .../ci/storperf/qtip-storperf-docker-compose.yaml | 25 ----- tests/ci/utils/start_services.sh | 28 ++++++ 11 files changed, 187 insertions(+), 265 deletions(-) create mode 100644 qtip/scripts/quickstart.sh create mode 100644 tests/ci/compute/docker-compose.yaml mode change 100644 => 100755 tests/ci/experimental.sh delete mode 100755 tests/ci/launch_containers_by_testsuite.sh delete mode 100644 tests/ci/run_compute_qpi.sh delete mode 100755 tests/ci/run_storage_qpi.sh create mode 100644 tests/ci/storage/docker-compose.yaml delete mode 100755 tests/ci/storperf/containers.sh delete mode 100644 tests/ci/storperf/qtip-storperf-docker-compose.yaml create mode 100644 tests/ci/utils/start_services.sh diff --git a/qtip/scripts/quickstart.sh b/qtip/scripts/quickstart.sh new file mode 100644 index 00000000..58a12459 --- /dev/null +++ b/qtip/scripts/quickstart.sh @@ -0,0 +1,101 @@ +#!/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 +############################################################################## + +set -o nounset +set -o errexit +set -o pipefail +set -x + +usage(){ + echo "usage: $0 -q -t -i -p -s -r " >&2 +} + +verify_connectivity(){ + local ip=$1 + echo "Verifying connectivity to $ip..." + for i in $(seq 0 10); do + if ping -c 1 -W 1 $ip > /dev/null; then + echo "$ip is reachable!" + return 0 + fi + sleep 1 + done + error "Can not talk to $ip." +} + +#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} ;; + s) scenario=${OPTARG} ;; + r) testapi_url=${OPTARG} ;; + h) usage + exit 0 + ;; + *) echo "Non-option argument: '-${OPTARG}'" >&2 + usage + exit 2 + ;; + esac +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} + +# we currently support ericsson, intel, lf and zte labs +if [[ ! "$installer_type" =~ (fuel|apex) ]]; then + echo "Unsupported/unidentified installer $installer_type. Cannot continue!" + exit 1 +fi + +sshoptions="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" + +verify_connectivity ${installer_ip} + +case "$installer_type" in + fuel) + ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa -q + sshpass -p r00tme ssh-copy-id $sshoptions ${installer_ip} + ;; +esac + +cd /home/opnfv + +qtip create --project-template ${test_suite} --pod-name ${pod_name} --installer-type ${installer_type} \ +--installer-host ${installer_ip} --scenario ${scenario} ${test_suite} + +cd ${test_suite} + +qtip setup +eval `ssh-agent` +if [[ -z $testapi_url ]];then + qtip run +else + qtip run --extra-vars "testapi_url=$testapi_url" +fi +qtip teardown + +# Remove ssh public key from installer +case "$installer_type" in + fuel) + publickey=$(sed -r 's/\//\\\//g' /root/.ssh/id_rsa.pub) + ssh $sshoptions root@${installer_ip} "sed -i '/$publickey/d' /root/.ssh/authorized_keys" + ;; +esac + +echo "QTIP testing done!" +exit 0 diff --git a/tests/ci/compute/docker-compose.yaml b/tests/ci/compute/docker-compose.yaml new file mode 100644 index 00000000..f21190e9 --- /dev/null +++ b/tests/ci/compute/docker-compose.yaml @@ -0,0 +1,17 @@ +############################################################################## +# 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 +############################################################################## + +version: '2' +services: + + qtip: + container_name: compute_qtip + image: opnfv/qtip:${DOCKER_TAG} + env_file: ${ENV_FILE} + volumes: ${SSH_CREDENTIALS}:/root/.ssh diff --git a/tests/ci/experimental.sh b/tests/ci/experimental.sh old mode 100644 new mode 100755 index 3dd15d56..bb9694b7 --- a/tests/ci/experimental.sh +++ b/tests/ci/experimental.sh @@ -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 index 08b80028..00000000 --- a/tests/ci/launch_containers_by_testsuite.sh +++ /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 diff --git a/tests/ci/periodic.sh b/tests/ci/periodic.sh index 5bbebb93..a0054fec 100755 --- a/tests/ci/periodic.sh +++ b/tests/ci/periodic.sh @@ -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_compute_qpi.sh b/tests/ci/run_compute_qpi.sh deleted file mode 100644 index 7b3987fa..00000000 --- a/tests/ci/run_compute_qpi.sh +++ /dev/null @@ -1,96 +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 -############################################################################## -set -e -set -x - -usage(){ - echo "usage: $0 -t -i -p -s -r " >&2 -} - -verify_connectivity(){ - local ip=$1 - echo "Verifying connectivity to $ip..." - for i in $(seq 0 10); do - if ping -c 1 -W 1 $ip > /dev/null; then - echo "$ip is reachable!" - return 0 - fi - sleep 1 - done - error "Can not talk to $ip." -} - -#Getoptions -while getopts ":t:i:p:s:r:he" optchar; do - case "${optchar}" in - t) installer_type=${OPTARG} ;; - i) installer_ip=${OPTARG} ;; - p) pod_name=${OPTARG} ;; - s) scenario=${OPTARG} ;; - r) testapi_url=${OPTARG} ;; - h) usage - exit 0 - ;; - *) echo "Non-option argument: '-${OPTARG}'" >&2 - usage - exit 2 - ;; - esac -done - -#set vars from env if not provided by user as options -installer_type=${installer_type:-$INSTALLER_TYPE} -installer_ip=${installer_ip:-$INSTALLER_IP} -pod_name=${pod_name:-$NODE_NAME} -scenario=${scenario:-$SCENARIO} -testapi_url=${testapi_url:-$TESTAPI_URL} - -# we currently support ericsson, intel, lf and zte labs -if [[ ! "$installer_type" =~ (fuel|apex) ]]; then - echo "Unsupported/unidentified installer $installer_type. Cannot continue!" - exit 1 -fi - -sshoptions="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" - -verify_connectivity ${installer_ip} - -case "$installer_type" in - fuel) - ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa -q - sshpass -p r00tme ssh-copy-id $sshoptions ${installer_ip} - ;; -esac - -cd /home/opnfv - -qtip create --pod-name ${pod_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 - -# Remove ssh public key from installer -case "$installer_type" in - fuel) - publickey=$(sed -r 's/\//\\\//g' /root/.ssh/id_rsa.pub) - ssh $sshoptions root@${installer_ip} "sed -i '/$publickey/d' /root/.ssh/authorized_keys" - ;; -esac - -echo "Compute QPI done!" -exit 0 \ No newline at end of file diff --git a/tests/ci/run_storage_qpi.sh b/tests/ci/run_storage_qpi.sh deleted file mode 100755 index 275bbb51..00000000 --- a/tests/ci/run_storage_qpi.sh +++ /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 diff --git a/tests/ci/storage/docker-compose.yaml b/tests/ci/storage/docker-compose.yaml new file mode 100644 index 00000000..7ffb0364 --- /dev/null +++ b/tests/ci/storage/docker-compose.yaml @@ -0,0 +1,27 @@ +############################################################################## +# 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 +############################################################################## + +version: '2' +services: + + storperf: + container_name: storage_storperf + image: opnfv/storperf:${DOCKER_TAG} + ports: + - 5000:5000 + env_file: ${ENV_FILE} + + 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/storperf/containers.sh b/tests/ci/storperf/containers.sh deleted file mode 100755 index 62f8d4d5..00000000 --- a/tests/ci/storperf/containers.sh +++ /dev/null @@ -1,22 +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 -############################################################################## - -clean_containers() -{ - echo "QTIP: Cleanup existing qtip and storperf containers" - docker-compose -f qtip-storperf-docker-compose.yaml down -} - - -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 diff --git a/tests/ci/storperf/qtip-storperf-docker-compose.yaml b/tests/ci/storperf/qtip-storperf-docker-compose.yaml deleted file mode 100644 index a1360200..00000000 --- a/tests/ci/storperf/qtip-storperf-docker-compose.yaml +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################## -# 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 -############################################################################## - -version: '2' -services: - - storperf: - container_name: storperf - image: opnfv/storperf:${DOCKER_TAG} - ports: - - 5000:5000 - env_file: ${ENV_FILE} - - qtip: - container_name: qtip - image: opnfv/qtip:${DOCKER_TAG} - env_file: ${ENV_FILE} - links: - - storperf diff --git a/tests/ci/utils/start_services.sh b/tests/ci/utils/start_services.sh new file mode 100644 index 00000000..78bc2970 --- /dev/null +++ b/tests/ci/utils/start_services.sh @@ -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 -- cgit 1.2.3-korg