def enable(self):
"""Enables DHCP for this network by spawning a local process."""
- interface_name = self.device_manager.setup(self.network,
- reuse_existing=True)
+ interface_name = self.device_manager.setup(self.network)
if self.active:
self.restart()
elif self._enable_dhcp():
return dhcp_port
- def setup(self, network, reuse_existing=False):
+ def setup(self, network):
"""Create and initialize a device for network's DHCP on this host."""
port = self.setup_dhcp_port(network)
interface_name = self.get_interface_name(network, port)
if ip_lib.device_exists(interface_name,
self.root_helper,
network.namespace):
- if not reuse_existing:
- raise exceptions.PreexistingDeviceFailure(
- dev_name=interface_name)
-
LOG.debug(_('Reusing existing device: %s.'), interface_name)
else:
self.driver.plug(network.id,
self.iproute_cls_p.stop()
super(TestDeviceManager, self).tearDown()
- def _test_setup_helper(self, device_exists, reuse_existing=False,
- net=None, port=None):
+ def _test_setup_helper(self, device_exists, net=None, port=None):
net = net or fake_network
port = port or fake_port1
plugin = mock.Mock()
dh = dhcp.DeviceManager(cfg.CONF, cfg.CONF.root_helper, plugin)
dh._set_default_route = mock.Mock()
- interface_name = dh.setup(net, reuse_existing)
+ interface_name = dh.setup(net)
self.assertEqual(interface_name, 'tap12345678-12')
expected_ips,
namespace=net.namespace)]
- if not reuse_existing:
+ if not device_exists:
expected.insert(1,
mock.call.plug(net.id,
port.id,
self._test_setup_helper(False)
def test_setup_device_exists(self):
- with testtools.ExpectedException(exceptions.PreexistingDeviceFailure):
- self._test_setup_helper(True)
-
- def test_setup_device_exists_reuse(self):
- self._test_setup_helper(True, True)
+ self._test_setup_helper(True)
def test_create_dhcp_port_raise_conflict(self):
plugin = mock.Mock()
self.mock_mgr.assert_has_calls(
[mock.call(self.conf, 'sudo', None),
- mock.call().setup(mock.ANY, reuse_existing=True)])
+ mock.call().setup(mock.ANY)])
self.assertEqual(lp.called, ['spawn'])
self.assertTrue(mocks['interface_name'].__set__.called)