[ovs-dev,v2] OVN: show gw chassis in decreasing prio order
diff mbox series

Message ID 559fc380eb1ad741b6d8cf393b6ec223cdf35d3e.1524752270.git.lorenzo.bianconi@redhat.com
State Accepted
Headers show
Series
  • [ovs-dev,v2] OVN: show gw chassis in decreasing prio order
Related show

Commit Message

Lorenzo Bianconi April 26, 2018, 2:35 p.m. UTC
Report gateway chassis in decreasing priority order running ovn-nbctl
show sub-command. Add get_ordered_gw_chassis_prio_list routine to sort
gw chassis according to the configured priority

Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
Changes since v1:
- added test case to ovn-nbctl.at
---
 ovn/utilities/ovn-nbctl.c | 64 +++++++++++++++++++++++++++++------------------
 tests/ovn-nbctl.at        |  9 +++++++
 2 files changed, 48 insertions(+), 25 deletions(-)

Comments

Ben Pfaff May 9, 2018, 9:38 p.m. UTC | #1
On Thu, Apr 26, 2018 at 04:35:46PM +0200, Lorenzo Bianconi wrote:
> Report gateway chassis in decreasing priority order running ovn-nbctl
> show sub-command. Add get_ordered_gw_chassis_prio_list routine to sort
> gw chassis according to the configured priority
> 
> Acked-by: Mark Michelson <mmichels@redhat.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
> Changes since v1:
> - added test case to ovn-nbctl.at

Thanks, applied to master.

Patch
diff mbox series

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 86013fa2e..05d783c7b 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -607,6 +607,38 @@  print_alias(const struct smap *external_ids, const char *key, struct ds *s)
     }
 }
 
+/* gateway_chassis ordering
+ *  */
+static int
+compare_chassis_prio_(const void *gc1_, const void *gc2_)
+{
+    const struct nbrec_gateway_chassis *const *gc1p = gc1_;
+    const struct nbrec_gateway_chassis *const *gc2p = gc2_;
+    const struct nbrec_gateway_chassis *gc1 = *gc1p;
+    const struct nbrec_gateway_chassis *gc2 = *gc2p;
+
+    int prio_diff = gc2->priority - gc1->priority;
+    if (!prio_diff) {
+        return strcmp(gc2->name, gc1->name);
+    }
+    return prio_diff;
+}
+
+static const struct nbrec_gateway_chassis **
+get_ordered_gw_chassis_prio_list(const struct nbrec_logical_router_port *lrp)
+{
+    const struct nbrec_gateway_chassis **gcs;
+    int i;
+
+    gcs = xmalloc(sizeof *gcs * lrp->n_gateway_chassis);
+    for (i = 0; i < lrp->n_gateway_chassis; i++) {
+        gcs[i] = lrp->gateway_chassis[i];
+    }
+
+    qsort(gcs, lrp->n_gateway_chassis, sizeof *gcs, compare_chassis_prio_);
+    return gcs;
+}
+
 /* Given pointer to logical router, this routine prints the router
  * information.  */
 static void
@@ -635,12 +667,17 @@  print_lr(const struct nbrec_logical_router *lr, struct ds *s)
         }
 
         if (lrp->n_gateway_chassis) {
+            const struct nbrec_gateway_chassis **gcs;
+
+            gcs = get_ordered_gw_chassis_prio_list(lrp);
             ds_put_cstr(s, "        gateway chassis: [");
             for (size_t j = 0; j < lrp->n_gateway_chassis; j++) {
-                ds_put_format(s, "%s ", lrp->gateway_chassis[j]->chassis_name);
+                const struct nbrec_gateway_chassis *gc = gcs[j];
+                ds_put_format(s, "%s ", gc->chassis_name);
             }
             ds_chomp(s, ' ');
             ds_put_cstr(s, "]\n");
+            free(gcs);
         }
     }
 
@@ -3021,23 +3058,6 @@  nbctl_lrp_del_gateway_chassis(struct ctl_context *ctx)
               chassis_name, ctx->argv[1]);
 }
 
-/* gateway_chassis ordering
- *  */
-static int
-compare_chassis_prio_(const void *gc1_, const void *gc2_)
-{
-    const struct nbrec_gateway_chassis *const *gc1p = gc1_;
-    const struct nbrec_gateway_chassis *const *gc2p = gc2_;
-    const struct nbrec_gateway_chassis *gc1 = *gc1p;
-    const struct nbrec_gateway_chassis *gc2 = *gc2p;
-
-    int prio_diff = gc2->priority - gc1->priority;
-    if (!prio_diff) {
-        return strcmp(gc2->name, gc1->name);
-    }
-    return prio_diff;
-}
-
 /* Print a list of gateway chassis. */
 static void
 nbctl_lrp_get_gateway_chassis(struct ctl_context *ctx)
@@ -3048,13 +3068,7 @@  nbctl_lrp_get_gateway_chassis(struct ctl_context *ctx)
     size_t i;
 
     lrp = lrp_by_name_or_uuid(ctx, id, true);
-
-    gcs = xmalloc(sizeof *gcs * lrp->n_gateway_chassis);
-    for (i = 0; i < lrp->n_gateway_chassis; i++) {
-        gcs[i] = lrp->gateway_chassis[i];
-    }
-
-    qsort(gcs, lrp->n_gateway_chassis, sizeof *gcs, compare_chassis_prio_);
+    gcs = get_ordered_gw_chassis_prio_list(lrp);
 
     for (i = 0; i < lrp->n_gateway_chassis; i++) {
         const struct nbrec_gateway_chassis *gc = gcs[i];
diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at
index 514e7e7d2..e1e81732a 100644
--- a/tests/ovn-nbctl.at
+++ b/tests/ovn-nbctl.at
@@ -1127,6 +1127,15 @@  lrp0-chassis2     5
 AT_CHECK([ovn-nbctl lrp-del-gateway-chassis lrp0 chassis2])
 AT_CHECK([ovn-nbctl lrp-get-gateway-chassis lrp0])
 
+AT_CHECK([ovn-nbctl lrp-set-gateway-chassis lrp0 chassis1 1])
+AT_CHECK([ovn-nbctl lrp-set-gateway-chassis lrp0 chassis2 10])
+AT_CHECK([ovn-nbctl lrp-set-gateway-chassis lrp0 chassis3 5])
+AT_CHECK([ovn-nbctl lrp-get-gateway-chassis lrp0], [0], [dnl
+lrp0-chassis2    10
+lrp0-chassis3     5
+lrp0-chassis1     1
+])
+
 OVN_NBCTL_TEST_STOP
 AT_CLEANUP