Stop the RPC connections when the agent exits

This behaviour is already present in the OVS agent RPC plugin;
this patch is imitating that in the ``CommonAgentLoop`` class.

Closes-Bug: #2019314
Change-Id: I8c87e5ff7b948455c62e2fa2a3c89b8b1e45875c
This commit is contained in:
Rodolfo Alonso Hernandez 2023-05-19 16:52:16 +00:00
parent fd21c905ca
commit 050536c66e
2 changed files with 13 additions and 1 deletions

View File

@ -67,6 +67,7 @@ class CommonAgentLoop(service.Service):
self.quitting_rpc_timeout = quitting_rpc_timeout
self.agent_type = agent_type
self.agent_binary = agent_binary
self.connection = None
def _validate_manager_class(self):
if not isinstance(self.mgr,
@ -115,6 +116,8 @@ class CommonAgentLoop(service.Service):
LOG.info("Stopping %s agent.", self.agent_type)
if graceful and self.quitting_rpc_timeout:
self.set_rpc_timeout(self.quitting_rpc_timeout)
if self.connection:
self.connection.close()
super(CommonAgentLoop, self).stop(graceful)
def reset(self):

View File

@ -25,6 +25,7 @@ from oslo_config import cfg
import testtools
from neutron.agent.linux import bridge_lib
from neutron.conf.plugins.ml2.drivers import linuxbridge as conf_lb
from neutron.plugins.ml2.drivers.agent import _agent_manager_base as amb
from neutron.plugins.ml2.drivers.agent import _common_agent as ca
from neutron.tests import base
@ -48,7 +49,8 @@ PORT_DATA = {
class TestCommonAgentLoop(base.BaseTestCase):
def setUp(self):
super(TestCommonAgentLoop, self).setUp()
super().setUp()
conf_lb.register_linuxbridge_opts(cfg=cfg.CONF)
# disable setting up periodic state reporting
cfg.CONF.set_override('report_interval', 0, 'AGENT')
cfg.CONF.set_default('firewall_driver',
@ -613,3 +615,10 @@ class TestCommonAgentLoop(base.BaseTestCase):
)
self.assertNotIn(NETWORK_ID, self.agent.network_ports.keys())
self.assertEqual(port_2_data['port_id'], cleaned_port_id)
def test_stop(self):
mock_connection = mock.Mock()
self.agent.connection = mock_connection
with mock.patch.object(self.agent, 'set_rpc_timeout'):
self.agent.stop()
mock_connection.close.assert_called_once()