Debian Codegraph @

networking_l2gw/tests/unit/services/l2gateway/agent/test_l2gw_agent.py

raw
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.common import config as common_config
19 from neutron.tests import base
20
21 from oslo_config import cfg
22
23 from networking_l2gw.services.l2gateway.common import config
24 from networking_l2gw.services.l2gateway import l2gw_agent as agent
25
26
27 class TestL2gwAgent(base.BaseTestCase):
28 def setUp(self):
29 super().setUp()
30 config.register_ovsdb_opts_helper(cfg.CONF)
31
32 def test_start(self):
33 with mock.patch.object(
34 agent.n_rpc.Service, 'start'
35 ) as mock_start:
36 mgr = mock.Mock()
37 cfg.CONF.periodic_interval = mock.Mock(return_value=10)
38 agent_service = agent.L2gatewayAgentService('host',
39 'topic', mgr)
40 agent_service.start()
41 self.assertTrue(mock_start.called)
42
43 def test_main_l2gw_agent(self):
44 logging_str = 'neutron.conf.agent.common.setup_logging'
45 common_config_str = mock.patch.object(common_config, 'init').start()
46 with mock.patch.object(common_config_str, 'init'), \
47 mock.patch(logging_str), \
48 mock.patch.object(agent.service, 'launch') as mock_launch, \
49 mock.patch('sys.argv'), \
50 mock.patch.object(agent.manager, 'OVSDBManager'), \
51 mock.patch.object(cfg.CONF, 'register_opts'):
52 agent.main()
53 mock_launch.assert_called_once_with(cfg.CONF, mock.ANY)