Skip to content

Commit 7ac580d

Browse files
authored
Unity: Detach host with retry (#346)
1 parent cedad6a commit 7ac580d

5 files changed

Lines changed: 57 additions & 2 deletions

File tree

storops/exception.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,3 +1510,8 @@ class UnityCompressionRequireAllFlashPoolError(UnityException):
15101510
@rest_exception
15111511
class UnityQuotaConfigModifyException(UnityException):
15121512
error_code = 0x900022a
1513+
1514+
1515+
@rest_exception
1516+
class UnityLunModifyByAnotherRequestException(UnityException):
1517+
error_code = 108008704

storops/unity/resource/host.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ def _get_host_luns(self, lun=None, snap=None, hlu=None):
191191

192192
return ret
193193

194-
def detach(self, lun_or_snap):
194+
@retry(limit=20, wait=5,
195+
on_error=ex.UnityLunModifyByAnotherRequestException)
196+
def _detach_with_retry(self, lun_or_snap):
197+
lun_or_snap.update()
195198
if self.host_luns:
196199
# To detach the `dummy luns` which are attached via legacy storops.
197200
dummy_lun_ids = [lun.get_id() for lun in self.host_luns.lun
@@ -205,6 +208,14 @@ def detach(self, lun_or_snap):
205208
pass
206209
return lun_or_snap.detach_from(self)
207210

211+
def detach(self, lun_or_snap):
212+
try:
213+
return self._detach_with_retry(lun_or_snap)
214+
except ex.UnityLunModifyByAnotherRequestException:
215+
log.error('Failed to detach lun or snap {} from host with '
216+
'20 times retry.'.format(lun_or_snap.name))
217+
raise
218+
208219
def detach_alu(self, lun):
209220
log.warn('Method detach_alu is deprecated. Use detach instead.')
210221
return lun.detach_from(self)

storops_test/unity/resource/test_host.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
UnityAttachAluExceedLimitError, UnitySnapAlreadyPromotedException, \
2929
SystemAPINotSupported, UnityHostInitiatorExistedError, \
3030
UnityResourceNotAttachedError, UnityNoHluAvailableError, \
31-
UnityHluNumberInUseError, UnityAttachExceedLimitError
31+
UnityHluNumberInUseError, UnityAttachExceedLimitError, \
32+
UnityLunModifyByAnotherRequestException
3233
from storops.unity.enums import HostTypeEnum, HostManageEnum, \
3334
HostPortTypeEnum, HealthEnum, HostInitiatorTypeEnum, \
3435
HostInitiatorSourceTypeEnum, HostInitiatorIscsiTypeEnum
@@ -367,6 +368,16 @@ def test_detach_alu(self):
367368
resp = host.detach_alu(lun)
368369
assert_that(resp.is_ok(), equal_to(True))
369370

371+
@patch_rest
372+
def test_detach_with_retry_lun_modified_by_another_request(self):
373+
host = UnityHost(cli=t_rest(), _id='Host_10')
374+
lun = UnityLun(_id='sv_5', cli=t_rest())
375+
376+
def f():
377+
host.detach(lun)
378+
379+
assert_that(f, raises(UnityLunModifyByAnotherRequestException))
380+
370381
@patch_rest
371382
def test_attach_attached_hlu(self):
372383
host = UnityHost(cli=t_rest(), _id='Host_10')

storops_test/unity/rest_data/storageResource/index.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,22 @@
884884
},
885885
"response": "empty.json"
886886
},
887+
{
888+
"url": "/api/instances/storageResource/sv_5/action/modifyLun?compact=True",
889+
"body": {
890+
"lunParameters": {
891+
"hostAccess": [
892+
{
893+
"host": {
894+
"id": "Host_1"
895+
},
896+
"accessMask": 3
897+
}
898+
]
899+
}
900+
},
901+
"response": "lun_modified_by_another_request.json"
902+
},
887903
{
888904
"url": "/api/instances/storageResource/sv_6/action/modifyLun?compact=True",
889905
"body": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"error": {
3+
"errorCode": 108008704,
4+
"httpStatusCode": 409,
5+
"messages": [
6+
{
7+
"en-US": "The requested operation has failed because the LUN has already been modified by another request. Please retry. (Error Code:0x6701500)"
8+
}
9+
],
10+
"created": "2021-05-11T03:52:56.102Z"
11+
}
12+
}

0 commit comments

Comments
 (0)