Merge "Avoid multiple initializations of Host class"

This commit is contained in:
Jenkins 2017-02-25 14:54:01 +00:00 committed by Gerrit Code Review
commit 9175018622
2 changed files with 11 additions and 0 deletions

View File

@ -65,6 +65,12 @@ class HostTestCase(test.NoDBTestCase):
self.useFixture(fakelibvirt.FakeLibvirtFixture())
self.host = host.Host("qemu:///system")
@mock.patch("nova.virt.libvirt.host.Host._init_events")
def test_repeat_initialization(self, mock_init_events):
for i in range(3):
self.host.initialize()
mock_init_events.assert_called_once_with()
@mock.patch.object(fakelibvirt.virConnect, "registerCloseCallback")
def test_close_callback(self, mock_close):
self.close_callback = None

View File

@ -104,6 +104,8 @@ class Host(object):
# STOPPED lifecycle event some seconds.
self._lifecycle_delay = 15
self._initialized = False
def _native_thread(self):
"""Receives async events coming in from libvirtd.
@ -468,6 +470,9 @@ class Host(object):
pass
def initialize(self):
if self._initialized:
return
# NOTE(dkliban): Error handler needs to be registered before libvirt
# connection is used for the first time. Otherwise, the
# handler does not get registered.