Merge "Use `assert_has_calls` to check function calls"

This commit is contained in:
Jenkins 2017-07-06 14:42:26 +00:00 committed by Gerrit Code Review
commit fff78cf0d2
4 changed files with 39 additions and 50 deletions

View File

@ -64,7 +64,7 @@ class LinuxNetTest(testtools.TestCase):
check_exit_code=[0, 2, 254]),
mock.call('ip', 'link', 'set', 'vlan123', 'up',
check_exit_code=[0, 2, 254])]
self.assertEqual(calls, mock_exec.mock_calls)
mock_exec.assert_has_calls(calls)
mock_set_mtu.assert_called_once_with('vlan123', 1500)
@mock.patch.object(processutils, "execute")
@ -81,7 +81,7 @@ class LinuxNetTest(testtools.TestCase):
def test_ensure_bridge_exists(self, mock_dev_exists, mock_exec):
linux_net.ensure_bridge("br0", None, filtering=False)
self.assertEqual([], mock_exec.mock_calls)
mock_exec.assert_not_called()
mock_dev_exists.assert_called_once_with("br0")
@mock.patch.object(processutils, "execute")
@ -101,7 +101,7 @@ class LinuxNetTest(testtools.TestCase):
mock.call('brctl', 'setfd', 'br0', 0),
mock.call('brctl', 'stp', 'br0', "off"),
mock.call('ip', 'link', 'set', 'br0', "up")]
self.assertEqual(calls, mock_exec.mock_calls)
mock_exec.assert_has_calls(calls)
mock_dev_exists.assert_has_calls([mock.call("br0"), mock.call("br0")])
@mock.patch.object(os.path, "exists", return_value=False)
@ -115,7 +115,7 @@ class LinuxNetTest(testtools.TestCase):
mock.call('brctl', 'setfd', 'br0', 0),
mock.call('brctl', 'stp', 'br0', "off"),
mock.call('ip', 'link', 'set', 'br0', "up")]
self.assertEqual(calls, mock_exec.mock_calls)
mock_exec.assert_has_calls(calls)
mock_dev_exists.assert_called_once_with("br0")
@mock.patch.object(os.path, "exists", return_value=True)
@ -131,5 +131,5 @@ class LinuxNetTest(testtools.TestCase):
mock.call('tee', '/proc/sys/net/ipv6/conf/br0/disable_ipv6',
check_exit_code=[0, 1], process_input='1'),
mock.call('ip', 'link', 'set', 'br0', "up")]
self.assertEqual(calls, mock_exec.mock_calls)
mock_exec.assert_has_calls(calls)
mock_dev_exists.assert_called_once_with("br0")

View File

@ -48,8 +48,8 @@ class PluginTest(testtools.TestCase):
plugin = linux_bridge.LinuxBridgePlugin.load("linux_bridge")
plugin.plug(vif, self.instance)
self.assertEqual(len(mock_ensure_bridge.calls), 0)
self.assertEqual(len(mock_ensure_vlan_bridge.calls), 0)
mock_ensure_bridge.assert_not_called()
mock_ensure_vlan_bridge.assert_not_called()
@mock.patch.object(linux_net, 'ensure_vlan_bridge')
@mock.patch.object(linux_net, 'ensure_bridge')
@ -73,7 +73,7 @@ class PluginTest(testtools.TestCase):
plugin.plug(vif, self.instance)
mock_ensure_bridge.assert_called_with("br0", "eth0", filtering=False)
self.assertEqual(len(mock_ensure_vlan_bridge.calls), 0)
mock_ensure_vlan_bridge.assert_not_called()
mock_ensure_bridge.reset_mock()
vif.has_traffic_filtering = False
@ -110,6 +110,6 @@ class PluginTest(testtools.TestCase):
plugin = linux_bridge.LinuxBridgePlugin.load("linux_bridge")
plugin.plug(vif, self.instance)
self.assertEqual(len(mock_ensure_bridge.calls), 0)
mock_ensure_bridge.assert_not_called()
mock_ensure_vlan_bridge.assert_called_with(
99, "br0", "eth0", mtu=mtu or 1500)

View File

@ -35,13 +35,10 @@ class LinuxNetTest(testtools.TestCase):
def test_ensure_bridge_exists(self, mock_dev_exists, mock_execute):
linux_net.ensure_bridge("br0")
self.assertEqual(mock_execute.mock_calls, [
mock_execute.assert_has_calls([
mock.call('ip', 'link', 'set', 'br0', 'up',
check_exit_code=[0, 2, 254]),
])
self.assertEqual(mock_dev_exists.mock_calls, [
mock.call("br0"),
])
check_exit_code=[0, 2, 254])])
mock_dev_exists.assert_has_calls([mock.call("br0")])
@mock.patch.object(os.path, "exists", return_value=False)
@mock.patch.object(processutils, "execute")
@ -50,18 +47,17 @@ class LinuxNetTest(testtools.TestCase):
mock_path_exists):
linux_net.ensure_bridge("br0")
self.assertEqual(mock_execute.mock_calls, [
calls = [
mock.call('brctl', 'addbr', 'br0'),
mock.call('brctl', 'setfd', 'br0', 0),
mock.call('brctl', 'stp', 'br0', "off"),
mock.call('tee', '/sys/class/net/br0/bridge/multicast_snooping',
check_exit_code=[0, 1], process_input='0'),
mock.call('ip', 'link', 'set', 'br0', 'up',
check_exit_code=[0, 2, 254]),
])
self.assertEqual(mock_dev_exists.mock_calls, [
mock.call("br0")
])
check_exit_code=[0, 2, 254])
]
mock_execute.assert_has_calls(calls)
mock_dev_exists.assert_has_calls([mock.call("br0")])
@mock.patch.object(os.path, "exists", return_value=True)
@mock.patch.object(processutils, "execute")
@ -70,7 +66,7 @@ class LinuxNetTest(testtools.TestCase):
mock_path_exists):
linux_net.ensure_bridge("br0")
self.assertEqual(mock_execute.mock_calls, [
calls = [
mock.call('brctl', 'addbr', 'br0'),
mock.call('brctl', 'setfd', 'br0', 0),
mock.call('brctl', 'stp', 'br0', "off"),
@ -79,43 +75,37 @@ class LinuxNetTest(testtools.TestCase):
mock.call('tee', '/proc/sys/net/ipv6/conf/br0/disable_ipv6',
check_exit_code=[0, 1], process_input='1'),
mock.call('ip', 'link', 'set', 'br0', 'up',
check_exit_code=[0, 2, 254]),
])
self.assertEqual(mock_dev_exists.mock_calls, [
mock.call("br0")
])
check_exit_code=[0, 2, 254])
]
mock_execute.assert_has_calls(calls)
mock_dev_exists.assert_has_calls([mock.call("br0")])
@mock.patch.object(processutils, "execute")
@mock.patch.object(linux_net, "device_exists", return_value=False)
def test_delete_bridge_none(self, mock_dev_exists, mock_execute):
linux_net.delete_bridge("br0", "vnet1")
self.assertEqual(mock_execute.mock_calls, [])
self.assertEqual(mock_dev_exists.mock_calls, [
mock.call("br0")
])
mock_execute.assert_not_called()
mock_dev_exists.assert_has_calls([mock.call("br0")])
@mock.patch.object(processutils, "execute")
@mock.patch.object(linux_net, "device_exists", return_value=True)
def test_delete_bridge_exists(self, mock_dev_exists, mock_execute):
linux_net.delete_bridge("br0", "vnet1")
self.assertEqual(mock_execute.mock_calls, [
calls = [
mock.call('brctl', 'delif', 'br0', 'vnet1'),
mock.call('ip', 'link', 'set', 'br0', 'down'),
mock.call('brctl', 'delbr', 'br0'),
])
self.assertEqual(mock_dev_exists.mock_calls, [
mock.call("br0")
])
mock.call('brctl', 'delbr', 'br0')]
mock_execute.assert_has_calls(calls)
mock_dev_exists.assert_has_calls([mock.call("br0")])
@mock.patch.object(processutils, "execute")
def test_add_bridge_port(self, mock_execute):
linux_net.add_bridge_port("br0", "vnet1")
self.assertEqual(mock_execute.mock_calls, [
mock.call('brctl', 'addif', 'br0', 'vnet1'),
])
mock_execute.assert_has_calls([
mock.call('brctl', 'addif', 'br0', 'vnet1')])
def test_ovs_vif_port_cmd(self):
expected = ['--', '--if-exists',
@ -270,10 +260,9 @@ class LinuxNetTest(testtools.TestCase):
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)
mock_execute.assert_has_calls([
mock.call('ovs-vsctl', *args),
mock.call('ovs-vsctl', '--timeout=%s' % timeout, *args)])
@mock.patch.object(linux_net, '_ovs_vsctl')
def test_set_mtu_request(self, mock_vsctl):

View File

@ -139,7 +139,7 @@ class PluginTest(testtools.TestCase):
plugin = ovs.OvsPlugin.load("ovs")
plugin._plug_bridge = plug_bridge_mock
plugin.plug(self.vif_ovs, self.instance)
self.assertFalse(plug_bridge_mock.called)
plug_bridge_mock.assert_not_called()
ensure_ovs_bridge.assert_called_once_with(
self.vif_ovs.network.bridge, constants.OVS_DATAPATH_SYSTEM)
@ -189,8 +189,8 @@ class PluginTest(testtools.TestCase):
ensure_bridge.assert_has_calls(calls['ensure_bridge'])
device_exists.assert_has_calls(calls['device_exists'])
create_veth_pair.assert_has_calls(calls['create_veth_pair'])
self.assertFalse(update_veth_pair.called)
self.assertFalse(_update_vif_port.called)
update_veth_pair.assert_not_called()
_update_vif_port.assert_not_called()
add_bridge_port.assert_has_calls(calls['add_bridge_port'])
_create_vif_port.assert_has_calls(calls['_create_vif_port'])
ensure_ovs_bridge.assert_has_calls(calls['ensure_ovs_bridge'])
@ -205,8 +205,8 @@ class PluginTest(testtools.TestCase):
device_exists.return_value = True
self.assertTrue(linux_net.device_exists('test'))
plugin.plug(self.vif_ovs_hybrid, self.instance)
self.assertFalse(create_veth_pair.called)
self.assertFalse(_create_vif_port.called)
create_veth_pair.assert_not_called()
_create_vif_port.assert_not_called()
update_veth_pair.assert_has_calls(calls['update_veth_pair'])
_update_vif_port.assert_has_calls(calls['_update_vif_port'])
@ -241,7 +241,7 @@ class PluginTest(testtools.TestCase):
plugin = ovs.OvsPlugin.load("ovs")
plugin._unplug_bridge = unplug_bridge_mock
plugin.unplug(self.vif_ovs, self.instance)
self.assertFalse(unplug_bridge_mock.called)
unplug_bridge_mock.assert_not_called()
@mock.patch.object(linux_net, 'delete_ovs_vif_port')
@mock.patch.object(linux_net, 'delete_bridge')