revert removal of create_ovs_vif_port timeout

- This change revert the accidental removal of the timeout
  keyword argument form the creat_ovs_vif_port function
  caused by Ifa53e5e821093459ab7a390ff8af26028b2a9056
- This change introduces unit test to check the useage of
  the timeout arg.

Change-Id: I32ecaef92c4efe21138436abdcf0995ec90de307
Closes-bug: #1595713
This commit is contained in:
Sean Mooney 2016-06-23 21:13:59 +00:00
parent 2eb892caab
commit d9c72d2bc2
2 changed files with 41 additions and 2 deletions

View File

@ -62,10 +62,10 @@ def _create_ovs_vif_cmd(bridge, dev, iface_id, mac,
@privsep.vif_plug.entrypoint
def create_ovs_vif_port(bridge, dev, iface_id, mac, instance_id,
mtu=None, interface_type=None):
mtu=None, interface_type=None, timeout=None):
_ovs_vsctl(_create_ovs_vif_cmd(bridge, dev, iface_id,
mac, instance_id,
interface_type))
interface_type), timeout=timeout)
# Note at present there is no support for setting the
# mtu for vhost-user type ports.
if mtu and interface_type != constants.OVS_VHOSTUSER_INTERFACE_TYPE:

View File

@ -171,3 +171,42 @@ class LinuxNetTest(testtools.TestCase):
"fake-instance-uuid", None)
self.assertFalse(mock_set_device_mtu.called)
self.assertTrue(mock_vsctl.called)
@mock.patch.object(linux_net, '_ovs_vsctl')
@mock.patch.object(linux_net, '_create_ovs_vif_cmd',
return_value='ovs_command')
@mock.patch.object(linux_net, '_set_device_mtu')
def test_ovs_vif_port_with_timeout(self, mock_set_device_mtu,
mock_create_cmd, mock_vsctl):
linux_net.create_ovs_vif_port(
'fake-bridge',
'fake-dev', 'fake-iface-id', 'fake-mac',
"fake-instance-uuid", timeout=42)
self.assertTrue(mock_create_cmd.called)
self.assertFalse(mock_set_device_mtu.called)
mock_vsctl.assert_called_with('ovs_command', timeout=42)
@mock.patch.object(linux_net, '_ovs_vsctl')
@mock.patch.object(linux_net, '_create_ovs_vif_cmd',
return_value='ovs_command')
@mock.patch.object(linux_net, '_set_device_mtu')
def test_ovs_vif_port_with_no_timeout(self, mock_set_device_mtu,
mock_create_cmd, mock_vsctl):
linux_net.create_ovs_vif_port(
'fake-bridge',
'fake-dev', 'fake-iface-id', 'fake-mac',
"fake-instance-uuid")
self.assertTrue(mock_create_cmd.called)
self.assertFalse(mock_set_device_mtu.called)
mock_vsctl.assert_called_with('ovs_command', timeout=None)
@mock.patch.object(processutils, "execute")
def test_ovs_vsctl(self, mock_execute):
args = ['fake-args', 42]
timeout = 42
linux_net._ovs_vsctl(args)
linux_net._ovs_vsctl(args, timeout=timeout)
self.assertEqual(
[mock.call('ovs-vsctl', *args),
mock.call('ovs-vsctl', '--timeout=%s' % timeout, *args)],
mock_execute.mock_calls)