ovn-bgp-agent/ovn_bgp_agent/tests/unit/test_agent.py
Luis Tomas Bolivar a1ff266565 Ensure options are registered for unit testing
As part of commit [1] we moved the register options to a function,
that means unit tests need to be updated to register those option
in the setup if they are needed, otherwise we can get errors like:

Captured traceback:
~~~~~~~~~~~~~~~~~~~
Traceback (most recent call last):
  File "/builddir/build/BUILD/ovn-bgp-agent-0.3.1.dev112/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_bgp_watcher.py", line 878, in test_run_no_subnets_datapath
    CONF.set_override('expose_tenant_networks', False)
  File "/usr/lib/python3.9/site-packages/oslo_config/cfg.py", line 2059, in __inner
    result = f(self, *args, **kwargs)
  File "/usr/lib/python3.9/site-packages/oslo_config/cfg.py", line 2442, in set_override
    opt_info = self._get_opt_info(name, group)
  File "/usr/lib/python3.9/site-packages/oslo_config/cfg.py", line 2858, in _get_opt_info
    raise NoSuchOptError(opt_name, group)
oslo_config.cfg.NoSuchOptError: no such option expose_tenant_networks in group [DEFAULT]

[1] 90b6940b21

Change-Id: I138ab9a4ed6f7b1d0138129c00362f603fc4320a
2023-05-04 09:49:30 +02:00

41 lines
1.4 KiB
Python

# Copyright 2021 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest import mock
from ovn_bgp_agent import agent
from ovn_bgp_agent.tests import base as test_base
class TestAgent(test_base.TestCase):
@mock.patch('oslo_service.service.launch')
@mock.patch('ovn_bgp_agent.config.register_opts')
@mock.patch('ovn_bgp_agent.config.init')
@mock.patch('ovn_bgp_agent.config.setup_logging')
@mock.patch('ovn_bgp_agent.agent.BGPAgent')
def test_start(self, m_agent, m_setup_logging, m_config_init,
m_register_opts, m_oslo_launch):
m_launcher = mock.Mock()
m_oslo_launch.return_value = m_launcher
agent.start()
m_register_opts.assert_called()
m_config_init.assert_called()
m_setup_logging.assert_called()
m_agent.assert_called()
m_oslo_launch.assert_called()
m_launcher.wait.assert_called()