]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make timeout for ovs-vsctl configurable
authorSalvatore Orlando <salv.orlando@gmail.com>
Tue, 10 Dec 2013 12:20:26 +0000 (04:20 -0800)
committerSalvatore Orlando <salv.orlando@gmail.com>
Fri, 10 Jan 2014 22:31:02 +0000 (14:31 -0800)
This patch adds a new configuration variable for the timeout on
ovs-vsctl commands, and sets the default timeout to 10 seconds.
This is aimed at allowing users to tune the agents in order to avoid
timeout errors on their deployments.

Change-Id: I73ea0d0de49a4b4a118bc2d68ad9c093ea122717
Closes-Bug: #1254520

etc/dhcp_agent.ini
etc/l3_agent.ini
neutron/agent/dhcp_agent.py
neutron/agent/l3_agent.py
neutron/agent/linux/ovs_lib.py
neutron/plugins/ryu/common/config.py
neutron/tests/unit/openvswitch/test_ovs_lib.py

index e062beb2f083b3840078946863ef25434047d81e..425684b04f6cb96983256c9904f303aa813efa9d 100644 (file)
@@ -81,3 +81,7 @@
 # you are sure that your version of iproute does not suffer from the problem.
 # If True, namespaces will be deleted when a dhcp server is disabled.
 # dhcp_delete_namespaces = False
+
+# Timeout for ovs-vsctl commands.
+# If the timeout expires, ovs commands will fail with ALARMCLOCK error.
+# ovs_vsctl_timeout = 10
index 777e10ad7fcc69d53518ee98cf33342f42a28cc8..96dcc34ebf44dfd9ee53a2ef1affa4afc0ba2b5d 100644 (file)
@@ -71,3 +71,7 @@
 # you are sure that your version of iproute does not suffer from the problem.
 # If True, namespaces will be deleted when a router is destroyed.
 # router_delete_namespaces = False
+
+# Timeout for ovs-vsctl commands.
+# If the timeout expires, ovs commands will fail with ALARMCLOCK error.
+# ovs_vsctl_timeout = 10
index 777668f674dd79b8ede3ba3030d00a1ede4533f6..605a369f243c6588da5e2dec6cf1af5ac6f3e589 100644 (file)
@@ -25,6 +25,7 @@ from neutron.agent.common import config
 from neutron.agent.linux import dhcp
 from neutron.agent.linux import external_process
 from neutron.agent.linux import interface
+from neutron.agent.linux import ovs_lib  # noqa
 from neutron.agent import rpc as agent_rpc
 from neutron.common import constants
 from neutron.common import exceptions
index 8853fb2c68510a67baa1840f533e7c212461d737..a61045005fdafdefe092278f1d52afcbe85f6fdc 100644 (file)
@@ -26,6 +26,7 @@ from neutron.agent.linux import external_process
 from neutron.agent.linux import interface
 from neutron.agent.linux import ip_lib
 from neutron.agent.linux import iptables_manager
+from neutron.agent.linux import ovs_lib  # noqa
 from neutron.agent.linux import utils
 from neutron.agent import rpc as agent_rpc
 from neutron.common import constants as l3_constants
index b6fcf9270142c3d272ca1e58ee6d8bb344ce0bd1..0ff48e39c1c20a2f3fd423f4fe9671734d400442 100644 (file)
@@ -20,6 +20,8 @@
 
 import re
 
+from oslo.config import cfg
+
 from neutron.agent.linux import ip_lib
 from neutron.agent.linux import utils
 from neutron.openstack.common import jsonutils
@@ -28,6 +30,15 @@ from neutron.plugins.common import constants as p_const
 #  TODO(JLH) Should we remove the explicit include of the ovs plugin here
 from neutron.plugins.openvswitch.common import constants
 
+# Default timeout for ovs-vsctl command
+DEFAULT_OVS_VSCTL_TIMEOUT = 10
+OPTS = [
+    cfg.IntOpt('ovs_vsctl_timeout',
+               default=DEFAULT_OVS_VSCTL_TIMEOUT,
+               help=_('Timeout in seconds for ovs-vsctl commands')),
+]
+cfg.CONF.register_opts(OPTS)
+
 LOG = logging.getLogger(__name__)
 
 
@@ -50,9 +61,10 @@ class BaseOVS(object):
 
     def __init__(self, root_helper):
         self.root_helper = root_helper
+        self.vsctl_timeout = cfg.CONF.ovs_vsctl_timeout
 
     def run_vsctl(self, args, check_error=False):
-        full_args = ["ovs-vsctl", "--timeout=2"] + args
+        full_args = ["ovs-vsctl", "--timeout=%d" % self.vsctl_timeout] + args
         try:
             return utils.execute(full_args, root_helper=self.root_helper)
         except Exception as e:
@@ -393,7 +405,8 @@ class OVSBridge(BaseOVS):
 
 
 def get_bridge_for_iface(root_helper, iface):
-    args = ["ovs-vsctl", "--timeout=2", "iface-to-br", iface]
+    args = ["ovs-vsctl", "--timeout=%d" % cfg.CONF.ovs_vsctl_timeout,
+            "iface-to-br", iface]
     try:
         return utils.execute(args, root_helper=root_helper).strip()
     except Exception:
@@ -402,7 +415,8 @@ def get_bridge_for_iface(root_helper, iface):
 
 
 def get_bridges(root_helper):
-    args = ["ovs-vsctl", "--timeout=2", "list-br"]
+    args = ["ovs-vsctl", "--timeout=%d" % cfg.CONF.ovs_vsctl_timeout,
+            "list-br"]
     try:
         return utils.execute(args, root_helper=root_helper).strip().split("\n")
     except Exception as e:
index 37b369df205a5ec6150e0fcb00b76f19cd050ce3..be6766d1bed59f5e7c32e86cf43ec3d96488ce00 100644 (file)
@@ -17,7 +17,7 @@
 from oslo.config import cfg
 
 from neutron.agent.common import config
-
+from neutron.agent.linux import ovs_lib  # noqa
 
 ovs_opts = [
     cfg.StrOpt('integration_bridge', default='br-int',
index dd3f1137500fd3f3b4f6808f9c5c76f25101eb82..9ec041bb6baa3546658803c46c6e62d0f8b4182c 100644 (file)
@@ -16,6 +16,7 @@
 # @author: Dan Wendlandt, Nicira, Inc.
 
 import mock
+from oslo.config import cfg
 import testtools
 
 from neutron.agent.linux import ovs_lib
@@ -109,11 +110,12 @@ class OVS_Lib_Test(base.BaseTestCase):
     def setUp(self):
         super(OVS_Lib_Test, self).setUp()
         self.BR_NAME = "br-int"
-        self.TO = "--timeout=2"
+        self.TO = "--timeout=10"
 
         self.root_helper = 'sudo'
         self.br = ovs_lib.OVSBridge(self.BR_NAME, self.root_helper)
-        self.execute = mock.patch.object(utils, "execute").start()
+        self.execute = mock.patch.object(
+            utils, "execute", spec=utils.execute).start()
         self.addCleanup(mock.patch.stopall)
 
     def test_vifport(self):
@@ -151,14 +153,29 @@ class OVS_Lib_Test(base.BaseTestCase):
 
         self.br.reset_bridge()
 
-    def test_delete_port(self):
+    def _build_timeout_opt(self, exp_timeout):
+        return "--timeout=%d" % exp_timeout if exp_timeout else self.TO
+
+    def _test_delete_port(self, exp_timeout=None):
+        exp_timeout_str = self._build_timeout_opt(exp_timeout)
         pname = "tap5"
         self.br.delete_port(pname)
         self.execute.assert_called_once_with(
-            ["ovs-vsctl", self.TO, "--", "--if-exists",
+            ["ovs-vsctl", exp_timeout_str, "--", "--if-exists",
              "del-port", self.BR_NAME, pname],
             root_helper=self.root_helper)
 
+    def test_delete_port(self):
+        self._test_delete_port()
+
+    def test_call_command_non_default_timeput(self):
+        # This test is only for verifying a non-default timeout
+        # is correctly applied. Does not need to be repeated for
+        # every ovs_lib method
+        new_timeout = 5
+        self.br.vsctl_timeout = new_timeout
+        self._test_delete_port(new_timeout)
+
     def test_add_flow(self):
         ofport = "99"
         vid = 4000
@@ -503,17 +520,25 @@ class OVS_Lib_Test(base.BaseTestCase):
         self.assertEqual(port_name, 'dhc5c1321a7-c7')
         self.assertEqual(ofport, 2)
 
-    def test_iface_to_br(self):
+    def _test_iface_to_br(self, exp_timeout=None):
         iface = 'tap0'
         br = 'br-int'
         root_helper = 'sudo'
         self.execute.return_value = 'br-int'
-
+        exp_timeout_str = self._build_timeout_opt(exp_timeout)
         self.assertEqual(ovs_lib.get_bridge_for_iface(root_helper, iface), br)
         self.execute.assert_called_once_with(
-            ["ovs-vsctl", self.TO, "iface-to-br", iface],
+            ["ovs-vsctl", exp_timeout_str, "iface-to-br", iface],
             root_helper=root_helper)
 
+    def test_iface_to_br(self):
+        self._test_iface_to_br()
+
+    def test_iface_to_br_non_default_timeout(self):
+        new_timeout = 5
+        cfg.CONF.set_override('ovs_vsctl_timeout', new_timeout)
+        self._test_iface_to_br(new_timeout)
+
     def test_iface_to_br_handles_ovs_vsctl_exception(self):
         iface = 'tap0'
         root_helper = 'sudo'
@@ -547,16 +572,24 @@ class OVS_Lib_Test(base.BaseTestCase):
             mock.call('tap5678')
         ])
 
-    def test_get_bridges(self):
+    def _test_get_bridges(self, exp_timeout=None):
         bridges = ['br-int', 'br-ex']
         root_helper = 'sudo'
         self.execute.return_value = 'br-int\nbr-ex\n'
-
+        timeout_str = self._build_timeout_opt(exp_timeout)
         self.assertEqual(ovs_lib.get_bridges(root_helper), bridges)
         self.execute.assert_called_once_with(
-            ["ovs-vsctl", self.TO, "list-br"],
+            ["ovs-vsctl", timeout_str, "list-br"],
             root_helper=root_helper)
 
+    def test_get_bridges(self):
+        self._test_get_bridges()
+
+    def test_get_bridges_not_default_timeout(self):
+        new_timeout = 5
+        cfg.CONF.set_override('ovs_vsctl_timeout', new_timeout)
+        self._test_get_bridges(new_timeout)
+
     def test_get_local_port_mac_succeeds(self):
         with mock.patch('neutron.agent.linux.ip_lib.IpLinkCommand',
                         return_value=mock.Mock(address='foo')):