if no subnet enable DHCP, DHCP agent should be disable

Bug #1483690 reported by huangpengtaohw
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
neutron
Expired
Undecided
Unassigned

Bug Description

I creat a network ,then creat a Subnet with enable Gateway and DHCP.
a port and a DHCP Agents was created.
then I disable Gateway and DHCP, the port was deleted but there is no change in the DHCP Agents status .

it make no sense DHCP Agents is running well if no subnet is enable DHCP.
I think the DHCP Agents should be deleted too if no subnet is enable DHCP.

Changed in neutron:
assignee: nobody → Raga lahari (raga-lahari)
Revision history for this message
Raga lahari (raga-lahari) wrote :

Hi,
After gateway and DHCP disable, We are also observing that port is getting deleted. dnsmasq also not running for that subnet. Let us know how to check the DHCP agent status for that network. Is there any neutron client command to check the same?

Revision history for this message
huangpengtaohw (huangpengtao) wrote :

after port was deleted and the dhcp agent is still seen in the dashboard. If you were right, the problem is the data is not deleted in the database.

Revision history for this message
Raga lahari (raga-lahari) wrote :

Hi,

According to the bug, dhcp-agent association with the network is still existed even if no subnet with dhcp-enable is available.

openstack@openstack:/opt/stack/neutron$ neutron subnet-create f0ab9b8d-0977-4eb9-9ca4-d84142a90081 --name subnet1 2.2.2.0/24 --enable-dhcp
Created a new subnet:
+-------------------+------------------------------------------+
| Field | Value |
+-------------------+------------------------------------------+
| allocation_pools | {"start": "2.2.2.2", "end": "2.2.2.254"} |
| cidr | 2.2.2.0/24 |
| dns_nameservers | |
| enable_dhcp | True |
| gateway_ip | 2.2.2.1 |
| host_routes | |
| id | d81b2cd8-b318-4f9b-842c-bd809ebffb87 |
| ip_version | 4 |
| ipv6_address_mode | |
| ipv6_ra_mode | |
| name | subnet1 |
| network_id | f0ab9b8d-0977-4eb9-9ca4-d84142a90081 |
| subnetpool_id | |
| tenant_id | e998f06543e4477b9a0bd5359a740a39 |
+-------------------+------------------------------------------+

openstack@openstack:/opt/stack/neutron$ neutron dhcp-agent-list-hosting-net f0ab9b8d-0977-4eb9-9ca4-d84142a90081
+--------------------------------------+-----------+----------------+-------+
| id | host | admin_state_up | alive |
+--------------------------------------+-----------+----------------+-------+
| af4de443-2e24-4892-b104-4041ceb2899d | openstack | True | :-) |
+--------------------------------------+-----------+----------------+-------+

 Updating subnet with --disable-dhcp agent

openstack@openstack:/opt/stack/neutron$ neutron subnet-update d81b2cd8-b318-4f9b-842c-bd809ebffb87 --disable-dhcp
Updated subnet: d81b2cd8-b318-4f9b-842c-bd809ebffb87

Still dhcp-agent is running for that network
openstack@openstack:/opt/stack/neutron$ neutron dhcp-agent-list-hosting-net f0ab9b8d-0977-4eb9-9ca4-d84142a90081
+--------------------------------------+-----------+----------------+-------+
| id | host | admin_state_up | alive |
+--------------------------------------+-----------+----------------+-------+
| af4de443-2e24-4892-b104-4041ceb2899d | openstack | True | :-) |
+--------------------------------------+-----------+----------------+-------+
openstack@openstack:/opt/stack/neutron$

Proposing solution:
There should not be any dhcp-agent associated for given network if there is no subnet with dhcp-enable.

Please post your comments or concerns for this solution.

Revision history for this message
huangpengtaohw (huangpengtao) wrote :

you are right, thanks for your work

Revision history for this message
Raga lahari (raga-lahari) wrote :
Download full text (3.2 KiB)

Hi,

We are proposing following code change to fix the bug. Please provide your comments.

As described in bug, Dhcpagent association with the given network is not getting deleted even if no subnet with dhcp-enable .

In side neutron/db/db_base_plugin_v2.py, modified update_subnet() to check for any subnet is having dhcp-enable for given network. If there are no subnets with dhcp-enable, then removing network association with the dhcp agents.

In update_subnet()
        # Keep up with fields that changed
        result.update(changes)

+ plugin = manager.NeutronManager.get_plugin()
+ enable_dhcp=False
+ if not s.get('enable_dhcp'):
+ network_dhcp_status = self.get_network_dhcp_status(context,db_subnet.network_id)
+ if not network_dhcp_status:
+ dhcp_agents = plugin.list_dhcp_agents_hosting_network(context,db_subnet.network_id).get('agents')
+ for agnet in dhcp_agents:
+ self.remove_network_from_dhcp_agent(context,agnet['id'],db_subnet.network_id,notify=False)
+
         if update_ports_needed:
             # Find ports that have not yet been updated
             # with an IP address by Prefix Delegation, and update them

Added new function get_network_dhcp_status(). It will return True if any subnet of given network has enable_dhcp value True.

+ def get_network_dhcp_status(self, context, network_id):
+ enable_dhcp = False
+ filters = {'network_id': [network_id]}
+ fields = ['network_id', 'enable_dhcp']
+ subnets = self.plugin.get_subnets(context, filters=filters, fields=fields)
+ for s in subnets:
+ if s['enable_dhcp']:
+ return True
+ if not enable_dhcp:
+ return False

After above change, Observed following error message.

ERROR neutron.api.rpc.agentnotifiers.dhcp_rpc_agent_api [req-ee89dd42-4d8a-4065-b9cd-b13a6e1d5c12 admin 1e87b805d0c34b4ea0d303d56dcac7fb] Will not send event subnet_update_end for network 411adad2-e41b-4229-9cb7-ae7cee58ef4b: no agent available. Payload: {'subnet': {'name': u'sub10', 'enable_dhcp': False, 'network_id': u'411adad2-e41b-4229-9cb7-ae7cee58ef4b', 'tenant_id': u'1e87b805d0c34b4ea0d303d56dcac7fb', 'dns_nameservers': [], 'gateway_ip': u'2.2.2.1', 'ipv6_ra_mode': None, 'allocation_pools': [{'start': u'2.2.2.2', 'end': u'2.2.2.254'}], 'host_routes': [], 'ip_version': 4, 'ipv6_address_mode': None, 'cidr': u'2.2.2.0/24', 'id': u'1dfb91c7-f2c7-4190-974e-fd767cfff051', 'subnetpool_id': None}}

This error message is notification coming from neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py. So to fix this error log, modified code in _get_enabled_agents() to Log error message only if any subnet is having enable_dhcp is true and not associated with dhcp agent.

@@ -94,8 +95,9 @@ class DhcpAgentNotifyAPI(object):
         if not enabled_agents:
             num_ports = self.plugin.get_ports_count(
                 context, {'network_id': [network_id]})
+
             notification_required = (
- num_ports > 0 and len(network['subnets']) >= 1)
+ num_ports > 0 and len(network['subnets'...

Read more...

Revision history for this message
huangpengtaohw (huangpengtao) wrote :

when creat or delete port,the code will run into create_port or delete_port db_base_plugin_v2.py. do you think so?

Revision history for this message
Gary Kotton (garyk) wrote :

What do you mean by "I think the DHCP Agents should be deleted too if no subnet is enable DHCP."? The DHCP agent should be around to treat new networks

Changed in neutron:
assignee: Raga lahari (raga-lahari) → nobody
Revision history for this message
Armando Migliaccio (armando-migliaccio) wrote :

This bug is > 180 days without activity. We are unsetting assignee and milestone and setting status to Incomplete in order to allow its expiry in 60 days.

If the bug is still valid, then update the bug status.

Changed in neutron:
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for neutron because there has been no activity for 60 days.]

Changed in neutron:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.