Add gnocchi-config-generator

This is a new tool that allows to not worry about the
oslo-config-generator configuration file path.

Change-Id: Iec9097c67fcf0161c69f0bf76e89a910238ea210
This commit is contained in:
Julien Danjou 2017-01-11 18:24:50 +01:00
parent 39265b4916
commit 410b1643bf
9 changed files with 49 additions and 15 deletions

View File

@ -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"

View File

@ -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:

View File

@ -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([

View File

@ -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)

View File

@ -1,5 +1,4 @@
[DEFAULT]
output_file = etc/gnocchi/gnocchi.conf
wrap_width = 79
namespace = gnocchi
namespace = oslo.db

24
gnocchi/tests/test_bin.py Normal file
View File

@ -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())

View File

@ -0,0 +1,5 @@
---
features:
- >-
The `gnocchi-config-generator` program can now generates a default
configuration file, usable as a template for custom tweaking.

View File

@ -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

View File

@ -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