check the block_device_allocate_retries

we need to check the value of the configuration item
block_device_allocate_retries in order to ensure to
retry at least once,done like that configuration
item network_allocate_retries

Change-Id: Ia5b65bd160cb4e740d21c1b51d234e14e33135e7
Closes-Bug:#1363558
This commit is contained in:
zhangtralon 2014-08-31 10:55:39 +08:00 committed by zhangchunlong1@huawei.com
parent ea662946ff
commit 3d5cb0face
2 changed files with 44 additions and 4 deletions

View File

@ -1203,18 +1203,28 @@ class ComputeManager(manager.Manager):
# TODO(yamahata): creating volume simultaneously
# reduces creation time?
# TODO(yamahata): eliminate dumb polling
attempts = 0
start = time.time()
while attempts < CONF.block_device_allocate_retries:
retries = CONF.block_device_allocate_retries
if retries < 0:
LOG.warn(_LW("Treating negative config value (%(retries)s) for "
"'block_device_retries' as 0."),
{'retries': retries})
# (1) treat negative config value as 0
# (2) the configured value is 0, one attempt should be made
# (3) the configured value is > 0, then the total number attempts
# is (retries + 1)
attempts = 1
if retries >= 1:
attempts = retries + 1
for attempt in range(1, attempts + 1):
volume = self.volume_api.get(context, vol_id)
volume_status = volume['status']
if volume_status not in ['creating', 'downloading']:
if volume_status != 'available':
LOG.warn(_("Volume id: %s finished being created but was"
" not set as 'available'"), vol_id)
return attempts + 1
return attempt
greenthread.sleep(CONF.block_device_allocate_retries_interval)
attempts += 1
# NOTE(harlowja): Should only happen if we ran out of attempts
raise exception.VolumeNotCreated(volume_id=vol_id,
seconds=int(time.time() - start),

View File

@ -522,6 +522,36 @@ class ComputeVolumeTestCase(BaseTestCase):
attempts = c._await_block_device_map_created(self.context, '1')
self.assertEqual(attempts, 3)
def test_await_block_device_created_retries_negative(self):
c = self.compute
self.flags(block_device_allocate_retries=-1)
self.flags(block_device_allocate_retries_interval=0.1)
def volume_get(context, vol_id):
return {
'status': 'available',
'id': 'blah',
}
self.stubs.Set(c.volume_api, 'get', volume_get)
attempts = c._await_block_device_map_created(self.context, '1')
self.assertEqual(1, attempts)
def test_await_block_device_created_retries_zero(self):
c = self.compute
self.flags(block_device_allocate_retries=0)
self.flags(block_device_allocate_retries_interval=0.1)
def volume_get(context, vol_id):
return {
'status': 'available',
'id': 'blah',
}
self.stubs.Set(c.volume_api, 'get', volume_get)
attempts = c._await_block_device_map_created(self.context, '1')
self.assertEqual(1, attempts)
def test_boot_volume_serial(self):
with (
mock.patch.object(objects.BlockDeviceMapping, 'save')