|
43 | 43 | from oslo_config import cfg
|
44 | 44 | from oslo_db import exception as db_exc
|
45 | 45 | from oslo_utils import netutils
|
| 46 | +from oslo_utils import timeutils |
46 | 47 | from oslo_utils import uuidutils
|
47 | 48 | import testtools
|
48 | 49 | import webob
|
|
65 | 66 | from neutron.plugins.ml2.common import exceptions as ml2_exc
|
66 | 67 | from neutron.plugins.ml2 import db as ml2_db
|
67 | 68 | from neutron.plugins.ml2 import driver_context
|
| 69 | +from neutron.plugins.ml2.drivers import type_tunnel |
68 | 70 | from neutron.plugins.ml2.drivers import type_vlan
|
69 | 71 | from neutron.plugins.ml2 import managers
|
70 | 72 | from neutron.plugins.ml2 import models
|
@@ -596,6 +598,64 @@ def test_update_network_with_incorrect_resource_body(self):
|
596 | 598 | self.assertIn("network", res.json['NeutronError']['message'])
|
597 | 599 |
|
598 | 600 |
|
| 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 | + |
599 | 659 | class TestMl2NetworksV2AgentMechDrivers(Ml2PluginV2TestCase):
|
600 | 660 |
|
601 | 661 | _mechanism_drivers = ['logger', 'test', 'test_with_agent']
|
|
0 commit comments