]> git.proxmox.com Git - ovs.git/commitdiff
ovn-nbctl: Don't die in pg_by_name_or_uuid().
authorJakub Sitnicki <jkbs@redhat.com>
Tue, 17 Jul 2018 13:34:05 +0000 (15:34 +0200)
committerBen Pfaff <blp@ovn.org>
Mon, 23 Jul 2018 22:27:57 +0000 (15:27 -0700)
Let the caller handle the error. This prepares us for reporting errors
in daemon mode.

Also, extend the tests to cover this error path.

Signed-off-by: Jakub Sitnicki <jkbs@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
ovn/utilities/ovn-nbctl.c
tests/ovn-nbctl.at

index d075246973ae2f9658deec81a358840b1d5cd4e8..0cd11e845040bad949af9fed9ef86315424a5df1 100644 (file)
@@ -609,10 +609,12 @@ lb_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
     return NULL;
 }
 
-static const struct nbrec_port_group *
-pg_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist)
+static char * OVS_WARN_UNUSED_RESULT
+pg_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
+                   const struct nbrec_port_group **pg_p)
 {
     const struct nbrec_port_group *pg = NULL;
+    *pg_p = NULL;
 
     struct uuid pg_uuid;
     bool is_uuid = uuid_from_string(&pg_uuid, id);
@@ -632,11 +634,12 @@ pg_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist)
     }
 
     if (!pg && must_exist) {
-        ctl_fatal("%s: port group %s not found", id,
-                  is_uuid ? "UUID" : "name");
+        return xasprintf("%s: port group %s not found", id,
+                         is_uuid ? "UUID" : "name");
     }
 
-    return pg;
+    *pg_p = pg;
+    return NULL;
 }
 
 static void
@@ -1559,7 +1562,10 @@ acl_cmd_get_pg_or_ls(struct ctl_context *ctx,
     char *error;
 
     if (!opt_type) {
-        *pg = pg_by_name_or_uuid(ctx, ctx->argv[1], false);
+        error = pg_by_name_or_uuid(ctx, ctx->argv[1], false, pg);
+        if (error) {
+            return error;
+        }
         error = ls_by_name_or_uuid(ctx, ctx->argv[1], false, ls);
         if (error) {
             return error;
@@ -1574,7 +1580,10 @@ acl_cmd_get_pg_or_ls(struct ctl_context *ctx,
                              ctx->argv[1]);
         }
     } else if (!strcmp(opt_type, "port-group")) {
-        *pg = pg_by_name_or_uuid(ctx, ctx->argv[1], true);
+        error = pg_by_name_or_uuid(ctx, ctx->argv[1], true, pg);
+        if (error) {
+            return error;
+        }
         *ls = NULL;
     } else if (!strcmp(opt_type, "switch")) {
         error = ls_by_name_or_uuid(ctx, ctx->argv[1], true, ls);
index 73a61a4be0b72e1318d6f1cdd8236337e60cfffc..9f6a2783b9c39312f4f1bb3b7382e408b1f94d21 100644 (file)
@@ -234,6 +234,11 @@ OVN_NBCTL_TEST_ACL([ls1], [--type=switch])
 AT_CHECK([ovn-nbctl create port_group name=pg0], [0], [ignore])
 OVN_NBCTL_TEST_ACL([pg0], [--type=port-group])
 
+dnl Test when port group doesn't exist
+AT_CHECK([ovn-nbctl --type=port-group acl-add pg1 to-lport 100 ip drop], [1], [], [dnl
+ovn-nbctl: pg1: port group name not found
+])
+
 dnl Test when same name exists in logical switches and portgroups
 AT_CHECK([ovn-nbctl create port_group name=ls0], [0], [ignore])
 AT_CHECK([ovn-nbctl acl-add ls0 to-lport 100 ip drop], [1], [], [stderr])