|
15 | 15 | # under the License. |
16 | 16 | from __future__ import unicode_literals |
17 | 17 |
|
| 18 | +import time |
18 | 19 | from unittest import TestCase |
19 | 20 |
|
20 | 21 | import ddt |
21 | 22 | import mock |
22 | 23 | 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 |
24 | 25 |
|
25 | 26 | from storops.exception import UnityHostIpInUseError, \ |
26 | 27 | UnityResourceNotFoundError, UnityHostInitiatorNotFoundError, \ |
@@ -376,7 +377,12 @@ def test_detach_with_retry_lun_modified_by_another_request(self): |
376 | 377 | def f(): |
377 | 378 | host.detach(lun) |
378 | 379 |
|
| 380 | + start = time.time() |
379 | 381 | 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)) |
380 | 386 |
|
381 | 387 | @patch_rest |
382 | 388 | def test_attach_attached_hlu(self): |
@@ -495,6 +501,24 @@ def test_attach_with_retry_hlu_in_use(self): |
495 | 501 | assert_that(calling(host._attach_with_retry).with_args(lun, True), |
496 | 502 | raises(UnityHluNumberInUseError)) |
497 | 503 |
|
| 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 | + |
498 | 522 | @patch_rest |
499 | 523 | def test_attach_with_retry_hlu_in_use_but_no_retry(self): |
500 | 524 | host = UnityHost(cli=t_rest(), _id='Host_24') |
|
0 commit comments