Initialize nova_notifier for only port data changes

If notify_nova_on_port_status_changes is False, but
notify_nova_on_port_data_changes is True, the nova_notifier
object in the plugin will not be initialized correctly.
This was never noticed because these two options are
typically configured identically.

Change-Id: I3b0ca77b677fe335161b9a649b4ac397e64eacaa
Related-bug: #1843269
This commit is contained in:
Brian Haley 2019-09-16 16:53:34 -04:00
parent 593f9faef4
commit ab75405708
1 changed files with 11 additions and 9 deletions

View File

@ -159,20 +159,22 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
def __init__(self):
self.set_ipam_backend()
if cfg.CONF.notify_nova_on_port_status_changes:
if (cfg.CONF.notify_nova_on_port_status_changes or
cfg.CONF.notify_nova_on_port_data_changes):
# Import nova conditionally to support the use case of Neutron
# being used outside of an OpenStack context.
from neutron.notifiers import nova
self.nova_notifier = nova.Notifier.get_instance()
# NOTE(arosen) These event listeners are here to hook into when
# port status changes and notify nova about their change.
self.nova_notifier = nova.Notifier.get_instance()
db_api.sqla_listen(models_v2.Port, 'after_insert',
self.nova_notifier.send_port_status)
db_api.sqla_listen(models_v2.Port, 'after_update',
self.nova_notifier.send_port_status)
db_api.sqla_listen(
models_v2.Port.status, 'set',
self.nova_notifier.record_port_status_changed)
if cfg.CONF.notify_nova_on_port_status_changes:
db_api.sqla_listen(models_v2.Port, 'after_insert',
self.nova_notifier.send_port_status)
db_api.sqla_listen(models_v2.Port, 'after_update',
self.nova_notifier.send_port_status)
db_api.sqla_listen(
models_v2.Port.status, 'set',
self.nova_notifier.record_port_status_changed)
if cfg.CONF.ironic.enable_notifications:
# Import ironic notifier conditionally
from neutron.notifiers import ironic