|
|
|
@ -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')):
|
|
|
|
|