Create DHCP agent tap device from port ID
Fixes bug 1022806 Change-Id: If29ffdc35d02f8e18789173f250c1eab28a258fc
This commit is contained in:
parent
dde2388470
commit
1da4b87b72
@ -206,8 +206,10 @@ class DeviceManager(object):
|
||||
LOG.error(_('You must specify an interface driver'))
|
||||
self.driver = importutils.import_object(conf.interface_driver, conf)
|
||||
|
||||
def get_interface_name(self, network):
|
||||
return ('tap' + network.id)[:self.driver.DEV_NAME_LEN]
|
||||
def get_interface_name(self, network, port=None):
|
||||
if not port:
|
||||
port = self._get_or_create_port(network)
|
||||
return ('tap' + port.id)[:self.driver.DEV_NAME_LEN]
|
||||
|
||||
def get_device_id(self, network):
|
||||
# There could be more than one dhcp server per network, so create
|
||||
@ -217,8 +219,8 @@ class DeviceManager(object):
|
||||
return 'dhcp%s-%s' % (host_uuid, network.id)
|
||||
|
||||
def setup(self, network, reuse_existing=False):
|
||||
interface_name = self.get_interface_name(network)
|
||||
port = self._get_or_create_port(network)
|
||||
interface_name = self.get_interface_name(network, port)
|
||||
|
||||
if ip_lib.device_exists(interface_name):
|
||||
if not reuse_existing:
|
||||
|
@ -139,10 +139,6 @@ class BridgeInterfaceDriver(LinuxInterfaceDriver):
|
||||
|
||||
def plug(self, network_id, port_id, device_name, mac_address):
|
||||
"""Plugin the interface."""
|
||||
bridge = self.get_bridge(network_id)
|
||||
|
||||
self.check_bridge_exists(bridge)
|
||||
|
||||
if not ip_lib.device_exists(device_name):
|
||||
device = ip_lib.IPDevice(device_name, self.conf.root_helper)
|
||||
try:
|
||||
|
@ -233,7 +233,7 @@ class TestDeviceManager(unittest.TestCase):
|
||||
tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
subnets=fake_subnets)
|
||||
|
||||
fake_port = FakeModel('12345678-aaaa-aaaa-1234567890ab',
|
||||
fake_port = FakeModel('12345678-1234-aaaa-1234567890ab',
|
||||
mac_address='aa:bb:cc:dd:ee:ff')
|
||||
|
||||
port_dict = dict(mac_address='aa:bb:cc:dd:ee:ff', allocations=[], id=1)
|
||||
@ -270,7 +270,7 @@ class TestDeviceManager(unittest.TestCase):
|
||||
|
||||
self.mock_driver.assert_has_calls([
|
||||
mock.call.plug('12345678-1234-5678-1234567890ab',
|
||||
'12345678-aaaa-aaaa-1234567890ab',
|
||||
'12345678-1234-aaaa-1234567890ab',
|
||||
'tap12345678-12',
|
||||
'aa:bb:cc:dd:ee:ff'),
|
||||
mock.call.init_l3(mock.ANY, 'tap12345678-12')]
|
||||
@ -284,13 +284,43 @@ class TestDeviceManager(unittest.TestCase):
|
||||
tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
subnets=fake_subnets)
|
||||
|
||||
fake_port = FakeModel('12345678-1234-aaaa-1234567890ab',
|
||||
mac_address='aa:bb:cc:dd:ee:ff')
|
||||
|
||||
port_dict = dict(mac_address='aa:bb:cc:dd:ee:ff', allocations=[], id=1)
|
||||
|
||||
self.client_inst.create_port.return_value = dict(port=port_dict)
|
||||
self.device_exists.return_value = False
|
||||
|
||||
# fake the db
|
||||
filter_by_result = mock.Mock()
|
||||
filter_by_result.one = mock.Mock(return_value=fake_port)
|
||||
|
||||
self.filter_called = False
|
||||
|
||||
def get_filter_results(*args, **kwargs):
|
||||
if self.filter_called:
|
||||
return filter_by_result
|
||||
else:
|
||||
self.filter_called = True
|
||||
raise sqlsoup.SQLAlchemyError()
|
||||
|
||||
return filter_results.pop(0)
|
||||
|
||||
mock_db = mock.Mock()
|
||||
mock_db.ports = mock.Mock(name='ports2')
|
||||
mock_db.ports.filter_by = mock.Mock(
|
||||
name='filter_by',
|
||||
side_effect=get_filter_results)
|
||||
|
||||
with mock.patch('quantum.agent.linux.interface.NullDriver') as dvr_cls:
|
||||
mock_driver = mock.MagicMock()
|
||||
mock_driver.DEV_NAME_LEN = (
|
||||
interface.LinuxInterfaceDriver.DEV_NAME_LEN)
|
||||
mock_driver.port = fake_port
|
||||
dvr_cls.return_value = mock_driver
|
||||
|
||||
dh = dhcp_agent.DeviceManager(self.conf, None)
|
||||
dh = dhcp_agent.DeviceManager(self.conf, mock_db)
|
||||
dh.destroy(fake_network)
|
||||
|
||||
dvr_cls.assert_called_once_with(self.conf)
|
||||
|
Loading…
Reference in New Issue
Block a user