[ovs-dev,3/4] ovn-nbctl: Sort output of most commands.
diff mbox

Message ID 1441316822-60290-3-git-send-email-jpettit@nicira.com
State Accepted
Headers show

Commit Message

Justin Pettit Sept. 3, 2015, 9:47 p.m. UTC
This will be helpful for unit tests.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
---
 ovn/utilities/ovn-nbctl.c |   49 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 42 insertions(+), 7 deletions(-)

Comments

Ben Pfaff Sept. 4, 2015, 5:54 p.m. UTC | #1
On Thu, Sep 03, 2015 at 02:47:01PM -0700, Justin Pettit wrote:
> This will be helpful for unit tests.
> 
> Signed-off-by: Justin Pettit <jpettit@nicira.com>

I don't understand why this commit changes do_lport_get_macs() and
do_lport_get_port_security(), since the changes appear to be no-ops.
Did you omit the code to sort them?
Justin Pettit Sept. 4, 2015, 8:12 p.m. UTC | #2
> On Sep 4, 2015, at 10:54 AM, Ben Pfaff <blp@nicira.com> wrote:
> 
> On Thu, Sep 03, 2015 at 02:47:01PM -0700, Justin Pettit wrote:
>> This will be helpful for unit tests.
>> 
>> Signed-off-by: Justin Pettit <jpettit@nicira.com>
> 
> I don't understand why this commit changes do_lport_get_macs() and
> do_lport_get_port_security(), since the changes appear to be no-ops.
> Did you omit the code to sort them?

D'oh.  Forgot to call svec_sort().  I'll send out a v2 in a minute.

--Justin

Patch
diff mbox

diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 0bdb3a3..aac7be1 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,14 @@  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_FOR_EACH(i, mac, &macs) {
+        printf("%s\n", mac);
     }
+    svec_destroy(&macs);
 }
 
 static void
@@ -566,6 +594,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 +603,14 @@  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_FOR_EACH(i, addr, &addrs) {
+        printf("%s\n", addr);
     }
+    svec_destroy(&addrs);
 }
 
 static void