From bf458d530a3dd583a3323af38b8cc01777891a17 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 | 110 +++++++++++++++++---------- 2 files changed, 91 insertions(+), 65 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..56e1d3ee 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 @@ -52,14 +61,15 @@ while (( $# > 0 )); do cat < /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} # wait for lb to be ACTIVE while true; do - [[ `openstack loadbalancer show ${LB_ID} --column provisioning_status --format value` = ACTIVE ]] \ - && break + if [[ $(openstack loadbalancer show ${LB_ID} --column provisioning_status --format value) == ACTIVE ]]; then + break + fi echo "waiting for $lb" done @@ -99,18 +116,27 @@ 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 - [[ `openstack loadbalancer pool show ${POOL_ID} --column provisioning_status --format value` = ACTIVE ]] \ - && break + if [[ $(openstack loadbalancer pool show ${POOL_ID} --column provisioning_status --format value) == ACTIVE ]]; then + break + fi echo "waiting for ${lb}-pool" done @@ -120,13 +146,13 @@ 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 -for member in ${member_vm[@]}; do - netaddr=$(openstack port list --server $member --network private --column "Fixed IP Addresses" --format value | \ +for member in "${member_vm[@]}"; do + netaddr=$(openstack port list --server ${member} --network private --column "Fixed IP Addresses" --format value | \ sed -rn -e "s/.+ip_address='([[:digit:]\.]+)',\s+.+/\1/" \ -e "s/.+ip_address':\s+'([[:digit:]\.]+)'}.+/\1/p") member_id=$(openstack loadbalancer member create --subnet-id private_subnet \ @@ -141,11 +167,20 @@ done openstack loadbalancer member list ${POOL_ID} +floating_ip=$(openstack floating ip create --format value --column floating_ip_address ext_net) +lb_vip_port_id=$(openstack loadbalancer show --format value --column vip_port_id ${LB_ID}) +openstack floating ip set --port $lb_vip_port_id $floating_ip + +if [[ ${hm_protocol} != HTTP ]]; then + exit +fi + L7_POLICY1_ID=$(openstack loadbalancer l7policy create --action REDIRECT_TO_POOL \ --redirect-pool ${POOL_ID} --name ${lb}-l7policy1 --format value --column id ${LISTENER_ID}) while true; do - [[ $(openstack loadbalancer l7policy show ${L7_POLICY1_ID} --format value --column provisioning_status) = ACTIVE ]] \ - && break + if [[ $(openstack loadbalancer l7policy show ${L7_POLICY1_ID} --format value --column provisioning_status) == ACTIVE ]]; then + break + fi echo "waiting for ${lb}-l7policy1" done @@ -154,8 +189,9 @@ openstack loadbalancer l7policy show ${L7_POLICY1_ID} L7_RULE1_ID=$(openstack loadbalancer l7rule create --compare-type STARTS_WITH --type PATH \ --value /js --format value --column id ${L7_POLICY1_ID}) while true; do - [[ $(openstack loadbalancer l7rule show --format value --column provisioning_status ${L7_POLICY1_ID} ${L7_RULE1_ID}) = ACTIVE ]] \ - && break + if [[ $(openstack loadbalancer l7rule show --format value --column provisioning_status ${L7_POLICY1_ID} ${L7_RULE1_ID}) == ACTIVE ]]; then + break + fi echo "waiting for ${L7_RULE1_ID}" done @@ -164,8 +200,9 @@ openstack loadbalancer l7rule show ${L7_POLICY1_ID} ${L7_RULE1_ID} L7_POLICY2_ID=$(openstack loadbalancer l7policy create --action REDIRECT_TO_POOL \ --redirect-pool ${lb}-pool --name ${lb}-l7policy2 --format value --column id ${lb}-listener) while true; do - [[ $(openstack loadbalancer l7policy show ${L7_POLICY2_ID} --format value --column provisioning_status) = ACTIVE ]] \ - && break + if [[ $(openstack loadbalancer l7policy show ${L7_POLICY2_ID} --format value --column provisioning_status) == ACTIVE ]]; then + break + fi echo "waiting for ${lb}-l7policy2" done @@ -174,17 +211,10 @@ openstack loadbalancer l7policy show ${L7_POLICY2_ID} L7_RULE2_ID=$(openstack loadbalancer l7rule create --compare-type STARTS_WITH --type PATH \ --value /images --format value --column id ${L7_POLICY2_ID}) while true; do - [[ $(openstack loadbalancer l7rule show --format value --column provisioning_status ${L7_POLICY2_ID} ${L7_RULE2_ID}) = ACTIVE ]] \ - && break + if [[ $(openstack loadbalancer l7rule show --format value --column provisioning_status ${L7_POLICY2_ID} ${L7_RULE2_ID}) == ACTIVE ]]; then + break + fi echo "waiting for ${L7_RULE2_ID}" done openstack loadbalancer l7rule show ${L7_POLICY2_ID} ${L7_RULE2_ID} - -floating_ip=$(openstack floating ip create --format value --column floating_ip_address ext_net) -lb_vip_port_id=$(openstack loadbalancer show --format value --column vip_port_id ${LB_ID}) -openstack floating ip set --port $lb_vip_port_id $floating_ip - -# Local Variables: -# sh-basic-offset: 4 -# End: