libvirt events engine: constant fixes

The libvirt constants for pool and nodedev events need tweaking since
they don't match the rule used to autogenerate them. Fixes these warnings
at the engine start.

   Skipping "pool/lifecycle" events: libvirt too old
   Skipping "pool/refresh" events: libvirt too old
   Skipping "nodedev/lifecycle" events: libvirt too old
   Skipping "nodedev/update" events: libvirt too old
This commit is contained in:
Cédric Bosdonnat 2020-06-22 11:43:14 +02:00 committed by Daniel Wozniak
parent e46af5dee1
commit 392cf89296
3 changed files with 38 additions and 4 deletions

1
changelog/57746.fixed Normal file
View file

@ -0,0 +1 @@
Fix the registration of libvirt pool and nodedev events

View file

@ -33,7 +33,7 @@ CALLBACK_DEFS constant. If the filters list contains ``all``, all
events will be relayed.
Be aware that the list of events increases with libvirt versions, for example
network events have been added in libvirt 1.2.1.
network events have been added in libvirt 1.2.1 and storage events in 2.0.0.
Running the engine on non-root
------------------------------
@ -137,8 +137,14 @@ CALLBACK_DEFS = {
("block_threshold", None),
),
"network": (("lifecycle", None),),
"pool": (("lifecycle", None), ("refresh", None)),
"nodedev": (("lifecycle", None), ("update", None)),
"pool": (
("lifecycle", "VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE"),
("refresh", "VIR_STORAGE_POOL_EVENT_ID_REFRESH"),
),
"nodedev": (
("lifecycle", "VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE"),
("update", "VIR_NODE_DEVICE_EVENT_ID_UPDATE"),
),
"secret": (("lifecycle", None), ("value_changed", None)),
}
@ -753,7 +759,6 @@ def start(uri=None, tag_prefix="salt/engines/libvirt_events", filters=None):
exit_loop = False
while not exit_loop:
exit_loop = libvirt.virEventRunDefaultImpl() < 0
log.debug("=== in the loop exit_loop %s ===", exit_loop)
except Exception as err: # pylint: disable=broad-except
log.exception(err)

View file

@ -28,6 +28,10 @@ class EngineLibvirtEventTestCase(TestCase, LoaderModuleMockMixin):
) # Don't loop for ever
self.mock_libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE = 0
self.mock_libvirt.VIR_DOMAIN_EVENT_ID_REBOOT = 1
self.mock_libvirt.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE = 0
self.mock_libvirt.VIR_STORAGE_POOL_EVENT_ID_REFRESH = 1
self.mock_libvirt.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE = 0
self.mock_libvirt.VIR_NODE_DEVICE_EVENT_ID_UPDATE = 1
self.addCleanup(patcher.stop)
self.addCleanup(delattr, self, "mock_libvirt")
return {libvirt_events: {}}
@ -112,6 +116,30 @@ class EngineLibvirtEventTestCase(TestCase, LoaderModuleMockMixin):
libvirt_events._network_event_lifecycle_cb,
{"prefix": "test/prefix", "object": "network", "event": "lifecycle"},
)
mock_cnx.storagePoolEventRegisterAny.assert_any_call(
None,
mock_libvirt.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
libvirt_events._pool_event_lifecycle_cb,
{"prefix": "test/prefix", "object": "pool", "event": "lifecycle"},
)
mock_cnx.storagePoolEventRegisterAny.assert_any_call(
None,
mock_libvirt.VIR_STORAGE_POOL_EVENT_ID_REFRESH,
libvirt_events._pool_event_refresh_cb,
{"prefix": "test/prefix", "object": "pool", "event": "refresh"},
)
mock_cnx.nodeDeviceEventRegisterAny.assert_any_call(
None,
mock_libvirt.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE,
libvirt_events._nodedev_event_lifecycle_cb,
{"prefix": "test/prefix", "object": "nodedev", "event": "lifecycle"},
)
mock_cnx.nodeDeviceEventRegisterAny.assert_any_call(
None,
mock_libvirt.VIR_NODE_DEVICE_EVENT_ID_UPDATE,
libvirt_events._nodedev_event_update_cb,
{"prefix": "test/prefix", "object": "nodedev", "event": "update"},
)
# Check that the deregister events are called with the result of register
mock_cnx.networkEventDeregisterAny.assert_called_with(