@@ -2535,7 +2535,7 @@ lr_get_name(const struct nbrec_logical_router
*lr, char uuid_s[UUID_LEN + 1],
return uuid_s;
}
-static const struct nbrec_gateway_chassis*
+static const struct nbrec_gateway_chassis *
gc_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist)
{
const struct nbrec_gateway_chassis *gc = NULL;
@@ -2565,7 +2565,7 @@ gc_by_name_or_uuid(struct ctl_context *ctx,
const char *id, bool must_exist)
static void
nbctl_lrp_set_gateway_chassis(struct ctl_context *ctx)
{
- const char *gc_name;
+ char *gc_name;
int64_t priority = 0;
const char *lrp_name = ctx->argv[1];
const struct nbrec_logical_router_port *lrp;
@@ -2581,15 +2581,17 @@ nbctl_lrp_set_gateway_chassis(struct ctl_context *ctx)
}
gc_name = xasprintf("%s-%s", lrp_name, chassis_name);
- const struct nbrec_gateway_chassis *gc;
- gc = gc_by_name_or_uuid(ctx, gc_name, false);
- if (gc) {
- nbrec_gateway_chassis_set_priority(gc, priority);
+ const struct nbrec_gateway_chassis *existing_gc;
+ existing_gc = gc_by_name_or_uuid(ctx, gc_name, false);
+ if (existing_gc) {
+ nbrec_gateway_chassis_set_priority(existing_gc, priority);
+ free(gc_name);
return;
}
/* Create the logical gateway chassis. */
- gc = nbrec_gateway_chassis_insert(ctx->txn);
+ struct nbrec_gateway_chassis *gc
+ = nbrec_gateway_chassis_insert(ctx->txn);
nbrec_gateway_chassis_set_name(gc, gc_name);
nbrec_gateway_chassis_set_chassis_name(gc, chassis_name);
nbrec_gateway_chassis_set_priority(gc, priority);
@@ -2600,11 +2602,11 @@ nbctl_lrp_set_gateway_chassis(struct ctl_context *ctx)
sizeof *new_gc * (lrp->n_gateway_chassis + 1));
nullable_memcpy(new_gc, lrp->gateway_chassis,
sizeof *new_gc * lrp->n_gateway_chassis);
- new_gc[lrp->n_gateway_chassis] = CONST_CAST(
- struct nbrec_gateway_chassis *, gc);
+ new_gc[lrp->n_gateway_chassis] = gc;
nbrec_logical_router_port_set_gateway_chassis(
lrp, new_gc, lrp->n_gateway_chassis + 1);
free(new_gc);
+ free(gc_name);
}
/* Removes logical router port 'lrp->gateway_chassis[idx]'. */
@@ -2612,17 +2614,22 @@ static void
remove_gc(const struct nbrec_logical_router_port *lrp, size_t idx)
{
const struct nbrec_gateway_chassis *gc = lrp->gateway_chassis[idx];
- /* First remove 'gc' from the array of gateway_chassis. This is what will
- * actually cause the gateway chassis to be deleted when the transaction is
- * sent to the database server (due to garbage collection). */
- struct nbrec_gateway_chassis **new_gc
- = xmemdup(lrp->gateway_chassis,
- sizeof *new_gc * lrp->n_gateway_chassis);
- new_gc[idx] = new_gc[lrp->n_gateway_chassis - 1];
- nbrec_logical_router_port_verify_gateway_chassis(lrp);
- nbrec_logical_router_port_set_gateway_chassis(
- lrp, new_gc, lrp->n_gateway_chassis - 1);
- free(new_gc);
+
+ if (lrp->n_gateway_chassis == 1) {
+ nbrec_logical_router_port_set_gateway_chassis(lrp, NULL, 0);
+ } else {
+ /* First remove 'gc' from the array of gateway_chassis. This
is what will
+ * actually cause the gateway chassis to be deleted when the
transaction is
+ * sent to the database server (due to garbage collection). */
+ struct nbrec_gateway_chassis **new_gc
+ = xmemdup(lrp->gateway_chassis,
+ sizeof *new_gc * lrp->n_gateway_chassis);
+ new_gc[idx] = new_gc[lrp->n_gateway_chassis - 1];
+ nbrec_logical_router_port_verify_gateway_chassis(lrp);
+ nbrec_logical_router_port_set_gateway_chassis(
+ lrp, new_gc, lrp->n_gateway_chassis - 1);
+ free(new_gc);
+ }
/* Delete 'gc' from the IDL. This won't have a real effect on
* the database server (the IDL will suppress it in fact) but it
@@ -803,6 +803,9 @@ AT_CHECK([ovn-nbctl lrp-get-gateway-chassis lrp0], [0], [dnl
lrp0-chassis2 5
])
+AT_CHECK([ovn-nbctl lrp-del-gateway-chassis lrp0 chassis2])
+AT_CHECK([ovn-nbctl lrp-get-gateway-chassis lrp0])
+
OVN_NBCTL_TEST_STOP
AT_CLEANUP