Merge "check the block_device_allocate_retries"

This commit is contained in:
Jenkins 2014-09-20 22:37:37 +00:00 committed by Gerrit Code Review
commit 2800d0814c
2 changed files with 44 additions and 4 deletions

View File

@ -1235,18 +1235,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

@ -525,6 +525,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')