| 1 |
# Copyright (c) 2015 OpenStack Foundation. |
| 2 |
# All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
from unittest import mock |
| 17 |
|
| 18 |
from neutron.tests import base |
| 19 |
from neutron_lib import rpc as n_rpc |
| 20 |
from oslo_config import cfg |
| 21 |
import ovs.jsonrpc |
| 22 |
from ovsdbapp.backend.ovs_idl import command as cmd |
| 23 |
from ovsdbapp.backend.ovs_idl import idlutils |
| 24 |
|
| 25 |
from networking_l2gw.services.l2gateway.agent.ovsdb import impl_idl |
| 26 |
|
| 27 |
|
| 28 |
class Msg: |
| 29 |
id = 0 |
| 30 |
type = 1 |
| 31 |
method = 'update' |
| 32 |
params = [ |
| 33 |
None, {'Global': { |
| 34 |
'381d60b5-6171-484a-842f-49f3e83bb586': {'new': { |
| 35 |
'switches': ['uuid', '03eebc5d-153f-4b03-8efa-45d22eb9942f'], |
| 36 |
'other_config': [ |
| 37 |
'map', [] |
| 38 |
], |
| 39 |
'managers': ['set', []]} |
| 40 |
}}, |
| 41 |
'Physical_Switch': {'03eebc5d-153f-4b03-8efa-45d22eb9942f': { |
| 42 |
'new': {'management_ips': ['set', []], |
| 43 |
'description': '', 'other_config': ['map', []], |
| 44 |
'tunnel_ips': ['set', []], |
| 45 |
'switch_fault_status': ['set', []], |
| 46 |
'ports': ['set', []], 'tunnels': ['set', []], |
| 47 |
'name': 'ps1'}}}} |
| 48 |
] |
| 49 |
|
| 50 |
|
| 51 |
class SimpleIdlTests(base.BaseTestCase): |
| 52 |
def setUp(self): |
| 53 |
super().setUp() |
| 54 |
n_rpc.init(cfg.CONF) |
| 55 |
|
| 56 |
def test_list_physical_switches(self): |
| 57 |
session_mock = mock.patch.object( |
| 58 |
ovs.jsonrpc.Session, |
| 59 |
'open', |
| 60 |
return_value=ovs.jsonrpc.Session(None, None, None) |
| 61 |
) |
| 62 |
wait_mock = mock.patch.object(idlutils, 'wait_for_change') |
| 63 |
|
| 64 |
execute_mock = mock.patch.object( |
| 65 |
cmd.BaseCommand, |
| 66 |
'execute', |
| 67 |
return_value=['ps1']) |
| 68 |
with session_mock, execute_mock, wait_mock: |
| 69 |
ovs.jsonrpc.Session.run = mock.MagicMock( |
| 70 |
return_value=mock.MagicMock(return_value='myrun')) |
| 71 |
ovs.jsonrpc.Session.get_seqno = mock.MagicMock(return_value=None) |
| 72 |
ovs.jsonrpc.Session.wait = mock.MagicMock(return_value=None) |
| 73 |
ovs.jsonrpc.Session.is_connected = mock.MagicMock( |
| 74 |
return_value=True) |
| 75 |
ovs.jsonrpc.Session.recv = mock.MagicMock( |
| 76 |
side_effect=[Msg, None, None, None, None]) |
| 77 |
|
| 78 |
self.db = impl_idl.OvsdbHardwareVtepIdl(self, |
| 79 |
'tcp:fake_ip:fake_port', |
| 80 |
3) |
| 81 |
|
| 82 |
sw_list = self.db.get_physical_sw_list().execute() |
| 83 |
|
| 84 |
assert (sw_list is not None) & (sw_list[0] == 'ps1') |
| 85 |
print('physical switch: %s' % sw_list) |