blob: 1c49be01a1fbdcf58c76d3e43cdb5da6bce7e628 [file] [log] [blame]
Ievgeniia Zadorozhnaa1c21bb2024-01-27 02:51:59 +01001#!/bin/bash
Alexe67127e2022-10-03 14:42:30 -05002### initial folders
3function ewriteln() {
4 echo ${1} | tee -a $MY_PROJFOLDER/env.sh
5}
Alexa0053b92022-10-14 16:38:28 -05006function qkeystone() {
7 keystone_pod=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get pod -n openstack -o=custom-columns=NAME:.metadata.name | grep keystone-client)
8 # echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec {} -c keystone-client --stdin -- "${1}"'"
9 kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- '${1}'
10}
Ievgeniia Zadorozhnaa1c21bb2024-01-27 02:51:59 +010011function get_conformance_image_tag() {
12 kubeconfig_path=$1
13 k8s_server_version=$(kubectl --kubeconfig="$kubeconfig_path" version -o json 2>/dev/null | jq -r '.serverVersion.gitVersion')
14 k8s_short_version=${k8s_server_version:1:4}
15 image_tag=""
16 case $k8s_short_version in
17 "1.18")
18 image_tag="1.18.9-16"
19 ;;
20 "1.19")
21 image_tag="1.19.2-1"
22 ;;
23 "1.20")
24 image_tag="1.20.6-4"
25 ;;
26 "1.21")
27 image_tag="1.21.9-4"
28 ;;
29 "1.24")
30 image_tag="1.24.4-2"
31 ;;
32 "1.27")
33 image_tag="1.27.6-2"
34 ;;
35 esac
36 echo "$image_tag"
37}
Alexe67127e2022-10-03 14:42:30 -050038
39export MY_PROJFOLDER=/artifacts
40echo "# Using folder '$MY_PROJFOLDER'"
41cd $MY_PROJFOLDER
Alex2c8b8802022-10-20 14:07:15 -050042[ ! -d envs ] && mkdir envs
43[ ! -d yamls ] && mkdir yamls
44[ ! -d reports ] && mkdir reports
45[ ! -d tmp ] && mkdir tmp
Alexe67127e2022-10-03 14:42:30 -050046
47# move mcc konfig to default place
48if [ -f $MY_PROJFOLDER/mcc-kubeconfig.yaml ]; then
49 mv $MY_PROJFOLDER/mcc-kubeconfig.yaml $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml
50fi
Alex2c8b8802022-10-20 14:07:15 -050051if [ -f $MY_PROJFOLDER/node.key ]; then
52 mv $MY_PROJFOLDER/node.key $MY_PROJFOLDER/envs/node.key
53fi
Alexe67127e2022-10-03 14:42:30 -050054if [ ! -f $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml ]; then
55 echo "ERROR: MCC kubeconfig not found either at '$MY_PROJFOLDER/mcc-kubeconfig.yaml' or '$MY_PROJFOLDER/envs/mcc-kubeconfig.yaml'"
Alex2c8b8802022-10-20 14:07:15 -050056 exit 1
Alexe67127e2022-10-03 14:42:30 -050057fi
58echo " "
59
60### prepare needed variables
61echo "# Updating '$MY_PROJFOLDER/env.sh'"
Alexf7f0a152022-10-10 16:17:32 -050062
Alexe67127e2022-10-03 14:42:30 -050063export KUBECONFIG=$MY_PROJFOLDER/envs/mcc-kubeconfig.yaml
64if [ ! -f $MY_PROJFOLDER/env.sh ]; then
65 touch $MY_PROJFOLDER/env.sh
66else
67 truncate -s 0 $MY_PROJFOLDER/env.sh
68 echo "$MY_PROJFOLDER/env.sh has been truncated"
69fi
Alexf7f0a152022-10-10 16:17:32 -050070ewriteln "export MY_CLIENTNAME='ClientName'"
71ewriteln "export MY_CLIENTSHORTNAME='clname'"
72ewriteln "export MY_PROJNAME='MOS_DEPLOY'"
Ievgeniia Zadorozhna2b0ba2c2024-02-20 00:15:35 +010073CUSTOM_PUBLIC_NET_NAME=""
Alexe67127e2022-10-03 14:42:30 -050074ewriteln "export MY_PROJFOLDER=/artifacts"
Alexf7f0a152022-10-10 16:17:32 -050075
Alexe67127e2022-10-03 14:42:30 -050076# NS & CLUSTER
Alexa0053b92022-10-14 16:38:28 -050077printf "\n\n# Getting namespace and cluster"
78nn=( $(kubectl get cluster -A --no-headers -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | grep -v default) )
79echo "# Extracted data: '${nn[@]}'"
Alexd1ac2262023-03-31 13:53:33 -050080vNS="${nn[1]}"
81vCLUSTER="${nn[0]}"
Alexa0053b92022-10-14 16:38:28 -050082ewriteln "export MOS_NS=${vNS}"
83ewriteln "export MOS_CLUSTER=${vCLUSTER}"
84echo "# Extracted NS: '${vNS}'"
85echo "# Extracted CLUSTER: '${vCLUSTER}'"
86
87printf "\n\n# Writing additional options"
Alexe67127e2022-10-03 14:42:30 -050088ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
89ewriteln "export HELM_BINARY_PATH=$(which helm)"
Alex876e93a2022-12-21 12:02:13 -060090ewriteln "export K8S_CONFORMANCE_CONCURRENCY=10"
Alexe67127e2022-10-03 14:42:30 -050091
Ievgeniia Zadorozhnaa1c21bb2024-01-27 02:51:59 +010092printf "\n\n# Writing additional options for K8S conformance tests for MCC cluster...\n"
93mcc_kubeconfig_path="$MY_PROJFOLDER/envs/mcc-kubeconfig.yaml"
94mcc_conformance_image_tag=$(get_conformance_image_tag "$mcc_kubeconfig_path")
95if [ -z "$mcc_conformance_image_tag" ]; then
96 echo "Could not identify K8S_CONFORMANCE_IMAGE_VERSION for MCC."
97fi
98mcc_conformance_image_url="mirantis.azurecr.io/lcm/kubernetes/k8s-conformance:v${mcc_conformance_image_tag}"
99ewriteln "export MCC_K8S_CONFORMANCE_IMAGE_VERSION='${mcc_conformance_image_tag}'"
100ewriteln "export MCC_K8S_CONFORMANCE_IMAGE_URL='${mcc_conformance_image_url}'"
101
Alexe67127e2022-10-03 14:42:30 -0500102# extract MOS kubeconfig
103echo " "
Alexa0053b92022-10-14 16:38:28 -0500104printf "\n\nExtracting mos-kubeconfig.yaml"
105if [[ ! -z ${vCLUSTER+x} ]]; then
106 kubectl --kubeconfig $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml -n ${vNS} get secrets ${vCLUSTER}-kubeconfig -o jsonpath='{.data.admin\.conf}' | base64 -d | sed 's/:5443/:443/g' | tee $MY_PROJFOLDER/envs/mos-kubeconfig.yaml
Alexe67127e2022-10-03 14:42:30 -0500107else
Alexa0053b92022-10-14 16:38:28 -0500108 echo "MOS_CLUSTER variable empty/invalid: '${vCLUSTER}'"
Alexe67127e2022-10-03 14:42:30 -0500109fi
110
111# generate additional files
Alexa0053b92022-10-14 16:38:28 -0500112printf "\n\nPreparing additional files"
Alexe67127e2022-10-03 14:42:30 -0500113# copy files
114cp -v /opt/res-files/k8s/workspace/* $MY_PROJFOLDER/envs/
Alexa0053b92022-10-14 16:38:28 -0500115[ ! -d $MY_PROJFOLDER/scripts ] && mkdir $MY_PROJFOLDER/scripts
116mv -v $MY_PROJFOLDER/envs/*.sh $MY_PROJFOLDER/scripts/
Alex2c8b8802022-10-20 14:07:15 -0500117
118cp -v /opt/res-files/k8s/yamls/qa-rally.yaml $MY_PROJFOLDER/yamls
119cp -v /opt/res-files/k8s/yamls/qa-res.yaml $MY_PROJFOLDER/yamls
120cp -v /opt/res-files/k8s/yamls/qa-toolset-bare.yaml $MY_PROJFOLDER/yamls
121cp -v /opt/res-files/k8s/yamls/qa-toolset.yaml $MY_PROJFOLDER/yamls
122
Alexa0053b92022-10-14 16:38:28 -0500123# remove duplicate init
124rm -v $MY_PROJFOLDER/scripts/init-workspace.sh
Alexf7f0a152022-10-10 16:17:32 -0500125# update IP Addresses
126mccip=$(cat $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
127echo "-> MCC Server IP is: ${mccip}"
128sed -i "s/ip_address/$mccip/g" $MY_PROJFOLDER/envs/mcc-checker.env
129
130if [ -f $MY_PROJFOLDER/envs/mos-kubeconfig.yaml ]; then
131 mosip=$(cat $MY_PROJFOLDER/envs/mos-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
132 echo "-> MOS Server IP is: ${mosip}"
133 sed -i "s/ip_address/$mosip/g" $MY_PROJFOLDER/envs/mos-checker.env
Alexa0053b92022-10-14 16:38:28 -0500134
135 vSC="$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get sc | grep default | cut -d' ' -f1)"
136 echo "-> Storage class is ${vSC}"
137 echo "# Updating resources yaml "
138 sed -i "s/storage_class/${vSC}/g" $MY_PROJFOLDER/yamls/qa-res.yaml
139 echo " "
140 ewriteln "export MOS_SC=${vSC}"
141
142 ewriteln "export OSH_DEPLOYMENT_NAME=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack get openstackdeployment --no-headers | cut -d' ' -f1)"
143 ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
144 ewriteln "export HELM_BINARY_PATH=$(which helm)"
145
Ievgeniia Zadorozhnaa1c21bb2024-01-27 02:51:59 +0100146 printf "\n\n# Writing additional options for K8S conformance tests for MOS cluster...\n"
147 mos_kubeconfig_path="$MY_PROJFOLDER/envs/mos-kubeconfig.yaml"
148 mos_conformance_image_tag=$(get_conformance_image_tag "$mos_kubeconfig_path")
149 if [ -z "$mos_conformance_image_tag" ]; then
150 echo "Could not identify K8S_CONFORMANCE_IMAGE_VERSION for MOS."
151 fi
152 mos_conformance_image_url="mirantis.azurecr.io/lcm/kubernetes/k8s-conformance:v${mos_conformance_image_tag}"
153 ewriteln "export MOS_K8S_CONFORMANCE_IMAGE_VERSION='${mos_conformance_image_tag}'"
154 ewriteln "export MOS_K8S_CONFORMANCE_IMAGE_URL='${mos_conformance_image_url}'"
155
Alexa0053b92022-10-14 16:38:28 -0500156 echo " "
Alexa0053b92022-10-14 16:38:28 -0500157 keystone_pod=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get pod -n openstack -o=custom-columns=NAME:.metadata.name | grep keystone-client)
Ievgeniia Zadorozhna2b0ba2c2024-02-20 00:15:35 +0100158 if [ -n "${CUSTOM_PUBLIC_NET_NAME:-}" ]; then
159 # if CUSTOM_PUBLIC_NET_NAME is set to some specific net, check it is present on the cloud
160 echo "# Checking that the external network ${CUSTOM_PUBLIC_NET_NAME} is present on the cloud"
161 cmd="openstack network show ${CUSTOM_PUBLIC_NET_NAME} -c id -f value 2>/dev/null"
162 echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- sh -c '${cmd}'"
163 network_exists=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec "${keystone_pod}" -c keystone-client --stdin -- sh -c "${cmd}")
164 if [ -n "$network_exists" ]; then
165 echo "# Setting TEMPEST_CUSTOM_PUBLIC_NET to ${CUSTOM_PUBLIC_NET_NAME}"
166 ewriteln "export TEMPEST_CUSTOM_PUBLIC_NET=${CUSTOM_PUBLIC_NET_NAME}"
167 else
168 echo "The custom external (floating) network ${CUSTOM_PUBLIC_NET_NAME} is not found on the cloud. Set CUSTOM_PUBLIC_NET_NAME=\"\" to automatically pick some public network."
169 exit 1
170 fi
171 else
172 # else if it is not set by the QA engineer, let's extract the first external network and use it
173 echo "# Extracting network: taking the first found external network"
174 cmd="openstack network list --external -c Name -f value | head -n1"
175 echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- sh -c '${cmd}'"
176 vPUBNET=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- sh -c "${cmd}")
177 echo "-> 'openstack network list --external -c Name -f value | head -n1': '${vPUBNET}'"
178 ewriteln "export TEMPEST_CUSTOM_PUBLIC_NET=${vPUBNET}"
179 fi
Alex35945732023-04-07 10:03:59 -0500180
181 echo "# Extracting volume types"
182 cmd_all="openstack volume type list -f value -c Name"
183 vVOLTYPES=( $(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd_all}) )
184 echo "# Volume types available: ${vVOLTYPES[@]}"
185 cmd_default="openstack volume type list -f value -c Name --default"
186 vVOLTYPE=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd_default})
187 echo "# Default volume type used: ${vVOLTYPE}"
188 ewriteln "export TEMPEST_CUSTOM_VOLUME_TYPE=${vVOLTYPE}"
189 # hardcoded values
Ievgeniia Zadorozhna2b0ba2c2024-02-20 00:15:35 +0100190 ewriteln "# export TEMPEST_CUSTOM_FLAVOR=cvp.tiny"
191 ewriteln "# export TEMPEST_CUSTOM_IMAGE=cvp.cirros.51"
192 ewriteln "# export TEMPEST_CUSTOM_IMAGE_ALT=cvp.cirros.52"
Alexf7f0a152022-10-10 16:17:32 -0500193 #prepare tempest custom yaml
194 cp /opt/res-files/k8s/yamls/tempest_custom.yaml.clean $MY_PROJFOLDER/yamls/tempest_custom.yaml
195 ewriteln 'export TEMPEST_CUSTOM_PARAMETERS=$(cat $MY_PROJFOLDER/yamls/tempest_custom.yaml)'
196fi
Alexe67127e2022-10-03 14:42:30 -0500197
Alexa0053b92022-10-14 16:38:28 -0500198# Aliases
199ewriteln 'alias k=kubectl'
200
Alexe67127e2022-10-03 14:42:30 -0500201# end
202echo " "
203echo "# Done!"