summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmando Migliaccio <armamig@gmail.com>2016-11-30 20:37:28 -0800
committerPaul Belanger <pabelanger@redhat.com>2017-03-06 16:25:29 +0000
commitca751a1486812e498d9539980d8cd7bf6d7ebab7 (patch)
treebcfe2cb2415dfffb9c6c749f846d14d61338f0e9
parent5691f29e8fd1212bb22b1a48d32dbbddf7e0587d (diff)
Spin off context module
NeutronLibImpact Partially-implements: blueprint neutron-lib Change-Id: I48cf45dc1b07035d952152eac2548a3bd9fc2832
Notes
Notes (review): Code-Review+2: Ihar Hrachyshka <ihrachys@redhat.com> Code-Review+2: garyk <gkotton@vmware.com> Verified+1: Arista CI <arista-openstack-test@aristanetworks.com> Code-Review+1: Manjeet Singh Bhatia <manjeet.s.bhatia@intel.com> Verified+1: Nuage CI <nuage-ci@nuagenetworks.net> Workflow+1: Ihar Hrachyshka <ihrachys@redhat.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 06 Mar 2017 23:58:19 +0000 Reviewed-on: https://review.openstack.org/388157 Project: openstack/neutron Branch: refs/heads/master
-rw-r--r--neutron/agent/dhcp/agent.py2
-rw-r--r--neutron/agent/l3/agent.py2
-rw-r--r--neutron/agent/metadata/agent.py2
-rw-r--r--neutron/api/rpc/handlers/l3_rpc.py2
-rw-r--r--neutron/auth.py3
-rw-r--r--neutron/cmd/eventlet/usage_audit.py2
-rw-r--r--neutron/common/profiler.py2
-rw-r--r--neutron/common/rpc.py2
-rw-r--r--neutron/context.py175
-rw-r--r--neutron/db/agents_db.py2
-rw-r--r--neutron/db/agentschedulers_db.py2
-rw-r--r--neutron/db/api.py6
-rw-r--r--neutron/db/db_base_plugin_v2.py2
-rw-r--r--neutron/db/l3_db.py2
-rw-r--r--neutron/notifiers/nova.py2
-rw-r--r--neutron/plugins/ml2/drivers/agent/_common_agent.py2
-rw-r--r--neutron/plugins/ml2/drivers/helpers.py2
-rw-r--r--neutron/plugins/ml2/drivers/l2pop/mech_driver.py2
-rw-r--r--neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py2
-rw-r--r--neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py2
-rw-r--r--neutron/plugins/ml2/drivers/type_tunnel.py2
-rw-r--r--neutron/plugins/ml2/drivers/type_vlan.py2
-rw-r--r--neutron/plugins/ml2/ovo_rpc.py2
-rw-r--r--neutron/policy.py23
-rw-r--r--neutron/service.py2
-rw-r--r--neutron/services/externaldns/driver.py2
-rw-r--r--neutron/services/metering/agents/metering_agent.py2
-rw-r--r--neutron/services/qos/qos_plugin.py2
-rw-r--r--neutron/services/trunk/drivers/openvswitch/agent/ovsdb_handler.py2
-rw-r--r--neutron/services/trunk/plugin.py2
-rw-r--r--neutron/tests/common/helpers.py2
-rw-r--r--neutron/tests/functional/api/test_policies.py6
-rw-r--r--neutron/tests/functional/db/test_ipam.py2
-rw-r--r--neutron/tests/functional/pecan_wsgi/test_controllers.py8
-rw-r--r--neutron/tests/functional/pecan_wsgi/test_functional.py2
-rw-r--r--neutron/tests/functional/pecan_wsgi/test_hooks.py2
-rw-r--r--neutron/tests/functional/plugins/ml2/test_plugin.py2
-rw-r--r--neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py2
-rw-r--r--neutron/tests/functional/scheduler/test_l3_agent_scheduler.py2
-rw-r--r--neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py2
-rw-r--r--neutron/tests/retargetable/client_fixtures.py2
-rw-r--r--neutron/tests/unit/_test_extension_portbindings.py2
-rw-r--r--neutron/tests/unit/agent/l2/extensions/test_qos.py2
-rw-r--r--neutron/tests/unit/agent/test_securitygroups_rpc.py2
-rw-r--r--neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py2
-rw-r--r--neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py2
-rw-r--r--neutron/tests/unit/api/v2/test_attributes.py2
-rw-r--r--neutron/tests/unit/api/v2/test_base.py2
-rw-r--r--neutron/tests/unit/api/v2/test_resource.py2
-rw-r--r--neutron/tests/unit/common/test_rpc.py27
-rw-r--r--neutron/tests/unit/core_extensions/test_qos.py2
-rw-r--r--neutron/tests/unit/db/metering/test_metering_db.py2
-rw-r--r--neutron/tests/unit/db/quota/test_api.py2
-rw-r--r--neutron/tests/unit/db/quota/test_driver.py2
-rw-r--r--neutron/tests/unit/db/test_agents_db.py2
-rw-r--r--neutron/tests/unit/db/test_agentschedulers_db.py4
-rw-r--r--neutron/tests/unit/db/test_common_db_mixin.py2
-rw-r--r--neutron/tests/unit/db/test_db_base_plugin_v2.py2
-rw-r--r--neutron/tests/unit/db/test_dvr_mac_db.py2
-rw-r--r--neutron/tests/unit/db/test_extraroute_db.py2
-rw-r--r--neutron/tests/unit/db/test_l3_dvr_db.py2
-rw-r--r--neutron/tests/unit/db/test_l3_hamode_db.py2
-rw-r--r--neutron/tests/unit/db/test_provisioning_blocks.py2
-rw-r--r--neutron/tests/unit/db/test_securitygroups_db.py2
-rw-r--r--neutron/tests/unit/db/test_sqlalchemytypes.py2
-rw-r--r--neutron/tests/unit/db/test_standard_attr.py2
-rw-r--r--neutron/tests/unit/extensions/test_address_scope.py2
-rw-r--r--neutron/tests/unit/extensions/test_agent.py2
-rw-r--r--neutron/tests/unit/extensions/test_availability_zone.py3
-rw-r--r--neutron/tests/unit/extensions/test_dns.py2
-rw-r--r--neutron/tests/unit/extensions/test_external_net.py2
-rw-r--r--neutron/tests/unit/extensions/test_extraroute.py2
-rw-r--r--neutron/tests/unit/extensions/test_flavors.py2
-rw-r--r--neutron/tests/unit/extensions/test_l3.py2
-rw-r--r--neutron/tests/unit/extensions/test_l3_ext_gw_mode.py4
-rw-r--r--neutron/tests/unit/extensions/test_portsecurity.py2
-rw-r--r--neutron/tests/unit/extensions/test_providernet.py2
-rw-r--r--neutron/tests/unit/extensions/test_quotasv2.py2
-rw-r--r--neutron/tests/unit/extensions/test_securitygroup.py2
-rw-r--r--neutron/tests/unit/extensions/test_segment.py2
-rw-r--r--neutron/tests/unit/extensions/test_servicetype.py2
-rw-r--r--neutron/tests/unit/extensions/test_timestamp.py2
-rw-r--r--neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_db_api.py2
-rw-r--r--neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py2
-rw-r--r--neutron/tests/unit/ipam/test_requests.py2
-rw-r--r--neutron/tests/unit/ipam/test_subnet_alloc.py2
-rw-r--r--neutron/tests/unit/objects/db/test_api.py2
-rw-r--r--neutron/tests/unit/objects/port/extensions/test_allowedaddresspairs.py3
-rw-r--r--neutron/tests/unit/objects/test_base.py2
-rw-r--r--neutron/tests/unit/objects/test_rbac_db.py2
-rw-r--r--neutron/tests/unit/objects/test_subnet.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/drivers/base_type_tunnel.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/extension_drivers/test_qos_driver.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/drivers/test_helpers.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/test_db.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/test_extension_driver_api.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/test_ovo_rpc.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/test_plugin.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/test_port_binding.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/test_security_group.py2
-rw-r--r--neutron/tests/unit/plugins/ml2/test_tracked_resources.py2
-rw-r--r--neutron/tests/unit/quota/test_resource.py2
-rw-r--r--neutron/tests/unit/quota/test_resource_registry.py2
-rw-r--r--neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py4
-rw-r--r--neutron/tests/unit/scheduler/test_l3_agent_scheduler.py2
-rw-r--r--neutron/tests/unit/services/auto_allocate/test_db.py2
-rw-r--r--neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py2
-rw-r--r--neutron/tests/unit/services/metering/test_metering_plugin.py6
-rw-r--r--neutron/tests/unit/services/qos/notification_drivers/test_manager.py2
-rw-r--r--neutron/tests/unit/services/qos/test_qos_plugin.py2
-rw-r--r--neutron/tests/unit/services/revisions/test_revision_plugin.py2
-rw-r--r--neutron/tests/unit/test_context.py169
-rw-r--r--neutron/tests/unit/test_policy.py41
-rw-r--r--neutron/wsgi.py4
121 files changed, 152 insertions, 544 deletions
diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py
index 276e5ac..57988e7 100644
--- a/neutron/agent/dhcp/agent.py
+++ b/neutron/agent/dhcp/agent.py
@@ -18,6 +18,7 @@ import os
18 18
19import eventlet 19import eventlet
20from neutron_lib import constants 20from neutron_lib import constants
21from neutron_lib import context
21from neutron_lib import exceptions 22from neutron_lib import exceptions
22from oslo_concurrency import lockutils 23from oslo_concurrency import lockutils
23from oslo_config import cfg 24from oslo_config import cfg
@@ -37,7 +38,6 @@ from neutron.common import constants as n_const
37from neutron.common import rpc as n_rpc 38from neutron.common import rpc as n_rpc
38from neutron.common import topics 39from neutron.common import topics
39from neutron.common import utils 40from neutron.common import utils
40from neutron import context
41from neutron import manager 41from neutron import manager
42 42
43LOG = logging.getLogger(__name__) 43LOG = logging.getLogger(__name__)
diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py
index 64c15cb..2f8b255 100644
--- a/neutron/agent/l3/agent.py
+++ b/neutron/agent/l3/agent.py
@@ -16,6 +16,7 @@
16import eventlet 16import eventlet
17import netaddr 17import netaddr
18from neutron_lib import constants as lib_const 18from neutron_lib import constants as lib_const
19from neutron_lib import context as n_context
19from oslo_config import cfg 20from oslo_config import cfg
20from oslo_context import context as common_context 21from oslo_context import context as common_context
21from oslo_log import log as logging 22from oslo_log import log as logging
@@ -53,7 +54,6 @@ from neutron.common import ipv6_utils
53from neutron.common import rpc as n_rpc 54from neutron.common import rpc as n_rpc
54from neutron.common import topics 55from neutron.common import topics
55from neutron.common import utils 56from neutron.common import utils
56from neutron import context as n_context
57from neutron import manager 57from neutron import manager
58 58
59LOG = logging.getLogger(__name__) 59LOG = logging.getLogger(__name__)
diff --git a/neutron/agent/metadata/agent.py b/neutron/agent/metadata/agent.py
index 707b311..f849945c 100644
--- a/neutron/agent/metadata/agent.py
+++ b/neutron/agent/metadata/agent.py
@@ -17,6 +17,7 @@ import hmac
17 17
18import httplib2 18import httplib2
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20from oslo_config import cfg 21from oslo_config import cfg
21from oslo_log import log as logging 22from oslo_log import log as logging
22import oslo_messaging 23import oslo_messaging
@@ -34,7 +35,6 @@ from neutron.common import constants as n_const
34from neutron.common import rpc as n_rpc 35from neutron.common import rpc as n_rpc
35from neutron.common import topics 36from neutron.common import topics
36from neutron.conf.agent.metadata import config 37from neutron.conf.agent.metadata import config
37from neutron import context
38 38
39LOG = logging.getLogger(__name__) 39LOG = logging.getLogger(__name__)
40 40
diff --git a/neutron/api/rpc/handlers/l3_rpc.py b/neutron/api/rpc/handlers/l3_rpc.py
index c75389f..079271f 100644
--- a/neutron/api/rpc/handlers/l3_rpc.py
+++ b/neutron/api/rpc/handlers/l3_rpc.py
@@ -14,6 +14,7 @@
14# limitations under the License. 14# limitations under the License.
15 15
16from neutron_lib import constants 16from neutron_lib import constants
17from neutron_lib import context as neutron_context
17from neutron_lib import exceptions 18from neutron_lib import exceptions
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_config import cfg 20from oslo_config import cfg
@@ -23,7 +24,6 @@ import six
23 24
24from neutron.common import constants as n_const 25from neutron.common import constants as n_const
25from neutron.common import utils 26from neutron.common import utils
26from neutron import context as neutron_context
27from neutron.db import api as db_api 27from neutron.db import api as db_api
28from neutron.extensions import l3 28from neutron.extensions import l3
29from neutron.extensions import portbindings 29from neutron.extensions import portbindings
diff --git a/neutron/auth.py b/neutron/auth.py
index 5d972b8..23150f3 100644
--- a/neutron/auth.py
+++ b/neutron/auth.py
@@ -12,6 +12,7 @@
12# License for the specific language governing permissions and limitations 12# License for the specific language governing permissions and limitations
13# under the License. 13# under the License.
14 14
15from neutron_lib import context
15from oslo_config import cfg 16from oslo_config import cfg
16from oslo_log import log as logging 17from oslo_log import log as logging
17from oslo_middleware import base 18from oslo_middleware import base
@@ -19,8 +20,6 @@ from oslo_middleware import request_id
19import webob.dec 20import webob.dec
20import webob.exc 21import webob.exc
21 22
22from neutron import context
23
24LOG = logging.getLogger(__name__) 23LOG = logging.getLogger(__name__)
25 24
26 25
diff --git a/neutron/cmd/eventlet/usage_audit.py b/neutron/cmd/eventlet/usage_audit.py
index 56fe7a0..44eb85b 100644
--- a/neutron/cmd/eventlet/usage_audit.py
+++ b/neutron/cmd/eventlet/usage_audit.py
@@ -20,11 +20,11 @@ subnets.
20import sys 20import sys
21 21
22from neutron_lib import constants 22from neutron_lib import constants
23from neutron_lib import context
23from neutron_lib.plugins import directory 24from neutron_lib.plugins import directory
24 25
25from neutron.common import config 26from neutron.common import config
26from neutron.common import rpc as n_rpc 27from neutron.common import rpc as n_rpc
27from neutron import context
28from neutron import manager 28from neutron import manager
29 29
30 30
diff --git a/neutron/common/profiler.py b/neutron/common/profiler.py
index b68d8cc..5d7afae 100644
--- a/neutron/common/profiler.py
+++ b/neutron/common/profiler.py
@@ -10,6 +10,7 @@
10# License for the specific language governing permissions and limitations 10# License for the specific language governing permissions and limitations
11# under the License. 11# under the License.
12 12
13from neutron_lib import context
13from oslo_config import cfg 14from oslo_config import cfg
14from oslo_log import log as logging 15from oslo_log import log as logging
15import osprofiler.initializer 16import osprofiler.initializer
@@ -17,7 +18,6 @@ from osprofiler import opts as profiler_opts
17import osprofiler.web 18import osprofiler.web
18 19
19from neutron._i18n import _LI 20from neutron._i18n import _LI
20from neutron import context
21 21
22 22
23CONF = cfg.CONF 23CONF = cfg.CONF
diff --git a/neutron/common/rpc.py b/neutron/common/rpc.py
index 5d80144..01bd99d 100644
--- a/neutron/common/rpc.py
+++ b/neutron/common/rpc.py
@@ -18,6 +18,7 @@ import collections
18import random 18import random
19import time 19import time
20 20
21from neutron_lib import context
21from neutron_lib import exceptions as lib_exceptions 22from neutron_lib import exceptions as lib_exceptions
22from oslo_config import cfg 23from oslo_config import cfg
23from oslo_log import log as logging 24from oslo_log import log as logging
@@ -30,7 +31,6 @@ from osprofiler import profiler
30 31
31from neutron._i18n import _LE, _LW 32from neutron._i18n import _LE, _LW
32from neutron.common import exceptions 33from neutron.common import exceptions
33from neutron import context
34 34
35 35
36LOG = logging.getLogger(__name__) 36LOG = logging.getLogger(__name__)
diff --git a/neutron/context.py b/neutron/context.py
deleted file mode 100644
index f8c49ca..0000000
--- a/neutron/context.py
+++ /dev/null
@@ -1,175 +0,0 @@
1# Copyright 2012 OpenStack Foundation.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16"""Context: context for security/db session."""
17
18import copy
19import datetime
20
21from oslo_context import context as oslo_context
22from oslo_db.sqlalchemy import enginefacade
23
24from neutron.db import api as db_api
25from neutron import policy
26
27
28class ContextBase(oslo_context.RequestContext):
29 """Security context and request information.
30
31 Represents the user taking a given action within the system.
32
33 """
34
35 def __init__(self, user_id=None, tenant_id=None, is_admin=None,
36 timestamp=None, tenant_name=None, user_name=None,
37 is_advsvc=None, **kwargs):
38 """Object initialization.
39
40 :param overwrite: Set to False to ensure that the greenthread local
41 copy of the index is not overwritten.
42 """
43 # NOTE(jamielennox): We maintain these arguments in order for tests
44 # that pass arguments positionally.
45 kwargs.setdefault('user', user_id)
46 kwargs.setdefault('tenant', tenant_id)
47 super(ContextBase, self).__init__(is_admin=is_admin, **kwargs)
48
49 self.user_name = user_name
50 # NOTE(sdague): tenant* is a deprecated set of names from
51 # keystone, and is no longer set in modern keystone middleware
52 # code, as such this is almost always going to be None.
53 self.tenant_name = tenant_name
54
55 if not timestamp:
56 timestamp = datetime.datetime.utcnow()
57 self.timestamp = timestamp
58 self.is_advsvc = is_advsvc
59 if self.is_advsvc is None:
60 self.is_advsvc = self.is_admin or policy.check_is_advsvc(self)
61 if self.is_admin is None:
62 self.is_admin = policy.check_is_admin(self)
63
64 @property
65 def project_id(self):
66 return self.tenant
67
68 @property
69 def tenant_id(self):
70 return self.tenant
71
72 @tenant_id.setter
73 def tenant_id(self, tenant_id):
74 self.tenant = tenant_id
75
76 @property
77 def user_id(self):
78 return self.user
79
80 @user_id.setter
81 def user_id(self, user_id):
82 self.user = user_id
83
84 def to_dict(self):
85 context = super(ContextBase, self).to_dict()
86 context.update({
87 'user_id': self.user_id,
88 'tenant_id': self.tenant_id,
89 'project_id': self.project_id,
90 'timestamp': str(self.timestamp),
91 # prefer project_name, as that's what's going to be set by
92 # keystone. Fall back if for some reason it's blank.
93 'tenant_name': self.project_name or self.tenant_name,
94 'project_name': self.project_name or self.tenant_name,
95 'user_name': self.user_name,
96 })
97 return context
98
99 def to_policy_values(self):
100 values = super(ContextBase, self).to_policy_values()
101 values['tenant_id'] = self.tenant_id
102 values['is_admin'] = self.is_admin
103
104 # NOTE(jamielennox): These are almost certainly unused and non-standard
105 # but kept for backwards compatibility. Remove them in Pike
106 # (oslo.context from Ocata release already issues deprecation warnings
107 # for non-standard keys).
108 values['user'] = self.user
109 values['tenant'] = self.tenant
110 values['domain'] = self.domain
111 values['user_domain'] = self.user_domain
112 values['project_domain'] = self.project_domain
113 # prefer project_name, as that's what's going to be set by
114 # keystone. Fall back if for some reason it's blank.
115 values['tenant_name'] = self.project_name or self.tenant_name
116 values['project_name'] = self.project_name or self.tenant_name
117 values['user_name'] = self.user_name
118
119 return values
120
121 @classmethod
122 def from_dict(cls, values):
123 return cls(user_id=values.get('user_id', values.get('user')),
124 tenant_id=values.get('tenant_id', values.get('project_id')),
125 is_admin=values.get('is_admin'),
126 roles=values.get('roles'),
127 timestamp=values.get('timestamp'),
128 request_id=values.get('request_id'),
129 tenant_name=values.get('tenant_name'),
130 user_name=values.get('user_name'),
131 auth_token=values.get('auth_token'))
132
133 def elevated(self):
134 """Return a version of this context with admin flag set."""
135 context = copy.copy(self)
136 context.is_admin = True
137
138 if 'admin' not in [x.lower() for x in context.roles]:
139 context.roles = context.roles + ["admin"]
140
141 return context
142
143
144@enginefacade.transaction_context_provider
145class ContextBaseWithSession(ContextBase):
146 pass
147
148
149class Context(ContextBaseWithSession):
150 def __init__(self, *args, **kwargs):
151 super(Context, self).__init__(*args, **kwargs)
152 self._session = None
153
154 @property
155 def session(self):
156 # TODO(akamyshnikova): checking for session attribute won't be needed
157 # when reader and writer will be used
158 if hasattr(super(Context, self), 'session'):
159 return super(Context, self).session
160 if self._session is None:
161 self._session = db_api.get_writer_session()
162 return self._session
163
164
165def get_admin_context():
166 return Context(user_id=None,
167 tenant_id=None,
168 is_admin=True,
169 overwrite=False)
170
171
172def get_admin_context_without_session():
173 return ContextBase(user_id=None,
174 tenant_id=None,
175 is_admin=True)
diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py
index 0d27ac2..0928d25 100644
--- a/neutron/db/agents_db.py
+++ b/neutron/db/agents_db.py
@@ -19,6 +19,7 @@ import debtcollector
19from eventlet import greenthread 19from eventlet import greenthread
20from neutron_lib.api import converters 20from neutron_lib.api import converters
21from neutron_lib import constants 21from neutron_lib import constants
22from neutron_lib import context
22from neutron_lib.plugins import directory 23from neutron_lib.plugins import directory
23from oslo_config import cfg 24from oslo_config import cfg
24from oslo_log import log as logging 25from oslo_log import log as logging
@@ -37,7 +38,6 @@ from neutron.callbacks import events
37from neutron.callbacks import registry 38from neutron.callbacks import registry
38from neutron.callbacks import resources 39from neutron.callbacks import resources
39from neutron.common import constants as n_const 40from neutron.common import constants as n_const
40from neutron import context
41from neutron.db import _utils as db_utils 41from neutron.db import _utils as db_utils
42from neutron.db import api as db_api 42from neutron.db import api as db_api
43from neutron.db.models import agent as agent_model 43from neutron.db.models import agent as agent_model
diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py
index c900e3e..716889d 100644
--- a/neutron/db/agentschedulers_db.py
+++ b/neutron/db/agentschedulers_db.py
@@ -18,6 +18,7 @@ import random
18import time 18import time
19 19
20from neutron_lib import constants 20from neutron_lib import constants
21from neutron_lib import context as ncontext
21from oslo_config import cfg 22from oslo_config import cfg
22from oslo_log import log as logging 23from oslo_log import log as logging
23import oslo_messaging 24import oslo_messaging
@@ -29,7 +30,6 @@ from neutron._i18n import _, _LE, _LI, _LW
29from neutron.agent.common import utils as agent_utils 30from neutron.agent.common import utils as agent_utils
30from neutron.common import constants as n_const 31from neutron.common import constants as n_const
31from neutron.common import utils 32from neutron.common import utils
32from neutron import context as ncontext
33from neutron.db import agents_db 33from neutron.db import agents_db
34from neutron.db.availability_zone import network as network_az 34from neutron.db.availability_zone import network as network_az
35from neutron.db.models import agent as agent_model 35from neutron.db.models import agent as agent_model
diff --git a/neutron/db/api.py b/neutron/db/api.py
index affd3c4..3f1e687 100644
--- a/neutron/db/api.py
+++ b/neutron/db/api.py
@@ -17,11 +17,11 @@ import contextlib
17import copy 17import copy
18 18
19from debtcollector import removals 19from debtcollector import removals
20from neutron_lib.db import api
20from neutron_lib import exceptions 21from neutron_lib import exceptions
21from oslo_config import cfg 22from oslo_config import cfg
22from oslo_db import api as oslo_db_api 23from oslo_db import api as oslo_db_api
23from oslo_db import exception as db_exc 24from oslo_db import exception as db_exc
24from oslo_db.sqlalchemy import enginefacade
25from oslo_log import log as logging 25from oslo_log import log as logging
26from oslo_utils import excutils 26from oslo_utils import excutils
27from osprofiler import opts as profiler_opts 27from osprofiler import opts as profiler_opts
@@ -44,9 +44,7 @@ def set_hook(engine):
44 osprofiler.sqlalchemy.add_tracing(sqlalchemy, engine, 'neutron.db') 44 osprofiler.sqlalchemy.add_tracing(sqlalchemy, engine, 'neutron.db')
45 45
46 46
47context_manager = enginefacade.transaction_context() 47context_manager = api.get_context_manager()
48
49context_manager.configure(sqlite_fk=True)
50 48
51# TODO(ihrachys) the hook assumes options defined by osprofiler, and the only 49# TODO(ihrachys) the hook assumes options defined by osprofiler, and the only
52# public function that is provided by osprofiler that will register them is 50# public function that is provided by osprofiler that will register them is
diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py
index 34f6b76..e125838 100644
--- a/neutron/db/db_base_plugin_v2.py
+++ b/neutron/db/db_base_plugin_v2.py
@@ -18,6 +18,7 @@ import functools
18import netaddr 18import netaddr
19from neutron_lib.api import validators 19from neutron_lib.api import validators
20from neutron_lib import constants 20from neutron_lib import constants
21from neutron_lib import context as ctx
21from neutron_lib import exceptions as exc 22from neutron_lib import exceptions as exc
22from neutron_lib.plugins import directory 23from neutron_lib.plugins import directory
23from oslo_config import cfg 24from oslo_config import cfg
@@ -39,7 +40,6 @@ from neutron.common import constants as n_const
39from neutron.common import exceptions as n_exc 40from neutron.common import exceptions as n_exc
40from neutron.common import ipv6_utils 41from neutron.common import ipv6_utils
41from neutron.common import utils 42from neutron.common import utils
42from neutron import context as ctx
43from neutron.db import _utils as ndb_utils 43from neutron.db import _utils as ndb_utils
44from neutron.db import api as db_api 44from neutron.db import api as db_api
45from neutron.db import db_base_plugin_common 45from neutron.db import db_base_plugin_common
diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py
index 6bfd57f..9a66069 100644
--- a/neutron/db/l3_db.py
+++ b/neutron/db/l3_db.py
@@ -20,6 +20,7 @@ from debtcollector import removals
20import netaddr 20import netaddr
21from neutron_lib.api import validators 21from neutron_lib.api import validators
22from neutron_lib import constants 22from neutron_lib import constants
23from neutron_lib import context as n_ctx
23from neutron_lib import exceptions as n_exc 24from neutron_lib import exceptions as n_exc
24from neutron_lib.plugins import directory 25from neutron_lib.plugins import directory
25from oslo_log import log as logging 26from oslo_log import log as logging
@@ -38,7 +39,6 @@ from neutron.common import constants as n_const
38from neutron.common import ipv6_utils 39from neutron.common import ipv6_utils
39from neutron.common import rpc as n_rpc 40from neutron.common import rpc as n_rpc
40from neutron.common import utils 41from neutron.common import utils
41from neutron import context as n_ctx
42from neutron.db import _utils as db_utils 42from neutron.db import _utils as db_utils
43from neutron.db import api as db_api 43from neutron.db import api as db_api
44from neutron.db import common_db_mixin 44from neutron.db import common_db_mixin
diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py
index 1729038..0971f46 100644
--- a/neutron/notifiers/nova.py
+++ b/neutron/notifiers/nova.py
@@ -15,6 +15,7 @@
15 15
16from keystoneauth1 import loading as ks_loading 16from keystoneauth1 import loading as ks_loading
17from neutron_lib import constants 17from neutron_lib import constants
18from neutron_lib import context
18from neutron_lib import exceptions as exc 19from neutron_lib import exceptions as exc
19from neutron_lib.plugins import directory 20from neutron_lib.plugins import directory
20from novaclient import api_versions 21from novaclient import api_versions
@@ -29,7 +30,6 @@ from neutron._i18n import _LE, _LI, _LW
29from neutron.callbacks import events 30from neutron.callbacks import events
30from neutron.callbacks import registry 31from neutron.callbacks import registry
31from neutron.callbacks import resources 32from neutron.callbacks import resources
32from neutron import context
33from neutron.notifiers import batch_notifier 33from neutron.notifiers import batch_notifier
34 34
35 35
diff --git a/neutron/plugins/ml2/drivers/agent/_common_agent.py b/neutron/plugins/ml2/drivers/agent/_common_agent.py
index f40d0e7..a31134c 100644
--- a/neutron/plugins/ml2/drivers/agent/_common_agent.py
+++ b/neutron/plugins/ml2/drivers/agent/_common_agent.py
@@ -20,6 +20,7 @@ import sys
20import time 20import time
21 21
22from neutron_lib import constants 22from neutron_lib import constants
23from neutron_lib import context
23from oslo_config import cfg 24from oslo_config import cfg
24from oslo_log import log as logging 25from oslo_log import log as logging
25from oslo_service import loopingcall 26from oslo_service import loopingcall
@@ -39,7 +40,6 @@ from neutron.callbacks import resources as local_resources
39from neutron.common import config as common_config 40from neutron.common import config as common_config
40from neutron.common import constants as n_const 41from neutron.common import constants as n_const
41from neutron.common import topics 42from neutron.common import topics
42from neutron import context
43from neutron.plugins.ml2.drivers.agent import _agent_manager_base as amb 43from neutron.plugins.ml2.drivers.agent import _agent_manager_base as amb
44from neutron.plugins.ml2.drivers.agent import capabilities 44from neutron.plugins.ml2.drivers.agent import capabilities
45from neutron.plugins.ml2.drivers.agent import config as cagt_config # noqa 45from neutron.plugins.ml2.drivers.agent import config as cagt_config # noqa
diff --git a/neutron/plugins/ml2/drivers/helpers.py b/neutron/plugins/ml2/drivers/helpers.py
index 1996ff8..91dc3cc 100644
--- a/neutron/plugins/ml2/drivers/helpers.py
+++ b/neutron/plugins/ml2/drivers/helpers.py
@@ -15,6 +15,7 @@
15 15
16import random 16import random
17 17
18from neutron_lib import context as neutron_ctx
18from neutron_lib.utils import helpers 19from neutron_lib.utils import helpers
19from oslo_config import cfg 20from oslo_config import cfg
20from oslo_db import exception as db_exc 21from oslo_db import exception as db_exc
@@ -22,7 +23,6 @@ from oslo_log import log
22 23
23from neutron._i18n import _LE 24from neutron._i18n import _LE
24from neutron.common import exceptions as exc 25from neutron.common import exceptions as exc
25from neutron import context as neutron_ctx
26from neutron.plugins.common import utils as p_utils 26from neutron.plugins.common import utils as p_utils
27from neutron.plugins.ml2 import driver_api as api 27from neutron.plugins.ml2 import driver_api as api
28 28
diff --git a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py
index 74aa035..e1f5a13 100644
--- a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py
+++ b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py
@@ -14,6 +14,7 @@
14# under the License. 14# under the License.
15 15
16from neutron_lib import constants as const 16from neutron_lib import constants as const
17from neutron_lib import context as n_context
17from neutron_lib import exceptions 18from neutron_lib import exceptions
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_config import cfg 20from oslo_config import cfg
@@ -21,7 +22,6 @@ from oslo_log import log as logging
21 22
22from neutron._i18n import _, _LW 23from neutron._i18n import _, _LW
23from neutron.conf.plugins.ml2.drivers import l2pop as config 24from neutron.conf.plugins.ml2.drivers import l2pop as config
24from neutron import context as n_context
25from neutron.db import api as db_api 25from neutron.db import api as db_api
26from neutron.db import l3_hamode_db 26from neutron.db import l3_hamode_db
27from neutron.plugins.ml2 import driver_api as api 27from neutron.plugins.ml2 import driver_api as api
diff --git a/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py b/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py
index 0527bb8..1625f74 100644
--- a/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py
+++ b/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py
@@ -21,6 +21,7 @@ import sys
21import time 21import time
22 22
23from neutron_lib import constants as n_constants 23from neutron_lib import constants as n_constants
24from neutron_lib import context
24from neutron_lib.utils import helpers 25from neutron_lib.utils import helpers
25from oslo_config import cfg 26from oslo_config import cfg
26from oslo_log import log as logging 27from oslo_log import log as logging
@@ -38,7 +39,6 @@ from neutron.api.rpc.handlers import securitygroups_rpc as sg_rpc
38from neutron.common import config as common_config 39from neutron.common import config as common_config
39from neutron.common import profiler as setup_profiler 40from neutron.common import profiler as setup_profiler
40from neutron.common import topics 41from neutron.common import topics
41from neutron import context
42from neutron.extensions import portbindings 42from neutron.extensions import portbindings
43from neutron.plugins.ml2.drivers.mech_sriov.agent.common import config 43from neutron.plugins.ml2.drivers.mech_sriov.agent.common import config
44from neutron.plugins.ml2.drivers.mech_sriov.agent.common \ 44from neutron.plugins.ml2.drivers.mech_sriov.agent.common \
diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py
index 6b8adc5..4975358 100644
--- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py
+++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py
@@ -23,6 +23,7 @@ import time
23 23
24import netaddr 24import netaddr
25from neutron_lib import constants as n_const 25from neutron_lib import constants as n_const
26from neutron_lib import context
26from neutron_lib.utils import helpers 27from neutron_lib.utils import helpers
27from oslo_config import cfg 28from oslo_config import cfg
28from oslo_log import log as logging 29from oslo_log import log as logging
@@ -53,7 +54,6 @@ from neutron.common import config
53from neutron.common import constants as c_const 54from neutron.common import constants as c_const
54from neutron.common import topics 55from neutron.common import topics
55from neutron.conf.agent import xenapi_conf 56from neutron.conf.agent import xenapi_conf
56from neutron import context
57from neutron.extensions import portbindings 57from neutron.extensions import portbindings
58from neutron.plugins.common import constants as p_const 58from neutron.plugins.common import constants as p_const
59from neutron.plugins.common import utils as p_utils 59from neutron.plugins.common import utils as p_utils
diff --git a/neutron/plugins/ml2/drivers/type_tunnel.py b/neutron/plugins/ml2/drivers/type_tunnel.py
index d1cf343..9ba44b7 100644
--- a/neutron/plugins/ml2/drivers/type_tunnel.py
+++ b/neutron/plugins/ml2/drivers/type_tunnel.py
@@ -17,6 +17,7 @@ import itertools
17import operator 17import operator
18 18
19import netaddr 19import netaddr
20from neutron_lib import context
20from neutron_lib import exceptions as exc 21from neutron_lib import exceptions as exc
21from oslo_config import cfg 22from oslo_config import cfg
22from oslo_db import api as oslo_db_api 23from oslo_db import api as oslo_db_api
@@ -28,7 +29,6 @@ from sqlalchemy import or_
28 29
29from neutron._i18n import _, _LI, _LW 30from neutron._i18n import _, _LI, _LW
30from neutron.common import topics 31from neutron.common import topics
31from neutron import context
32from neutron.db import api as db_api 32from neutron.db import api as db_api
33from neutron.plugins.common import constants as p_const 33from neutron.plugins.common import constants as p_const
34from neutron.plugins.common import utils as plugin_utils 34from neutron.plugins.common import utils as plugin_utils
diff --git a/neutron/plugins/ml2/drivers/type_vlan.py b/neutron/plugins/ml2/drivers/type_vlan.py
index d696685..bf56fcf 100644
--- a/neutron/plugins/ml2/drivers/type_vlan.py
+++ b/neutron/plugins/ml2/drivers/type_vlan.py
@@ -15,6 +15,7 @@
15 15
16import sys 16import sys
17 17
18from neutron_lib import context
18from neutron_lib import exceptions as exc 19from neutron_lib import exceptions as exc
19from oslo_config import cfg 20from oslo_config import cfg
20from oslo_log import log 21from oslo_log import log
@@ -22,7 +23,6 @@ from six import moves
22 23
23from neutron._i18n import _, _LE, _LI, _LW 24from neutron._i18n import _, _LE, _LI, _LW
24from neutron.conf.plugins.ml2.drivers import driver_type 25from neutron.conf.plugins.ml2.drivers import driver_type
25from neutron import context
26from neutron.db import api as db_api 26from neutron.db import api as db_api
27from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model 27from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
28from neutron.plugins.common import constants as p_const 28from neutron.plugins.common import constants as p_const
diff --git a/neutron/plugins/ml2/ovo_rpc.py b/neutron/plugins/ml2/ovo_rpc.py
index ec7d84d..ad8d376 100644
--- a/neutron/plugins/ml2/ovo_rpc.py
+++ b/neutron/plugins/ml2/ovo_rpc.py
@@ -14,6 +14,7 @@
14import traceback 14import traceback
15 15
16import eventlet 16import eventlet
17from neutron_lib import context as n_ctx
17from oslo_concurrency import lockutils 18from oslo_concurrency import lockutils
18from oslo_log import log as logging 19from oslo_log import log as logging
19 20
@@ -23,7 +24,6 @@ from neutron.api.rpc.handlers import resources_rpc
23from neutron.callbacks import events 24from neutron.callbacks import events
24from neutron.callbacks import registry 25from neutron.callbacks import registry
25from neutron.callbacks import resources 26from neutron.callbacks import resources
26from neutron import context as n_ctx
27from neutron.db import api as db_api 27from neutron.db import api as db_api
28from neutron.objects import network 28from neutron.objects import network
29from neutron.objects import ports 29from neutron.objects import ports
diff --git a/neutron/policy.py b/neutron/policy.py
index 247edd7..ed9e2f1 100644
--- a/neutron/policy.py
+++ b/neutron/policy.py
@@ -17,6 +17,7 @@ import collections
17import re 17import re
18 18
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20from neutron_lib import exceptions 21from neutron_lib import exceptions
21from neutron_lib.plugins import directory 22from neutron_lib.plugins import directory
22from oslo_config import cfg 23from oslo_config import cfg
@@ -24,7 +25,6 @@ from oslo_db import exception as db_exc
24from oslo_log import log as logging 25from oslo_log import log as logging
25from oslo_policy import policy 26from oslo_policy import policy
26from oslo_utils import excutils 27from oslo_utils import excutils
27from oslo_utils import importutils
28import six 28import six
29 29
30from neutron._i18n import _, _LE, _LW 30from neutron._i18n import _, _LE, _LW
@@ -222,7 +222,6 @@ class OwnerCheck(policy.Check):
222 f = getattr(directory.get_plugin(), 'get_%s' % resource_type) 222 f = getattr(directory.get_plugin(), 'get_%s' % resource_type)
223 # f *must* exist, if not found it is better to let neutron 223 # f *must* exist, if not found it is better to let neutron
224 # explode. Check will be performed with admin context 224 # explode. Check will be performed with admin context
225 context = importutils.import_module('neutron.context')
226 try: 225 try:
227 data = f(context.get_admin_context(), 226 data = f(context.get_admin_context(),
228 resource_id, 227 resource_id,
@@ -409,23 +408,3 @@ def enforce(context, action, target, plugin=None, pluralized=None):
409 log_rule_list(rule) 408 log_rule_list(rule)
410 LOG.debug("Failed policy check for '%s'", action) 409 LOG.debug("Failed policy check for '%s'", action)
411 return result 410 return result
412
413
414def check_is_admin(context):
415 """Verify context has admin rights according to policy settings."""
416 init()
417 # the target is user-self
418 credentials = context.to_policy_values()
419 if ADMIN_CTX_POLICY not in _ENFORCER.rules:
420 return False
421 return _ENFORCER.enforce(ADMIN_CTX_POLICY, credentials, credentials)
422
423
424def check_is_advsvc(context):
425 """Verify context has advsvc rights according to policy settings."""
426 init()
427 # the target is user-self
428 credentials = context.to_policy_values()
429 if ADVSVC_CTX_POLICY not in _ENFORCER.rules:
430 return False
431 return _ENFORCER.enforce(ADVSVC_CTX_POLICY, credentials, credentials)
diff --git a/neutron/service.py b/neutron/service.py
index bf9d10b..c3942fd 100644
--- a/neutron/service.py
+++ b/neutron/service.py
@@ -17,6 +17,7 @@ import inspect
17import os 17import os
18import random 18import random
19 19
20from neutron_lib import context
20from neutron_lib.plugins import directory 21from neutron_lib.plugins import directory
21from oslo_concurrency import processutils 22from oslo_concurrency import processutils
22from oslo_config import cfg 23from oslo_config import cfg
@@ -35,7 +36,6 @@ from neutron.common import config
35from neutron.common import profiler 36from neutron.common import profiler
36from neutron.common import rpc as n_rpc 37from neutron.common import rpc as n_rpc
37from neutron.conf import service 38from neutron.conf import service
38from neutron import context
39from neutron.db import api as session 39from neutron.db import api as session
40from neutron import worker as neutron_worker 40from neutron import worker as neutron_worker
41from neutron import wsgi 41from neutron import wsgi
diff --git a/neutron/services/externaldns/driver.py b/neutron/services/externaldns/driver.py
index e25de81..ae9feef 100644
--- a/neutron/services/externaldns/driver.py
+++ b/neutron/services/externaldns/driver.py
@@ -46,7 +46,7 @@ class ExternalDNSService(object):
46 """Create a record set in the specified zone. 46 """Create a record set in the specified zone.
47 47
48 :param context: neutron api request context 48 :param context: neutron api request context
49 :type context: neutron.context.Context 49 :type context: neutron_lib.context.Context
50 :param dns_domain: the dns_domain where the record set will be created 50 :param dns_domain: the dns_domain where the record set will be created
51 :type dns_domain: String 51 :type dns_domain: String
52 :param dns_name: the name associated with the record set 52 :param dns_name: the name associated with the record set
diff --git a/neutron/services/metering/agents/metering_agent.py b/neutron/services/metering/agents/metering_agent.py
index f8c5bd3..14a7a1d 100644
--- a/neutron/services/metering/agents/metering_agent.py
+++ b/neutron/services/metering/agents/metering_agent.py
@@ -15,6 +15,7 @@
15import sys 15import sys
16 16
17from neutron_lib import constants 17from neutron_lib import constants
18from neutron_lib import context
18from oslo_config import cfg 19from oslo_config import cfg
19from oslo_log import log as logging 20from oslo_log import log as logging
20import oslo_messaging 21import oslo_messaging
@@ -33,7 +34,6 @@ from neutron.common import rpc as n_rpc
33from neutron.common import topics 34from neutron.common import topics
34from neutron.common import utils 35from neutron.common import utils
35from neutron.conf.services import metering_agent 36from neutron.conf.services import metering_agent
36from neutron import context
37from neutron import manager 37from neutron import manager
38from neutron import service as neutron_service 38from neutron import service as neutron_service
39 39
diff --git a/neutron/services/qos/qos_plugin.py b/neutron/services/qos/qos_plugin.py
index 3f434a9..56d1ef4 100644
--- a/neutron/services/qos/qos_plugin.py
+++ b/neutron/services/qos/qos_plugin.py
@@ -52,7 +52,7 @@ class QoSPlugin(qos.QoSPluginBase):
52 """Create a QoS policy. 52 """Create a QoS policy.
53 53
54 :param context: neutron api request context 54 :param context: neutron api request context
55 :type context: neutron.context.Context 55 :type context: neutron_lib.context.Context
56 :param policy: policy data to be applied 56 :param policy: policy data to be applied
57 :type policy: dict 57 :type policy: dict
58 58
diff --git a/neutron/services/trunk/drivers/openvswitch/agent/ovsdb_handler.py b/neutron/services/trunk/drivers/openvswitch/agent/ovsdb_handler.py
index 3814c31..f5463db 100644
--- a/neutron/services/trunk/drivers/openvswitch/agent/ovsdb_handler.py
+++ b/neutron/services/trunk/drivers/openvswitch/agent/ovsdb_handler.py
@@ -16,6 +16,7 @@
16import functools 16import functools
17 17
18import eventlet 18import eventlet
19from neutron_lib import context as n_context
19from oslo_concurrency import lockutils 20from oslo_concurrency import lockutils
20from oslo_context import context as o_context 21from oslo_context import context as o_context
21from oslo_log import log as logging 22from oslo_log import log as logging
@@ -28,7 +29,6 @@ from neutron.api.rpc.handlers import resources_rpc
28from neutron.callbacks import events 29from neutron.callbacks import events
29from neutron.callbacks import registry 30from neutron.callbacks import registry
30from neutron.common import utils as common_utils 31from neutron.common import utils as common_utils
31from neutron import context as n_context
32from neutron.plugins.ml2.drivers.openvswitch.agent.common \ 32from neutron.plugins.ml2.drivers.openvswitch.agent.common \
33 import constants as ovs_agent_constants 33 import constants as ovs_agent_constants
34from neutron.services.trunk import constants 34from neutron.services.trunk import constants
diff --git a/neutron/services/trunk/plugin.py b/neutron/services/trunk/plugin.py
index 9473d96..924785c 100644
--- a/neutron/services/trunk/plugin.py
+++ b/neutron/services/trunk/plugin.py
@@ -14,6 +14,7 @@
14 14
15import copy 15import copy
16 16
17from neutron_lib import context
17from oslo_log import log as logging 18from oslo_log import log as logging
18from oslo_utils import uuidutils 19from oslo_utils import uuidutils
19 20
@@ -21,7 +22,6 @@ from neutron.api.v2 import attributes
21from neutron.callbacks import events 22from neutron.callbacks import events
22from neutron.callbacks import registry 23from neutron.callbacks import registry
23from neutron.callbacks import resources 24from neutron.callbacks import resources
24from neutron import context
25from neutron.db import api as db_api 25from neutron.db import api as db_api
26from neutron.db import common_db_mixin 26from neutron.db import common_db_mixin
27from neutron.db import db_base_plugin_common 27from neutron.db import db_base_plugin_common
diff --git a/neutron/tests/common/helpers.py b/neutron/tests/common/helpers.py
index 63a132b..8d76c19 100644
--- a/neutron/tests/common/helpers.py
+++ b/neutron/tests/common/helpers.py
@@ -19,6 +19,7 @@ import os
19import random 19import random
20 20
21from neutron_lib import constants 21from neutron_lib import constants
22from neutron_lib import context
22from oslo_utils import timeutils 23from oslo_utils import timeutils
23import six 24import six
24import testtools 25import testtools
@@ -26,7 +27,6 @@ import testtools
26import neutron 27import neutron
27from neutron.agent.common import ovs_lib 28from neutron.agent.common import ovs_lib
28from neutron.common import topics 29from neutron.common import topics
29from neutron import context
30from neutron.db import agents_db 30from neutron.db import agents_db
31from neutron.db import common_db_mixin 31from neutron.db import common_db_mixin
32 32
diff --git a/neutron/tests/functional/api/test_policies.py b/neutron/tests/functional/api/test_policies.py
index 9ad4851..9f0515c 100644
--- a/neutron/tests/functional/api/test_policies.py
+++ b/neutron/tests/functional/api/test_policies.py
@@ -15,9 +15,10 @@
15 15
16import os.path 16import os.path
17 17
18from neutron_lib import context
19
18from neutron.api import extensions 20from neutron.api import extensions
19from neutron.api.v2 import attributes 21from neutron.api.v2 import attributes
20from neutron import context
21from neutron import policy 22from neutron import policy
22from neutron.tests import base 23from neutron.tests import base
23from neutron.tests import tools 24from neutron.tests import tools
@@ -41,7 +42,6 @@ class APIPolicyTestCase(base.BaseTestCase):
41 self.useFixture(tools.AttributeMapMemento()) 42 self.useFixture(tools.AttributeMapMemento())
42 self.extension_path = os.path.abspath(os.path.join( 43 self.extension_path = os.path.abspath(os.path.join(
43 TEST_PATH, "../../../extensions")) 44 TEST_PATH, "../../../extensions"))
44 policy.reset()
45 self.addCleanup(policy.reset) 45 self.addCleanup(policy.reset)
46 46
47 def _network_definition(self): 47 def _network_definition(self):
@@ -79,9 +79,11 @@ class APIPolicyTestCase(base.BaseTestCase):
79 populating extensions and extending the resource map results in 79 populating extensions and extending the resource map results in
80 networks with router:external are visible to regular tenants. 80 networks with router:external are visible to regular tenants.
81 """ 81 """
82 policy.reset()
82 extension_manager = extensions.ExtensionManager(self.extension_path) 83 extension_manager = extensions.ExtensionManager(self.extension_path)
83 extension_manager.extend_resources(self.api_version, 84 extension_manager.extend_resources(self.api_version,
84 attributes.RESOURCE_ATTRIBUTE_MAP) 85 attributes.RESOURCE_ATTRIBUTE_MAP)
86 policy.init()
85 admin_context = context.get_admin_context() 87 admin_context = context.get_admin_context()
86 tenant_context = context.Context('test_user', 'test_tenant_id', False) 88 tenant_context = context.Context('test_user', 'test_tenant_id', False)
87 self.assertTrue(self._check_external_router_policy(admin_context)) 89 self.assertTrue(self._check_external_router_policy(admin_context))
diff --git a/neutron/tests/functional/db/test_ipam.py b/neutron/tests/functional/db/test_ipam.py
index bc3be1b..a2924b9 100644
--- a/neutron/tests/functional/db/test_ipam.py
+++ b/neutron/tests/functional/db/test_ipam.py
@@ -14,12 +14,12 @@
14# under the License. 14# under the License.
15 15
16from neutron_lib import constants 16from neutron_lib import constants
17from neutron_lib import context
17from neutron_lib import exceptions as n_exc 18from neutron_lib import exceptions as n_exc
18from oslo_config import cfg 19from oslo_config import cfg
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
20import testtools 21import testtools
21 22
22from neutron import context
23from neutron.db import db_base_plugin_v2 as base_plugin 23from neutron.db import db_base_plugin_v2 as base_plugin
24from neutron.db import models_v2 24from neutron.db import models_v2
25from neutron.tests.unit import testlib_api 25from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/functional/pecan_wsgi/test_controllers.py b/neutron/tests/functional/pecan_wsgi/test_controllers.py
index 0187a8b..797dcdb 100644
--- a/neutron/tests/functional/pecan_wsgi/test_controllers.py
+++ b/neutron/tests/functional/pecan_wsgi/test_controllers.py
@@ -14,6 +14,7 @@ import uuid
14 14
15import mock 15import mock
16from neutron_lib import constants as n_const 16from neutron_lib import constants as n_const
17from neutron_lib import context
17from neutron_lib.plugins import directory 18from neutron_lib.plugins import directory
18from oslo_config import cfg 19from oslo_config import cfg
19from oslo_db import exception as db_exc 20from oslo_db import exception as db_exc
@@ -23,7 +24,6 @@ import pecan
23from pecan import request 24from pecan import request
24 25
25from neutron.api import extensions 26from neutron.api import extensions
26from neutron import context
27from neutron import manager 27from neutron import manager
28from neutron.pecan_wsgi.controllers import root as controllers 28from neutron.pecan_wsgi.controllers import root as controllers
29from neutron.pecan_wsgi.controllers import utils as controller_utils 29from neutron.pecan_wsgi.controllers import utils as controller_utils
@@ -297,6 +297,8 @@ class TestResourceController(TestRootController):
297 297
298 def setUp(self): 298 def setUp(self):
299 super(TestResourceController, self).setUp() 299 super(TestResourceController, self).setUp()
300 policy.init()
301 self.addCleanup(policy.reset)
300 self._gen_port() 302 self._gen_port()
301 303
302 def _gen_port(self): 304 def _gen_port(self):
@@ -456,6 +458,8 @@ class TestPaginationAndSorting(test_functional.PecanFunctionalTest):
456 458
457 def setUp(self): 459 def setUp(self):
458 super(TestPaginationAndSorting, self).setUp() 460 super(TestPaginationAndSorting, self).setUp()
461 policy.init()
462 self.addCleanup(policy.reset)
459 self.plugin = directory.get_plugin() 463 self.plugin = directory.get_plugin()
460 self.ctx = context.get_admin_context() 464 self.ctx = context.get_admin_context()
461 self._create_networks(self.RESOURCE_COUNT) 465 self._create_networks(self.RESOURCE_COUNT)
@@ -702,6 +706,8 @@ class TestRouterController(TestResourceController):
702 ['neutron.services.l3_router.l3_router_plugin.L3RouterPlugin', 706 ['neutron.services.l3_router.l3_router_plugin.L3RouterPlugin',
703 'neutron.services.flavors.flavors_plugin.FlavorsPlugin']) 707 'neutron.services.flavors.flavors_plugin.FlavorsPlugin'])
704 super(TestRouterController, self).setUp() 708 super(TestRouterController, self).setUp()
709 policy.init()
710 self.addCleanup(policy.reset)
705 plugin = directory.get_plugin() 711 plugin = directory.get_plugin()
706 ctx = context.get_admin_context() 712 ctx = context.get_admin_context()
707 l3_plugin = directory.get_plugin(n_const.L3) 713 l3_plugin = directory.get_plugin(n_const.L3)
diff --git a/neutron/tests/functional/pecan_wsgi/test_functional.py b/neutron/tests/functional/pecan_wsgi/test_functional.py
index bc74ee9..38b27ab 100644
--- a/neutron/tests/functional/pecan_wsgi/test_functional.py
+++ b/neutron/tests/functional/pecan_wsgi/test_functional.py
@@ -17,6 +17,7 @@ import os
17 17
18import mock 18import mock
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20from neutron_lib import exceptions as n_exc 21from neutron_lib import exceptions as n_exc
21from oslo_config import cfg 22from oslo_config import cfg
22from oslo_middleware import base 23from oslo_middleware import base
@@ -27,7 +28,6 @@ import webob.dec
27import webtest 28import webtest
28 29
29from neutron.api import extensions as exts 30from neutron.api import extensions as exts
30from neutron import context
31from neutron import manager 31from neutron import manager
32from neutron import tests 32from neutron import tests
33from neutron.tests.unit import testlib_api 33from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/functional/pecan_wsgi/test_hooks.py b/neutron/tests/functional/pecan_wsgi/test_hooks.py
index 24def5e..b1e1b5c 100644
--- a/neutron/tests/functional/pecan_wsgi/test_hooks.py
+++ b/neutron/tests/functional/pecan_wsgi/test_hooks.py
@@ -14,6 +14,7 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from neutron_lib.db import constants as db_const 18from neutron_lib.db import constants as db_const
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_policy import policy as oslo_policy 20from oslo_policy import policy as oslo_policy
@@ -21,7 +22,6 @@ from oslo_serialization import jsonutils
21 22
22from neutron.api.v2 import attributes 23from neutron.api.v2 import attributes
23from neutron.callbacks import events 24from neutron.callbacks import events
24from neutron import context
25from neutron.db.quota import driver as quota_driver 25from neutron.db.quota import driver as quota_driver
26from neutron import manager 26from neutron import manager
27from neutron.pecan_wsgi.controllers import resource 27from neutron.pecan_wsgi.controllers import resource
diff --git a/neutron/tests/functional/plugins/ml2/test_plugin.py b/neutron/tests/functional/plugins/ml2/test_plugin.py
index 97c46a6..e14584e 100644
--- a/neutron/tests/functional/plugins/ml2/test_plugin.py
+++ b/neutron/tests/functional/plugins/ml2/test_plugin.py
@@ -14,8 +14,8 @@
14# under the License. 14# under the License.
15 15
16from neutron_lib import constants 16from neutron_lib import constants
17from neutron_lib import context
17 18
18from neutron import context
19from neutron.db import agents_db 19from neutron.db import agents_db
20from neutron.extensions import portbindings 20from neutron.extensions import portbindings
21from neutron.tests.common import helpers 21from neutron.tests.common import helpers
diff --git a/neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py
index 5cef44f..1e7d707 100644
--- a/neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py
+++ b/neutron/tests/functional/scheduler/test_dhcp_agent_scheduler.py
@@ -17,10 +17,10 @@ import collections
17from operator import attrgetter 17from operator import attrgetter
18 18
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20import six 21import six
21import testscenarios 22import testscenarios
22 23
23from neutron import context
24from neutron.db import agents_db 24from neutron.db import agents_db
25from neutron.db import agentschedulers_db 25from neutron.db import agentschedulers_db
26from neutron.db import common_db_mixin 26from neutron.db import common_db_mixin
diff --git a/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py b/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py
index f206442..76369df 100644
--- a/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py
+++ b/neutron/tests/functional/scheduler/test_l3_agent_scheduler.py
@@ -17,10 +17,10 @@ import collections
17import random 17import random
18 18
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20from oslo_utils import uuidutils 21from oslo_utils import uuidutils
21import testscenarios 22import testscenarios
22 23
23from neutron import context
24from neutron.db.models import external_net as ext_net_models 24from neutron.db.models import external_net as ext_net_models
25from neutron.scheduler import l3_agent_scheduler 25from neutron.scheduler import l3_agent_scheduler
26from neutron.services.l3_router import l3_router_plugin 26from neutron.services.l3_router import l3_router_plugin
diff --git a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py
index df4d705..a5f761f 100644
--- a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py
+++ b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py
@@ -14,13 +14,13 @@
14 14
15import mock 15import mock
16from neutron_lib import constants 16from neutron_lib import constants
17from neutron_lib import context
17 18
18from neutron.api.rpc.handlers import l3_rpc 19from neutron.api.rpc.handlers import l3_rpc
19from neutron.callbacks import events 20from neutron.callbacks import events
20from neutron.callbacks import registry 21from neutron.callbacks import registry
21from neutron.callbacks import resources 22from neutron.callbacks import resources
22from neutron.common import topics 23from neutron.common import topics
23from neutron import context
24from neutron.extensions import external_net 24from neutron.extensions import external_net
25from neutron.extensions import l3 25from neutron.extensions import l3
26from neutron.extensions import portbindings 26from neutron.extensions import portbindings
diff --git a/neutron/tests/retargetable/client_fixtures.py b/neutron/tests/retargetable/client_fixtures.py
index 86be753..f4c5a81 100644
--- a/neutron/tests/retargetable/client_fixtures.py
+++ b/neutron/tests/retargetable/client_fixtures.py
@@ -18,11 +18,11 @@ Neutron API via different methods.
18import abc 18import abc
19 19
20import fixtures 20import fixtures
21from neutron_lib import context
21from neutron_lib import exceptions as n_exc 22from neutron_lib import exceptions as n_exc
22from neutron_lib.plugins import directory 23from neutron_lib.plugins import directory
23import six 24import six
24 25
25from neutron import context
26from neutron import manager 26from neutron import manager
27from neutron.tests import base 27from neutron.tests import base
28from neutron.tests.unit import testlib_api 28from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/unit/_test_extension_portbindings.py b/neutron/tests/unit/_test_extension_portbindings.py
index f56b005..22314ae 100644
--- a/neutron/tests/unit/_test_extension_portbindings.py
+++ b/neutron/tests/unit/_test_extension_portbindings.py
@@ -13,12 +13,12 @@
13# License for the specific language governing permissions and limitations 13# License for the specific language governing permissions and limitations
14# under the License. 14# under the License.
15 15
16from neutron_lib import context
16from neutron_lib.plugins import directory 17from neutron_lib.plugins import directory
17from oslo_config import cfg 18from oslo_config import cfg
18from six.moves import http_client as httplib 19from six.moves import http_client as httplib
19from webob import exc 20from webob import exc
20 21
21from neutron import context
22from neutron.extensions import portbindings 22from neutron.extensions import portbindings
23from neutron.tests.unit.db import test_db_base_plugin_v2 23from neutron.tests.unit.db import test_db_base_plugin_v2
24 24
diff --git a/neutron/tests/unit/agent/l2/extensions/test_qos.py b/neutron/tests/unit/agent/l2/extensions/test_qos.py
index c226bf7..30bb643 100644
--- a/neutron/tests/unit/agent/l2/extensions/test_qos.py
+++ b/neutron/tests/unit/agent/l2/extensions/test_qos.py
@@ -14,6 +14,7 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from neutron_lib import exceptions 18from neutron_lib import exceptions
18from oslo_utils import uuidutils 19from oslo_utils import uuidutils
19 20
@@ -23,7 +24,6 @@ from neutron.api.rpc.callbacks.consumer import registry
23from neutron.api.rpc.callbacks import events 24from neutron.api.rpc.callbacks import events
24from neutron.api.rpc.callbacks import resources 25from neutron.api.rpc.callbacks import resources
25from neutron.api.rpc.handlers import resources_rpc 26from neutron.api.rpc.handlers import resources_rpc
26from neutron import context
27from neutron.objects.qos import policy 27from neutron.objects.qos import policy
28from neutron.objects.qos import rule 28from neutron.objects.qos import rule
29from neutron.plugins.ml2.drivers.openvswitch.agent import ( 29from neutron.plugins.ml2.drivers.openvswitch.agent import (
diff --git a/neutron/tests/unit/agent/test_securitygroups_rpc.py b/neutron/tests/unit/agent/test_securitygroups_rpc.py
index 50259e4..67b0e7d 100644
--- a/neutron/tests/unit/agent/test_securitygroups_rpc.py
+++ b/neutron/tests/unit/agent/test_securitygroups_rpc.py
@@ -18,6 +18,7 @@ import contextlib
18 18
19import mock 19import mock
20from neutron_lib import constants as const 20from neutron_lib import constants as const
21from neutron_lib import context
21from neutron_lib.plugins import directory 22from neutron_lib.plugins import directory
22from oslo_config import cfg 23from oslo_config import cfg
23import oslo_messaging 24import oslo_messaging
@@ -30,7 +31,6 @@ from neutron.agent.linux import iptables_manager
30from neutron.agent import securitygroups_rpc as sg_rpc 31from neutron.agent import securitygroups_rpc as sg_rpc
31from neutron.api.rpc.handlers import securitygroups_rpc 32from neutron.api.rpc.handlers import securitygroups_rpc
32from neutron.common import rpc as n_rpc 33from neutron.common import rpc as n_rpc
33from neutron import context
34from neutron.db import securitygroups_rpc_base as sg_db_rpc 34from neutron.db import securitygroups_rpc_base as sg_db_rpc
35from neutron.extensions import allowedaddresspairs as addr_pair 35from neutron.extensions import allowedaddresspairs as addr_pair
36from neutron.extensions import securitygroup as ext_sg 36from neutron.extensions import securitygroup as ext_sg
diff --git a/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py
index bbc54fe..f1b17d6 100644
--- a/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py
+++ b/neutron/tests/unit/api/rpc/handlers/test_l3_rpc.py
@@ -14,11 +14,11 @@
14# limitations under the License. 14# limitations under the License.
15 15
16from neutron_lib import constants 16from neutron_lib import constants
17from neutron_lib import context
17from neutron_lib.plugins import directory 18from neutron_lib.plugins import directory
18from oslo_config import cfg 19from oslo_config import cfg
19 20
20from neutron.api.rpc.handlers import l3_rpc 21from neutron.api.rpc.handlers import l3_rpc
21from neutron import context
22from neutron.tests.unit.db import test_db_base_plugin_v2 22from neutron.tests.unit.db import test_db_base_plugin_v2
23from neutron.tests.unit import testlib_api 23from neutron.tests.unit import testlib_api
24 24
diff --git a/neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py
index 843ced2..6a5aad2 100644
--- a/neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py
+++ b/neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py
@@ -14,6 +14,7 @@
14# limitations under the License. 14# limitations under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from oslo_utils import uuidutils 18from oslo_utils import uuidutils
18from oslo_versionedobjects import fields as obj_fields 19from oslo_versionedobjects import fields as obj_fields
19from oslo_versionedobjects import fixture 20from oslo_versionedobjects import fixture
@@ -23,7 +24,6 @@ from neutron.api.rpc.callbacks import resources
23from neutron.api.rpc.callbacks import version_manager 24from neutron.api.rpc.callbacks import version_manager
24from neutron.api.rpc.handlers import resources_rpc 25from neutron.api.rpc.handlers import resources_rpc
25from neutron.common import topics 26from neutron.common import topics
26from neutron import context
27from neutron.objects import base as objects_base 27from neutron.objects import base as objects_base
28from neutron.objects import common_types 28from neutron.objects import common_types
29from neutron.tests import base 29from neutron.tests import base
diff --git a/neutron/tests/unit/api/v2/test_attributes.py b/neutron/tests/unit/api/v2/test_attributes.py
index d6223af..c63efeb 100644
--- a/neutron/tests/unit/api/v2/test_attributes.py
+++ b/neutron/tests/unit/api/v2/test_attributes.py
@@ -15,12 +15,12 @@
15 15
16from neutron_lib.api import converters 16from neutron_lib.api import converters
17from neutron_lib import constants 17from neutron_lib import constants
18from neutron_lib import context
18from neutron_lib import exceptions as n_exc 19from neutron_lib import exceptions as n_exc
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
20import webob.exc 21import webob.exc
21 22
22from neutron.api.v2 import attributes 23from neutron.api.v2 import attributes
23from neutron import context
24from neutron.tests import base 24from neutron.tests import base
25 25
26 26
diff --git a/neutron/tests/unit/api/v2/test_base.py b/neutron/tests/unit/api/v2/test_base.py
index 2382066..d02622b 100644
--- a/neutron/tests/unit/api/v2/test_base.py
+++ b/neutron/tests/unit/api/v2/test_base.py
@@ -18,6 +18,7 @@ import os
18import mock 18import mock
19from neutron_lib.api import converters 19from neutron_lib.api import converters
20from neutron_lib import constants 20from neutron_lib import constants
21from neutron_lib import context
21from neutron_lib import exceptions as n_exc 22from neutron_lib import exceptions as n_exc
22from neutron_lib.plugins import directory 23from neutron_lib.plugins import directory
23from oslo_config import cfg 24from oslo_config import cfg
@@ -36,7 +37,6 @@ from neutron.api.v2 import attributes
36from neutron.api.v2 import base as v2_base 37from neutron.api.v2 import base as v2_base
37from neutron.api.v2 import router 38from neutron.api.v2 import router
38from neutron.callbacks import registry 39from neutron.callbacks import registry
39from neutron import context
40from neutron import policy 40from neutron import policy
41from neutron import quota 41from neutron import quota
42from neutron.quota import resource_registry 42from neutron.quota import resource_registry
diff --git a/neutron/tests/unit/api/v2/test_resource.py b/neutron/tests/unit/api/v2/test_resource.py
index 24d25ce..0d3c20a 100644
--- a/neutron/tests/unit/api/v2/test_resource.py
+++ b/neutron/tests/unit/api/v2/test_resource.py
@@ -14,6 +14,7 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from neutron_lib import exceptions as n_exc 18from neutron_lib import exceptions as n_exc
18import oslo_i18n 19import oslo_i18n
19from webob import exc 20from webob import exc
@@ -22,7 +23,6 @@ import webtest
22from neutron._i18n import _ 23from neutron._i18n import _
23from neutron.api.v2 import resource as wsgi_resource 24from neutron.api.v2 import resource as wsgi_resource
24from neutron.common import utils 25from neutron.common import utils
25from neutron import context
26from neutron.tests import base 26from neutron.tests import base
27from neutron import wsgi 27from neutron import wsgi
28 28
diff --git a/neutron/tests/unit/common/test_rpc.py b/neutron/tests/unit/common/test_rpc.py
index 2a011e1..d09931a 100644
--- a/neutron/tests/unit/common/test_rpc.py
+++ b/neutron/tests/unit/common/test_rpc.py
@@ -234,46 +234,41 @@ class TestRequestContextSerializer(base.DietTestCase):
234 234
235 context.to_dict.assert_called_once_with() 235 context.to_dict.assert_called_once_with()
236 236
237 @mock.patch('neutron.policy.check_is_advsvc', return_val=False) 237 def test_deserialize_context(self):
238 @mock.patch('neutron.policy.check_is_admin', return_val=False)
239 def test_deserialize_context(self, m, n):
240 context_dict = {'foo': 'bar', 238 context_dict = {'foo': 'bar',
241 'user_id': 1, 239 'user_id': 1,
242 'tenant_id': 1} 240 'tenant_id': 1,
241 'is_admin': True}
243 242
244 c = self.ser.deserialize_context(context_dict) 243 c = self.ser.deserialize_context(context_dict)
245 244
246 self.assertEqual(1, c.user_id) 245 self.assertEqual(1, c.user_id)
247 self.assertEqual(1, c.project_id) 246 self.assertEqual(1, c.project_id)
248 247
249 @mock.patch('neutron.policy.check_is_advsvc', return_val=False) 248 def test_deserialize_context_no_user_id(self):
250 @mock.patch('neutron.policy.check_is_admin', return_val=False)
251 def test_deserialize_context_no_user_id(self, m, n):
252 context_dict = {'foo': 'bar', 249 context_dict = {'foo': 'bar',
253 'user': 1, 250 'user': 1,
254 'tenant_id': 1} 251 'tenant_id': 1,
252 'is_admin': True}
255 253
256 c = self.ser.deserialize_context(context_dict) 254 c = self.ser.deserialize_context(context_dict)
257 255
258 self.assertEqual(1, c.user_id) 256 self.assertEqual(1, c.user_id)
259 self.assertEqual(1, c.project_id) 257 self.assertEqual(1, c.project_id)
260 258
261 @mock.patch('neutron.policy.check_is_advsvc', return_val=False) 259 def test_deserialize_context_no_tenant_id(self):
262 @mock.patch('neutron.policy.check_is_admin', return_val=False)
263 def test_deserialize_context_no_tenant_id(self, m, n):
264 context_dict = {'foo': 'bar', 260 context_dict = {'foo': 'bar',
265 'user_id': 1, 261 'user_id': 1,
266 'project_id': 1} 262 'project_id': 1,
263 'is_admin': True}
267 264
268 c = self.ser.deserialize_context(context_dict) 265 c = self.ser.deserialize_context(context_dict)
269 266
270 self.assertEqual(1, c.user_id) 267 self.assertEqual(1, c.user_id)
271 self.assertEqual(1, c.project_id) 268 self.assertEqual(1, c.project_id)
272 269
273 @mock.patch('neutron.policy.check_is_advsvc', return_val=False) 270 def test_deserialize_context_no_ids(self):
274 @mock.patch('neutron.policy.check_is_admin', return_val=False) 271 context_dict = {'foo': 'bar', 'is_admin': True}
275 def test_deserialize_context_no_ids(self, m, n):
276 context_dict = {'foo': 'bar'}
277 272
278 c = self.ser.deserialize_context(context_dict) 273 c = self.ser.deserialize_context(context_dict)
279 274
diff --git a/neutron/tests/unit/core_extensions/test_qos.py b/neutron/tests/unit/core_extensions/test_qos.py
index 00ebd8b..a550e8f 100644
--- a/neutron/tests/unit/core_extensions/test_qos.py
+++ b/neutron/tests/unit/core_extensions/test_qos.py
@@ -14,9 +14,9 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17 18
18from neutron.common import exceptions as n_exc 19from neutron.common import exceptions as n_exc
19from neutron import context
20from neutron.core_extensions import base as base_core 20from neutron.core_extensions import base as base_core
21from neutron.core_extensions import qos as qos_core 21from neutron.core_extensions import qos as qos_core
22from neutron.plugins.common import constants as plugin_constants 22from neutron.plugins.common import constants as plugin_constants
diff --git a/neutron/tests/unit/db/metering/test_metering_db.py b/neutron/tests/unit/db/metering/test_metering_db.py
index 5c69e73..2d3193a 100644
--- a/neutron/tests/unit/db/metering/test_metering_db.py
+++ b/neutron/tests/unit/db/metering/test_metering_db.py
@@ -15,13 +15,13 @@
15import contextlib 15import contextlib
16 16
17from neutron_lib import constants as n_consts 17from neutron_lib import constants as n_consts
18from neutron_lib import context
18from neutron_lib.db import constants as db_const 19from neutron_lib.db import constants as db_const
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
20import webob.exc 21import webob.exc
21 22
22from neutron.api import extensions 23from neutron.api import extensions
23from neutron.common import config 24from neutron.common import config
24from neutron import context
25import neutron.extensions 25import neutron.extensions
26from neutron.extensions import metering 26from neutron.extensions import metering
27from neutron.plugins.common import constants 27from neutron.plugins.common import constants
diff --git a/neutron/tests/unit/db/quota/test_api.py b/neutron/tests/unit/db/quota/test_api.py
index 15647f9..839a946 100644
--- a/neutron/tests/unit/db/quota/test_api.py
+++ b/neutron/tests/unit/db/quota/test_api.py
@@ -15,8 +15,8 @@
15import datetime 15import datetime
16 16
17import mock 17import mock
18from neutron_lib import context
18 19
19from neutron import context
20from neutron.db.quota import api as quota_api 20from neutron.db.quota import api as quota_api
21from neutron.tests.unit import testlib_api 21from neutron.tests.unit import testlib_api
22 22
diff --git a/neutron/tests/unit/db/quota/test_driver.py b/neutron/tests/unit/db/quota/test_driver.py
index 6f4041d..6156ed3 100644
--- a/neutron/tests/unit/db/quota/test_driver.py
+++ b/neutron/tests/unit/db/quota/test_driver.py
@@ -13,10 +13,10 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16from neutron_lib import context
16from neutron_lib import exceptions as lib_exc 17from neutron_lib import exceptions as lib_exc
17 18
18from neutron.common import exceptions 19from neutron.common import exceptions
19from neutron import context
20from neutron.db import db_base_plugin_v2 as base_plugin 20from neutron.db import db_base_plugin_v2 as base_plugin
21from neutron.db.quota import driver 21from neutron.db.quota import driver
22from neutron.tests.unit import testlib_api 22from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/unit/db/test_agents_db.py b/neutron/tests/unit/db/test_agents_db.py
index a6d9d4f..19245ad 100644
--- a/neutron/tests/unit/db/test_agents_db.py
+++ b/neutron/tests/unit/db/test_agents_db.py
@@ -19,13 +19,13 @@ import datetime
19import mock 19import mock
20 20
21from neutron_lib import constants 21from neutron_lib import constants
22from neutron_lib import context
22from neutron_lib import exceptions as n_exc 23from neutron_lib import exceptions as n_exc
23from oslo_config import cfg 24from oslo_config import cfg
24from oslo_db import exception as exc 25from oslo_db import exception as exc
25from oslo_utils import timeutils 26from oslo_utils import timeutils
26import testscenarios 27import testscenarios
27 28
28from neutron import context
29from neutron.db import agents_db 29from neutron.db import agents_db
30from neutron.db import db_base_plugin_v2 as base_plugin 30from neutron.db import db_base_plugin_v2 as base_plugin
31from neutron.db.models import agent as agent_model 31from neutron.db.models import agent as agent_model
diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py
index f09ee2e..6780a11 100644
--- a/neutron/tests/unit/db/test_agentschedulers_db.py
+++ b/neutron/tests/unit/db/test_agentschedulers_db.py
@@ -17,6 +17,7 @@ import datetime
17 17
18import mock 18import mock
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20from neutron_lib.plugins import directory 21from neutron_lib.plugins import directory
21from oslo_config import cfg 22from oslo_config import cfg
22from oslo_db import exception as db_exc 23from oslo_db import exception as db_exc
@@ -30,7 +31,6 @@ from neutron.api.rpc.handlers import dhcp_rpc
30from neutron.api.rpc.handlers import l3_rpc 31from neutron.api.rpc.handlers import l3_rpc
31from neutron.api.v2 import attributes 32from neutron.api.v2 import attributes
32from neutron.common import constants as n_const 33from neutron.common import constants as n_const
33from neutron import context
34from neutron.db import agents_db 34from neutron.db import agents_db
35from neutron.db import agentschedulers_db 35from neutron.db import agentschedulers_db
36from neutron.db.models import agent as agent_model 36from neutron.db.models import agent as agent_model
@@ -706,7 +706,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase):
706 self._take_down_agent_and_run_reschedule(L3_HOSTA) # Exception 706 self._take_down_agent_and_run_reschedule(L3_HOSTA) # Exception
707 707
708 def test_router_rescheduler_catches_exceptions_on_fetching_bindings(self): 708 def test_router_rescheduler_catches_exceptions_on_fetching_bindings(self):
709 with mock.patch('neutron.context.get_admin_context') as get_ctx: 709 with mock.patch('neutron_lib.context.get_admin_context') as get_ctx:
710 mock_ctx = mock.Mock() 710 mock_ctx = mock.Mock()
711 get_ctx.return_value = mock_ctx 711 get_ctx.return_value = mock_ctx
712 mock_ctx.session.query.side_effect = db_exc.DBError() 712 mock_ctx.session.query.side_effect = db_exc.DBError()
diff --git a/neutron/tests/unit/db/test_common_db_mixin.py b/neutron/tests/unit/db/test_common_db_mixin.py
index b35fc97..fc50c0f 100644
--- a/neutron/tests/unit/db/test_common_db_mixin.py
+++ b/neutron/tests/unit/db/test_common_db_mixin.py
@@ -14,8 +14,8 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17 18
18from neutron import context
19from neutron.db import _utils as db_utils 19from neutron.db import _utils as db_utils
20from neutron.tests.unit import testlib_api 20from neutron.tests.unit import testlib_api
21 21
diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py
index 255b024..467b911 100644
--- a/neutron/tests/unit/db/test_db_base_plugin_v2.py
+++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py
@@ -22,6 +22,7 @@ import eventlet
22import mock 22import mock
23import netaddr 23import netaddr
24from neutron_lib import constants 24from neutron_lib import constants
25from neutron_lib import context
25from neutron_lib import exceptions as lib_exc 26from neutron_lib import exceptions as lib_exc
26from neutron_lib.plugins import directory 27from neutron_lib.plugins import directory
27from neutron_lib.utils import helpers 28from neutron_lib.utils import helpers
@@ -47,7 +48,6 @@ from neutron.common import exceptions as n_exc
47from neutron.common import ipv6_utils 48from neutron.common import ipv6_utils
48from neutron.common import test_lib 49from neutron.common import test_lib
49from neutron.common import utils 50from neutron.common import utils
50from neutron import context
51from neutron.db import api as db_api 51from neutron.db import api as db_api
52from neutron.db import db_base_plugin_common 52from neutron.db import db_base_plugin_common
53from neutron.db import ipam_backend_mixin 53from neutron.db import ipam_backend_mixin
diff --git a/neutron/tests/unit/db/test_dvr_mac_db.py b/neutron/tests/unit/db/test_dvr_mac_db.py
index 86a3740..4b4532f 100644
--- a/neutron/tests/unit/db/test_dvr_mac_db.py
+++ b/neutron/tests/unit/db/test_dvr_mac_db.py
@@ -15,12 +15,12 @@
15 15
16import mock 16import mock
17from neutron_lib import constants 17from neutron_lib import constants
18from neutron_lib import context
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19 20
20from neutron.callbacks import events 21from neutron.callbacks import events
21from neutron.callbacks import registry 22from neutron.callbacks import registry
22from neutron.callbacks import resources 23from neutron.callbacks import resources
23from neutron import context
24from neutron.db import api as db_api 24from neutron.db import api as db_api
25from neutron.db import dvr_mac_db 25from neutron.db import dvr_mac_db
26from neutron.db.models import dvr as dvr_models 26from neutron.db.models import dvr as dvr_models
diff --git a/neutron/tests/unit/db/test_extraroute_db.py b/neutron/tests/unit/db/test_extraroute_db.py
index 62570a6..fff5cc8 100644
--- a/neutron/tests/unit/db/test_extraroute_db.py
+++ b/neutron/tests/unit/db/test_extraroute_db.py
@@ -14,8 +14,8 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17 18
18from neutron import context
19from neutron.db import common_db_mixin 19from neutron.db import common_db_mixin
20from neutron.db import extraroute_db 20from neutron.db import extraroute_db
21from neutron.tests.unit import testlib_api 21from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/unit/db/test_l3_dvr_db.py b/neutron/tests/unit/db/test_l3_dvr_db.py
index f7e21cd..7ba7fba 100644
--- a/neutron/tests/unit/db/test_l3_dvr_db.py
+++ b/neutron/tests/unit/db/test_l3_dvr_db.py
@@ -15,6 +15,7 @@
15 15
16import mock 16import mock
17from neutron_lib import constants as const 17from neutron_lib import constants as const
18from neutron_lib import context
18from neutron_lib import exceptions 19from neutron_lib import exceptions
19from neutron_lib.plugins import directory 20from neutron_lib.plugins import directory
20from oslo_utils import uuidutils 21from oslo_utils import uuidutils
@@ -23,7 +24,6 @@ from neutron.callbacks import events
23from neutron.callbacks import registry 24from neutron.callbacks import registry
24from neutron.callbacks import resources 25from neutron.callbacks import resources
25from neutron.common import constants as n_const 26from neutron.common import constants as n_const
26from neutron import context
27from neutron.db import agents_db 27from neutron.db import agents_db
28from neutron.db import common_db_mixin 28from neutron.db import common_db_mixin
29from neutron.db import l3_agentschedulers_db 29from neutron.db import l3_agentschedulers_db
diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py
index 09266e6..94254c8 100644
--- a/neutron/tests/unit/db/test_l3_hamode_db.py
+++ b/neutron/tests/unit/db/test_l3_hamode_db.py
@@ -14,6 +14,7 @@
14 14
15import mock 15import mock
16from neutron_lib import constants 16from neutron_lib import constants
17from neutron_lib import context
17from neutron_lib import exceptions as n_exc 18from neutron_lib import exceptions as n_exc
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_config import cfg 20from oslo_config import cfg
@@ -30,7 +31,6 @@ from neutron.callbacks import exceptions as c_exc
30from neutron.callbacks import registry 31from neutron.callbacks import registry
31from neutron.callbacks import resources 32from neutron.callbacks import resources
32from neutron.common import constants as n_const 33from neutron.common import constants as n_const
33from neutron import context
34from neutron.db import agents_db 34from neutron.db import agents_db
35from neutron.db import common_db_mixin 35from neutron.db import common_db_mixin
36from neutron.db import l3_agentschedulers_db 36from neutron.db import l3_agentschedulers_db
diff --git a/neutron/tests/unit/db/test_provisioning_blocks.py b/neutron/tests/unit/db/test_provisioning_blocks.py
index c0fee00..b120243 100644
--- a/neutron/tests/unit/db/test_provisioning_blocks.py
+++ b/neutron/tests/unit/db/test_provisioning_blocks.py
@@ -13,11 +13,11 @@
13# under the License. 13# under the License.
14 14
15import mock 15import mock
16from neutron_lib import context as n_ctx
16import testtools 17import testtools
17 18
18from neutron.callbacks import registry 19from neutron.callbacks import registry
19from neutron.callbacks import resources 20from neutron.callbacks import resources
20from neutron import context as n_ctx
21from neutron.db import models_v2 21from neutron.db import models_v2
22from neutron.db import provisioning_blocks as pb 22from neutron.db import provisioning_blocks as pb
23from neutron.tests.unit import testlib_api 23from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/unit/db/test_securitygroups_db.py b/neutron/tests/unit/db/test_securitygroups_db.py
index 7d0637e..548a0ad 100644
--- a/neutron/tests/unit/db/test_securitygroups_db.py
+++ b/neutron/tests/unit/db/test_securitygroups_db.py
@@ -13,6 +13,7 @@
13 13
14import mock 14import mock
15from neutron_lib import constants 15from neutron_lib import constants
16from neutron_lib import context
16import sqlalchemy 17import sqlalchemy
17import testtools 18import testtools
18 19
@@ -20,7 +21,6 @@ from neutron.callbacks import events
20from neutron.callbacks import exceptions 21from neutron.callbacks import exceptions
21from neutron.callbacks import registry 22from neutron.callbacks import registry
22from neutron.callbacks import resources 23from neutron.callbacks import resources
23from neutron import context
24from neutron.db import common_db_mixin 24from neutron.db import common_db_mixin
25from neutron.db import securitygroups_db 25from neutron.db import securitygroups_db
26from neutron.extensions import securitygroup 26from neutron.extensions import securitygroup
diff --git a/neutron/tests/unit/db/test_sqlalchemytypes.py b/neutron/tests/unit/db/test_sqlalchemytypes.py
index f22deec..c2ef7f4 100644
--- a/neutron/tests/unit/db/test_sqlalchemytypes.py
+++ b/neutron/tests/unit/db/test_sqlalchemytypes.py
@@ -13,6 +13,7 @@
13import abc 13import abc
14import netaddr 14import netaddr
15 15
16from neutron_lib import context
16from oslo_db import exception 17from oslo_db import exception
17from oslo_db.tests.sqlalchemy import base as test_base 18from oslo_db.tests.sqlalchemy import base as test_base
18from oslo_utils import timeutils 19from oslo_utils import timeutils
@@ -20,7 +21,6 @@ from oslo_utils import uuidutils
20import six 21import six
21import sqlalchemy as sa 22import sqlalchemy as sa
22 23
23from neutron import context
24from neutron.db import sqlalchemytypes 24from neutron.db import sqlalchemytypes
25from neutron.tests import tools 25from neutron.tests import tools
26 26
diff --git a/neutron/tests/unit/db/test_standard_attr.py b/neutron/tests/unit/db/test_standard_attr.py
index 58378bb..dc71be2 100644
--- a/neutron/tests/unit/db/test_standard_attr.py
+++ b/neutron/tests/unit/db/test_standard_attr.py
@@ -14,10 +14,10 @@
14 14
15import gc 15import gc
16 16
17from neutron_lib import context
17from sqlalchemy.ext import declarative 18from sqlalchemy.ext import declarative
18import testtools 19import testtools
19 20
20from neutron import context
21from neutron.db import standard_attr 21from neutron.db import standard_attr
22from neutron.tests import base 22from neutron.tests import base
23from neutron.tests.unit import testlib_api 23from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/unit/extensions/test_address_scope.py b/neutron/tests/unit/extensions/test_address_scope.py
index dbee1ab..ceba993 100644
--- a/neutron/tests/unit/extensions/test_address_scope.py
+++ b/neutron/tests/unit/extensions/test_address_scope.py
@@ -17,13 +17,13 @@ import contextlib
17import mock 17import mock
18import netaddr 18import netaddr
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20import webob.exc 21import webob.exc
21 22
22from neutron.api.v2 import attributes as attr 23from neutron.api.v2 import attributes as attr
23from neutron.callbacks import events 24from neutron.callbacks import events
24from neutron.callbacks import registry 25from neutron.callbacks import registry
25from neutron.callbacks import resources 26from neutron.callbacks import resources
26from neutron import context
27from neutron.db import address_scope_db 27from neutron.db import address_scope_db
28from neutron.db import db_base_plugin_v2 28from neutron.db import db_base_plugin_v2
29from neutron.extensions import address_scope as ext_address_scope 29from neutron.extensions import address_scope as ext_address_scope
diff --git a/neutron/tests/unit/extensions/test_agent.py b/neutron/tests/unit/extensions/test_agent.py
index 5fc814a..32cb984 100644
--- a/neutron/tests/unit/extensions/test_agent.py
+++ b/neutron/tests/unit/extensions/test_agent.py
@@ -18,12 +18,12 @@ from datetime import datetime
18import time 18import time
19 19
20from neutron_lib import constants 20from neutron_lib import constants
21from neutron_lib import context
21from oslo_config import cfg 22from oslo_config import cfg
22from oslo_utils import uuidutils 23from oslo_utils import uuidutils
23from webob import exc 24from webob import exc
24 25
25from neutron.api.v2 import attributes 26from neutron.api.v2 import attributes
26from neutron import context
27from neutron.db import agents_db 27from neutron.db import agents_db
28from neutron.db import db_base_plugin_v2 28from neutron.db import db_base_plugin_v2
29from neutron.extensions import agent 29from neutron.extensions import agent
diff --git a/neutron/tests/unit/extensions/test_availability_zone.py b/neutron/tests/unit/extensions/test_availability_zone.py
index 918bf43..a78fef6 100644
--- a/neutron/tests/unit/extensions/test_availability_zone.py
+++ b/neutron/tests/unit/extensions/test_availability_zone.py
@@ -11,7 +11,8 @@
11# License for the specific language governing permissions and limitations 11# License for the specific language governing permissions and limitations
12# under the License. 12# under the License.
13 13
14from neutron import context 14from neutron_lib import context
15
15from neutron.db import agents_db 16from neutron.db import agents_db
16from neutron.db import db_base_plugin_v2 17from neutron.db import db_base_plugin_v2
17from neutron.extensions import agent 18from neutron.extensions import agent
diff --git a/neutron/tests/unit/extensions/test_dns.py b/neutron/tests/unit/extensions/test_dns.py
index 084a40b..53cddeb 100644
--- a/neutron/tests/unit/extensions/test_dns.py
+++ b/neutron/tests/unit/extensions/test_dns.py
@@ -16,11 +16,11 @@ import math
16 16
17import netaddr 17import netaddr
18from neutron_lib import constants 18from neutron_lib import constants
19from neutron_lib import context
19from neutron_lib.plugins import directory 20from neutron_lib.plugins import directory
20from oslo_config import cfg 21from oslo_config import cfg
21 22
22from neutron.common import utils 23from neutron.common import utils
23from neutron import context
24from neutron.db import db_base_plugin_v2 24from neutron.db import db_base_plugin_v2
25from neutron.extensions import dns 25from neutron.extensions import dns
26from neutron.plugins.ml2 import config 26from neutron.plugins.ml2 import config
diff --git a/neutron/tests/unit/extensions/test_external_net.py b/neutron/tests/unit/extensions/test_external_net.py
index 43c8055..148f6ed 100644
--- a/neutron/tests/unit/extensions/test_external_net.py
+++ b/neutron/tests/unit/extensions/test_external_net.py
@@ -15,12 +15,12 @@
15 15
16import mock 16import mock
17from neutron_lib import constants 17from neutron_lib import constants
18from neutron_lib import context
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
20import testtools 21import testtools
21from webob import exc 22from webob import exc
22 23
23from neutron import context
24from neutron.db import models_v2 24from neutron.db import models_v2
25from neutron.extensions import external_net as external_net 25from neutron.extensions import external_net as external_net
26from neutron.tests.unit.api.v2 import test_base 26from neutron.tests.unit.api.v2 import test_base
diff --git a/neutron/tests/unit/extensions/test_extraroute.py b/neutron/tests/unit/extensions/test_extraroute.py
index 448c853..33f580d 100644
--- a/neutron/tests/unit/extensions/test_extraroute.py
+++ b/neutron/tests/unit/extensions/test_extraroute.py
@@ -14,12 +14,12 @@
14# under the License. 14# under the License.
15 15
16from neutron_lib import constants 16from neutron_lib import constants
17from neutron_lib import context
17from neutron_lib.utils import helpers 18from neutron_lib.utils import helpers
18from oslo_config import cfg 19from oslo_config import cfg
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
20from webob import exc 21from webob import exc
21 22
22from neutron import context
23from neutron.db import extraroute_db 23from neutron.db import extraroute_db
24from neutron.extensions import extraroute 24from neutron.extensions import extraroute
25from neutron.extensions import l3 25from neutron.extensions import l3
diff --git a/neutron/tests/unit/extensions/test_flavors.py b/neutron/tests/unit/extensions/test_flavors.py
index 163e725..5498ccb 100644
--- a/neutron/tests/unit/extensions/test_flavors.py
+++ b/neutron/tests/unit/extensions/test_flavors.py
@@ -17,12 +17,12 @@ import copy
17import fixtures 17import fixtures
18import mock 18import mock
19 19
20from neutron_lib import context
20from neutron_lib.db import constants as db_const 21from neutron_lib.db import constants as db_const
21from oslo_config import cfg 22from oslo_config import cfg
22from oslo_utils import uuidutils 23from oslo_utils import uuidutils
23from webob import exc 24from webob import exc
24 25
25from neutron import context
26from neutron.db import api as dbapi 26from neutron.db import api as dbapi
27from neutron.db.models import l3 as l3_models 27from neutron.db.models import l3 as l3_models
28from neutron.db import servicetype_db 28from neutron.db import servicetype_db
diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py
index e16fe4a..be328c0 100644
--- a/neutron/tests/unit/extensions/test_l3.py
+++ b/neutron/tests/unit/extensions/test_l3.py
@@ -20,6 +20,7 @@ import copy
20import mock 20import mock
21import netaddr 21import netaddr
22from neutron_lib import constants as lib_constants 22from neutron_lib import constants as lib_constants
23from neutron_lib import context
23from neutron_lib import exceptions as n_exc 24from neutron_lib import exceptions as n_exc
24from neutron_lib.plugins import directory 25from neutron_lib.plugins import directory
25from oslo_config import cfg 26from oslo_config import cfg
@@ -36,7 +37,6 @@ from neutron.callbacks import events
36from neutron.callbacks import exceptions 37from neutron.callbacks import exceptions
37from neutron.callbacks import registry 38from neutron.callbacks import registry
38from neutron.callbacks import resources 39from neutron.callbacks import resources
39from neutron import context
40from neutron.db import common_db_mixin 40from neutron.db import common_db_mixin
41from neutron.db import db_base_plugin_v2 41from neutron.db import db_base_plugin_v2
42from neutron.db import dns_db 42from neutron.db import dns_db
diff --git a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
index 303db1f..f1ea8d5 100644
--- a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
+++ b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
@@ -17,6 +17,7 @@
17import mock 17import mock
18import netaddr 18import netaddr
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context as nctx
20from neutron_lib.plugins import directory 21from neutron_lib.plugins import directory
21from oslo_config import cfg 22from oslo_config import cfg
22from oslo_db import exception as db_exc 23from oslo_db import exception as db_exc
@@ -26,7 +27,6 @@ import testscenarios
26from webob import exc 27from webob import exc
27 28
28from neutron.common import utils 29from neutron.common import utils
29from neutron import context as nctx
30from neutron.db import api as db_api 30from neutron.db import api as db_api
31from neutron.db import l3_db 31from neutron.db import l3_db
32from neutron.db import l3_gwmode_db 32from neutron.db import l3_gwmode_db
@@ -121,7 +121,7 @@ class TestL3GwModeMixin(testlib_api.SqlTestCase):
121 self.setup_coreplugin(plugin) 121 self.setup_coreplugin(plugin)
122 self.target_object = TestDbIntPlugin() 122 self.target_object = TestDbIntPlugin()
123 # Patch the context 123 # Patch the context
124 ctx_patcher = mock.patch('neutron.context', autospec=True) 124 ctx_patcher = mock.patch('neutron_lib.context', autospec=True)
125 mock_context = ctx_patcher.start() 125 mock_context = ctx_patcher.start()
126 self.context = mock_context.get_admin_context() 126 self.context = mock_context.get_admin_context()
127 # This ensure also calls to elevated work in unit tests 127 # This ensure also calls to elevated work in unit tests
diff --git a/neutron/tests/unit/extensions/test_portsecurity.py b/neutron/tests/unit/extensions/test_portsecurity.py
index 9ccb3a2..7b4080b 100644
--- a/neutron/tests/unit/extensions/test_portsecurity.py
+++ b/neutron/tests/unit/extensions/test_portsecurity.py
@@ -14,10 +14,10 @@
14# limitations under the License. 14# limitations under the License.
15 15
16from neutron_lib.api import validators 16from neutron_lib.api import validators
17from neutron_lib import context
17from neutron_lib.plugins import directory 18from neutron_lib.plugins import directory
18from webob import exc 19from webob import exc
19 20
20from neutron import context
21from neutron.db import _utils as db_utils 21from neutron.db import _utils as db_utils
22from neutron.db import db_base_plugin_v2 22from neutron.db import db_base_plugin_v2
23from neutron.db import portsecurity_db 23from neutron.db import portsecurity_db
diff --git a/neutron/tests/unit/extensions/test_providernet.py b/neutron/tests/unit/extensions/test_providernet.py
index c94da7b..1018990 100644
--- a/neutron/tests/unit/extensions/test_providernet.py
+++ b/neutron/tests/unit/extensions/test_providernet.py
@@ -15,6 +15,7 @@
15 15
16import mock 16import mock
17from neutron_lib import constants 17from neutron_lib import constants
18from neutron_lib import context
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_config import cfg 20from oslo_config import cfg
20from oslo_utils import uuidutils 21from oslo_utils import uuidutils
@@ -23,7 +24,6 @@ import webtest
23 24
24from neutron.api import extensions 25from neutron.api import extensions
25from neutron.api.v2 import router 26from neutron.api.v2 import router
26from neutron import context
27from neutron.extensions import providernet as pnet 27from neutron.extensions import providernet as pnet
28from neutron import quota 28from neutron import quota
29from neutron.tests import tools 29from neutron.tests import tools
diff --git a/neutron/tests/unit/extensions/test_quotasv2.py b/neutron/tests/unit/extensions/test_quotasv2.py
index ec8db31..19e7827 100644
--- a/neutron/tests/unit/extensions/test_quotasv2.py
+++ b/neutron/tests/unit/extensions/test_quotasv2.py
@@ -16,6 +16,7 @@
16import sys 16import sys
17 17
18import mock 18import mock
19from neutron_lib import context
19from oslo_config import cfg 20from oslo_config import cfg
20import testtools 21import testtools
21from webob import exc 22from webob import exc
@@ -26,7 +27,6 @@ from neutron.api.v2 import router
26from neutron.common import config 27from neutron.common import config
27from neutron.common import constants 28from neutron.common import constants
28from neutron.common import exceptions 29from neutron.common import exceptions
29from neutron import context
30from neutron.db.quota import driver 30from neutron.db.quota import driver
31from neutron import quota 31from neutron import quota
32from neutron.quota import resource_registry 32from neutron.quota import resource_registry
diff --git a/neutron/tests/unit/extensions/test_securitygroup.py b/neutron/tests/unit/extensions/test_securitygroup.py
index ed1c255..17edb8d 100644
--- a/neutron/tests/unit/extensions/test_securitygroup.py
+++ b/neutron/tests/unit/extensions/test_securitygroup.py
@@ -18,6 +18,7 @@ import contextlib
18import mock 18import mock
19from neutron_lib.api import validators 19from neutron_lib.api import validators
20from neutron_lib import constants as const 20from neutron_lib import constants as const
21from neutron_lib import context
21from neutron_lib.plugins import directory 22from neutron_lib.plugins import directory
22from oslo_config import cfg 23from oslo_config import cfg
23import oslo_db.exception as exc 24import oslo_db.exception as exc
@@ -27,7 +28,6 @@ import webob.exc
27 28
28from neutron.api.v2 import attributes as attr 29from neutron.api.v2 import attributes as attr
29from neutron.common import exceptions as n_exc 30from neutron.common import exceptions as n_exc
30from neutron import context
31from neutron.db import db_base_plugin_v2 31from neutron.db import db_base_plugin_v2
32from neutron.db import securitygroups_db 32from neutron.db import securitygroups_db
33from neutron.extensions import securitygroup as ext_sg 33from neutron.extensions import securitygroup as ext_sg
diff --git a/neutron/tests/unit/extensions/test_segment.py b/neutron/tests/unit/extensions/test_segment.py
index be04b90..ee28792 100644
--- a/neutron/tests/unit/extensions/test_segment.py
+++ b/neutron/tests/unit/extensions/test_segment.py
@@ -18,6 +18,7 @@ from keystoneauth1 import exceptions as ks_exc
18import mock 18import mock
19import netaddr 19import netaddr
20from neutron_lib import constants 20from neutron_lib import constants
21from neutron_lib import context
21from neutron_lib import exceptions as n_exc 22from neutron_lib import exceptions as n_exc
22from neutron_lib.plugins import directory 23from neutron_lib.plugins import directory
23from novaclient import exceptions as nova_exc 24from novaclient import exceptions as nova_exc
@@ -32,7 +33,6 @@ from neutron.callbacks import registry
32from neutron.callbacks import resources 33from neutron.callbacks import resources
33from neutron.common import exceptions as neutron_exc 34from neutron.common import exceptions as neutron_exc
34from neutron.conf.plugins.ml2.drivers import driver_type 35from neutron.conf.plugins.ml2.drivers import driver_type
35from neutron import context
36from neutron.db import agents_db 36from neutron.db import agents_db
37from neutron.db import agentschedulers_db 37from neutron.db import agentschedulers_db
38from neutron.db import db_base_plugin_v2 38from neutron.db import db_base_plugin_v2
diff --git a/neutron/tests/unit/extensions/test_servicetype.py b/neutron/tests/unit/extensions/test_servicetype.py
index 4352706..a5b3100 100644
--- a/neutron/tests/unit/extensions/test_servicetype.py
+++ b/neutron/tests/unit/extensions/test_servicetype.py
@@ -14,6 +14,7 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from neutron_lib import exceptions as n_exc 18from neutron_lib import exceptions as n_exc
18from oslo_config import cfg 19from oslo_config import cfg
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
@@ -21,7 +22,6 @@ import webob.exc as webexc
21import webtest 22import webtest
22 23
23from neutron.api import extensions 24from neutron.api import extensions
24from neutron import context
25from neutron.db.models import servicetype as st_model 25from neutron.db.models import servicetype as st_model
26from neutron.db import servicetype_db as st_db 26from neutron.db import servicetype_db as st_db
27from neutron.extensions import servicetype 27from neutron.extensions import servicetype
diff --git a/neutron/tests/unit/extensions/test_timestamp.py b/neutron/tests/unit/extensions/test_timestamp.py
index 9989034..6aed29d 100644
--- a/neutron/tests/unit/extensions/test_timestamp.py
+++ b/neutron/tests/unit/extensions/test_timestamp.py
@@ -16,10 +16,10 @@ import datetime
16import six 16import six
17 17
18import mock 18import mock
19from neutron_lib import context
19from neutron_lib.plugins import directory 20from neutron_lib.plugins import directory
20from oslo_utils import timeutils 21from oslo_utils import timeutils
21 22
22from neutron import context
23from neutron.db import db_base_plugin_v2 23from neutron.db import db_base_plugin_v2
24from neutron.db.models import tag as tag_model 24from neutron.db.models import tag as tag_model
25from neutron.db import models_v2 25from neutron.db import models_v2
diff --git a/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_db_api.py b/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_db_api.py
index 329f601..9f5f284 100644
--- a/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_db_api.py
+++ b/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_db_api.py
@@ -13,9 +13,9 @@
13# License for the specific language governing permissions and limitations 13# License for the specific language governing permissions and limitations
14# under the License. 14# under the License.
15 15
16from neutron_lib import context
16from oslo_utils import uuidutils 17from oslo_utils import uuidutils
17 18
18from neutron import context
19from neutron.ipam.drivers.neutrondb_ipam import db_api 19from neutron.ipam.drivers.neutrondb_ipam import db_api
20from neutron.objects import ipam as ipam_obj 20from neutron.objects import ipam as ipam_obj
21from neutron.tests.unit import testlib_api 21from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py b/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py
index a0a882d..a607c9e 100644
--- a/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py
+++ b/neutron/tests/unit/ipam/drivers/neutrondb_ipam/test_driver.py
@@ -16,12 +16,12 @@
16import mock 16import mock
17import netaddr 17import netaddr
18from neutron_lib import constants 18from neutron_lib import constants
19from neutron_lib import context
19from neutron_lib import exceptions as n_exc 20from neutron_lib import exceptions as n_exc
20from neutron_lib.plugins import directory 21from neutron_lib.plugins import directory
21from oslo_utils import uuidutils 22from oslo_utils import uuidutils
22 23
23from neutron.common import constants as n_const 24from neutron.common import constants as n_const
24from neutron import context
25from neutron.ipam.drivers.neutrondb_ipam import driver 25from neutron.ipam.drivers.neutrondb_ipam import driver
26from neutron.ipam import exceptions as ipam_exc 26from neutron.ipam import exceptions as ipam_exc
27from neutron.ipam import requests as ipam_req 27from neutron.ipam import requests as ipam_req
diff --git a/neutron/tests/unit/ipam/test_requests.py b/neutron/tests/unit/ipam/test_requests.py
index 59a45a2..e283bb8 100644
--- a/neutron/tests/unit/ipam/test_requests.py
+++ b/neutron/tests/unit/ipam/test_requests.py
@@ -13,11 +13,11 @@
13import mock 13import mock
14import netaddr 14import netaddr
15from neutron_lib import constants 15from neutron_lib import constants
16from neutron_lib import context
16from oslo_config import cfg 17from oslo_config import cfg
17from oslo_utils import netutils 18from oslo_utils import netutils
18from oslo_utils import uuidutils 19from oslo_utils import uuidutils
19 20
20from neutron import context
21from neutron.ipam import driver 21from neutron.ipam import driver
22from neutron.ipam import exceptions as ipam_exc 22from neutron.ipam import exceptions as ipam_exc
23from neutron.ipam import requests as ipam_req 23from neutron.ipam import requests as ipam_req
diff --git a/neutron/tests/unit/ipam/test_subnet_alloc.py b/neutron/tests/unit/ipam/test_subnet_alloc.py
index 4a666bd..eaf5122 100644
--- a/neutron/tests/unit/ipam/test_subnet_alloc.py
+++ b/neutron/tests/unit/ipam/test_subnet_alloc.py
@@ -16,13 +16,13 @@
16import mock 16import mock
17import netaddr 17import netaddr
18from neutron_lib import constants 18from neutron_lib import constants
19from neutron_lib import context
19from neutron_lib.plugins import directory 20from neutron_lib.plugins import directory
20from oslo_config import cfg 21from oslo_config import cfg
21from oslo_db import exception as db_exc 22from oslo_db import exception as db_exc
22from oslo_utils import uuidutils 23from oslo_utils import uuidutils
23 24
24from neutron.common import exceptions as n_exc 25from neutron.common import exceptions as n_exc
25from neutron import context
26from neutron.ipam import requests as ipam_req 26from neutron.ipam import requests as ipam_req
27from neutron.ipam import subnet_alloc 27from neutron.ipam import subnet_alloc
28from neutron.tests.unit.db import test_db_base_plugin_v2 28from neutron.tests.unit.db import test_db_base_plugin_v2
diff --git a/neutron/tests/unit/objects/db/test_api.py b/neutron/tests/unit/objects/db/test_api.py
index dd03265..4471992 100644
--- a/neutron/tests/unit/objects/db/test_api.py
+++ b/neutron/tests/unit/objects/db/test_api.py
@@ -11,10 +11,10 @@
11# under the License. 11# under the License.
12 12
13import mock 13import mock
14from neutron_lib import context
14from neutron_lib import exceptions as n_exc 15from neutron_lib import exceptions as n_exc
15from neutron_lib.plugins import directory 16from neutron_lib.plugins import directory
16 17
17from neutron import context
18from neutron.db import models_v2 18from neutron.db import models_v2
19from neutron.objects import base 19from neutron.objects import base
20from neutron.objects.db import api 20from neutron.objects.db import api
diff --git a/neutron/tests/unit/objects/port/extensions/test_allowedaddresspairs.py b/neutron/tests/unit/objects/port/extensions/test_allowedaddresspairs.py
index d62f6f4..6323db1 100644
--- a/neutron/tests/unit/objects/port/extensions/test_allowedaddresspairs.py
+++ b/neutron/tests/unit/objects/port/extensions/test_allowedaddresspairs.py
@@ -10,7 +10,8 @@
10# License for the specific language governing permissions and limitations 10# License for the specific language governing permissions and limitations
11# under the License. 11# under the License.
12 12
13from neutron import context 13from neutron_lib import context
14
14from neutron.objects.port.extensions import allowedaddresspairs 15from neutron.objects.port.extensions import allowedaddresspairs
15from neutron.tests.unit.objects import test_base as obj_test_base 16from neutron.tests.unit.objects import test_base as obj_test_base
16from neutron.tests.unit import testlib_api 17from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/unit/objects/test_base.py b/neutron/tests/unit/objects/test_base.py
index 3c30a1d..f26f0fa 100644
--- a/neutron/tests/unit/objects/test_base.py
+++ b/neutron/tests/unit/objects/test_base.py
@@ -18,6 +18,7 @@ import random
18 18
19import mock 19import mock
20import netaddr 20import netaddr
21from neutron_lib import context
21from neutron_lib import exceptions as n_exc 22from neutron_lib import exceptions as n_exc
22from neutron_lib.utils import helpers 23from neutron_lib.utils import helpers
23from oslo_db import exception as obj_exc 24from oslo_db import exception as obj_exc
@@ -30,7 +31,6 @@ import testtools
30 31
31from neutron.common import constants 32from neutron.common import constants
32from neutron.common import utils 33from neutron.common import utils
33from neutron import context
34from neutron.db import db_base_plugin_v2 34from neutron.db import db_base_plugin_v2
35from neutron.db.models import external_net as ext_net_model 35from neutron.db.models import external_net as ext_net_model
36from neutron.db.models import l3 as l3_model 36from neutron.db.models import l3 as l3_model
diff --git a/neutron/tests/unit/objects/test_rbac_db.py b/neutron/tests/unit/objects/test_rbac_db.py
index ebd4bb2..920f5b0 100644
--- a/neutron/tests/unit/objects/test_rbac_db.py
+++ b/neutron/tests/unit/objects/test_rbac_db.py
@@ -12,6 +12,7 @@
12 12
13import mock 13import mock
14 14
15from neutron_lib import context as n_context
15from neutron_lib.db import model_base 16from neutron_lib.db import model_base
16from neutron_lib import exceptions as n_exc 17from neutron_lib import exceptions as n_exc
17from oslo_versionedobjects import base as obj_base 18from oslo_versionedobjects import base as obj_base
@@ -19,7 +20,6 @@ from oslo_versionedobjects import fields as obj_fields
19import sqlalchemy as sa 20import sqlalchemy as sa
20 21
21from neutron.callbacks import events 22from neutron.callbacks import events
22from neutron import context as n_context
23from neutron.db import rbac_db_models 23from neutron.db import rbac_db_models
24from neutron.extensions import rbac as ext_rbac 24from neutron.extensions import rbac as ext_rbac
25from neutron.objects import common_types 25from neutron.objects import common_types
diff --git a/neutron/tests/unit/objects/test_subnet.py b/neutron/tests/unit/objects/test_subnet.py
index d37c35f..cc119df 100644
--- a/neutron/tests/unit/objects/test_subnet.py
+++ b/neutron/tests/unit/objects/test_subnet.py
@@ -10,9 +10,9 @@
10# License for the specific language governing permissions and limitations 10# License for the specific language governing permissions and limitations
11# under the License. 11# under the License.
12 12
13from neutron_lib import context
13from oslo_utils import uuidutils 14from oslo_utils import uuidutils
14 15
15from neutron import context
16from neutron.db import rbac_db_models 16from neutron.db import rbac_db_models
17from neutron.objects import base as obj_base 17from neutron.objects import base as obj_base
18from neutron.objects.db import api as obj_db_api 18from neutron.objects.db import api as obj_db_api
diff --git a/neutron/tests/unit/plugins/ml2/drivers/base_type_tunnel.py b/neutron/tests/unit/plugins/ml2/drivers/base_type_tunnel.py
index 80a33fb..ef9aa45 100644
--- a/neutron/tests/unit/plugins/ml2/drivers/base_type_tunnel.py
+++ b/neutron/tests/unit/plugins/ml2/drivers/base_type_tunnel.py
@@ -14,12 +14,12 @@
14# limitations under the License. 14# limitations under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from neutron_lib import exceptions as exc 18from neutron_lib import exceptions as exc
18from six import moves 19from six import moves
19import testtools 20import testtools
20from testtools import matchers 21from testtools import matchers
21 22
22from neutron import context
23from neutron.plugins.common import constants as p_const 23from neutron.plugins.common import constants as p_const
24from neutron.plugins.ml2 import config 24from neutron.plugins.ml2 import config
25from neutron.plugins.ml2 import driver_api as api 25from neutron.plugins.ml2 import driver_api as api
diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py
index c2e163a..48e5f92 100644
--- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py
+++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_db.py
@@ -13,11 +13,11 @@
13# under the License. 13# under the License.
14 14
15from neutron_lib import constants 15from neutron_lib import constants
16from neutron_lib import context
16from oslo_utils import uuidutils 17from oslo_utils import uuidutils
17 18
18from neutron.common import constants as n_const 19from neutron.common import constants as n_const
19from neutron.common import utils 20from neutron.common import utils
20from neutron import context
21from neutron.db.models import l3 as l3_models 21from neutron.db.models import l3 as l3_models
22from neutron.db.models import l3_attrs 22from neutron.db.models import l3_attrs
23from neutron.db.models import l3ha as l3ha_model 23from neutron.db.models import l3ha as l3ha_model
diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py
index e52c043..ab5292f 100644
--- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py
+++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py
@@ -15,6 +15,7 @@
15 15
16import mock 16import mock
17from neutron_lib import constants 17from neutron_lib import constants
18from neutron_lib import context
18from neutron_lib import exceptions 19from neutron_lib import exceptions
19from neutron_lib.plugins import directory 20from neutron_lib.plugins import directory
20from oslo_serialization import jsonutils 21from oslo_serialization import jsonutils
@@ -23,7 +24,6 @@ import testtools
23from neutron.api.v2 import attributes 24from neutron.api.v2 import attributes
24from neutron.common import constants as n_const 25from neutron.common import constants as n_const
25from neutron.common import topics 26from neutron.common import topics
26from neutron import context
27from neutron.db import agents_db 27from neutron.db import agents_db
28from neutron.db import common_db_mixin 28from neutron.db import common_db_mixin
29from neutron.db import l3_agentschedulers_db 29from neutron.db import l3_agentschedulers_db
diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py
index 1a3d8ed..01a64c5 100644
--- a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py
+++ b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py
@@ -14,10 +14,10 @@
14# limitations under the License. 14# limitations under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from oslo_utils import uuidutils 18from oslo_utils import uuidutils
18 19
19from neutron.common import constants 20from neutron.common import constants
20from neutron import context
21from neutron.objects.qos import policy 21from neutron.objects.qos import policy
22from neutron.objects.qos import rule 22from neutron.objects.qos import rule
23from neutron.plugins.ml2.drivers.mech_sriov.agent.common import exceptions 23from neutron.plugins.ml2.drivers.mech_sriov.agent.common import exceptions
diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/extension_drivers/test_qos_driver.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/extension_drivers/test_qos_driver.py
index 9bbeca2..dd294a9 100644
--- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/extension_drivers/test_qos_driver.py
+++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/extension_drivers/test_qos_driver.py
@@ -13,9 +13,9 @@
13import copy 13import copy
14 14
15import mock 15import mock
16from neutron_lib import context
16from oslo_utils import uuidutils 17from oslo_utils import uuidutils
17 18
18from neutron import context
19from neutron.objects.qos import policy 19from neutron.objects.qos import policy
20from neutron.objects.qos import rule 20from neutron.objects.qos import rule
21from neutron.plugins.ml2.drivers.openvswitch.agent import ( 21from neutron.plugins.ml2.drivers.openvswitch.agent import (
diff --git a/neutron/tests/unit/plugins/ml2/drivers/test_helpers.py b/neutron/tests/unit/plugins/ml2/drivers/test_helpers.py
index 68485f0..8b9cddd 100644
--- a/neutron/tests/unit/plugins/ml2/drivers/test_helpers.py
+++ b/neutron/tests/unit/plugins/ml2/drivers/test_helpers.py
@@ -14,10 +14,10 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from oslo_db import exception as exc 18from oslo_db import exception as exc
18from sqlalchemy.orm import query 19from sqlalchemy.orm import query
19 20
20from neutron import context
21from neutron.plugins.ml2.drivers import type_vlan 21from neutron.plugins.ml2.drivers import type_vlan
22from neutron.tests.unit import testlib_api 22from neutron.tests.unit import testlib_api
23 23
diff --git a/neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py b/neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py
index 5d2d055..0c55cf5 100644
--- a/neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py
+++ b/neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py
@@ -13,10 +13,10 @@
13# License for the specific language governing permissions and limitations 13# License for the specific language governing permissions and limitations
14# under the License. 14# under the License.
15 15
16from neutron_lib import context
16from neutron_lib import exceptions as exc 17from neutron_lib import exceptions as exc
17 18
18from neutron.common import exceptions as n_exc 19from neutron.common import exceptions as n_exc
19from neutron import context
20from neutron.objects.plugins.ml2 import flatallocation as flat_obj 20from neutron.objects.plugins.ml2 import flatallocation as flat_obj
21from neutron.plugins.common import constants as p_const 21from neutron.plugins.common import constants as p_const
22from neutron.plugins.ml2 import config 22from neutron.plugins.ml2 import config
diff --git a/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py b/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py
index 3ab5d3a..a6a9189 100644
--- a/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py
+++ b/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py
@@ -14,10 +14,10 @@
14# under the License. 14# under the License.
15 15
16import mock 16import mock
17from neutron_lib import context
17from neutron_lib import exceptions as exc 18from neutron_lib import exceptions as exc
18from testtools import matchers 19from testtools import matchers
19 20
20from neutron import context
21from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model 21from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
22from neutron.plugins.common import constants as p_const 22from neutron.plugins.common import constants as p_const
23from neutron.plugins.common import utils as plugin_utils 23from neutron.plugins.common import utils as plugin_utils
diff --git a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py
index a47a2af..66a05dc 100644
--- a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py
+++ b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py
@@ -20,10 +20,10 @@ from keystoneauth1 import session
20import mock 20import mock
21import netaddr 21import netaddr
22from neutron_lib import constants 22from neutron_lib import constants
23from neutron_lib import context
23from neutron_lib.plugins import directory 24from neutron_lib.plugins import directory
24import testtools 25import testtools
25 26
26from neutron import context
27from neutron.extensions import dns 27from neutron.extensions import dns
28from neutron.extensions import providernet as pnet 28from neutron.extensions import providernet as pnet
29from neutron.objects import ports as port_obj 29from neutron.objects import ports as port_obj
diff --git a/neutron/tests/unit/plugins/ml2/test_db.py b/neutron/tests/unit/plugins/ml2/test_db.py
index 9ee5aa3..f5dc1d0 100644
--- a/neutron/tests/unit/plugins/ml2/test_db.py
+++ b/neutron/tests/unit/plugins/ml2/test_db.py
@@ -18,11 +18,11 @@ import warnings
18import mock 18import mock
19import netaddr 19import netaddr
20from neutron_lib import constants 20from neutron_lib import constants
21from neutron_lib import context
21from oslo_utils import uuidutils 22from oslo_utils import uuidutils
22from sqlalchemy.orm import exc 23from sqlalchemy.orm import exc
23from sqlalchemy.orm import query 24from sqlalchemy.orm import query
24 25
25from neutron import context
26from neutron.db import db_base_plugin_v2 26from neutron.db import db_base_plugin_v2
27from neutron.db.models import l3 as l3_models 27from neutron.db.models import l3 as l3_models
28from neutron.db import models_v2 28from neutron.db import models_v2
diff --git a/neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py b/neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py
index 4d7f1d3..b25353a 100644
--- a/neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py
+++ b/neutron/tests/unit/plugins/ml2/test_ext_portsecurity.py
@@ -13,9 +13,9 @@
13# License for the specific language governing permissions and limitations 13# License for the specific language governing permissions and limitations
14# under the License. 14# under the License.
15 15
16from neutron_lib import context
16from neutron_lib.plugins import directory 17from neutron_lib.plugins import directory
17 18
18from neutron import context
19from neutron.extensions import portsecurity as psec 19from neutron.extensions import portsecurity as psec
20from neutron.plugins.ml2 import config 20from neutron.plugins.ml2 import config
21from neutron.tests.unit.extensions import test_portsecurity as test_psec 21from neutron.tests.unit.extensions import test_portsecurity as test_psec
diff --git a/neutron/tests/unit/plugins/ml2/test_extension_driver_api.py b/neutron/tests/unit/plugins/ml2/test_extension_driver_api.py
index d0be38d..b81c2b2 100644
--- a/neutron/tests/unit/plugins/ml2/test_extension_driver_api.py
+++ b/neutron/tests/unit/plugins/ml2/test_extension_driver_api.py
@@ -11,10 +11,10 @@
11# under the License. 11# under the License.
12 12
13import mock 13import mock
14from neutron_lib import context
14from neutron_lib.plugins import directory 15from neutron_lib.plugins import directory
15from oslo_utils import uuidutils 16from oslo_utils import uuidutils
16 17
17from neutron import context
18from neutron.plugins.ml2 import config 18from neutron.plugins.ml2 import config
19from neutron.tests.unit.plugins.ml2.drivers import ext_test 19from neutron.tests.unit.plugins.ml2.drivers import ext_test
20from neutron.tests.unit.plugins.ml2 import test_plugin 20from neutron.tests.unit.plugins.ml2 import test_plugin
diff --git a/neutron/tests/unit/plugins/ml2/test_ovo_rpc.py b/neutron/tests/unit/plugins/ml2/test_ovo_rpc.py
index 7ca8017..55bc7ec 100644
--- a/neutron/tests/unit/plugins/ml2/test_ovo_rpc.py
+++ b/neutron/tests/unit/plugins/ml2/test_ovo_rpc.py
@@ -12,9 +12,9 @@
12# under the License. 12# under the License.
13 13
14import mock 14import mock
15from neutron_lib import context
15from neutron_lib.plugins import directory 16from neutron_lib.plugins import directory
16 17
17from neutron import context
18from neutron.objects import network 18from neutron.objects import network
19from neutron.objects import securitygroup 19from neutron.objects import securitygroup
20from neutron.objects import subnet 20from neutron.objects import subnet
diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py
index 50d4d62..5765f0d 100644
--- a/neutron/tests/unit/plugins/ml2/test_plugin.py
+++ b/neutron/tests/unit/plugins/ml2/test_plugin.py
@@ -22,6 +22,7 @@ import testtools
22import webob 22import webob
23 23
24from neutron_lib import constants 24from neutron_lib import constants
25from neutron_lib import context
25from neutron_lib import exceptions as exc 26from neutron_lib import exceptions as exc
26from neutron_lib.plugins import directory 27from neutron_lib.plugins import directory
27from oslo_db import exception as db_exc 28from oslo_db import exception as db_exc
@@ -34,7 +35,6 @@ from neutron.callbacks import exceptions as c_exc
34from neutron.callbacks import registry 35from neutron.callbacks import registry
35from neutron.callbacks import resources 36from neutron.callbacks import resources
36from neutron.common import utils 37from neutron.common import utils
37from neutron import context
38from neutron.db import agents_db 38from neutron.db import agents_db
39from neutron.db import api as db_api 39from neutron.db import api as db_api
40from neutron.db.models import l3 as l3_models 40from neutron.db.models import l3 as l3_models
diff --git a/neutron/tests/unit/plugins/ml2/test_port_binding.py b/neutron/tests/unit/plugins/ml2/test_port_binding.py
index dc21aea..ede0c63 100644
--- a/neutron/tests/unit/plugins/ml2/test_port_binding.py
+++ b/neutron/tests/unit/plugins/ml2/test_port_binding.py
@@ -15,10 +15,10 @@
15 15
16import mock 16import mock
17from neutron_lib import constants as const 17from neutron_lib import constants as const
18from neutron_lib import context
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19 20
20from neutron.conf.plugins.ml2.drivers import driver_type 21from neutron.conf.plugins.ml2.drivers import driver_type
21from neutron import context
22from neutron.extensions import portbindings 22from neutron.extensions import portbindings
23from neutron.plugins.ml2 import config 23from neutron.plugins.ml2 import config
24from neutron.plugins.ml2 import driver_context 24from neutron.plugins.ml2 import driver_context
diff --git a/neutron/tests/unit/plugins/ml2/test_security_group.py b/neutron/tests/unit/plugins/ml2/test_security_group.py
index 9662bfb..aeead13 100644
--- a/neutron/tests/unit/plugins/ml2/test_security_group.py
+++ b/neutron/tests/unit/plugins/ml2/test_security_group.py
@@ -18,12 +18,12 @@ import math
18 18
19import mock 19import mock
20from neutron_lib import constants as const 20from neutron_lib import constants as const
21from neutron_lib import context
21from neutron_lib.plugins import directory 22from neutron_lib.plugins import directory
22 23
23from neutron.callbacks import events 24from neutron.callbacks import events
24from neutron.callbacks import registry 25from neutron.callbacks import registry
25from neutron.callbacks import resources 26from neutron.callbacks import resources
26from neutron import context
27from neutron.extensions import securitygroup as ext_sg 27from neutron.extensions import securitygroup as ext_sg
28from neutron.tests import tools 28from neutron.tests import tools
29from neutron.tests.unit.agent import test_securitygroups_rpc as test_sg_rpc 29from neutron.tests.unit.agent import test_securitygroups_rpc as test_sg_rpc
diff --git a/neutron/tests/unit/plugins/ml2/test_tracked_resources.py b/neutron/tests/unit/plugins/ml2/test_tracked_resources.py
index fd945da..115a74d 100644
--- a/neutron/tests/unit/plugins/ml2/test_tracked_resources.py
+++ b/neutron/tests/unit/plugins/ml2/test_tracked_resources.py
@@ -11,9 +11,9 @@
11# under the License. 11# under the License.
12 12
13import mock 13import mock
14from neutron_lib import context
14from oslo_utils import uuidutils 15from oslo_utils import uuidutils
15 16
16from neutron import context
17from neutron.db.quota import api as quota_db_api 17from neutron.db.quota import api as quota_db_api
18from neutron.tests.unit.api import test_extensions 18from neutron.tests.unit.api import test_extensions
19from neutron.tests.unit.extensions import test_l3 19from neutron.tests.unit.extensions import test_l3
diff --git a/neutron/tests/unit/quota/test_resource.py b/neutron/tests/unit/quota/test_resource.py
index 93f6da4..a7c0681 100644
--- a/neutron/tests/unit/quota/test_resource.py
+++ b/neutron/tests/unit/quota/test_resource.py
@@ -13,11 +13,11 @@
13# under the License. 13# under the License.
14 14
15import mock 15import mock
16from neutron_lib import context
16from oslo_config import cfg 17from oslo_config import cfg
17from oslo_utils import uuidutils 18from oslo_utils import uuidutils
18import testtools 19import testtools
19 20
20from neutron import context
21from neutron.db import api as db_api 21from neutron.db import api as db_api
22from neutron.db.quota import api as quota_api 22from neutron.db.quota import api as quota_api
23from neutron.quota import resource 23from neutron.quota import resource
diff --git a/neutron/tests/unit/quota/test_resource_registry.py b/neutron/tests/unit/quota/test_resource_registry.py
index 52ead4e..fb34079 100644
--- a/neutron/tests/unit/quota/test_resource_registry.py
+++ b/neutron/tests/unit/quota/test_resource_registry.py
@@ -13,10 +13,10 @@
13# under the License. 13# under the License.
14 14
15import mock 15import mock
16from neutron_lib import context
16from oslo_config import cfg 17from oslo_config import cfg
17import testtools 18import testtools
18 19
19from neutron import context
20from neutron.quota import resource 20from neutron.quota import resource
21from neutron.quota import resource_registry 21from neutron.quota import resource_registry
22from neutron.tests import base 22from neutron.tests import base
diff --git a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py
index 0eb3761..495fc1c 100644
--- a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py
+++ b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py
@@ -17,11 +17,11 @@ import random
17 17
18import mock 18import mock
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20from oslo_config import cfg 21from oslo_config import cfg
21from oslo_utils import importutils 22from oslo_utils import importutils
22import testscenarios 23import testscenarios
23 24
24from neutron import context
25from neutron.db import agentschedulers_db as sched_db 25from neutron.db import agentschedulers_db as sched_db
26from neutron.db import common_db_mixin 26from neutron.db import common_db_mixin
27from neutron.db import models_v2 27from neutron.db import models_v2
@@ -485,7 +485,7 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase,
485 self.remove_networks_from_down_agents() 485 self.remove_networks_from_down_agents()
486 486
487 def test_reschedule_network_catches_exceptions_on_fetching_bindings(self): 487 def test_reschedule_network_catches_exceptions_on_fetching_bindings(self):
488 with mock.patch('neutron.context.get_admin_context') as get_ctx: 488 with mock.patch('neutron_lib.context.get_admin_context') as get_ctx:
489 mock_ctx = mock.Mock() 489 mock_ctx = mock.Mock()
490 get_ctx.return_value = mock_ctx 490 get_ctx.return_value = mock_ctx
491 mock_ctx.session.query.side_effect = Exception() 491 mock_ctx.session.query.side_effect = Exception()
diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py
index d4403d0..e2ce55b 100644
--- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py
+++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py
@@ -19,6 +19,7 @@ import datetime
19 19
20import mock 20import mock
21from neutron_lib import constants 21from neutron_lib import constants
22from neutron_lib import context as n_context
22from neutron_lib.plugins import directory 23from neutron_lib.plugins import directory
23from oslo_config import cfg 24from oslo_config import cfg
24from oslo_utils import importutils 25from oslo_utils import importutils
@@ -28,7 +29,6 @@ from sqlalchemy import orm
28import testscenarios 29import testscenarios
29import testtools 30import testtools
30 31
31from neutron import context as n_context
32from neutron.db import db_base_plugin_v2 as db_v2 32from neutron.db import db_base_plugin_v2 as db_v2
33from neutron.db import l3_db 33from neutron.db import l3_db
34from neutron.db import l3_dvr_ha_scheduler_db 34from neutron.db import l3_dvr_ha_scheduler_db
diff --git a/neutron/tests/unit/services/auto_allocate/test_db.py b/neutron/tests/unit/services/auto_allocate/test_db.py
index d489d94..1ce207c 100644
--- a/neutron/tests/unit/services/auto_allocate/test_db.py
+++ b/neutron/tests/unit/services/auto_allocate/test_db.py
@@ -14,12 +14,12 @@
14import mock 14import mock
15import testtools 15import testtools
16 16
17from neutron_lib import context
17from neutron_lib import exceptions as n_exc 18from neutron_lib import exceptions as n_exc
18from oslo_db import exception as db_exc 19from oslo_db import exception as db_exc
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
20 21
21from neutron.common import exceptions as c_exc 22from neutron.common import exceptions as c_exc
22from neutron import context
23from neutron.services.auto_allocate import db 23from neutron.services.auto_allocate import db
24from neutron.services.auto_allocate import exceptions 24from neutron.services.auto_allocate import exceptions
25from neutron.tests.unit import testlib_api 25from neutron.tests.unit import testlib_api
diff --git a/neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py b/neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py
index 99a8878..6fcbd8f 100644
--- a/neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py
+++ b/neutron/tests/unit/services/l3_router/service_providers/test_driver_controller.py
@@ -14,12 +14,12 @@
14 14
15import mock 15import mock
16from neutron_lib import constants 16from neutron_lib import constants
17from neutron_lib import context
17from neutron_lib import exceptions as lib_exc 18from neutron_lib import exceptions as lib_exc
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
20import testtools 21import testtools
21 22
22from neutron import context
23from neutron.plugins.common import constants as p_cons 23from neutron.plugins.common import constants as p_cons
24from neutron.services.l3_router.service_providers import driver_controller 24from neutron.services.l3_router.service_providers import driver_controller
25from neutron.services import provider_configuration 25from neutron.services import provider_configuration
diff --git a/neutron/tests/unit/services/metering/test_metering_plugin.py b/neutron/tests/unit/services/metering/test_metering_plugin.py
index 5a29da9..4dba631 100644
--- a/neutron/tests/unit/services/metering/test_metering_plugin.py
+++ b/neutron/tests/unit/services/metering/test_metering_plugin.py
@@ -13,11 +13,11 @@
13# under the License. 13# under the License.
14 14
15import mock 15import mock
16from neutron_lib import context
16from neutron_lib.plugins import directory 17from neutron_lib.plugins import directory
17from oslo_utils import uuidutils 18from oslo_utils import uuidutils
18 19
19from neutron.api.v2 import attributes as attr 20from neutron.api.v2 import attributes as attr
20from neutron import context
21from neutron.db import api as db_api 21from neutron.db import api as db_api
22from neutron.db.metering import metering_rpc 22from neutron.db.metering import metering_rpc
23from neutron.db.models import agent as agent_model 23from neutron.db.models import agent as agent_model
@@ -96,7 +96,7 @@ class TestMeteringPlugin(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
96 96
97 self.tenant_id = 'a7e61382-47b8-4d40-bae3-f95981b5637b' 97 self.tenant_id = 'a7e61382-47b8-4d40-bae3-f95981b5637b'
98 self.ctx = FakeContext('', self.tenant_id, is_admin=True) 98 self.ctx = FakeContext('', self.tenant_id, is_admin=True)
99 self.context_patch = mock.patch('neutron.context.Context', 99 self.context_patch = mock.patch('neutron_lib.context.Context',
100 return_value=self.ctx) 100 return_value=self.ctx)
101 self.mock_context = self.context_patch.start() 101 self.mock_context = self.context_patch.start()
102 102
@@ -330,7 +330,7 @@ class TestMeteringPluginL3AgentScheduler(
330 330
331 self.tenant_id = 'a7e61382-47b8-4d40-bae3-f95981b5637b' 331 self.tenant_id = 'a7e61382-47b8-4d40-bae3-f95981b5637b'
332 self.ctx = FakeContext('', self.tenant_id, is_admin=True) 332 self.ctx = FakeContext('', self.tenant_id, is_admin=True)
333 self.context_patch = mock.patch('neutron.context.Context', 333 self.context_patch = mock.patch('neutron_lib.context.Context',
334 return_value=self.ctx) 334 return_value=self.ctx)
335 self.mock_context = self.context_patch.start() 335 self.mock_context = self.context_patch.start()
336 336
diff --git a/neutron/tests/unit/services/qos/notification_drivers/test_manager.py b/neutron/tests/unit/services/qos/notification_drivers/test_manager.py
index 1c8ad8c..f182606 100644
--- a/neutron/tests/unit/services/qos/notification_drivers/test_manager.py
+++ b/neutron/tests/unit/services/qos/notification_drivers/test_manager.py
@@ -11,11 +11,11 @@
11# under the License. 11# under the License.
12 12
13import mock 13import mock
14from neutron_lib import context
14from oslo_config import cfg 15from oslo_config import cfg
15from oslo_utils import uuidutils 16from oslo_utils import uuidutils
16 17
17from neutron.conf.services import qos_driver_manager as driver_mgr_config 18from neutron.conf.services import qos_driver_manager as driver_mgr_config
18from neutron import context
19from neutron.objects.qos import policy as policy_object 19from neutron.objects.qos import policy as policy_object
20from neutron.services.qos.notification_drivers import manager as driver_mgr 20from neutron.services.qos.notification_drivers import manager as driver_mgr
21from neutron.services.qos.notification_drivers import message_queue 21from neutron.services.qos.notification_drivers import message_queue
diff --git a/neutron/tests/unit/services/qos/test_qos_plugin.py b/neutron/tests/unit/services/qos/test_qos_plugin.py
index 82326b4..8377aeb 100644
--- a/neutron/tests/unit/services/qos/test_qos_plugin.py
+++ b/neutron/tests/unit/services/qos/test_qos_plugin.py
@@ -10,12 +10,12 @@
10# License for the specific language governing permissions and limitations 10# License for the specific language governing permissions and limitations
11# under the License. 11# under the License.
12import mock 12import mock
13from neutron_lib import context
13from neutron_lib.plugins import directory 14from neutron_lib.plugins import directory
14from oslo_config import cfg 15from oslo_config import cfg
15from oslo_utils import uuidutils 16from oslo_utils import uuidutils
16 17
17from neutron.common import exceptions as n_exc 18from neutron.common import exceptions as n_exc
18from neutron import context
19from neutron import manager 19from neutron import manager
20from neutron.objects import base as base_object 20from neutron.objects import base as base_object
21from neutron.objects.qos import policy as policy_object 21from neutron.objects.qos import policy as policy_object
diff --git a/neutron/tests/unit/services/revisions/test_revision_plugin.py b/neutron/tests/unit/services/revisions/test_revision_plugin.py
index 6857fd2..11d6a59 100644
--- a/neutron/tests/unit/services/revisions/test_revision_plugin.py
+++ b/neutron/tests/unit/services/revisions/test_revision_plugin.py
@@ -15,10 +15,10 @@
15 15
16import netaddr 16import netaddr
17from neutron_lib import constants 17from neutron_lib import constants
18from neutron_lib import context as nctx
18from neutron_lib.plugins import directory 19from neutron_lib.plugins import directory
19from oslo_utils import uuidutils 20from oslo_utils import uuidutils
20 21
21from neutron import context as nctx
22from neutron.db import models_v2 22from neutron.db import models_v2
23from neutron.plugins.ml2 import config 23from neutron.plugins.ml2 import config
24from neutron.tests.unit.plugins.ml2 import test_plugin 24from neutron.tests.unit.plugins.ml2 import test_plugin
diff --git a/neutron/tests/unit/test_context.py b/neutron/tests/unit/test_context.py
deleted file mode 100644
index 8fd906a..0000000
--- a/neutron/tests/unit/test_context.py
+++ /dev/null
@@ -1,169 +0,0 @@
1# Copyright 2012 VMware, Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import mock
17from oslo_context import context as oslo_context
18from testtools import matchers
19
20from neutron import context
21from neutron.tests import base
22
23
24class TestNeutronContext(base.BaseTestCase):
25
26 def setUp(self):
27 super(TestNeutronContext, self).setUp()
28 db_api = 'neutron.db.api.get_writer_session'
29 self._db_api_session_patcher = mock.patch(db_api)
30 self.db_api_session = self._db_api_session_patcher.start()
31
32 def test_neutron_context_create(self):
33 ctx = context.Context('user_id', 'tenant_id')
34 self.assertEqual('user_id', ctx.user_id)
35 self.assertEqual('tenant_id', ctx.project_id)
36 self.assertEqual('tenant_id', ctx.tenant_id)
37 request_id = ctx.request_id
38 if isinstance(request_id, bytes):
39 request_id = request_id.decode('utf-8')
40 self.assertThat(request_id, matchers.StartsWith('req-'))
41 self.assertEqual('user_id', ctx.user)
42 self.assertEqual('tenant_id', ctx.tenant)
43 self.assertIsNone(ctx.user_name)
44 self.assertIsNone(ctx.tenant_name)
45 self.assertIsNone(ctx.auth_token)
46
47 def test_neutron_context_create_with_name(self):
48 ctx = context.Context('user_id', 'tenant_id',
49 tenant_name='tenant_name', user_name='user_name')
50 # Check name is set
51 self.assertEqual('user_name', ctx.user_name)
52 self.assertEqual('tenant_name', ctx.tenant_name)
53 # Check user/tenant contains its ID even if user/tenant_name is passed
54 self.assertEqual('user_id', ctx.user)
55 self.assertEqual('tenant_id', ctx.tenant)
56
57 def test_neutron_context_create_with_request_id(self):
58 ctx = context.Context('user_id', 'tenant_id', request_id='req_id_xxx')
59 self.assertEqual('req_id_xxx', ctx.request_id)
60
61 def test_neutron_context_create_with_auth_token(self):
62 ctx = context.Context('user_id', 'tenant_id',
63 auth_token='auth_token_xxx')
64 self.assertEqual('auth_token_xxx', ctx.auth_token)
65
66 def test_neutron_context_to_dict(self):
67 ctx = context.Context('user_id', 'tenant_id')
68 ctx_dict = ctx.to_dict()
69 self.assertEqual('user_id', ctx_dict['user_id'])
70 self.assertEqual('tenant_id', ctx_dict['project_id'])
71 self.assertEqual(ctx.request_id, ctx_dict['request_id'])
72 self.assertEqual('user_id', ctx_dict['user'])
73 self.assertEqual('tenant_id', ctx_dict['tenant'])
74 self.assertIsNone(ctx_dict['user_name'])
75 self.assertIsNone(ctx_dict['tenant_name'])
76 self.assertIsNone(ctx_dict['project_name'])
77 self.assertIsNone(ctx_dict['auth_token'])
78
79 def test_neutron_context_to_dict_with_name(self):
80 ctx = context.Context('user_id', 'tenant_id',
81 tenant_name='tenant_name', user_name='user_name')
82 ctx_dict = ctx.to_dict()
83 self.assertEqual('user_name', ctx_dict['user_name'])
84 self.assertEqual('tenant_name', ctx_dict['tenant_name'])
85 self.assertEqual('tenant_name', ctx_dict['project_name'])
86
87 def test_neutron_context_to_dict_with_auth_token(self):
88 ctx = context.Context('user_id', 'tenant_id',
89 auth_token='auth_token_xxx')
90 ctx_dict = ctx.to_dict()
91 self.assertEqual('auth_token_xxx', ctx_dict['auth_token'])
92
93 def test_neutron_context_admin_to_dict(self):
94 self.db_api_session.return_value = 'fakesession'
95 ctx = context.get_admin_context()
96 ctx_dict = ctx.to_dict()
97 self.assertIsNone(ctx_dict['user_id'])
98 self.assertIsNone(ctx_dict['tenant_id'])
99 self.assertIsNone(ctx_dict['auth_token'])
100 self.assertIsNotNone(ctx.session)
101 self.assertNotIn('session', ctx_dict)
102
103 def test_neutron_context_admin_without_session_to_dict(self):
104 ctx = context.get_admin_context_without_session()
105 ctx_dict = ctx.to_dict()
106 self.assertIsNone(ctx_dict['user_id'])
107 self.assertIsNone(ctx_dict['tenant_id'])
108 self.assertIsNone(ctx_dict['auth_token'])
109 self.assertFalse(hasattr(ctx, 'session'))
110
111 def test_neutron_context_elevated_retains_request_id(self):
112 ctx = context.Context('user_id', 'tenant_id')
113 self.assertFalse(ctx.is_admin)
114 req_id_before = ctx.request_id
115
116 elevated_ctx = ctx.elevated()
117 self.assertTrue(elevated_ctx.is_admin)
118 self.assertEqual(req_id_before, elevated_ctx.request_id)
119
120 def test_neutron_context_overwrite(self):
121 ctx1 = context.Context('user_id', 'tenant_id')
122 self.assertEqual(ctx1.request_id,
123 oslo_context.get_current().request_id)
124
125 # If overwrite is not specified, request_id should be updated.
126 ctx2 = context.Context('user_id', 'tenant_id')
127 self.assertNotEqual(ctx2.request_id, ctx1.request_id)
128 self.assertEqual(ctx2.request_id,
129 oslo_context.get_current().request_id)
130
131 # If overwrite is specified, request_id should be kept.
132 ctx3 = context.Context('user_id', 'tenant_id', overwrite=False)
133 self.assertNotEqual(ctx3.request_id, ctx2.request_id)
134 self.assertEqual(ctx2.request_id,
135 oslo_context.get_current().request_id)
136
137 def test_neutron_context_get_admin_context_not_update_local_store(self):
138 ctx = context.Context('user_id', 'tenant_id')
139 req_id_before = oslo_context.get_current().request_id
140 self.assertEqual(ctx.request_id, req_id_before)
141
142 ctx_admin = context.get_admin_context()
143 self.assertEqual(req_id_before, oslo_context.get_current().request_id)
144 self.assertNotEqual(req_id_before, ctx_admin.request_id)
145
146 def test_to_policy_values(self):
147 values = {
148 'user_id': 'user_id',
149 'tenant_id': 'tenant_id',
150 'is_admin': 'is_admin',
151 'tenant_name': 'tenant_name',
152 'user_name': 'user_name',
153 'domain': 'domain',
154 'user_domain': 'user_domain',
155 'project_domain': 'project_domain',
156 'user_name': 'user_name',
157 }
158 additional_values = {
159 'user': 'user_id',
160 'tenant': 'tenant_id',
161 'project_id': 'tenant_id',
162 'project_name': 'tenant_name',
163 }
164 ctx = context.Context(**values)
165 # apply dict() to get a real dictionary, needed for newer oslo.context
166 # that returns _DeprecatedPolicyValues object instead
167 policy_values = dict(ctx.to_policy_values())
168 self.assertDictSupersetOf(values, policy_values)
169 self.assertDictSupersetOf(additional_values, policy_values)
diff --git a/neutron/tests/unit/test_policy.py b/neutron/tests/unit/test_policy.py
index d2cf370..7534c42 100644
--- a/neutron/tests/unit/test_policy.py
+++ b/neutron/tests/unit/test_policy.py
@@ -17,8 +17,10 @@
17 17
18import mock 18import mock
19from neutron_lib import constants 19from neutron_lib import constants
20from neutron_lib import context
20from neutron_lib import exceptions 21from neutron_lib import exceptions
21from neutron_lib.plugins import directory 22from neutron_lib.plugins import directory
23from oslo_config import cfg
22from oslo_db import exception as db_exc 24from oslo_db import exception as db_exc
23from oslo_policy import fixture as op_fixture 25from oslo_policy import fixture as op_fixture
24from oslo_policy import policy as oslo_policy 26from oslo_policy import policy as oslo_policy
@@ -28,7 +30,6 @@ from oslo_utils import importutils
28import neutron 30import neutron
29from neutron.api.v2 import attributes 31from neutron.api.v2 import attributes
30from neutron.common import constants as n_const 32from neutron.common import constants as n_const
31from neutron import context
32from neutron import policy 33from neutron import policy
33from neutron.tests import base 34from neutron.tests import base
34 35
@@ -199,12 +200,11 @@ FAKE_RESOURCES = {"%ss" % FAKE_RESOURCE_NAME:
199class NeutronPolicyTestCase(base.BaseTestCase): 200class NeutronPolicyTestCase(base.BaseTestCase):
200 201
201 def fakepolicyinit(self, **kwargs): 202 def fakepolicyinit(self, **kwargs):
202 enf = policy._ENFORCER 203 policy._ENFORCER = oslo_policy.Enforcer(cfg.CONF)
203 enf.set_rules(oslo_policy.Rules(self.rules)) 204 policy._ENFORCER.set_rules(oslo_policy.Rules(self.rules))
204 205
205 def setUp(self): 206 def setUp(self):
206 super(NeutronPolicyTestCase, self).setUp() 207 super(NeutronPolicyTestCase, self).setUp()
207 policy.refresh()
208 # Add Fake resources to RESOURCE_ATTRIBUTE_MAP 208 # Add Fake resources to RESOURCE_ATTRIBUTE_MAP
209 attributes.RESOURCE_ATTRIBUTE_MAP.update(FAKE_RESOURCES) 209 attributes.RESOURCE_ATTRIBUTE_MAP.update(FAKE_RESOURCES)
210 self._set_rules() 210 self._set_rules()
@@ -216,7 +216,9 @@ class NeutronPolicyTestCase(base.BaseTestCase):
216 'init', 216 'init',
217 new=self.fakepolicyinit) 217 new=self.fakepolicyinit)
218 self.patcher.start() 218 self.patcher.start()
219 policy.refresh()
219 self.addCleanup(remove_fake_resource) 220 self.addCleanup(remove_fake_resource)
221 self.addCleanup(policy.refresh)
220 self.context = context.Context('fake', 'fake', roles=['user']) 222 self.context = context.Context('fake', 'fake', roles=['user'])
221 plugin_klass = importutils.import_class( 223 plugin_klass = importutils.import_class(
222 "neutron.db.db_base_plugin_v2.NeutronDbPluginV2") 224 "neutron.db.db_base_plugin_v2.NeutronDbPluginV2")
@@ -369,37 +371,6 @@ class NeutronPolicyTestCase(base.BaseTestCase):
369 def test_nonadmin_read_on_shared_succeeds(self): 371 def test_nonadmin_read_on_shared_succeeds(self):
370 self._test_nonadmin_action_on_attr('get', 'shared', True) 372 self._test_nonadmin_action_on_attr('get', 'shared', True)
371 373
372 def test_check_is_admin_with_admin_context_succeeds(self):
373 admin_context = context.get_admin_context()
374 # explicitly set roles as this test verifies user credentials
375 # with the policy engine
376 admin_context.roles = ['admin']
377 self.assertTrue(policy.check_is_admin(admin_context))
378
379 def test_check_is_admin_with_user_context_fails(self):
380 self.assertFalse(policy.check_is_admin(self.context))
381
382 def test_check_is_admin_with_no_admin_policy_fails(self):
383 del self.rules[policy.ADMIN_CTX_POLICY]
384 admin_context = context.get_admin_context()
385 self.assertFalse(policy.check_is_admin(admin_context))
386
387 def test_check_is_advsvc_with_admin_context_fails(self):
388 admin_context = context.get_admin_context()
389 self.assertFalse(policy.check_is_advsvc(admin_context))
390
391 def test_check_is_advsvc_with_svc_context_succeeds(self):
392 svc_context = context.Context('', 'svc', roles=['advsvc'])
393 self.assertTrue(policy.check_is_advsvc(svc_context))
394
395 def test_check_is_advsvc_with_no_advsvc_policy_fails(self):
396 del self.rules[policy.ADVSVC_CTX_POLICY]
397 svc_context = context.Context('', 'svc', roles=['advsvc'])
398 self.assertFalse(policy.check_is_advsvc(svc_context))
399
400 def test_check_is_advsvc_with_user_context_fails(self):
401 self.assertFalse(policy.check_is_advsvc(self.context))
402
403 def _test_enforce_adminonly_attribute(self, action, **kwargs): 374 def _test_enforce_adminonly_attribute(self, action, **kwargs):
404 admin_context = context.get_admin_context() 375 admin_context = context.get_admin_context()
405 target = {'shared': True} 376 target = {'shared': True}
diff --git a/neutron/wsgi.py b/neutron/wsgi.py
index 9464fa5..08e43a1 100644
--- a/neutron/wsgi.py
+++ b/neutron/wsgi.py
@@ -22,7 +22,7 @@ import sys
22import time 22import time
23 23
24import eventlet.wsgi 24import eventlet.wsgi
25from neutron.conf import wsgi as wsgi_config 25from neutron_lib import context
26from neutron_lib import exceptions as exception 26from neutron_lib import exceptions as exception
27from oslo_config import cfg 27from oslo_config import cfg
28import oslo_i18n 28import oslo_i18n
@@ -41,7 +41,7 @@ import webob.exc
41from neutron._i18n import _, _LE, _LI 41from neutron._i18n import _, _LE, _LI
42from neutron.common import config 42from neutron.common import config
43from neutron.common import exceptions as n_exc 43from neutron.common import exceptions as n_exc
44from neutron import context 44from neutron.conf import wsgi as wsgi_config
45from neutron.db import api 45from neutron.db import api
46from neutron import worker as neutron_worker 46from neutron import worker as neutron_worker
47 47