Skip to content

Commit

Permalink
Unity: skip hlu0 for snap host access (#314)
Browse files Browse the repository at this point in the history
Modify hlu to non-zero after attaching the snap to the host.
  • Loading branch information
Murray-LIANG authored May 26, 2020
1 parent f20f215 commit 3e32785
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion storops/connection/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import requests
import six
from requests.exceptions import ConnectTimeout
from requests.exceptions import RequestException
from retryz import retry

Expand Down Expand Up @@ -124,7 +125,7 @@ def _cs_request(self, url, method, **kwargs):
self.base_url + url,
method,
**kwargs)
except requests.ConnectTimeout as ex:
except ConnectTimeout as ex:
raise StoropsConnectTimeoutError(message=str(ex))

def _get_limit(self):
Expand Down
10 changes: 9 additions & 1 deletion storops/unity/resource/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ 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,
# but not when attaching snap.
from storops.unity.resource.lun import UnityLun as _UnityLun
if skip_hlu_0 and isinstance(lun_or_snap, _UnityLun):
is_lun = isinstance(lun_or_snap, _UnityLun)
if skip_hlu_0 and is_lun:
candidate_hlu = self._random_hlu_number()
lun_or_snap.attach_to(self, hlu=candidate_hlu)
self.update()
Expand All @@ -254,6 +255,13 @@ def _attach_with_retry(self, lun_or_snap, skip_hlu_0):
lun_or_snap.attach_to(self)
self.update()
host_lun = self.get_host_lun(lun_or_snap)

# Use the old way to modify the hlu after attaching snap if we need
# to skip hlu0 for a snapshot.
if (not is_lun) and skip_hlu_0 and host_lun.hlu == 0:
candidate_hlu = self._random_hlu_number()
self._modify_hlu(host_lun, candidate_hlu)
return candidate_hlu
return host_lun.hlu

def attach(self, lun_or_snap, skip_hlu_0=False):
Expand Down
34 changes: 33 additions & 1 deletion storops_test/unity/resource/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def test_attach_with_retry_skip_hlu_0(self):
assert_that(hlu, equal_to(12781))

@patch_rest
def test_attach_with_retry_member_snap_skip_hlu_0(self):
def test_attach_with_retry_snap_skip_hlu_0(self):
host = UnityHost(cli=t_rest(), _id='Host_27')
snap = UnitySnap(_id='38654705831', cli=t_rest())
with mock.patch('storops.unity.resource.host.UnityHost.'
Expand All @@ -427,6 +427,38 @@ def test_attach_with_retry_member_snap_skip_hlu_0(self):
assert_that(hlu, is_not(equal_to(0)))
assert_that(hlu, equal_to(12781))

@patch_rest
def test_attach_with_retry_snap_not_skip_hlu_0(self):
host = UnityHost(cli=t_rest(), _id='Host_27')
snap = UnitySnap(_id='38654705831', cli=t_rest())
with mock.patch('storops.unity.resource.host.UnityHost.'
'_random_hlu_number', new=lambda _: 12781):
hlu = host._attach_with_retry(snap, False)
assert_that(hlu, equal_to(0))

@patch_rest
def test_attach_with_retry_snap_skip_hlu_0_5_0_0(self):
host = UnityHost(cli=t_rest(), _id='Host_27')
snap = UnitySnap(_id='38654705831', cli=t_rest(version='5.0.0'))
with mock.patch('storops.unity.resource.host.UnityHost.'
'_random_hlu_number', new=lambda _: 12782):
with mock.patch('storops.unity.resource.host.UnityHost.'
'_modify_hlu') as mock_modify_hlu:
hlu = host._attach_with_retry(snap, True)
host_lun = host.get_host_lun(snap)
mock_modify_hlu.assert_called_with(host_lun, 12782)
assert_that(hlu, equal_to(12782))

@patch_rest
def test_attach_with_retry_snap_not_skip_hlu_0_5_0_0(self):
host = UnityHost(cli=t_rest(), _id='Host_27')
snap = UnitySnap(_id='38654705831', cli=t_rest(version='5.0.0'))
with mock.patch('storops.unity.resource.host.UnityHost.'
'_modify_hlu') as mock_modify_hlu:
hlu = host._attach_with_retry(snap, False)
assert_that(mock_modify_hlu.called, equal_to(False))
assert_that(hlu, equal_to(0))

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

0 comments on commit 3e32785

Please sign in to comment.