Only mark ports ready on synced networks
The DHCP agent was previously resending every single port to the server whenever sync_state was called, even if it was just for one network. This let to sending way too much unnecessary data to the server and also potentially resulted in sending a port to the server that wasn't actually provisioned yet. This patch corrects the behavior by only sending ports for networks that are being synced if it's a conditional sync. Closes-Bug: #1639086 Change-Id: Ie7686837b18ff251baa315ef95dc511cda475672
This commit is contained in:
parent
41bf03f927
commit
7dc2707c2b
|
@ -175,7 +175,7 @@ class DhcpAgent(manager.Manager):
|
|||
pool.waitall()
|
||||
# we notify all ports in case some were created while the agent
|
||||
# was down
|
||||
self.dhcp_ready_ports |= set(self.cache.get_port_ids())
|
||||
self.dhcp_ready_ports |= set(self.cache.get_port_ids(only_nets))
|
||||
LOG.info(_LI('Synchronizing state complete'))
|
||||
|
||||
except Exception as e:
|
||||
|
@ -572,8 +572,11 @@ class NetworkCache(object):
|
|||
return True
|
||||
return False
|
||||
|
||||
def get_port_ids(self):
|
||||
return self.port_lookup.keys()
|
||||
def get_port_ids(self, network_ids=None):
|
||||
if not network_ids:
|
||||
return self.port_lookup.keys()
|
||||
return (p_id for p_id, net in self.port_lookup.items()
|
||||
if net in network_ids)
|
||||
|
||||
def get_network_ids(self):
|
||||
return self.cache.keys()
|
||||
|
|
|
@ -1256,6 +1256,30 @@ class TestNetworkCache(base.BaseTestCase):
|
|||
self.assertEqual(set([fake_port1['id'], fake_port2['id']]),
|
||||
set(nc.get_port_ids()))
|
||||
|
||||
def test_get_port_ids_limited_nets(self):
|
||||
fake_net = dhcp.NetModel(
|
||||
dict(id='12345678-1234-5678-1234567890ab',
|
||||
tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
subnets=[fake_subnet1],
|
||||
ports=[fake_port1]))
|
||||
fake_port2 = copy.deepcopy(fake_port1)
|
||||
fake_port2['id'] = 'fp2'
|
||||
fake_port2['network_id'] = '12345678-1234-5678-1234567890ac'
|
||||
fake_net2 = dhcp.NetModel(
|
||||
dict(id='12345678-1234-5678-1234567890ac',
|
||||
tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
subnets=[fake_subnet1],
|
||||
ports=[fake_port2]))
|
||||
nc = dhcp_agent.NetworkCache()
|
||||
nc.put(fake_net)
|
||||
nc.put(fake_net2)
|
||||
self.assertEqual(set([fake_port1['id']]),
|
||||
set(nc.get_port_ids([fake_net.id, 'net2'])))
|
||||
self.assertEqual(set(),
|
||||
set(nc.get_port_ids(['net2'])))
|
||||
self.assertEqual(set([fake_port2['id']]),
|
||||
set(nc.get_port_ids([fake_port2.network_id, 'net2'])))
|
||||
|
||||
def test_put_port(self):
|
||||
fake_net = dhcp.NetModel(
|
||||
dict(id='12345678-1234-5678-1234567890ab',
|
||||
|
|
Loading…
Reference in New Issue