| 1 |
# Copyright (c) 2016 OpenStack Foundation |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 |
# implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
from unittest import mock |
| 17 |
|
| 18 |
from neutron.plugins.ml2.drivers.l2pop import rpc as l2pop_rpc |
| 19 |
from neutron.plugins.ml2.drivers import type_tunnel |
| 20 |
from neutron.plugins.ml2 import managers |
| 21 |
from neutron.plugins.ml2 import rpc as rpc |
| 22 |
from neutron.tests import base |
| 23 |
|
| 24 |
from networking_l2gw.services.l2gateway.common import tunnel_calls |
| 25 |
|
| 26 |
|
| 27 |
class TestTunnelCalls(base.BaseTestCase): |
| 28 |
|
| 29 |
def setUp(self): |
| 30 |
super().setUp() |
| 31 |
mock.patch.object(managers, 'TypeManager').start() |
| 32 |
self.tunnel_call = tunnel_calls.Tunnel_Calls() |
| 33 |
self.context = mock.MagicMock() |
| 34 |
|
| 35 |
def test_trigger_tunnel_sync(self): |
| 36 |
with mock.patch.object(rpc, 'RpcCallbacks'), \ |
| 37 |
mock.patch.object(type_tunnel.TunnelRpcCallbackMixin, |
| 38 |
'tunnel_sync') as mock_tunnel_sync: |
| 39 |
self.tunnel_call.trigger_tunnel_sync(self.context, 'fake_ip') |
| 40 |
mock_tunnel_sync.assert_called_with( |
| 41 |
self.context, tunnel_ip='fake_ip', tunnel_type='vxlan') |
| 42 |
|
| 43 |
def test_trigger_l2pop_sync(self): |
| 44 |
fake_fdb_entry = "fake_fdb_entry" |
| 45 |
with mock.patch.object(l2pop_rpc.L2populationAgentNotifyAPI, |
| 46 |
'add_fdb_entries') as (mock_add_fdb): |
| 47 |
self.tunnel_call.trigger_l2pop_sync(self.context, |
| 48 |
fake_fdb_entry) |
| 49 |
mock_add_fdb.assert_called_with(self.context, |
| 50 |
fake_fdb_entry) |
| 51 |
|
| 52 |
def test_trigger_l2pop_delete(self): |
| 53 |
fake_fdb_entry = "fake_fdb_entry" |
| 54 |
fake_host = 'fake_host' |
| 55 |
with mock.patch.object(l2pop_rpc.L2populationAgentNotifyAPI, |
| 56 |
'remove_fdb_entries') as (mock_delete_fdb): |
| 57 |
self.tunnel_call.trigger_l2pop_delete(self.context, |
| 58 |
fake_fdb_entry, fake_host) |
| 59 |
mock_delete_fdb.assert_called_with(self.context, |
| 60 |
fake_fdb_entry, fake_host) |