From c88f02f83dfd5dadbf5c90f13a0a34157105b8ee Mon Sep 17 00:00:00 2001 From: ZhiQiang Fan Date: Tue, 24 Nov 2015 04:04:02 +0800 Subject: [PATCH] initialize ceilometerclient when we use it There is a chance that ceilometerclient cannot be initialized if keystone is not available, putting the initialization in __init__ will fail to load threshold extension for such case. This patch moves the initialization out from __init__ to a dedicate property method. Conflicts: aodh/evaluator/threshold.py Change-Id: I24895126c3efe9920390401e4d10a2ce6b1f1376 Closes-Bug: #1518447 (cherry picked from commit 3592c67acea6b7f3a0e5c070bd940fdfb0a5db4f) --- aodh/evaluator/threshold.py | 39 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/aodh/evaluator/threshold.py b/aodh/evaluator/threshold.py index 91e13ae5c..2071217ef 100644 --- a/aodh/evaluator/threshold.py +++ b/aodh/evaluator/threshold.py @@ -46,23 +46,28 @@ class ThresholdEvaluator(evaluator.Evaluator): def __init__(self, conf, notifier): super(ThresholdEvaluator, self).__init__(conf, notifier) - auth_config = conf.service_credentials - self._client = ceiloclient.get_client( - 2, - os_auth_url=auth_config.os_auth_url.replace('/v2.0', '/'), - os_region_name=auth_config.os_region_name, - os_tenant_name=auth_config.os_tenant_name, - os_password=auth_config.os_password, - os_username=auth_config.os_username, - os_cacert=auth_config.os_cacert, - os_endpoint_type=auth_config.os_endpoint_type, - insecure=auth_config.insecure, - timeout=conf.http_timeout, - os_user_domain_id=auth_config.os_user_domain_id, - os_project_name=auth_config.os_project_name, - os_project_domain_id=auth_config.os_project_domain_id, + self._cm_client = None - ) + @property + def cm_client(self): + if self._cm_client is None: + auth_config = self.conf.service_credentials + self._cm_client = ceiloclient.get_client( + 2, + os_auth_url=auth_config.os_auth_url.replace('/v2.0', '/'), + os_region_name=auth_config.os_region_name, + os_tenant_name=auth_config.os_tenant_name, + os_password=auth_config.os_password, + os_username=auth_config.os_username, + os_cacert=auth_config.os_cacert, + os_endpoint_type=auth_config.os_endpoint_type, + insecure=auth_config.insecure, + timeout=self.conf.http_timeout, + os_user_domain_id=auth_config.os_user_domain_id, + os_project_name=auth_config.os_project_name, + os_project_domain_id=auth_config.os_project_domain_id, + ) + return self._cm_client @classmethod def _bound_duration(cls, alarm): @@ -114,7 +119,7 @@ class ThresholdEvaluator(evaluator.Evaluator): query.extend([before, after]) LOG.debug('stats query %s', query) try: - return self._client.statistics.list( + return self.cm_client.statistics.list( meter_name=alarm.rule['meter_name'], q=query, period=alarm.rule['period']) except Exception: