Merge "Fixed: network object was not updated after calling the enable driver while configure DHCP for a network"

This commit is contained in:
Zuul 2026-01-10 00:42:27 +00:00 committed by Gerrit Code Review
commit 87c337006d
3 changed files with 25 additions and 3 deletions

View file

@ -455,6 +455,14 @@ class DhcpAgent(manager.Manager):
if (any(s for s in network.subnets if s.enable_dhcp) and
self.call_driver('enable', network)):
# Ensure we have an up-to-date network object
# Without, the object may not contain the new DHCP port
# which in turn could have a port wrongfully marked
# as stale and deleted
new_network = self.safe_get_network_info(network.id)
if new_network:
network = new_network
self.update_isolated_metadata_proxy(network)
self.cache.put(network)
# After enabling dhcp for network, mark all existing

View file

@ -170,6 +170,7 @@ class DHCPAgentOVSTestFramework(base.BaseSudoTestCase):
return device_manager.get_interface_name(network, port)
def configure_dhcp_for_network(self, network, dhcp_enabled=True):
self.mock_plugin_api.get_network_info.return_value = network
self.agent.configure_dhcp_for_network(network)
self.addCleanup(self._cleanup_network, network, dhcp_enabled)

View file

@ -727,14 +727,27 @@ class TestDhcpAgent(base.BaseTestCase):
def test_configure_dhcp_for_network(self):
dhcp = dhcp_agent.DhcpAgent(HOSTNAME)
dhcp.init_host()
new_fake_network = copy.deepcopy(fake_network)
new_fake_network.ports.append(fake_dhcp_port)
with mock.patch.object(
dhcp, 'update_isolated_metadata_proxy') as ump, \
dhcp, 'call_driver', return_value=True) as call_driver_mock, \
mock.patch.object(
dhcp, 'call_driver', return_value=True):
dhcp,
'safe_get_network_info',
return_value=new_fake_network
), \
mock.patch.object(
dhcp, 'update_isolated_metadata_proxy') as ump:
dhcp.configure_dhcp_for_network(fake_network)
ump.assert_called_once_with(fake_network)
call_driver_mock.assert_called_once_with('enable', fake_network)
ump.assert_called_once_with(new_fake_network)
self.assertIn(fake_network.id, dhcp.cache.get_network_ids())
self.assertIn(fake_port1.id, dhcp.cache.get_port_ids(fake_network.id))
self.assertIn(
fake_dhcp_port.id,
dhcp.cache.get_port_ids(fake_network.id)
)
self.assertIn(fake_port1.id, dhcp.dhcp_ready_ports)
def test_configure_dhcp_for_network_no_subnets_with_dhcp_enabled(self):