]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix TypeError: <MagicMock name='LinuxBridgeManager().local_ip'
authorAaron Rosen <arosen@nicira.com>
Tue, 22 Oct 2013 22:33:45 +0000 (15:33 -0700)
committerGerrit Code Review <review@openstack.org>
Thu, 24 Oct 2013 02:24:56 +0000 (02:24 +0000)
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

neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py

index ba76786603d4fa38d5170ff96258834a89184376..fa2c2c0acde48370e5124a26c7584bffadd59151 100644 (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):