Merge "Remove release_lease from the DHCP driver interface"

This commit is contained in:
Jenkins 2014-02-05 15:05:51 +00:00 committed by Gerrit Code Review
commit 3d851a7e44
5 changed files with 2 additions and 56 deletions

View File

@ -255,21 +255,6 @@ class DhcpAgent(manager.Manager):
else: else:
self.disable_dhcp_helper(network.id) self.disable_dhcp_helper(network.id)
def release_lease_for_removed_ips(self, prev_port, updated_port, network):
"""Releases the dhcp lease for ips removed from a port."""
if prev_port:
previous_ips = set(fixed_ip.ip_address
for fixed_ip in prev_port.fixed_ips)
current_ips = set(fixed_ip.ip_address
for fixed_ip in updated_port.fixed_ips)
# pass in port with removed ips on it
removed_ips = previous_ips - current_ips
if removed_ips:
self.call_driver('release_lease',
network,
mac_address=updated_port.mac_address,
removed_ips=removed_ips)
@utils.synchronized('dhcp-agent') @utils.synchronized('dhcp-agent')
def network_create_end(self, context, payload): def network_create_end(self, context, payload):
"""Handle the network.create.end notification event.""" """Handle the network.create.end notification event."""
@ -313,11 +298,8 @@ class DhcpAgent(manager.Manager):
updated_port = dhcp.DictModel(payload['port']) updated_port = dhcp.DictModel(payload['port'])
network = self.cache.get_network_by_id(updated_port.network_id) network = self.cache.get_network_by_id(updated_port.network_id)
if network: if network:
prev_port = self.cache.get_port_by_id(updated_port.id)
self.cache.put_port(updated_port) self.cache.put_port(updated_port)
self.call_driver('reload_allocations', network) self.call_driver('reload_allocations', network)
self.release_lease_for_removed_ips(prev_port, updated_port,
network)
# Use the update handler for the port create event. # Use the update handler for the port create event.
port_create_end = port_update_end port_create_end = port_update_end
@ -330,12 +312,6 @@ class DhcpAgent(manager.Manager):
network = self.cache.get_network_by_id(port.network_id) network = self.cache.get_network_by_id(port.network_id)
self.cache.remove_port(port) self.cache.remove_port(port)
self.call_driver('reload_allocations', network) self.call_driver('reload_allocations', network)
removed_ips = [fixed_ip.ip_address
for fixed_ip in port.fixed_ips]
self.call_driver('release_lease',
network,
mac_address=port.mac_address,
removed_ips=removed_ips)
def enable_isolated_metadata_proxy(self, network): def enable_isolated_metadata_proxy(self, network):

View File

@ -134,10 +134,6 @@ class DhcpBase(object):
def active(self): def active(self):
"""Boolean representing the running state of the DHCP server.""" """Boolean representing the running state of the DHCP server."""
@abc.abstractmethod
def release_lease(self, mac_address, removed_ips):
"""Release a DHCP lease."""
@abc.abstractmethod @abc.abstractmethod
def reload_allocations(self): def reload_allocations(self):
"""Force the DHCP server to reload the assignment database.""" """Force the DHCP server to reload the assignment database."""
@ -379,9 +375,6 @@ class Dnsmasq(DhcpLocalProcess):
cmd = ['%s=%s' % pair for pair in env.items()] + cmd cmd = ['%s=%s' % pair for pair in env.items()] + cmd
utils.execute(cmd, self.root_helper) utils.execute(cmd, self.root_helper)
def release_lease(self, mac_address, removed_ips):
pass
def _release_lease(self, mac_address, ip): def _release_lease(self, mac_address, ip):
"""Release a DHCP lease.""" """Release a DHCP lease."""
cmd = ['dhcp_release', self.interface_name, ip, mac_address] cmd = ['dhcp_release', self.interface_name, ip, mac_address]

View File

@ -44,9 +44,6 @@ class DhcpNoOpDriver(dhcp.DhcpLocalProcess):
self.device_manager.destroy(self.network, self.interface_name) self.device_manager.destroy(self.network, self.interface_name)
self._remove_config_files() self._remove_config_files()
def release_lease(self, mac_address, removed_ips):
pass
def reload_allocations(self): def reload_allocations(self):
"""Force the DHCP server to reload the assignment database.""" """Force the DHCP server to reload the assignment database."""
pass pass

View File

@ -793,7 +793,6 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
self.dhcp.port_update_end(None, payload) self.dhcp.port_update_end(None, payload)
self.cache.assert_has_calls( self.cache.assert_has_calls(
[mock.call.get_network_by_id(fake_port2.network_id), [mock.call.get_network_by_id(fake_port2.network_id),
mock.call.get_port_by_id(fake_port2.id),
mock.call.put_port(mock.ANY)]) mock.call.put_port(mock.ANY)])
self.call_driver.assert_called_once_with('reload_allocations', self.call_driver.assert_called_once_with('reload_allocations',
fake_network) fake_network)
@ -807,16 +806,9 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
self.dhcp.port_update_end(None, payload) self.dhcp.port_update_end(None, payload)
self.cache.assert_has_calls( self.cache.assert_has_calls(
[mock.call.get_network_by_id(fake_port1.network_id), [mock.call.get_network_by_id(fake_port1.network_id),
mock.call.get_port_by_id(fake_port1.id),
mock.call.put_port(mock.ANY)]) mock.call.put_port(mock.ANY)])
self.call_driver.assert_has_calls( self.call_driver.assert_has_calls(
[mock.call.call_driver('reload_allocations', fake_network), [mock.call.call_driver('reload_allocations', fake_network)])
mock.call.call_driver(
'release_lease',
fake_network,
mac_address=fake_port1.mac_address,
removed_ips=set([updated_fake_port1.fixed_ips[0].ip_address]))
])
def test_port_delete_end(self): def test_port_delete_end(self):
payload = dict(port_id=fake_port2.id) payload = dict(port_id=fake_port2.id)
@ -824,18 +816,12 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
self.cache.get_port_by_id.return_value = fake_port2 self.cache.get_port_by_id.return_value = fake_port2
self.dhcp.port_delete_end(None, payload) self.dhcp.port_delete_end(None, payload)
removed_ips = [fixed_ip.ip_address
for fixed_ip in fake_port2.fixed_ips]
self.cache.assert_has_calls( self.cache.assert_has_calls(
[mock.call.get_port_by_id(fake_port2.id), [mock.call.get_port_by_id(fake_port2.id),
mock.call.get_network_by_id(fake_network.id), mock.call.get_network_by_id(fake_network.id),
mock.call.remove_port(fake_port2)]) mock.call.remove_port(fake_port2)])
self.call_driver.assert_has_calls( self.call_driver.assert_has_calls(
[mock.call.call_driver('reload_allocations', fake_network), [mock.call.call_driver('reload_allocations', fake_network)])
mock.call.call_driver('release_lease',
fake_network,
mac_address=fake_port2.mac_address,
removed_ips=removed_ips)])
def test_port_delete_end_unknown_port(self): def test_port_delete_end_unknown_port(self):
payload = dict(port_id='unknown') payload = dict(port_id='unknown')

View File

@ -324,9 +324,6 @@ class LocalChild(dhcp.DhcpLocalProcess):
def spawn_process(self): def spawn_process(self):
self.called.append('spawn') self.called.append('spawn')
def release_lease(self):
self.called.append('release_lease')
class TestBase(base.BaseTestCase): class TestBase(base.BaseTestCase):
def setUp(self): def setUp(self):
@ -381,9 +378,6 @@ class TestDhcpBase(TestBase):
def reload_allocations(self): def reload_allocations(self):
pass pass
def release_lease(self):
pass
@property @property
def active(self): def active(self):
return True return True