Merge "Stop any spawned ProcessMonitor at test cleanup"

This commit is contained in:
Jenkins 2015-03-26 22:15:03 +00:00 committed by Gerrit Code Review
commit 822a488976
4 changed files with 30 additions and 3 deletions

View File

@ -199,7 +199,11 @@ class ProcessMonitor(object):
self._monitored_processes.pop(service_id, None)
def stop(self):
"""Stop the process monitoring. """
"""Stop the process monitoring.
This method will stop the monitoring thread, but no monitored
process will be stopped.
"""
self._monitor_processes = False
def _spawn_checking_thread(self):

View File

@ -27,10 +27,12 @@ import logging as std_logging
import os.path
import fixtures
import mock
from oslo_concurrency.fixture import lockutils
from oslo_config import cfg
from oslo_messaging import conffixture as messaging_conffixture
from neutron.agent.linux import external_process
from neutron.common import config
from neutron.common import rpc as n_rpc
from neutron import policy
@ -61,6 +63,28 @@ def fake_consume_in_threads(self):
bool_from_env = sub_base.bool_from_env
class ProcessMonitorFixture(fixtures.Fixture):
"""Test fixture to capture and cleanup any spawn process monitor."""
def setUp(self):
super(ProcessMonitorFixture, self).setUp()
self.old_callable = (
external_process.ProcessMonitor._spawn_checking_thread)
p = mock.patch("neutron.agent.linux.external_process.ProcessMonitor."
"_spawn_checking_thread",
new=lambda x: self.record_calls(x))
p.start()
self.instances = []
self.addCleanup(self.stop)
def stop(self):
for instance in self.instances:
instance.stop()
def record_calls(self, instance):
self.old_callable(instance)
self.instances.append(instance)
class BaseTestCase(sub_base.SubBaseTestCase):
@staticmethod
@ -97,6 +121,7 @@ class BaseTestCase(sub_base.SubBaseTestCase):
cfg.CONF.set_override('state_path', self.get_default_temp_dir().path)
self.addCleanup(CONF.reset)
self.useFixture(ProcessMonitorFixture())
self.useFixture(fixtures.MonkeyPatch(
'neutron.common.exceptions.NeutronException.use_fatal_exceptions',

View File

@ -36,7 +36,6 @@ class KeepalivedManagerTestCase(base.BaseTestCase,
'router1', self.expected_config, conf_path=cfg.CONF.state_path,
process_monitor=self.process_monitor)
self.addCleanup(self.manager.get_process().disable)
self.addCleanup(self.process_monitor.stop)
def test_keepalived_spawn(self):
self.manager.spawn()

View File

@ -34,7 +34,6 @@ class BaseTestProcessMonitor(base.BaseTestCase):
self._process_monitor = None
self.create_child_processes_manager('respawn')
self.addCleanup(self.cleanup_spawned_children)
self.addCleanup(self._process_monitor.stop)
def create_child_processes_manager(self, action):
cfg.CONF.set_override('check_child_processes_action', action, 'AGENT')