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 ##############################################################################
18 # Fix ownership of output files
19 user_id=$(stat -c '%u:%g' $cwd)
20 sudo chown -R ${user_id} $results_dir
24 logger -s -t "run_blu_val.info" "$*"
28 echo "usage: $0 -n <blueprint_name>" >&2
29 echo "[-r <results_dir> results dir">&2
30 echo "[-b <blueprint_yaml> blueprint definition">&2
31 echo "[-k <k8s_config_dir> k8s config dir">&2
32 echo "[-j <k8s_master> k8s master">&2
33 echo "[-u <ssh_user> ssh user">&2
34 echo "[-s <ssh_key>] path to ssh key">&2
35 echo "[-c <custmom_var_file> ] path to variables yaml file">&2
36 echo "[-l <layer> ] blueprint layer">&2
37 echo "[-o ] run optional tests">&2
38 echo "[-v <version> ] version">&2
41 verify_connectivity() {
43 info "Verifying connectivity to $ip..."
44 for i in $(seq 0 10); do
45 if ping -c 1 -W 1 "$ip" > /dev/null; then
46 info "$ip is reachable!"
51 error "Can not talk to $ip."
55 logger -s -t "run_blu_val.error" "$*"
59 # Get options from shell
60 while getopts "j:k:u:s:b:l:r:n:ov:" optchar; do
62 j) k8s_master=${OPTARG} ;;
63 k) k8s_config_dir=${OPTARG} ;;
64 s) ssh_key=${OPTARG} ;;
65 b) blueprint_yaml=${OPTARG} ;;
66 l) blueprint_layer=${OPTARG} ;;
67 r) results_dir=${OPTARG} ;;
68 n) blueprint_name=${OPTARG} ;;
69 u) sh_user=${OPTARG} ;;
70 o) is_optional="true" ;;
71 v) version=${OPTARG} ;;
72 *) echo "Non-option argument: '-${OPTARG}'" >&2
79 # Blueprint name is mandatory
80 if [ -z "$blueprint_name" ]
83 error "Please specify blueprint name. "
86 # Use cwd/kube for k8s config
89 # Initialize ssh key used
90 ssh_key=${ssh_key:-$K8S_SSH_KEY}
91 # K8s config directory
92 k8s_config_dir=${k8s_config_dir:-$input}
93 mkdir -p "$k8s_config_dir"
95 # Testing configuration
96 version=${version:-$VERSION}
97 results_dir=${results_dir:-$cwd/results}
98 k8s_master=${k8s_master:-$K8S_MASTER_IP}
99 ssh_user=${sh_user:-$K8S_SSH_USER}
100 blueprint_layer=${blueprint_layer:-$LAYER}
102 # If blueprint layer is not defined use k8s by default
103 if [ "$blueprint_layer" == "k8s" ]
105 if [ -z "$k8s_master" ]
108 error "Please provide valid k8s IP address."
110 verify_connectivity "${k8s_master}"
111 if [[ -n $K8S_SSH_PASSWORD ]]
113 sshpass -p "${K8S_SSH_PASSWORD}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\
114 "${ssh_user}@${k8s_master}:~/.kube/*" "$k8s_config_dir"
116 scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\
117 "${ssh_user}"@"${k8s_master}":~/.kube/* "$k8s_config_dir"
123 if [ ! -d "$cwd/validation" ]
125 git clone http://gerrit.akraino.org/r/validation
128 if [[ -n $blueprint_yaml ]]
130 cp "$blueprint_yaml" ./validation/bluval/
133 volumes_path="$cwd/validation/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/validation/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" ]
145 # shellcheck disable=SC2086
146 python3 validation/bluval/blucon.py $options "$blueprint_name"