Message ID | 20231017162354.173449-1-ekovalev.off@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | [ovs-dev] nbctl: Add optional ha-chassis-group arg to ha-chassis-group-list | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | warning | apply and check: warning |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
ovsrobot/github-robot-_ovn-kubernetes | success | github build: passed |
Bleep bloop. Greetings Evgenii Kovalev, I am a robot and I have tried out your patch. Thanks for your contribution. I encountered some error that I wasn't expecting. See the details below. checkpatch: WARNING: Line lacks whitespace around operator #110 FILE: utilities/ovn-nbctl.c:467: ha-chassis-group-add GRP Create an HA chassis group GRP\n\ WARNING: Line lacks whitespace around operator #111 FILE: utilities/ovn-nbctl.c:468: ha-chassis-group-del GRP Delete the HA chassis group GRP\n\ WARNING: Line is 92 characters long (recommended limit is 79) WARNING: Line lacks whitespace around operator #112 FILE: utilities/ovn-nbctl.c:469: ha-chassis-group-list [GRP] Print the supplied HA chassis group or all if none supplied\n\ WARNING: Line is 93 characters long (recommended limit is 79) #130 FILE: utilities/ovn-nbctl.c:7309: ha_ch_grp_info_print(struct ctl_context *ctx, const struct nbrec_ha_chassis_group *ha_ch_grp) Lines checked: 194, Warnings: 5, Errors: 0 Please check this out. If you feel there has been an error, please email aconole@redhat.com Thanks, 0-day Robot
On Tue, Oct 17, 2023 at 12:25 PM Evgenii Kovalev <ekovalev.off@gmail.com> wrote: > > This commit adds support for optional ha-chassis-group argument to > ha-chassis-group-list command to show one record. > > Also add few tests to validate output from ha-chassis-group-list. > > Signed-off-by: Evgenii Kovalev <ekovalev.off@gmail.com> Thanks for the patch and for the contribution. I added your name to AUTHORS list and applied the patch to the main. Numan > --- > tests/ovn-nbctl.at | 53 +++++++++++++++++++++++++++++++++++++ > utilities/ovn-nbctl.8.xml | 8 +++--- > utilities/ovn-nbctl.c | 55 +++++++++++++++++++++++++++------------ > 3 files changed, 96 insertions(+), 20 deletions(-) > > diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at > index fde3a28ee..7206d1fe5 100644 > --- a/tests/ovn-nbctl.at > +++ b/tests/ovn-nbctl.at > @@ -2741,3 +2741,56 @@ cp $PKIDIR/$cert $cert > OVS_WAIT_UNTIL([ovn-appctl -t ovn-nbctl run show]) > > AT_CLEANUP > + > +dnl --------------------------------------------------------------------- > + > +AT_SETUP([ovn-nbctl - ha-chassis-group-list group]) > +OVN_NBCTL_TEST_START daemon > +check ovn-nbctl ha-chassis-group-add chg1 > +chg1uuid=$(fetch_column nb:HA_Chassis_Group _uuid name=chg1) > +check ovn-nbctl ha-chassis-group-add chg2 > +chg2uuid=$(fetch_column nb:HA_Chassis_Group _uuid name=chg2) > +check ovn-nbctl ha-chassis-group-add-chassis chg1 hv1 1 > +check ovn-nbctl ha-chassis-group-add-chassis chg1 hv2 2 > +check ovn-nbctl ha-chassis-group-add-chassis chg2 hv3 3 > +check ovn-nbctl ha-chassis-group-add-chassis chg2 hv4 4 > +AT_CHECK([ovn-nbctl ha-chassis-group-list], [0], [ignore]) > + > +AT_CHECK_UNQUOTED([ovn-nbctl ha-chassis-group-list $chg1uuid | grep chg1 | awk '{print $1}'], [0], [dnl > +$chg1uuid > +]) > +AT_CHECK([ovn-nbctl ha-chassis-group-list chg1 | awk '{print $2}' | grep chg], [0], [dnl > +(chg1) > +]) > +AT_CHECK([ovn-nbctl ha-chassis-group-list chg1 | awk '{print $2}' | grep -A1 hv1], [0], [dnl > +(hv1) > +1 > +]) > +AT_CHECK([ovn-nbctl ha-chassis-group-list chg1 | awk '{print $2}' | grep -A1 hv2], [0], [dnl > +(hv2) > +2 > +]) > + > +AT_CHECK_UNQUOTED([ovn-nbctl ha-chassis-group-list $chg2uuid | grep chg2 | awk '{print $1}'], [0], [dnl > +$chg2uuid > +]) > +AT_CHECK([ovn-nbctl ha-chassis-group-list chg2 | awk '{print $2}' | grep chg], [0], [dnl > +(chg2) > +]) > +AT_CHECK([ovn-nbctl ha-chassis-group-list chg2 | awk '{print $2}' | grep -A1 hv3], [0], [dnl > +(hv3) > +3 > +]) > +AT_CHECK([ovn-nbctl ha-chassis-group-list chg2 | awk '{print $2}' | grep -A1 hv4], [0], [dnl > +(hv4) > +4 > +]) > + > +AT_CHECK([ovn-nbctl ha-chassis-group-list negative], [1], [], [dnl > +ovn-nbctl: negative: ha_chassis_group name not found > +]) > +AT_CHECK([ovn-nbctl ha-chassis-group-list 11111111-1111-1111-1111-111111111111], [1], [], [dnl > +ovn-nbctl: 11111111-1111-1111-1111-111111111111: ha_chassis_group UUID not found > +]) > +OVN_NBCTL_TEST_STOP "/terminating with signal 15/d" > +AT_CLEANUP > diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml > index b4af43185..6f74bd557 100644 > --- a/utilities/ovn-nbctl.8.xml > +++ b/utilities/ovn-nbctl.8.xml > @@ -1466,10 +1466,12 @@ > <code>group</code> does not exist. > </dd> > > - <dt><code>ha-chassis-group-list</code></dt> > + <dt><code>ha-chassis-group-list</code> [<var>ha-chassis-group</var>]</dt> > <dd> > - Lists the HA chassis group <code>group</code> along with the > - <code>HA chassis</code> if any associated with it. > + Lists all HA chassis groups along with the <code>HA chassis</code> > + if any associated with it. > + If <var>ha-chassis-group</var> is also specified, then only the > + specified <var>ha-chassis-group</var> will be listed. > </dd> > > <dt><code>ha-chassis-group-add-chassis</code> <var>group</var> > diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c > index 444fbd2fe..9029e8133 100644 > --- a/utilities/ovn-nbctl.c > +++ b/utilities/ovn-nbctl.c > @@ -464,9 +464,9 @@ Port group commands:\n\ > pg-set-ports PG PORTS Set PORTS on port group PG\n\ > pg-del PG Delete port group PG\n\ > HA chassis group commands:\n\ > - ha-chassis-group-add GRP Create an HA chassis group GRP\n\ > - ha-chassis-group-del GRP Delete the HA chassis group GRP\n\ > - ha-chassis-group-list List the HA chassis groups\n\ > + ha-chassis-group-add GRP Create an HA chassis group GRP\n\ > + ha-chassis-group-del GRP Delete the HA chassis group GRP\n\ > + ha-chassis-group-list [GRP] Print the supplied HA chassis group or all if none supplied\n\ > ha-chassis-group-add-chassis GRP CHASSIS PRIORITY Adds an HA\ > chassis with mandatory PRIORITY to the HA chassis group GRP\n\ > ha-chassis-group-remove-chassis GRP CHASSIS Removes the HA chassis\ > @@ -7260,7 +7260,7 @@ ha_chassis_group_by_name_or_uuid(struct ctl_context *ctx, const char *id, > } > > if (!ha_ch_grp && must_exist) { > - ctx->error = xasprintf("%s: ha_chassi_group %s not found", > + ctx->error = xasprintf("%s: ha_chassis_group %s not found", > id, is_uuid ? "UUID" : "name"); > } > > @@ -7306,23 +7306,44 @@ pre_ha_ch_grp_list(struct ctl_context *ctx) > } > > static void > -cmd_ha_ch_grp_list(struct ctl_context *ctx) > +ha_ch_grp_info_print(struct ctl_context *ctx, const struct nbrec_ha_chassis_group *ha_ch_grp) > +{ > + ds_put_format(&ctx->output, UUID_FMT " (%s)\n", > + UUID_ARGS(&ha_ch_grp->header_.uuid), ha_ch_grp->name); > + const struct nbrec_ha_chassis *ha_ch; > + for (size_t i = 0; i < ha_ch_grp->n_ha_chassis; i++) { > + ha_ch = ha_ch_grp->ha_chassis[i]; > + ds_put_format(&ctx->output, > + " "UUID_FMT " (%s)\n" > + " priority %"PRId64"\n\n", > + UUID_ARGS(&ha_ch->header_.uuid), ha_ch->chassis_name, > + ha_ch->priority); > + } > + ds_put_cstr(&ctx->output, "\n"); > +} > + > +static void > +ha_ch_grp_list_all(struct ctl_context *ctx) > { > const struct nbrec_ha_chassis_group *ha_ch_grp; > > NBREC_HA_CHASSIS_GROUP_FOR_EACH (ha_ch_grp, ctx->idl) { > - ds_put_format(&ctx->output, UUID_FMT " (%s)\n", > - UUID_ARGS(&ha_ch_grp->header_.uuid), ha_ch_grp->name); > - const struct nbrec_ha_chassis *ha_ch; > - for (size_t i = 0; i < ha_ch_grp->n_ha_chassis; i++) { > - ha_ch = ha_ch_grp->ha_chassis[i]; > - ds_put_format(&ctx->output, > - " "UUID_FMT " (%s)\n" > - " priority %"PRId64"\n\n", > - UUID_ARGS(&ha_ch->header_.uuid), ha_ch->chassis_name, > - ha_ch->priority); > + ha_ch_grp_info_print(ctx, ha_ch_grp); > + } > +} > + > +static void > +cmd_ha_ch_grp_list(struct ctl_context *ctx) > +{ > + if (ctx->argc == 1) { > + ha_ch_grp_list_all(ctx); > + } else if (ctx->argc == 2) { > + const char *name_or_id = ctx->argv[1]; > + const struct nbrec_ha_chassis_group *ha_ch_grp = > + ha_chassis_group_by_name_or_uuid(ctx, name_or_id, true); > + if (ha_ch_grp) { > + ha_ch_grp_info_print(ctx, ha_ch_grp); > } > - ds_put_cstr(&ctx->output, "\n"); > } > } > > @@ -7966,7 +7987,7 @@ static const struct ctl_command_syntax nbctl_commands[] = { > NULL, cmd_ha_ch_grp_add, NULL, "", RW }, > {"ha-chassis-group-del", 1, 1, "[CHASSIS GROUP]", > pre_ha_ch_grp_del, cmd_ha_ch_grp_del, NULL, "", RW }, > - {"ha-chassis-group-list", 0, 0, "[CHASSIS GROUP]", > + {"ha-chassis-group-list", 0, 1, "[CHASSIS GROUP]", > pre_ha_ch_grp_list, cmd_ha_ch_grp_list, NULL, "", RO }, > {"ha-chassis-group-add-chassis", 3, 3, "[CHASSIS GROUP]", > pre_ha_ch_grp_add_chassis, cmd_ha_ch_grp_add_chassis, NULL, "", RW }, > -- > 2.34.1 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev >
diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index fde3a28ee..7206d1fe5 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -2741,3 +2741,56 @@ cp $PKIDIR/$cert $cert OVS_WAIT_UNTIL([ovn-appctl -t ovn-nbctl run show]) AT_CLEANUP + +dnl --------------------------------------------------------------------- + +AT_SETUP([ovn-nbctl - ha-chassis-group-list group]) +OVN_NBCTL_TEST_START daemon +check ovn-nbctl ha-chassis-group-add chg1 +chg1uuid=$(fetch_column nb:HA_Chassis_Group _uuid name=chg1) +check ovn-nbctl ha-chassis-group-add chg2 +chg2uuid=$(fetch_column nb:HA_Chassis_Group _uuid name=chg2) +check ovn-nbctl ha-chassis-group-add-chassis chg1 hv1 1 +check ovn-nbctl ha-chassis-group-add-chassis chg1 hv2 2 +check ovn-nbctl ha-chassis-group-add-chassis chg2 hv3 3 +check ovn-nbctl ha-chassis-group-add-chassis chg2 hv4 4 +AT_CHECK([ovn-nbctl ha-chassis-group-list], [0], [ignore]) + +AT_CHECK_UNQUOTED([ovn-nbctl ha-chassis-group-list $chg1uuid | grep chg1 | awk '{print $1}'], [0], [dnl +$chg1uuid +]) +AT_CHECK([ovn-nbctl ha-chassis-group-list chg1 | awk '{print $2}' | grep chg], [0], [dnl +(chg1) +]) +AT_CHECK([ovn-nbctl ha-chassis-group-list chg1 | awk '{print $2}' | grep -A1 hv1], [0], [dnl +(hv1) +1 +]) +AT_CHECK([ovn-nbctl ha-chassis-group-list chg1 | awk '{print $2}' | grep -A1 hv2], [0], [dnl +(hv2) +2 +]) + +AT_CHECK_UNQUOTED([ovn-nbctl ha-chassis-group-list $chg2uuid | grep chg2 | awk '{print $1}'], [0], [dnl +$chg2uuid +]) +AT_CHECK([ovn-nbctl ha-chassis-group-list chg2 | awk '{print $2}' | grep chg], [0], [dnl +(chg2) +]) +AT_CHECK([ovn-nbctl ha-chassis-group-list chg2 | awk '{print $2}' | grep -A1 hv3], [0], [dnl +(hv3) +3 +]) +AT_CHECK([ovn-nbctl ha-chassis-group-list chg2 | awk '{print $2}' | grep -A1 hv4], [0], [dnl +(hv4) +4 +]) + +AT_CHECK([ovn-nbctl ha-chassis-group-list negative], [1], [], [dnl +ovn-nbctl: negative: ha_chassis_group name not found +]) +AT_CHECK([ovn-nbctl ha-chassis-group-list 11111111-1111-1111-1111-111111111111], [1], [], [dnl +ovn-nbctl: 11111111-1111-1111-1111-111111111111: ha_chassis_group UUID not found +]) +OVN_NBCTL_TEST_STOP "/terminating with signal 15/d" +AT_CLEANUP diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml index b4af43185..6f74bd557 100644 --- a/utilities/ovn-nbctl.8.xml +++ b/utilities/ovn-nbctl.8.xml @@ -1466,10 +1466,12 @@ <code>group</code> does not exist. </dd> - <dt><code>ha-chassis-group-list</code></dt> + <dt><code>ha-chassis-group-list</code> [<var>ha-chassis-group</var>]</dt> <dd> - Lists the HA chassis group <code>group</code> along with the - <code>HA chassis</code> if any associated with it. + Lists all HA chassis groups along with the <code>HA chassis</code> + if any associated with it. + If <var>ha-chassis-group</var> is also specified, then only the + specified <var>ha-chassis-group</var> will be listed. </dd> <dt><code>ha-chassis-group-add-chassis</code> <var>group</var> diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 444fbd2fe..9029e8133 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -464,9 +464,9 @@ Port group commands:\n\ pg-set-ports PG PORTS Set PORTS on port group PG\n\ pg-del PG Delete port group PG\n\ HA chassis group commands:\n\ - ha-chassis-group-add GRP Create an HA chassis group GRP\n\ - ha-chassis-group-del GRP Delete the HA chassis group GRP\n\ - ha-chassis-group-list List the HA chassis groups\n\ + ha-chassis-group-add GRP Create an HA chassis group GRP\n\ + ha-chassis-group-del GRP Delete the HA chassis group GRP\n\ + ha-chassis-group-list [GRP] Print the supplied HA chassis group or all if none supplied\n\ ha-chassis-group-add-chassis GRP CHASSIS PRIORITY Adds an HA\ chassis with mandatory PRIORITY to the HA chassis group GRP\n\ ha-chassis-group-remove-chassis GRP CHASSIS Removes the HA chassis\ @@ -7260,7 +7260,7 @@ ha_chassis_group_by_name_or_uuid(struct ctl_context *ctx, const char *id, } if (!ha_ch_grp && must_exist) { - ctx->error = xasprintf("%s: ha_chassi_group %s not found", + ctx->error = xasprintf("%s: ha_chassis_group %s not found", id, is_uuid ? "UUID" : "name"); } @@ -7306,23 +7306,44 @@ pre_ha_ch_grp_list(struct ctl_context *ctx) } static void -cmd_ha_ch_grp_list(struct ctl_context *ctx) +ha_ch_grp_info_print(struct ctl_context *ctx, const struct nbrec_ha_chassis_group *ha_ch_grp) +{ + ds_put_format(&ctx->output, UUID_FMT " (%s)\n", + UUID_ARGS(&ha_ch_grp->header_.uuid), ha_ch_grp->name); + const struct nbrec_ha_chassis *ha_ch; + for (size_t i = 0; i < ha_ch_grp->n_ha_chassis; i++) { + ha_ch = ha_ch_grp->ha_chassis[i]; + ds_put_format(&ctx->output, + " "UUID_FMT " (%s)\n" + " priority %"PRId64"\n\n", + UUID_ARGS(&ha_ch->header_.uuid), ha_ch->chassis_name, + ha_ch->priority); + } + ds_put_cstr(&ctx->output, "\n"); +} + +static void +ha_ch_grp_list_all(struct ctl_context *ctx) { const struct nbrec_ha_chassis_group *ha_ch_grp; NBREC_HA_CHASSIS_GROUP_FOR_EACH (ha_ch_grp, ctx->idl) { - ds_put_format(&ctx->output, UUID_FMT " (%s)\n", - UUID_ARGS(&ha_ch_grp->header_.uuid), ha_ch_grp->name); - const struct nbrec_ha_chassis *ha_ch; - for (size_t i = 0; i < ha_ch_grp->n_ha_chassis; i++) { - ha_ch = ha_ch_grp->ha_chassis[i]; - ds_put_format(&ctx->output, - " "UUID_FMT " (%s)\n" - " priority %"PRId64"\n\n", - UUID_ARGS(&ha_ch->header_.uuid), ha_ch->chassis_name, - ha_ch->priority); + ha_ch_grp_info_print(ctx, ha_ch_grp); + } +} + +static void +cmd_ha_ch_grp_list(struct ctl_context *ctx) +{ + if (ctx->argc == 1) { + ha_ch_grp_list_all(ctx); + } else if (ctx->argc == 2) { + const char *name_or_id = ctx->argv[1]; + const struct nbrec_ha_chassis_group *ha_ch_grp = + ha_chassis_group_by_name_or_uuid(ctx, name_or_id, true); + if (ha_ch_grp) { + ha_ch_grp_info_print(ctx, ha_ch_grp); } - ds_put_cstr(&ctx->output, "\n"); } } @@ -7966,7 +7987,7 @@ static const struct ctl_command_syntax nbctl_commands[] = { NULL, cmd_ha_ch_grp_add, NULL, "", RW }, {"ha-chassis-group-del", 1, 1, "[CHASSIS GROUP]", pre_ha_ch_grp_del, cmd_ha_ch_grp_del, NULL, "", RW }, - {"ha-chassis-group-list", 0, 0, "[CHASSIS GROUP]", + {"ha-chassis-group-list", 0, 1, "[CHASSIS GROUP]", pre_ha_ch_grp_list, cmd_ha_ch_grp_list, NULL, "", RO }, {"ha-chassis-group-add-chassis", 3, 3, "[CHASSIS GROUP]", pre_ha_ch_grp_add_chassis, cmd_ha_ch_grp_add_chassis, NULL, "", RW },
This commit adds support for optional ha-chassis-group argument to ha-chassis-group-list command to show one record. Also add few tests to validate output from ha-chassis-group-list. Signed-off-by: Evgenii Kovalev <ekovalev.off@gmail.com> --- tests/ovn-nbctl.at | 53 +++++++++++++++++++++++++++++++++++++ utilities/ovn-nbctl.8.xml | 8 +++--- utilities/ovn-nbctl.c | 55 +++++++++++++++++++++++++++------------ 3 files changed, 96 insertions(+), 20 deletions(-)