Merge "Huawei: Simplify wait_for_condition calls"
This commit is contained in:
commit
b56ebd44b2
@ -2299,6 +2299,12 @@ class HuaweiTestBase(test.TestCase):
|
|||||||
self.group = fake_group.fake_group_obj(
|
self.group = fake_group.fake_group_obj(
|
||||||
admin_contex, id=ID, status='available')
|
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):
|
def test_encode_name(self):
|
||||||
lun_name = huawei_utils.encode_name(self.volume.id)
|
lun_name = huawei_utils.encode_name(self.volume.id)
|
||||||
self.assertEqual('21ec7341-ca82ece92e1ac480c963f1', lun_name)
|
self.assertEqual('21ec7341-ca82ece92e1ac480c963f1', lun_name)
|
||||||
@ -4117,7 +4123,7 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase):
|
|||||||
replica.wait_volume_online(self.driver.client, lun_info)
|
replica.wait_volume_online(self.driver.client, lun_info)
|
||||||
|
|
||||||
with mock.patch.object(rest_client.RestClient, 'get_lun_info',
|
with mock.patch.object(rest_client.RestClient, 'get_lun_info',
|
||||||
offline_status):
|
return_value=offline_status):
|
||||||
self.assertRaises(exception.VolumeBackendAPIException,
|
self.assertRaises(exception.VolumeBackendAPIException,
|
||||||
replica.wait_volume_online,
|
replica.wait_volume_online,
|
||||||
self.driver.client,
|
self.driver.client,
|
||||||
@ -4131,16 +4137,11 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase):
|
|||||||
common_driver = replication.ReplicaCommonDriver(self.configuration, op)
|
common_driver = replication.ReplicaCommonDriver(self.configuration, op)
|
||||||
self.mock_object(replication.PairOp, 'get_replica_info',
|
self.mock_object(replication.PairOp, 'get_replica_info',
|
||||||
return_value={'SECRESACCESS': access_ro})
|
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)
|
common_driver.wait_second_access(pair_id, access_ro)
|
||||||
self.assertRaises(exception.VolumeBackendAPIException,
|
self.assertRaises(exception.VolumeBackendAPIException,
|
||||||
common_driver.wait_second_access, pair_id, access_rw)
|
common_driver.wait_second_access, pair_id, access_rw)
|
||||||
|
|
||||||
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
|
|
||||||
new=utils.ZeroIntervalLoopingCall)
|
|
||||||
def test_wait_replica_ready(self):
|
def test_wait_replica_ready(self):
|
||||||
normal_status = {
|
normal_status = {
|
||||||
'RUNNINGSTATUS': constants.REPLICA_RUNNING_STATUS_NORMAL,
|
'RUNNINGSTATUS': constants.REPLICA_RUNNING_STATUS_NORMAL,
|
||||||
|
@ -15,12 +15,11 @@
|
|||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import six
|
|
||||||
import time
|
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_service import loopingcall
|
|
||||||
from oslo_utils import units
|
from oslo_utils import units
|
||||||
|
import retrying
|
||||||
|
import six
|
||||||
|
|
||||||
from cinder import exception
|
from cinder import exception
|
||||||
from cinder.i18n import _
|
from cinder.i18n import _
|
||||||
@ -62,26 +61,18 @@ def old_encode_host_name(name):
|
|||||||
|
|
||||||
|
|
||||||
def wait_for_condition(func, interval, timeout):
|
def wait_for_condition(func, interval, timeout):
|
||||||
start_time = time.time()
|
|
||||||
|
|
||||||
def _inner():
|
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:
|
try:
|
||||||
res = func()
|
r.call(func)
|
||||||
except Exception as ex:
|
except retrying.RetryError:
|
||||||
raise exception.VolumeBackendAPIException(data=ex)
|
msg = _('wait_for_condition: %s timed out.') % func.__name__
|
||||||
|
|
||||||
if res:
|
|
||||||
raise loopingcall.LoopingCallDone()
|
|
||||||
|
|
||||||
if int(time.time()) - start_time > timeout:
|
|
||||||
msg = (_('wait_for_condition: %s timed out.')
|
|
||||||
% func.__name__)
|
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exception.VolumeBackendAPIException(data=msg)
|
raise exception.VolumeBackendAPIException(data=msg)
|
||||||
|
|
||||||
timer = loopingcall.FixedIntervalLoopingCall(_inner)
|
|
||||||
timer.start(interval=interval).wait()
|
|
||||||
|
|
||||||
|
|
||||||
def get_volume_size(volume):
|
def get_volume_size(volume):
|
||||||
"""Calculate the volume size.
|
"""Calculate the volume size.
|
||||||
|
Loading…
Reference in New Issue
Block a user