Make timeout for ovs-vsctl configurable
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
This commit is contained in:
parent
0432c80bbb
commit
4af2163bd4
@ -81,3 +81,7 @@
|
|||||||
# you are sure that your version of iproute does not suffer from the problem.
|
# 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.
|
# If True, namespaces will be deleted when a dhcp server is disabled.
|
||||||
# dhcp_delete_namespaces = False
|
# dhcp_delete_namespaces = False
|
||||||
|
|
||||||
|
# Timeout for ovs-vsctl commands.
|
||||||
|
# If the timeout expires, ovs commands will fail with ALARMCLOCK error.
|
||||||
|
# ovs_vsctl_timeout = 10
|
||||||
|
@ -71,3 +71,7 @@
|
|||||||
# you are sure that your version of iproute does not suffer from the problem.
|
# 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.
|
# If True, namespaces will be deleted when a router is destroyed.
|
||||||
# router_delete_namespaces = False
|
# router_delete_namespaces = False
|
||||||
|
|
||||||
|
# Timeout for ovs-vsctl commands.
|
||||||
|
# If the timeout expires, ovs commands will fail with ALARMCLOCK error.
|
||||||
|
# ovs_vsctl_timeout = 10
|
||||||
|
@ -25,6 +25,7 @@ from neutron.agent.common import config
|
|||||||
from neutron.agent.linux import dhcp
|
from neutron.agent.linux import dhcp
|
||||||
from neutron.agent.linux import external_process
|
from neutron.agent.linux import external_process
|
||||||
from neutron.agent.linux import interface
|
from neutron.agent.linux import interface
|
||||||
|
from neutron.agent.linux import ovs_lib # noqa
|
||||||
from neutron.agent import rpc as agent_rpc
|
from neutron.agent import rpc as agent_rpc
|
||||||
from neutron.common import constants
|
from neutron.common import constants
|
||||||
from neutron.common import exceptions
|
from neutron.common import exceptions
|
||||||
|
@ -26,6 +26,7 @@ from neutron.agent.linux import external_process
|
|||||||
from neutron.agent.linux import interface
|
from neutron.agent.linux import interface
|
||||||
from neutron.agent.linux import ip_lib
|
from neutron.agent.linux import ip_lib
|
||||||
from neutron.agent.linux import iptables_manager
|
from neutron.agent.linux import iptables_manager
|
||||||
|
from neutron.agent.linux import ovs_lib # noqa
|
||||||
from neutron.agent.linux import utils
|
from neutron.agent.linux import utils
|
||||||
from neutron.agent import rpc as agent_rpc
|
from neutron.agent import rpc as agent_rpc
|
||||||
from neutron.common import constants as l3_constants
|
from neutron.common import constants as l3_constants
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from oslo.config import cfg
|
||||||
|
|
||||||
from neutron.agent.linux import ip_lib
|
from neutron.agent.linux import ip_lib
|
||||||
from neutron.agent.linux import utils
|
from neutron.agent.linux import utils
|
||||||
from neutron.openstack.common import jsonutils
|
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
|
# TODO(JLH) Should we remove the explicit include of the ovs plugin here
|
||||||
from neutron.plugins.openvswitch.common import constants
|
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__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -50,9 +61,10 @@ class BaseOVS(object):
|
|||||||
|
|
||||||
def __init__(self, root_helper):
|
def __init__(self, root_helper):
|
||||||
self.root_helper = root_helper
|
self.root_helper = root_helper
|
||||||
|
self.vsctl_timeout = cfg.CONF.ovs_vsctl_timeout
|
||||||
|
|
||||||
def run_vsctl(self, args, check_error=False):
|
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:
|
try:
|
||||||
return utils.execute(full_args, root_helper=self.root_helper)
|
return utils.execute(full_args, root_helper=self.root_helper)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -393,7 +405,8 @@ class OVSBridge(BaseOVS):
|
|||||||
|
|
||||||
|
|
||||||
def get_bridge_for_iface(root_helper, iface):
|
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:
|
try:
|
||||||
return utils.execute(args, root_helper=root_helper).strip()
|
return utils.execute(args, root_helper=root_helper).strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -402,7 +415,8 @@ def get_bridge_for_iface(root_helper, iface):
|
|||||||
|
|
||||||
|
|
||||||
def get_bridges(root_helper):
|
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:
|
try:
|
||||||
return utils.execute(args, root_helper=root_helper).strip().split("\n")
|
return utils.execute(args, root_helper=root_helper).strip().split("\n")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from neutron.agent.common import config
|
from neutron.agent.common import config
|
||||||
|
from neutron.agent.linux import ovs_lib # noqa
|
||||||
|
|
||||||
ovs_opts = [
|
ovs_opts = [
|
||||||
cfg.StrOpt('integration_bridge', default='br-int',
|
cfg.StrOpt('integration_bridge', default='br-int',
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
# @author: Dan Wendlandt, Nicira, Inc.
|
# @author: Dan Wendlandt, Nicira, Inc.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
from oslo.config import cfg
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from neutron.agent.linux import ovs_lib
|
from neutron.agent.linux import ovs_lib
|
||||||
@ -109,11 +110,12 @@ class OVS_Lib_Test(base.BaseTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(OVS_Lib_Test, self).setUp()
|
super(OVS_Lib_Test, self).setUp()
|
||||||
self.BR_NAME = "br-int"
|
self.BR_NAME = "br-int"
|
||||||
self.TO = "--timeout=2"
|
self.TO = "--timeout=10"
|
||||||
|
|
||||||
self.root_helper = 'sudo'
|
self.root_helper = 'sudo'
|
||||||
self.br = ovs_lib.OVSBridge(self.BR_NAME, self.root_helper)
|
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)
|
self.addCleanup(mock.patch.stopall)
|
||||||
|
|
||||||
def test_vifport(self):
|
def test_vifport(self):
|
||||||
@ -151,14 +153,29 @@ class OVS_Lib_Test(base.BaseTestCase):
|
|||||||
|
|
||||||
self.br.reset_bridge()
|
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"
|
pname = "tap5"
|
||||||
self.br.delete_port(pname)
|
self.br.delete_port(pname)
|
||||||
self.execute.assert_called_once_with(
|
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],
|
"del-port", self.BR_NAME, pname],
|
||||||
root_helper=self.root_helper)
|
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):
|
def test_add_flow(self):
|
||||||
ofport = "99"
|
ofport = "99"
|
||||||
vid = 4000
|
vid = 4000
|
||||||
@ -503,17 +520,25 @@ class OVS_Lib_Test(base.BaseTestCase):
|
|||||||
self.assertEqual(port_name, 'dhc5c1321a7-c7')
|
self.assertEqual(port_name, 'dhc5c1321a7-c7')
|
||||||
self.assertEqual(ofport, 2)
|
self.assertEqual(ofport, 2)
|
||||||
|
|
||||||
def test_iface_to_br(self):
|
def _test_iface_to_br(self, exp_timeout=None):
|
||||||
iface = 'tap0'
|
iface = 'tap0'
|
||||||
br = 'br-int'
|
br = 'br-int'
|
||||||
root_helper = 'sudo'
|
root_helper = 'sudo'
|
||||||
self.execute.return_value = 'br-int'
|
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.assertEqual(ovs_lib.get_bridge_for_iface(root_helper, iface), br)
|
||||||
self.execute.assert_called_once_with(
|
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)
|
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):
|
def test_iface_to_br_handles_ovs_vsctl_exception(self):
|
||||||
iface = 'tap0'
|
iface = 'tap0'
|
||||||
root_helper = 'sudo'
|
root_helper = 'sudo'
|
||||||
@ -547,16 +572,24 @@ class OVS_Lib_Test(base.BaseTestCase):
|
|||||||
mock.call('tap5678')
|
mock.call('tap5678')
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_get_bridges(self):
|
def _test_get_bridges(self, exp_timeout=None):
|
||||||
bridges = ['br-int', 'br-ex']
|
bridges = ['br-int', 'br-ex']
|
||||||
root_helper = 'sudo'
|
root_helper = 'sudo'
|
||||||
self.execute.return_value = 'br-int\nbr-ex\n'
|
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.assertEqual(ovs_lib.get_bridges(root_helper), bridges)
|
||||||
self.execute.assert_called_once_with(
|
self.execute.assert_called_once_with(
|
||||||
["ovs-vsctl", self.TO, "list-br"],
|
["ovs-vsctl", timeout_str, "list-br"],
|
||||||
root_helper=root_helper)
|
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):
|
def test_get_local_port_mac_succeeds(self):
|
||||||
with mock.patch('neutron.agent.linux.ip_lib.IpLinkCommand',
|
with mock.patch('neutron.agent.linux.ip_lib.IpLinkCommand',
|
||||||
return_value=mock.Mock(address='foo')):
|
return_value=mock.Mock(address='foo')):
|
||||||
|
Loading…
Reference in New Issue
Block a user