Debian Codegraph @

neutron_taas/tests/unit/services/ovn/ovsdb/test_impl_idl_taas.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import os
14 from unittest import mock
15
16 from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
17 from neutron.tests import base
18 from ovs.db import idl as ovs_idl
19 from ovsdbapp.backend import ovs_idl as real_ovs_idl
20 from ovsdbapp.backend.ovs_idl import idlutils
21
22 from neutron_taas.services.taas.service_drivers.ovn.ovsdb import impl_idl_taas
23
24
25 basedir = os.path.dirname(os.path.abspath(__file__))
26 schema_files = {
27 'OVN_Northbound': os.path.join(basedir,
28 'schema_files', 'ovn-nb.ovsschema'),
29 }
30
31
32 class TestOvnNbIdlForTaas(base.BaseTestCase):
33
34 def setUp(self):
35 super().setUp()
36 ovn_conf.register_opts()
37 self.mock_gsh = mock.patch.object(
38 idlutils, 'get_schema_helper',
39 side_effect=lambda x, y: ovs_idl.SchemaHelper(
40 location=schema_files['OVN_Northbound'])).start()
41 self.idl_taas = impl_idl_taas.OvnNbIdlForTaas()
42
43 def test__get_ovsdb_helper(self):
44 self.mock_gsh.reset_mock()
45 self.idl_taas._get_ovsdb_helper('foo')
46 self.mock_gsh.assert_called_once_with('foo', 'OVN_Northbound')
47
48 @mock.patch.object(real_ovs_idl.Backend, 'autocreate_indices', mock.Mock(),
49 create=True)
50 def test_start(self):
51 with mock.patch('ovsdbapp.backend.ovs_idl.connection.Connection',
52 side_effect=lambda x, timeout: mock.Mock()):
53 idl_taas_1 = impl_idl_taas.OvnNbIdlForTaas()
54 ret_taas_1 = idl_taas_1.start()
55 id1 = id(ret_taas_1.ovsdb_connection)
56 idl_taas_2 = impl_idl_taas.OvnNbIdlForTaas()
57 ret_taas_2 = idl_taas_2.start()
58 id2 = id(ret_taas_2.ovsdb_connection)
59 self.assertNotEqual(id1, id2)
60
61 @mock.patch('ovsdbapp.backend.ovs_idl.connection.Connection')
62 def test_stop(self, mock_conn):
63 mock_conn.stop.return_value = False
64 with mock.patch.object(self.idl_taas, 'close') as mock_close:
65 self.idl_taas.start()
66 self.idl_taas.stop()
67 mock_close.assert_called_once_with()
68
69 @mock.patch('ovsdbapp.backend.ovs_idl.connection.Connection')
70 def test_stop_no_connection(self, mock_conn):
71 mock_conn.stop.return_value = False
72 with mock.patch.object(self.idl_taas, 'close') as mock_close:
73 self.idl_taas.stop()
74 mock_close.assert_called_once_with()