Fix TypeError: <MagicMock name='LinuxBridgeManager().local_ip'

This patch fixes an error that does not result in a test failure but
causes the following error to be logged in the test logs:

TypeError: <MagicMock name='LinuxBridgeManager().local_ip' id='666599248'>
is not JSON serializable

Related-Bug: #1234857

Change-Id: I65cdd997745d8b760031f8f32e3c10682ad2288e
(cherry picked from commit: d26dfed7d4)
This commit is contained in:
Aaron Rosen 2013-10-22 15:33:45 -07:00
parent 8fdcb08ed3
commit decd4e7ad8
1 changed files with 21 additions and 24 deletions

View File

@ -97,11 +97,6 @@ class TestLinuxBridgeAgent(base.BaseTestCase):
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 @@ class TestLinuxBridgeAgent(base.BaseTestCase):
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 @@ class TestLinuxBridgeAgent(base.BaseTestCase):
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 @@ class TestLinuxBridgeAgent(base.BaseTestCase):
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):