From 62191c866a4e5117e47f4aece72fe5fc7bc520e5 Mon Sep 17 00:00:00 2001 From: "Jay S. Bryant" Date: Fri, 3 Apr 2015 14:19:28 -0500 Subject: [PATCH] Mock wait_for_volume_removal in test_brick_connector Systems where /dev/disk/by-path did exist were failing unit test for test_connect_volume, test_connect_volume_with_alternative_targets and test_connect_volume_with_alternative_targets_primary_error in cinder.tests.test_brick_connector . The problem was that the test cases were mocking out os.path to return exists. This resulted in the new code from commit 43029941219505bc3861dd285e3393e08c76b433 never being able to exit the wait_for_volume_removal loop. To avoid this problem I am mocking out wait_for_volume_removal for these test cases. wait_for_volume_removal is tested elsewhere and not relevant for these test cases. Change-Id: Ib7f75c852f9c79f261e319be0c1e3fd21acab8f1 Closes-bug: 1440153 --- cinder/tests/brick/test_brick_connector.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cinder/tests/brick/test_brick_connector.py b/cinder/tests/brick/test_brick_connector.py index 4a55cb5e1..cc2509f60 100644 --- a/cinder/tests/brick/test_brick_connector.py +++ b/cinder/tests/brick/test_brick_connector.py @@ -27,6 +27,7 @@ from cinder.brick import exception from cinder.brick.initiator import connector from cinder.brick.initiator import host_driver from cinder.brick.initiator import linuxfc +from cinder.brick.initiator import linuxscsi from cinder.i18n import _LE from cinder.openstack.common import loopingcall from cinder import test @@ -267,12 +268,17 @@ class ISCSIConnectorTestCase(ConnectorTestCase): @test.testtools.skipUnless(os.path.exists('/dev/disk/by-path'), 'Test requires /dev/disk/by-path') - def test_connect_volume(self): + @mock.patch.object(linuxscsi.LinuxSCSI, 'wait_for_volume_removal', + return_value=None) + def test_connect_volume(self, mock_wait_for_vol_rem): self._test_connect_volume({}, []) @test.testtools.skipUnless(os.path.exists('/dev/disk/by-path'), 'Test requires /dev/disk/by-path') - def test_connect_volume_with_alternative_targets(self): + @mock.patch.object(linuxscsi.LinuxSCSI, 'wait_for_volume_removal', + return_value=None) + def test_connect_volume_with_alternative_targets(self, + mock_wait_for_vol_rem): location = '10.0.2.15:3260' location2 = '10.0.3.15:3260' iqn = 'iqn.2010-10.org.openstack:volume-00000001' @@ -295,8 +301,10 @@ class ISCSIConnectorTestCase(ConnectorTestCase): 'Test requires /dev/disk/by-path') @mock.patch.object(os.path, 'exists') @mock.patch.object(connector.ISCSIConnector, '_run_iscsiadm') + @mock.patch.object(linuxscsi.LinuxSCSI, 'wait_for_volume_removal', + return_value=None) def test_connect_volume_with_alternative_targets_primary_error( - self, mock_iscsiadm, mock_exists): + self, mock_wait_for_vol_rem, mock_iscsiadm, mock_exists): location = '10.0.2.15:3260' location2 = '10.0.3.15:3260' name = 'volume-00000001' -- 2.45.2