Bug 1476385

Summary: [OVN] python ovsdb idl library should support unicode
Product: Red Hat Enterprise Linux 7 Reporter: Lance Richardson <lrichard>
Component: openvswitchAssignee: Mark Michelson <mmichels>
Status: CLOSED CURRENTRELEASE QA Contact: qding
Severity: high Docs Contact:
Priority: high    
Version: 7.3CC: aloughla, atragler, danken, fleitner, kzhang, mmichels, mmirecki, myakove, qding, rkhan, sukulkar
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Unspecified   
Whiteboard:
Fixed In Version: openvswitch-2.7.2-9.git20170914 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-02-16 17:04:01 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Reproducer script
none
Reproducer python script none

Description Lance Richardson 2017-07-28 19:05:27 UTC
Created attachment 1306009 [details]
Reproducer script

Description of problem:
The Python version of the ovsdb idl library fails when strings requiring
unicode encoding are used; the C version of the ovsdb idl library does
not have this limitation. The two implementations should be consistent
in support for unicode-encoded data.

Version-Release number of selected component (if applicable):


How reproducible:
Always.

Steps to Reproduce:
1. Check out and build openvswitch from upstream git repository.
2. Execute "make sandbox SANDBOXFLAGS=--ovn".
3. Execute "PYTHONPATH=$(pwd)/../python python3 pyssh"

Actual results:
Connected!
Traceback (most recent call last):
  File "/tmp/pyssh", line 54, in <module>
    status = txn.commit_block()
  File "/home/vagrant/ovs/python/ovs/db/idl.py", line 1402, in commit_block
    status = self.commit()
  File "/home/vagrant/ovs/python/ovs/db/idl.py", line 1385, in commit
    if not self.idl._session.send(msg):
  File "/home/vagrant/ovs/python/ovs/jsonrpc.py", line 540, in send
    return self.rpc.send(msg)
  File "/home/vagrant/ovs/python/ovs/jsonrpc.py", line 242, in send
    self.output += ovs.json.to_string(msg.to_json())
  File "/home/vagrant/ovs/python/ovs/json.py", line 48, in to_string
    sort_keys=sort_keys)
  File "/usr/lib64/python2.7/json/__init__.py", line 250, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 210, in encode
    return ''.join(chunks)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 1: ordinal not in range(128)


Expected results:
Connected!
ROW: uuid:d2a76fbf-281a-4012-8270-14085b98e777  name:שלוםfoo

Additional info:

Comment 2 Lance Richardson 2017-07-28 19:07:56 UTC
Problem originally reported by mmirecki.

Comment 3 Lance Richardson 2017-07-31 13:58:40 UTC
There was a typo in reproduction step 3, should be:

   Execute "PYTHONPATH=$(pwd)/../python python2 pyssh"

Updated reproducer (works with python3):

#coding: utf-8
import time, six, sys
import ovs.db.idl

def get_switches(idl):
    rows = idl.tables['Logical_Switch'].rows
    for row in six.itervalues(rows):
        print(u'ROW: uuid:' + six.text_type(row.uuid) + u'  name:' + row.name)


schema_helper = ovs.db.idl.SchemaHelper('../ovn/ovn-nb.ovsschema')
schema_helper.register_columns('Logical_Switch', ['name', 'ports', 'other_config', 'external_ids'])

ovs.stream.Stream.ssl_set_private_key_file('sandbox/ovnnb-privkey.pem')
ovs.stream.Stream.ssl_set_certificate_file('sandbox/ovnnb-cert.pem')
ovs.stream.Stream.ssl_set_ca_cert_file('sandbox/pki/switchca/cacert.pem')

idl = ovs.db.idl.Idl('ssl:127.0.0.1:6641', schema_helper)

while True:
    idl.run()
    if idl.has_ever_connected():
        print('Connected!')
        break

txn = ovs.db.idl.Transaction(idl)

row = txn.insert(idl.tables['Logical_Switch'])
#switchname = 'שלום'
switchname = 'רשת חיצונית'
row.__setattr__('name', switchname + "foo")
status = txn.commit_block()

get_switches(idl)

Comment 4 Lance Richardson 2017-08-08 19:53:50 UTC
Upstream patch posted:

https://mail.openvswitch.org/pipermail/ovs-dev/2017-August/337039.html

Comment 5 Dan Kenigsberg 2017-08-21 09:36:04 UTC
I see that commit e7164d96bcbcf790 is merged upstream. Lance, can you now clone this bug to 7.4.z and backport it to ovs-2.7 ?

Comment 6 Lance Richardson 2017-08-22 20:07:02 UTC
(In reply to Dan Kenigsberg from comment #5)
> I see that commit e7164d96bcbcf790 is merged upstream. Lance, can you now
> clone this bug to 7.4.z and backport it to ovs-2.7 ?

This would be delivered via the fast datapath stream, not the RHEL7 z-stream.
We should be able to get it in the next fdprod (2.7) release.

The port migration feature has also been committed upstream, in master
and 2.8 branches, should be able to backport that as well. We'd like to
deliver what you need in as few fdprod releases as possible, perhaps it
would be good if you could make sure Anita has the list for planning (we
are discussing a 2.8 fdprod package as well).

Comment 8 Dan Kenigsberg 2017-08-29 13:45:19 UTC
Anita, can we have this in 2.7 fdprod ?

Comment 9 Lance Richardson 2017-09-06 15:39:07 UTC
The patch for this issue is in upstream 2.7 master, will be included in 2.7.3
when it is tagged and released.

commit 91a322a3ac91c4e47afd6f9a92eedeeb1a61d205
Author: Lance Richardson <lrichard>
Date:   Wed Aug 9 15:38:43 2017 -0400

    python: make python idl unicode-tolerant
    
    Ensure that JSON is utf-8 encoded and that bytes sent/received on
    the stream sockets are in utf-8 form. Add a test case to verify
    that unicode data can be sent/received successfully using Python
    IDL module.
    
    Co-authored-by: Terry Wilson <twilson>
    Signed-off-by: Terry Wilson <twilson>
    Signed-off-by: Lance Richardson <lrichard>
    Signed-off-by: Russell Bryant <russell>

Comment 12 Dan Kenigsberg 2017-09-13 04:30:13 UTC
I believe Meny's team can help testing this bug - in the RHV use case - but I would let him answer.

Comment 16 Flavio Leitner 2017-09-21 23:46:05 UTC
Mark,

Could you please provide a small reproducer for QE to validate our package?
Thanks,
fbl

Comment 17 Mark Michelson 2017-09-22 13:13:48 UTC
Sure thing, I'll get it up here as soon as I can.

Comment 18 Mark Michelson 2017-09-22 14:47:16 UTC
Flavio et al,

Lance already attached a reproducer script on this issue. Is there something wrong with it?

https://bugzilla.redhat.com/attachment.cgi?id=1306009

Comment 19 qding 2017-09-25 01:22:28 UTC
(In reply to Mark Michelson from comment #18)
> Flavio et al,
> 
> Lance already attached a reproducer script on this issue. Is there something
> wrong with it?
> 
> https://bugzilla.redhat.com/attachment.cgi?id=1306009

Hi Mark,

The reproducer is based on upstream git repository and the script https://bugzilla.redhat.com/attachment.cgi?id=1306009 is based on sandbox. We're now verify the bug is fixed in redhah rpm package after openvswitch-2.7.2-9.git20170914. So can you please give a procedure based on a machine with redhat rpm installed?

Thanks
Qijun

Comment 20 Mark Michelson 2017-09-25 15:08:56 UTC
Thanks for the explanation. I will attempt to adapt Lance's reproducer patch to work in the scenario you mentioned.

Comment 21 Mark Michelson 2017-09-25 21:15:56 UTC
Created attachment 1330717 [details]
Reproducer python script

I am uploading reproducer.py, which will reproduce the issue.

Steps to reproduce:
1) Install OVN RPMs
2) Start the OVN NorthD service with systemd

# sudo systemctl enable ovn-northd
# sudo systemctl start ovn-northd

3) Initialize the OVN northbound database

# sudo ovn-nbctl init

4) Run the reproducer.py script

# sudo reproducer.py


On a system that has the bug, you should see something like:
Connected!
Traceback (most recent call last):
  File "reproducer.py", line 29, in <module>
    status = txn.commit_block()
  File "/usr/lib/python2.7/site-packages/ovs/db/idl.py", line 1396, in commit_block
    status = self.commit()
  File "/usr/lib/python2.7/site-packages/ovs/db/idl.py", line 1379, in commit
    if not self.idl._session.send(msg):
  File "/usr/lib/python2.7/site-packages/ovs/jsonrpc.py", line 533, in send
    return self.rpc.send(msg)
  File "/usr/lib/python2.7/site-packages/ovs/jsonrpc.py", line 242, in send
    self.output += ovs.json.to_string(msg.to_json())
  File "/usr/lib/python2.7/site-packages/ovs/json.py", line 47, in to_string
    sort_keys=sort_keys)
  File "/usr/lib64/python2.7/json/__init__.py", line 250, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 210, in encode
    return ''.join(chunks)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 1: ordinal not in range(128)


On a build that does not have the issue, you should see something like:
Connected!
ROW: uuid:a725f492-a5a4-46d5-89ac-1ed61160915e  name:שלוםfoo

Comment 22 qding 2017-09-26 05:27:28 UTC
Run with steps in comment#21
Reproduced with python-openvswitch-2.7.2-8.git20170719.el7fdp.noarch
Verified with python-openvswitch-2.7.2-10.git20170914.el7fdp.noarch
network-qe has no regression test cases for python-openvswitch.

Comment 23 Flavio Leitner 2018-02-16 17:04:01 UTC
Closing resolved bugs.