Skip to content

Commit 71510f8

Browse files
authored
Unity: Attach with retry if LUN being modified (#354)
1 parent 7092c51 commit 71510f8

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

storops/unity/resource/host.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ def _random_hlu_number(self):
236236
max=MAX_HLU_NUMBER))
237237

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

253255
@version('>=4.4.0') # noqa
256+
@retry(limit=6, wait=5,
257+
on_error=ex.UnityLunModifyByAnotherRequestException)
254258
@retry(limit=5, on_error=ex.UnityHluNumberInUseError)
255259
def _attach_with_retry(self, lun_or_snap, skip_hlu_0):
256260
# From 4.4.0 (Osprey), it supported to pass in hlu when attaching LUN,

storops_test/unity/resource/test_host.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
# under the License.
1616
from __future__ import unicode_literals
1717

18+
import time
1819
from unittest import TestCase
1920

2021
import ddt
2122
import mock
2223
from hamcrest import equal_to, assert_that, instance_of, raises, none, \
23-
only_contains, not_none, is_not, calling
24+
only_contains, not_none, is_not, calling, greater_than
2425

2526
from storops.exception import UnityHostIpInUseError, \
2627
UnityResourceNotFoundError, UnityHostInitiatorNotFoundError, \
@@ -376,7 +377,12 @@ def test_detach_with_retry_lun_modified_by_another_request(self):
376377
def f():
377378
host.detach(lun)
378379

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

381387
@patch_rest
382388
def test_attach_attached_hlu(self):
@@ -495,6 +501,24 @@ def test_attach_with_retry_hlu_in_use(self):
495501
assert_that(calling(host._attach_with_retry).with_args(lun, True),
496502
raises(UnityHluNumberInUseError))
497503

504+
@patch_rest
505+
def test_attach_with_retry_lun_modify_by_another_request(self):
506+
host = UnityHost(cli=t_rest(), _id='Host_23')
507+
lun = UnityLun(_id='sv_5610', cli=t_rest())
508+
lun.is_cg_member = False
509+
mock_lun_modifying = mock.Mock(
510+
side_effect=UnityLunModifyByAnotherRequestException)
511+
with mock.patch('storops.unity.resource.host.UnityHost.'
512+
'_modify_hlu',
513+
new=mock_lun_modifying):
514+
start = time.time()
515+
assert_that(calling(host._attach_with_retry).with_args(lun, True),
516+
raises(UnityLunModifyByAnotherRequestException))
517+
end = time.time()
518+
# _attach_with_retry retry 6 times with 5s interval, it will take
519+
# at least (6 - 1) * 5 = 25s to finish the retries.
520+
assert_that(end - start, greater_than(25))
521+
498522
@patch_rest
499523
def test_attach_with_retry_hlu_in_use_but_no_retry(self):
500524
host = UnityHost(cli=t_rest(), _id='Host_24')

0 commit comments

Comments
 (0)