Swallow & report 404s from Swift (missing tenant)

The 404s are caused when Keystone has a tenant that Swift does not.
These 404s can safely be ignored.
If not ignored, some meters are not collected from Swift, as the
ClientException stops the tenant loop from completing.

Change-Id: I34aa40ba6c8e40e6d51b0a8dd24b8975c742f3ab
(cherry picked from commit 2ab761db26)
Closes-bug: #1681362
This commit is contained in:
Thomas Graichen 2016-10-27 12:26:31 +01:00 committed by Mehdi Abaakouk (sileht)
parent b102f73f71
commit df47b4e90b
1 changed files with 17 additions and 10 deletions

View File

@ -22,6 +22,7 @@ from oslo_config import cfg
from oslo_log import log
import six.moves.urllib.parse as urlparse
from swiftclient import client as swift
from swiftclient.exceptions import ClientException
from ceilometer.agent import plugin_base
from ceilometer.i18n import _LI
@ -85,12 +86,18 @@ class _Base(plugin_base.PollsterBase):
if not endpoint:
raise StopIteration()
swift_api_method = getattr(swift, '%s_account' % self.METHOD)
for t in tenants:
api_method = '%s_account' % self.METHOD
yield (t.id, getattr(swift, api_method)
(self._neaten_url(endpoint, t.id,
self.conf.reseller_prefix),
keystone_client.get_auth_token(ksclient)))
try:
yield (t.id, swift_api_method(
self._neaten_url(endpoint, t.id,
self.conf.reseller_prefix),
keystone_client.get_auth_token(ksclient)))
except ClientException as e:
if e.http_status == 404:
LOG.warning("Swift tenant id %s not found.", t.id)
else:
raise e
@staticmethod
def _neaten_url(endpoint, tenant_id, reseller_prefix):
@ -100,7 +107,7 @@ class _Base(plugin_base.PollsterBase):
class ObjectsPollster(_Base):
"""Collect the total objects count for each project."""
"""Collect the total objects count for each project"""
def get_samples(self, manager, cache, resources):
tenants = resources
for tenant, account in self._iter_accounts(manager.keystone,
@ -118,7 +125,7 @@ class ObjectsPollster(_Base):
class ObjectsSizePollster(_Base):
"""Collect the total objects size of each project."""
"""Collect the total objects size of each project"""
def get_samples(self, manager, cache, resources):
tenants = resources
for tenant, account in self._iter_accounts(manager.keystone,
@ -136,7 +143,7 @@ class ObjectsSizePollster(_Base):
class ObjectsContainersPollster(_Base):
"""Collect the container count for each project."""
"""Collect the container count for each project"""
def get_samples(self, manager, cache, resources):
tenants = resources
for tenant, account in self._iter_accounts(manager.keystone,
@ -154,7 +161,7 @@ class ObjectsContainersPollster(_Base):
class ContainersObjectsPollster(_Base):
"""Collect the objects count per container for each project."""
"""Collect the objects count per container for each project"""
METHOD = 'get'
@ -177,7 +184,7 @@ class ContainersObjectsPollster(_Base):
class ContainersSizePollster(_Base):
"""Collect the total objects size per container for each project."""
"""Collect the total objects size per container for each project"""
METHOD = 'get'