From 5203913e8e39ad20c26dee453a0217bcba902785 Mon Sep 17 00:00:00 2001 From: Linda Wang Date: Thu, 25 Jan 2018 04:15:51 +0000 Subject: [PATCH] [Functest] Run k8s tests on Compass Change-Id: I8e88ab0598f43be8d0c9c4ad199dba91c1561f13 Signed-off-by: Linda Wang --- jjb/functest/functest-daily-jobs.yml | 38 +++++++++++++++++++++- jjb/functest/functest-k8.sh | 55 +++++++++++++++++++++++++++++++ utils/fetch_k8_conf.sh | 63 ++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100755 jjb/functest/functest-k8.sh create mode 100755 utils/fetch_k8_conf.sh diff --git a/jjb/functest/functest-daily-jobs.yml b/jjb/functest/functest-daily-jobs.yml index 79e5c1503..1f17a507e 100644 --- a/jjb/functest/functest-daily-jobs.yml +++ b/jjb/functest/functest-daily-jobs.yml @@ -244,12 +244,31 @@ builders: - description-setter: description: "Built on $NODE_NAME" - - 'functest-{testsuite}-builder' + - conditional-step: + condition-kind: regex-match + regex: "os-*" + label: 'DEPLOY_SCENARIO' + steps: + - 'functest-{testsuite}-builder' + - conditional-step: + condition-kind: regex-match + regex: "k8-*" + label: 'DEPLOY_SCENARIO' + steps: + - 'functest-k8-builder' ######################## # parameter macros ######################## +- parameter: + name: functest-k8-parameter + parameters: + - string: + name: FUNCTEST_MODE + default: 'daily' + description: "Daily suite name to run on K8 deployment" + - parameter: name: functest-daily-parameter parameters: @@ -374,6 +393,23 @@ - 'functest-store-results' - 'functest-exit' +- builder: + name: functest-k8-builder + builders: + - 'functest-cleanup' + - 'functest-daily-k8' + - 'functest-store-results' + - 'functest-exit' + +- builder: + name: functest-daily-k8 + builders: + # yamllint disable rule:indentation + - shell: + !include-raw: + - ../../utils/fetch_k8_conf.sh + - ./functest-k8.sh + - builder: name: functest-daily builders: diff --git a/jjb/functest/functest-k8.sh b/jjb/functest/functest-k8.sh new file mode 100755 index 000000000..6df5c53b0 --- /dev/null +++ b/jjb/functest/functest-k8.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +set -e +set +u +set +o pipefail + +[[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null" +FUNCTEST_DIR=/home/opnfv/functest + +rc_file=${HOME}/k8.creds +sudo rm -rf $rc_file + +if [[ ${INSTALLER_TYPE} == 'compass' ]]; then + admin_conf_file_vol = "-v ${HOME}/admin.conf:/root/.kube/config" + echo "export KUBECONFIG=/root/.kube/config" >> $rc_file + echo "export KUBERNETES_PROVIDER=local" >> $rc_file + KUBE_MASTER_URL = $(cat ${HOME}/admin.conf|grep server| awk '{print $2}') + echo "export KUBE_MASTER_URL=$KUBE_MASTER_URL" >> $rc_file + KUBE_MASTER_IP = $(echo $KUBE_MASTER_URL|awk -F'https://|:[0-9]+' '$0=$2') + echo "export KUBE_MASTER_IP=$KUBE_MASTER_IP" >> $rc_file +else + echo "Not supported by other installers yet" + exit 1 +fi + +rc_file_vol="-v ${rc_file}:${FUNCTEST_DIR}/conf/env_file" + +dir_result="${HOME}/opnfv/functest/results/${BRANCH##*/}" +mkdir -p ${dir_result} +sudo rm -rf ${dir_result}/* +results_vol="-v ${dir_result}:${FUNCTEST_DIR}/results" + +volumes="${rc_file_vol} ${results_vol} ${admin_conf_file_vol}" + +# 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 + +envs="-e INSTALLER_TYPE=${INSTALLER_TYPE} \ + -e NODE_NAME=${NODE_NAME} -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} \ + -e BUILD_TAG=${BUILD_TAG} -e DEPLOY_TYPE=${DEPLOY_TYPE}" + +DOCKER_TAG=`[[ ${BRANCH##*/} == "master" ]] && echo "latest" || echo ${BRANCH##*/}` + +FUNCTEST_IMAGE=opnfv/functest-kubernetes:${DOCKER_TAG} +docker pull ${FUNCTEST_IMAGE}>/dev/null +cmd_opt="run_tests -r -t all" +cmd="docker run --rm --privileged=true ${volumes} ${FUNCTEST_IMAGE} /bin/bash -c '${cmd_opt}'" +echo "Running Functest k8s test cases, CMD: ${cmd}" +eval ${cmd} +ret_value=$? +if [ ${ret_value} != 0 ]; then + echo ${ret_value} > ${ret_val_file} +fi diff --git a/utils/fetch_k8_conf.sh b/utils/fetch_k8_conf.sh new file mode 100755 index 000000000..f82fa5497 --- /dev/null +++ b/utils/fetch_k8_conf.sh @@ -0,0 +1,63 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2018 Huawei 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 errexit +set -o nounset +set -o pipefail + +info () { + logger -s -t "fetch_k8_conf.info" "$*" +} + + +error () { + logger -s -t "fetch_k8_conf.error" "$*" + exit 1 +} + +: ${DEPLOY_TYPE:=''} + +#Get options +while getopts ":d:i:a:h:s:o:v" optchar; do + case "${optchar}" in + d) dest_path=${OPTARG} ;; + i) installer_type=${OPTARG} ;; + v) DEPLOY_TYPE="virt" ;; + *) echo "Non-option argument: '-${OPTARG}'" >&2 + usage + exit 2 + ;; + esac +done + +# set vars from env if not provided by user as options +dest_path=${dest_path:-$HOME/admin.conf} +installer_type=${installer_type:-$INSTALLER_TYPE} + +if [ -z $dest_path ] || [ -z $installer_type ]; then + usage + exit 2 +fi + +# Checking if destination path is valid +if [ -d $dest_path ]; then + error "Please provide the full destination path for the credentials file including the filename" +else + # Check if we can create the file (e.g. path is correct) + touch $dest_path || error "Cannot create the file specified. Check that the path is correct and run the script again." +fi + +info "Fetching admin.conf file..." +if [ "$installer_type" == "compass" ]; then + sudo docker cp compass-tasks:/opt/admin.conf $dest_path &> /dev/null + sudo chown $(whoami):$(whoami) $dest_path + info "Fetch admin.conf successfully" +else + error "Installer $installer is not supported by this script" +fi + -- 2.16.6