Split service preparation, periodic interval configurable

Change-Id: I71d1e81e2b2347fb7e3ba2edfa7f21eb9cffb401
Signed-off-by: Julien Danjou <julien.danjou@enovance.com>
This commit is contained in:
Julien Danjou 2012-06-26 14:26:57 +02:00
parent 5d90f057cb
commit 3c01ccefd5
4 changed files with 68 additions and 23 deletions

View File

@ -19,30 +19,19 @@
import eventlet
eventlet.monkey_patch()
import sys
from nova import flags
from ceilometer.service import prepare_service
from ceilometer.openstack.common import cfg
from nova import service
from nova import utils
from ceilometer import log
if __name__ == '__main__':
flags.parse_args(sys.argv)
log.setup()
utils.monkey_patch()
prepare_service(sys.argv)
server = \
service.Service.create(binary='ceilometer-agent',
topic='ceilometer.agent',
manager='ceilometer.agent.manager.AgentManager',
# FIXME(dhellmann): The
# periodic_interval is set very
# short for development. After we
# fix the configuration loading we
# can use the config file to
# adjust it and remove this
# hard-coded value.
periodic_interval=10,
)
periodic_interval=cfg.CONF.periodic_interval)
service.serve(server)
service.wait()

View File

@ -19,18 +19,15 @@
import eventlet
eventlet.monkey_patch()
import sys
from nova import flags
from ceilometer.service import prepare_service
from ceilometer.openstack.common import cfg
from nova import service
from nova import utils
from ceilometer import log
if __name__ == '__main__':
flags.parse_args(sys.argv)
log.setup()
utils.monkey_patch()
prepare_service(sys.argv)
server = \
service.Service.create(binary='ceilometer-collector',
topic='ceilometer.collector',

32
ceilometer/service.py Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Copyright © 2012 eNovance <licensing@enovance.com>
#
# Author: Julien Danjou <julien@danjou.info>
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from ceilometer import log
from ceilometer.openstack.common import cfg
cfg.CONF.register_opts([
cfg.IntOpt('periodic_interval',
default=60,
help='seconds between running periodic tasks')
])
def prepare_service(argv=[]):
cfg.CONF(argv[1:])
log.setup()

27
tests/test_service.py Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Copyright © 2012 eNovance <licensing@enovance.com>
#
# Author: Julien Danjou <julien@danjou.info>
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
from ceilometer import service
class ServiceTestCase(unittest.TestCase):
def test_prepare_service(self):
service.prepare_service()