Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity: Attach with retry if LUN being modified #354

Merged
merged 1 commit into from
Jan 24, 2022
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
4 changes: 4 additions & 0 deletions storops/unity/resource/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def _random_hlu_number(self):
max=MAX_HLU_NUMBER))

@version('<4.4.0') # noqa
@retry(limit=6, wait=5,
on_error=ex.UnityLunModifyByAnotherRequestException)
@retry(limit=5, on_error=ex.UnityHluNumberInUseError)
def _attach_with_retry(self, lun_or_snap, skip_hlu_0):
# Before 4.4.0 (Osprey), it didn't support to pass in hlu when
Expand All @@ -251,6 +253,8 @@ def _attach_with_retry(self, lun_or_snap, skip_hlu_0):
return host_lun.hlu

@version('>=4.4.0') # noqa
@retry(limit=6, wait=5,
on_error=ex.UnityLunModifyByAnotherRequestException)
@retry(limit=5, on_error=ex.UnityHluNumberInUseError)
def _attach_with_retry(self, lun_or_snap, skip_hlu_0):
# From 4.4.0 (Osprey), it supported to pass in hlu when attaching LUN,
Expand Down
26 changes: 25 additions & 1 deletion storops_test/unity/resource/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# under the License.
from __future__ import unicode_literals

import time
from unittest import TestCase

import ddt
import mock
from hamcrest import equal_to, assert_that, instance_of, raises, none, \
only_contains, not_none, is_not, calling
only_contains, not_none, is_not, calling, greater_than

from storops.exception import UnityHostIpInUseError, \
UnityResourceNotFoundError, UnityHostInitiatorNotFoundError, \
Expand Down Expand Up @@ -376,7 +377,12 @@ def test_detach_with_retry_lun_modified_by_another_request(self):
def f():
host.detach(lun)

start = time.time()
assert_that(f, raises(UnityLunModifyByAnotherRequestException))
end = time.time()
# _detach_with_retry retry 20 times with 5s interval, it will take
# at least (20 - 1) * 5 = 95s to finish the retries.
assert_that(end - start, greater_than(95))

@patch_rest
def test_attach_attached_hlu(self):
Expand Down Expand Up @@ -495,6 +501,24 @@ def test_attach_with_retry_hlu_in_use(self):
assert_that(calling(host._attach_with_retry).with_args(lun, True),
raises(UnityHluNumberInUseError))

@patch_rest
def test_attach_with_retry_lun_modify_by_another_request(self):
host = UnityHost(cli=t_rest(), _id='Host_23')
lun = UnityLun(_id='sv_5610', cli=t_rest())
lun.is_cg_member = False
mock_lun_modifying = mock.Mock(
side_effect=UnityLunModifyByAnotherRequestException)
with mock.patch('storops.unity.resource.host.UnityHost.'
'_modify_hlu',
new=mock_lun_modifying):
start = time.time()
assert_that(calling(host._attach_with_retry).with_args(lun, True),
raises(UnityLunModifyByAnotherRequestException))
end = time.time()
# _attach_with_retry retry 6 times with 5s interval, it will take
# at least (6 - 1) * 5 = 25s to finish the retries.
assert_that(end - start, greater_than(25))

@patch_rest
def test_attach_with_retry_hlu_in_use_but_no_retry(self):
host = UnityHost(cli=t_rest(), _id='Host_24')
Expand Down