2 ##############################################################################
3 # Copyright (c) 2019 ENEA and others.
4 # valentin.radulescu@enea.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
13 export PATH=$PATH:/home/jenkins/.local/bin
16 current_user=$(whoami)
21 logger -s -t "run_blu_val.info" "$*"
29 # change owner of results created by root in container
30 if [ -d "$results_dir" ]
32 sudo chown -R "$current_user" "$results_dir"
38 echo "[-n <blueprint_name> ]">&2
39 echo "[-b <blueprint_yaml> ] blueprint definition">&2
40 echo "[-k <k8s_config_dir> ] k8s config dir">&2
41 echo "[-j <cluster_master_ip> ] cluster master IP">&2
42 echo "[-u <ssh_user> ] ssh user">&2
43 echo "[-p <ssh_password> ] ssh password">&2
44 echo "[-s <ssh_key> ] path to ssh key">&2
45 echo "[-c <custmom_var_file> ] path to variables yaml file">&2
46 echo "[-l <layer> ] blueprint layer">&2
47 echo "[-P ] pull docker images">&2
48 echo "[-o ] run optional tests">&2
49 echo "[-v <version> ] version">&2
52 verify_connectivity() {
54 info "Verifying connectivity to $ip..."
55 # shellcheck disable=SC2034
56 for i in $(seq 0 10); do
57 if ping -c 1 -W 1 "$ip" > /dev/null; then
58 info "$ip is reachable!"
63 error "Can not talk to $ip."
67 logger -s -t "run_blu_val.error" "$*"
71 # Get options from shell
72 while getopts "j:k:u:p:s:b:l:r:n:oPv:" optchar; do
74 j) cluster_master_ip=${OPTARG} ;;
75 k) k8s_config_dir=${OPTARG} ;;
76 u) sh_user=${OPTARG} ;;
77 p) ssh_password=${OPTARG} ;;
78 s) ssh_key=${OPTARG} ;;
79 b) blueprint_yaml=${OPTARG} ;;
80 l) blueprint_layer=${OPTARG} ;;
81 n) blueprint_name=${OPTARG} ;;
82 o) is_optional="true" ;;
84 v) version=${OPTARG} ;;
85 *) echo "Non-option argument: '-${OPTARG}'" >&2
92 # Blueprint name is mandatory
93 blueprint_name=${blueprint_name:-$BLUEPRINT}
94 if [ -z "$blueprint_name" ]
97 error "Please specify blueprint name. "
100 # Use cwd/kube for k8s config
103 # Initialize ssh key used
104 ssh_key=${ssh_key:-$CLUSTER_SSH_KEY}
105 # K8s config directory
106 k8s_config_dir=${k8s_config_dir:-$input}
107 mkdir -p "$k8s_config_dir"
109 # Testing configuration
110 version=${version:-$VERSION}
111 results_dir=$cwd/results
112 cluster_master_ip=${cluster_master_ip:-$CLUSTER_MASTER_IP}
113 ssh_user=${sh_user:-$CLUSTER_SSH_USER}
114 ssh_password=${ssh_password:-$CLUSTER_SSH_PASSWORD}
115 blueprint_layer=${blueprint_layer:-$LAYER}
117 if [ "$blueprint_layer" == "k8s" ] || [ -z "$blueprint_layer" ]
119 if [ -z "$cluster_master_ip" ]
122 error "Please provide valid IP address to access the k8s cluster."
124 verify_connectivity "${cluster_master_ip}"
125 if [[ -n ${ssh_password} ]]
127 sshpass -p "${ssh_password}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\
128 "${ssh_user}@${cluster_master_ip}:~/.kube/config" "$k8s_config_dir"
130 scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\
131 "${ssh_user}"@"${cluster_master_ip}":~/.kube/config "$k8s_config_dir"
135 if [[ -n $blueprint_yaml ]]
137 cp "$blueprint_yaml" ./bluval/
141 mkdir -p "$cwd/ssh_key_dir"
143 volumes_path="$cwd/bluval/volumes.yaml"
144 # update information in volumes yaml
146 -e "/ssh_key_dir/{n; s@local: ''@local: '$cwd/ssh_key_dir'@}" \
147 -e "/kube_config_dir/{n; s@local: ''@local: '$k8s_config_dir'@}" \
148 -e "/custom_variables_file/{n; s@local: ''@local: '$cwd/tests/variables.yaml'@}" \
149 -e "/blueprint_dir/{n; s@local: ''@local: '$cwd/bluval/'@}" \
150 -e "/results_dir/{n; s@local: ''@local: '$results_dir'@}" \
155 cp $ssh_key $cwd/ssh_key_dir/id_rsa
156 ssh_keyfile=/root/.ssh/id_rsa
159 variables_path="$cwd/tests/variables.yaml"
160 # update information in variables yaml
162 -e "s@host: [0-9]*.[0-9]*.[0-9]*.[0-9]*@host: $cluster_master_ip@" \
163 -e "s@username: [A-Za-z0-9_]* @username: $ssh_user@" \
164 -e "s@password: [A-Za-z0-9_]* @password: $ssh_password@" \
165 -e "s@ssh_keyfile: [A-Za-z0-9_]* @ssh_keyfile: $ssh_keyfile@" \
168 if [[ -n $blueprint_layer ]]
170 options="-l$blueprint_layer"
172 if [ "$is_optional" == "true" ] || [ "$OPTIONAL" == "yes" ]
176 if [ "$pull" == "true" ] || [ "$PULL" == "yes" ]
182 if python3 --version > /dev/null; then
183 # shellcheck disable=SC2086
184 python3 bluval/blucon.py $options "$blueprint_name"
186 # shellcheck disable=SC2086
187 VALIDATION_DIR="$WORKSPACE" RESULTS_DIR="$WORKSPACE/results" \
188 bluval/blucon.sh $options "$blueprint_name"
191 # even if the script fails we need to change the owner of results
192 # shellcheck disable=SC2181
193 if [ $? -ne 0 ]; then
195 error "Bluval validation FAIL "
200 if has_substring "$NODE_NAME" "snd-"
202 echo "In sandbox the logs are not pushed"
204 TIMESTAMP=$(date +'%Y%m%d-%H%M%S')
205 NEXUS_URL=https://nexus.akraino.org/
206 NEXUS_PATH="${LAB_SILO}/bluval_results/${blueprint_name}/${VERSION}/${TIMESTAMP}"
207 zip -r results.zip ./results
208 lftools deploy nexus-zip "$NEXUS_URL" logs "$NEXUS_PATH" results.zip