Fix reset/start methods on AgentStatusCheckWorker
This worker would fail to start again if stop() or reset() was called on it because of some bad conditional logic. This doesn't appear to impact the current in-tree use case but it should behave correctly. Closes-Bug: #1641788 Change-Id: Id6334c1ef6c99bd112ada31e8fe3746d7e035356
This commit is contained in:
parent
24166e2981
commit
7c7e2418a2
@ -86,8 +86,8 @@ class AgentStatusCheckWorker(neutron_worker.NeutronWorker):
|
||||
super(AgentStatusCheckWorker, self).start()
|
||||
if self._loop is None:
|
||||
self._loop = loopingcall.FixedIntervalLoopingCall(self._check_func)
|
||||
self._loop.start(interval=self._interval,
|
||||
initial_delay=self._initial_delay)
|
||||
self._loop.start(interval=self._interval,
|
||||
initial_delay=self._initial_delay)
|
||||
|
||||
def wait(self):
|
||||
if self._loop is not None:
|
||||
@ -98,10 +98,9 @@ class AgentStatusCheckWorker(neutron_worker.NeutronWorker):
|
||||
self._loop.stop()
|
||||
|
||||
def reset(self):
|
||||
if self._loop is not None:
|
||||
self.stop()
|
||||
self.wait()
|
||||
self.start()
|
||||
self.stop()
|
||||
self.wait()
|
||||
self.start()
|
||||
|
||||
|
||||
class AgentSchedulerDbMixin(agents_db.AgentDbMixin):
|
||||
|
@ -29,6 +29,7 @@ from neutron.api.rpc.handlers import dhcp_rpc
|
||||
from neutron.api.rpc.handlers import l3_rpc
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import utils
|
||||
from neutron import context
|
||||
from neutron.db import agents_db
|
||||
from neutron.db import agentschedulers_db
|
||||
@ -39,6 +40,7 @@ from neutron.extensions import dhcpagentscheduler
|
||||
from neutron.extensions import l3agentscheduler
|
||||
from neutron import manager
|
||||
from neutron.plugins.common import constants as service_constants
|
||||
from neutron.tests import base
|
||||
from neutron.tests.common import helpers
|
||||
from neutron.tests import fake_notifier
|
||||
from neutron.tests import tools
|
||||
@ -1451,6 +1453,31 @@ class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn,
|
||||
self.assertTrue(self._is_schedule_network_called(device_id))
|
||||
|
||||
|
||||
class AgentStatusCheckWorkerTestCase(base.BaseTestCase):
|
||||
|
||||
def test_agent_worker_lifecycle(self):
|
||||
check_function = mock.Mock()
|
||||
worker = agentschedulers_db.AgentStatusCheckWorker(
|
||||
check_function, interval=1, initial_delay=1)
|
||||
self.addCleanup(worker.stop)
|
||||
worker.wait()
|
||||
self.assertFalse(check_function.called)
|
||||
worker.start()
|
||||
utils.wait_until_true(
|
||||
lambda: check_function.called,
|
||||
timeout=5,
|
||||
exception=RuntimeError("check_function not called"))
|
||||
worker.stop()
|
||||
check_function.reset_mock()
|
||||
worker.wait()
|
||||
self.assertFalse(check_function.called)
|
||||
worker.reset()
|
||||
utils.wait_until_true(
|
||||
lambda: check_function.called,
|
||||
timeout=5,
|
||||
exception=RuntimeError("check_function not called"))
|
||||
|
||||
|
||||
class OvsL3AgentNotifierTestCase(test_l3.L3NatTestCaseMixin,
|
||||
test_agent.AgentDBTestMixIn,
|
||||
AgentSchedulerTestMixIn,
|
||||
|
Loading…
x
Reference in New Issue
Block a user