Preparing for Pike support 2 (neutron_lib context)

Using the neutron context from neutron_lib (but
continues using db_api from neutron instead of
neutron_lib).

Note that Neutron still uses the context from the Neutron
repo in Ocata, so with this patch, both, Neutron and
neutron_lib, contexts will be in play depending on
whether the context is being instantiated by Neutron
or by GBP.

Also updating the tox hacking ignores to not require
translation hints for log messages. This should have been
removed in the previously merged patch which removed the log
message hints.

Change-Id: I8df4d00a8c0109e04e1f72576a54048332666078
This commit is contained in:
Sumit Naiksatam
2017-10-24 16:49:25 -07:00
parent 84353cca91
commit 76d2c32a36
39 changed files with 97 additions and 84 deletions

View File

@@ -10,7 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron import context as n_ctx
import sys
from neutron import context as old_context
from neutron_lib import context as n_context
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import importutils
@@ -22,6 +25,29 @@ LOG = logging.getLogger(__name__)
cfg.CONF.import_group('keystone_authtoken', 'keystonemiddleware.auth_token')
def get_current_context():
i = 1
try:
while True:
for val in sys._getframe(i).f_locals.itervalues():
# REVISIT (Sumit); In Ocata, neutron is still
# using the neutron_lib context, hence we need
# to check for both. This should be changed in
# Pike to only check for the neutron_lib context.
if isinstance(val, n_context.Context) or (
isinstance(val, old_context.Context)):
return val
i = i + 1
except Exception:
return
def get_current_session():
ctx = get_current_context()
if ctx:
return ctx.session
def get_resource_plural(resource):
if resource.endswith('y'):
resource_plural = resource.replace('y', 'ies')
@@ -48,7 +74,7 @@ def load_plugin(namespace, plugin):
def admin_context(context):
admin_context = n_ctx.get_admin_context()
admin_context = n_context.get_admin_context()
admin_context._session = context.session
return admin_context