Switch to oslo.context library
Change-Id: I2eba3c17eb5b3a16d84c268b9e4999c48635ac2b
This commit is contained in:
parent
a18deee3f7
commit
cc65556ed6
@ -23,13 +23,13 @@ import fnmatch
|
||||
import itertools
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo_context import context
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
from stevedore import extension
|
||||
|
||||
from ceilometer import coordination
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer.openstack.common import service as os_service
|
||||
from ceilometer import pipeline as publish_pipeline
|
||||
|
@ -24,11 +24,11 @@ import fnmatch
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
from oslo.config import cfg
|
||||
import oslo.messaging
|
||||
from oslo_context import context
|
||||
import six
|
||||
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer import messaging
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer.publisher import utils
|
||||
|
||||
|
@ -19,12 +19,12 @@
|
||||
import eventlet
|
||||
from oslo.config import cfg
|
||||
from oslo.serialization import jsonutils
|
||||
from oslo_context import context
|
||||
import requests
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from ceilometer.alarm import notifier
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common import log
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
@ -16,12 +16,12 @@
|
||||
# under the License.
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo_context import context
|
||||
import six
|
||||
|
||||
from ceilometer.alarm.storage import models
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer import messaging
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common import log
|
||||
|
||||
OPTS = [
|
||||
|
@ -41,6 +41,7 @@ from oslo.config import cfg
|
||||
from oslo.utils import netutils
|
||||
from oslo.utils import strutils
|
||||
from oslo.utils import timeutils
|
||||
from oslo_context import context
|
||||
import pecan
|
||||
from pecan import rest
|
||||
import pytz
|
||||
@ -56,7 +57,6 @@ from ceilometer.api import rbac
|
||||
from ceilometer.event.storage import models as event_models
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer import messaging
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer import sample
|
||||
from ceilometer import storage
|
||||
|
@ -30,8 +30,8 @@ import eventlet
|
||||
eventlet.monkey_patch(socket=True, select=True, thread=True)
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import timeutils
|
||||
from oslo_context import context
|
||||
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer import pipeline
|
||||
from ceilometer import sample
|
||||
from ceilometer import service
|
||||
|
@ -18,8 +18,7 @@
|
||||
from oslo.config import cfg
|
||||
import oslo.messaging
|
||||
from oslo.serialization import jsonutils
|
||||
|
||||
from ceilometer.openstack.common import context
|
||||
from oslo_context import context
|
||||
|
||||
DEFAULT_URL = "__default__"
|
||||
TRANSPORTS = {}
|
||||
|
@ -17,13 +17,13 @@
|
||||
|
||||
from oslo.config import cfg
|
||||
import oslo.messaging
|
||||
from oslo_context import context
|
||||
from stevedore import extension
|
||||
|
||||
from ceilometer import coordination
|
||||
from ceilometer.event import endpoint as event_endpoint
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer import messaging
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer.openstack.common import service as os_service
|
||||
from ceilometer import pipeline
|
||||
|
@ -15,10 +15,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_context import context as req_context
|
||||
from stevedore import extension
|
||||
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer.openstack.common import context as req_context
|
||||
from ceilometer.openstack.common import log as logging
|
||||
from ceilometer import pipeline
|
||||
from ceilometer import transformer
|
||||
|
@ -43,10 +43,10 @@ from __future__ import absolute_import
|
||||
import logging
|
||||
|
||||
from oslo.utils import timeutils
|
||||
from oslo_context import context
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer import pipeline
|
||||
from ceilometer import sample
|
||||
from ceilometer import service
|
||||
|
@ -1,122 +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 or context.is_admin:
|
||||
return False
|
||||
return context.user_id and context.project_id
|
@ -18,12 +18,12 @@
|
||||
import mock
|
||||
from oslo.config import fixture as fixture_config
|
||||
from oslo.serialization import jsonutils
|
||||
from oslo_context import context
|
||||
from oslotest import mockpatch
|
||||
import requests
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from ceilometer.alarm import service
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.tests import base as tests_base
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
self.setup_messaging(self.CONF)
|
||||
self.service = service.AlarmNotifierService()
|
||||
self.useFixture(mockpatch.Patch(
|
||||
'ceilometer.openstack.common.context.generate_request_id',
|
||||
'oslo_context.context.generate_request_id',
|
||||
self._fake_generate_request_id))
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
|
@ -2213,7 +2213,7 @@ class TestAlarms(v2.FunctionalTest,
|
||||
'user_id']).issubset(payload.keys()))
|
||||
|
||||
endpoint.info.assert_called_once_with(
|
||||
{'instance_uuid': None,
|
||||
{'resource_uuid': None,
|
||||
'domain': None,
|
||||
'project_domain': None,
|
||||
'auth_token': None,
|
||||
|
@ -18,13 +18,13 @@ import datetime
|
||||
|
||||
from keystoneclient import exceptions
|
||||
import mock
|
||||
from oslo_context import context
|
||||
from oslotest import base
|
||||
from oslotest import mockpatch
|
||||
import six
|
||||
|
||||
from ceilometer.agent import manager
|
||||
from ceilometer.energy import kwapi
|
||||
from ceilometer.openstack.common import context
|
||||
|
||||
|
||||
PROBE_DICT = {
|
||||
|
@ -17,12 +17,12 @@
|
||||
|
||||
import mock
|
||||
from oslo.config import fixture as fixture_config
|
||||
from oslo_context import context
|
||||
from oslotest import base
|
||||
from oslotest import mockpatch
|
||||
|
||||
from ceilometer.agent import manager
|
||||
from ceilometer.image import glance
|
||||
from ceilometer.openstack.common import context
|
||||
|
||||
IMAGE_LIST = [
|
||||
type('Image', (object,),
|
||||
|
@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslo_context import context
|
||||
from oslotest import base
|
||||
from oslotest import mockpatch
|
||||
|
||||
@ -23,7 +24,6 @@ from ceilometer.agent import manager
|
||||
from ceilometer.agent import plugin_base
|
||||
from ceilometer.network.services import discovery
|
||||
from ceilometer.network.services import fwaas
|
||||
from ceilometer.openstack.common import context
|
||||
|
||||
|
||||
class _BaseTestFWPollster(base.BaseTestCase):
|
||||
|
@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslo_context import context
|
||||
from oslotest import base
|
||||
from oslotest import mockpatch
|
||||
|
||||
@ -23,7 +24,6 @@ from ceilometer.agent import manager
|
||||
from ceilometer.agent import plugin_base
|
||||
from ceilometer.network.services import discovery
|
||||
from ceilometer.network.services import lbaas
|
||||
from ceilometer.openstack.common import context
|
||||
|
||||
|
||||
class _BaseTestLBPollster(base.BaseTestCase):
|
||||
|
@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslo_context import context
|
||||
from oslotest import base
|
||||
from oslotest import mockpatch
|
||||
|
||||
@ -23,7 +24,6 @@ from ceilometer.agent import manager
|
||||
from ceilometer.agent import plugin_base
|
||||
from ceilometer.network.services import discovery
|
||||
from ceilometer.network.services import vpnaas
|
||||
from ceilometer.openstack.common import context
|
||||
|
||||
|
||||
class _BaseTestVPNPollster(base.BaseTestCase):
|
||||
|
@ -20,11 +20,11 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslo_context import context
|
||||
from oslotest import base
|
||||
|
||||
from ceilometer.agent import manager
|
||||
from ceilometer.network import floatingip
|
||||
from ceilometer.openstack.common import context
|
||||
|
||||
|
||||
class TestFloatingIPPollster(base.BaseTestCase):
|
||||
|
@ -24,10 +24,10 @@ import mock
|
||||
from oslo.config import fixture as fixture_config
|
||||
import oslo.messaging
|
||||
from oslo.utils import netutils
|
||||
from oslo_context import context
|
||||
import testscenarios.testcase
|
||||
|
||||
from ceilometer import messaging
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.publisher import messaging as msg_publisher
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests import base as tests_base
|
||||
|
@ -22,13 +22,13 @@ import msgpack
|
||||
from oslo.config import fixture as fixture_config
|
||||
import oslo.messaging
|
||||
from oslo.utils import timeutils
|
||||
from oslo_context import context
|
||||
from oslotest import mockpatch
|
||||
from stevedore import extension
|
||||
|
||||
from ceilometer import collector
|
||||
from ceilometer import dispatcher
|
||||
from ceilometer import messaging
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.publisher import utils
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests import base as tests_base
|
||||
|
@ -22,13 +22,13 @@ from oslo.config import fixture as fixture_config
|
||||
import oslo.messaging
|
||||
import oslo.messaging.conffixture
|
||||
from oslo.utils import timeutils
|
||||
from oslo_context import context
|
||||
from stevedore import extension
|
||||
import yaml
|
||||
|
||||
from ceilometer.compute.notifications import instance
|
||||
from ceilometer import messaging
|
||||
from ceilometer import notification
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common import fileutils
|
||||
from ceilometer.publisher import test as test_publisher
|
||||
from ceilometer.tests import base as tests_base
|
||||
|
@ -1,7 +1,6 @@
|
||||
[DEFAULT]
|
||||
|
||||
# The list of modules to copy from oslo-incubator
|
||||
module=context
|
||||
module=log
|
||||
module=policy
|
||||
module=service
|
||||
|
@ -16,6 +16,7 @@ lockfile>=0.8
|
||||
lxml>=2.3
|
||||
msgpack-python>=0.4.0
|
||||
netaddr>=0.7.12
|
||||
oslo.context>=0.1.0 # Apache-2.0
|
||||
oslo.db>=1.1.0 # Apache-2.0
|
||||
oslo.concurrency>=0.3.0 # Apache-2.0
|
||||
oslo.config>=1.4.0 # Apache-2.0
|
||||
|
Loading…
Reference in New Issue
Block a user