diff mbox

[ovs-dev,PATCHv2] ovn-nbctl: Sort output of most commands.

Message ID 1441398119-39465-1-git-send-email-jpettit@nicira.com
State Accepted
Headers show

Commit Message

Justin Pettit Sept. 4, 2015, 8:21 p.m. UTC
This will be helpful for unit tests.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
---
v1->v2: Actually sort the macs and port security addresses.
---
 ovn/utilities/ovn-nbctl.c |   51 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 44 insertions(+), 7 deletions(-)

Comments

Ben Pfaff Sept. 4, 2015, 8:28 p.m. UTC | #1
On Fri, Sep 04, 2015 at 01:21:59PM -0700, Justin Pettit wrote:
> This will be helpful for unit tests.
> 
> Signed-off-by: Justin Pettit <jpettit@nicira.com>
> ---
> v1->v2: Actually sort the macs and port security addresses.

Acked-by: Ben Pfaff <blp@nicira.com>
Justin Pettit Sept. 4, 2015, 9:30 p.m. UTC | #2
> On Sep 4, 2015, at 1:28 PM, Ben Pfaff <blp@nicira.com> wrote:
> 
> On Fri, Sep 04, 2015 at 01:21:59PM -0700, Justin Pettit wrote:
>> This will be helpful for unit tests.
>> 
>> Signed-off-by: Justin Pettit <jpettit@nicira.com>
>> ---
>> v1->v2: Actually sort the macs and port security addresses.
> 
> Acked-by: Ben Pfaff <blp@nicira.com>

Thanks.  I pushed the series.

--Justin
diff mbox

Patch

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 0bdb3a3..d095df1 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -25,8 +25,10 @@ 
 #include "ovn/lib/ovn-nb-idl.h"
 #include "poll-loop.h"
 #include "process.h"
+#include "smap.h"
 #include "stream.h"
 #include "stream-ssl.h"
+#include "svec.h"
 #include "util.h"
 #include "openvswitch/vlog.h"
 
@@ -217,11 +219,20 @@  do_lswitch_list(struct ovs_cmdl_context *ctx)
 {
     struct nbctl_context *nb_ctx = ctx->pvt;
     const struct nbrec_logical_switch *lswitch;
+    struct smap lswitches;
 
+    smap_init(&lswitches);
     NBREC_LOGICAL_SWITCH_FOR_EACH(lswitch, nb_ctx->idl) {
-        printf(UUID_FMT " (%s)\n",
-               UUID_ARGS(&lswitch->header_.uuid), lswitch->name);
+        smap_add_format(&lswitches, lswitch->name, UUID_FMT " (%s)",
+                        UUID_ARGS(&lswitch->header_.uuid), lswitch->name);
     }
+    const struct smap_node **nodes = smap_sort(&lswitches);
+    for (size_t i = 0; i < smap_count(&lswitches); i++) {
+        const struct smap_node *node = nodes[i];
+        printf("%s\n", node->value);
+    }
+    smap_destroy(&lswitches);
+    free(nodes);
 }
 
 static void
@@ -408,17 +419,27 @@  do_lport_list(struct ovs_cmdl_context *ctx)
     struct nbctl_context *nb_ctx = ctx->pvt;
     const char *id = ctx->argv[1];
     const struct nbrec_logical_switch *lswitch;
+    struct smap lports;
+    size_t i;
 
     lswitch = lswitch_by_name_or_uuid(nb_ctx, id);
     if (!lswitch) {
         return;
     }
 
-    for (size_t i = 0; i < lswitch->n_ports; i++) {
+    smap_init(&lports);
+    for (i = 0; i < lswitch->n_ports; i++) {
         const struct nbrec_logical_port *lport = lswitch->ports[i];
-        printf(UUID_FMT " (%s)\n",
-               UUID_ARGS(&lport->header_.uuid), lport->name);
+        smap_add_format(&lports, lport->name, UUID_FMT " (%s)",
+                        UUID_ARGS(&lport->header_.uuid), lport->name);
     }
+    const struct smap_node **nodes = smap_sort(&lports);
+    for (i = 0; i < smap_count(&lports); i++) {
+        const struct smap_node *node = nodes[i];
+        printf("%s\n", node->value);
+    }
+    smap_destroy(&lports);
+    free(nodes);
 }
 
 static void
@@ -532,6 +553,8 @@  do_lport_get_macs(struct ovs_cmdl_context *ctx)
     struct nbctl_context *nb_ctx = ctx->pvt;
     const char *id = ctx->argv[1];
     const struct nbrec_logical_port *lport;
+    struct svec macs;
+    const char *mac;
     size_t i;
 
     lport = lport_by_name_or_uuid(nb_ctx, id);
@@ -539,9 +562,15 @@  do_lport_get_macs(struct ovs_cmdl_context *ctx)
         return;
     }
 
+    svec_init(&macs);
     for (i = 0; i < lport->n_macs; i++) {
-        printf("%s\n", lport->macs[i]);
+        svec_add(&macs, lport->macs[i]);
+    }
+    svec_sort(&macs);
+    SVEC_FOR_EACH(i, mac, &macs) {
+        printf("%s\n", mac);
     }
+    svec_destroy(&macs);
 }
 
 static void
@@ -566,6 +595,8 @@  do_lport_get_port_security(struct ovs_cmdl_context *ctx)
     struct nbctl_context *nb_ctx = ctx->pvt;
     const char *id = ctx->argv[1];
     const struct nbrec_logical_port *lport;
+    struct svec addrs;
+    const char *addr;
     size_t i;
 
     lport = lport_by_name_or_uuid(nb_ctx, id);
@@ -573,9 +604,15 @@  do_lport_get_port_security(struct ovs_cmdl_context *ctx)
         return;
     }
 
+    svec_init(&addrs);
     for (i = 0; i < lport->n_port_security; i++) {
-        printf("%s\n", lport->port_security[i]);
+        svec_add(&addrs, lport->port_security[i]);
+    }
+    svec_sort(&addrs);
+    SVEC_FOR_EACH(i, addr, &addrs) {
+        printf("%s\n", addr);
     }
+    svec_destroy(&addrs);
 }
 
 static void