From cc0fc91200c57d715c8f0f212e0247cd9261a79b Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 29 May 2013 13:34:20 +0200 Subject: [PATCH] Use console scripts for ceilometer-api Blueprint: setuptools-console-scripts Change-Id: Ia64319ba2ea5fdd2778c7faea76478272bb237a6 Signed-off-by: Julien Danjou --- bin/ceilometer-api | 63 ----------------------------------- ceilometer/api/app.py | 32 ++++++++++++++++++ doc/source/install/manual.rst | 2 +- setup.cfg | 3 +- tests/test_bin.py | 2 +- tox.ini | 2 +- 6 files changed, 36 insertions(+), 68 deletions(-) delete mode 100755 bin/ceilometer-api diff --git a/bin/ceilometer-api b/bin/ceilometer-api deleted file mode 100755 index 3124932b6..000000000 --- a/bin/ceilometer-api +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -*- encoding: utf-8 -*- -# -# Copyright © 2012 New Dream Network, LLC (DreamHost) -# -# Author: Doug Hellmann -# -# 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. -"""Set up the development API server. -""" -import logging -import os -import sys -from wsgiref import simple_server - -from oslo.config import cfg - -from ceilometer.openstack.common import gettextutils -gettextutils.install('ceilometer') - -from ceilometer.api import app -from ceilometer.openstack.common import log -from ceilometer import service - - -if __name__ == '__main__': - # Parse OpenStack config file and command line options, then - # configure logging. - service.prepare_service(sys.argv) - - # Build the WSGI app - root = app.VersionSelectorApplication() - - # Create the WSGI server and start it - host, port = cfg.CONF.api.host, cfg.CONF.api.port - srv = simple_server.make_server(host, port, root) - - LOG = log.getLogger(__name__) - LOG.info('Starting server in PID %s' % os.getpid()) - LOG.info("Configuration:") - cfg.CONF.log_opt_values(LOG, logging.INFO) - - if host == '0.0.0.0': - LOG.info('serving on 0.0.0.0:%s, view at http://127.0.0.1:%s' % - (port, port)) - else: - LOG.info("serving on http://%s:%s" % (host, port)) - - try: - srv.serve_forever() - except KeyboardInterrupt: - # allow CTRL+C to shutdown without an error - pass diff --git a/ceilometer/api/app.py b/ceilometer/api/app.py index a684067c1..4ac4b74a1 100644 --- a/ceilometer/api/app.py +++ b/ceilometer/api/app.py @@ -16,14 +16,22 @@ # License for the specific language governing permissions and limitations # under the License. +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 from ceilometer.api import hooks 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__) auth_opts = [ cfg.StrOpt('auth_strategy', @@ -91,3 +99,27 @@ class VersionSelectorApplication(object): if environ['PATH_INFO'].startswith('/v1/'): return self.v1(environ, start_response) return self.v2(environ, start_response) + + +def start(): + gettextutils.install('ceilometer') + service.prepare_service(sys.argv) + + # Build the WSGI app + root = VersionSelectorApplication() + + # Create the WSGI server and start it + host, port = cfg.CONF.api.host, cfg.CONF.api.port + srv = simple_server.make_server(host, port, root) + + LOG.info('Starting server in PID %s' % os.getpid()) + LOG.info("Configuration:") + cfg.CONF.log_opt_values(LOG, logging.INFO) + + if host == '0.0.0.0': + LOG.info('serving on 0.0.0.0:%s, view at http://127.0.0.1:%s' % + (port, port)) + else: + LOG.info("serving on http://%s:%s" % (host, port)) + + srv.serve_forever() diff --git a/doc/source/install/manual.rst b/doc/source/install/manual.rst index 10d3014b5..bcb76fe3b 100644 --- a/doc/source/install/manual.rst +++ b/doc/source/install/manual.rst @@ -334,7 +334,7 @@ Installing the API Server :: - $ ./bin/ceilometer-api + $ ceilometer-api .. note:: diff --git a/setup.cfg b/setup.cfg index d9cadf763..703541daf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,8 +26,6 @@ setup-hooks = [files] packages = ceilometer -scripts = - bin/ceilometer-api [entry_points] ceilometer.collector = @@ -86,6 +84,7 @@ paste.filter_factory = swift = ceilometer.objectstore.swift_middleware:filter_factory console_scripts = + ceilometer-api = ceilometer.api.app:start ceilometer-agent-central = ceilometer.central.manager:agent_central ceilometer-agent-compute = ceilometer.compute.manager:agent_compute ceilometer-dbsync = ceilometer.storage:dbsync diff --git a/tests/test_bin.py b/tests/test_bin.py index d93b9f5e2..56cc0e9d1 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -87,7 +87,7 @@ class BinApiTestCase(base.TestCase): "port=%s\n" % self.api_port) tmp.write("[database]\n") tmp.write("connection=log://localhost\n") - self.subp = subprocess.Popen([self.path_get('bin/ceilometer-api'), + self.subp = subprocess.Popen(['ceilometer-api', "--config-file=%s" % self.tempfile]) def tearDown(self): diff --git a/tox.ini b/tox.ini index 29049bef1..649c1fd1a 100644 --- a/tox.ini +++ b/tox.ini @@ -24,7 +24,7 @@ deps = pep8==1.4.5 flake8==2.0 hacking>=0.5.3,<0.6 commands = - flake8 ceilometer setup.py bin/ceilometer-api tests + flake8 ceilometer setup.py tests [testenv:docs] deps = -r{toxinidir}/requirements.txt