diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 5fa2ba63..f271aa62 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -228,10 +228,6 @@ function configure_gnocchi { # Configure logging iniset $GNOCCHI_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL" - # Install the configuration files - cp $GNOCCHI_DIR/etc/gnocchi/* $GNOCCHI_CONF_DIR - - # Set up logging if [ "$SYSLOG" != "False" ]; then iniset $GNOCCHI_CONF DEFAULT use_syslog "True" diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 63e3506b..0f471cf1 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -10,7 +10,7 @@ easily created by running: :: - oslo-config-generator --config-file=/etc/gnocchi/gnocchi-config-generator.conf --output-file=/etc/gnocchi/gnocchi.conf + gnocchi-config-generator > /etc/gnocchi/gnocchi.conf The configuration file should be pretty explicit, but here are some of the base options you want to change and configure: diff --git a/gnocchi/cli.py b/gnocchi/cli.py index 3a7ba02a..7ba3b229 100644 --- a/gnocchi/cli.py +++ b/gnocchi/cli.py @@ -1,5 +1,5 @@ # Copyright (c) 2013 Mirantis Inc. -# Copyright (c) 2015-2016 Red Hat +# Copyright (c) 2015-2017 Red Hat # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import multiprocessing +import sys import threading import time @@ -30,6 +31,7 @@ import tooz from tooz import coordination from gnocchi import archive_policy +from gnocchi import genconfig from gnocchi import indexer from gnocchi import service from gnocchi import statsd as statsd_service @@ -40,6 +42,10 @@ from gnocchi import utils LOG = log.getLogger(__name__) +def config_generator(): + return genconfig.prehook(None, sys.argv[1:]) + + def upgrade(): conf = cfg.ConfigOpts() conf.register_cli_opts([ diff --git a/gnocchi/genconfig.py b/gnocchi/genconfig.py index 84a2feb9..0eba7359 100644 --- a/gnocchi/genconfig.py +++ b/gnocchi/genconfig.py @@ -1,6 +1,6 @@ # -*- encoding: utf-8 -*- # -# Copyright © 2016 Red Hat, Inc. +# Copyright © 2016-2017 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 @@ -13,12 +13,17 @@ # 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 os -def prehook(cmd): +def prehook(cmd, args=None): + if args is None: + args = ['--output-file', 'etc/gnocchi/gnocchi.conf'] try: from oslo_config import generator - generator.main(['--config-file', - 'etc/gnocchi/gnocchi-config-generator.conf']) + generator.main( + ['--config-file', + '%s/gnocchi-config-generator.conf' % os.path.dirname(__file__)] + + args) except Exception as e: print("Unable to build sample configuration file: %s" % e) diff --git a/etc/gnocchi/gnocchi-config-generator.conf b/gnocchi/gnocchi-config-generator.conf similarity index 88% rename from etc/gnocchi/gnocchi-config-generator.conf rename to gnocchi/gnocchi-config-generator.conf index 741f015f..df6e9880 100644 --- a/etc/gnocchi/gnocchi-config-generator.conf +++ b/gnocchi/gnocchi-config-generator.conf @@ -1,5 +1,4 @@ [DEFAULT] -output_file = etc/gnocchi/gnocchi.conf wrap_width = 79 namespace = gnocchi namespace = oslo.db diff --git a/gnocchi/tests/test_bin.py b/gnocchi/tests/test_bin.py new file mode 100644 index 00000000..e70bb865 --- /dev/null +++ b/gnocchi/tests/test_bin.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +# +# Copyright © 2017 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 +# 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 subprocess + +from oslotest import base + + +class BinTestCase(base.BaseTestCase): + def test_gnocchi_config_generator_run(self): + subp = subprocess.Popen(['gnocchi-config-generator']) + self.assertEqual(0, subp.wait()) diff --git a/releasenotes/notes/gnocchi_config_generator-0fc337ba8e3afd5f.yaml b/releasenotes/notes/gnocchi_config_generator-0fc337ba8e3afd5f.yaml new file mode 100644 index 00000000..73af05f2 --- /dev/null +++ b/releasenotes/notes/gnocchi_config_generator-0fc337ba8e3afd5f.yaml @@ -0,0 +1,5 @@ +--- +features: + - >- + The `gnocchi-config-generator` program can now generates a default + configuration file, usable as a template for custom tweaking. diff --git a/setup.cfg b/setup.cfg index fbd25736..08fe573e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -92,8 +92,6 @@ pre-hook.build_config = gnocchi.genconfig.prehook [files] packages = gnocchi -data_files = - etc/gnocchi = etc/gnocchi/* [entry_points] gnocchi.indexer.sqlalchemy.resource_type_attribute = @@ -127,6 +125,7 @@ gnocchi.rest.auth_helper = keystone = gnocchi.rest.auth_helper:KeystoneAuthHelper console_scripts = + gnocchi-config-generator = gnocchi.cli:config_generator gnocchi-upgrade = gnocchi.cli:upgrade gnocchi-statsd = gnocchi.cli:statsd gnocchi-metricd = gnocchi.cli:metricd diff --git a/tox.ini b/tox.ini index b0e37db1..3816a770 100644 --- a/tox.ini +++ b/tox.ini @@ -29,7 +29,7 @@ deps = .[test] # NOTE(tonyb): This project has chosen to *NOT* consume upper-constraints.txt commands = doc8 --ignore-path doc/source/rest.rst doc/source - oslo-config-generator --config-file=etc/gnocchi/gnocchi-config-generator.conf + gnocchi-config-generator {toxinidir}/run-tests.sh {posargs} [testenv:py35-postgresql-file-upgrade-from-3.0] @@ -125,7 +125,7 @@ enable-extensions = H904 [testenv:genconfig] deps = .[mysql,postgresql,test,file,ceph,swift,s3] -commands = oslo-config-generator --config-file=etc/gnocchi/gnocchi-config-generator.conf +commands = gnocchi-config-generator [testenv:docs] # This does not work, see: https://bitbucket.org/hpk42/tox/issues/302