Remove deprecated Swift middleware

Change-Id: Ifd1861e3df46fad0e44ff9b5cbd58711bbc87c97
This commit is contained in:
Julien Danjou 2015-05-25 07:30:12 +02:00
parent 89089c2a70
commit 191f7bf9cc
6 changed files with 0 additions and 837 deletions

View File

@ -1,235 +0,0 @@
#!/usr/bin/env python
#
# Copyright 2012 eNovance <licensing@enovance.com>
#
# 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.
"""
Ceilometer Middleware for Swift Proxy
Configuration:
In /etc/swift/proxy-server.conf on the main pipeline add "ceilometer" just
before "proxy-server" and add the following filter in the file:
.. code-block:: python
[filter:ceilometer]
use = egg:ceilometer#swift
# Some optional configuration
# this allow to publish additional metadata
metadata_headers = X-TEST
# Set reseller prefix (defaults to "AUTH_" if not set)
reseller_prefix = AUTH_
"""
from __future__ import absolute_import
import logging
from oslo_context import context
from oslo_utils import timeutils
import six
import six.moves.urllib.parse as urlparse
from ceilometer.openstack.common import versionutils
from ceilometer import pipeline
from ceilometer import sample
from ceilometer import service
class InputProxy(object):
"""File-like object that counts bytes read.
To be swapped in for wsgi.input for accounting purposes.
Borrowed from swift.common.utils. Duplidated here to avoid
dependency on swift package.
"""
def __init__(self, wsgi_input):
self.wsgi_input = wsgi_input
self.bytes_received = 0
def read(self, *args, **kwargs):
"""Pass read request to the underlying file-like object
Add bytes read to total.
"""
chunk = self.wsgi_input.read(*args, **kwargs)
self.bytes_received += len(chunk)
return chunk
def readline(self, *args, **kwargs):
"""Pass readline request to the underlying file-like object
Add bytes read to total.
"""
line = self.wsgi_input.readline(*args, **kwargs)
self.bytes_received += len(line)
return line
@versionutils.deprecated(as_of=versionutils.deprecated.KILO,
in_favor_of='ceilometermiddleware.swift:Swift')
class CeilometerMiddleware(object):
"""Ceilometer middleware used for counting requests."""
def __init__(self, app, conf):
self.app = app
self.metadata_headers = [h.strip().replace('-', '_').lower()
for h in conf.get(
"metadata_headers",
"").split(",") if h.strip()]
self.logger = logging.getLogger('ceilometer')
self.logger.setLevel(getattr(logging,
conf.get('log_level', 'WARN').upper()))
service.prepare_service([])
self.pipeline_manager = pipeline.setup_pipeline()
self.reseller_prefix = conf.get('reseller_prefix', 'AUTH_')
if self.reseller_prefix and self.reseller_prefix[-1] != '_':
self.reseller_prefix += '_'
def __call__(self, env, start_response):
start_response_args = [None]
input_proxy = InputProxy(env['wsgi.input'])
env['wsgi.input'] = input_proxy
def my_start_response(status, headers, exc_info=None):
start_response_args[0] = (status, list(headers), exc_info)
def iter_response(iterable):
iterator = iter(iterable)
try:
chunk = next(iterator)
while not chunk:
chunk = next(iterator)
except StopIteration:
chunk = ''
if start_response_args[0]:
start_response(*start_response_args[0])
bytes_sent = 0
try:
while chunk:
bytes_sent += len(chunk)
yield chunk
chunk = next(iterator)
finally:
try:
self.publish_sample(env,
input_proxy.bytes_received,
bytes_sent)
except Exception:
self.logger.exception('Failed to publish samples')
try:
iterable = self.app(env, my_start_response)
except Exception:
self.publish_sample(env, input_proxy.bytes_received, 0)
raise
else:
return iter_response(iterable)
def publish_sample(self, env, bytes_received, bytes_sent):
path = urlparse.quote(env['PATH_INFO'])
method = env['REQUEST_METHOD']
headers = {}
for header in env:
if header.startswith('HTTP_') and env[header]:
key = header[5:]
if isinstance(env[header], six.text_type):
headers[key] = env[header].encode('utf-8')
else:
headers[key] = str(env[header])
try:
container = obj = None
version, account, remainder = path.replace(
'/', '', 1).split('/', 2)
if not version or not account:
raise ValueError('Invalid path: %s' % path)
if remainder:
if '/' in remainder:
container, obj = remainder.split('/', 1)
else:
container = remainder
except ValueError:
return
now = timeutils.utcnow().isoformat()
resource_metadata = {
"path": path,
"version": version,
"container": container,
"object": obj,
}
for header in self.metadata_headers:
if header.upper() in headers:
resource_metadata['http_header_%s' % header] = headers.get(
header.upper())
with self.pipeline_manager.publisher(
context.get_admin_context()) as publisher:
if bytes_received:
publisher([sample.Sample(
name='storage.objects.incoming.bytes',
type=sample.TYPE_DELTA,
unit='B',
volume=bytes_received,
user_id=env.get('HTTP_X_USER_ID'),
project_id=env.get('HTTP_X_TENANT_ID'),
resource_id=account.partition(self.reseller_prefix)[2],
timestamp=now,
resource_metadata=resource_metadata)])
if bytes_sent:
publisher([sample.Sample(
name='storage.objects.outgoing.bytes',
type=sample.TYPE_DELTA,
unit='B',
volume=bytes_sent,
user_id=env.get('HTTP_X_USER_ID'),
project_id=env.get('HTTP_X_TENANT_ID'),
resource_id=account.partition(self.reseller_prefix)[2],
timestamp=now,
resource_metadata=resource_metadata)])
# publish the event for each request
# request method will be recorded in the metadata
resource_metadata['method'] = method.lower()
publisher([sample.Sample(
name='storage.api.request',
type=sample.TYPE_DELTA,
unit='request',
volume=1,
user_id=env.get('HTTP_X_USER_ID'),
project_id=env.get('HTTP_X_TENANT_ID'),
resource_id=account.partition(self.reseller_prefix)[2],
timestamp=now,
resource_metadata=resource_metadata)])
def filter_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
def ceilometer_filter(app):
return CeilometerMiddleware(app, conf)
return ceilometer_filter

View File

@ -1,253 +0,0 @@
# Copyright (c) 2013 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.
"""
Helpers for comparing version strings.
"""
import functools
import inspect
import logging
from oslo_config import cfg
import pkg_resources
import six
from ceilometer.openstack.common._i18n import _
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
opts = [
cfg.BoolOpt('fatal_deprecations',
default=False,
help='Enables or disables fatal status of deprecations.'),
]
class deprecated(object):
"""A decorator to mark callables as deprecated.
This decorator logs a deprecation message when the callable it decorates is
used. The message will include the release where the callable was
deprecated, the release where it may be removed and possibly an optional
replacement.
Examples:
1. Specifying the required deprecated release
>>> @deprecated(as_of=deprecated.ICEHOUSE)
... def a(): pass
2. Specifying a replacement:
>>> @deprecated(as_of=deprecated.ICEHOUSE, in_favor_of='f()')
... def b(): pass
3. Specifying the release where the functionality may be removed:
>>> @deprecated(as_of=deprecated.ICEHOUSE, remove_in=+1)
... def c(): pass
4. Specifying the deprecated functionality will not be removed:
>>> @deprecated(as_of=deprecated.ICEHOUSE, remove_in=0)
... def d(): pass
5. Specifying a replacement, deprecated functionality will not be removed:
>>> @deprecated(as_of=deprecated.ICEHOUSE, in_favor_of='f()', remove_in=0)
... def e(): pass
"""
# NOTE(morganfainberg): Bexar is used for unit test purposes, it is
# expected we maintain a gap between Bexar and Folsom in this list.
BEXAR = 'B'
FOLSOM = 'F'
GRIZZLY = 'G'
HAVANA = 'H'
ICEHOUSE = 'I'
JUNO = 'J'
KILO = 'K'
_RELEASES = {
# NOTE(morganfainberg): Bexar is used for unit test purposes, it is
# expected we maintain a gap between Bexar and Folsom in this list.
'B': 'Bexar',
'F': 'Folsom',
'G': 'Grizzly',
'H': 'Havana',
'I': 'Icehouse',
'J': 'Juno',
'K': 'Kilo',
}
_deprecated_msg_with_alternative = _(
'%(what)s is deprecated as of %(as_of)s in favor of '
'%(in_favor_of)s and may be removed in %(remove_in)s.')
_deprecated_msg_no_alternative = _(
'%(what)s is deprecated as of %(as_of)s and may be '
'removed in %(remove_in)s. It will not be superseded.')
_deprecated_msg_with_alternative_no_removal = _(
'%(what)s is deprecated as of %(as_of)s in favor of %(in_favor_of)s.')
_deprecated_msg_with_no_alternative_no_removal = _(
'%(what)s is deprecated as of %(as_of)s. It will not be superseded.')
def __init__(self, as_of, in_favor_of=None, remove_in=2, what=None):
"""Initialize decorator
:param as_of: the release deprecating the callable. Constants
are define in this class for convenience.
:param in_favor_of: the replacement for the callable (optional)
:param remove_in: an integer specifying how many releases to wait
before removing (default: 2)
:param what: name of the thing being deprecated (default: the
callable's name)
"""
self.as_of = as_of
self.in_favor_of = in_favor_of
self.remove_in = remove_in
self.what = what
def __call__(self, func_or_cls):
if not self.what:
self.what = func_or_cls.__name__ + '()'
msg, details = self._build_message()
if inspect.isfunction(func_or_cls):
@six.wraps(func_or_cls)
def wrapped(*args, **kwargs):
report_deprecated_feature(LOG, msg, details)
return func_or_cls(*args, **kwargs)
return wrapped
elif inspect.isclass(func_or_cls):
orig_init = func_or_cls.__init__
# TODO(tsufiev): change `functools` module to `six` as
# soon as six 1.7.4 (with fix for passing `assigned`
# argument to underlying `functools.wraps`) is released
# and added to the oslo-incubator requrements
@functools.wraps(orig_init, assigned=('__name__', '__doc__'))
def new_init(self, *args, **kwargs):
report_deprecated_feature(LOG, msg, details)
orig_init(self, *args, **kwargs)
func_or_cls.__init__ = new_init
return func_or_cls
else:
raise TypeError('deprecated can be used only with functions or '
'classes')
def _get_safe_to_remove_release(self, release):
# TODO(dstanek): this method will have to be reimplemented once
# when we get to the X release because once we get to the Y
# release, what is Y+2?
new_release = chr(ord(release) + self.remove_in)
if new_release in self._RELEASES:
return self._RELEASES[new_release]
else:
return new_release
def _build_message(self):
details = dict(what=self.what,
as_of=self._RELEASES[self.as_of],
remove_in=self._get_safe_to_remove_release(self.as_of))
if self.in_favor_of:
details['in_favor_of'] = self.in_favor_of
if self.remove_in > 0:
msg = self._deprecated_msg_with_alternative
else:
# There are no plans to remove this function, but it is
# now deprecated.
msg = self._deprecated_msg_with_alternative_no_removal
else:
if self.remove_in > 0:
msg = self._deprecated_msg_no_alternative
else:
# There are no plans to remove this function, but it is
# now deprecated.
msg = self._deprecated_msg_with_no_alternative_no_removal
return msg, details
def is_compatible(requested_version, current_version, same_major=True):
"""Determine whether `requested_version` is satisfied by
`current_version`; in other words, `current_version` is >=
`requested_version`.
:param requested_version: version to check for compatibility
:param current_version: version to check against
:param same_major: if True, the major version must be identical between
`requested_version` and `current_version`. This is used when a
major-version difference indicates incompatibility between the two
versions. Since this is the common-case in practice, the default is
True.
:returns: True if compatible, False if not
"""
requested_parts = pkg_resources.parse_version(requested_version)
current_parts = pkg_resources.parse_version(current_version)
if same_major and (requested_parts[0] != current_parts[0]):
return False
return current_parts >= requested_parts
# Track the messages we have sent already. See
# report_deprecated_feature().
_deprecated_messages_sent = {}
def report_deprecated_feature(logger, msg, *args, **kwargs):
"""Call this function when a deprecated feature is used.
If the system is configured for fatal deprecations then the message
is logged at the 'critical' level and :class:`DeprecatedConfig` will
be raised.
Otherwise, the message will be logged (once) at the 'warn' level.
:raises: :class:`DeprecatedConfig` if the system is configured for
fatal deprecations.
"""
stdmsg = _("Deprecated: %s") % msg
CONF.register_opts(opts)
if CONF.fatal_deprecations:
logger.critical(stdmsg, *args, **kwargs)
raise DeprecatedConfig(msg=stdmsg)
# Using a list because a tuple with dict can't be stored in a set.
sent_args = _deprecated_messages_sent.setdefault(msg, list())
if args in sent_args:
# Already logged this message, so don't log it again.
return
sent_args.append(args)
logger.warn(stdmsg, *args, **kwargs)
class DeprecatedConfig(Exception):
message = _("Fatal call to deprecated config: %(msg)s")
def __init__(self, msg):
super(Exception, self).__init__(self.message % dict(msg=msg))

View File

@ -1,343 +0,0 @@
#!/usr/bin/env python
#
# Copyright 2012 eNovance <licensing@enovance.com>
#
# 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.
import mock
from oslo_config import fixture as fixture_config
from oslotest import mockpatch
import six
from ceilometer.objectstore import swift_middleware
from ceilometer import pipeline
from ceilometer.tests import base as tests_base
class FakeApp(object):
def __init__(self, body=None):
self.body = body or ['This string is 28 bytes long']
def __call__(self, env, start_response):
yield
start_response('200 OK', [
('Content-Type', 'text/plain'),
('Content-Length', str(sum(map(len, self.body))))
])
while env['wsgi.input'].read(5):
pass
for line in self.body:
yield line
class FakeRequest(object):
"""A bare bones request object
The middleware will inspect this for request method,
wsgi.input and headers.
"""
def __init__(self, path, environ=None, headers=None):
environ = environ or {}
headers = headers or {}
environ['PATH_INFO'] = path
if 'wsgi.input' not in environ:
environ['wsgi.input'] = six.moves.cStringIO('')
for header, value in six.iteritems(headers):
environ['HTTP_%s' % header.upper()] = value
self.environ = environ
class TestSwiftMiddleware(tests_base.BaseTestCase):
class _faux_pipeline_manager(pipeline.PipelineManager):
class _faux_pipeline(object):
def __init__(self, pipeline_manager):
self.pipeline_manager = pipeline_manager
self.samples = []
def publish_data(self, ctxt, samples):
self.samples.extend(samples)
def flush(self, context):
pass
def __init__(self):
self.pipelines = [self._faux_pipeline(self)]
def _fake_setup_pipeline(self, transformer_manager=None):
return self.pipeline_manager
def setUp(self):
super(TestSwiftMiddleware, self).setUp()
self.pipeline_manager = self._faux_pipeline_manager()
self.useFixture(mockpatch.PatchObject(
pipeline, 'setup_pipeline',
side_effect=self._fake_setup_pipeline))
self.CONF = self.useFixture(fixture_config.Config()).conf
self.setup_messaging(self.CONF)
@staticmethod
def start_response(*args):
pass
def test_get(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
req = FakeRequest('/1.0/account/container/obj',
environ={'REQUEST_METHOD': 'GET'})
resp = app(req.environ, self.start_response)
self.assertEqual(["This string is 28 bytes long"], list(resp))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(2, len(samples))
data = samples[0]
self.assertEqual(28, data.volume)
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertEqual('obj', data.resource_metadata['object'])
# test the # of request and the request method
data = samples[1]
self.assertEqual('storage.api.request', data.name)
self.assertEqual(1, data.volume)
self.assertEqual('get', data.resource_metadata['method'])
def test_put(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
req = FakeRequest(
'/1.0/account/container/obj',
environ={'REQUEST_METHOD': 'PUT',
'wsgi.input':
six.moves.cStringIO('some stuff')})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(2, len(samples))
data = samples[0]
self.assertEqual(10, data.volume)
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertEqual('obj', data.resource_metadata['object'])
# test the # of request and the request method
data = samples[1]
self.assertEqual('storage.api.request', data.name)
self.assertEqual(1, data.volume)
self.assertEqual('put', data.resource_metadata['method'])
def test_post(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
req = FakeRequest(
'/1.0/account/container/obj',
environ={'REQUEST_METHOD': 'POST',
'wsgi.input': six.moves.cStringIO('some other stuff')})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(2, len(samples))
data = samples[0]
self.assertEqual(16, data.volume)
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertEqual('obj', data.resource_metadata['object'])
# test the # of request and the request method
data = samples[1]
self.assertEqual('storage.api.request', data.name)
self.assertEqual(1, data.volume)
self.assertEqual('post', data.resource_metadata['method'])
def test_head(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
req = FakeRequest('/1.0/account/container/obj',
environ={'REQUEST_METHOD': 'HEAD'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(1, len(samples))
data = samples[0]
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertEqual('obj', data.resource_metadata['object'])
self.assertEqual('head', data.resource_metadata['method'])
self.assertEqual('storage.api.request', data.name)
self.assertEqual(1, data.volume)
def test_bogus_request(self):
"""Test even for arbitrary request method, this will still work."""
app = swift_middleware.CeilometerMiddleware(FakeApp(body=['']), {})
req = FakeRequest('/1.0/account/container/obj',
environ={'REQUEST_METHOD': 'BOGUS'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(1, len(samples))
data = samples[0]
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertEqual('obj', data.resource_metadata['object'])
self.assertEqual('bogus', data.resource_metadata['method'])
self.assertEqual('storage.api.request', data.name)
self.assertEqual(1, data.volume)
def test_get_container(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
req = FakeRequest('/1.0/account/container',
environ={'REQUEST_METHOD': 'GET'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(2, len(samples))
data = samples[0]
self.assertEqual(28, data.volume)
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertIsNone(data.resource_metadata['object'])
def test_no_metadata_headers(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
req = FakeRequest('/1.0/account/container',
environ={'REQUEST_METHOD': 'GET'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(2, len(samples))
data = samples[0]
http_headers = [k for k in data.resource_metadata.keys()
if k.startswith('http_header_')]
self.assertEqual(0, len(http_headers))
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertIsNone(data.resource_metadata['object'])
def test_metadata_headers(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {
'metadata_headers': 'X_VAR1, x-var2, x-var3, token'
})
req = FakeRequest('/1.0/account/container',
environ={'REQUEST_METHOD': 'GET'},
headers={'X_VAR1': 'value1',
'X_VAR2': 'value2',
'TOKEN': 'token'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(2, len(samples))
data = samples[0]
http_headers = [k for k in data.resource_metadata.keys()
if k.startswith('http_header_')]
self.assertEqual(3, len(http_headers))
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertIsNone(data.resource_metadata['object'])
self.assertEqual(b'value1',
data.resource_metadata['http_header_x_var1'])
self.assertEqual(b'value2',
data.resource_metadata['http_header_x_var2'])
self.assertEqual(b'token',
data.resource_metadata['http_header_token'])
self.assertFalse(b'http_header_x_var3' in data.resource_metadata)
def test_metadata_headers_unicode(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {
'metadata_headers': 'unicode'
})
uni = u'\xef\xbd\xa1\xef\xbd\xa5'
req = FakeRequest('/1.0/account/container',
environ={'REQUEST_METHOD': 'GET'},
headers={'UNICODE': uni})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(2, len(samples))
data = samples[0]
http_headers = [k for k in data.resource_metadata.keys()
if k.startswith('http_header_')]
self.assertEqual(1, len(http_headers))
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertIsNone(data.resource_metadata['object'])
self.assertEqual(uni.encode('utf-8'),
data.resource_metadata['http_header_unicode'])
def test_metadata_headers_on_not_existing_header(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {
'metadata_headers': 'x-var3'
})
req = FakeRequest('/1.0/account/container',
environ={'REQUEST_METHOD': 'GET'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(2, len(samples))
data = samples[0]
http_headers = [k for k in data.resource_metadata.keys()
if k.startswith('http_header_')]
self.assertEqual(0, len(http_headers))
self.assertEqual('1.0', data.resource_metadata['version'])
self.assertEqual('container', data.resource_metadata['container'])
self.assertIsNone(data.resource_metadata['object'])
def test_bogus_path(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
req = FakeRequest('/5.0//',
environ={'REQUEST_METHOD': 'GET'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(0, len(samples))
def test_missing_resource_id(self):
app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
req = FakeRequest('/v1/', environ={'REQUEST_METHOD': 'GET'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(0, len(samples))
@mock.patch.object(swift_middleware.CeilometerMiddleware,
'publish_sample')
def test_publish_sample_fail(self, mocked_publish_sample):
mocked_publish_sample.side_effect = Exception("a exception")
app = swift_middleware.CeilometerMiddleware(FakeApp(body=["test"]), {})
req = FakeRequest('/1.0/account/container',
environ={'REQUEST_METHOD': 'GET'})
resp = list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples
self.assertEqual(0, len(samples))
self.assertEqual(["test"], resp)
mocked_publish_sample.assert_called_once_with(mock.ANY, 0, 4)
def test_no_reseller_prefix(self):
# No reseller prefix set: ensure middleware uses AUTH_
app = swift_middleware.CeilometerMiddleware(FakeApp(), {})
req = FakeRequest('/1.0/AUTH_account/container/obj',
environ={'REQUEST_METHOD': 'GET'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples[0]
self.assertEqual("account", samples.resource_id)
def test_custom_reseller_prefix(self):
# Custom reseller prefix set
app = swift_middleware.CeilometerMiddleware(
FakeApp(), {'reseller_prefix': 'CUSTOM_'})
req = FakeRequest('/1.0/CUSTOM_account/container/obj',
environ={'REQUEST_METHOD': 'GET'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples[0]
self.assertEqual("account", samples.resource_id)
def test_invalid_reseller_prefix(self):
# Custom reseller prefix set, but without trailing underscore
app = swift_middleware.CeilometerMiddleware(
FakeApp(), {'reseller_prefix': 'CUSTOM'})
req = FakeRequest('/1.0/CUSTOM_account/container/obj',
environ={'REQUEST_METHOD': 'GET'})
list(app(req.environ, self.start_response))
samples = self.pipeline_manager.pipelines[0].samples[0]
self.assertEqual("account", samples.resource_id)

View File

@ -2,7 +2,6 @@
# The list of modules to copy from oslo-incubator # The list of modules to copy from oslo-incubator
module=service module=service
module=versionutils
# The base module to hold the copy of openstack.common # The base module to hold the copy of openstack.common
base=ceilometer base=ceilometer

View File

@ -323,9 +323,6 @@ ceilometer.event.trait_plugin =
split = ceilometer.event.trait_plugins:SplitterTraitPlugin split = ceilometer.event.trait_plugins:SplitterTraitPlugin
bitfield = ceilometer.event.trait_plugins:BitfieldTraitPlugin bitfield = ceilometer.event.trait_plugins:BitfieldTraitPlugin
paste.filter_factory =
swift = ceilometer.objectstore.swift_middleware:filter_factory
console_scripts = console_scripts =
ceilometer-api = ceilometer.cmd.api:main ceilometer-api = ceilometer.cmd.api:main
ceilometer-agent-central = ceilometer.cmd.eventlet.polling:main_central ceilometer-agent-central = ceilometer.cmd.eventlet.polling:main_central

View File

@ -60,8 +60,6 @@ commands = python -m testtools.run \
ceilometer.tests.network.services.test_vpnaas \ ceilometer.tests.network.services.test_vpnaas \
ceilometer.tests.network.test_floatingip \ ceilometer.tests.network.test_floatingip \
ceilometer.tests.network.test_notifications \ ceilometer.tests.network.test_notifications \
ceilometer.tests.objectstore.test_swift_middleware \
ceilometer.tests.objectstore.test_swift \
ceilometer.tests.orchestration.test_notifications \ ceilometer.tests.orchestration.test_notifications \
ceilometer.tests.profiler.test_notifications \ ceilometer.tests.profiler.test_notifications \
ceilometer.tests.publisher.test_direct \ ceilometer.tests.publisher.test_direct \