Skip to content

Commit

Permalink
Unity: Detach host with retry (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
yong-huang authored May 13, 2021
1 parent cedad6a commit 7ac580d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
5 changes: 5 additions & 0 deletions storops/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,3 +1510,8 @@ class UnityCompressionRequireAllFlashPoolError(UnityException):
@rest_exception
class UnityQuotaConfigModifyException(UnityException):
error_code = 0x900022a


@rest_exception
class UnityLunModifyByAnotherRequestException(UnityException):
error_code = 108008704
13 changes: 12 additions & 1 deletion storops/unity/resource/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ def _get_host_luns(self, lun=None, snap=None, hlu=None):

return ret

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

def detach(self, lun_or_snap):
try:
return self._detach_with_retry(lun_or_snap)
except ex.UnityLunModifyByAnotherRequestException:
log.error('Failed to detach lun or snap {} from host with '
'20 times retry.'.format(lun_or_snap.name))
raise

def detach_alu(self, lun):
log.warn('Method detach_alu is deprecated. Use detach instead.')
return lun.detach_from(self)
Expand Down
13 changes: 12 additions & 1 deletion storops_test/unity/resource/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
UnityAttachAluExceedLimitError, UnitySnapAlreadyPromotedException, \
SystemAPINotSupported, UnityHostInitiatorExistedError, \
UnityResourceNotAttachedError, UnityNoHluAvailableError, \
UnityHluNumberInUseError, UnityAttachExceedLimitError
UnityHluNumberInUseError, UnityAttachExceedLimitError, \
UnityLunModifyByAnotherRequestException
from storops.unity.enums import HostTypeEnum, HostManageEnum, \
HostPortTypeEnum, HealthEnum, HostInitiatorTypeEnum, \
HostInitiatorSourceTypeEnum, HostInitiatorIscsiTypeEnum
Expand Down Expand Up @@ -367,6 +368,16 @@ def test_detach_alu(self):
resp = host.detach_alu(lun)
assert_that(resp.is_ok(), equal_to(True))

@patch_rest
def test_detach_with_retry_lun_modified_by_another_request(self):
host = UnityHost(cli=t_rest(), _id='Host_10')
lun = UnityLun(_id='sv_5', cli=t_rest())

def f():
host.detach(lun)

assert_that(f, raises(UnityLunModifyByAnotherRequestException))

@patch_rest
def test_attach_attached_hlu(self):
host = UnityHost(cli=t_rest(), _id='Host_10')
Expand Down
16 changes: 16 additions & 0 deletions storops_test/unity/rest_data/storageResource/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,22 @@
},
"response": "empty.json"
},
{
"url": "/api/instances/storageResource/sv_5/action/modifyLun?compact=True",
"body": {
"lunParameters": {
"hostAccess": [
{
"host": {
"id": "Host_1"
},
"accessMask": 3
}
]
}
},
"response": "lun_modified_by_another_request.json"
},
{
"url": "/api/instances/storageResource/sv_6/action/modifyLun?compact=True",
"body": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"error": {
"errorCode": 108008704,
"httpStatusCode": 409,
"messages": [
{
"en-US": "The requested operation has failed because the LUN has already been modified by another request. Please retry. (Error Code:0x6701500)"
}
],
"created": "2021-05-11T03:52:56.102Z"
}
}

0 comments on commit 7ac580d

Please sign in to comment.