Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion tests/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
40 changes: 40 additions & 0 deletions tests/test_mpath_dmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading