unit: fix ValueError on TransactionQueue init with py34

With native ovsdb_interface several py34 tests fail
with ValueError during ovs_lib.OVSBridge creation
because of unbuffered text I/O in TransactionQueue
initialization.
This patch fixes the issue by switching to binary mode
in os.fdopen

Change-Id: I4158cc24f6b28a290a4a4d4bec6c2383c6bf12aa
Closes-Bug: #1580270
This commit is contained in:
Inessa Vasilevskaya 2016-05-10 20:44:42 +03:00
parent 89e27a3acc
commit dc7e2b10e8
2 changed files with 9 additions and 2 deletions

View File

@ -29,8 +29,10 @@ class TransactionQueue(Queue.Queue, object):
def __init__(self, *args, **kwargs):
super(TransactionQueue, self).__init__(*args, **kwargs)
alertpipe = os.pipe()
self.alertin = os.fdopen(alertpipe[0], 'r', 0)
self.alertout = os.fdopen(alertpipe[1], 'w', 0)
# NOTE(ivasilevskaya) python 3 doesn't allow unbuffered I/O. Will get
# around this constraint by using binary mode.
self.alertin = os.fdopen(alertpipe[0], 'rb', 0)
self.alertout = os.fdopen(alertpipe[1], 'wb', 0)
def get_nowait(self, *args, **kwargs):
try:

View File

@ -57,3 +57,8 @@ class TestOVSNativeConnection(base.BaseTestCase):
@helpers.requires_py2
def test_start_with_table_name_list(self):
self._test_start(table_name_list=['fake-table1', 'fake-table2'])
def test_transaction_queue_init(self):
# a test to cover py34 failure during initialization (LP Bug #1580270)
# make sure no ValueError: can't have unbuffered text I/O is raised
connection.TransactionQueue()