Merge "Only notify nova of port status changes if configured" into stable/stein

This commit is contained in:
Zuul 2020-05-18 16:22:54 +00:00 committed by Gerrit Code Review
commit e086606f25
2 changed files with 13 additions and 1 deletions

View File

@ -23,6 +23,7 @@ from neutron_lib.plugins import directory
from neutron_lib.plugins.ml2 import api from neutron_lib.plugins.ml2 import api
from neutron_lib import rpc as n_rpc from neutron_lib import rpc as n_rpc
from neutron_lib.services.qos import constants as qos_consts from neutron_lib.services.qos import constants as qos_consts
from oslo_config import cfg
from oslo_log import log from oslo_log import log
import oslo_messaging import oslo_messaging
from sqlalchemy.orm import exc from sqlalchemy.orm import exc
@ -277,7 +278,12 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin):
else: else:
if port.device_owner.startswith( if port.device_owner.startswith(
n_const.DEVICE_OWNER_COMPUTE_PREFIX): n_const.DEVICE_OWNER_COMPUTE_PREFIX):
plugin.nova_notifier.notify_port_active_direct(port) # NOTE(haleyb): It is possible for a test to override a
# config option after the plugin has been initialized so
# the nova_notifier attribute is not set on the plugin.
if (cfg.CONF.notify_nova_on_port_status_changes and
hasattr(plugin, 'nova_notifier')):
plugin.nova_notifier.notify_port_active_direct(port)
return return
else: else:
self.update_port_status_to_active(port, rpc_context, port_id, host) self.update_port_status_to_active(port, rpc_context, port_id, host)

View File

@ -240,6 +240,12 @@ class RpcCallbacksTestCase(base.BaseTestCase):
(self.plugin.nova_notifier.notify_port_active_direct. (self.plugin.nova_notifier.notify_port_active_direct.
assert_called_once_with(port)) assert_called_once_with(port))
def test_update_device_up_with_device_not_bound_to_host_no_notify(self):
cfg.CONF.set_override('notify_nova_on_port_status_changes', False)
self.assertIsNone(self._test_update_device_not_bound_to_host(
self.callbacks.update_device_up))
self.plugin.nova_notifier.notify_port_active_direct.assert_not_called()
def test_update_device_down_with_device_not_bound_to_host(self): def test_update_device_down_with_device_not_bound_to_host(self):
self.assertEqual( self.assertEqual(
{'device': 'fake_device', 'exists': True}, {'device': 'fake_device', 'exists': True},