]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add configurable ovsdb monitor respawn interval
authorTerry Wilson <twilson@redhat.com>
Wed, 20 Nov 2013 15:55:02 +0000 (09:55 -0600)
committerTerry Wilson <twilson@redhat.com>
Wed, 20 Nov 2013 21:16:27 +0000 (15:16 -0600)
If minimize_polling=True and the ovsdb-client process died, the
default respawn interval of 0 would mean that we'd start polling
again. This patch adds the option ovsdb_monitor_respawn_interval and
defaults it to 30 seconds.

Change-Id: I12c1e05ec4d6d2bd4d84024a91116e2ac3974868
Close-Bug: 1243867

etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini
neutron/agent/linux/polling.py
neutron/plugins/openvswitch/agent/ovs_neutron_agent.py
neutron/plugins/openvswitch/common/config.py
neutron/plugins/openvswitch/common/constants.py
neutron/tests/functional/agent/linux/test_ovsdb_monitor.py
neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py

index bb3caf3a58f1a32ca147e620f1a2295c967aa75b..2632a25aaf447df4ae0b03e6abe9287cb55a02bc 100644 (file)
 # Minimize polling by monitoring ovsdb for interface changes
 # minimize_polling = False
 
+# When minimize_polling = True, the number of seconds to wait before
+# respawning the ovsdb monitor after losing communication with it
+# ovsdb_monitor_respawn_interval = 30
+
 # (ListOpt) The types of tenant network tunnels supported by the agent.
 # Setting this will enable tunneling support in the agent. This can be set to
 # either 'gre' or 'vxlan'. If this is unset, it will default to [] and
index 64ea2cebfd46b28d980be24597d87327126feab5..8cce60be4d7c5e8c8ba65f514a2a0a56144cf4e1 100644 (file)
@@ -19,12 +19,18 @@ import contextlib
 import eventlet
 
 from neutron.agent.linux import ovsdb_monitor
+from neutron.plugins.openvswitch.common import constants
 
 
 @contextlib.contextmanager
-def get_polling_manager(minimize_polling=False, root_helper=None):
+def get_polling_manager(minimize_polling=False,
+                        root_helper=None,
+                        ovsdb_monitor_respawn_interval=(
+                            constants.DEFAULT_OVSDBMON_RESPAWN)):
     if minimize_polling:
-        pm = InterfacePollingMinimizer(root_helper=root_helper)
+        pm = InterfacePollingMinimizer(
+            root_helper=root_helper,
+            ovsdb_monitor_respawn_interval=ovsdb_monitor_respawn_interval)
         pm.start()
     else:
         pm = AlwaysPoll()
@@ -86,10 +92,14 @@ class AlwaysPoll(BasePollingManager):
 class InterfacePollingMinimizer(BasePollingManager):
     """Monitors ovsdb to determine when polling is required."""
 
-    def __init__(self, root_helper=None):
+    def __init__(self, root_helper=None,
+                 ovsdb_monitor_respawn_interval=(
+                     constants.DEFAULT_OVSDBMON_RESPAWN)):
+
         super(InterfacePollingMinimizer, self).__init__()
         self._monitor = ovsdb_monitor.SimpleInterfaceMonitor(
-            root_helper=root_helper)
+            root_helper=root_helper,
+            respawn_interval=ovsdb_monitor_respawn_interval)
 
     def start(self):
         self._monitor.start()
index b093d0a2d30260b0dfc41124207b6a19122919f9..ef7cda71ed3e459a0a500fb1de9fad67cc00fb76 100644 (file)
@@ -158,7 +158,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                  bridge_mappings, root_helper,
                  polling_interval, tunnel_types=None,
                  veth_mtu=None, l2_population=False,
-                 minimize_polling=False):
+                 minimize_polling=False,
+                 ovsdb_monitor_respawn_interval=(
+                     constants.DEFAULT_OVSDBMON_RESPAWN)):
         '''Constructor.
 
         :param integ_br: name of the integration bridge.
@@ -173,6 +175,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         :param veth_mtu: MTU size for veth interfaces.
         :param minimize_polling: Optional, whether to minimize polling by
                monitoring ovsdb for interface changes.
+        :param ovsdb_monitor_respawn_interval: Optional, when using polling
+               minimization, the number of seconds to wait before respawning
+               the ovsdb monitor.
         '''
         self.veth_mtu = veth_mtu
         self.root_helper = root_helper
@@ -204,6 +209,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
 
         self.polling_interval = polling_interval
         self.minimize_polling = minimize_polling
+        self.ovsdb_monitor_respawn_interval = ovsdb_monitor_respawn_interval
 
         if tunnel_types:
             self.enable_tunneling = True
@@ -1115,8 +1121,11 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                            'elapsed': elapsed})
 
     def daemon_loop(self):
-        with polling.get_polling_manager(self.minimize_polling,
-                                         self.root_helper) as pm:
+        with polling.get_polling_manager(
+            self.minimize_polling,
+            self.root_helper,
+            self.ovsdb_monitor_respawn_interval) as pm:
+
             self.rpc_loop(polling_manager=pm)
 
 
index abd2a56fa4e6f71999758d8d23c3c657b6f85185..4b473943bb82956534f63d95a3d955a483bbe172 100644 (file)
@@ -66,6 +66,10 @@ agent_opts = [
                 default=False,
                 help=_("Minimize polling by monitoring ovsdb for interface "
                        "changes.")),
+    cfg.IntOpt('ovsdb_monitor_respawn_interval',
+               default=constants.DEFAULT_OVSDBMON_RESPAWN,
+               help=_("The number of seconds to wait before respawning the "
+                      "ovsdb monitor after losing communication with it")),
     cfg.ListOpt('tunnel_types', default=DEFAULT_TUNNEL_TYPES,
                 help=_("Network types supported by the agent "
                        "(gre and/or vxlan)")),
index 01488b447e9ea7ca9e4a58379503869c63f94e90..9d1abd05fa311357455d2620d1d7d55ea00e5284 100644 (file)
@@ -48,3 +48,6 @@ UCAST_TO_TUN = 20
 FLOOD_TO_TUN = 21
 # Map tunnel types to tables number
 TUN_TABLE = {TYPE_GRE: GRE_TUN_TO_LV, TYPE_VXLAN: VXLAN_TUN_TO_LV}
+
+# The default respawn interval for the ovsdb monitor
+DEFAULT_OVSDBMON_RESPAWN = 30
index 51284c8ea7ed98cf3306b19ce62e7a1b8c3f0da1..602204bb505a0b92b09fa4814f802242532ecc35 100644 (file)
@@ -120,8 +120,8 @@ class TestOvsdbMonitor(BaseMonitorTest):
             old_pid = self.monitor._process.pid
             output1 = self.collect_initial_output()
             pid = self.monitor._get_pid_to_kill()
-            self.monitor._reset_queues()
             self.monitor._kill_process(pid)
+            self.monitor._reset_queues()
             while (self.monitor._process.pid == old_pid):
                 eventlet.sleep(0.01)
             output2 = self.collect_initial_output()
index 874ef2011d0d2c3cd636c25cdccf20d4d47f9cda..1ffa79e012f6f32689f73998c654baa634075cc9 100644 (file)
@@ -588,7 +588,8 @@ class TestOvsNeutronAgent(base.BaseTestCase):
             'neutron.agent.linux.polling.get_polling_manager') as mock_get_pm:
             with mock.patch.object(self.agent, 'rpc_loop') as mock_loop:
                 self.agent.daemon_loop()
-        mock_get_pm.assert_called_with(False, 'sudo')
+        mock_get_pm.assert_called_with(False, 'sudo',
+                                       constants.DEFAULT_OVSDBMON_RESPAWN)
         mock_loop.called_once()
 
     def test_setup_tunnel_port_error_negative(self):