ovs-vsctl: Allow referring to rows whose names are UUIDs by those names.
authorBen Pfaff <blp@nicira.com>
Wed, 29 Oct 2014 21:11:07 +0000 (14:11 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 29 Oct 2014 21:45:20 +0000 (14:45 -0700)
Every row in the database has a UUID, generated by the database server.
Rows in most tables also have a user-assigned name (e.g. a bridge or port
or interface name).  The ovs-vsctl database commands (e.g. "set", "get",
"list", ...) accept both UUIDs and names, but until now if a command's
argument had the form of a UUID, then it had to be the database-assigned
UUID for a row; that is, ovs-vsctl did not check whether it was the name
of a row.  This commit changes that: a UUID argument to a database command
is now first checked against database UUIDs then, if it is not a database
UUID, it is checked as the name of a row.

This is prompted by Windows integration with OpenStack, which uses UUIDs
as port names.

CC: Nithin Raju <nithin@vmware.com>
Requested-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Gurucharan Shetty <gshetty@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
tests/ovs-vsctl.at
utilities/ovs-vsctl.c

index 2f83566..fe65aed 100644 (file)
@@ -1285,3 +1285,21 @@ AT_CHECK([sed "/|bridge|WARN|/d" ovs-vswitchd.log > ovs-vswitchd.log], [0], [],
 AT_CHECK([ovs-vsctl del-port br0 reserved_name], [0], [], [])])
 OVS_VSWITCHD_STOP
 AT_CLEANUP
+
+AT_SETUP([naming in db commands])
+OVS_VSCTL_SETUP
+
+dnl First check that the database commands can refer to row by database UUID.
+AT_CHECK([RUN_OVS_VSCTL([add-br br0])])
+uuid=`[]RUN_OVS_VSCTL(get port br0 _uuid)`
+AT_CHECK([RUN_OVS_VSCTL([get port $uuid name])], [0], ["br0"
+])
+
+dnl Next check that, if a database row is given a name that has the same form
+dnl as the database UUIDs, the name can still be used to refer to rows.
+AT_CHECK([RUN_OVS_VSCTL([add-br 0fcd11a1-2ba8-4b38-a358-4bccf2bf3057])])
+AT_CHECK([RUN_OVS_VSCTL([get interface 0fcd11a1-2ba8-4b38-a358-4bccf2bf3057 type])], [0], [internal
+])
+
+OVS_VSCTL_CLEANUP
+AT_CLEANUP
index 270d9bf..8ac6d10 100644 (file)
@@ -2744,9 +2744,11 @@ get_row (struct vsctl_context *ctx,
     const struct ovsdb_idl_row *row;
     struct uuid uuid;
 
+    row = NULL;
     if (uuid_from_string(&uuid, record_id)) {
         row = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class, &uuid);
-    } else {
+    }
+    if (!row) {
         int i;
 
         for (i = 0; i < ARRAY_SIZE(table->row_ids); i++) {