]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add systemd notification after reporting initial state
authorBrent Eagles <beagles@redhat.com>
Tue, 8 Dec 2015 16:02:21 +0000 (12:32 -0330)
committerBrent Eagles <beagles@redhat.com>
Tue, 5 Jan 2016 20:43:52 +0000 (17:13 -0330)
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

neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py
neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py

index 08323bef69a388f97b711237909df0d9cb837a9f..14d07afd4bac1c3b332b01ae93f820a3fefabeb7 100644 (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!"))
 
index 2b1873fa0535c36115ea3941e8cf8d89499e8307..02906b3e0035991a49a6766716d60eda82d484a7 100644 (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,