diff --git a/ironic/common/context.py b/ironic/common/context.py index 26ca85d567..aaeffb3332 100644 --- a/ironic/common/context.py +++ b/ironic/common/context.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from ironic.openstack.common import context +from oslo_context import context class RequestContext(context.RequestContext): diff --git a/ironic/common/service.py b/ironic/common/service.py index 854676b3a2..a7b8d5e259 100644 --- a/ironic/common/service.py +++ b/ironic/common/service.py @@ -21,6 +21,7 @@ import socket from oslo import messaging from oslo_config import cfg +from oslo_context import context from oslo_utils import importutils from ironic.common import config @@ -28,7 +29,6 @@ from ironic.common.i18n import _LE from ironic.common.i18n import _LI from ironic.common import rpc from ironic.objects import base as objects_base -from ironic.openstack.common import context from ironic.openstack.common import log from ironic.openstack.common import service diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py index 837f46030e..b0de70bc00 100644 --- a/ironic/conductor/manager.py +++ b/ironic/conductor/manager.py @@ -52,6 +52,7 @@ from eventlet import greenpool from oslo import messaging from oslo_concurrency import lockutils from oslo_config import cfg +from oslo_context import context as ironic_context from oslo_db import exception as db_exception from oslo_utils import excutils from oslo_utils import uuidutils @@ -74,7 +75,6 @@ from ironic.conductor import task_manager from ironic.conductor import utils from ironic.db import api as dbapi from ironic import objects -from ironic.openstack.common import context as ironic_context from ironic.openstack.common import log from ironic.openstack.common import periodic_task diff --git a/ironic/objects/base.py b/ironic/objects/base.py index 06c7429631..bd3cc63d38 100644 --- a/ironic/objects/base.py +++ b/ironic/objects/base.py @@ -18,13 +18,13 @@ import collections import copy from oslo import messaging +from oslo_context import context import six from ironic.common import exception from ironic.common.i18n import _ from ironic.common.i18n import _LE from ironic.objects import utils as obj_utils -from ironic.openstack.common import context from ironic.openstack.common import log as logging from ironic.openstack.common import versionutils diff --git a/ironic/openstack/common/context.py b/ironic/openstack/common/context.py deleted file mode 100644 index b612db7140..0000000000 --- a/ironic/openstack/common/context.py +++ /dev/null @@ -1,126 +0,0 @@ -# Copyright 2011 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Simple class that stores security context information in the web request. - -Projects should subclass this class if they wish to enhance the request -context or provide additional information in their specific WSGI pipeline. -""" - -import itertools -import uuid - - -def generate_request_id(): - return b'req-' + str(uuid.uuid4()).encode('ascii') - - -class RequestContext(object): - - """Helper class to represent useful information about a request context. - - Stores information about the security context under which the user - accesses the system, as well as additional request information. - """ - - user_idt_format = '{user} {tenant} {domain} {user_domain} {p_domain}' - - def __init__(self, auth_token=None, user=None, tenant=None, domain=None, - user_domain=None, project_domain=None, is_admin=False, - read_only=False, show_deleted=False, request_id=None, - instance_uuid=None): - self.auth_token = auth_token - self.user = user - self.tenant = tenant - self.domain = domain - self.user_domain = user_domain - self.project_domain = project_domain - self.is_admin = is_admin - self.read_only = read_only - self.show_deleted = show_deleted - self.instance_uuid = instance_uuid - if not request_id: - request_id = generate_request_id() - self.request_id = request_id - - def to_dict(self): - user_idt = ( - self.user_idt_format.format(user=self.user or '-', - tenant=self.tenant or '-', - domain=self.domain or '-', - user_domain=self.user_domain or '-', - p_domain=self.project_domain or '-')) - - return {'user': self.user, - 'tenant': self.tenant, - 'domain': self.domain, - 'user_domain': self.user_domain, - 'project_domain': self.project_domain, - 'is_admin': self.is_admin, - 'read_only': self.read_only, - 'show_deleted': self.show_deleted, - 'auth_token': self.auth_token, - 'request_id': self.request_id, - 'instance_uuid': self.instance_uuid, - 'user_identity': user_idt} - - @classmethod - def from_dict(cls, ctx): - return cls( - auth_token=ctx.get("auth_token"), - user=ctx.get("user"), - tenant=ctx.get("tenant"), - domain=ctx.get("domain"), - user_domain=ctx.get("user_domain"), - project_domain=ctx.get("project_domain"), - is_admin=ctx.get("is_admin", False), - read_only=ctx.get("read_only", False), - show_deleted=ctx.get("show_deleted", False), - request_id=ctx.get("request_id"), - instance_uuid=ctx.get("instance_uuid")) - - -def get_admin_context(show_deleted=False): - context = RequestContext(None, - tenant=None, - is_admin=True, - show_deleted=show_deleted) - return context - - -def get_context_from_function_and_args(function, args, kwargs): - """Find an arg of type RequestContext and return it. - - This is useful in a couple of decorators where we don't - know much about the function we're wrapping. - """ - - for arg in itertools.chain(kwargs.values(), args): - if isinstance(arg, RequestContext): - return arg - - return None - - -def is_user_context(context): - """Indicates if the request context is a normal user.""" - if not context: - return False - if context.is_admin: - return False - if not context.user_id or not context.project_id: - return False - return True diff --git a/ironic/tests/base.py b/ironic/tests/base.py index 2caee82d77..9059ccfcb6 100644 --- a/ironic/tests/base.py +++ b/ironic/tests/base.py @@ -29,11 +29,11 @@ import eventlet eventlet.monkey_patch(os=False) import fixtures from oslo_config import cfg +from oslo_context import context as ironic_context import testtools from ironic.common import hash_ring from ironic.objects import base as objects_base -from ironic.openstack.common import context as ironic_context from ironic.openstack.common import log as logging from ironic.tests import conf_fixture from ironic.tests import policy_fixture diff --git a/ironic/tests/conductor/test_manager.py b/ironic/tests/conductor/test_manager.py index f48ee2b68c..6d9dc075cb 100644 --- a/ironic/tests/conductor/test_manager.py +++ b/ironic/tests/conductor/test_manager.py @@ -24,6 +24,7 @@ import eventlet import mock from oslo import messaging from oslo_config import cfg +from oslo_context import context from oslo_db import exception as db_exception from oslo_utils import strutils from oslo_utils import uuidutils @@ -40,7 +41,6 @@ from ironic.conductor import utils as conductor_utils from ironic.db import api as dbapi from ironic.drivers import base as drivers_base from ironic import objects -from ironic.openstack.common import context from ironic.tests import base as tests_base from ironic.tests.conductor import utils as mgr_utils from ironic.tests.db import base as tests_db_base diff --git a/ironic/tests/objects/test_objects.py b/ironic/tests/objects/test_objects.py index 3f6f44ed7e..fea636a2bd 100644 --- a/ironic/tests/objects/test_objects.py +++ b/ironic/tests/objects/test_objects.py @@ -18,13 +18,13 @@ import gettext import iso8601 import netaddr +from oslo_context import context from oslo_utils import timeutils import six from ironic.common import exception from ironic.objects import base from ironic.objects import utils -from ironic.openstack.common import context from ironic.tests import base as test_base gettext.install('ironic') diff --git a/ironic/tests/test_glance_service.py b/ironic/tests/test_glance_service.py index 0f315755b0..dfe6d90b30 100644 --- a/ironic/tests/test_glance_service.py +++ b/ironic/tests/test_glance_service.py @@ -20,6 +20,7 @@ import os import tempfile import mock +from oslo_context import context import testtools @@ -27,7 +28,6 @@ from ironic.common import exception from ironic.common.glance_service import base_image_service from ironic.common.glance_service import service_utils from ironic.common import image_service as service -from ironic.openstack.common import context from ironic.tests import base from ironic.tests import matchers from ironic.tests import stubs diff --git a/openstack-common.conf b/openstack-common.conf index 87cc25c642..3822830ed6 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -2,7 +2,6 @@ # The list of modules to copy from oslo-incubator module=config.generator -module=context module=fileutils module=gettextutils module=imageutils diff --git a/requirements.txt b/requirements.txt index 53fe356df6..6b5d116cc5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,6 +21,7 @@ pysendfile==2.0.0 websockify>=0.6.0,<0.7 oslo.concurrency>=1.4.1 # Apache-2.0 oslo.config>=1.9.0 # Apache-2.0 +oslo.context>=0.2.0 oslo.db>=1.5.0 # Apache-2.0 oslo.rootwrap>=1.5.0 oslo.i18n>=1.3.0 # Apache-2.0