Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | export OS_INTERFACE='admin' |
| 3 | |
Ievgeniia Zadorozhna | 2bbb1cc | 2024-02-29 18:48:21 +0100 | [diff] [blame] | 4 | # Prepare clouds.yaml file for the future cleanup, with original admin creds |
| 5 | sed -i "s#AUTH_URL#${OS_AUTH_URL}#g; s#USERNAME#${OS_USERNAME}#g; s#USER_PASSWORD#${OS_PASSWORD}#g; s#PROJECT_NAME#${OS_PROJECT_NAME}#g; s#PROJECT_DOMAIN_NAME#${OS_PROJECT_DOMAIN_NAME}#g; s#USER_DOMAIN_NAME#${OS_USER_DOMAIN_NAME}#g; s#REGION_NAME#${OS_REGION_NAME}#g" /opt/res-files/clouds.yaml |
| 6 | |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 7 | # local vars |
| 8 | name_prefix=cvp |
| 9 | filename=${name_prefix}.manifest |
| 10 | rcfile=${name_prefix}rc |
| 11 | huge_pages=false |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 12 | set_gw_heat_router=false |
Ievgeniia Zadorozhna | e83b961 | 2024-12-24 16:02:23 +0100 | [diff] [blame^] | 13 | raw_disk_format=false |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 14 | logfile=prepare.log |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 15 | working_folder=$(pwd) |
| 16 | |
| 17 | # Cloud admin details |
| 18 | admin_username=${OS_USERNAME} |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 19 | |
| 20 | # Project, User, Roles |
| 21 | project=${name_prefix}.project |
| 22 | user=${name_prefix}.user |
| 23 | admin=${name_prefix}.admin |
| 24 | password=mcp1234 |
Ievgeniia Zadorozhna | 24e7e85 | 2024-08-06 17:32:44 +0200 | [diff] [blame] | 25 | domain=${OS_PROJECT_DOMAIN_NAME} |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 26 | |
| 27 | # Security group |
| 28 | sg_all=${name_prefix}.sg.all |
| 29 | sg_icmp=${name_prefix}.sg.icmp |
| 30 | sg_ssh=${name_prefix}.sg.ssh |
| 31 | sg_iperf=${name_prefix}.sg.perf |
| 32 | |
| 33 | # Testkey |
| 34 | key=${name_prefix}_testkey |
| 35 | |
| 36 | # Flavors: tiny, small (cirrus and migration), medium (ubuntu and volume/stress activities) |
| 37 | flavor_t=${name_prefix}.tiny |
| 38 | flavor_s=${name_prefix}.small |
| 39 | flavor_m=${name_prefix}.medium |
| 40 | flavor_h=${name_prefix}.high |
| 41 | |
| 42 | # Fixed Networks (2, for testing router interconnection) |
| 43 | net_left=${name_prefix}.net.1 |
| 44 | net_right=${name_prefix}.net.2 |
| 45 | subnet1=${name_prefix}.subnet.1 |
| 46 | subnet2=${name_prefix}.subnet.2 |
| 47 | |
| 48 | # Router |
| 49 | router=${name_prefix}.router |
| 50 | |
Ievgeniia Zadorozhna | 1cb5b10 | 2024-01-19 04:31:09 +0100 | [diff] [blame] | 51 | # Images: cirros (6.0, 6.2), ubuntu (16.04, 20.04) |
| 52 | cirros61=${name_prefix}.cirros.61 |
| 53 | cirros62=${name_prefix}.cirros.62 |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 54 | ubuntu16=${name_prefix}.ubuntu.1604 |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 55 | ubuntu20=${name_prefix}.ubuntu.2004 |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 56 | |
Ievgeniia Zadorozhna | 1cb5b10 | 2024-01-19 04:31:09 +0100 | [diff] [blame] | 57 | cirros61_link=https://download.cirros-cloud.net/0.6.1/cirros-0.6.1-x86_64-disk.img |
| 58 | cirros62_link=https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 59 | ubuntu16_link=https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 60 | ubuntu20_link=https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 61 | |
| 62 | # Volume (2GB) |
| 63 | volume=${name_prefix}.volume |
| 64 | |
| 65 | function show_help { |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 66 | printf "QA verification: Resources creation script\n\t-h, -?\t\tShow this help\n" |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 67 | printf "\t-H\t\tAdds '--property hw:mem_page_size=large' to flavors, i.e. huge_pages for DPDK\n" |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 68 | printf "\t-w <path>\tSets working folder (default: ${working_folder})\n" |
| 69 | printf "\t-g\t\tTo set external_gateway_info to heat-router with the external network (if not set yet)\n" |
Ievgeniia Zadorozhna | e83b961 | 2024-12-24 16:02:23 +0100 | [diff] [blame^] | 70 | printf "\t-r\t\tTo create the images in RAW disk format instead of the QCOW2\n" |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | OPTIND=1 # Reset in case getopts has been used previously in the shell. |
Ievgeniia Zadorozhna | e83b961 | 2024-12-24 16:02:23 +0100 | [diff] [blame^] | 74 | while getopts ":grHw:h?" opt; do |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 75 | case "$opt" in |
| 76 | h|\?) |
| 77 | show_help |
| 78 | exit 0 |
| 79 | ;; |
| 80 | w) working_folder=${OPTARG} |
| 81 | printf "# Working folder is ${working_folder}\n" |
| 82 | ;; |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 83 | H) huge_pages=true |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 84 | printf "# Using 'huge_pages' property in flavors\n" |
| 85 | ;; |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 86 | g) set_gw_heat_router=true |
| 87 | printf "# Setting external_gateway_info to heat-router with the external network (if not set yet)\n\n" |
| 88 | ;; |
Ievgeniia Zadorozhna | e83b961 | 2024-12-24 16:02:23 +0100 | [diff] [blame^] | 89 | r) raw_disk_format=true |
| 90 | printf "# Creating the images in RAW disk format instead of the QCOW2\n" |
| 91 | ;; |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 92 | esac |
| 93 | done |
| 94 | |
| 95 | shift $((OPTIND-1)) |
| 96 | [ "${1:-}" = "--" ] && shift |
| 97 | |
| 98 | function put() { |
| 99 | echo "$1=$2" | tee -a ${filename} |
| 100 | } |
| 101 | |
| 102 | # now, some hard to understand stuff... |
| 103 | # f1 $(<command with output to cut>) |
| 104 | function f1() { echo $1 | cut -d' ' -f1; }; |
| 105 | # <commands with output to cut> | p1 |
| 106 | function p1() { while read input; do echo ${input} | cut -d' ' -f1; done; }; |
| 107 | # ol1 is short for openstack list with 1 param. Also grep and cut |
| 108 | # "ol1 network public" will list all networks, grep by name public and return IDs |
| 109 | function ol1() { echo $(openstack $1 list -c ID -c Name -f value | grep $2 | cut -d' ' -f1); } |
| 110 | # same as ol1 but with 2 initial commands before list |
| 111 | function ol2() { echo $(openstack $1 $2 list -c ID -c Name -f value | grep $3 | cut -d' ' -f1); } |
| 112 | |
| 113 | function print_manifest() { |
| 114 | touch ./${filename} |
| 115 | truncate -s 0 ${filename} |
| 116 | printf "\n\n# Checking and filling manifest: $(pwd)/${filename}\n" |
| 117 | put project_name ${project} |
| 118 | put project_id $(ol1 project ${project}) |
| 119 | put user_name ${user} |
| 120 | put user_id $(ol1 user ${user}) |
| 121 | put admin_name ${admin} |
| 122 | put admin_id $(ol1 user ${admin}) |
| 123 | # sg |
| 124 | put secgroup_all_name ${sg_all} |
| 125 | put secgroup_all_id $(ol2 security group ${sg_all}) |
| 126 | put secgroup_icmp_name ${sg_icmp} |
| 127 | put secgroup_icmp_id $(ol2 security group ${sg_icmp}) |
| 128 | put secgroup_ssh_name ${sg_ssh} |
| 129 | put secgroup_ssh_id $(ol2 security group ${sg_ssh}) |
| 130 | put secgroup_iperf_name ${sg_iperf} |
| 131 | put secgroup_iperf_id $(ol2 security group ${sg_iperf}) |
| 132 | |
| 133 | # keypair |
| 134 | put keypair_name ${key} |
| 135 | put keypair_id $(ol1 keypair ${key}) |
| 136 | |
| 137 | # flavors |
| 138 | put flavor_tiny_name ${flavor_t} |
| 139 | put flavor_tiny_id $(ol1 flavor ${flavor_t}) |
| 140 | put flavor_small_name ${flavor_s} |
| 141 | put flavor_small_id $(ol1 flavor ${flavor_s}) |
| 142 | put flavor_medium_name ${flavor_m} |
| 143 | put flavor_medium_id $(ol1 flavor ${flavor_m}) |
| 144 | put flavor_high_name ${flavor_h} |
| 145 | put flavor_high_id $(ol1 flavor ${flavor_h}) |
| 146 | |
| 147 | # fixed nets |
| 148 | put fixed_net_left_name ${net_left} |
| 149 | put fixed_net_left_id $(ol1 network ${net_left}) |
| 150 | put fixed_net_right_name ${net_right} |
| 151 | put fixed_net_right_id $(ol1 network ${net_right}) |
| 152 | put fixed_net_left_subnet_name ${subnet1} |
| 153 | put fixed_net_left_subnet_id $(openstack subnet list --network ${net_left} -c ID -f value | p1) |
| 154 | put fixed_net_right_subnet_name ${subnet2} |
| 155 | put fixed_net_right_subnet_id $(openstack subnet list --network ${net_right} -c ID -f value | p1) |
| 156 | |
| 157 | # router |
| 158 | put router_name ${router} |
| 159 | put router_id $(ol1 router ${router}) |
| 160 | |
| 161 | # volumes |
| 162 | put volume_name ${volume} |
| 163 | put volume_id $(ol1 volume ${volume}) |
| 164 | |
| 165 | # images |
Ievgeniia Zadorozhna | 1cb5b10 | 2024-01-19 04:31:09 +0100 | [diff] [blame] | 166 | put cirros61_name ${cirros61} |
| 167 | put cirros61_id $(ol1 image ${cirros61}) |
| 168 | put cirros62_name ${cirros62} |
| 169 | put cirros62_id $(ol1 image ${cirros62}) |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 170 | put ubuntu16_name ${ubuntu16} |
| 171 | put ubuntu16_id $(ol1 image ${ubuntu16}) |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 172 | put ubuntu20_name ${ubuntu20} |
| 173 | put ubuntu20_id $(ol1 image ${ubuntu20}) |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | # create rc file out of current ENV vars |
| 177 | function putrc() { |
| 178 | printf "# Saving ${1} file\n" |
| 179 | echo "export OS_IDENTITY_API_VERSION=${OS_IDENTITY_API_VERSION:-3}" >${1} |
| 180 | echo "export OS_AUTH_URL=${OS_AUTH_URL}" >>${1} |
| 181 | echo "export OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME}" >>${1} |
| 182 | echo "export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME}" >>${1} |
| 183 | echo "export OS_PROJECT_NAME=${OS_PROJECT_NAME}" >>${1} |
| 184 | echo "export OS_TENANT_NAME=${OS_TENANT_NAME}" >>${1} |
| 185 | echo "export OS_USERNAME=${OS_USERNAME}" >>${1} |
| 186 | echo "export OS_PASSWORD=${OS_PASSWORD}" >>${1} |
| 187 | echo "export OS_REGION_NAME=${OS_REGION_NAME}" >>${1} |
| 188 | echo "export OS_INTERFACE=${OS_INTERFACE}" >>${1} |
| 189 | echo "export OS_ENDPOINT_TYPE=${OS_ENDPOINT_TYPE}" >>${1} |
| 190 | echo "export OS_CACERT=${OS_CACERT}" >>${1} |
| 191 | } |
| 192 | |
| 193 | # update ENV vars to newly created project |
| 194 | function updatesession() { |
| 195 | export OS_PROJECT_NAME=${project} |
| 196 | export OS_TENANT_NAME=${project} |
| 197 | export OS_USERNAME=${admin} |
| 198 | export OS_PASSWORD=${password} |
| 199 | } |
| 200 | |
| 201 | function process_cmds() { |
| 202 | if [ -s ${cmds} ]; then |
| 203 | cat ${cmds} | tr '\n' '\0' | xargs -P 1 -n 1 -0 echo | tee /dev/tty | openstack -v 2>&1 >>${logfile} |
| 204 | truncate -s 0 ${cmds} |
| 205 | fi |
| 206 | } |
| 207 | |
| 208 | function _project() { |
| 209 | echo project create ${project} >>${cmds} |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 210 | # admin_username=$(openstack user list --project admin --domain ${domain} -c Name -f value | grep admin) |
| 211 | # user admin_username from the initial env vars of the pod |
Ievgeniia Zadorozhna | a76c852 | 2023-08-03 17:00:54 +0300 | [diff] [blame] | 212 | echo role add --user ${admin_username} --project ${project} admin >>${cmds} |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | function _users() { |
| 216 | echo user create --project ${project} --password ${password} ${user} >>${cmds} |
| 217 | echo user create --project ${project} --password ${password} ${admin} >>${cmds} |
| 218 | echo role add --user ${admin} --project ${project} admin >>${cmds} |
| 219 | echo role add --user ${admin} --project ${project} creator >>${cmds} |
| 220 | echo role add --user ${user} --project ${project} member >>${cmds} |
| 221 | echo role add --user ${user} --project ${project} creator >>${cmds} |
Ievgeniia Zadorozhna | 5452a37 | 2023-07-10 20:54:13 +0300 | [diff] [blame] | 222 | echo role add --user ${user} --project ${project} load-balancer_member >>${cmds} |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 223 | |
| 224 | } |
| 225 | |
| 226 | function _sg_all() { |
| 227 | echo security group create --project ${project} ${sg_all} >>${cmds} |
| 228 | # icmp |
| 229 | echo security group rule create --protocol icmp ${sg_all} >>${cmds} |
| 230 | # ssh |
| 231 | echo security group rule create --protocol tcp --dst-port 22 ${sg_all} >>${cmds} |
| 232 | # iperf |
| 233 | echo security group rule create --protocol tcp --dst-port 5001 ${sg_all} >>${cmds} |
| 234 | # iperf3 |
| 235 | echo security group rule create --protocol tcp --dst-port 5201 ${sg_all} >>${cmds} |
| 236 | # nc connectivity |
| 237 | echo security group rule create --protocol tcp --dst-port 3000 ${sg_all} >>${cmds} |
| 238 | # http |
| 239 | echo security group rule create --protocol tcp --dst-port 80 ${sg_all} >>${cmds} |
| 240 | # https |
| 241 | echo security group rule create --protocol tcp --dst-port 443 ${sg_all} >>${cmds} |
| 242 | } |
| 243 | |
| 244 | function _sg_icmp() { |
| 245 | echo security group create --project ${project} ${sg_icmp} >>${cmds} |
| 246 | echo security group rule create --protocol icmp ${sg_icmp} >>${cmds} |
| 247 | } |
| 248 | |
| 249 | function _sg_ssh() { |
| 250 | echo security group create --project ${project} ${sg_ssh} >>${cmds} |
| 251 | # icmp |
| 252 | echo security group rule create --protocol icmp ${sg_ssh} >>${cmds} |
| 253 | # ssh |
| 254 | echo security group rule create --protocol tcp --dst-port 22 ${sg_ssh} >>${cmds} |
| 255 | } |
| 256 | |
| 257 | function _sg_iperf() { |
| 258 | echo security group create --project ${project} ${sg_iperf} >>${cmds} |
| 259 | # icmp |
| 260 | echo security group rule create --protocol icmp ${sg_iperf} >>${cmds} |
| 261 | # iperf |
| 262 | echo security group rule create --protocol tcp --dst-port 5001 ${sg_iperf} >>${cmds} |
| 263 | # iperf3 |
| 264 | echo security group rule create --protocol tcp --dst-port 5201 ${sg_iperf} >>${cmds} |
| 265 | } |
| 266 | |
| 267 | function create_keypair() { |
| 268 | echo "# Creating keypair" |
| 269 | openstack keypair create ${key} >${key} |
| 270 | chmod 600 ${key} |
| 271 | echo "-> created keyfile: $(pwd)/${key}" |
| 272 | } |
| 273 | |
| 274 | function _flavors() { |
| 275 | # huge paged flavors |
| 276 | if [ "$huge_pages" = true ]; then |
Alex | c7f187c | 2022-04-28 10:02:27 -0500 | [diff] [blame] | 277 | echo flavor create --id 1 --ram 256 --disk 5 --vcpus 1 ${flavor_t} --property hw:mem_page_size=large >>${cmds} |
| 278 | echo flavor create --id 2 --ram 512 --disk 10 --vcpus 2 ${flavor_s} --property hw:mem_page_size=large >>${cmds} |
| 279 | echo flavor create --id 3 --ram 2048 --disk 20 --vcpus 4 ${flavor_m} --property hw:mem_page_size=large >>${cmds} |
| 280 | echo flavor create --id 4 --ram 4096 --disk 30 --vcpus 6 ${flavor_h} --property hw:mem_page_size=large >>${cmds} |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 281 | else |
Alex | c7f187c | 2022-04-28 10:02:27 -0500 | [diff] [blame] | 282 | echo flavor create --id 1 --ram 256 --disk 5 --vcpus 1 ${flavor_t} >>${cmds} |
| 283 | echo flavor create --id 2 --ram 512 --disk 10 --vcpus 2 ${flavor_s} >>${cmds} |
| 284 | echo flavor create --id 3 --ram 2048 --disk 20 --vcpus 4 ${flavor_m} >>${cmds} |
| 285 | echo flavor create --id 4 --ram 4096 --disk 30 --vcpus 6 ${flavor_h} >>${cmds} |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 286 | fi |
| 287 | } |
| 288 | |
| 289 | function _volumes() { |
| 290 | echo volume create --size 2 ${volume} >>${cmds} |
| 291 | } |
| 292 | |
| 293 | function create_fixed_nets() { |
| 294 | echo "# Creating fixed networks" |
| 295 | echo network create --project ${project} ${net_left} >>${cmds} |
| 296 | echo subnet create ${subnet1} --network ${net_left} --subnet-range 10.10.11.0/24 >>${cmds} |
| 297 | echo network set --share ${net_left} >>${cmds} |
| 298 | echo network create --project ${project} ${net_right} >>${cmds} |
| 299 | echo subnet create ${subnet2} --network ${net_right} --subnet-range 10.10.12.0/24 >>${cmds} |
| 300 | echo network set --share ${net_right} >>${cmds} |
| 301 | process_cmds |
| 302 | |
| 303 | # get subnet ids |
| 304 | subnet1_id=$(openstack subnet list --network ${net_left} -c ID -f value) |
| 305 | subnet2_id=$(openstack subnet list --network ${net_right} -c ID -f value) |
| 306 | |
| 307 | echo router create --project ${project} ${router} >>${cmds} |
| 308 | process_cmds |
| 309 | |
| 310 | router_id=$(openstack router list -c ID -c Name -f value | grep ${router} | cut -d' ' -f1) |
| 311 | echo router add subnet ${router_id} ${subnet1_id} >>${cmds} |
| 312 | echo router add subnet ${router_id} ${subnet2_id} >>${cmds} |
| 313 | process_cmds |
| 314 | |
Ievgeniia Zadorozhna | dbf166a | 2022-03-09 18:52:36 +0300 | [diff] [blame] | 315 | # get external network name |
Ievgeniia Zadorozhna | 7bc5405 | 2024-02-20 00:15:35 +0100 | [diff] [blame] | 316 | if [ -n "${CUSTOM_PUBLIC_NET_NAME:-}" ]; then |
| 317 | # if CUSTOM_PUBLIC_NET_NAME is set to some specific net, check it is present on the cloud and use it |
| 318 | echo "# Checking that the external network ${CUSTOM_PUBLIC_NET_NAME} is present on the cloud" |
| 319 | network_exists=$(openstack network show "$CUSTOM_PUBLIC_NET_NAME" -c id -f value 2>/dev/null) |
| 320 | if [ -n "$network_exists" ]; then |
Ievgeniia Zadorozhna | c21d552 | 2024-07-26 18:42:49 +0200 | [diff] [blame] | 321 | TEST_PUBLIC_NET=${CUSTOM_PUBLIC_NET_NAME} |
Ievgeniia Zadorozhna | 7bc5405 | 2024-02-20 00:15:35 +0100 | [diff] [blame] | 322 | echo router set ${router} --external-gateway ${CUSTOM_PUBLIC_NET_NAME} >>${cmds} |
| 323 | process_cmds |
| 324 | else |
| 325 | echo "# The network ${CUSTOM_PUBLIC_NET_NAME} does not exist" |
| 326 | CUSTOM_PUBLIC_NET_NAME="" |
| 327 | fi |
| 328 | fi |
| 329 | if [ -z "${CUSTOM_PUBLIC_NET_NAME:-}" ]; then |
| 330 | echo "# Selecting a random external network as an external gateway for the router" |
| 331 | # if the custom network is not set or is empty, select the first external network |
| 332 | external=$(openstack network list --external -c Name -f value | head -n1) |
Ievgeniia Zadorozhna | c21d552 | 2024-07-26 18:42:49 +0200 | [diff] [blame] | 333 | TEST_PUBLIC_NET=${external} |
Ievgeniia Zadorozhna | 7bc5405 | 2024-02-20 00:15:35 +0100 | [diff] [blame] | 334 | echo router set ${router} --external-gateway ${external} >>${cmds} |
| 335 | process_cmds |
| 336 | fi |
Ievgeniia Zadorozhna | c21d552 | 2024-07-26 18:42:49 +0200 | [diff] [blame] | 337 | |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 338 | if [ "$set_gw_heat_router" = true ]; then |
| 339 | echo "# Variable 'set_gw_heat_router' is true; setting the external gateway info for heat-router (if not set yet)..." |
| 340 | # set external gateway info for the Heat router if it is not set (required for Heat Tempest tests) |
| 341 | external_gateway_info=$(openstack router show heat-router -f json -c external_gateway_info | jq -r '.external_gateway_info') |
| 342 | if [[ "$external_gateway_info" == "null" ]]; then |
| 343 | echo "# Setting external gw info for heat-router using ${TEST_PUBLIC_NET}" |
| 344 | openstack router set --external-gateway ${TEST_PUBLIC_NET} heat-router |
| 345 | if [[ $? -eq 0 ]]; then |
| 346 | echo "# External gateway set successfully for heat-router" |
| 347 | openstack router show heat-router -c external_gateway_info |
| 348 | else |
| 349 | echo "# Failed to set external gateway for heat-router" |
| 350 | fi |
Ievgeniia Zadorozhna | c21d552 | 2024-07-26 18:42:49 +0200 | [diff] [blame] | 351 | else |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 352 | echo "# Router heat-router already has an external gateway" |
| 353 | openstack router show heat-router -c external_gateway_info |
Ievgeniia Zadorozhna | c21d552 | 2024-07-26 18:42:49 +0200 | [diff] [blame] | 354 | fi |
| 355 | else |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 356 | echo "# Variable 'set_gw_heat_router' is not true, skipping setting external_gateway_info for heat-router..." |
Ievgeniia Zadorozhna | c21d552 | 2024-07-26 18:42:49 +0200 | [diff] [blame] | 357 | fi |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | function _get_image() { |
| 361 | # build vars for name and link |
| 362 | name="${1}" |
| 363 | link="${1}_link" |
| 364 | which wget >/dev/null |
| 365 | if [ $? -ne 0 ]; then |
| 366 | printf "\nERROR: 'wget' not detected. Download skipped: ${!name}\n" |
| 367 | else |
| 368 | # no redownloads, quet, save named and show progress |
| 369 | r=$(wget --no-check-certificate -nc -q -O ./${!name} --show-progress ${!link}) |
| 370 | if [ $? -ne 0 ]; then |
| 371 | # non-empty output on error |
| 372 | echo ${r} |
| 373 | fi |
| 374 | fi |
| 375 | } |
| 376 | |
| 377 | function create_image() { |
| 378 | name="${1}" |
| 379 | # Check if image is in the cloud |
| 380 | echo "# Checking image '${!name}'" |
| 381 | ids=( $(ol1 image ${!name}) ) |
| 382 | # if array is empty, download and upload it |
| 383 | if [ ${#ids[@]} -eq 0 ]; then |
| 384 | # check and download |
| 385 | if [ ! -f ${!name} ]; then |
| 386 | r=$(_get_image ${1}) |
| 387 | else |
| 388 | r="" |
| 389 | fi |
| 390 | # check if output is not empty |
| 391 | if [ ${#r} -eq 0 ]; then |
Ievgeniia Zadorozhna | e83b961 | 2024-12-24 16:02:23 +0100 | [diff] [blame^] | 392 | if [ "$raw_disk_format" = true ]; then |
| 393 | qemu-img convert -f qcow2 -O raw ${!name} ${!name}.raw |
| 394 | image_id=$(openstack image create --public --disk-format raw --container-format bare --file ${!name}.raw ${!name} -c id -f value) |
| 395 | echo "-> created ${!name} (${image_id})" |
| 396 | rm ${!name}.raw |
| 397 | else |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 398 | image_id=$(openstack image create --public --disk-format qcow2 --container-format bare --file ${!name} ${!name} -c id -f value) |
| 399 | echo "-> created ${!name} (${image_id})" |
Ievgeniia Zadorozhna | e83b961 | 2024-12-24 16:02:23 +0100 | [diff] [blame^] | 400 | fi |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 401 | else |
| 402 | printf "\n-> Error detected, creation skipped\n" |
| 403 | fi |
| 404 | else |
| 405 | # image(s) already there, list them |
| 406 | for id in ${ids[@]}; do |
| 407 | echo "-> found ${!name} with ID of '${id}'" |
| 408 | done |
| 409 | fi |
| 410 | } |
| 411 | |
| 412 | ################### |
| 413 | ### Main |
| 414 | ################### |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 415 | echo "Using working folder: ${working_folder}" |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 416 | if [[ -z ${working_folder+x} ]]; then |
| 417 | # cwd into working dir |
| 418 | cd ${working_folder} |
| 419 | fi |
| 420 | |
| 421 | cmds=$(mktemp) |
| 422 | trap "rm -f ${cmds}" EXIT |
| 423 | echo "Using tempfile: '${cmds}'" |
| 424 | |
| 425 | touch ${logfile} |
| 426 | echo "Using log file: '${logfile}'" |
| 427 | |
| 428 | # Create |
| 429 | echo "# Creating project and users" |
| 430 | _project |
| 431 | _users |
| 432 | process_cmds |
| 433 | |
| 434 | echo "# Creating 'rc' and switching" |
| 435 | putrc "./adminrc" |
| 436 | updatesession |
| 437 | putrc "./${rcfile}" |
| 438 | |
| 439 | echo "# Creating basic resources" |
| 440 | # not dependent stuff |
| 441 | _sg_all |
| 442 | _sg_icmp |
| 443 | _sg_ssh |
| 444 | _sg_iperf |
| 445 | _flavors |
| 446 | _volumes |
| 447 | process_cmds |
| 448 | |
| 449 | # sophisticated, step dependent stuff |
| 450 | create_keypair |
| 451 | create_fixed_nets |
| 452 | |
| 453 | # images |
Ievgeniia Zadorozhna | 1cb5b10 | 2024-01-19 04:31:09 +0100 | [diff] [blame] | 454 | create_image cirros61 |
| 455 | create_image cirros62 |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 456 | create_image ubuntu16 |
| 457 | create_image ubuntu20 |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 458 | |
| 459 | ### Manifest and fall back to original rc |
| 460 | print_manifest |
| 461 | printf ="\n\nSetting quota\n" |
Ievgeniia Zadorozhna | cf3140b | 2024-09-18 15:11:20 +0200 | [diff] [blame] | 462 | openstack quota set --cores -1 --ram -1 --instances -1 --volumes -1 --gigabytes -1 --server-groups -1 --server-group-members -1 cvp.project |
Alex | a443774 | 2022-02-16 14:42:38 -0600 | [diff] [blame] | 463 | source "./adminrc" |
| 464 | printf "\n\nOriginal rc preserved and backed up in 'adminrc'\nNew rc is '${rcfile}'\n" |