Create a nested helper function that will work on py3.x

The contextlib.nested function doesn't exist on py3.x so
in order to retain similar functionality create an equivalent
that will perform good enough for oslo.db usage.

Change-Id: I326816c9301f1c625e1e2723d4d639fd81cc596c
Merge "Create a nested helper function that will work on py3.x"