blob: 01e2d0de126c3dc54d5fe4802392dee528ebeb99 [file] [log] [blame]
Ievgeniia Zadorozhna68ba4f32024-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 Zadorozhna68ba4f32024-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")
Ievgeniia Zadorozhnad2a308a2024-08-19 15:04:31 +020033 image_tag="1.27.9-3"
Ievgeniia Zadorozhna68ba4f32024-01-27 02:51:59 +010034 ;;
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
Ievgeniia Zadorozhna3d761862024-10-01 19:28:04 +020070
71### Edit the following lines to set the client name, floating network name, IAM writer password
Alexf7f0a152022-10-10 16:17:32 -050072ewriteln "export MY_CLIENTNAME='ClientName'"
73ewriteln "export MY_CLIENTSHORTNAME='clname'"
74ewriteln "export MY_PROJNAME='MOS_DEPLOY'"
Ievgeniia Zadorozhna7bc54052024-02-20 00:15:35 +010075CUSTOM_PUBLIC_NET_NAME=""
Ievgeniia Zadorozhna3d761862024-10-01 19:28:04 +020076ewriteln "export WRITER_PASSWORD=''" # IAM (Keycloak) writer password
77
78### Setting the project directory
Alexe67127e2022-10-03 14:42:30 -050079ewriteln "export MY_PROJFOLDER=/artifacts"
Alexf7f0a152022-10-10 16:17:32 -050080
Alexe67127e2022-10-03 14:42:30 -050081# NS & CLUSTER
Alexa0053b92022-10-14 16:38:28 -050082printf "\n\n# Getting namespace and cluster"
83nn=( $(kubectl get cluster -A --no-headers -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | grep -v default) )
84echo "# Extracted data: '${nn[@]}'"
Alexd1ac2262023-03-31 13:53:33 -050085vNS="${nn[1]}"
86vCLUSTER="${nn[0]}"
Alexa0053b92022-10-14 16:38:28 -050087ewriteln "export MOS_NS=${vNS}"
88ewriteln "export MOS_CLUSTER=${vCLUSTER}"
89echo "# Extracted NS: '${vNS}'"
90echo "# Extracted CLUSTER: '${vCLUSTER}'"
91
92printf "\n\n# Writing additional options"
Alexe67127e2022-10-03 14:42:30 -050093ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
94ewriteln "export HELM_BINARY_PATH=$(which helm)"
Alex876e93a2022-12-21 12:02:13 -060095ewriteln "export K8S_CONFORMANCE_CONCURRENCY=10"
Alexe67127e2022-10-03 14:42:30 -050096
Ievgeniia Zadorozhna68ba4f32024-01-27 02:51:59 +010097printf "\n\n# Writing additional options for K8S conformance tests for MCC cluster...\n"
98mcc_kubeconfig_path="$MY_PROJFOLDER/envs/mcc-kubeconfig.yaml"
99mcc_conformance_image_tag=$(get_conformance_image_tag "$mcc_kubeconfig_path")
100if [ -z "$mcc_conformance_image_tag" ]; then
101 echo "Could not identify K8S_CONFORMANCE_IMAGE_VERSION for MCC."
102fi
103mcc_conformance_image_url="mirantis.azurecr.io/lcm/kubernetes/k8s-conformance:v${mcc_conformance_image_tag}"
104ewriteln "export MCC_K8S_CONFORMANCE_IMAGE_VERSION='${mcc_conformance_image_tag}'"
105ewriteln "export MCC_K8S_CONFORMANCE_IMAGE_URL='${mcc_conformance_image_url}'"
106
Ievgeniia Zadorozhna3d761862024-10-01 19:28:04 +0200107# getting IAM Keycloak URL
108ewriteln "export KEYCLOAK_URL=$(kubectl get cluster kaas-mgmt -o jsonpath='{.status.providerStatus.helm.releases.iam.keycloak.url}')"
109
Alexe67127e2022-10-03 14:42:30 -0500110# extract MOS kubeconfig
111echo " "
Alexa0053b92022-10-14 16:38:28 -0500112printf "\n\nExtracting mos-kubeconfig.yaml"
113if [[ ! -z ${vCLUSTER+x} ]]; then
114 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 -0500115else
Alexa0053b92022-10-14 16:38:28 -0500116 echo "MOS_CLUSTER variable empty/invalid: '${vCLUSTER}'"
Alexe67127e2022-10-03 14:42:30 -0500117fi
118
119# generate additional files
Alexa0053b92022-10-14 16:38:28 -0500120printf "\n\nPreparing additional files"
Alexe67127e2022-10-03 14:42:30 -0500121# copy files
122cp -v /opt/res-files/k8s/workspace/* $MY_PROJFOLDER/envs/
Alexa0053b92022-10-14 16:38:28 -0500123[ ! -d $MY_PROJFOLDER/scripts ] && mkdir $MY_PROJFOLDER/scripts
124mv -v $MY_PROJFOLDER/envs/*.sh $MY_PROJFOLDER/scripts/
Alex2c8b8802022-10-20 14:07:15 -0500125
126cp -v /opt/res-files/k8s/yamls/qa-rally.yaml $MY_PROJFOLDER/yamls
127cp -v /opt/res-files/k8s/yamls/qa-res.yaml $MY_PROJFOLDER/yamls
128cp -v /opt/res-files/k8s/yamls/qa-toolset-bare.yaml $MY_PROJFOLDER/yamls
129cp -v /opt/res-files/k8s/yamls/qa-toolset.yaml $MY_PROJFOLDER/yamls
130
Alexa0053b92022-10-14 16:38:28 -0500131# remove duplicate init
132rm -v $MY_PROJFOLDER/scripts/init-workspace.sh
Alexf7f0a152022-10-10 16:17:32 -0500133# update IP Addresses
134mccip=$(cat $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
135echo "-> MCC Server IP is: ${mccip}"
136sed -i "s/ip_address/$mccip/g" $MY_PROJFOLDER/envs/mcc-checker.env
137
138if [ -f $MY_PROJFOLDER/envs/mos-kubeconfig.yaml ]; then
139 mosip=$(cat $MY_PROJFOLDER/envs/mos-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
140 echo "-> MOS Server IP is: ${mosip}"
141 sed -i "s/ip_address/$mosip/g" $MY_PROJFOLDER/envs/mos-checker.env
Alexa0053b92022-10-14 16:38:28 -0500142
143 vSC="$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get sc | grep default | cut -d' ' -f1)"
144 echo "-> Storage class is ${vSC}"
145 echo "# Updating resources yaml "
146 sed -i "s/storage_class/${vSC}/g" $MY_PROJFOLDER/yamls/qa-res.yaml
147 echo " "
148 ewriteln "export MOS_SC=${vSC}"
149
150 ewriteln "export OSH_DEPLOYMENT_NAME=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack get openstackdeployment --no-headers | cut -d' ' -f1)"
151 ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
152 ewriteln "export HELM_BINARY_PATH=$(which helm)"
153
Ievgeniia Zadorozhna68ba4f32024-01-27 02:51:59 +0100154 printf "\n\n# Writing additional options for K8S conformance tests for MOS cluster...\n"
155 mos_kubeconfig_path="$MY_PROJFOLDER/envs/mos-kubeconfig.yaml"
156 mos_conformance_image_tag=$(get_conformance_image_tag "$mos_kubeconfig_path")
157 if [ -z "$mos_conformance_image_tag" ]; then
158 echo "Could not identify K8S_CONFORMANCE_IMAGE_VERSION for MOS."
159 fi
160 mos_conformance_image_url="mirantis.azurecr.io/lcm/kubernetes/k8s-conformance:v${mos_conformance_image_tag}"
161 ewriteln "export MOS_K8S_CONFORMANCE_IMAGE_VERSION='${mos_conformance_image_tag}'"
162 ewriteln "export MOS_K8S_CONFORMANCE_IMAGE_URL='${mos_conformance_image_url}'"
163
Alexa0053b92022-10-14 16:38:28 -0500164 echo " "
Alexa0053b92022-10-14 16:38:28 -0500165 keystone_pod=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get pod -n openstack -o=custom-columns=NAME:.metadata.name | grep keystone-client)
Ievgeniia Zadorozhna7bc54052024-02-20 00:15:35 +0100166 if [ -n "${CUSTOM_PUBLIC_NET_NAME:-}" ]; then
167 # if CUSTOM_PUBLIC_NET_NAME is set to some specific net, check it is present on the cloud
168 echo "# Checking that the external network ${CUSTOM_PUBLIC_NET_NAME} is present on the cloud"
169 cmd="openstack network show ${CUSTOM_PUBLIC_NET_NAME} -c id -f value 2>/dev/null"
170 echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- sh -c '${cmd}'"
171 network_exists=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec "${keystone_pod}" -c keystone-client --stdin -- sh -c "${cmd}")
172 if [ -n "$network_exists" ]; then
173 echo "# Setting TEMPEST_CUSTOM_PUBLIC_NET to ${CUSTOM_PUBLIC_NET_NAME}"
174 ewriteln "export TEMPEST_CUSTOM_PUBLIC_NET=${CUSTOM_PUBLIC_NET_NAME}"
175 else
176 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."
177 exit 1
178 fi
179 else
180 # else if it is not set by the QA engineer, let's extract the first external network and use it
181 echo "# Extracting network: taking the first found external network"
182 cmd="openstack network list --external -c Name -f value | head -n1"
183 echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- sh -c '${cmd}'"
184 vPUBNET=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- sh -c "${cmd}")
185 echo "-> 'openstack network list --external -c Name -f value | head -n1': '${vPUBNET}'"
186 ewriteln "export TEMPEST_CUSTOM_PUBLIC_NET=${vPUBNET}"
187 fi
Alex35945732023-04-07 10:03:59 -0500188
189 echo "# Extracting volume types"
190 cmd_all="openstack volume type list -f value -c Name"
191 vVOLTYPES=( $(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd_all}) )
192 echo "# Volume types available: ${vVOLTYPES[@]}"
193 cmd_default="openstack volume type list -f value -c Name --default"
194 vVOLTYPE=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd_default})
195 echo "# Default volume type used: ${vVOLTYPE}"
196 ewriteln "export TEMPEST_CUSTOM_VOLUME_TYPE=${vVOLTYPE}"
197 # hardcoded values
Ievgeniia Zadorozhna7bc54052024-02-20 00:15:35 +0100198 ewriteln "# export TEMPEST_CUSTOM_FLAVOR=cvp.tiny"
199 ewriteln "# export TEMPEST_CUSTOM_IMAGE=cvp.cirros.61"
200 ewriteln "# export TEMPEST_CUSTOM_IMAGE_ALT=cvp.cirros.62"
Alexf7f0a152022-10-10 16:17:32 -0500201 #prepare tempest custom yaml
202 cp /opt/res-files/k8s/yamls/tempest_custom.yaml.clean $MY_PROJFOLDER/yamls/tempest_custom.yaml
203 ewriteln 'export TEMPEST_CUSTOM_PARAMETERS=$(cat $MY_PROJFOLDER/yamls/tempest_custom.yaml)'
204fi
Alexe67127e2022-10-03 14:42:30 -0500205
Alexa0053b92022-10-14 16:38:28 -0500206# Aliases
207ewriteln 'alias k=kubectl'
208
Alexe67127e2022-10-03 14:42:30 -0500209# end
210echo " "
211echo "# Done!"