Spin off context module

NeutronLibImpact

Partially-implements: blueprint neutron-lib

Change-Id: I48cf45dc1b07035d952152eac2548a3bd9fc2832
changes/57/388157/41
Armando Migliaccio 6 years ago committed by Paul Belanger
parent 5691f29e8f
commit ca751a1486
  1. 2
      neutron/agent/dhcp/agent.py
  2. 2
      neutron/agent/l3/agent.py
  3. 2
      neutron/agent/metadata/agent.py
  4. 2
      neutron/api/rpc/handlers/l3_rpc.py
  5. 3
      neutron/auth.py
  6. 2
      neutron/cmd/eventlet/usage_audit.py
  7. 2
      neutron/common/profiler.py
  8. 2
      neutron/common/rpc.py
  9. 175
      neutron/context.py
  10. 2
      neutron/db/agents_db.py
  11. 2
      neutron/db/agentschedulers_db.py
  12. 6
      neutron/db/api.py
  13. 2
      neutron/db/db_base_plugin_v2.py
  14. 2
      neutron/db/l3_db.py
  15. 2
      neutron/notifiers/nova.py
  16. 2
      neutron/plugins/ml2/drivers/agent/_common_agent.py
  17. 2
      neutron/plugins/ml2/drivers/helpers.py
  18. 2
      neutron/plugins/ml2/drivers/l2pop/mech_driver.py
  19. 2
      neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py
  20. 2
      neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py
  21. 2
      neutron/plugins/ml2/drivers/type_tunnel.py
  22. 2
      neutron/plugins/ml2/drivers/type_vlan.py
  23. 2
      neutron/plugins/ml2/ovo_rpc.py
  24. 23
      neutron/policy.py
  25. 2
      neutron/service.py
  26. 2
      neutron/services/externaldns/driver.py
  27. 2
      neutron/services/metering/agents/metering_agent.py
  28. 2
      neutron/services/qos/qos_plugin.py
  29. 2
      neutron/services/trunk/drivers/openvswitch/agent/ovsdb_handler.py
  30. 2
      neutron/services/trunk/plugin.py
  31. 2
      neutron/tests/common/helpers.py
  32. 6
      neutron/tests/functional/api/test_policies.py
  33. 2
      neutron/tests/functional/db/test_ipam.py
  34. 8
      neutron/tests/functional/pecan_wsgi/test_controllers.py
  35. 2
      neutron/tests/functional/pecan_wsgi/test_functional.py
  36. 2
      neutron/tests/functional/pecan_wsgi/test_hooks.py
  37. 2
      neutron/tests/functional/plugins/ml2/test_plugin.py
  38. 2
      neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py
  39. 2
      neutron/tests/functional/scheduler/test_l3_agent_scheduler.py
  40. 2
      neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py
  41. 2
      neutron/tests/retargetable/client_fixtures.py
  42. 2
      neutron/tests/unit/_test_extension_portbindings.py
  43. 2
      neutron/tests/unit/agent/l2/extensions/test_qos.py
  44. 2
      neutron/tests/unit/agent/test_securitygroups_rpc.py
  45. 2
      neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py
  46. 2
      neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py
  47. 2
      neutron/tests/unit/api/v2/test_attributes.py
  48. 2
      neutron/tests/unit/api/v2/test_base.py
  49. 2
      neutron/tests/unit/api/v2/test_resource.py
  50. 27
      neutron/tests/unit/common/test_rpc.py
  51. 2
      neutron/tests/unit/core_extensions/test_qos.py
  52. 2
      neutron/tests/unit/db/metering/test_metering_db.py
  53. 2
      neutron/tests/unit/db/quota/test_api.py
  54. 2
      neutron/tests/unit/db/quota/test_driver.py
  55. 2
      neutron/tests/unit/db/test_agents_db.py
  56. 4
      neutron/tests/unit/db/test_agentschedulers_db.py
  57. 2
      neutron/tests/unit/db/test_common_db_mixin.py
  58. 2
      neutron/tests/unit/db/test_db_base_plugin_v2.py
  59. 2
      neutron/tests/unit/db/test_dvr_mac_db.py
  60. 2
      neutron/tests/unit/db/test_extraroute_db.py
  61. 2
      neutron/tests/unit/db/test_l3_dvr_db.py
  62. 2
      neutron/tests/unit/db/test_l3_hamode_db.py
  63. 2
      neutron/tests/unit/db/test_provisioning_blocks.py
  64. 2
      neutron/tests/unit/db/test_securitygroups_db.py
  65. 2
      neutron/tests/unit/db/test_sqlalchemytypes.py
  66. 2
      neutron/tests/unit/db/test_standard_attr.py
  67. 2
      neutron/tests/unit/extensions/test_address_scope.py
  68. 2
      neutron/tests/unit/extensions/test_agent.py
  69. 3
      neutron/tests/unit/extensions/test_availability_zone.py
  70. 2
      neutron/tests/unit/extensions/test_dns.py
  71. 2
      neutron/tests/unit/extensions/test_external_net.py
  72. 2
      neutron/tests/unit/extensions/test_extraroute.py
  73. 2
      neutron/tests/unit/extensions/test_flavors.py
  74. 2
      neutron/tests/unit/extensions/test_l3.py
  75. 4
      neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
  76. 2
      neutron/tests/unit/extensions/test_portsecurity.py
  77. 2
      neutron/tests/unit/extensions/test_providernet.py
  78. 2
      neutron/tests/unit/extensions/test_quotasv2.py
  79. 2
      neutron/tests/unit/extensions/test_securitygroup.py
  80. 2
      neutron/tests/unit/extensions/test_segment.py
  81. 2
      neutron/tests/unit/extensions/test_servicetype.py
  82. 2
      neutron/tests/unit/extensions/test_timestamp.py
  83. 2
      neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_db_api.py
  84. 2
      neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py
  85. 2
      neutron/tests/unit/ipam/test_requests.py
  86. 2
      neutron/tests/unit/ipam/test_subnet_alloc.py
  87. 2
      neutron/tests/unit/objects/db/test_api.py
  88. 3
      neutron/tests/unit/objects/port/extensions/test_allowedaddresspairs.py
  89. 2
      neutron/tests/unit/objects/test_base.py
  90. 2
      neutron/tests/unit/objects/test_rbac_db.py
  91. 2
      neutron/tests/unit/objects/test_subnet.py
  92. 2
      neutron/tests/unit/plugins/ml2/drivers/base_type_tunnel.py
  93. 2
      neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py
  94. 2
      neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py
  95. 2
      neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py
  96. 2
      neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/extension_drivers/test_qos_driver.py
  97. 2
      neutron/tests/unit/plugins/ml2/drivers/test_helpers.py
  98. 2
      neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py
  99. 2
      neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py
  100. 2
      neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py
  101. Some files were not shown because too many files have changed in this diff Show More

@ -18,6 +18,7 @@ import os
import eventlet
from neutron_lib import constants
from neutron_lib import context
from neutron_lib import exceptions
from oslo_concurrency import lockutils
from oslo_config import cfg
@ -37,7 +38,6 @@ from neutron.common import constants as n_const
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.common import utils
from neutron import context
from neutron import manager
LOG = logging.getLogger(__name__)

@ -16,6 +16,7 @@
import eventlet
import netaddr
from neutron_lib import constants as lib_const
from neutron_lib import context as n_context
from oslo_config import cfg
from oslo_context import context as common_context
from oslo_log import log as logging
@ -53,7 +54,6 @@ from neutron.common import ipv6_utils
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.common import utils
from neutron import context as n_context
from neutron import manager
LOG = logging.getLogger(__name__)

@ -17,6 +17,7 @@ import hmac
import httplib2
from neutron_lib import constants
from neutron_lib import context
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
@ -34,7 +35,6 @@ from neutron.common import constants as n_const
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.conf.agent.metadata import config
from neutron import context
LOG = logging.getLogger(__name__)

@ -14,6 +14,7 @@
# limitations under the License.
from neutron_lib import constants
from neutron_lib import context as neutron_context
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from oslo_config import cfg
@ -23,7 +24,6 @@ import six
from neutron.common import constants as n_const
from neutron.common import utils
from neutron import context as neutron_context
from neutron.db import api as db_api
from neutron.extensions import l3
from neutron.extensions import portbindings

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import context
from oslo_config import cfg
from oslo_log import log as logging
from oslo_middleware import base
@ -19,8 +20,6 @@ from oslo_middleware import request_id
import webob.dec
import webob.exc
from neutron import context
LOG = logging.getLogger(__name__)

@ -20,11 +20,11 @@ subnets.
import sys
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.plugins import directory
from neutron.common import config
from neutron.common import rpc as n_rpc
from neutron import context
from neutron import manager

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import context
from oslo_config import cfg
from oslo_log import log as logging
import osprofiler.initializer
@ -17,7 +18,6 @@ from osprofiler import opts as profiler_opts
import osprofiler.web
from neutron._i18n import _LI
from neutron import context
CONF = cfg.CONF

@ -18,6 +18,7 @@ import collections
import random
import time
from neutron_lib import context
from neutron_lib import exceptions as lib_exceptions
from oslo_config import cfg
from oslo_log import log as logging
@ -30,7 +31,6 @@ from osprofiler import profiler
from neutron._i18n import _LE, _LW
from neutron.common import exceptions
from neutron import context
LOG = logging.getLogger(__name__)

@ -1,175 +0,0 @@
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Context: context for security/db session."""
import copy
import datetime
from oslo_context import context as oslo_context
from oslo_db.sqlalchemy import enginefacade
from neutron.db import api as db_api
from neutron import policy
class ContextBase(oslo_context.RequestContext):
"""Security context and request information.
Represents the user taking a given action within the system.
"""
def __init__(self, user_id=None, tenant_id=None, is_admin=None,
timestamp=None, tenant_name=None, user_name=None,
is_advsvc=None, **kwargs):
"""Object initialization.
:param overwrite: Set to False to ensure that the greenthread local
copy of the index is not overwritten.
"""
# NOTE(jamielennox): We maintain these arguments in order for tests
# that pass arguments positionally.
kwargs.setdefault('user', user_id)
kwargs.setdefault('tenant', tenant_id)
super(ContextBase, self).__init__(is_admin=is_admin, **kwargs)
self.user_name = user_name
# NOTE(sdague): tenant* is a deprecated set of names from
# keystone, and is no longer set in modern keystone middleware
# code, as such this is almost always going to be None.
self.tenant_name = tenant_name
if not timestamp:
timestamp = datetime.datetime.utcnow()
self.timestamp = timestamp
self.is_advsvc = is_advsvc
if self.is_advsvc is None:
self.is_advsvc = self.is_admin or policy.check_is_advsvc(self)
if self.is_admin is None:
self.is_admin = policy.check_is_admin(self)
@property
def project_id(self):
return self.tenant
@property
def tenant_id(self):
return self.tenant
@tenant_id.setter
def tenant_id(self, tenant_id):
self.tenant = tenant_id
@property
def user_id(self):
return self.user
@user_id.setter
def user_id(self, user_id):
self.user = user_id
def to_dict(self):
context = super(ContextBase, self).to_dict()
context.update({
'user_id': self.user_id,
'tenant_id': self.tenant_id,
'project_id': self.project_id,
'timestamp': str(self.timestamp),
# prefer project_name, as that's what's going to be set by
# keystone. Fall back if for some reason it's blank.
'tenant_name': self.project_name or self.tenant_name,
'project_name': self.project_name or self.tenant_name,
'user_name': self.user_name,
})
return context
def to_policy_values(self):
values = super(ContextBase, self).to_policy_values()
values['tenant_id'] = self.tenant_id
values['is_admin'] = self.is_admin
# NOTE(jamielennox): These are almost certainly unused and non-standard
# but kept for backwards compatibility. Remove them in Pike
# (oslo.context from Ocata release already issues deprecation warnings
# for non-standard keys).
values['user'] = self.user
values['tenant'] = self.tenant
values['domain'] = self.domain
values['user_domain'] = self.user_domain
values['project_domain'] = self.project_domain
# prefer project_name, as that's what's going to be set by
# keystone. Fall back if for some reason it's blank.
values['tenant_name'] = self.project_name or self.tenant_name
values['project_name'] = self.project_name or self.tenant_name
values['user_name'] = self.user_name
return values
@classmethod
def from_dict(cls, values):
return cls(user_id=values.get('user_id', values.get('user')),
tenant_id=values.get('tenant_id', values.get('project_id')),
is_admin=values.get('is_admin'),
roles=values.get('roles'),
timestamp=values.get('timestamp'),
request_id=values.get('request_id'),
tenant_name=values.get('tenant_name'),
user_name=values.get('user_name'),
auth_token=values.get('auth_token'))
def elevated(self):
"""Return a version of this context with admin flag set."""
context = copy.copy(self)
context.is_admin = True
if 'admin' not in [x.lower() for x in context.roles]:
context.roles = context.roles + ["admin"]
return context
@enginefacade.transaction_context_provider
class ContextBaseWithSession(ContextBase):
pass
class Context(ContextBaseWithSession):
def __init__(self, *args, **kwargs):
super(Context, self).__init__(*args, **kwargs)
self._session = None
@property
def session(self):
# TODO(akamyshnikova): checking for session attribute won't be needed
# when reader and writer will be used
if hasattr(super(Context, self), 'session'):
return super(Context, self).session
if self._session is None:
self._session = db_api.get_writer_session()
return self._session
def get_admin_context():
return Context(user_id=None,
tenant_id=None,
is_admin=True,
overwrite=False)
def get_admin_context_without_session():
return ContextBase(user_id=None,
tenant_id=None,
is_admin=True)

@ -19,6 +19,7 @@ import debtcollector
from eventlet import greenthread
from neutron_lib.api import converters
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_log import log as logging
@ -37,7 +38,6 @@ from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import constants as n_const
from neutron import context
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db.models import agent as agent_model

@ -18,6 +18,7 @@ import random
import time
from neutron_lib import constants
from neutron_lib import context as ncontext
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
@ -29,7 +30,6 @@ from neutron._i18n import _, _LE, _LI, _LW
from neutron.agent.common import utils as agent_utils
from neutron.common import constants as n_const
from neutron.common import utils
from neutron import context as ncontext
from neutron.db import agents_db
from neutron.db.availability_zone import network as network_az
from neutron.db.models import agent as agent_model

@ -17,11 +17,11 @@ import contextlib
import copy
from debtcollector import removals
from neutron_lib.db import api
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc
from oslo_db.sqlalchemy import enginefacade
from oslo_log import log as logging
from oslo_utils import excutils
from osprofiler import opts as profiler_opts
@ -44,9 +44,7 @@ def set_hook(engine):
osprofiler.sqlalchemy.add_tracing(sqlalchemy, engine, 'neutron.db')
context_manager = enginefacade.transaction_context()
context_manager.configure(sqlite_fk=True)
context_manager = api.get_context_manager()
# TODO(ihrachys) the hook assumes options defined by osprofiler, and the only
# public function that is provided by osprofiler that will register them is

@ -18,6 +18,7 @@ import functools
import netaddr
from neutron_lib.api import validators
from neutron_lib import constants
from neutron_lib import context as ctx
from neutron_lib import exceptions as exc
from neutron_lib.plugins import directory
from oslo_config import cfg
@ -39,7 +40,6 @@ from neutron.common import constants as n_const
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.common import utils
from neutron import context as ctx
from neutron.db import _utils as ndb_utils
from neutron.db import api as db_api
from neutron.db import db_base_plugin_common

@ -20,6 +20,7 @@ from debtcollector import removals
import netaddr
from neutron_lib.api import validators
from neutron_lib import constants
from neutron_lib import context as n_ctx
from neutron_lib import exceptions as n_exc
from neutron_lib.plugins import directory
from oslo_log import log as logging
@ -38,7 +39,6 @@ from neutron.common import constants as n_const
from neutron.common import ipv6_utils
from neutron.common import rpc as n_rpc
from neutron.common import utils
from neutron import context as n_ctx
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db import common_db_mixin

@ -15,6 +15,7 @@
from keystoneauth1 import loading as ks_loading
from neutron_lib import constants
from neutron_lib import context
from neutron_lib import exceptions as exc
from neutron_lib.plugins import directory
from novaclient import api_versions
@ -29,7 +30,6 @@ from neutron._i18n import _LE, _LI, _LW
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron import context
from neutron.notifiers import batch_notifier

@ -20,6 +20,7 @@ import sys
import time
from neutron_lib import constants
from neutron_lib import context
from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import loopingcall
@ -39,7 +40,6 @@ from neutron.callbacks import resources as local_resources
from neutron.common import config as common_config
from neutron.common import constants as n_const
from neutron.common import topics
from neutron import context
from neutron.plugins.ml2.drivers.agent import _agent_manager_base as amb
from neutron.plugins.ml2.drivers.agent import capabilities
from neutron.plugins.ml2.drivers.agent import config as cagt_config # noqa

@ -15,6 +15,7 @@
import random
from neutron_lib import context as neutron_ctx
from neutron_lib.utils import helpers
from oslo_config import cfg
from oslo_db import exception as db_exc
@ -22,7 +23,6 @@ from oslo_log import log
from neutron._i18n import _LE
from neutron.common import exceptions as exc
from neutron import context as neutron_ctx
from neutron.plugins.common import utils as p_utils
from neutron.plugins.ml2 import driver_api as api

@ -14,6 +14,7 @@
# under the License.
from neutron_lib import constants as const
from neutron_lib import context as n_context
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from oslo_config import cfg
@ -21,7 +22,6 @@ from oslo_log import log as logging
from neutron._i18n import _, _LW
from neutron.conf.plugins.ml2.drivers import l2pop as config
from neutron import context as n_context
from neutron.db import api as db_api
from neutron.db import l3_hamode_db
from neutron.plugins.ml2 import driver_api as api

@ -21,6 +21,7 @@ import sys
import time
from neutron_lib import constants as n_constants
from neutron_lib import context
from neutron_lib.utils import helpers
from oslo_config import cfg
from oslo_log import log as logging
@ -38,7 +39,6 @@ from neutron.api.rpc.handlers import securitygroups_rpc as sg_rpc
from neutron.common import config as common_config
from neutron.common import profiler as setup_profiler
from neutron.common import topics
from neutron import context
from neutron.extensions import portbindings
from neutron.plugins.ml2.drivers.mech_sriov.agent.common import config
from neutron.plugins.ml2.drivers.mech_sriov.agent.common \

@ -23,6 +23,7 @@ import time
import netaddr
from neutron_lib import constants as n_const
from neutron_lib import context
from neutron_lib.utils import helpers
from oslo_config import cfg
from oslo_log import log as logging
@ -53,7 +54,6 @@ from neutron.common import config
from neutron.common import constants as c_const
from neutron.common import topics
from neutron.conf.agent import xenapi_conf
from neutron import context
from neutron.extensions import portbindings
from neutron.plugins.common import constants as p_const
from neutron.plugins.common import utils as p_utils

@ -17,6 +17,7 @@ import itertools
import operator
import netaddr
from neutron_lib import context
from neutron_lib import exceptions as exc
from oslo_config import cfg
from oslo_db import api as oslo_db_api
@ -28,7 +29,6 @@ from sqlalchemy import or_
from neutron._i18n import _, _LI, _LW
from neutron.common import topics
from neutron import context
from neutron.db import api as db_api
from neutron.plugins.common import constants as p_const
from neutron.plugins.common import utils as plugin_utils

@ -15,6 +15,7 @@
import sys
from neutron_lib import context
from neutron_lib import exceptions as exc
from oslo_config import cfg
from oslo_log import log
@ -22,7 +23,6 @@ from six import moves
from neutron._i18n import _, _LE, _LI, _LW
from neutron.conf.plugins.ml2.drivers import driver_type
from neutron import context
from neutron.db import api as db_api
from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
from neutron.plugins.common import constants as p_const

@ -14,6 +14,7 @@
import traceback
import eventlet
from neutron_lib import context as n_ctx
from oslo_concurrency import lockutils
from oslo_log import log as logging
@ -23,7 +24,6 @@ from neutron.api.rpc.handlers import resources_rpc
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron import context as n_ctx
from neutron.db import api as db_api
from neutron.objects import network
from neutron.objects import ports

@ -17,6 +17,7 @@ import collections
import re
from neutron_lib import constants
from neutron_lib import context
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from oslo_config import cfg
@ -24,7 +25,6 @@ from oslo_db import exception as db_exc
from oslo_log import log as logging
from oslo_policy import policy
from oslo_utils import excutils
from oslo_utils import importutils
import six
from neutron._i18n import _, _LE, _LW
@ -222,7 +222,6 @@ class OwnerCheck(policy.Check):
f = getattr(directory.get_plugin(), 'get_%s' % resource_type)
# f *must* exist, if not found it is better to let neutron
# explode. Check will be performed with admin context
context = importutils.import_module('neutron.context')
try:
data = f(context.get_admin_context(),
resource_id,
@ -409,23 +408,3 @@ def enforce(context, action, target, plugin=None, pluralized=None):
log_rule_list(rule)
LOG.debug("Failed policy check for '%s'", action)
return result
def check_is_admin(context):
"""Verify context has admin rights according to policy settings."""
init()
# the target is user-self
credentials = context.to_policy_values()
if ADMIN_CTX_POLICY not in _ENFORCER.rules:
return False
return _ENFORCER.enforce(ADMIN_CTX_POLICY, credentials, credentials)
def check_is_advsvc(context):
"""Verify context has advsvc rights according to policy settings."""
init()
# the target is user-self
credentials = context.to_policy_values()
if ADVSVC_CTX_POLICY not in _ENFORCER.rules:
return False
return _ENFORCER.enforce(ADVSVC_CTX_POLICY, credentials, credentials)

@ -17,6 +17,7 @@ import inspect
import os
import random
from neutron_lib import context
from neutron_lib.plugins import directory
from oslo_concurrency import processutils
from oslo_config import cfg
@ -35,7 +36,6 @@ from neutron.common import config
from neutron.common import profiler
from neutron.common import rpc as n_rpc
from neutron.conf import service
from neutron import context
from neutron.db import api as session
from neutron import worker as neutron_worker
from neutron import wsgi

@ -46,7 +46,7 @@ class ExternalDNSService(object):
"""Create a record set in the specified zone.
:param context: neutron api request context
:type context: neutron.context.Context
:type context: neutron_lib.context.Context
:param dns_domain: the dns_domain where the record set will be created
:type dns_domain: String
:param dns_name: the name associated with the record set

@ -15,6 +15,7 @@
import sys
from neutron_lib import constants
from neutron_lib import context
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
@ -33,7 +34,6 @@ from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.common import utils
from neutron.conf.services import metering_agent
from neutron import context
from neutron import manager
from neutron import service as neutron_service

@ -52,7 +52,7 @@ class QoSPlugin(qos.QoSPluginBase):
"""Create a QoS policy.
:param context: neutron api request context
:type context: neutron.context.Context
:type context: neutron_lib.context.Context
:param policy: policy data to be applied
:type policy: dict

@ -16,6 +16,7 @@
import functools
import eventlet
from neutron_lib import context as n_context
from oslo_concurrency import lockutils
from oslo_context import context as o_context
from oslo_log import log as logging
@ -28,7 +29,6 @@ from neutron.api.rpc.handlers import resources_rpc
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.common import utils as common_utils
from neutron import context as n_context
from neutron.plugins.ml2.drivers.openvswitch.agent.common \
import constants as ovs_agent_constants
from neutron.services.trunk import constants

@ -14,6 +14,7 @@
import copy
from neutron_lib import context
from oslo_log import log as logging
from oslo_utils import uuidutils
@ -21,7 +22,6 @@ from neutron.api.v2 import attributes
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron import context
from neutron.db import api as db_api
from neutron.db import common_db_mixin
from neutron.db import db_base_plugin_common

@ -19,6 +19,7 @@ import os
import random
from neutron_lib import constants
from neutron_lib import context
from oslo_utils import timeutils
import six
import testtools
@ -26,7 +27,6 @@ import testtools
import neutron
from neutron.agent.common import ovs_lib
from neutron.common import topics
from neutron import context
from neutron.db import agents_db
from neutron.db import common_db_mixin

@ -15,9 +15,10 @@
import os.path
from neutron_lib import context
from neutron.api import extensions
from neutron.api.v2 import attributes
from neutron import context
from neutron import policy
from neutron.tests import base
from neutron.tests import tools
@ -41,7 +42,6 @@ class APIPolicyTestCase(base.BaseTestCase):
self.useFixture(tools.AttributeMapMemento())
self.extension_path = os.path.abspath(os.path.join(
TEST_PATH, "../../../extensions"))
policy.reset()
self.addCleanup(policy.reset)
def _network_definition(self):
@ -79,9 +79,11 @@ class APIPolicyTestCase(base.BaseTestCase):
populating extensions and extending the resource map results in
networks with router:external are visible to regular tenants.
"""
policy.reset()
extension_manager = extensions.ExtensionManager(self.extension_path)
extension_manager.extend_resources(self.api_version,
attributes.RESOURCE_ATTRIBUTE_MAP)
policy.init()
admin_context = context.get_admin_context()
tenant_context = context.Context('test_user', 'test_tenant_id', False)
self.assertTrue(self._check_external_router_policy(admin_context))

@ -14,12 +14,12 @@
# under the License.
from neutron_lib import constants
from neutron_lib import context
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_utils import uuidutils
import testtools
from neutron import context
from neutron.db import db_base_plugin_v2 as base_plugin
from neutron.db import models_v2
from neutron.tests.unit import testlib_api

@ -14,6 +14,7 @@ import uuid
import mock
from neutron_lib import constants as n_const
from neutron_lib import context
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_db import exception as db_exc
@ -23,7 +24,6 @@ import pecan
from pecan import request
from neutron.api import extensions
from neutron import context
from neutron import manager
from neutron.pecan_wsgi.controllers import root as controllers
from neutron.pecan_wsgi.controllers import utils as controller_utils
@ -297,6 +297,8 @@ class TestResourceController(TestRootController):
def setUp(self):
super(TestResourceController, self).setUp()
policy.init()
self.addCleanup(policy.reset)
self._gen_port()
def _gen_port(self):
@ -456,6 +458,8 @@ class TestPaginationAndSorting(test_functional.PecanFunctionalTest):
def setUp(self):
super(TestPaginationAndSorting, self).setUp()
policy.init()
self.addCleanup(policy.reset)
self.plugin = directory.get_plugin()
self.ctx = context.get_admin_context()
self._create_networks(self.RESOURCE_COUNT)
@ -702,6 +706,8 @@ class TestRouterController(TestResourceController):
['neutron.services.l3_router.l3_router_plugin.L3RouterPlugin',
'neutron.services.flavors.flavors_plugin.FlavorsPlugin'])
super(TestRouterController, self).setUp()
policy.init()
self.addCleanup(policy.reset)
plugin = directory.get_plugin()
ctx = context.get_admin_context()
l3_plugin = directory.get_plugin(n_const.L3)

@ -17,6 +17,7 @@ import os
import mock
from neutron_lib import constants
from neutron_lib import context
from neutron_lib import exceptions as n_exc
from oslo_config import cfg
from oslo_middleware import base
@ -27,7 +28,6 @@ import webob.dec
import webtest
from neutron.api import extensions as exts
from neutron import context
from neutron import manager
from neutron import tests
from neutron.tests.unit import testlib_api

@ -14,6 +14,7 @@
# under the License.
import mock
from neutron_lib import context
from neutron_lib.db import constants as db_const
from neutron_lib.plugins import directory
from oslo_policy import policy as oslo_policy
@ -21,7 +22,6 @@ from oslo_serialization import jsonutils
from neutron.api.v2 import attributes
from neutron.callbacks import events
from neutron import context
from neutron.db.quota import driver as quota_driver
from neutron import manager
from neutron.pecan_wsgi.controllers import resource

@ -14,8 +14,8 @@
# under the License.
from neutron_lib import constants
from neutron_lib import context
from neutron import context
from neutron.db import agents_db
from neutron.extensions import portbindings
from neutron.tests.common import helpers

@ -17,10 +17,10 @@ import collections
from operator import attrgetter
from neutron_lib import constants
from neutron_lib import context
import six
import testscenarios
from neutron import context
from neutron.db import agents_db
from neutron.db import agentschedulers_db
from neutron.db import common_db_mixin

@ -17,10 +17,10 @@ import collections
import random
from neutron_lib import constants
from neutron_lib import context
from oslo_utils import uuidutils
import testscenarios
from neutron import context
from neutron.db.models import external_net as ext_net_models
from neutron.scheduler import l3_agent_scheduler
from neutron.services.l3_router import l3_router_plugin

@ -14,13 +14,13 @@
import mock
from neutron_lib import constants
from neutron_lib import context
from neutron.api.rpc.handlers import l3_rpc
from neutron.callbacks import events
from neutron.callbacks import registry
from neutron.callbacks import resources
from neutron.common import topics
from neutron import context
from neutron.extensions import external_net
from neutron.extensions import l3
from neutron.extensions import portbindings

@ -18,11 +18,11 @@ Neutron API via different methods.
import abc
import fixtures
from neutron_lib import context
from neutron_lib import exceptions as n_exc
from neutron_lib.plugins import directory
import six
from neutron import context
from neutron import manager
from neutron.tests import base
from neutron.tests.unit import testlib_api

@ -13,12 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import context
from neutron_lib.plugins import directory
from oslo_config import cfg
from six.moves import http_client as httplib
from webob import exc
from neutron import context
from neutron.extensions import portbindings
from neutron.tests.unit.db import test_db_base_plugin_v2

@ -14,6 +14,7 @@
# under the License.
import mock
from neutron_lib import context
from neutron_lib import exceptions
from oslo_utils import uuidutils
@ -23,7 +24,6 @@ from neutron.api.rpc.callbacks.consumer import registry
from neutron.api.rpc.callbacks import events
from neutron.api.rpc.callbacks import resources
from neutron.api.rpc.handlers import resources_rpc
from neutron import context
from neutron.objects.qos import policy
from neutron.objects.qos import rule
from neutron.plugins.ml2.drivers.openvswitch.agent import (

@ -18,6 +18,7 @@ import contextlib
import mock
from neutron_lib import constants as const
from neutron_lib import context
from neutron_lib.plugins import directory
from oslo_config import cfg
import oslo_messaging
@ -30,7 +31,6 @@ from neutron.agent.linux import iptables_manager
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.api.rpc.handlers import securitygroups_rpc
from neutron.common import rpc as n_rpc
from neutron import context
from neutron.db import securitygroups_rpc_base as sg_db_rpc
from neutron.extensions import allowedaddresspairs as addr_pair
from neutron.extensions import securitygroup as ext_sg

@ -14,11 +14,11 @@
# limitations under the License.
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.plugins import directory
from oslo_config import cfg
from neutron.api.rpc.handlers import l3_rpc
from neutron import context
from neutron.tests.unit.db import test_db_base_plugin_v2
from neutron.tests.unit import testlib_api

@ -14,6 +14,7 @@
# limitations under the License.
import mock
from neutron_lib import context
from oslo_utils import uuidutils
from oslo_versionedobjects import fields as obj_fields
from oslo_versionedobjects import fixture
@ -23,7 +24,6 @@ from neutron.api.rpc.callbacks import resources
from neutron.api.rpc.callbacks import version_manager
from neutron.api.rpc.handlers import resources_rpc
from neutron.common import topics
from neutron import context
from neutron.objects import base as objects_base
from neutron.objects import common_types
from neutron.tests import base

@ -15,12 +15,12 @@
from neutron_lib.api import converters
from neutron_lib import constants
from neutron_lib import context
from neutron_lib import exceptions as n_exc
from oslo_utils import uuidutils
import webob.exc
from neutron.api.v2 import attributes
from neutron import context
from neutron.tests import base

@ -18,6 +18,7 @@ import os
import mock
from neutron_lib.api import converters
from neutron_lib import constants
from neutron_lib import context
from neutron_lib import exceptions as n_exc
from neutron_lib.plugins import directory
from oslo_config import cfg
@ -36,7 +37,6 @@ from neutron.api.v2 import attributes
from neutron.api.v2 import base as v2_base
from neutron.api.v2 import router
from neutron.callbacks import registry
from neutron import context
from neutron import policy
from neutron import quota
from neutron.quota import resource_registry

@ -14,6 +14,7 @@
# under the License.
import mock
from neutron_lib import context
from neutron_lib import exceptions as n_exc
import oslo_i18n
from webob import exc
@ -22,7 +23,6 @@ import webtest
from neutron._i18n import _
from neutron.api.v2 import resource as wsgi_resource
from neutron.common import utils
from neutron import context
from neutron.tests import base
from neutron import wsgi

@ -234,46 +234,41 @@ class TestRequestContextSerializer(base.DietTestCase):
context.to_dict.assert_called_once_with()
@mock.patch('neutron.policy.check_is_advsvc', return_val=False)
@mock.patch('neutron.policy.check_is_admin', return_val=False)
def test_deserialize_context(self, m, n):
def test_deserialize_context(self):
context_dict = {'foo': 'bar',
'user_id': 1,
'tenant_id': 1}
'tenant_id': 1,
'is_admin': True}