Merge "Refactor the ProcessMonitor _exit_handler to ProcessMonitor"
This commit is contained in:
commit
7132514e83
|
@ -70,21 +70,7 @@ class DhcpAgent(manager.Manager):
|
|||
self._process_monitor = external_process.ProcessMonitor(
|
||||
config=self.conf,
|
||||
root_helper=self.root_helper,
|
||||
resource_type='dhcp',
|
||||
exit_handler=self._exit_handler)
|
||||
|
||||
def _exit_handler(self, uuid, service):
|
||||
"""This is an exit handler for the ProcessMonitor.
|
||||
|
||||
It will be called if the administrator configured the exit action in
|
||||
check_child_processes_actions, and one of our external processes die
|
||||
unexpectedly.
|
||||
"""
|
||||
LOG.error(_LE("Exiting neutron-dhcp-agent because of a malfunction "
|
||||
"with the %(service)s process identified by uuid "
|
||||
"%(uuid)s"),
|
||||
{'service': service, 'uuid': uuid})
|
||||
raise SystemExit(1)
|
||||
resource_type='dhcp')
|
||||
|
||||
def _populate_networks_cache(self):
|
||||
"""Populate the networks cache when the DHCP-agent starts."""
|
||||
|
|
|
@ -132,7 +132,7 @@ ServiceId = collections.namedtuple('ServiceId', ['uuid', 'service'])
|
|||
|
||||
class ProcessMonitor(object):
|
||||
|
||||
def __init__(self, config, root_helper, resource_type, exit_handler):
|
||||
def __init__(self, config, root_helper, resource_type):
|
||||
"""Handle multiple process managers and watch over all of them.
|
||||
|
||||
:param config: oslo config object with the agent configuration.
|
||||
|
@ -141,15 +141,10 @@ class ProcessMonitor(object):
|
|||
:type root_helper: str
|
||||
:param resource_type: can be dhcp, router, load_balancer, etc.
|
||||
:type resource_type: str
|
||||
:param exit_handler: function to execute when agent exit has to
|
||||
be executed, it should take care of actual
|
||||
exit
|
||||
:type exit_hanlder: function
|
||||
"""
|
||||
self._config = config
|
||||
self._root_helper = root_helper
|
||||
self._resource_type = resource_type
|
||||
self._exit_handler = exit_handler
|
||||
|
||||
self._process_managers = {}
|
||||
|
||||
|
@ -299,3 +294,15 @@ class ProcessMonitor(object):
|
|||
LOG.error(_LE("Exiting agent as programmed in check_child_processes_"
|
||||
"actions"))
|
||||
self._exit_handler(service_id.uuid, service_id.service)
|
||||
|
||||
def _exit_handler(self, uuid, service):
|
||||
"""This is an exit handler for the ProcessMonitor.
|
||||
|
||||
It will be called if the administrator configured the exit action in
|
||||
check_child_processes_actions, and one of our external processes die
|
||||
unexpectedly.
|
||||
"""
|
||||
LOG.error(_LE("Exiting agent because of a malfunction with the "
|
||||
"%(service)s process identified by uuid %(uuid)s"),
|
||||
{'service': service, 'uuid': uuid})
|
||||
raise SystemExit(1)
|
||||
|
|
|
@ -77,8 +77,7 @@ def _get_dhcp_process_monitor(config, root_helper):
|
|||
return external_process.ProcessMonitor(
|
||||
config=config,
|
||||
root_helper=root_helper,
|
||||
resource_type='dhcp',
|
||||
exit_handler=lambda: None)
|
||||
resource_type='dhcp')
|
||||
|
||||
|
||||
def kill_dhcp(conf, namespace):
|
||||
|
|
|
@ -28,7 +28,6 @@ class BaseTestProcessMonitor(base.BaseSudoTestCase):
|
|||
|
||||
def setUp(self):
|
||||
super(BaseTestProcessMonitor, self).setUp()
|
||||
self._exit_handler_called = False
|
||||
cfg.CONF.set_override('check_child_processes_interval', 1, 'AGENT')
|
||||
self._child_processes = []
|
||||
self._ext_processes = None
|
||||
|
@ -43,12 +42,7 @@ class BaseTestProcessMonitor(base.BaseSudoTestCase):
|
|||
return external_process.ProcessMonitor(
|
||||
config=cfg.CONF,
|
||||
root_helper=None,
|
||||
resource_type='test',
|
||||
exit_handler=self._exit_handler)
|
||||
|
||||
def _exit_handler(self, uuid, service):
|
||||
self._exit_handler_called = True
|
||||
self._exit_handler_params = (uuid, service)
|
||||
resource_type='test')
|
||||
|
||||
def _make_cmdline_callback(self, uuid):
|
||||
def _cmdline_callback(pidfile):
|
||||
|
|
|
@ -42,15 +42,13 @@ class BaseTestProcessMonitor(base.BaseTestCase):
|
|||
self.create_child_process_monitor('respawn')
|
||||
|
||||
def create_child_process_monitor(self, action):
|
||||
self.exit_handler = mock.Mock()
|
||||
conf = mock.Mock()
|
||||
conf.AGENT.check_child_processes_action = action
|
||||
conf.AGENT.check_child_processes = True
|
||||
self.pmonitor = external_process.ProcessMonitor(
|
||||
config=conf,
|
||||
root_helper=None,
|
||||
resource_type='test',
|
||||
exit_handler=self.exit_handler)
|
||||
resource_type='test')
|
||||
|
||||
def get_monitored_process_manager(self, uuid, service=None):
|
||||
self.pmonitor.enable(uuid=uuid, service=service, cmd_callback=None)
|
||||
|
@ -69,8 +67,10 @@ class TestProcessMonitor(BaseTestProcessMonitor):
|
|||
self.create_child_process_monitor('exit')
|
||||
pm = self.get_monitored_process_manager(TEST_UUID)
|
||||
pm.active = False
|
||||
self.pmonitor._check_child_processes()
|
||||
self.exit_handler.assert_called_once_with(TEST_UUID, None)
|
||||
with mock.patch.object(external_process.ProcessMonitor,
|
||||
'_exit_handler') as exit_handler:
|
||||
self.pmonitor._check_child_processes()
|
||||
exit_handler.assert_called_once_with(TEST_UUID, None)
|
||||
|
||||
def test_different_service_types(self):
|
||||
pm_none = self.get_monitored_process_manager(TEST_UUID)
|
||||
|
|
Loading…
Reference in New Issue