On Tue, Jul 22, 2025 at 6:48 PM Lucas Vargas Dias via dev <
ovs-dev@openvswitch.org> wrote:

> Configuration of Gateway Chassis with different name than the default
> format of "$lrp-$chassis" could lead to duplicates when priority was
> changed for the GW Chassis with different name e.g.:
>
> lrp0_chassis1     1  --> inserted by cms
> lrp0-chassis1     2  --> change priority with ovn-nbctl
> lrp-set-gateway-chassis
>
> ovn-controller would then create a log message every time it tried
> recalculate priorities.
>
> Search the GW Chassis linked to specified LRP by chassis_name first
> before resorting to uuid search.
>
> Signed-off-by: Lucas Vargas Dias <lucas.vd...@luizalabs.com>
> ---
>  tests/ovn-nbctl.at    | 16 +++++++++++++++-
>  utilities/ovn-nbctl.c | 25 ++++++++++++++-----------
>  2 files changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at
> index bdeb3aeee..fe4a984d0 100644
> --- a/tests/ovn-nbctl.at
> +++ b/tests/ovn-nbctl.at
> @@ -1958,7 +1958,21 @@ AT_CHECK([ovn-nbctl lrp-get-gateway-chassis lrp0],
> [0], [dnl
>  lrp0-chassis2    10
>  lrp0-chassis3     5
>  lrp0-chassis1     1
> -])])
> +])
> +gc_uuid=$(ovn-nbctl --bare --colum _uuid find gateway_chassis
> name='lrp0-chassis1')
> +AT_CHECK([ovn-nbctl set gateway_chassis $gc_uuid name='lrp0_chassis1'])
> +AT_CHECK([ovn-nbctl lrp-get-gateway-chassis lrp0], [0], [dnl
> +lrp0-chassis2    10
> +lrp0-chassis3     5
> +lrp0_chassis1     1
> +])
> +AT_CHECK([ovn-nbctl lrp-set-gateway-chassis lrp0 chassis1 2])
> +AT_CHECK([ovn-nbctl lrp-get-gateway-chassis lrp0], [0], [dnl
> +lrp0-chassis2    10
> +lrp0-chassis3     5
> +lrp0_chassis1     2
> +])
> +])
>
>  dnl ---------------------------------------------------------------------
>
> diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
> index 56a513217..8bc58e8ef 100644
> --- a/utilities/ovn-nbctl.c
> +++ b/utilities/ovn-nbctl.c
> @@ -5829,26 +5829,28 @@ lr_get_name(const struct nbrec_logical_router *lr,
> char uuid_s[UUID_LEN + 1],
>  }
>
>  static char * OVS_WARN_UNUSED_RESULT
> -gc_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool
> must_exist,
> -                   const struct nbrec_gateway_chassis **gc_p)
> +gc_by_chassis_name_or_uuid(struct ctl_context *ctx,
> +                           const char *id, bool must_exist,
> +                           const struct nbrec_gateway_chassis **gc_p,
> +                           const struct nbrec_logical_router_port *lrp
> +                           )
>

nit: Formatting.

 {
>      const struct nbrec_gateway_chassis *gc = NULL;
>      *gc_p = NULL;
>
> +    for (size_t i = 0; i < lrp->n_gateway_chassis; i++) {
> +        if (!strcmp(lrp->gateway_chassis[i]->chassis_name, id)) {
> +            *gc_p = lrp->gateway_chassis[i];
> +            return NULL;
> +        }
> +    }
> +
>      struct uuid gc_uuid;
>      bool is_uuid = uuid_from_string(&gc_uuid, id);
>      if (is_uuid) {
>          gc = nbrec_gateway_chassis_get_for_uuid(ctx->idl, &gc_uuid);
>      }
>
> -    if (!gc) {
> -        NBREC_GATEWAY_CHASSIS_FOR_EACH (gc, ctx->idl) {
> -            if (!strcmp(gc->name, id)) {
> -                break;
> -            }
> -        }
> -    }
> -
>      if (!gc && must_exist) {
>          return xasprintf("%s: gateway chassis %s not found", id,
>                           is_uuid ? "UUID" : "name");
> @@ -5867,6 +5869,7 @@ nbctl_pre_lrp_set_gateway_chassis(struct ctl_context
> *ctx)
>
>      ovsdb_idl_add_column(ctx->idl, &nbrec_gateway_chassis_col_name);
>      ovsdb_idl_add_column(ctx->idl, &nbrec_gateway_chassis_col_priority);
> +    ovsdb_idl_add_column(ctx->idl,
> &nbrec_gateway_chassis_col_chassis_name);
>  }
>
>  static void
> @@ -5897,7 +5900,7 @@ nbctl_lrp_set_gateway_chassis(struct ctl_context
> *ctx)
>
>      gc_name = xasprintf("%s-%s", lrp_name, chassis_name);
>      const struct nbrec_gateway_chassis *gc;
> -    error = gc_by_name_or_uuid(ctx, gc_name, false, &gc);
> +    error = gc_by_chassis_name_or_uuid(ctx, chassis_name, false, &gc,
> lrp);
>      if (error) {
>          ctx->error = error;
>          free(gc_name);
> --
> 2.34.1
>
>
> --
>
>
>
>
> _'Esta mensagem é direcionada apenas para os endereços constantes no
> cabeçalho inicial. Se você não está listado nos endereços constantes no
> cabeçalho, pedimos-lhe que desconsidere completamente o conteúdo dessa
> mensagem e cuja cópia, encaminhamento e/ou execução das ações citadas
> estão
> imediatamente anuladas e proibidas'._
>
>
> * **'Apesar do Magazine Luiza tomar
> todas as precauções razoáveis para assegurar que nenhum vírus esteja
> presente nesse e-mail, a empresa não poderá aceitar a responsabilidade por
> quaisquer perdas ou danos causados por esse e-mail ou por seus anexos'.*
>
>
>
> _______________________________________________
> dev mailing list
> d...@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
>
Thank you Lucas,

I have fixed one small nit and applied it to the main and backported all
the way down 24.03.

Regards,
Ales
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to