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 ##############################################################################
15 current_user=$(whoami)
19 logger -s -t "run_blu_val.info" "$*"
23 # change owner of results created by root in container
24 if [ -d "$results_dir" ]
26 sudo chown -R "$current_user" "$results_dir"
31 echo "usage: $0 -n <blueprint_name>" >&2
32 echo "[-r <results_dir> results dir">&2
33 echo "[-b <blueprint_yaml> blueprint definition">&2
34 echo "[-k <k8s_config_dir> k8s config dir">&2
35 echo "[-j <k8s_master> k8s master">&2
36 echo "[-u <ssh_user> ssh user">&2
37 echo "[-s <ssh_key>] path to ssh key">&2
38 echo "[-c <custmom_var_file> ] path to variables yaml file">&2
39 echo "[-l <layer> ] blueprint layer">&2
40 echo "[-o ] run optional tests">&2
41 echo "[-v <version> ] version">&2
44 verify_connectivity() {
46 info "Verifying connectivity to $ip..."
47 for i in $(seq 0 10); do
48 if ping -c 1 -W 1 "$ip" > /dev/null; then
49 info "$ip is reachable!"
54 error "Can not talk to $ip."
58 logger -s -t "run_blu_val.error" "$*"
62 # Get options from shell
63 while getopts "j:k:u:s:b:l:r:n:ov:" optchar; do
65 j) k8s_master=${OPTARG} ;;
66 k) k8s_config_dir=${OPTARG} ;;
67 s) ssh_key=${OPTARG} ;;
68 b) blueprint_yaml=${OPTARG} ;;
69 l) blueprint_layer=${OPTARG} ;;
70 r) results_dir=${OPTARG} ;;
71 n) blueprint_name=${OPTARG} ;;
72 u) sh_user=${OPTARG} ;;
73 o) is_optional="true" ;;
74 v) version=${OPTARG} ;;
75 *) echo "Non-option argument: '-${OPTARG}'" >&2
82 # Blueprint name is mandatory
83 if [ -z "$blueprint_name" ]
86 error "Please specify blueprint name. "
89 # Use cwd/kube for k8s config
92 # Initialize ssh key used
93 ssh_key=${ssh_key:-$K8S_SSH_KEY}
94 # K8s config directory
95 k8s_config_dir=${k8s_config_dir:-$input}
96 mkdir -p "$k8s_config_dir"
98 # Testing configuration
99 version=${version:-$VERSION}
100 results_dir=${results_dir:-$cwd/results}
101 k8s_master=${k8s_master:-$K8S_MASTER_IP}
102 ssh_user=${sh_user:-$K8S_SSH_USER}
103 blueprint_layer=${blueprint_layer:-$LAYER}
105 # If blueprint layer is not defined use k8s by default
106 if [ "$blueprint_layer" == "k8s" ]
108 if [ -z "$k8s_master" ]
111 error "Please provide valid k8s IP address."
113 verify_connectivity "${k8s_master}"
114 if [[ -n $K8S_SSH_PASSWORD ]]
116 sshpass -p "${K8S_SSH_PASSWORD}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\
117 "${ssh_user}@${k8s_master}:~/.kube/*" "$k8s_config_dir"
119 scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\
120 "${ssh_user}"@"${k8s_master}":~/.kube/* "$k8s_config_dir"
124 if [ ! -d "$cwd/validation" ]
126 git clone http://gerrit.akraino.org/r/validation
129 if [[ -n $blueprint_yaml ]]
131 cp "$blueprint_yaml" ./validation/bluval/
134 volumes_path="$cwd/validation/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/validation/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" ]
148 # even if the script fails we need to change the owner of results
149 # shellcheck disable=SC2086
150 python3 validation/bluval/blucon.py $options "$blueprint_name"
152 if [ $? -ne 0 ]; then
154 error "Bluval validation failed!"