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 "[-s <ssh_key>] path to ssh key">&2
44 echo "[-c <custmom_var_file> ] path to variables yaml file">&2
45 echo "[-l <layer> ] blueprint layer">&2
46 echo "[-o ] run optional tests">&2
47 echo "[-v <version> ] version">&2
50 verify_connectivity() {
52 info "Verifying connectivity to $ip..."
53 # shellcheck disable=SC2034
54 for i in $(seq 0 10); do
55 if ping -c 1 -W 1 "$ip" > /dev/null; then
56 info "$ip is reachable!"
61 error "Can not talk to $ip."
65 logger -s -t "run_blu_val.error" "$*"
69 # Get options from shell
70 while getopts "j:k:u:s:b:l:r:n:opv:" optchar; do
72 j) cluster_master_ip=${OPTARG} ;;
73 k) k8s_config_dir=${OPTARG} ;;
74 s) ssh_key=${OPTARG} ;;
75 b) blueprint_yaml=${OPTARG} ;;
76 l) blueprint_layer=${OPTARG} ;;
77 n) blueprint_name=${OPTARG} ;;
78 u) sh_user=${OPTARG} ;;
79 o) is_optional="true" ;;
81 v) version=${OPTARG} ;;
82 *) echo "Non-option argument: '-${OPTARG}'" >&2
89 # Blueprint name is mandatory
90 blueprint_name=${blueprint_name:-$BLUEPRINT}
91 if [ -z "$blueprint_name" ]
94 error "Please specify blueprint name. "
97 # Use cwd/kube for k8s config
100 # Initialize ssh key used
101 ssh_key=${ssh_key:-$CLUSTER_SSH_KEY}
102 # K8s config directory
103 k8s_config_dir=${k8s_config_dir:-$input}
104 mkdir -p "$k8s_config_dir"
106 # Testing configuration
107 version=${version:-$VERSION}
108 results_dir=$cwd/results
109 cluster_master_ip=${cluster_master_ip:-$CLUSTER_MASTER_IP}
110 ssh_user=${sh_user:-$CLUSTER_SSH_USER}
111 blueprint_layer=${blueprint_layer:-$LAYER}
113 if [ "$blueprint_layer" == "k8s" ] || [ -z "$blueprint_layer" ]
115 if [ -z "$cluster_master_ip" ]
118 error "Please provide valid IP address to access the k8s cluster."
120 verify_connectivity "${cluster_master_ip}"
121 if [[ -n $CLUSTER_SSH_PASSWORD ]]
123 sshpass -p "${CLUSTER_SSH_PASSWORD}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\
124 "${ssh_user}@${cluster_master_ip}:~/.kube/*" "$k8s_config_dir"
126 scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\
127 "${ssh_user}"@"${cluster_master_ip}":~/.kube/* "$k8s_config_dir"
131 if [[ -n $blueprint_yaml ]]
133 cp "$blueprint_yaml" ./bluval/
136 volumes_path="$cwd/bluval/volumes.yaml"
137 # update information in volumes yaml
139 -e "/ssh_key_dir/{n; s@local: ''@local: '$cwd/ssh_key_dir'@}" \
140 -e "/kube_config_dir/{n; s@local: ''@local: '$k8s_config_dir'@}" \
141 -e "/custom_variables_file/{n; s@local: ''@local: '$cwd/tests/variables.yaml'@}" \
142 -e "/blueprint_dir/{n; s@local: ''@local: '$cwd/bluval/'@}" \
143 -e "/results_dir/{n; s@local: ''@local: '$results_dir'@}" \
147 mkdir -p "$cwd/ssh_key_dir"
149 # copy ssh_key in ssh_key_dir
150 cp "$ssh_key" "$cwd/ssh_key_dir/id_rsa"
152 variables_path="$cwd/tests/variables.yaml"
153 # update information in variables yaml
155 -e "s@host: [0-9]*.[0-9]*.[0-9]*.[0-9]*@host: $cluster_master_ip@" \
156 -e "s@username: [A-Za-z0-9_]* @username: $ssh_user@" \
159 if [[ -n $blueprint_layer ]]
161 options="-l$blueprint_layer"
163 if [ "$is_optional" == "true" ] || [ "$OPTIONAL" == "yes" ]
167 if [ "$pull" == "true" ] || [ "$PULL" == "yes" ]
173 if python3 --version > /dev/null; then
174 # shellcheck disable=SC2086
175 python3 bluval/blucon.py $options "$blueprint_name"
177 # shellcheck disable=SC2086
178 VALIDATION_DIR="$WORKSPACE" RESULTS_DIR="$WORKSPACE/results" \
179 bluval/blucon.sh $options "$blueprint_name"
182 # even if the script fails we need to change the owner of results
183 # shellcheck disable=SC2181
184 if [ $? -ne 0 ]; then
186 error "Bluval validation FAIL "
191 if has_substring "$NODE_NAME" "snd-"
193 echo "In sandbox the logs are not pushed"
195 TIMESTAMP=$(date +'%Y%m%d-%H%M%S')
196 NEXUS_URL=https://nexus.akraino.org/
197 NEXUS_PATH="${LAB_SILO}/bluval_results/${blueprint_name}/${VERSION}/${TIMESTAMP}"
198 zip -r results.zip ./results
199 lftools deploy nexus-zip "$NEXUS_URL" logs "$NEXUS_PATH" results.zip