Re: [ovs-dev] [PATCH 02/13] log: Require log entries to be JSON objects.

2017-12-22 Thread Justin Pettit

> On Dec 7, 2017, at 4:12 PM, Ben Pfaff  wrote:
> 
> The current and upcoming users of the OVSDB logging module only use
> JSON objects as records.  This commit simplifies the users slightly
> by allowing them to always assume that the records are JSON objects.
> 
> Unfortunately this resulted in a large number of updates to tests,
> which didn't always use JSON objects.
> 
> Signed-off-by: Ben Pfaff 

Acked-by: Justin Pettit 

--Justin


___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH 02/13] log: Require log entries to be JSON objects.

2017-12-07 Thread Ben Pfaff
The current and upcoming users of the OVSDB logging module only use
JSON objects as records.  This commit simplifies the users slightly
by allowing them to always assume that the records are JSON objects.

Unfortunately this resulted in a large number of updates to tests,
which didn't always use JSON objects.

Signed-off-by: Ben Pfaff 
---
 ovsdb/log.c|  17 +
 tests/ovsdb-log.at | 212 ++---
 2 files changed, 123 insertions(+), 106 deletions(-)

diff --git a/ovsdb/log.c b/ovsdb/log.c
index e6f66e668fe5..d9fedd9ded6c 100644
--- a/ovsdb/log.c
+++ b/ovsdb/log.c
@@ -254,6 +254,16 @@ parse_body(struct ovsdb_log *file, off_t offset, unsigned 
long int length,
 return NULL;
 }
 
+/* Attempts to read a log record from 'file'.
+ *
+ * If successful, returns NULL and stores in '*jsonp' the JSON object that the
+ * record contains.  The caller owns the data and must eventually free it (with
+ * json_destroy()).
+ *
+ * If a read error occurs, returns the error and stores NULL in '*jsonp'.
+ *
+ * If the read reaches end of file, returns NULL and stores NULL in
+ * '*jsonp'. */
 struct ovsdb_error *
 ovsdb_log_read(struct ovsdb_log *file, struct json **jsonp)
 {
@@ -315,6 +325,13 @@ ovsdb_log_read(struct ovsdb_log *file, struct json **jsonp)
json->u.string);
 goto error;
 }
+if (json->type != JSON_OBJECT) {
+error = ovsdb_syntax_error(NULL, NULL, "%s: %lu bytes starting at "
+   "offset %lld are not a JSON object",
+   file->name, data_length,
+   (long long int) data_offset);
+goto error;
+}
 
 file->prev_offset = file->offset;
 file->offset = data_offset + data_length;
diff --git a/tests/ovsdb-log.at b/tests/ovsdb-log.at
index c8efaaec1a50..29c0c5913c15 100644
--- a/tests/ovsdb-log.at
+++ b/tests/ovsdb-log.at
@@ -19,14 +19,14 @@ AT_SETUP([write one, reread])
 AT_KEYWORDS([ovsdb log])
 AT_CAPTURE_FILE([file])
 AT_CHECK(
-  [[test-ovsdb log-io file create 'write:[0]']], [0], 
+  [[test-ovsdb log-io file create 'write:{"x":0}']], [0],
   [[file: open successful
-file: write:[0] successful
+file: write:{"x":0} successful
 ]], [ignore])
 AT_CHECK(
   [test-ovsdb log-io file read-only read read], [0], 
   [[file: open successful
-file: read: [0]
+file: read: {"x":0}
 file: read: end of log
 ]], [ignore])
 AT_CHECK([test -f .file.~lock~])
@@ -36,14 +36,14 @@ AT_SETUP([check that create fails if file exists])
 AT_KEYWORDS([ovsdb log])
 AT_CAPTURE_FILE([file])
 AT_CHECK(
-  [[test-ovsdb log-io file create 'write:[1]']], [0], 
+  [[test-ovsdb log-io file create 'write:{"x":1}']], [0],
   [[file: open successful
-file: write:[1] successful
+file: write:{"x":1} successful
 ]], [ignore])
 AT_CHECK(
   [test-ovsdb log-io file read-only read], [0], 
   [[file: open successful
-file: read: [1]
+file: read: {"x":1}
 ]], [ignore])
 AT_CHECK(
   [test-ovsdb log-io file create read], [1],
@@ -56,18 +56,18 @@ AT_SETUP([write one, reread])
 AT_KEYWORDS([ovsdb log])
 AT_CAPTURE_FILE([file])
 AT_CHECK(
-  [[test-ovsdb log-io file create 'write:[0]' 'write:[1]' 'write:[2]']], [0], 
+  [[test-ovsdb log-io file create 'write:{"x":0}' 'write:{"x":1}' 
'write:{"x":2}']], [0],
   [[file: open successful
-file: write:[0] successful
-file: write:[1] successful
-file: write:[2] successful
+file: write:{"x":0} successful
+file: write:{"x":1} successful
+file: write:{"x":2} successful
 ]], [ignore])
 AT_CHECK(
   [test-ovsdb log-io file read-only read read read read], [0], 
   [[file: open successful
-file: read: [0]
-file: read: [1]
-file: read: [2]
+file: read: {"x":0}
+file: read: {"x":1}
+file: read: {"x":2}
 file: read: end of log
 ]], [ignore])
 AT_CHECK([test -f .file.~lock~])
@@ -79,18 +79,18 @@ AT_CAPTURE_FILE([file])
 # Sometimes you just need more magic:
 # http://www.catb.org/jargon/html/magic-story.html
 AT_CHECK(
-  [[test-ovsdb --magic="MORE MAGIC" log-io file create 'write:[0]' 'write:[1]' 
'write:[2]']], [0],
+  [[test-ovsdb --magic="MORE_MAGIC" log-io file create 'write:{"x":0}' 
'write:{"x":1}' 'write:{"x":2}']], [0],
   [[file: open successful
-file: write:[0] successful
-file: write:[1] successful
-file: write:[2] successful
+file: write:{"x":0} successful
+file: write:{"x":1} successful
+file: write:{"x":2} successful
 ]], [ignore])
 AT_CHECK(
-  [test-ovsdb --magic="MORE MAGIC" log-io file read-only read read read read], 
[0],
+  [test-ovsdb --magic="MORE_MAGIC" log-io file read-only read read read read], 
[0],
   [[file: open successful
-file: read: [0]
-file: read: [1]
-file: read: [2]
+file: read: {"x":0}
+file: read: {"x":1}
+file: read: {"x":2}
 file: read: end of log
 ]], [ignore])
 AT_CHECK(
@@ -104,27 +104,27 @@ AT_SETUP([write one, reread, append])
 AT_KEYWORDS([ovsdb log])
 AT_CAPTURE_FILE([file])
 AT_CHECK(
-  [[test-ovsdb log-io file create 'write:[0]' 'write:[1]'