|
| 1 | +# |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 | +# not use this file except in compliance with the License. You may obtain |
| 4 | +# a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | +# License for the specific language governing permissions and limitations |
| 12 | +# under the License. |
| 13 | +# |
| 14 | +import sys |
| 15 | +from unittest import mock |
| 16 | + |
| 17 | +from oslo_config import cfg |
| 18 | +from oslo_log import log |
| 19 | + |
| 20 | +from ovn_octavia_provider.cmd import octavia_ovn_db_sync_util |
| 21 | +from ovn_octavia_provider import driver |
| 22 | +from ovn_octavia_provider.tests.unit import base as ovn_base |
| 23 | + |
| 24 | + |
| 25 | +class TestCMD(ovn_base.TestOvnOctaviaBase): |
| 26 | + |
| 27 | + def setUp(self): |
| 28 | + super().setUp() |
| 29 | + mock.patch.object(log, 'register_options').start() |
| 30 | + self.m_cfg = mock.patch.object( |
| 31 | + cfg.ConfigOpts, '__call__').start() |
| 32 | + |
| 33 | + @mock.patch.object(driver.OvnProviderDriver, 'do_sync') |
| 34 | + def test_octavia_ovn_db_sync_util(self, m_sync): |
| 35 | + octavia_ovn_db_sync_util.main() |
| 36 | + m_sync.assert_called_once_with(provider='ovn') |
| 37 | + |
| 38 | + @mock.patch.object(cfg.CONF, 'set_override') |
| 39 | + @mock.patch.object(driver.OvnProviderDriver, 'do_sync') |
| 40 | + def test_octavia_ovn_db_sync_util_with_debug(self, m_sync, m_cfg_or): |
| 41 | + return_value = ['octavia-ovn-db-sync-util', |
| 42 | + '--debug'] |
| 43 | + return_value_no_debug = ['octavia-ovn-db-sync-util'] |
| 44 | + with mock.patch.object(sys, 'argv', return_value): |
| 45 | + octavia_ovn_db_sync_util.main() |
| 46 | + with mock.patch.object(sys, 'argv', return_value_no_debug): |
| 47 | + octavia_ovn_db_sync_util.main() |
| 48 | + m_cfg_or.assert_has_calls([mock.call('debug', True), |
| 49 | + mock.call('debug', False)]) |
| 50 | + |
| 51 | + @mock.patch.object(octavia_ovn_db_sync_util, 'LOG') |
| 52 | + def test_octavia_ovn_db_sync_util_config_error(self, m_log): |
| 53 | + self.m_cfg.side_effect = [TypeError()] |
| 54 | + self.assertRaises(TypeError, octavia_ovn_db_sync_util.main) |
| 55 | + msg = ("Error parsing the configuration values. Please verify.") |
| 56 | + m_log.error.assert_called_once_with(msg) |
0 commit comments