Clean up sqlalchemy exception code

Moves DB exceptions that can be shared between DB implementations into
their own module.

Adds DBDeadlock() exception wrapping.  Nova has its own code for
determining Deadlock and it's better to consolidate it with
DBDuplicateKey checking.

Change-Id: I108bd0da2a14d62e460a997b1472f0b65bfc9b95
AMQP: skip duplicate messages

When using rabbit's mirrored queues or qpid's replicated queues, there
are conditions under which you can receive the same message twice.

One such condition is where a message has been sent to a consumer but
before an ack is received by a consumer, the master fails over to a
slave and the slave resends the message. Note that the consumer may have
sent the ack, but it was lost as the master went down.

Dispatching the same message twice is obviously something we want to
avoid. In order to do so, we add a unique_id to each message sent and
have consumers maintain a fixed length queue of recently seen unique
message IDs. Before dispatching any received message, the queue is
checked and the message is skipped if it is a duplicate.

Fixes bugs 1107064.

Change-Id: I5bfacadbdf7de8b34d6370b9aa869c271957692d
Merge "Clean up sqlalchemy exception code"