2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-03 07:45:30 +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 logging
import ovs.jsonrpc import ovs.jsonrpc
import ovs.db.parser
import ovs.db.schema import ovs.db.schema
from ovs.db import error from ovs.db import error
import ovs.ovsuuid import ovs.ovsuuid
@@ -206,16 +207,11 @@ class Idl:
'is not an object' 'is not an object'
% (table_name, uuid_string)) % (table_name, uuid_string))
old = row_update.get("old", None) parser = ovs.db.parser.Parser(json, "row-update")
new = row_update.get("new", None) 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: if not old and not new:
raise error.Error('<row-update> missing "old" and ' raise error.Error('<row-update> missing "old" and '
'"new" members', row_update) '"new" members', row_update)