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 logger -s -t "run_blu_val.info" "$*"
22 echo "usage: $0 -n <blueprint_name>" >&2
23 echo "[-r <results_dir> results dir">&2
24 echo "[-b <blueprint_yaml> blueprint definition">&2
25 echo "[-k <k8s_config_dir> k8s config dir">&2
26 echo "[-j <k8s_master> k8s master">&2
27 echo "[-u <ssh_user> ssh user">&2
28 echo "[-s <ssh_key>] path to ssh key">&2
29 echo "[-c <custmom_var_file> ] path to variables yaml file">&2
30 echo "[-l <layer> ] blueprint layer">&2
31 echo "[-o ] run optional tests">&2
32 echo "[-v <version> ] version">&2
35 verify_connectivity() {
37 info "Verifying connectivity to $ip..."
38 for i in $(seq 0 10); do
39 if ping -c 1 -W 1 "$ip" > /dev/null; then
40 info "$ip is reachable!"
45 error "Can not talk to $ip."
49 logger -s -t "run_blu_val.error" "$*"
53 # Get options from shell
54 while getopts "j:k:u:s:b:l:r:n:ov:" optchar; do
56 j) k8s_master=${OPTARG} ;;
57 k) k8s_config_dir=${OPTARG} ;;
58 s) ssh_key=${OPTARG} ;;
59 b) blueprint_yaml=${OPTARG} ;;
60 l) blueprint_layer=${OPTARG} ;;
61 r) results_dir=${OPTARG} ;;
62 n) blueprint_name=${OPTARG} ;;
63 u) sh_user=${OPTARG} ;;
64 o) is_optional="true" ;;
65 v) version=${OPTARG} ;;
66 *) echo "Non-option argument: '-${OPTARG}'" >&2
73 # Blueprint name is mandatory
74 if [ -z "$blueprint_name" ]
77 error "Please specify blueprint name. "
80 # Use cwd/kube for k8s config
83 # Initialize ssh key used
84 ssh_key=${ssh_key:-$K8S_SSH_KEY}
85 # K8s config directory
86 k8s_config_dir=${k8s_config_dir:-$input}
87 mkdir -p "$k8s_config_dir"
89 # Testing configuration
90 version=${version:-$VERSION}
91 results_dir=${results_dir:-$cwd/results}
92 k8s_master=${k8s_master:-$K8S_MASTER_IP}
93 ssh_user=${sh_user:-$K8S_SSH_USER}
94 blueprint_layer=${blueprint_layer:-$LAYER}
96 # If blueprint layer is not defined use k8s by default
97 if [ "$blueprint_layer" == "k8s" ]
99 if [ -z "$k8s_master" ]
102 error "Please provide valid k8s IP address."
104 verify_connectivity "${k8s_master}"
105 if [[ -n $K8S_SSH_PASSWORD ]]
107 sshpass -p "${K8S_SSH_PASSWORD}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\
108 "${ssh_user}@${k8s_master}:~/.kube/*" "$k8s_config_dir"
110 scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\
111 "${ssh_user}"@"${k8s_master}":~/.kube/* "$k8s_config_dir"
115 if [ ! -d "$cwd/validation" ]
117 git clone http://gerrit.akraino.org/r/validation
120 if [[ -n $blueprint_yaml ]]
122 cp "$blueprint_yaml" ./validation/bluval/
125 volumes_path="$cwd/validation/bluval/volumes.yaml"
126 #update information in volumes yaml
127 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"
129 if [[ -n $blueprint_layer ]]
131 options="-l$blueprint_layer"
133 if [ "$is_optional" == "true" ] || [ "$OPTIONAL" == "yes" ]
137 # shellcheck disable=SC2086
138 python3 validation/bluval/blucon.py $options "$blueprint_name"