Codebase list python-castellan / 18fdab8
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 Kaitlin Farr 8 years ago
2 changed file(s) with 34 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
332332 Barbican key creation is done asynchronously, so this loop continues
333333 checking until the order is active or a timeout occurs.
334334 """
335 active = u'ACTIVE'
335 active_status = u'ACTIVE'
336 error_status = u'ERROR'
336337 number_of_retries = self.conf.barbican.number_of_retries
337338 retry_delay = self.conf.barbican.retry_delay
338339 order = barbican_client.orders.get(order_ref)
339340 time.sleep(.25)
340341 for n in range(number_of_retries):
341 if order.status != active:
342 if order.status == error_status:
343 kwargs = {"status": error_status,
344 "code": order.error_status_code,
345 "reason": order.error_reason}
346 msg = u._LE("Order is in %(status)s status - status code: "
347 "%(code)s, status reason: %(reason)s") % kwargs
348 LOG.error(msg)
349 raise exception.KeyManagerError(reason=msg)
350 if order.status != active_status:
342351 kwargs = {'attempt': n,
343352 'total': number_of_retries,
344353 'status': order.status,
345 'active': active,
354 'active': active_status,
346355 'delay': retry_delay}
347356 msg = u._LI("Retry attempt #%(attempt)i out of %(total)i: "
348357 "Order status is '%(status)s'. Waiting for "
354363 else:
355364 return order
356365 msg = u._LE("Exceeded retries: Failed to find '%(active)s' status "
357 "within %(num_retries)i retries") % {'active': active,
358 'num_retries':
359 number_of_retries}
366 "within %(num_retries)i retries") % {
367 'active': active_status,
368 'num_retries': number_of_retries}
360369 LOG.error(msg)
361370 raise exception.KeyManagerError(reason=msg)
362371
320320
321321 self.assertEqual(number_of_retries + 1,
322322 self.mock_barbican.orders.get.call_count)
323
324 def test_get_active_order_error(self):
325 order_ref_url = ("http://localhost:9311/v1/orders/"
326 "4fe939b7-72bc-49aa-bd1e-e979589858af")
327
328 error_order = mock.Mock()
329 error_order.status = u'ERROR'
330 error_order.order_ref = order_ref_url
331 error_order.error_status_code = u"500"
332 error_order.error_reason = u"Test Error"
333
334 self.mock_barbican.orders.get.return_value = error_order
335
336 self.assertRaises(exception.KeyManagerError,
337 self.key_mgr._get_active_order,
338 self.mock_barbican,
339 order_ref_url)
340
341 self.assertEqual(1, self.mock_barbican.orders.get.call_count)