blob: 7b835e7fa504afbba961bfcf1e6d1db50187ac76 [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'"
Alexe67127e2022-10-03 14:42:30 -050073ewriteln "export MY_PROJFOLDER=/artifacts"
Alexf7f0a152022-10-10 16:17:32 -050074
Alexe67127e2022-10-03 14:42:30 -050075# NS & CLUSTER
Alexa0053b92022-10-14 16:38:28 -050076printf "\n\n# Getting namespace and cluster"
77nn=( $(kubectl get cluster -A --no-headers -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | grep -v default) )
78echo "# Extracted data: '${nn[@]}'"
Alexd1ac2262023-03-31 13:53:33 -050079vNS="${nn[1]}"
80vCLUSTER="${nn[0]}"
Alexa0053b92022-10-14 16:38:28 -050081ewriteln "export MOS_NS=${vNS}"
82ewriteln "export MOS_CLUSTER=${vCLUSTER}"
83echo "# Extracted NS: '${vNS}'"
84echo "# Extracted CLUSTER: '${vCLUSTER}'"
85
86printf "\n\n# Writing additional options"
Alexe67127e2022-10-03 14:42:30 -050087ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
88ewriteln "export HELM_BINARY_PATH=$(which helm)"
Alex876e93a2022-12-21 12:02:13 -060089ewriteln "export K8S_CONFORMANCE_CONCURRENCY=10"
Alexe67127e2022-10-03 14:42:30 -050090
Ievgeniia Zadorozhnaa1c21bb2024-01-27 02:51:59 +010091printf "\n\n# Writing additional options for K8S conformance tests for MCC cluster...\n"
92mcc_kubeconfig_path="$MY_PROJFOLDER/envs/mcc-kubeconfig.yaml"
93mcc_conformance_image_tag=$(get_conformance_image_tag "$mcc_kubeconfig_path")
94if [ -z "$mcc_conformance_image_tag" ]; then
95 echo "Could not identify K8S_CONFORMANCE_IMAGE_VERSION for MCC."
96fi
97mcc_conformance_image_url="mirantis.azurecr.io/lcm/kubernetes/k8s-conformance:v${mcc_conformance_image_tag}"
98ewriteln "export MCC_K8S_CONFORMANCE_IMAGE_VERSION='${mcc_conformance_image_tag}'"
99ewriteln "export MCC_K8S_CONFORMANCE_IMAGE_URL='${mcc_conformance_image_url}'"
100
Alexe67127e2022-10-03 14:42:30 -0500101# extract MOS kubeconfig
102echo " "
Alexa0053b92022-10-14 16:38:28 -0500103printf "\n\nExtracting mos-kubeconfig.yaml"
104if [[ ! -z ${vCLUSTER+x} ]]; then
105 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 -0500106else
Alexa0053b92022-10-14 16:38:28 -0500107 echo "MOS_CLUSTER variable empty/invalid: '${vCLUSTER}'"
Alexe67127e2022-10-03 14:42:30 -0500108fi
109
110# generate additional files
Alexa0053b92022-10-14 16:38:28 -0500111printf "\n\nPreparing additional files"
Alexe67127e2022-10-03 14:42:30 -0500112# copy files
113cp -v /opt/res-files/k8s/workspace/* $MY_PROJFOLDER/envs/
Alexa0053b92022-10-14 16:38:28 -0500114[ ! -d $MY_PROJFOLDER/scripts ] && mkdir $MY_PROJFOLDER/scripts
115mv -v $MY_PROJFOLDER/envs/*.sh $MY_PROJFOLDER/scripts/
Alex2c8b8802022-10-20 14:07:15 -0500116
117cp -v /opt/res-files/k8s/yamls/qa-rally.yaml $MY_PROJFOLDER/yamls
118cp -v /opt/res-files/k8s/yamls/qa-res.yaml $MY_PROJFOLDER/yamls
119cp -v /opt/res-files/k8s/yamls/qa-toolset-bare.yaml $MY_PROJFOLDER/yamls
120cp -v /opt/res-files/k8s/yamls/qa-toolset.yaml $MY_PROJFOLDER/yamls
121
Alexa0053b92022-10-14 16:38:28 -0500122# remove duplicate init
123rm -v $MY_PROJFOLDER/scripts/init-workspace.sh
Alexf7f0a152022-10-10 16:17:32 -0500124# update IP Addresses
125mccip=$(cat $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
126echo "-> MCC Server IP is: ${mccip}"
127sed -i "s/ip_address/$mccip/g" $MY_PROJFOLDER/envs/mcc-checker.env
128
129if [ -f $MY_PROJFOLDER/envs/mos-kubeconfig.yaml ]; then
130 mosip=$(cat $MY_PROJFOLDER/envs/mos-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
131 echo "-> MOS Server IP is: ${mosip}"
132 sed -i "s/ip_address/$mosip/g" $MY_PROJFOLDER/envs/mos-checker.env
Alexa0053b92022-10-14 16:38:28 -0500133
134 vSC="$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get sc | grep default | cut -d' ' -f1)"
135 echo "-> Storage class is ${vSC}"
136 echo "# Updating resources yaml "
137 sed -i "s/storage_class/${vSC}/g" $MY_PROJFOLDER/yamls/qa-res.yaml
138 echo " "
139 ewriteln "export MOS_SC=${vSC}"
140
141 ewriteln "export OSH_DEPLOYMENT_NAME=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack get openstackdeployment --no-headers | cut -d' ' -f1)"
142 ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
143 ewriteln "export HELM_BINARY_PATH=$(which helm)"
144
Ievgeniia Zadorozhnaa1c21bb2024-01-27 02:51:59 +0100145 printf "\n\n# Writing additional options for K8S conformance tests for MOS cluster...\n"
146 mos_kubeconfig_path="$MY_PROJFOLDER/envs/mos-kubeconfig.yaml"
147 mos_conformance_image_tag=$(get_conformance_image_tag "$mos_kubeconfig_path")
148 if [ -z "$mos_conformance_image_tag" ]; then
149 echo "Could not identify K8S_CONFORMANCE_IMAGE_VERSION for MOS."
150 fi
151 mos_conformance_image_url="mirantis.azurecr.io/lcm/kubernetes/k8s-conformance:v${mos_conformance_image_tag}"
152 ewriteln "export MOS_K8S_CONFORMANCE_IMAGE_VERSION='${mos_conformance_image_tag}'"
153 ewriteln "export MOS_K8S_CONFORMANCE_IMAGE_URL='${mos_conformance_image_url}'"
154
Alexa0053b92022-10-14 16:38:28 -0500155 echo " "
Alexa0053b92022-10-14 16:38:28 -0500156 keystone_pod=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get pod -n openstack -o=custom-columns=NAME:.metadata.name | grep keystone-client)
Ievgeniia Zadorozhnabbe0f442024-01-22 23:59:05 +0100157 echo "# Extracting network: taking the first found external network"
158 cmd="openstack network list --external -c Name -f value | head -n1"
Ievgeniia Zadorozhna7fc6a9c2024-01-23 12:29:11 +0100159 echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- sh -c '${cmd}'"
160 vPUBNET=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- sh -c "${cmd}")
Ievgeniia Zadorozhnabbe0f442024-01-22 23:59:05 +0100161 echo "-> 'openstack network list --external -c Name -f value | head -n1': '${vPUBNET}'"
Alexa0053b92022-10-14 16:38:28 -0500162 ewriteln "export TEMPEST_CUSTOM_PUBLIC_NET=${vPUBNET}"
Alex35945732023-04-07 10:03:59 -0500163
164 echo "# Extracting volume types"
165 cmd_all="openstack volume type list -f value -c Name"
166 vVOLTYPES=( $(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd_all}) )
167 echo "# Volume types available: ${vVOLTYPES[@]}"
168 cmd_default="openstack volume type list -f value -c Name --default"
169 vVOLTYPE=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd_default})
170 echo "# Default volume type used: ${vVOLTYPE}"
171 ewriteln "export TEMPEST_CUSTOM_VOLUME_TYPE=${vVOLTYPE}"
172 # hardcoded values
Alex876e93a2022-12-21 12:02:13 -0600173 ewriteln "export TEMPEST_CUSTOM_FLAVOR=cvp.tiny"
Alexa0053b92022-10-14 16:38:28 -0500174 ewriteln "export TEMPEST_CUSTOM_IMAGE=cvp.cirros.51"
175 ewriteln "export TEMPEST_CUSTOM_IMAGE_ALT=cvp.cirros.52"
Alexf7f0a152022-10-10 16:17:32 -0500176 #prepare tempest custom yaml
177 cp /opt/res-files/k8s/yamls/tempest_custom.yaml.clean $MY_PROJFOLDER/yamls/tempest_custom.yaml
178 ewriteln 'export TEMPEST_CUSTOM_PARAMETERS=$(cat $MY_PROJFOLDER/yamls/tempest_custom.yaml)'
179fi
Alexe67127e2022-10-03 14:42:30 -0500180
Alexa0053b92022-10-14 16:38:28 -0500181# Aliases
182ewriteln 'alias k=kubectl'
183
Alexe67127e2022-10-03 14:42:30 -0500184# end
185echo " "
186echo "# Done!"