Skip to content

Commit 77f48f7

Browse files
committed
Delete tunnel endpoints if endpoint agent is deleted
Closes-Bug: #2084446 Change-Id: I64ad033e600c2c87af4716736c10e11c143afea2 Signed-off-by: lajoskatona <[email protected]> (cherry picked from commit 618c06b02f2a62819ae76871b9ad920c145f62ed)
1 parent abd1b57 commit 77f48f7

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def tunnel_update(self, context, **kwargs):
901901

902902
@profiler.trace("rpc")
903903
def tunnel_delete(self, context, **kwargs):
904-
LOG.debug("tunnel_delete received")
904+
LOG.debug("tunnel_delete received: %s", kwargs)
905905
if not self.enable_tunneling:
906906
return
907907
tunnel_ip = kwargs.get('tunnel_ip')

neutron/plugins/ml2/plugin.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,34 @@ def _reset_mac_for_direct_physical(self, orig_port, port, binding):
492492
return True
493493
return False
494494

495+
@registry.receives(resources.AGENT, [events.AFTER_DELETE])
496+
def delete_agent_notified(self, resource, event, trigger,
497+
payload=None):
498+
context = payload.context
499+
agent = payload.states[0]
500+
if agent.binary != const.AGENT_PROCESS_OVS:
501+
return
502+
tunnel_id = payload.resource_id
503+
tunnel_ip = agent.configurations.get('tunneling_ip')
504+
tunnel_types = agent.configurations.get('tunnel_types')
505+
if not tunnel_ip or not tunnel_types:
506+
return
507+
LOG.debug('Deleting tunnel id %s, and endpoints associated with '
508+
'it (tunnel_ip: %s tunnel_types: %s)',
509+
tunnel_id, tunnel_ip, tunnel_types)
510+
for t_type in tunnel_types:
511+
self.notifier.tunnel_delete(
512+
context=context,
513+
tunnel_ip=tunnel_ip,
514+
tunnel_type=t_type)
515+
try:
516+
driver = self.type_manager.drivers.get(t_type)
517+
except KeyError:
518+
LOG.warning('Tunnel type %s is not registered, cannot '
519+
'delete tunnel endpoint for it.', t_type)
520+
else:
521+
driver.obj.delete_endpoint(tunnel_ip)
522+
495523
@registry.receives(resources.AGENT, [events.AFTER_UPDATE])
496524
def _retry_binding_revived_agents(self, resource, event, trigger,
497525
payload=None):

neutron/tests/unit/plugins/ml2/test_plugin.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from oslo_config import cfg
4444
from oslo_db import exception as db_exc
4545
from oslo_utils import netutils
46+
from oslo_utils import timeutils
4647
from oslo_utils import uuidutils
4748
import testtools
4849
import webob
@@ -65,6 +66,7 @@
6566
from neutron.plugins.ml2.common import exceptions as ml2_exc
6667
from neutron.plugins.ml2 import db as ml2_db
6768
from neutron.plugins.ml2 import driver_context
69+
from neutron.plugins.ml2.drivers import type_tunnel
6870
from neutron.plugins.ml2.drivers import type_vlan
6971
from neutron.plugins.ml2 import managers
7072
from neutron.plugins.ml2 import models
@@ -596,6 +598,64 @@ def test_update_network_with_incorrect_resource_body(self):
596598
self.assertIn("network", res.json['NeutronError']['message'])
597599

598600

601+
class TestMl2AgentNotifications(Ml2PluginV2TestCase):
602+
603+
class Agent:
604+
def __init__(self, agent_dict):
605+
for field in agent_dict:
606+
setattr(self, field, agent_dict[field])
607+
608+
def test_delete_agent_notified(self):
609+
agent_status = {'agent_type': constants.AGENT_TYPE_OVS,
610+
'binary': constants.AGENT_PROCESS_OVS,
611+
'host': 'AHOST',
612+
'topic': 'N/A',
613+
'configurations': {'tunnel_types': ['vxlan'],
614+
'tunneling_ip': '100.101.2.3'}}
615+
agent = self.plugin.create_or_update_agent(self.context,
616+
dict(agent_status),
617+
timeutils.utcnow())
618+
agnt = self.Agent(agent[1])
619+
with mock.patch.object(
620+
self.plugin.notifier, 'tunnel_delete') as m_t_del:
621+
with mock.patch.object(
622+
type_tunnel.EndpointTunnelTypeDriver,
623+
'delete_endpoint') as m_del_ep:
624+
self.plugin.delete_agent_notified(
625+
resource='agent', event='after_delete', trigger=None,
626+
payload=events.DBEventPayload(
627+
self.context, states=(agnt,),
628+
resource_id=agent[1]['id']))
629+
m_t_del.assert_called_once_with(
630+
context=mock.ANY,
631+
tunnel_ip='100.101.2.3', tunnel_type='vxlan')
632+
m_del_ep.assert_called_once_with('100.101.2.3')
633+
634+
def test_delete_agent_notified_non_ovs(self):
635+
agent_status = {'agent_type': constants.AGENT_TYPE_NIC_SWITCH,
636+
'binary': constants.AGENT_PROCESS_NIC_SWITCH,
637+
'host': 'AHOST',
638+
'topic': 'N/A',
639+
'configurations': {'tunnel_types': ['vxlan'],
640+
'tunneling_ip': '100.101.2.3'}}
641+
agent = self.plugin.create_or_update_agent(self.context,
642+
dict(agent_status),
643+
timeutils.utcnow())
644+
agnt = self.Agent(agent[1])
645+
with mock.patch.object(
646+
self.plugin.notifier, 'tunnel_delete') as m_t_del:
647+
with mock.patch.object(
648+
type_tunnel.EndpointTunnelTypeDriver,
649+
'delete_endpoint') as m_del_ep:
650+
self.plugin.delete_agent_notified(
651+
resource='agent', event='after_delete', trigger=None,
652+
payload=events.DBEventPayload(
653+
self.context, states=(agnt,),
654+
resource_id=agent[1]['id']))
655+
m_t_del.assert_not_called()
656+
m_del_ep.assert_not_called()
657+
658+
599659
class TestMl2NetworksV2AgentMechDrivers(Ml2PluginV2TestCase):
600660

601661
_mechanism_drivers = ['logger', 'test', 'test_with_agent']

0 commit comments

Comments
 (0)