diff --git a/tests/test_cleanup.py b/tests/test_cleanup.py index 23b283797..9f4f1c8ff 100644 --- a/tests/test_cleanup.py +++ b/tests/test_cleanup.py @@ -384,12 +384,45 @@ def test_gc_pause_skipped_if_immediate(self, mock_abortable, mock_sr): # Never call runAbortable self.assertEqual(0, mock_abortable.call_count) + @mock.patch('sm.cleanup._gc_service_cmd', autospec=True) @mock.patch('sm.cleanup.SR', autospec=True) @mock.patch('sm.cleanup._abort') def test_lock_released_by_abort_when_held( self, mock_abort, - mock_sr): + mock_sr, + mock_stop): + """ + If _abort returns True make sure we release the lockGCActive which will + have been held by _abort, also check that we return True. + """ + self.setup_mock_sr(mock_sr) + + # Fake that abort returns True, so we hold lockGCActive. + mock_abort.return_value = True + + # Setup mock of release function. + cleanup.lockGCActive = TestRelease() + cleanup.lockGCActive.release = mock.Mock(return_value=None) + + mock_stop.return_value = (0, "", "") + + ret = cleanup.abort(str(mock_sr.uuid), False) + + # Pass on the return from _abort. + self.assertEqual(True, ret) + + # We hold lockGCActive so make sure we release it. + self.assertEqual(cleanup.lockGCActive.release.call_count, 1) + + @mock.patch('sm.cleanup._gc_service_cmd', autospec=True) + @mock.patch('sm.cleanup.SR', autospec=True) + @mock.patch('sm.cleanup._abort') + def test_lock_released_by_abort_when_held_stop_fail( + self, + mock_abort, + mock_sr, + mock_stop): """ If _abort returns True make sure we release the lockGCActive which will have been held by _abort, also check that we return True. @@ -403,6 +436,8 @@ def test_lock_released_by_abort_when_held( cleanup.lockGCActive = TestRelease() cleanup.lockGCActive.release = mock.Mock(return_value=None) + mock_stop.return_value = (1, "", "") + ret = cleanup.abort(str(mock_sr.uuid), False) # Pass on the return from _abort. diff --git a/tests/test_mpath_dmp.py b/tests/test_mpath_dmp.py index b3b118c9f..8156ace65 100644 --- a/tests/test_mpath_dmp.py +++ b/tests/test_mpath_dmp.py @@ -427,3 +427,43 @@ def exists(path): with self.assertRaises(SROSError): mpath_dmp.refresh('360a98000534b4f4e46704f5270674d70', 0) + + @mock.patch("sm.core.mpath_dmp._is_mpath_daemon_running", mock.MagicMock(return_value=True)) + @mock.patch('sm.core.mpath_dmp.util.pread2', autospec=True) + @mock.patch('sm.core.mpath_dmp.util.time.sleep', autospec=True) + @mock.patch('sm.core.mpath_dmp.os.path.exists', autospec=True) + def test_reset_device_not_found( + self, mock_exists, mock_sleep, mock_pread): + + mock_exists.return_value = False + + device_not_found_exception = util.CommandException(1, "", "device not found") + + side_effects = [0] + side_effects += 4 * [device_not_found_exception] + side_effects += [0] + mock_pread.side_effect = side_effects + + mpath_dmp.reset('360a98000534b4f4e46704f5270674d70', explicit_unmap=True) + + self.assertEqual(6, mock_pread.call_count) + + @mock.patch("sm.core.mpath_dmp._is_mpath_daemon_running", mock.MagicMock(return_value=True)) + @mock.patch('sm.core.mpath_dmp.util.pread2', autospec=True) + @mock.patch('sm.core.mpath_dmp.util.time.sleep', autospec=True) + @mock.patch('sm.core.mpath_dmp.os.path.exists', autospec=True) + def test_reset_flush_error( + self, mock_exists, mock_sleep, mock_pread): + + mock_exists.return_value = False + + device_not_found_exception = util.CommandException(1, "", "Some Random error") + + side_effects = [0] + side_effects += 4 * [device_not_found_exception] + mock_pread.side_effect = side_effects + + with self.assertRaises(util.CommandException): + mpath_dmp.reset('360a98000534b4f4e46704f5270674d70', explicit_unmap=True) + + self.assertEqual(5, mock_pread.call_count)