Add systemd notification after reporting initial state

This patch adds a notification for systemd after the agent has reported
its initial state to the Neutron server. This enables configuring
orderly startup of services that are dependent on the server having a
healthy openvswitch agent running.

Related-Bug: #1525901

Change-Id: I8d08f1b2ae196b1e48f9d91e06966687c0a8bd43
This commit is contained in:
Brent Eagles 2015-12-08 12:32:21 -03:30
parent 0c07378509
commit 398d10e323
2 changed files with 14 additions and 1 deletions

View File

@ -25,6 +25,7 @@ from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
from oslo_service import loopingcall
from oslo_service import systemd
import six
from six import moves
@ -318,7 +319,11 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
LOG.info(_LI('Agent has just been revived. '
'Doing a full sync.'))
self.fullsync = True
self.agent_state.pop('start_flag', None)
if self.agent_state.pop('start_flag', None):
# On initial start, we notify systemd after initialization
# is complete.
systemd.notify_once()
except Exception:
LOG.exception(_LE("Failed reporting state!"))

View File

@ -99,6 +99,9 @@ class TestOvsNeutronAgent(object):
notifier_cls = notifier_p.start()
self.notifier = mock.Mock()
notifier_cls.return_value = self.notifier
systemd_patch = mock.patch('oslo_service.systemd.notify_once')
self.systemd_notify = systemd_patch.start()
cfg.CONF.set_default('firewall_driver',
'neutron.agent.firewall.NoopFirewallDriver',
group='SECURITYGROUP')
@ -846,9 +849,12 @@ class TestOvsNeutronAgent(object):
with mock.patch.object(self.agent.state_rpc,
"report_state") as report_st:
self.agent.int_br_device_count = 5
self.systemd_notify.assert_not_called()
self.agent._report_state()
report_st.assert_called_with(self.agent.context,
self.agent.agent_state, True)
self.systemd_notify.assert_called_once_with()
self.systemd_notify.reset_mock()
self.assertNotIn("start_flag", self.agent.agent_state)
self.assertEqual(
self.agent.agent_state["configurations"]["devices"],
@ -857,6 +863,7 @@ class TestOvsNeutronAgent(object):
self.agent._report_state()
report_st.assert_called_with(self.agent.context,
self.agent.agent_state, True)
self.systemd_notify.assert_not_called()
def test_report_state_fail(self):
with mock.patch.object(self.agent.state_rpc,
@ -868,6 +875,7 @@ class TestOvsNeutronAgent(object):
self.agent._report_state()
report_st.assert_called_with(self.agent.context,
self.agent.agent_state, True)
self.systemd_notify.assert_not_called()
def test_report_state_revived(self):
with mock.patch.object(self.agent.state_rpc,