Skip to content

Commit

Permalink
Fixed bug 962840, added a test case.
Browse files Browse the repository at this point in the history
eventlet.tpool.Proxy doesn't work with old-style class in __str__()
or __repr__() calls. See bug #962840 for details.
We perform a monkey patch to replace those two instance methods.

Change-Id: Ia51bbd3e71cad7df45da5b3b27eef70f9d9e9002
  • Loading branch information
maoy committed Apr 5, 2012
1 parent c7532c6 commit bc173ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions nova/tests/test_libvirt.py
Expand Up @@ -2509,3 +2509,21 @@ def fake_create_new_domain(xml):

ref = self.libvirtconnection.finish_revert_migration(ins_ref, None)
self.assertTrue(isinstance(ref, eventlet.event.Event))


class LibvirtNonblockingTestCase(test.TestCase):
"""Test libvirt_nonblocking option"""

def setUp(self):
super(LibvirtNonblockingTestCase, self).setUp()
self.flags(libvirt_nonblocking=True, libvirt_uri="test:///default")

def tearDown(self):
super(LibvirtNonblockingTestCase, self).tearDown()

@test.skip_if(missing_libvirt(), "Test requires libvirt")
def test_connection_to_primitive(self):
"""Test bug 962840"""
import nova.virt.libvirt.connection
connection = nova.virt.libvirt.connection.get_connection('')
utils.to_primitive(connection._conn, convert_instances=True)
18 changes: 18 additions & 0 deletions nova/virt/libvirt/connection.py
Expand Up @@ -158,6 +158,24 @@
flags.DECLARE('vncserver_proxyclient_address', 'nova.vnc')


def patch_tpool_proxy():
"""eventlet.tpool.Proxy doesn't work with old-style class in __str__()
or __repr__() calls. See bug #962840 for details.
We perform a monkey patch to replace those two instance methods.
"""
def str_method(self):
return str(self._obj)

def repr_method(self):
return repr(self._obj)

tpool.Proxy.__str__ = str_method
tpool.Proxy.__repr__ = repr_method


patch_tpool_proxy()


def get_connection(read_only):
# These are loaded late so that there's no need to install these
# libraries when not using libvirt.
Expand Down

0 comments on commit bc173ec

Please sign in to comment.