ovs-vsctl: Improve error message for "ovs-vsctl del-port <bridge>".
authorBen Pfaff <blp@nicira.com>
Wed, 19 Jun 2013 04:01:33 +0000 (21:01 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 20 Jun 2013 06:04:41 +0000 (23:04 -0700)
Previously, commands like this:
    ovs-vsctl add-br br0
    ovs-vsctl del-port br0
yielded an error message like:
    no port named br0
which is confusing.  This commit improves the error message to:
    cannot delete port br0 because it is the local port for bridge br0
    (deleting this port requires deleting the entire bridge)

Bug #17994.
Reported-by: Reid Price <reid@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
tests/ovs-vsctl.at
utilities/ovs-vsctl.c

index ec08cd4..fa2c3ff 100644 (file)
@@ -323,6 +323,10 @@ AT_CHECK([RUN_OVS_VSCTL(
 ], [], [OVS_VSCTL_CLEANUP])
 AT_CHECK([RUN_OVS_VSCTL([--may-exist add-port b b1])], [0], [], [],
   [OVS_VSCTL_CLEANUP])
+AT_CHECK([RUN_OVS_VSCTL([del-port a])], [1], [],
+  [ovs-vsctl: cannot delete port a because it is the local port for bridge a (deleting this port requires deleting the entire bridge)
+],
+  [OVS_VSCTL_CLEANUP])
 AT_CHECK([RUN_OVS_VSCTL([--may-exist add-port a b1])], [1], [],
   [ovs-vsctl: "--may-exist add-port a b1" but b1 is actually attached to bridge b
 ],
@@ -1246,4 +1250,4 @@ AT_CHECK([sed "/|bridge|WARN|/d" ovs-vswitchd.log > ovs-vswitchd.log], [0], [],
 # Delete the port
 AT_CHECK([ovs-vsctl del-port br0 reserved_name], [0], [], [])])
 OVS_VSWITCHD_STOP
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
index 19ab472..2d8c7c7 100644 (file)
@@ -2016,13 +2016,17 @@ cmd_del_port(struct vsctl_context *ctx)
 {
     bool must_exist = !shash_find(&ctx->options, "--if-exists");
     bool with_iface = shash_find(&ctx->options, "--with-iface") != NULL;
+    const char *target = ctx->argv[ctx->argc - 1];
     struct vsctl_port *port;
 
     vsctl_context_populate_cache(ctx);
-    if (!with_iface) {
-        port = find_port(ctx, ctx->argv[ctx->argc - 1], must_exist);
+    if (find_bridge(ctx, target, false)) {
+        vsctl_fatal("cannot delete port %s because it is the local port "
+                    "for bridge %s (deleting this port requires deleting "
+                    "the entire bridge)", target, target);
+    } else if (!with_iface) {
+        port = find_port(ctx, target, must_exist);
     } else {
-        const char *target = ctx->argv[ctx->argc - 1];
         struct vsctl_iface *iface;
 
         port = find_port(ctx, target, false);