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"
32 echo "[-n <blueprint_name>">&2
33 echo "[-r <results_dir> results dir">&2
34 echo "[-b <blueprint_yaml> blueprint definition">&2
35 echo "[-k <k8s_config_dir> k8s config dir">&2
36 echo "[-j <k8s_master> k8s master">&2
37 echo "[-u <ssh_user> ssh user">&2
38 echo "[-s <ssh_key>] path to ssh key">&2
39 echo "[-c <custmom_var_file> ] path to variables yaml file">&2
40 echo "[-l <layer> ] blueprint layer">&2
41 echo "[-o ] run optional tests">&2
42 echo "[-v <version> ] version">&2
45 verify_connectivity() {
47 info "Verifying connectivity to $ip..."
48 for i in $(seq 0 10); do
49 if ping -c 1 -W 1 "$ip" > /dev/null; then
50 info "$ip is reachable!"
55 error "Can not talk to $ip."
59 logger -s -t "run_blu_val.error" "$*"
63 # Get options from shell
64 while getopts "j:k:u:s:b:l:r:n:ov:" optchar; do
66 j) k8s_master=${OPTARG} ;;
67 k) k8s_config_dir=${OPTARG} ;;
68 s) ssh_key=${OPTARG} ;;
69 b) blueprint_yaml=${OPTARG} ;;
70 l) blueprint_layer=${OPTARG} ;;
71 r) results_dir=${OPTARG} ;;
72 n) blueprint_name=${OPTARG} ;;
73 u) sh_user=${OPTARG} ;;
74 o) is_optional="true" ;;
75 v) version=${OPTARG} ;;
76 *) echo "Non-option argument: '-${OPTARG}'" >&2
83 # Blueprint name is mandatory
84 blueprint_name=${blueprint_name:-$BLUEPRINT}
85 if [ -z "$blueprint_name" ]
88 error "Please specify blueprint name. "
91 # Use cwd/kube for k8s config
94 # Initialize ssh key used
95 ssh_key=${ssh_key:-$K8S_SSH_KEY}
96 # K8s config directory
97 k8s_config_dir=${k8s_config_dir:-$input}
98 mkdir -p "$k8s_config_dir"
100 # Testing configuration
101 version=${version:-$VERSION}
102 results_dir=${results_dir:-$cwd/results}
103 k8s_master=${k8s_master:-$K8S_MASTER_IP}
104 ssh_user=${sh_user:-$K8S_SSH_USER}
105 blueprint_layer=${blueprint_layer:-$LAYER}
107 # If blueprint layer is not defined use k8s by default
108 if [ "$blueprint_layer" == "k8s" ]
110 if [ -z "$k8s_master" ]
113 error "Please provide valid k8s IP address."
115 verify_connectivity "${k8s_master}"
116 if [[ -n $K8S_SSH_PASSWORD ]]
118 sshpass -p "${K8S_SSH_PASSWORD}" scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -r\
119 "${ssh_user}@${k8s_master}:~/.kube/*" "$k8s_config_dir"
121 scp -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -i"$ssh_key" -r\
122 "${ssh_user}"@"${k8s_master}":~/.kube/* "$k8s_config_dir"
126 if [[ -n $blueprint_yaml ]]
128 cp "$blueprint_yaml" ./bluval/
131 volumes_path="$cwd/bluval/volumes.yaml"
132 #update information in volumes yaml
133 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"
135 if [[ -n $blueprint_layer ]]
137 options="-l$blueprint_layer"
139 if [ "$is_optional" == "true" ] || [ "$OPTIONAL" == "yes" ]
144 printf 'ok / PASS /\nerror / FAIL /\n' > ./bluval/rules.txt
147 # even if the script fails we need to change the owner of results
148 # shellcheck disable=SC2086
149 python3 bluval/blucon.py $options "$blueprint_name"
151 if [ $? -ne 0 ]; then
153 error "Bluval validation failed!"