From: Brent Eagles Date: Tue, 8 Dec 2015 16:02:21 +0000 (-0330) Subject: Add systemd notification after reporting initial state X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=398d10e323216d46f0152a90f15e17e0c18aa0a2;p=openstack-build%2Fneutron-build.git 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 --- diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py index 08323bef6..14d07afd4 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -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!")) diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py index 2b1873fa0..02906b3e0 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py @@ -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,