From 856c4452bdc401794ddfe842dac70338700bc0f7 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 30 May 2013 14:34:28 +0200 Subject: [PATCH] service: run common initialization stuff Change-Id: I6f6f2e1f6885533b5d8ee8bf652f7f605c78bcdd Signed-off-by: Julien Danjou --- bin/ceilometer-send-counter | 5 +---- ceilometer/api/app.py | 5 +---- ceilometer/central/manager.py | 8 +------- ceilometer/collector/service.py | 13 ++----------- ceilometer/compute/manager.py | 8 +------- ceilometer/objectstore/swift_middleware.py | 2 +- ceilometer/service.py | 9 ++++++++- ceilometer/storage/__init__.py | 5 +---- ceilometer/tests/api.py | 2 -- tests/api/v2/test_app.py | 1 - tests/test_service.py | 2 +- 11 files changed, 17 insertions(+), 43 deletions(-) diff --git a/bin/ceilometer-send-counter b/bin/ceilometer-send-counter index 1d46932fd..9cb93ea85 100755 --- a/bin/ceilometer-send-counter +++ b/bin/ceilometer-send-counter @@ -26,9 +26,6 @@ import sys from oslo.config import cfg from stevedore import dispatch -from ceilometer.openstack.common import gettextutils -gettextutils.install('ceilometer') - from ceilometer import counter from ceilometer import pipeline from ceilometer import publisher @@ -75,7 +72,7 @@ cfg.CONF.register_cli_opts([ help='counter metadata'), ]) -service.prepare_service(sys.argv) +service.prepare_service() # Set up logging to use the console console = logging.StreamHandler(sys.stderr) diff --git a/ceilometer/api/app.py b/ceilometer/api/app.py index 4ac4b74a1..93ad46280 100644 --- a/ceilometer/api/app.py +++ b/ceilometer/api/app.py @@ -20,7 +20,6 @@ import logging import os from oslo.config import cfg import pecan -import sys from ceilometer.api import acl from ceilometer.api import config as api_config @@ -29,7 +28,6 @@ from ceilometer.api import middleware from ceilometer import service from ceilometer.openstack.common import log from wsgiref import simple_server -from ceilometer.openstack.common import gettextutils LOG = log.getLogger(__name__) @@ -102,8 +100,7 @@ class VersionSelectorApplication(object): def start(): - gettextutils.install('ceilometer') - service.prepare_service(sys.argv) + service.prepare_service() # Build the WSGI app root = VersionSelectorApplication() diff --git a/ceilometer/central/manager.py b/ceilometer/central/manager.py index ff734b8db..d91d1b23d 100644 --- a/ceilometer/central/manager.py +++ b/ceilometer/central/manager.py @@ -16,14 +16,11 @@ # License for the specific language governing permissions and limitations # under the License. -import eventlet from keystoneclient.v2_0 import client as ksclient from oslo.config import cfg -import sys from ceilometer import agent from ceilometer import extension_manager -from ceilometer.openstack.common import gettextutils from ceilometer.openstack.common import log from ceilometer.openstack.common import service as os_service from ceilometer.openstack.common.rpc import service as rpc_service @@ -84,10 +81,7 @@ class AgentManager(agent.AgentManager): def agent_central(): - # TODO(jd) move into prepare_service gettextutils and eventlet? - eventlet.monkey_patch() - gettextutils.install('ceilometer') - service.prepare_service(sys.argv) + service.prepare_service() os_service.launch(rpc_service.Service(cfg.CONF.host, 'ceilometer.agent.central', AgentManager())).wait() diff --git a/ceilometer/collector/service.py b/ceilometer/collector/service.py index bdd5ceaab..84ebb424e 100644 --- a/ceilometer/collector/service.py +++ b/ceilometer/collector/service.py @@ -16,17 +16,14 @@ # License for the specific language governing permissions and limitations # under the License. -import eventlet from oslo.config import cfg import msgpack import socket -import sys from ceilometer.publisher import meter as publisher_meter from ceilometer import extension_manager from ceilometer.service import prepare_service from ceilometer.openstack.common import context -from ceilometer.openstack.common import gettextutils from ceilometer.openstack.common import log from ceilometer.openstack.common import service as os_service from ceilometer.openstack.common.rpc import dispatcher as rpc_dispatcher @@ -112,10 +109,7 @@ class UDPCollectorService(os_service.Service): def udp_collector(): - # TODO(jd) move into prepare_service gettextutils and eventlet? - eventlet.monkey_patch() - gettextutils.install('ceilometer') - prepare_service(sys.argv) + prepare_service() os_service.launch(UDPCollectorService()).wait() @@ -234,9 +228,6 @@ class CollectorService(rpc_service.Service): def collector(): - # TODO(jd) move into prepare_service gettextutils and eventlet? - eventlet.monkey_patch() - gettextutils.install('ceilometer') - prepare_service(sys.argv) + prepare_service() os_service.launch(CollectorService(cfg.CONF.host, 'ceilometer.collector')).wait() diff --git a/ceilometer/compute/manager.py b/ceilometer/compute/manager.py index a675740f7..1f26ca60b 100644 --- a/ceilometer/compute/manager.py +++ b/ceilometer/compute/manager.py @@ -16,15 +16,12 @@ # License for the specific language governing permissions and limitations # under the License. -import eventlet from oslo.config import cfg -import sys from ceilometer import agent from ceilometer.compute.virt import inspector as virt_inspector from ceilometer import extension_manager from ceilometer import nova_client -from ceilometer.openstack.common import gettextutils from ceilometer.openstack.common import log from ceilometer.openstack.common import service as os_service from ceilometer.openstack.common.rpc import service as rpc_service @@ -90,10 +87,7 @@ class AgentManager(agent.AgentManager): def agent_compute(): - # TODO(jd) move into prepare_service gettextutils and eventlet? - eventlet.monkey_patch() - gettextutils.install('ceilometer') - service.prepare_service(sys.argv) + service.prepare_service() os_service.launch(rpc_service.Service(cfg.CONF.host, 'ceilometer.agent.compute', AgentManager())).wait() diff --git a/ceilometer/objectstore/swift_middleware.py b/ceilometer/objectstore/swift_middleware.py index 4fb868686..b7447ec92 100644 --- a/ceilometer/objectstore/swift_middleware.py +++ b/ceilometer/objectstore/swift_middleware.py @@ -78,7 +78,7 @@ class CeilometerMiddleware(object): "metadata_headers", "").split(",") if h.strip()] - service.prepare_service() + service.prepare_service([]) self.pipeline_manager = pipeline.setup_pipeline( transformer.TransformerExtensionManager( diff --git a/ceilometer/service.py b/ceilometer/service.py index 22591c2d3..85e268a32 100644 --- a/ceilometer/service.py +++ b/ceilometer/service.py @@ -17,11 +17,14 @@ # License for the specific language governing permissions and limitations # under the License. +import eventlet import os import socket +import sys from oslo.config import cfg +from ceilometer.openstack.common import gettextutils from ceilometer.openstack.common import log from ceilometer.openstack.common import rpc @@ -72,7 +75,9 @@ def _sanitize_cmd_line(argv): return [a for a in argv if a in cli_opt_names] -def prepare_service(argv=[]): +def prepare_service(argv=None): + eventlet.monkey_patch() + gettextutils.install('ceilometer') rpc.set_defaults(control_exchange='ceilometer') cfg.set_defaults(log.log_opts, default_log_levels=['amqplib=WARN', @@ -82,5 +87,7 @@ def prepare_service(argv=[]): 'stevedore=INFO', 'eventlet.wsgi.server=WARN' ]) + if argv is None: + argv = sys.argv cfg.CONF(argv[1:], project='ceilometer') log.setup('ceilometer') diff --git a/ceilometer/storage/__init__.py b/ceilometer/storage/__init__.py index 40e0252e8..7dab32037 100644 --- a/ceilometer/storage/__init__.py +++ b/ceilometer/storage/__init__.py @@ -23,9 +23,7 @@ import urlparse from oslo.config import cfg from stevedore import driver -import sys -from ceilometer.openstack.common import gettextutils from ceilometer.openstack.common import log from ceilometer import utils from ceilometer import service @@ -124,6 +122,5 @@ class EventFilter(object): def dbsync(): - gettextutils.install('ceilometer') - service.prepare_service(sys.argv) + service.prepare_service() get_connection(cfg.CONF).upgrade() diff --git a/ceilometer/tests/api.py b/ceilometer/tests/api.py index 66009a988..6d4dabace 100644 --- a/ceilometer/tests/api.py +++ b/ceilometer/tests/api.py @@ -26,7 +26,6 @@ from oslo.config import cfg import pecan import pecan.testing -from ceilometer import service from ceilometer.openstack.common import jsonutils from ceilometer.api import acl from ceilometer.api.v1 import app as v1_app @@ -84,7 +83,6 @@ class FunctionalTest(db_test_base.TestBase): def setUp(self): super(FunctionalTest, self).setUp() - service.prepare_service() cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME) cfg.CONF.set_override("policy_file", self.path_get('tests/policy.json')) diff --git a/tests/api/v2/test_app.py b/tests/api/v2/test_app.py index f98dd6ef0..2a20c80aa 100644 --- a/tests/api/v2/test_app.py +++ b/tests/api/v2/test_app.py @@ -35,7 +35,6 @@ class TestApp(base.TestCase): cfg.CONF.reset() def test_keystone_middleware_conf(self): - service.prepare_service() cfg.CONF.set_override("auth_protocol", "foottp", group=acl.OPT_GROUP_NAME) cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME) diff --git a/tests/test_service.py b/tests/test_service.py index 9c481747e..75f349234 100644 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -23,4 +23,4 @@ from ceilometer.tests import base class ServiceTestCase(base.TestCase): def test_prepare_service(self): - service.prepare_service() + service.prepare_service([])