Add _wrap_db_error() support to SessionTransaction.commit()

This patch adds _wrap_db_error() to the commit()
and rollback() methods of sqlalchemy.orm.session.SessionTransaction,
which is the object that is dealt with when one invokes
code of the form "with session.begin():".  The context manager
form does not invoke the commit() method on the
SQLAlchemy Session directly, and instead calls the one
local to the SessionTransaction.

In order to intercept this, we must build a subclass
of SessionTransaction with the appropriate wrapping, and
then patch it into the object that is returned by
Session.begin(), ensuring that it is compatible with
_wrap_db_error().

This whole approach is legacy; newer oslo.db versions
intercept errors at the point at which they occur
via engine events.

Tests are omitted here as we are relying upon the tests
that were added to the corresponding oslo-incubator code.

Closes-bug: #1370191

Change-Id: Ie0456e6daa86c99cf6fbe56ca5dfd8a618f14232
Add @_retry_on_deadlock to _instance_update()

This patch adds the @_retry_on_deadlock decorator
to _instance_update(), which has been observed to be
involved in some deadlock scenarios.  As it is the point
of transaction demarcation based on the presence of
get_session(), this is an appropriate point at which the
transaction can be re-attempted in the case of deadlock.

Change-Id: Id2cfdc129ea3cfc787b73f1f3e9aa286a7c0229a
Closes-bug: 1375467
Cherry-picked from: 68ed3c034ba1b0767694026000723e5255d24a64
Merge "Add _wrap_db_error() support to SessionTransaction.commit()" into stable/icehouse
Fix nova-compute start issue after evacuate

After evacuated successfully, and restarting the failed
host to get it back, Nova will call init_host() and then
call method _destroy_evacuated_instances(). In method
_destroy_evacuated_instances(), nova will check again if
the storage is shared or not to decide if the storage
should be destroyed. Now nova is using temp file to check
if it's shared file system, but it's wrong for RBD case.
So Nova will attempt to delete the shared block storage,
which will fail since it's used by the new instance. This
patch fixes this issue and adds test cases for that.

Closes-Bug: 1385484

Conflicts:
        nova/tests/virt/libvirt/test_libvirt.py

Change-Id: I71bb818f3c2930b3a2ddf1817dfd4bb61fae7e98
(cherry picked from commit 296d92bd44d1b8eb161f94f70cba5db4d17f8f65)
(cherry picked from commit ce1d1dd3dda0097d97f0b23b01d18dc1e3a9569a)
Fix nova evacuate issues for RBD

For RBD scenario, there are some issues in Nova code
now against evacuate function:

1. Based on current implementation, nova evacuate and
nova rebuild are sharing some code. When user enables
the on_shared_storage option for nova evacuate, nova
will check if the instance path is accessible. For
the RBD scenario, the volume(block) is shared between
different hosts, though the path isn't shared at the
filesystem level. This patch fixes this issue and adds
test cases for that.

2. Missing the 'recreate' parameter for rebuild method.
Though the libvirt driver doesn't implement rebuild
method(only Ironic driver implements it), but we really
need to set 'recreate' in kwargs so it gets passed to
_rebuild_default_impl so we don't call driver.destroy
on evacuate for shared filesystem/block storage cases.
It is fixed in this patch and test case is added as well.

Closes-Bug: 1249319
Closes-Bug: 1340411

Conflicts:
        nova/tests/compute/test_compute_mgr.py
        nova/tests/virt/libvirt/test_libvirt.py
        nova/virt/libvirt/driver.py

Change-Id: Idc8c45b055e986cf85730235d5d25777632ad1c1
(cherry picked from commit 91d3272b975572d9866b7d959547e438142dc4fb)
(cherry picked from commit 7920cfdab2fb10e01544eeb713a1e3bc79bc4996)
Merge "Fix nova evacuate issues for RBD" into stable/icehouse
Merge "Fix nova-compute start issue after evacuate" into stable/icehouse
Merge "Add @_retry_on_deadlock to _instance_update()" into stable/icehouse
Merge branch 'stable/icehouse' of https://github.com/openstack/nova into stable/icehouse