diff mbox series

[ovs-dev] tests: Add some Python3 test variants on ovsdb-idl.at

Message ID bb725770978378a663fa6fbe478ed2d38a1e1ee1.1520614179.git.tredaelli@redhat.com
State Superseded, archived
Headers show
Series [ovs-dev] tests: Add some Python3 test variants on ovsdb-idl.at | expand

Commit Message

Timothy Redaelli March 9, 2018, 4:49 p.m. UTC
Execute the "passive tcp", "fetch columns", "idl notify" and
"idl notify SSL" tests also using Python3 (when available).

Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
---
 tests/ovsdb-idl.at | 56 ++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 16 deletions(-)

Comments

Ben Pfaff March 9, 2018, 6:36 p.m. UTC | #1
On Fri, Mar 09, 2018 at 05:49:39PM +0100, Timothy Redaelli wrote:
> Execute the "passive tcp", "fetch columns", "idl notify" and
> "idl notify SSL" tests also using Python3 (when available).
> 
> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>

Thanks for working on this!

When I apply this, I get the actual test failure below.  I do not get
the test failure for the python2 variant.  Do you see this failure?

2160. ovsdb-idl.at:835: testing simple idl, initially populated - Python3 fetch ...
../../tests/ovsdb-idl.at:835: ovsdb_start_idltest
../../tests/ovsdb-idl.at:835: ovsdb-client transact unix:socket '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]'
stderr:
stdout:
[{"uuid":["uuid","4086e641-063a-4110-a7ea-822b6543baba"]},{"uuid":["uuid","8dafd5dc-4836-401a-98f9-c5253242fd94"]}]
../../tests/ovsdb-idl.at:835: $PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket ?simple:i,r! 'fetch 0 r'
stderr:
Traceback (most recent call last):
  File "../../../../tests/test-ovsdb.py", line 869, in <module>
    main(sys.argv)
  File "../../../../tests/test-ovsdb.py", line 864, in main
    func(*args)
  File "../../../../tests/test-ovsdb.py", line 634, in do_idl
    print_idl(idl, step)
  File "../../../../tests/test-ovsdb.py", line 194, in print_idl
    s += get_simple_table_printable_row(row)
  File "../../../../tests/test-ovsdb.py", line 175, in get_simple_table_printable_row
    return get_simple_printable_row_string(row, simple_columns)
  File "../../../../tests/test-ovsdb.py", line 157, in get_simple_printable_row_string
    if hasattr(row, column) and not (type(getattr(row, column))
  File "/home/blp/nicira/ovs/python/ovs/db/idl.py", line 777, in __getattr__
    column = self._table.columns[column_name]
KeyError: 'b'
stdout:
../../tests/ovsdb-idl.at:835: exit code was 1, expected 0
2160. ovsdb-idl.at:835: 2160. simple idl, initially populated - Python3 fetch (ovsdb-idl.at:835): FAILED (ovsdb-idl.at:835)
Timothy Redaelli March 12, 2018, 10:58 a.m. UTC | #2
On Fri, 9 Mar 2018 10:36:20 -0800
Ben Pfaff <blp@ovn.org> wrote:

> On Fri, Mar 09, 2018 at 05:49:39PM +0100, Timothy Redaelli wrote:
> > Execute the "passive tcp", "fetch columns", "idl notify" and
> > "idl notify SSL" tests also using Python3 (when available).
> > 
> > Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>  
> 
> Thanks for working on this!
> 
> When I apply this, I get the actual test failure below.  I do not get
> the test failure for the python2 variant.  Do you see this failure?
[...]

Yes, I was working on a proper fix for that problem, but I didn't have
time to fix that on Friday.

Launching that test with Python3 found a bug in python/ovs/db/idl.py
due to a change in how hasattr works.

In Python2 hasattr intercepts ALL the exceptions [1], but in Python3
hasattr only intercepts AttributeError exception [2].
You can also see the discussion on the upstream mailing [3] list, if you
want to do that.

I just sent a patch to the mailing list in order to fix this problem
[3].

[1] https://docs.python.org/2/library/functions.html#hasattr
[2] https://docs.python.org/3/library/functions.html#hasattr
[3]
https://mail.python.org/pipermail/python-3000/2008-January/011771.html
[4] https://patchwork.ozlabs.org/patch/884419/
diff mbox series

Patch

diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at
index 59b2c1991..01660a12f 100644
--- a/tests/ovsdb-idl.at
+++ b/tests/ovsdb-idl.at
@@ -140,9 +140,9 @@  m4_define([OVSDB_CHECK_IDL],
    OVSDB_CHECK_IDL_TCP6_PY($@)])
 
 # This test uses the Python IDL implementation with passive tcp
-m4_define([OVSDB_CHECK_IDL_PASSIVE_TCP_PY],
-  [AT_SETUP([$1 - Python ptcp])
-   AT_SKIP_IF([test $HAVE_PYTHON = no])
+m4_define([OVSDB_CHECK_IDL_PASSIVE_TCP_PYN],
+  [AT_SETUP([$1 ptcp])
+   AT_SKIP_IF([test $7 = no])
    AT_KEYWORDS([ovsdb server idl positive Python with tcp socket $5])
    # find free TCP port
    AT_CHECK([ovsdb_start_idltest "ptcp:0:127.0.0.1"])
@@ -152,7 +152,7 @@  m4_define([OVSDB_CHECK_IDL_PASSIVE_TCP_PY],
 
    # start OVSDB server in passive mode
    AT_CHECK([ovsdb_start_idltest "tcp:127.0.0.1:$TCP_PORT"])
-   AT_CHECK([$PYTHON $srcdir/test-ovsdb.py -t10 idl_passive $srcdir/idltest.ovsschema ptcp:127.0.0.1:$TCP_PORT $3],
+   AT_CHECK([$8 $srcdir/test-ovsdb.py -t10 idl_passive $srcdir/idltest.ovsschema ptcp:127.0.0.1:$TCP_PORT $3],
       [0], [stdout], [ignore])
    AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
             [0], [$4])
@@ -160,6 +160,12 @@  m4_define([OVSDB_CHECK_IDL_PASSIVE_TCP_PY],
    AT_CLEANUP
    ])
 
+m4_define([OVSDB_CHECK_IDL_PASSIVE_TCP_PY],
+    [OVSDB_CHECK_IDL_PASSIVE_TCP_PYN([$1 - Python2], [$2], [$3], [$4], [$5], [$6],
+                        [$HAVE_PYTHON], [$PYTHON])
+    OVSDB_CHECK_IDL_PASSIVE_TCP_PYN([$1 - Python3], [$2], [$3], [$4], [$5], [$6],
+                        [$HAVE_PYTHON3], [$PYTHON3])])
+
 OVSDB_CHECK_IDL_PASSIVE_TCP_PY([simple passive idl, initially empty, select empty],
   [],
   [['["idltest",{"op":"select","table":"link1","where":[]}]']],
@@ -803,20 +809,26 @@  AT_CHECK([grep '"monitor\|monitor_cond"' stderr | grep -c '"ua"'], [0], [1
 OVSDB_SERVER_SHUTDOWN
 AT_CLEANUP
 
-m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS_PY],
-  [AT_SETUP([$1 - Python fetch])
-   AT_SKIP_IF([test $HAVE_PYTHON = no])
+m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS_PYN],
+  [AT_SETUP([$1 fetch])
+   AT_SKIP_IF([test $8 = no])
    AT_KEYWORDS([ovsdb server idl positive Python increment fetch $6])
    AT_CHECK([ovsdb_start_idltest])
    m4_if([$2], [], [],
      [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
-   AT_CHECK([$PYTHON $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket [$3] $4],
+   AT_CHECK([$9 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket [$3] $4],
             [0], [stdout], [ignore])
    AT_CHECK([sort stdout | uuidfilt]m4_if([$7],,, [[| $7]]),
             [0], [$5])
    OVSDB_SERVER_SHUTDOWN
    AT_CLEANUP])
 
+m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS_PY],
+    [OVSDB_CHECK_IDL_FETCH_COLUMNS_PYN([$1 - Python2], [$2], [$3], [$4], [$5], [$6], [$7],
+                        [$HAVE_PYTHON], [$PYTHON])
+    OVSDB_CHECK_IDL_FETCH_COLUMNS_PYN([$1 - Python3], [$2], [$3], [$4], [$5], [$6], [$7],
+                        [$HAVE_PYTHON3], [$PYTHON3])])
+
 m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS],
    [OVSDB_CHECK_IDL_FETCH_COLUMNS_PY($@)])
 
@@ -1181,24 +1193,30 @@  OVSDB_CHECK_IDL_PY([partial-set idl],
 015: done
 ]])
 
-m4_define([OVSDB_CHECK_IDL_NOTIFY_PY],
-  [AT_SETUP([$1 - Python])
-   AT_SKIP_IF([test $HAVE_PYTHON = no])
+m4_define([OVSDB_CHECK_IDL_NOTIFY_PYN],
+  [AT_SETUP([$1])
+   AT_SKIP_IF([test $6 = no])
    AT_KEYWORDS([ovsdb server idl Python notify $4])
    AT_CHECK([ovsdb_start_idltest])
-   AT_CHECK([$PYTHON $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket $2],
+   AT_CHECK([$7 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket $2],
             [0], [stdout], [ignore], [kill `cat pid`])
    AT_CHECK([sort stdout | uuidfilt]m4_if([$5],,, [[| $5]]),
             [0], [$3], [], [kill `cat pid`])
    OVSDB_SERVER_SHUTDOWN
    AT_CLEANUP])
 
+m4_define([OVSDB_CHECK_IDL_NOTIFY_PY],
+    [OVSDB_CHECK_IDL_NOTIFY_PYN([$1 - Python2], [$2], [$3], [$4], [$5],
+                        [$HAVE_PYTHON], [$PYTHON])
+    OVSDB_CHECK_IDL_NOTIFY_PYN([$1 - Python3], [$2], [$3], [$4], [$5],
+                        [$HAVE_PYTHON3], [$PYTHON3])])
+
 # This test uses the Python IDL implementation with ssl
-m4_define([OVSDB_CHECK_IDL_NOTIFY_SSL_PY],
+m4_define([OVSDB_CHECK_IDL_NOTIFY_SSL_PYN],
   [AT_SETUP([$1 - SSL])
    AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
-   AT_SKIP_IF([test $HAVE_PYTHON = no])
-   $PYTHON -c "import OpenSSL.SSL"
+   AT_SKIP_IF([test $6 = no])
+   $7 -c "import OpenSSL.SSL"
    SSL_PRESENT=$?
    AT_SKIP_IF([test $SSL_PRESENT != 0])
    AT_KEYWORDS([ovsdb server idl Python notify - ssl socket])
@@ -1213,7 +1231,7 @@  m4_define([OVSDB_CHECK_IDL_NOTIFY_SSL_PY],
              --remote=pssl:0:127.0.0.1 db])
    on_exit 'kill `cat ovsdb-server.pid`'
    PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
-   AT_CHECK([$PYTHON $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema \
+   AT_CHECK([$7 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema \
              ssl:127.0.0.1:$TCP_PORT $PKIDIR/testpki-privkey.pem \
              $PKIDIR/testpki-cert.pem $PKIDIR/testpki-cacert.pem $2],
             [0], [stdout], [ignore], [kill `cat pid`])
@@ -1222,6 +1240,12 @@  m4_define([OVSDB_CHECK_IDL_NOTIFY_SSL_PY],
    OVSDB_SERVER_SHUTDOWN
    AT_CLEANUP])
 
+m4_define([OVSDB_CHECK_IDL_NOTIFY_SSL_PY],
+    [OVSDB_CHECK_IDL_NOTIFY_SSL_PYN([$1 - Python2], [$2], [$3], [$4], [$5],
+                        [$HAVE_PYTHON], [$PYTHON])
+    OVSDB_CHECK_IDL_NOTIFY_SSL_PYN([$1 - Python3], [$2], [$3], [$4], [$5],
+                        [$HAVE_PYTHON3], [$PYTHON3])])
+
 m4_define([OVSDB_CHECK_IDL_NOTIFY],
    [OVSDB_CHECK_IDL_NOTIFY_PY($@)
     OVSDB_CHECK_IDL_NOTIFY_SSL_PY($@)])