Add logic to error out of key creation if order errors out
The Barbican back end contains a timeout loop during key creation to return the key's UUID only if the Barbican order status is ACTIVE. This loop waits for ACTIVE status, but it should also exit the loop if an ERROR status is found. Change-Id: I8282f3929dcdf68b438285eb0dde884b36ec6c3b
This commit is contained in:
parent
cddd164bac
commit
18fdab8ef5
@ -333,17 +333,26 @@ class BarbicanKeyManager(key_manager.KeyManager):
|
||||
Barbican key creation is done asynchronously, so this loop continues
|
||||
checking until the order is active or a timeout occurs.
|
||||
"""
|
||||
active = u'ACTIVE'
|
||||
active_status = u'ACTIVE'
|
||||
error_status = u'ERROR'
|
||||
number_of_retries = self.conf.barbican.number_of_retries
|
||||
retry_delay = self.conf.barbican.retry_delay
|
||||
order = barbican_client.orders.get(order_ref)
|
||||
time.sleep(.25)
|
||||
for n in range(number_of_retries):
|
||||
if order.status != active:
|
||||
if order.status == error_status:
|
||||
kwargs = {"status": error_status,
|
||||
"code": order.error_status_code,
|
||||
"reason": order.error_reason}
|
||||
msg = u._LE("Order is in %(status)s status - status code: "
|
||||
"%(code)s, status reason: %(reason)s") % kwargs
|
||||
LOG.error(msg)
|
||||
raise exception.KeyManagerError(reason=msg)
|
||||
if order.status != active_status:
|
||||
kwargs = {'attempt': n,
|
||||
'total': number_of_retries,
|
||||
'status': order.status,
|
||||
'active': active,
|
||||
'active': active_status,
|
||||
'delay': retry_delay}
|
||||
msg = u._LI("Retry attempt #%(attempt)i out of %(total)i: "
|
||||
"Order status is '%(status)s'. Waiting for "
|
||||
@ -355,9 +364,9 @@ class BarbicanKeyManager(key_manager.KeyManager):
|
||||
else:
|
||||
return order
|
||||
msg = u._LE("Exceeded retries: Failed to find '%(active)s' status "
|
||||
"within %(num_retries)i retries") % {'active': active,
|
||||
'num_retries':
|
||||
number_of_retries}
|
||||
"within %(num_retries)i retries") % {
|
||||
'active': active_status,
|
||||
'num_retries': number_of_retries}
|
||||
LOG.error(msg)
|
||||
raise exception.KeyManagerError(reason=msg)
|
||||
|
||||
|
@ -321,3 +321,22 @@ class BarbicanKeyManagerTestCase(test_key_manager.KeyManagerTestCase):
|
||||
|
||||
self.assertEqual(number_of_retries + 1,
|
||||
self.mock_barbican.orders.get.call_count)
|
||||
|
||||
def test_get_active_order_error(self):
|
||||
order_ref_url = ("http://localhost:9311/v1/orders/"
|
||||
"4fe939b7-72bc-49aa-bd1e-e979589858af")
|
||||
|
||||
error_order = mock.Mock()
|
||||
error_order.status = u'ERROR'
|
||||
error_order.order_ref = order_ref_url
|
||||
error_order.error_status_code = u"500"
|
||||
error_order.error_reason = u"Test Error"
|
||||
|
||||
self.mock_barbican.orders.get.return_value = error_order
|
||||
|
||||
self.assertRaises(exception.KeyManagerError,
|
||||
self.key_mgr._get_active_order,
|
||||
self.mock_barbican,
|
||||
order_ref_url)
|
||||
|
||||
self.assertEqual(1, self.mock_barbican.orders.get.call_count)
|
||||
|
Loading…
Reference in New Issue
Block a user