Merge "Skip central agent interval_task when keystone fails"

This commit is contained in:
Jenkins 2014-03-21 17:23:12 +00:00 committed by Gerrit Code Review
commit 65a6366d57
2 changed files with 23 additions and 9 deletions

View File

@ -20,6 +20,7 @@ from keystoneclient.v2_0 import client as ksclient
from oslo.config import cfg
from ceilometer import agent
from ceilometer.openstack.common.gettextutils import _ # noqa
from ceilometer.openstack.common import log
cfg.CONF.import_group('service_credentials', 'ceilometer.service')
@ -33,14 +34,18 @@ class AgentManager(agent.AgentManager):
super(AgentManager, self).__init__('central')
def interval_task(self, task):
self.keystone = ksclient.Client(
username=cfg.CONF.service_credentials.os_username,
password=cfg.CONF.service_credentials.os_password,
tenant_id=cfg.CONF.service_credentials.os_tenant_id,
tenant_name=cfg.CONF.service_credentials.os_tenant_name,
cacert=cfg.CONF.service_credentials.os_cacert,
auth_url=cfg.CONF.service_credentials.os_auth_url,
region_name=cfg.CONF.service_credentials.os_region_name,
insecure=cfg.CONF.service_credentials.insecure)
try:
self.keystone = ksclient.Client(
username=cfg.CONF.service_credentials.os_username,
password=cfg.CONF.service_credentials.os_password,
tenant_id=cfg.CONF.service_credentials.os_tenant_id,
tenant_name=cfg.CONF.service_credentials.os_tenant_name,
cacert=cfg.CONF.service_credentials.os_cacert,
auth_url=cfg.CONF.service_credentials.os_auth_url,
region_name=cfg.CONF.service_credentials.os_region_name,
insecure=cfg.CONF.service_credentials.insecure)
except Exception as e:
LOG.error(_('Skip interval_task because Keystone error: %s'), e)
return
super(AgentManager, self).interval_task(task)

View File

@ -50,3 +50,12 @@ class TestRunTasks(agentbase.BaseAgentManagerTestCase):
polling_tasks = self.mgr.setup_polling_tasks()
self.mgr.interval_task(polling_tasks.values()[0])
self.assertTrue(self.Pollster.resources)
def test_skip_task_when_keystone_fail(self):
"""Test for https://bugs.launchpad.net/ceilometer/+bug/1287613."""
self.useFixture(mockpatch.Patch(
'keystoneclient.v2_0.client.Client',
side_effect=Exception))
polling_tasks = self.mgr.setup_polling_tasks()
self.mgr.interval_task(polling_tasks.values()[0])
self.assertFalse(self.Pollster.samples)