1 # Copyright 2013 Red Hat, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
17 from neutron.agent.common import base_polling
18 from neutron.agent.linux import polling
19 from neutron.tests import base
22 class TestGetPollingManager(base.BaseTestCase):
24 def test_return_always_poll_by_default(self):
25 with polling.get_polling_manager() as pm:
26 self.assertEqual(pm.__class__, base_polling.AlwaysPoll)
28 def test_manage_polling_minimizer(self):
29 mock_target = 'neutron.agent.linux.polling.InterfacePollingMinimizer'
30 with mock.patch('%s.start' % mock_target) as mock_start:
31 with mock.patch('%s.stop' % mock_target) as mock_stop:
32 with polling.get_polling_manager(minimize_polling=True) as pm:
33 self.assertEqual(pm.__class__,
34 polling.InterfacePollingMinimizer)
35 mock_stop.assert_has_calls([mock.call()])
36 mock_start.assert_has_calls([mock.call()])
39 class TestInterfacePollingMinimizer(base.BaseTestCase):
42 super(TestInterfacePollingMinimizer, self).setUp()
43 self.pm = polling.InterfacePollingMinimizer()
45 def test_start_calls_monitor_start(self):
46 with mock.patch.object(self.pm._monitor, 'start') as mock_start:
48 mock_start.assert_called_with()
50 def test_stop_calls_monitor_stop(self):
51 with mock.patch.object(self.pm._monitor, 'stop') as mock_stop:
53 mock_stop.assert_called_with()
55 def mock_has_updates(self, return_value):
56 target = ('neutron.agent.linux.ovsdb_monitor.SimpleInterfaceMonitor'
60 new_callable=mock.PropertyMock(return_value=return_value),
63 def test__is_polling_required_returns_when_updates_are_present(self):
64 with self.mock_has_updates(True):
65 self.assertTrue(self.pm._is_polling_required())