X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ci-management.git;a=blobdiff_plain;f=jjb%2Fshell%2Frun_bluval.sh;fp=jjb%2Fshell%2Frun_bluval.sh;h=5f0c4dbdb4c06f22a11c392d3a5d923ebf19d401;hp=0000000000000000000000000000000000000000;hb=7cb83b7f5818727f5293fc02b96d5e5f065a78a1;hpb=3e56727601d0017599732254185a97e68cf9ee66 diff --git a/jjb/shell/run_bluval.sh b/jjb/shell/run_bluval.sh new file mode 100755 index 0000000..5f0c4db --- /dev/null +++ b/jjb/shell/run_bluval.sh @@ -0,0 +1,138 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2019 ENEA and others. +# valentin.radulescu@enea.com +# 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 -o errexit +set -o pipefail + +cwd=$(pwd) +is_optional="false" + +info () { + logger -s -t "run_blu_val.info" "$*" +} + +usage() { + echo "usage: $0 -n " >&2 + echo "[-r results dir">&2 + echo "[-b blueprint definition">&2 + echo "[-k k8s config dir">&2 + echo "[-j k8s master">&2 + echo "[-u ssh user">&2 + echo "[-s ] path to ssh key">&2 + echo "[-c ] path to variables yaml file">&2 + echo "[-l ] blueprint layer">&2 + echo "[-o ] run optional tests">&2 + echo "[-v ] version">&2 +} + +verify_connectivity() { + local ip=$1 + info "Verifying connectivity to $ip..." + for i in $(seq 0 10); do + if ping -c 1 -W 1 "$ip" > /dev/null; then + info "$ip is reachable!" + return 0 + fi + sleep 1 + done + error "Can not talk to $ip." +} + +error () { + logger -s -t "run_blu_val.error" "$*" + exit 1 +} + +# Get options from shell +while getopts "j:k:u:s:b:l:r:n:ov:" optchar; do + case "${optchar}" in + j) k8s_master=${OPTARG} ;; + k) k8s_config_dir=${OPTARG} ;; + s) ssh_key=${OPTARG} ;; + b) blueprint_yaml=${OPTARG} ;; + l) blueprint_layer=${OPTARG} ;; + r) results_dir=${OPTARG} ;; + n) blueprint_name=${OPTARG} ;; + u) sh_user=${OPTARG} ;; + o) is_optional="true" ;; + v) version=${OPTARG} ;; + *) echo "Non-option argument: '-${OPTARG}'" >&2 + usage + exit 2 + ;; + esac +done + +# Blueprint name is mandatory +if [ -z "$blueprint_name" ] +then + usage + error "Please specify blueprint name. " +fi + +# Use cwd/kube for k8s config +input="$cwd/kube" + +# Initialize ssh key used +ssh_key=${ssh_key:-$K8S_SSH_KEY} +# K8s config directory +k8s_config_dir=${k8s_config_dir:-$input} +mkdir -p "$k8s_config_dir" + +# Testing configuration +version=${version:-$VERSION} +results_dir=${results_dir:-$cwd/results} +k8s_master=${k8s_master:-$K8S_MASTER_IP} +ssh_user=${sh_user:-$K8S_SSH_USER} +blueprint_layer=${blueprint_layer:-$LAYER} + +# If blueprint layer is not defined use k8s by default +if [ "$blueprint_layer" == "k8s" ] +then + if [ -z "$k8s_master" ] + then + usage + error "Please provide valid k8s IP address." + fi + verify_connectivity "${k8s_master}" + if [[ -n $K8S_SSH_PASSWORD ]] + then + sshpass -p "${K8S_SSH_PASSWORD}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\ + "${ssh_user}@${k8s_master}:~/.kube/*" "$k8s_config_dir" + else + scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\ + "${ssh_user}"@"${k8s_master}":~/.kube/* "$k8s_config_dir" + fi +fi + +if [ ! -d "$cwd/validation" ] +then + git clone http://gerrit.akraino.org/r/validation +fi + +if [[ -n $blueprint_yaml ]] +then + cp "$blueprint_yaml" ./validation/bluval/ +fi + +volumes_path="$cwd/validation/bluval/volumes.yaml" +#update information in volumes yaml +sed -i -e "/kube_config_dir/{n; s@local: ''@local: '$k8s_config_dir'@}" -e "/blueprint_dir/{n; s@local: ''@local: '$cwd/validation/bluval/'@}" -e "/results_dir/{n; s@local: ''@local: '$results_dir'@}" "$volumes_path" + +if [[ -n $blueprint_layer ]] +then + options="-l$blueprint_layer" +fi +if [ "$is_optional" == "true" ] || [ "$OPTIONAL" == "yes" ] +then + options+=" -o" +fi +# shellcheck disable=SC2086 +python3 validation/bluval/blucon.py $options "$blueprint_name"