Add a `_retry_on_deadlock` decorator

This patch adds a `_retry_on_deadlock` decorator from Nova. The aim is
to retry db transactions that had failed because of race-conditions.
Although this is not the best and most ideal fix - it'd be better to get
rid of the race condition - the fix does adds a guard against unseen
reace conditions for some of the functions in the database API.

I'll contribute this patch to oslo.db but in the meantime, I'd prefer to
let it land in Glance and then clean it up once it's in `oslo.db`.

Change-Id: Iea1fa94a7c8690c874859b1b1e9fd1cdf29fed21
Fixes-bug: #1339735
Merge "Add a `_retry_on_deadlock` decorator"