blob: 0e546aa70cbbdebc79df7e75997cbd0d242aee14 [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[@]}'"
51vNS="${nn[0]}"
52vCLUSTER="${nn[1]}"
53ewriteln "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)"
Alexe67127e2022-10-03 14:42:30 -050061
62# extract MOS kubeconfig
63echo " "
Alexa0053b92022-10-14 16:38:28 -050064printf "\n\nExtracting mos-kubeconfig.yaml"
65if [[ ! -z ${vCLUSTER+x} ]]; then
66 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 -050067else
Alexa0053b92022-10-14 16:38:28 -050068 echo "MOS_CLUSTER variable empty/invalid: '${vCLUSTER}'"
Alexe67127e2022-10-03 14:42:30 -050069fi
70
71# generate additional files
Alexa0053b92022-10-14 16:38:28 -050072printf "\n\nPreparing additional files"
Alexe67127e2022-10-03 14:42:30 -050073# copy files
74cp -v /opt/res-files/k8s/workspace/* $MY_PROJFOLDER/envs/
Alexa0053b92022-10-14 16:38:28 -050075[ ! -d $MY_PROJFOLDER/scripts ] && mkdir $MY_PROJFOLDER/scripts
76mv -v $MY_PROJFOLDER/envs/*.sh $MY_PROJFOLDER/scripts/
Alex2c8b8802022-10-20 14:07:15 -050077
78cp -v /opt/res-files/k8s/yamls/qa-rally.yaml $MY_PROJFOLDER/yamls
79cp -v /opt/res-files/k8s/yamls/qa-res.yaml $MY_PROJFOLDER/yamls
80cp -v /opt/res-files/k8s/yamls/qa-toolset-bare.yaml $MY_PROJFOLDER/yamls
81cp -v /opt/res-files/k8s/yamls/qa-toolset.yaml $MY_PROJFOLDER/yamls
82
Alexa0053b92022-10-14 16:38:28 -050083# remove duplicate init
84rm -v $MY_PROJFOLDER/scripts/init-workspace.sh
Alexf7f0a152022-10-10 16:17:32 -050085# update IP Addresses
86mccip=$(cat $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
87echo "-> MCC Server IP is: ${mccip}"
88sed -i "s/ip_address/$mccip/g" $MY_PROJFOLDER/envs/mcc-checker.env
89
90if [ -f $MY_PROJFOLDER/envs/mos-kubeconfig.yaml ]; then
91 mosip=$(cat $MY_PROJFOLDER/envs/mos-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3)
92 echo "-> MOS Server IP is: ${mosip}"
93 sed -i "s/ip_address/$mosip/g" $MY_PROJFOLDER/envs/mos-checker.env
Alexa0053b92022-10-14 16:38:28 -050094
95 vSC="$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get sc | grep default | cut -d' ' -f1)"
96 echo "-> Storage class is ${vSC}"
97 echo "# Updating resources yaml "
98 sed -i "s/storage_class/${vSC}/g" $MY_PROJFOLDER/yamls/qa-res.yaml
99 echo " "
100 ewriteln "export MOS_SC=${vSC}"
101
102 ewriteln "export OSH_DEPLOYMENT_NAME=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack get openstackdeployment --no-headers | cut -d' ' -f1)"
103 ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)"
104 ewriteln "export HELM_BINARY_PATH=$(which helm)"
105
106 echo " "
107 echo "# Extracting network"
108 keystone_pod=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get pod -n openstack -o=custom-columns=NAME:.metadata.name | grep keystone-client)
109 cmd="openstack network list --external -c Name -f value"
110 echo "# Running 'kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- "${cmd}"'"
111 vPUBNET=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml -n openstack exec ${keystone_pod} -c keystone-client --stdin -- ${cmd})
112 echo "-> 'openstack network list --external -c Name -f value': '${vPUBNET}'"
113 ewriteln "export TEMPEST_CUSTOM_PUBLIC_NET=${vPUBNET}"
114
115 ewriteln "export TEMPEST_CUSTOM_IMAGE=cvp.cirros.51"
116 ewriteln "export TEMPEST_CUSTOM_IMAGE_ALT=cvp.cirros.52"
Alexf7f0a152022-10-10 16:17:32 -0500117 #prepare tempest custom yaml
118 cp /opt/res-files/k8s/yamls/tempest_custom.yaml.clean $MY_PROJFOLDER/yamls/tempest_custom.yaml
119 ewriteln 'export TEMPEST_CUSTOM_PARAMETERS=$(cat $MY_PROJFOLDER/yamls/tempest_custom.yaml)'
120fi
Alexe67127e2022-10-03 14:42:30 -0500121
Alexa0053b92022-10-14 16:38:28 -0500122# Aliases
123ewriteln 'alias k=kubectl'
124
Alexe67127e2022-10-03 14:42:30 -0500125# end
126echo " "
127echo "# Done!"