]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix dangling patches in Cisco and Midonet tests
authorKevin Benton <blak111@gmail.com>
Sat, 12 Apr 2014 21:27:36 +0000 (21:27 +0000)
committerKevin Benton <blak111@gmail.com>
Sun, 13 Apr 2014 00:26:41 +0000 (00:26 +0000)
Cisco Nexus Tests:
Explicitly stops the patch to sys.modules immediately
after use to fix sporadic failures caused by the patch
not being handled correctly by mock.patch.stopall.

Midonet Interface Test:
Removes the double-patch of the 'device_exists' method
in ip_lib.

Closes-Bug: #1307025
Closes-Bug: #1307038
Change-Id: Ie22505bb8e406a61e40819d60c76d229916a6e01

neutron/tests/unit/cisco/test_nexus_plugin.py
neutron/tests/unit/test_linux_interface.py

index 58bf90f1f2fa9a43140230524517c501e371a869..ab41b22ea2c45debfc4e08549a1f1fc31b85913a 100644 (file)
@@ -13,6 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import contextlib
 import mock
 
 from oslo.config import cfg
@@ -148,12 +149,12 @@ class TestCiscoNexusPlugin(base.BaseTestCase):
         self.addCleanup(db.clear_db)
         # Use a mock netconf client
         self.mock_ncclient = mock.Mock()
-        self.patch_obj = mock.patch.dict('sys.modules',
-                                         {'ncclient': self.mock_ncclient})
-        self.patch_obj.start()
 
-        with mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin,
-                               '__init__', new=new_nexus_init):
+        with contextlib.nested(
+            mock.patch.dict('sys.modules', {'ncclient': self.mock_ncclient}),
+            mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin,
+                              '__init__', new=new_nexus_init)
+        ):
             self._cisco_nexus_plugin = cisco_nexus_plugin_v2.NexusPlugin()
 
         # Set the Cisco config module's first configured device IP address
index 9d278ea5109fe9fab898047242c2d6bd0942bfb9..0ecf2de0d125b95a520960235cb45a82ad430a91 100644 (file)
@@ -515,8 +515,6 @@ class TestMidonetInterfaceDriver(TestBase):
         self.conf = config.setup_conf()
         self.conf.register_opts(interface.OPTS)
         config.register_root_helper(self.conf)
-        self.device_exists_p = mock.patch.object(ip_lib, 'device_exists')
-        self.device_exists = self.device_exists_p.start()
         self.driver = interface.MidonetInterfaceDriver(self.conf)
         self.network_id = uuidutils.generate_uuid()
         self.port_id = uuidutils.generate_uuid()