From b98d2078708a4f9e81890d5d882415f10a821f76 Mon Sep 17 00:00:00 2001 From: Nicolas Bock Date: Thu, 9 Nov 2023 15:29:44 +0200 Subject: [PATCH] Make ovn provider non-optional This change enables the ovn-provider for Octavia mandatory if at least Victoria and OVN. Signed-off-by: Nicolas Bock --- openstack/pipeline/02configure | 46 +++++++++++------------ openstack/tools/create_octavia_lb.sh | 56 ++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 41 deletions(-) diff --git a/openstack/pipeline/02configure b/openstack/pipeline/02configure index 76c94381..5bc0fe67 100644 --- a/openstack/pipeline/02configure +++ b/openstack/pipeline/02configure @@ -419,26 +419,24 @@ do if has_opt --openstack-dashboard*; then MOD_OVERLAYS+=( "openstack/octavia-dashboard.yaml" ) fi - # no amphora if using ovn provider - if ! has_opt --octavia-ovn-provider; then - MOD_PARAMS[__AMPHORA_SSH_PUB_KEY__]="`get_amphora_ssh_pub_key`" - # This equates to m1.large (rather than m1.medium) which should - # allow creating 1x ubunu vm + 1x amphora vm on the same host thus - # avoiding the need for > 1 compute host. - MOD_PARAMS[__NOVA_COMPUTE_UNIT_CONSTRAINTS__]="mem=8G" - if ! has_opt --no-octavia-diskimage-retrofit; then - # By default we let retrofit use images uploaded by the post-deploy configure script. - MOD_OVERLAYS+=( "openstack/octavia-diskimage-retrofit.yaml" ) - MOD_PARAMS[__OCTAVIA_RETROFIT_UCA__]=`get_ost_release` - if ! has_opt --octavia-diskimage-retrofit-glance-simplestreams; then - MOD_OVERLAYS+=( "openstack/octavia-diskimage-retrofit-glance.yaml" ) - fi + MOD_PARAMS[__AMPHORA_SSH_PUB_KEY__]="`get_amphora_ssh_pub_key`" + # This equates to m1.large (rather than m1.medium) which should + # allow creating 1x ubunu vm + 1x amphora vm on the same host thus + # avoiding the need for > 1 compute host. + MOD_PARAMS[__NOVA_COMPUTE_UNIT_CONSTRAINTS__]="mem=8G" + if ! has_opt --no-octavia-diskimage-retrofit; then + # By default we let retrofit use images uploaded by the + # post-deploy configure script. + MOD_OVERLAYS+=( "openstack/octavia-diskimage-retrofit.yaml" ) + MOD_PARAMS[__OCTAVIA_RETROFIT_UCA__]=`get_ost_release` + if ! has_opt --octavia-diskimage-retrofit-glance-simplestreams; then + MOD_OVERLAYS+=( "openstack/octavia-diskimage-retrofit-glance.yaml" ) fi - MOD_MSGS[octavia.0]="you need to to create an amphora image before you can use Octavia" - MOD_MSGS[octavia.1]="this can be done in one of two ways:" - MOD_MSGS[octavia.2]="run ./tools/upload_octavia_amphora_image.sh --release $release to use a pre-created image (recommended)" - MOD_MSGS[octavia.3]="create a new image with 'juju $JUJU_RUN_CMD octavia-diskimage-retrofit/0 retrofit-image source-image=' with id of image in Glance to use as base" fi + MOD_MSGS[octavia.0]="you need to to create an amphora image before you can use Octavia" + MOD_MSGS[octavia.1]="this can be done in one of two ways:" + MOD_MSGS[octavia.2]="run ./tools/upload_octavia_amphora_image.sh --release $release to use a pre-created image (recommended)" + MOD_MSGS[octavia.3]="create a new image with 'juju $JUJU_RUN_CMD octavia-diskimage-retrofit/0 retrofit-image source-image=' with id of image in Glance to use as base" if has_opt --octavia-ipv4; then MOD_MSGS[octavia.4]="run tools/create_ipv4_octavia.sh" fi @@ -449,13 +447,11 @@ do MOD_MSGS[octavia.9]="create loadbalancer i.e. ./tools/create_octavia_lb.sh --member-vm " MOD_MSGS[octavia.10]="alternatively manually create loadbalancer" MOD_MSGS[octavia.11]="openstack loadbalancer create --name lb2 --vip-network-id lb-mgmt" - ;; - --octavia-ovn-provider) - MOD_OVERLAYS+=( "openstack/octavia-ovn-provider.yaml" ) - assert_min_release victoria octavia-ovn-provider - # ensure octavia and ovn - set -- $@ --octavia && cache $@ - set -- $@ --ml2-ovn && cache $@ + if has_min_release victoria; then + if is_ml2_ovn; then + MOD_OVERLAYS+=( "openstack/octavia-ovn-provider.yaml" ) + fi + fi ;; --octavia-ha*) get_units $1 __NUM_OCTAVIA_UNITS__ 3 diff --git a/openstack/tools/create_octavia_lb.sh b/openstack/tools/create_octavia_lb.sh index 0b878f11..deb04aa9 100755 --- a/openstack/tools/create_octavia_lb.sh +++ b/openstack/tools/create_octavia_lb.sh @@ -1,7 +1,8 @@ #!/bin/bash -eux lb=lb1 -member_vm= +declare -a member_vm=() +provider=amphora protocol=HTTP protocol_port=80 hm_protocol= @@ -21,7 +22,15 @@ while (( $# > 0 )); do echo "missing member VM" exit 1 fi - member_vm=$2 + member_vm+=( $2 ) + shift + ;; + --provider) + if (( $# < 2 )); then + echo "missing provider" + exit 1 + fi + provider=$2 shift ;; --protocol) @@ -40,7 +49,7 @@ while (( $# > 0 )); do protocol_port=$2 shift ;; - --healthmonitor-protocol) + --healthmonitor-protocol) if (( $# < 2 )); then echo "missing protocol for healthmonitor" exit 1 @@ -54,12 +63,13 @@ Usage: $(basename $0) [options] ---name NAME The loadbalancer name base, default = $lb (things +--name NAME The loadbalancer name base, default = ${lb} (things such as listener and pool are named using this base) ---member-vm NAME The name of the member VM. If not provided - use the first VM running. ---protocol PROTOCOL TCP, HTTP, ..., default = $protocol ---protocol-port PORT Port to use, default = $protocol_port +--member-vm NAME The name of the member VM. Can be used multiple times. + If not provided use the first VM running. +--provider PROVIDER The Octavia provider {amphora, ovn}, default = ${provider} +--protocol PROTOCOL TCP, HTTP, ..., default = ${protocol} +--protocol-port PORT Port to use, default = ${protocol_port} EOF exit 0 ;; @@ -78,11 +88,17 @@ if [[ ${hm_protocol} == HTTP ]]; then url_path="--url-path /" fi -`openstack loadbalancer list --column name --format value | \ - grep -q $lb` && { echo "ERROR: a loadbalancer called $lb already exists"; exit 1; } +if openstack loadbalancer show ${lb} > /dev/null; then + echo "ERROR: a loadbalancer called $lb already exists" + exit 1 +fi -LB_ID=$(openstack loadbalancer create --name $lb \ - --vip-subnet-id private_subnet --format value --column id) +LB_ID=$(openstack loadbalancer create \ + --name ${lb} \ + --vip-subnet-id private_subnet \ + --provider ${provider} \ + --format value \ + --column id) # Re-run the following until $lb shows ACTIVE and ONLINE status': openstack loadbalancer show ${LB_ID} @@ -99,13 +115,21 @@ LISTENER_ID=$(openstack loadbalancer listener create \ --format value --column id $lb) # wait for listener to be ACTIVE while true; do - [[ `openstack loadbalancer listener show ${LISTENER_ID} --column provisioning_status --format value` = ACTIVE ]] \ - && break + if [[ $(openstack loadbalancer listener show ${LISTENER_ID} --column provisioning_status --format value) == ACTIVE ]]; then + break + fi echo "waiting for ${lb}-listener" done +LB_ALGORITHM=ROUND_ROBIN +if [[ ${provider} == ovn ]]; then + LB_ALGORITHM=SOURCE_IP_PORT +fi POOL_ID=$(openstack loadbalancer pool create \ - --name ${lb}-pool --lb-algorithm ROUND_ROBIN --listener ${LISTENER_ID} --protocol ${protocol} \ + --name ${lb}-pool \ + --lb-algorithm ${LB_ALGORITHM} \ + --listener ${LISTENER_ID} \ + --protocol ${protocol} \ --format value --column id) # wait for pool to be ACTIVE while true; do @@ -120,7 +144,7 @@ HM_ID=$(openstack loadbalancer healthmonitor create \ openstack loadbalancer healthmonitor list # Add vm(s) to pool -if [ -z "$member_vm" ]; then +if (( ${#member_vm[@]} == 0 )); then readarray -t member_vm < <(openstack server list --column ID --format value) (( ${#member_vm[@]} )) || { echo "ERROR: could not find a vm to add to lb pool"; exit 1; } fi