1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
https://github.com/openstack/neutron/commit/d26dfed7d47926425bb55893da45f650d6549b9a
diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py
index ba76786..fa2c2c0 100644
--- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py
+++ b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py
@@ -97,11 +97,6 @@ def setUp(self):
super(TestLinuxBridgeAgent, self).setUp()
cfg.CONF.set_override('rpc_backend',
'neutron.openstack.common.rpc.impl_fake')
- self.lbmgr_patcher = mock.patch('neutron.plugins.linuxbridge.agent.'
- 'linuxbridge_neutron_agent.'
- 'LinuxBridgeManager')
- self.lbmgr_mock = self.lbmgr_patcher.start()
- self.addCleanup(self.lbmgr_patcher.stop)
self.execute_p = mock.patch.object(ip_lib.IPWrapper, '_execute')
self.execute = self.execute_p.start()
self.addCleanup(self.execute_p.stop)
@@ -113,8 +108,6 @@ def setUp(self):
self.get_mac.return_value = '00:00:00:00:00:01'
def test_update_devices_failed(self):
- lbmgr_instance = self.lbmgr_mock.return_value
- lbmgr_instance.update_devices.side_effect = RuntimeError
agent = linuxbridge_neutron_agent.LinuxBridgeNeutronAgentRPC({},
0,
None)
@@ -125,17 +118,18 @@ def info_mock(msg):
raise_exception[0] += 1
else:
raise RuntimeError()
-
- with mock.patch.object(linuxbridge_neutron_agent.LOG, 'info') as log:
- log.side_effect = info_mock
- with testtools.ExpectedException(RuntimeError):
- agent.daemon_loop()
- self.assertEqual(3, log.call_count)
+ with mock.patch.object(agent.br_mgr,
+ "update_devices") as update_devices:
+ update_devices.side_effect = RuntimeError
+ with mock.patch.object(linuxbridge_neutron_agent.LOG,
+ 'info') as log:
+ log.side_effect = info_mock
+ with testtools.ExpectedException(RuntimeError):
+ agent.daemon_loop()
+ self.assertEqual(3, log.call_count)
def test_process_network_devices_failed(self):
device_info = {'current': [1, 2, 3]}
- lbmgr_instance = self.lbmgr_mock.return_value
- lbmgr_instance.update_devices.return_value = device_info
agent = linuxbridge_neutron_agent.LinuxBridgeNeutronAgentRPC({},
0,
None)
@@ -147,15 +141,18 @@ def info_mock(msg):
else:
raise RuntimeError()
- with contextlib.nested(
- mock.patch.object(linuxbridge_neutron_agent.LOG, 'info'),
- mock.patch.object(agent, 'process_network_devices')
- ) as (log, process_network_devices):
- log.side_effect = info_mock
- process_network_devices.side_effect = RuntimeError
- with testtools.ExpectedException(RuntimeError):
- agent.daemon_loop()
- self.assertEqual(3, log.call_count)
+ with mock.patch.object(agent.br_mgr,
+ "update_devices") as update_devices:
+ update_devices.side_effect = device_info
+ with contextlib.nested(
+ mock.patch.object(linuxbridge_neutron_agent.LOG, 'info'),
+ mock.patch.object(agent, 'process_network_devices')
+ ) as (log, process_network_devices):
+ log.side_effect = info_mock
+ process_network_devices.side_effect = RuntimeError
+ with testtools.ExpectedException(RuntimeError):
+ agent.daemon_loop()
+ self.assertEqual(3, log.call_count)
class TestLinuxBridgeManager(base.BaseTestCase):
|