Merge "Avoid multiple initializations of Host class"
This commit is contained in:
commit
9175018622
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user