Merge "Huawei: Simplify wait_for_condition calls"

This commit is contained in:
Zuul 2018-12-07 13:45:30 +00:00 committed by Gerrit Code Review
commit b56ebd44b2
2 changed files with 19 additions and 27 deletions

View File

@ -2299,6 +2299,12 @@ class HuaweiTestBase(test.TestCase):
self.group = fake_group.fake_group_obj(
admin_contex, id=ID, status='available')
constants.DEFAULT_REPLICA_WAIT_INTERVAL = .1
constants.DEFAULT_REPLICA_WAIT_TIMEOUT = .5
constants.DEFAULT_WAIT_INTERVAL = .1
constants.DEFAULT_WAIT_TIMEOUT = .5
constants.MIGRATION_WAIT_INTERVAL = .1
def test_encode_name(self):
lun_name = huawei_utils.encode_name(self.volume.id)
self.assertEqual('21ec7341-ca82ece92e1ac480c963f1', lun_name)
@ -4117,7 +4123,7 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase):
replica.wait_volume_online(self.driver.client, lun_info)
with mock.patch.object(rest_client.RestClient, 'get_lun_info',
offline_status):
return_value=offline_status):
self.assertRaises(exception.VolumeBackendAPIException,
replica.wait_volume_online,
self.driver.client,
@ -4131,16 +4137,11 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase):
common_driver = replication.ReplicaCommonDriver(self.configuration, op)
self.mock_object(replication.PairOp, 'get_replica_info',
return_value={'SECRESACCESS': access_ro})
self.mock_object(huawei_utils.time, 'time',
side_effect=utils.generate_timeout_series(
constants.DEFAULT_REPLICA_WAIT_TIMEOUT))
common_driver.wait_second_access(pair_id, access_ro)
self.assertRaises(exception.VolumeBackendAPIException,
common_driver.wait_second_access, pair_id, access_rw)
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=utils.ZeroIntervalLoopingCall)
def test_wait_replica_ready(self):
normal_status = {
'RUNNINGSTATUS': constants.REPLICA_RUNNING_STATUS_NORMAL,

View File

@ -15,12 +15,11 @@
import hashlib
import json
import six
import time
from oslo_log import log as logging
from oslo_service import loopingcall
from oslo_utils import units
import retrying
import six
from cinder import exception
from cinder.i18n import _
@ -62,25 +61,17 @@ def old_encode_host_name(name):
def wait_for_condition(func, interval, timeout):
start_time = time.time()
def _inner():
try:
res = func()
except Exception as ex:
raise exception.VolumeBackendAPIException(data=ex)
if res:
raise loopingcall.LoopingCallDone()
if int(time.time()) - start_time > timeout:
msg = (_('wait_for_condition: %s timed out.')
% func.__name__)
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
timer = loopingcall.FixedIntervalLoopingCall(_inner)
timer.start(interval=interval).wait()
r = retrying.Retrying(retry_on_result=lambda result: not result,
retry_on_exception=lambda result: False,
wait_fixed=interval * 1000,
stop_max_delay=timeout * 1000)
try:
r.call(func)
except retrying.RetryError:
msg = _('wait_for_condition: %s timed out.') % func.__name__
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
def get_volume_size(volume):