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)