Cleanup the _execute shim in nova/network.
Originally for testing, it has been progressively replaced by more specific mocking and can now be removed. Change-Id: I11bf62d5ef3041541459d138bedb50aaeb702ae2
This commit is contained in:
parent
7c82342d57
commit
fb84430fd5
@ -1120,15 +1120,6 @@ def _host_dhcp_opts(vif_id=None, gateway=None):
|
||||
return ','.join(values)
|
||||
|
||||
|
||||
def _execute(*cmd, **kwargs):
|
||||
"""Wrapper around utils._execute for fake_network."""
|
||||
if CONF.fake_network:
|
||||
LOG.debug('FAKE NET: %s', ' '.join(map(str, cmd)))
|
||||
return 'fake', 0
|
||||
else:
|
||||
return utils.execute(*cmd, **kwargs)
|
||||
|
||||
|
||||
def _dhcp_file(dev, kind):
|
||||
"""Return path to a pid, leases, hosts or conf file for a bridge/device."""
|
||||
fileutils.ensure_tree(CONF.networks_path)
|
||||
|
@ -1257,19 +1257,12 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
||||
lookup_ip.assert_called_once_with('eth0')
|
||||
|
||||
def test_ensure_bridge_brclt_addif_exception(self):
|
||||
def fake_execute(*cmd, **kwargs):
|
||||
if ('brctl', 'addif', 'bridge', 'eth0') == cmd:
|
||||
return ('', 'some error happens')
|
||||
else:
|
||||
return ('', '')
|
||||
|
||||
with test.nested(
|
||||
mock.patch('nova.privsep.linux_net.device_exists',
|
||||
return_value=True),
|
||||
mock.patch('nova.privsep.linux_net.bridge_add_interface',
|
||||
return_value=('', 'some error happens')),
|
||||
mock.patch.object(linux_net, '_execute', fake_execute)
|
||||
) as (device_exists, _, _):
|
||||
return_value=('', 'some error happens'))
|
||||
) as (device_exists, _):
|
||||
driver = linux_net.LinuxBridgeInterfaceDriver()
|
||||
self.assertRaises(exception.NovaException,
|
||||
driver.ensure_bridge, 'bridge', 'eth0')
|
||||
@ -1386,21 +1379,19 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
||||
mock_set_enabled.assert_called_once_with('vlan_name')
|
||||
mock_set_macaddr.assert_called_once_with('vlan_name', 'MAC')
|
||||
|
||||
@mock.patch.object(linux_net, '_execute')
|
||||
@mock.patch('nova.privsep.linux_net.device_exists', return_value=True)
|
||||
@mock.patch('nova.privsep.linux_net.set_device_mtu')
|
||||
def test_ensure_vlan_device_exists(self, mock_set_device_mtu,
|
||||
mock_device_exists, mock_execute):
|
||||
mock_device_exists):
|
||||
interface = linux_net.LinuxBridgeInterfaceDriver.ensure_vlan(1, 'eth0')
|
||||
self.assertEqual("vlan1", interface)
|
||||
mock_device_exists.assert_called_once_with('vlan1')
|
||||
self.assertFalse(mock_execute.called)
|
||||
mock_set_device_mtu.assert_called_once_with('vlan1', None)
|
||||
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
@mock.patch('nova.privsep.linux_net.set_device_disabled',
|
||||
side_effect=processutils.ProcessExecutionError())
|
||||
def test_remove_bridge_negative(self, mock_execute, mock_exists):
|
||||
def test_remove_bridge_negative(self, mock_device_disabled, mock_exists):
|
||||
self.assertRaises(processutils.ProcessExecutionError,
|
||||
linux_net.LinuxBridgeInterfaceDriver.remove_bridge,
|
||||
'fake-bridge')
|
||||
|
Loading…
Reference in New Issue
Block a user