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)
20 logger -s -t "run_blu_val.info" "$*"
28 # change owner of results created by root in container
29 if [ -d "$results_dir" ]
31 sudo chown -R "$current_user" "$results_dir"
37 echo "[-n <blueprint_name>">&2
38 echo "[-b <blueprint_yaml> blueprint definition">&2
39 echo "[-k <k8s_config_dir> k8s config dir">&2
40 echo "[-j <cluster_master_ip> cluster master IP">&2
41 echo "[-u <ssh_user> ssh user">&2
42 echo "[-s <ssh_key>] path to ssh key">&2
43 echo "[-c <custmom_var_file> ] path to variables yaml file">&2
44 echo "[-l <layer> ] blueprint layer">&2
45 echo "[-o ] run optional tests">&2
46 echo "[-v <version> ] version">&2
49 verify_connectivity() {
51 info "Verifying connectivity to $ip..."
52 for i in $(seq 0 10); do
53 if ping -c 1 -W 1 "$ip" > /dev/null; then
54 info "$ip is reachable!"
59 error "Can not talk to $ip."
63 logger -s -t "run_blu_val.error" "$*"
67 # Get options from shell
68 while getopts "j:k:u:s:b:l:r:n:ov:" optchar; do
70 j) cluster_master_ip=${OPTARG} ;;
71 k) k8s_config_dir=${OPTARG} ;;
72 s) ssh_key=${OPTARG} ;;
73 b) blueprint_yaml=${OPTARG} ;;
74 l) blueprint_layer=${OPTARG} ;;
75 n) blueprint_name=${OPTARG} ;;
76 u) sh_user=${OPTARG} ;;
77 o) is_optional="true" ;;
78 v) version=${OPTARG} ;;
79 *) echo "Non-option argument: '-${OPTARG}'" >&2
86 # Blueprint name is mandatory
87 blueprint_name=${blueprint_name:-$BLUEPRINT}
88 if [ -z "$blueprint_name" ]
91 error "Please specify blueprint name. "
94 # Use cwd/kube for k8s config
97 # Initialize ssh key used
98 ssh_key=${ssh_key:-$CLUSTER_SSH_KEY}
99 # K8s config directory
100 k8s_config_dir=${k8s_config_dir:-$input}
101 mkdir -p "$k8s_config_dir"
103 # Testing configuration
104 version=${version:-$VERSION}
105 results_dir=$cwd/results
106 cluster_master_ip=${cluster_master_ip:-$CLUSTER_MASTER_IP}
107 ssh_user=${sh_user:-$CLUSTER_SSH_USER}
108 blueprint_layer=${blueprint_layer:-$LAYER}
110 if [ "$blueprint_layer" == "k8s" ]
112 if [ -z "$cluster_master_ip" ]
115 error "Please provide valid IP address to access the k8s cluster."
117 verify_connectivity "${cluster_master_ip}"
118 if [[ -n $CLUSTER_SSH_PASSWORD ]]
120 sshpass -p "${CLUSTER_SSH_PASSWORD}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\
121 "${ssh_user}@${cluster_master_ip}:~/.kube/*" "$k8s_config_dir"
123 scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\
124 "${ssh_user}"@"${cluster_master_ip}":~/.kube/* "$k8s_config_dir"
128 if [[ -n $blueprint_yaml ]]
130 cp "$blueprint_yaml" ./bluval/
133 volumes_path="$cwd/bluval/volumes.yaml"
134 #update information in volumes yaml
135 sed -i -e "/kube_config_dir/{n; s@local: ''@local: '$k8s_config_dir'@}" -e "/blueprint_dir/{n; s@local: ''@local: '$cwd/bluval/'@}" -e "/results_dir/{n; s@local: ''@local: '$results_dir'@}" "$volumes_path"
137 if [[ -n $blueprint_layer ]]
139 options="-l$blueprint_layer"
141 if [ "$is_optional" == "true" ] || [ "$OPTIONAL" == "yes" ]
146 printf 'ok / PASS /\nerror / FAIL /\n' > ./bluval/rules.txt
149 # even if the script fails we need to change the owner of results
150 # shellcheck disable=SC2086
151 python3 bluval/blucon.py $options "$blueprint_name"
153 if [ $? -ne 0 ]; then
155 error "Bluval validation FAIL "
160 if has_substring "$NODE_NAME" "snd-"
162 echo "In sandbox the logs are not pushed"
164 TIMESTAMP=$(date +'%Y%m%d-%H%M%S')
165 NEXUS_URL=https://nexus.akraino.org/
166 NEXUS_PATH="${LAB_SILO}/bluval_results/${blueprint_name}/${VERSION}/${TIMESTAMP}"
167 BUILD_URL="${JENKINS_HOSTNAME}/job/${JOB_NAME}/${BUILD_NUMBER}/"
168 zip -r results.zip ./results
169 lftools deploy nexus-zip "$NEXUS_URL" logs "$NEXUS_PATH" results.zip