Merge "DHCP: release DHCP port if not enough memory"
This commit is contained in:
commit
8c43659e88
|
@ -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:
|
||||
self.driver.plug(network.id,
|
||||
port.id,
|
||||
interface_name,
|
||||
port.mac_address,
|
||||
namespace=network.namespace)
|
||||
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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue