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."""
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.
: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 = {}
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)
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):
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
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):
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)
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)