On Wed, Sep 12, 2012 at 08:32:15AM -0700, Reid Price wrote:
> One note inline
> 
> On Sep 11, 2555 BE, at 23:17, Isaku Yamahata <[email protected]> wrote:
> 
> > Since Transaction._substitute doesn't substitute elements of list/tuple,
> > setting list references results in transaction error. Teach it such case.
> > 
> > Example:
> > {"op": "update",
> > "row":{"bridges":["set",[["uuid",
> >                           "1f42bc19-307f-42e7-a9c0-c12178bd8b51"],
> >                          ["uuid",
> >                           "f97e0c76-7146-489d-9bed-29bc704f65fe"]]]},
> > "table": "Open_vSwitch",
> > "where":[["_uuid", "==", ["uuid",
> >                           "20c2a046-ae7e-4453-a576-11034db24985"]]]}
> > 
> > In the above case, uuid in "row" aren't replaced by "named-uuid" because
> > the function doesn't look into elements of lists.
> > When list/tuple is found, look into elements recursively.
> > 
> > Signed-off-by: Isaku Yamahata <[email protected]>
> > ---
> > python/ovs/db/idl.py |    4 ++++
> > tests/ovsdb-idl.at   |   10 ++++++++++
> > tests/test-ovsdb.py  |   11 ++++++++++-
> > 3 files changed, 24 insertions(+), 1 deletions(-)
> > 
> > diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
> > index 7fed0cf..249fbaf 100644
> > --- a/python/ovs/db/idl.py
> > +++ b/python/ovs/db/idl.py
> > @@ -758,6 +758,10 @@ class Transaction(object):
> >                 row = self._txn_rows.get(uuid, None)
> >                 if row and row._data is None:
> >                     return ["named-uuid", _uuid_name_from_uuid(uuid)]
> 
> 
> 
> > +            else:
> > +                json = [self._substitute_uuids(element) for element in 
> > json]
> > +                if type(json) == tuple:
> > +                    json = tuple(json)
> 
> Didn't look at context, but this can't be correct, right?  Last two lines are
> A) Impossible to hit
> B) A no-op if json was local already
> 
> Do you just mean
> 
>  json = tuple(self._substitute_uuids(e) for e in json)
> 
> ?

Oops. You're right. Fixed it.

>From 1d39b5ac80db69abcddc92a4d9bf8ce39cf22237 Mon Sep 17 00:00:00 2001
Message-Id: 
<1d39b5ac80db69abcddc92a4d9bf8ce39cf22237.1347502936.git.yamah...@valinux.co.jp>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Isaku Yamahata <[email protected]>
Date: Mon, 10 Sep 2012 18:21:20 +0900
Subject: [PATCH] python/ovs/db/idl.py: Transaction._substitute doesn't handle 
list/tuple

Since Transaction._substitute doesn't substitute elements of list/tuple,
setting list references results in transaction error. Teach it such case.

Example:
{"op": "update",
 "row":{"bridges":["set",[["uuid",
                           "1f42bc19-307f-42e7-a9c0-c12178bd8b51"],
                          ["uuid",
                           "f97e0c76-7146-489d-9bed-29bc704f65fe"]]]},
 "table": "Open_vSwitch",
 "where":[["_uuid", "==", ["uuid",
                           "20c2a046-ae7e-4453-a576-11034db24985"]]]}

In the above case, uuid in "row" aren't replaced by "named-uuid" because
the function doesn't look into elements of lists.
When list/tuple is found, look into elements recursively.

Signed-off-by: Isaku Yamahata <[email protected]>
---
changes v1 -> v2:
- tuple case wasn't handled correctly.
---
 python/ovs/db/idl.py |    5 +++++
 tests/ovsdb-idl.at   |   10 ++++++++++
 tests/test-ovsdb.py  |   11 ++++++++++-
 3 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index 5330cea..9fc87dd 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -758,6 +758,11 @@ class Transaction(object):
                 row = self._txn_rows.get(uuid, None)
                 if row and row._data is None:
                     return ["named-uuid", _uuid_name_from_uuid(uuid)]
+            else:
+                if type(json) == list:
+                    json = [self._substitute_uuids(elem) for elem in json]
+                else:
+                    json = tuple(self._substitute_uuids(elem) for elem in json)
         return json
 
     def __disassemble(self):
diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at
index 48e7489..68fe868 100644
--- a/tests/ovsdb-idl.at
+++ b/tests/ovsdb-idl.at
@@ -429,3 +429,13 @@ OVSDB_CHECK_IDL([external-linking idl, consistent ops],
 002: i=1 k=1 ka=[] l2=0 uuid=<1>
 003: done
 ]])
+
+OVSDB_CHECK_IDL_PY([external-linking idl, insert ops],
+  [],
+  [['linktest']],
+  [[000: empty
+001: commit, status=success
+002: i=1 k=1 ka=[1] l2= uuid=<0>
+002: i=2 k=1 ka=[1 2] l2= uuid=<1>
+003: done
+]])
diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py
index 1350ccd..170476d 100644
--- a/tests/test-ovsdb.py
+++ b/tests/test-ovsdb.py
@@ -180,7 +180,7 @@ def print_idl(idl, step):
     for row in l2.itervalues():
         s = ["%03d: i=%s l1=" % (step, row.i)]
         if row.l1:
-            s.append(str(row.l1.i))
+            s.append(str(row.l1[0].i))
         s.append(" uuid=%s" % row.uuid)
         print(''.join(s))
         n += 1
@@ -312,6 +312,15 @@ def idl_set(idl, commands, step):
             sys.stdout.flush()
             txn.abort()
             return
+        elif name == "linktest":
+            l1_0 = txn.insert(idl.tables["link1"])
+            l1_0.i = 1
+            l1_0.k = [l1_0]
+            l1_0.ka = [l1_0]
+            l1_1 = txn.insert(idl.tables["link1"])
+            l1_1.i = 2
+            l1_1.k = [l1_0]
+            l1_1.ka = [l1_0, l1_1]
         else:
             sys.stderr.write("unknown command %s\n" % name)
             sys.exit(1)
-- 
1.7.1.1



-- 
yamahata
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to