Merge "DHCP: protect against case when device name is None"
This commit is contained in:
commit
71c3829589
@ -1225,7 +1225,10 @@ class DeviceManager(object):
|
|||||||
|
|
||||||
def destroy(self, network, device_name):
|
def destroy(self, network, device_name):
|
||||||
"""Destroy the device used for the network's DHCP on this host."""
|
"""Destroy the device used for the network's DHCP on this host."""
|
||||||
|
if device_name:
|
||||||
self.driver.unplug(device_name, namespace=network.namespace)
|
self.driver.unplug(device_name, namespace=network.namespace)
|
||||||
|
else:
|
||||||
|
LOG.debug('No interface exists for network %s', network.id)
|
||||||
|
|
||||||
self.plugin.release_dhcp_port(network.id,
|
self.plugin.release_dhcp_port(network.id,
|
||||||
self.get_device_id(network))
|
self.get_device_id(network))
|
||||||
|
@ -1393,6 +1393,26 @@ class TestDeviceManager(base.BaseTestCase):
|
|||||||
plugin.assert_has_calls(
|
plugin.assert_has_calls(
|
||||||
[mock.call.release_dhcp_port(fake_net.id, mock.ANY)])
|
[mock.call.release_dhcp_port(fake_net.id, mock.ANY)])
|
||||||
|
|
||||||
|
def test_destroy_with_none(self):
|
||||||
|
fake_net = dhcp.NetModel(
|
||||||
|
True, dict(id=FAKE_NETWORK_UUID,
|
||||||
|
tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa'))
|
||||||
|
|
||||||
|
with mock.patch('neutron.agent.linux.interface.NullDriver') as dvr_cls:
|
||||||
|
mock_driver = mock.MagicMock()
|
||||||
|
mock_driver.get_device_name.return_value = 'tap12345678-12'
|
||||||
|
dvr_cls.return_value = mock_driver
|
||||||
|
|
||||||
|
plugin = mock.Mock()
|
||||||
|
|
||||||
|
dh = dhcp.DeviceManager(cfg.CONF, plugin)
|
||||||
|
dh.destroy(fake_net, None)
|
||||||
|
|
||||||
|
dvr_cls.assert_called_once_with(cfg.CONF)
|
||||||
|
plugin.assert_has_calls(
|
||||||
|
[mock.call.release_dhcp_port(fake_net.id, mock.ANY)])
|
||||||
|
self.assertFalse(mock_driver.called)
|
||||||
|
|
||||||
def test_get_interface_name(self):
|
def test_get_interface_name(self):
|
||||||
fake_net = dhcp.NetModel(
|
fake_net = dhcp.NetModel(
|
||||||
True, dict(id='12345678-1234-5678-1234567890ab',
|
True, dict(id='12345678-1234-5678-1234567890ab',
|
||||||
|
Loading…
Reference in New Issue
Block a user