From 6ae96098572b9c3d178e8f9f5d7e7a533a739ecb Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 3 Feb 2015 14:33:30 +0100 Subject: [PATCH] discovery: allow to discover all endpoints This allow the Keystone endpoints discoverer to discover all the URLs if no service type is specified. Blueprint: ceilometer-healthcheck-middleware Change-Id: I6e1e5f6261ca55c5a0a0c70822f80257061d56c2 --- ceilometer/agent/discovery/endpoint.py | 13 ++++++------- ceilometer/tests/agent/test_discovery.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ceilometer/agent/discovery/endpoint.py b/ceilometer/agent/discovery/endpoint.py index 51bbae857..89761ec66 100644 --- a/ceilometer/agent/discovery/endpoint.py +++ b/ceilometer/agent/discovery/endpoint.py @@ -1,4 +1,4 @@ -# Copyright 2014 Red Hat, Inc +# Copyright 2014-2015 Red Hat, Inc # # 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 @@ -32,15 +32,14 @@ class EndpointDiscovery(plugin.DiscoveryBase): nova.floating_ips.list() and therefore gets all floating IPs at once. """ - def discover(self, manager, param=None): - if not param: - return [] + @staticmethod + def discover(manager, param=None): endpoints = manager.keystone.service_catalog.get_urls( service_type=param, endpoint_type=cfg.CONF.service_credentials.os_endpoint_type, region_name=cfg.CONF.service_credentials.os_region_name) if not endpoints: - LOG.warning(_LW('No endpoints found for service %s'), param) + LOG.warning(_LW('No endpoints found for service %s'), + "" if param is None else param) return [] - else: - return endpoints + return endpoints diff --git a/ceilometer/tests/agent/test_discovery.py b/ceilometer/tests/agent/test_discovery.py index 16ba41e5e..882dd5187 100644 --- a/ceilometer/tests/agent/test_discovery.py +++ b/ceilometer/tests/agent/test_discovery.py @@ -29,12 +29,12 @@ class TestEndpointDiscovery(base.BaseTestCase): self.discovery = endpoint.EndpointDiscovery() self.manager = mock.MagicMock() self.CONF = self.useFixture(fixture_config.Config()).conf - - def test_keystone_called(self): self.CONF.set_override('os_endpoint_type', 'test-endpoint-type', group='service_credentials') self.CONF.set_override('os_region_name', 'test-region-name', group='service_credentials') + + def test_keystone_called(self): self.discovery.discover(self.manager, param='test-service-type') expected = [mock.call(service_type='test-service-type', endpoint_type='test-endpoint-type', @@ -42,3 +42,12 @@ class TestEndpointDiscovery(base.BaseTestCase): self.assertEqual(expected, self.manager.keystone.service_catalog.get_urls .call_args_list) + + def test_keystone_called_no_service_type(self): + self.discovery.discover(self.manager) + expected = [mock.call(service_type=None, + endpoint_type='test-endpoint-type', + region_name='test-region-name')] + self.assertEqual(expected, + self.manager.keystone.service_catalog.get_urls + .call_args_list)