DHCP: release DHCP port if not enough memory

When the DHCP agent fails to create a namespace for the DHCP
service we will release the DHCP port instead of failing silently.

This will at least give the user an indication that there is no DHCP
service. No DHCP port will exist.

Change-Id: I59af745d3991e6deb424ecd9b916b03f146c246a
Closes-bug: #1544548
This commit is contained in:
Gary Kotton
2016-02-11 05:28:45 -08:00
parent 5b6dab1ac9
commit 80cfec6625
2 changed files with 29 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ import netaddr
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
from oslo_utils import excutils
from oslo_utils import uuidutils
import six
@@ -1202,11 +1203,19 @@ class DeviceManager(object):
namespace=network.namespace):
LOG.debug('Reusing existing device: %s.', interface_name)
else:
try:
self.driver.plug(network.id,
port.id,
interface_name,
port.mac_address,
namespace=network.namespace)
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE('Unable to plug DHCP port for '
'network %s. Releasing port.'),
network.id)
self.plugin.release_dhcp_port(network.id, port.device_id)
self.fill_dhcp_udp_checksums(namespace=network.namespace)
ip_cidrs = []
for fixed_ip in port.fixed_ips:

View File

@@ -1336,6 +1336,21 @@ class TestDeviceManager(base.BaseTestCase):
'device_id': mock.ANY}})])
self.assertIn(fake_dhcp_port, net.ports)
def test_setup_plug_exception(self):
plugin = mock.Mock()
plugin.create_dhcp_port.return_value = fake_dhcp_port
self.ensure_device_is_ready.return_value = False
self.mock_driver.get_device_name.return_value = 'tap12345678-12'
dh = dhcp.DeviceManager(cfg.CONF, plugin)
dh._set_default_route = mock.Mock()
dh._cleanup_stale_devices = mock.Mock()
dh.driver = mock.Mock()
dh.driver.plug.side_effect = OSError()
net = copy.deepcopy(fake_network)
self.assertRaises(OSError, dh.setup, net)
plugin.release_dhcp_port.assert_called_once_with(
net.id, mock.ANY)
def test_setup_ipv6(self):
self._test_setup_helper(True, net=fake_network_ipv6,
port=fake_ipv6_port)