Ievgeniia Zadorozhna | a1c21bb | 2024-01-27 02:51:59 +0100 | [diff] [blame] | 1 | #!/bin/bash |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 2 | ### initial folders |
| 3 | function ewriteln() { |
| 4 | echo ${1} | tee -a $MY_PROJFOLDER/env.sh |
| 5 | } |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 6 | function 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 Zadorozhna | a1c21bb | 2024-01-27 02:51:59 +0100 | [diff] [blame] | 11 | function 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 | } |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 38 | |
| 39 | export MY_PROJFOLDER=/artifacts |
| 40 | echo "# Using folder '$MY_PROJFOLDER'" |
| 41 | cd $MY_PROJFOLDER |
Alex | 2c8b880 | 2022-10-20 14:07:15 -0500 | [diff] [blame] | 42 | [ ! -d envs ] && mkdir envs |
| 43 | [ ! -d yamls ] && mkdir yamls |
| 44 | [ ! -d reports ] && mkdir reports |
| 45 | [ ! -d tmp ] && mkdir tmp |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 46 | |
| 47 | # move mcc konfig to default place |
| 48 | if [ -f $MY_PROJFOLDER/mcc-kubeconfig.yaml ]; then |
| 49 | mv $MY_PROJFOLDER/mcc-kubeconfig.yaml $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml |
| 50 | fi |
Alex | 2c8b880 | 2022-10-20 14:07:15 -0500 | [diff] [blame] | 51 | if [ -f $MY_PROJFOLDER/node.key ]; then |
| 52 | mv $MY_PROJFOLDER/node.key $MY_PROJFOLDER/envs/node.key |
| 53 | fi |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 54 | if [ ! -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'" |
Alex | 2c8b880 | 2022-10-20 14:07:15 -0500 | [diff] [blame] | 56 | exit 1 |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 57 | fi |
| 58 | echo " " |
| 59 | |
| 60 | ### prepare needed variables |
| 61 | echo "# Updating '$MY_PROJFOLDER/env.sh'" |
Alex | f7f0a15 | 2022-10-10 16:17:32 -0500 | [diff] [blame] | 62 | |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 63 | export KUBECONFIG=$MY_PROJFOLDER/envs/mcc-kubeconfig.yaml |
| 64 | if [ ! -f $MY_PROJFOLDER/env.sh ]; then |
| 65 | touch $MY_PROJFOLDER/env.sh |
| 66 | else |
| 67 | truncate -s 0 $MY_PROJFOLDER/env.sh |
| 68 | echo "$MY_PROJFOLDER/env.sh has been truncated" |
| 69 | fi |
Alex | f7f0a15 | 2022-10-10 16:17:32 -0500 | [diff] [blame] | 70 | ewriteln "export MY_CLIENTNAME='ClientName'" |
| 71 | ewriteln "export MY_CLIENTSHORTNAME='clname'" |
| 72 | ewriteln "export MY_PROJNAME='MOS_DEPLOY'" |
Ievgeniia Zadorozhna | 2b0ba2c | 2024-02-20 00:15:35 +0100 | [diff] [blame^] | 73 | CUSTOM_PUBLIC_NET_NAME="" |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 74 | ewriteln "export MY_PROJFOLDER=/artifacts" |
Alex | f7f0a15 | 2022-10-10 16:17:32 -0500 | [diff] [blame] | 75 | |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 76 | # NS & CLUSTER |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 77 | printf "\n\n# Getting namespace and cluster" |
| 78 | nn=( $(kubectl get cluster -A --no-headers -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace | grep -v default) ) |
| 79 | echo "# Extracted data: '${nn[@]}'" |
Alex | d1ac226 | 2023-03-31 13:53:33 -0500 | [diff] [blame] | 80 | vNS="${nn[1]}" |
| 81 | vCLUSTER="${nn[0]}" |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 82 | ewriteln "export MOS_NS=${vNS}" |
| 83 | ewriteln "export MOS_CLUSTER=${vCLUSTER}" |
| 84 | echo "# Extracted NS: '${vNS}'" |
| 85 | echo "# Extracted CLUSTER: '${vCLUSTER}'" |
| 86 | |
| 87 | printf "\n\n# Writing additional options" |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 88 | ewriteln "export SI_BINARIES_DIR=$(which helm | rev | cut -d'/' -f2- | rev)" |
| 89 | ewriteln "export HELM_BINARY_PATH=$(which helm)" |
Alex | 876e93a | 2022-12-21 12:02:13 -0600 | [diff] [blame] | 90 | ewriteln "export K8S_CONFORMANCE_CONCURRENCY=10" |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 91 | |
Ievgeniia Zadorozhna | a1c21bb | 2024-01-27 02:51:59 +0100 | [diff] [blame] | 92 | printf "\n\n# Writing additional options for K8S conformance tests for MCC cluster...\n" |
| 93 | mcc_kubeconfig_path="$MY_PROJFOLDER/envs/mcc-kubeconfig.yaml" |
| 94 | mcc_conformance_image_tag=$(get_conformance_image_tag "$mcc_kubeconfig_path") |
| 95 | if [ -z "$mcc_conformance_image_tag" ]; then |
| 96 | echo "Could not identify K8S_CONFORMANCE_IMAGE_VERSION for MCC." |
| 97 | fi |
| 98 | mcc_conformance_image_url="mirantis.azurecr.io/lcm/kubernetes/k8s-conformance:v${mcc_conformance_image_tag}" |
| 99 | ewriteln "export MCC_K8S_CONFORMANCE_IMAGE_VERSION='${mcc_conformance_image_tag}'" |
| 100 | ewriteln "export MCC_K8S_CONFORMANCE_IMAGE_URL='${mcc_conformance_image_url}'" |
| 101 | |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 102 | # extract MOS kubeconfig |
| 103 | echo " " |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 104 | printf "\n\nExtracting mos-kubeconfig.yaml" |
| 105 | if [[ ! -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 |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 107 | else |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 108 | echo "MOS_CLUSTER variable empty/invalid: '${vCLUSTER}'" |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 109 | fi |
| 110 | |
| 111 | # generate additional files |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 112 | printf "\n\nPreparing additional files" |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 113 | # copy files |
| 114 | cp -v /opt/res-files/k8s/workspace/* $MY_PROJFOLDER/envs/ |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 115 | [ ! -d $MY_PROJFOLDER/scripts ] && mkdir $MY_PROJFOLDER/scripts |
| 116 | mv -v $MY_PROJFOLDER/envs/*.sh $MY_PROJFOLDER/scripts/ |
Alex | 2c8b880 | 2022-10-20 14:07:15 -0500 | [diff] [blame] | 117 | |
| 118 | cp -v /opt/res-files/k8s/yamls/qa-rally.yaml $MY_PROJFOLDER/yamls |
| 119 | cp -v /opt/res-files/k8s/yamls/qa-res.yaml $MY_PROJFOLDER/yamls |
| 120 | cp -v /opt/res-files/k8s/yamls/qa-toolset-bare.yaml $MY_PROJFOLDER/yamls |
| 121 | cp -v /opt/res-files/k8s/yamls/qa-toolset.yaml $MY_PROJFOLDER/yamls |
| 122 | |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 123 | # remove duplicate init |
| 124 | rm -v $MY_PROJFOLDER/scripts/init-workspace.sh |
Alex | f7f0a15 | 2022-10-10 16:17:32 -0500 | [diff] [blame] | 125 | # update IP Addresses |
| 126 | mccip=$(cat $MY_PROJFOLDER/envs/mcc-kubeconfig.yaml | grep server | cut -d':' -f3 | cut -d'/' -f3) |
| 127 | echo "-> MCC Server IP is: ${mccip}" |
| 128 | sed -i "s/ip_address/$mccip/g" $MY_PROJFOLDER/envs/mcc-checker.env |
| 129 | |
| 130 | if [ -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 |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 134 | |
| 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 Zadorozhna | a1c21bb | 2024-01-27 02:51:59 +0100 | [diff] [blame] | 146 | 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 | |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 156 | echo " " |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 157 | keystone_pod=$(kubectl --kubeconfig $MY_PROJFOLDER/envs/mos-kubeconfig.yaml get pod -n openstack -o=custom-columns=NAME:.metadata.name | grep keystone-client) |
Ievgeniia Zadorozhna | 2b0ba2c | 2024-02-20 00:15:35 +0100 | [diff] [blame^] | 158 | 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 |
Alex | 3594573 | 2023-04-07 10:03:59 -0500 | [diff] [blame] | 180 | |
| 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 Zadorozhna | 2b0ba2c | 2024-02-20 00:15:35 +0100 | [diff] [blame^] | 190 | 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" |
Alex | f7f0a15 | 2022-10-10 16:17:32 -0500 | [diff] [blame] | 193 | #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)' |
| 196 | fi |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 197 | |
Alex | a0053b9 | 2022-10-14 16:38:28 -0500 | [diff] [blame] | 198 | # Aliases |
| 199 | ewriteln 'alias k=kubectl' |
| 200 | |
Alex | e67127e | 2022-10-03 14:42:30 -0500 | [diff] [blame] | 201 | # end |
| 202 | echo " " |
| 203 | echo "# Done!" |