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" "$*"
24 [ "$1" != "${2/$1/}" ]
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 <k8s_master> k8s master">&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) k8s_master=${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:-$K8S_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 k8s_master=${k8s_master:-$K8S_MASTER_IP}
107 ssh_user=${sh_user:-$K8S_SSH_USER}
108 blueprint_layer=${blueprint_layer:-$LAYER}
110 # If blueprint layer is not defined use k8s by default
111 if [ "$blueprint_layer" == "k8s" ]
113 if [ -z "$k8s_master" ]
116 error "Please provide valid k8s IP address."
118 verify_connectivity "${k8s_master}"
119 if [[ -n $K8S_SSH_PASSWORD ]]
121 sshpass -p "${K8S_SSH_PASSWORD}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\
122 "${ssh_user}@${k8s_master}:~/.kube/*" "$k8s_config_dir"
124 scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\
125 "${ssh_user}"@"${k8s_master}":~/.kube/* "$k8s_config_dir"
129 if [[ -n $blueprint_yaml ]]
131 cp "$blueprint_yaml" ./bluval/
134 volumes_path="$cwd/bluval/volumes.yaml"
135 #update information in volumes yaml
136 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"
138 if [[ -n $blueprint_layer ]]
140 options="-l$blueprint_layer"
142 if [ "$is_optional" == "true" ] || [ "$OPTIONAL" == "yes" ]
147 printf 'ok / PASS /\nerror / FAIL /\n' > ./bluval/rules.txt
150 # even if the script fails we need to change the owner of results
151 # shellcheck disable=SC2086
152 python3 bluval/blucon.py $options "$blueprint_name"
154 if [ $? -ne 0 ]; then
156 error "Bluval validation FAIL "
161 if has_substring "$NODE_NAME" "snd-"
163 echo "In sandbox the logs are not pushed"
165 TIMESTAMP=$(date +'%Y%m%d-%H%M%S')
166 NEXUS_URL=https://nexus.akraino.org/
167 NEXUS_PATH="${LAB_SILO}/bluval_results/${blueprint_name}/${VERSION}/${TIMESTAMP}"
168 BUILD_URL="${JENKINS_HOSTNAME}/job/${JOB_NAME}/${BUILD_NUMBER}/"
169 zip -r results.zip ./results
170 lftools deploy nexus-zip "$NEXUS_URL" logs "$NEXUS_PATH" results.zip