From f31ae53dd5cee1ebaec26dc563e8a3562f897b49 Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Fri, 20 Mar 2020 19:07:17 +0000 Subject: [PATCH] Revert "Switch to use cast method in dhcp_ready_on_ports method" This reverts commit 1a686fb401eca1843b81292fc88c13a2e6fd274d. With https://review.opendev.org/#/c/709824/ and this reverted, we have seen things work better in our large scale environment. Although cast() will return immediately, it can overwhelm the server by sending a lot of messages quickly, and won't necessarily prioritize the "new" ones, which are typically more important to mark as provisioned first. Change-Id: Ie61b222eec87c5613efc6a33553844c64a655a57 Related-bug: #1864675 --- neutron/agent/dhcp/agent.py | 7 +++++-- neutron/tests/unit/agent/dhcp/test_agent.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py index 035d8bb901a..0b2318d4ff9 100644 --- a/neutron/agent/dhcp/agent.py +++ b/neutron/agent/dhcp/agent.py @@ -256,6 +256,9 @@ class DhcpAgent(manager.Manager): LOG.info("DHCP configuration for ports %s is completed", ports_to_send) continue + except oslo_messaging.MessagingTimeout: + LOG.error("Timeout notifying server of ports ready. " + "Retrying...") except Exception: LOG.exception("Failure notifying DHCP server of " "ready DHCP ports. Will retry on next " @@ -785,8 +788,8 @@ class DhcpPluginApi(object): def dhcp_ready_on_ports(self, port_ids): """Notify the server that DHCP is configured for the port.""" cctxt = self.client.prepare(version='1.5') - cctxt.cast(self.context, 'dhcp_ready_on_ports', - port_ids=port_ids) + return cctxt.call(self.context, 'dhcp_ready_on_ports', + port_ids=port_ids) def get_networks(self, filters=None, fields=None): """Get networks. diff --git a/neutron/tests/unit/agent/dhcp/test_agent.py b/neutron/tests/unit/agent/dhcp/test_agent.py index 6a586e1b5a8..5e947da0dd0 100644 --- a/neutron/tests/unit/agent/dhcp/test_agent.py +++ b/neutron/tests/unit/agent/dhcp/test_agent.py @@ -456,6 +456,20 @@ class TestDhcpAgent(base.BaseTestCase): dhcp.start_ready_ports_loop() spawn.assert_called_once_with(dhcp._dhcp_ready_ports_loop) + def test__dhcp_ready_ports_doesnt_log_exception_on_timeout(self): + dhcp = dhcp_agent.DhcpAgent(HOSTNAME) + dhcp.dhcp_ready_ports = set(range(4)) + + with mock.patch.object(dhcp.plugin_rpc, 'dhcp_ready_on_ports', + side_effect=oslo_messaging.MessagingTimeout): + # exit after 2 iterations + with mock.patch.object(dhcp_agent.eventlet, 'sleep', + side_effect=[0, 0, RuntimeError]): + with mock.patch.object(dhcp_agent.LOG, 'exception') as lex: + with testtools.ExpectedException(RuntimeError): + dhcp._dhcp_ready_ports_loop() + self.assertFalse(lex.called) + def test__dhcp_ready_ports_loop(self): dhcp = dhcp_agent.DhcpAgent(HOSTNAME) dhcp.dhcp_ready_ports = set(range(4))