blob: 4f8f00c3000d5f29e11076b25649214fe26aa87a [file] [log] [blame]
Alexe67127e2022-10-03 14:42:30 -05001### initial folders
2function ewriteln() {
3 echo ${1} | tee -a $MY_PROJFOLDER/env.sh
4}
Alexa0053b92022-10-14 16:38:28 -05005function qkeystone() {
6 keystone_pod=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get pod -n openstack -o=custom-columns=NAME:.metadata.name | grep keystone-client)
7 # echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec {} -c keystone-client --stdin -- "${1}"'"
8 kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- '${1}'
9}
Alexe67127e2022-10-03 14:42:30 -050010
11export MY_PROJFOLDER=/artifacts
12echo "# Using folder '$MY_PROJFOLDER'"
13cd $MY_PROJFOLDER
Alex2c8b8802022-10-20 14:07:15 -050014[ ! -d envs ] && mkdir envs
15[ ! -d yamls ] && mkdir yamls
16[ ! -d reports ] && mkdir reports
17[ ! -d tmp ] && mkdir tmp
Alexe67127e2022-10-03 14:42:30 -050018
19# move mcc konfig to default place
20if [ -f $MY_PROJFOLDER/mcc-kubeconfig.yaml ]; then
21 mv $MY_PROJFOLDER/mcc-kubeconfig.yaml $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml
22fi
Alex2c8b8802022-10-20 14:07:15 -050023if [ -f $MY_PROJFOLDER/node.key ]; then
24 mv $MY_PROJFOLDER/node.key $MY_PROJFOLDER/envs/node.key
25fi
Alexe67127e2022-10-03 14:42:30 -050026if [ ! -f $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml ]; then
27 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 -050028 exit 1
Alexe67127e2022-10-03 14:42:30 -050029fi
30echo " "
31
32### prepare needed variables
33echo "# Updating '$MY_PROJFOLDER/env.sh'"
Alexf7f0a152022-10-10 16:17:32 -050034
Alexe67127e2022-10-03 14:42:30 -050035export KUBECONFIG=$MY_PROJFOLDER/envs/mcc-kubeconfig.yaml
36if [ ! -f $MY_PROJFOLDER/env.sh ]; then
37 touch $MY_PROJFOLDER/env.sh
38else
39 truncate -s 0 $MY_PROJFOLDER/env.sh
40 echo "$MY_PROJFOLDER/env.sh has been truncated"
41fi
Alexf7f0a152022-10-10 16:17:32 -050042ewriteln "export MY_CLIENTNAME='ClientName'"
43ewriteln "export MY_CLIENTSHORTNAME='clname'"
44ewriteln "export MY_PROJNAME='MOS_DEPLOY'"
Alexe67127e2022-10-03 14:42:30 -050045ewriteln "export MY_PROJFOLDER=/artifacts"
Alexf7f0a152022-10-10 16:17:32 -050046
Alexe67127e2022-10-03 14:42:30 -050047# NS & CLUSTER
Alexa0053b92022-10-14 16:38:28 -050048printf "\n\n# Getting namespace and cluster"
49nn=( $(kubectl get cluster -A --no-headers -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | grep -v default) )
50echo "# Extracted data: '${nn[@]}'"
Alexd1ac2262023-03-31 13:53:33 -050051vNS="${nn[1]}"
52vCLUSTER="${nn[0]}"
Alexa0053b92022-10-14 16:38:28 -050053ewriteln "export MOS_NS=${vNS}"
54ewriteln "export MOS_CLUSTER=${vCLUSTER}"
55echo "# Extracted NS: '${vNS}'"
56echo "# Extracted CLUSTER: '${vCLUSTER}'"
57
58printf "\n\n# Writing additional options"
Alexe67127e2022-10-03 14:42:30 -050059ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
60ewriteln "export HELM_BINARY_PATH=$(which helm)"
Alex876e93a2022-12-21 12:02:13 -060061ewriteln "export K8S_CONFORMANCE_CONCURRENCY=10"
Alexe67127e2022-10-03 14:42:30 -050062
63# extract MOS kubeconfig
64echo " "
Alexa0053b92022-10-14 16:38:28 -050065printf "\n\nExtracting mos-kubeconfig.yaml"
66if [[ ! -z ${vCLUSTER+x} ]]; then
67 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 -050068else
Alexa0053b92022-10-14 16:38:28 -050069 echo "MOS_CLUSTER variable empty/invalid: '${vCLUSTER}'"
Alexe67127e2022-10-03 14:42:30 -050070fi
71
72# generate additional files
Alexa0053b92022-10-14 16:38:28 -050073printf "\n\nPreparing additional files"
Alexe67127e2022-10-03 14:42:30 -050074# copy files
75cp -v /opt/res-files/k8s/workspace/* $MY_PROJFOLDER/envs/
Alexa0053b92022-10-14 16:38:28 -050076[ ! -d $MY_PROJFOLDER/scripts ] && mkdir $MY_PROJFOLDER/scripts
77mv -v $MY_PROJFOLDER/envs/*.sh $MY_PROJFOLDER/scripts/
Alex2c8b8802022-10-20 14:07:15 -050078
79cp -v /opt/res-files/k8s/yamls/qa-rally.yaml $MY_PROJFOLDER/yamls
80cp -v /opt/res-files/k8s/yamls/qa-res.yaml $MY_PROJFOLDER/yamls
81cp -v /opt/res-files/k8s/yamls/qa-toolset-bare.yaml $MY_PROJFOLDER/yamls
82cp -v /opt/res-files/k8s/yamls/qa-toolset.yaml $MY_PROJFOLDER/yamls
83
Alexa0053b92022-10-14 16:38:28 -050084# remove duplicate init
85rm -v $MY_PROJFOLDER/scripts/init-workspace.sh
Alexf7f0a152022-10-10 16:17:32 -050086# update IP Addresses
87mccip=$(cat $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
88echo "-> MCC Server IP is: ${mccip}"
89sed -i "s/ip_address/$mccip/g" $MY_PROJFOLDER/envs/mcc-checker.env
90
91if [ -f $MY_PROJFOLDER/envs/mos-kubeconfig.yaml ]; then
92 mosip=$(cat $MY_PROJFOLDER/envs/mos-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
93 echo "-> MOS Server IP is: ${mosip}"
94 sed -i "s/ip_address/$mosip/g" $MY_PROJFOLDER/envs/mos-checker.env
Alexa0053b92022-10-14 16:38:28 -050095
96 vSC="$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get sc | grep default | cut -d' ' -f1)"
97 echo "-> Storage class is ${vSC}"
98 echo "# Updating resources yaml "
99 sed -i "s/storage_class/${vSC}/g" $MY_PROJFOLDER/yamls/qa-res.yaml
100 echo " "
101 ewriteln "export MOS_SC=${vSC}"
102
103 ewriteln "export OSH_DEPLOYMENT_NAME=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack get openstackdeployment --no-headers | cut -d' ' -f1)"
104 ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
105 ewriteln "export HELM_BINARY_PATH=$(which helm)"
106
107 echo " "
Alexa0053b92022-10-14 16:38:28 -0500108 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 +0100109 echo "# Extracting network: taking the first found external network"
110 cmd="openstack network list --external -c Name -f value | head -n1"
Alexa0053b92022-10-14 16:38:28 -0500111 echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- "${cmd}"'"
112 vPUBNET=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd})
Ievgeniia Zadorozhnabbe0f442024-01-22 23:59:05 +0100113 echo "-> 'openstack network list --external -c Name -f value | head -n1': '${vPUBNET}'"
Alexa0053b92022-10-14 16:38:28 -0500114 ewriteln "export TEMPEST_CUSTOM_PUBLIC_NET=${vPUBNET}"
Alex35945732023-04-07 10:03:59 -0500115
116 echo "# Extracting volume types"
117 cmd_all="openstack volume type list -f value -c Name"
118 vVOLTYPES=( $(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd_all}) )
119 echo "# Volume types available: ${vVOLTYPES[@]}"
120 cmd_default="openstack volume type list -f value -c Name --default"
121 vVOLTYPE=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd_default})
122 echo "# Default volume type used: ${vVOLTYPE}"
123 ewriteln "export TEMPEST_CUSTOM_VOLUME_TYPE=${vVOLTYPE}"
124 # hardcoded values
Alex876e93a2022-12-21 12:02:13 -0600125 ewriteln "export TEMPEST_CUSTOM_FLAVOR=cvp.tiny"
Alexa0053b92022-10-14 16:38:28 -0500126 ewriteln "export TEMPEST_CUSTOM_IMAGE=cvp.cirros.51"
127 ewriteln "export TEMPEST_CUSTOM_IMAGE_ALT=cvp.cirros.52"
Alexf7f0a152022-10-10 16:17:32 -0500128 #prepare tempest custom yaml
129 cp /opt/res-files/k8s/yamls/tempest_custom.yaml.clean $MY_PROJFOLDER/yamls/tempest_custom.yaml
130 ewriteln 'export TEMPEST_CUSTOM_PARAMETERS=$(cat $MY_PROJFOLDER/yamls/tempest_custom.yaml)'
131fi
Alexe67127e2022-10-03 14:42:30 -0500132
Alexa0053b92022-10-14 16:38:28 -0500133# Aliases
134ewriteln 'alias k=kubectl'
135
Alexe67127e2022-10-03 14:42:30 -0500136# end
137echo " "
138echo "# Done!"