2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-02 07:15:17 +00:00

ovs.db.idl: Improve error reporting for bad <row-update>s.

Strangely malformed <row-update>s could hypothetically get confusing error
message.  Using the Parser class should avoid that.

Reported-by: Reid Price <reid@nicira.com>
This commit is contained in:
Ben Pfaff
2011-08-22 17:12:59 -07:00
parent 6a6f8d1673
commit 4c0f62718f

View File

@@ -15,6 +15,7 @@
import logging
import ovs.jsonrpc
import ovs.db.parser
import ovs.db.schema
from ovs.db import error
import ovs.ovsuuid
@@ -206,16 +207,11 @@ class Idl:
'is not an object'
% (table_name, uuid_string))
old = row_update.get("old", None)
new = row_update.get("new", None)
parser = ovs.db.parser.Parser(json, "row-update")
old = parser.get_optional("old", [dict])
new = parser.get_optional("new", [dict])
parser.finish()
if old is not None and type(old) != dict:
raise error.Error('"old" <row> is not an object', old)
if new is not None and type(new) != dict:
raise error.Error('"new" <row> is not an object', new)
if (old is not None) + (new is not None) != len(row_update):
raise error.Error("<row-update> contains unexpected "
"member", row_update)
if not old and not new:
raise error.Error('<row-update> missing "old" and '
'"new" members', row_update)