From e719861c00ab1e50e271c3bcdbc0b9130353d2d4 Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Thu, 3 Dec 2015 14:39:29 +0000 Subject: [PATCH] Automatically generate neutron LBaaS configuration files This adds a new tox environment, genconfig, which generates sample neutron LBaaS configuration file using oslo-config-generator. DocImpact: Update the docs that LBaaS no longer includes static example configuration files. Instead, use tools/generate_config_file_samples.sh to generate them and the files generated now end with .sample extension. Partially-Implements: blueprint autogen-neutron-conf-file Change-Id: I25507f3bc6e995580aa91a912c2cf4110757df15 Partial-bug: #1199963 --- .gitignore | 1 + devstack/plugin.sh | 7 +- etc/README.txt | 9 ++ etc/oslo-config-generator/lbaas_agent.ini | 6 ++ etc/oslo-config-generator/neutron_lbaas.conf | 5 + etc/oslo-config-generator/services_lbaas.conf | 5 + neutron_lbaas/opts.py | 91 +++++++++++++++++++ ...nfig-file-generation-cddf85d9d4022e2d.yaml | 7 ++ setup.cfg | 4 + tools/generate_config_file_samples.sh | 28 ++++++ tox.ini | 4 + 11 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 etc/README.txt create mode 100644 etc/oslo-config-generator/lbaas_agent.ini create mode 100644 etc/oslo-config-generator/neutron_lbaas.conf create mode 100644 etc/oslo-config-generator/services_lbaas.conf create mode 100644 neutron_lbaas/opts.py create mode 100644 releasenotes/notes/config-file-generation-cddf85d9d4022e2d.yaml create mode 100755 tools/generate_config_file_samples.sh diff --git a/.gitignore b/.gitignore index 21250141d..f50466e97 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ cover/ covhtml/ dist/ doc/build +etc/*.sample *.DS_Store *.pyc neutron.egg-info/ diff --git a/devstack/plugin.sh b/devstack/plugin.sh index a6ee72ba6..5a35a198c 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -27,7 +27,10 @@ function neutron_lbaas_configure_common { die $LINENO "Do not enable both Version 1 and Version 2 of LBaaS." fi - cp $NEUTRON_LBAAS_DIR/etc/neutron_lbaas.conf $NEUTRON_LBAAS_CONF + # Uses oslo config generator to generate LBaaS sample configuration files + (cd $NEUTRON_LBAAS_DIR && exec ./tools/generate_config_file_samples.sh) + + cp $NEUTRON_LBAAS_DIR/etc/neutron_lbaas.conf.sample $NEUTRON_LBAAS_CONF if is_service_enabled $LBAAS_V1; then inicomment $NEUTRON_LBAAS_CONF service_providers service_provider @@ -61,7 +64,7 @@ function neutron_lbaas_configure_common { function neutron_lbaas_configure_agent { mkdir -p $LBAAS_AGENT_CONF_PATH - cp $NEUTRON_LBAAS_DIR/etc/lbaas_agent.ini $LBAAS_AGENT_CONF_FILENAME + cp $NEUTRON_LBAAS_DIR/etc/lbaas_agent.ini.sample $LBAAS_AGENT_CONF_FILENAME # ovs_use_veth needs to be set before the plugin configuration # occurs to allow plugins to override the setting. diff --git a/etc/README.txt b/etc/README.txt new file mode 100644 index 000000000..6b55e7519 --- /dev/null +++ b/etc/README.txt @@ -0,0 +1,9 @@ +To generate the sample neutron LBaaS configuration files, run the following +command from the top level of the neutron LBaaS directory: + +tox -e genconfig + +If a 'tox' environment is unavailable, then you can run the following script +instead to generate the configuration files: + +./tools/generate_config_file_samples.sh diff --git a/etc/oslo-config-generator/lbaas_agent.ini b/etc/oslo-config-generator/lbaas_agent.ini new file mode 100644 index 000000000..de2dec1a3 --- /dev/null +++ b/etc/oslo-config-generator/lbaas_agent.ini @@ -0,0 +1,6 @@ +[DEFAULT] +output_file = etc/lbaas_agent.ini.sample +wrap_width = 79 + +namespace = neutron.lbaas.agent +namespace = oslo.log diff --git a/etc/oslo-config-generator/neutron_lbaas.conf b/etc/oslo-config-generator/neutron_lbaas.conf new file mode 100644 index 000000000..1641831a7 --- /dev/null +++ b/etc/oslo-config-generator/neutron_lbaas.conf @@ -0,0 +1,5 @@ +[DEFAULT] +output_file = etc/neutron_lbaas.conf.sample +wrap_width = 79 + +namespace = neutron.lbaas diff --git a/etc/oslo-config-generator/services_lbaas.conf b/etc/oslo-config-generator/services_lbaas.conf new file mode 100644 index 000000000..4094d9db6 --- /dev/null +++ b/etc/oslo-config-generator/services_lbaas.conf @@ -0,0 +1,5 @@ +[DEFAULT] +output_file = etc/services_lbaas.conf.sample +wrap_width = 79 + +namespace = neutron.lbaas.service diff --git a/neutron_lbaas/opts.py b/neutron_lbaas/opts.py new file mode 100644 index 000000000..97ca68390 --- /dev/null +++ b/neutron_lbaas/opts.py @@ -0,0 +1,91 @@ +# 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 itertools + +import neutron.agent.common.config +import neutron.agent.linux.interface +import neutron.services.provider_configuration + +import neutron_lbaas.agent.agent +import neutron_lbaas.common.cert_manager +import neutron_lbaas.common.cert_manager.local_cert_manager +import neutron_lbaas.common.keystone +import neutron_lbaas.drivers.common.agent_driver_base +import neutron_lbaas.drivers.octavia.driver +import neutron_lbaas.drivers.radware.base_v2_driver +import neutron_lbaas.extensions.loadbalancerv2 +import neutron_lbaas.services.loadbalancer.agent.agent_manager +import neutron_lbaas.services.loadbalancer.drivers.haproxy.jinja_cfg +import neutron_lbaas.services.loadbalancer.drivers.haproxy.namespace_driver +import neutron_lbaas.services.loadbalancer.drivers.netscaler.netscaler_driver +import neutron_lbaas.services.loadbalancer.drivers.radware.driver + + +def list_agent_opts(): + return [ + ('DEFAULT', + itertools.chain( + neutron_lbaas.agent.agent.OPTS, + neutron_lbaas.services.loadbalancer.agent.agent_manager.OPTS, + neutron.agent.linux.interface.OPTS, + neutron.agent.common.config.INTERFACE_DRIVER_OPTS) + ), + ('haproxy', + neutron_lbaas.services.loadbalancer.drivers.haproxy. + namespace_driver.OPTS) + ] + + +def list_opts(): + return [ + ('DEFAULT', + neutron_lbaas.drivers.common.agent_driver_base.AGENT_SCHEDULER_OPTS), + ('quotas', + neutron_lbaas.extensions.loadbalancerv2.lbaasv2_quota_opts), + ('service_auth', + neutron_lbaas.common.keystone.OPTS), + ('service_providers', + neutron.services.provider_configuration.serviceprovider_opts), + ('certificates', + itertools.chain( + neutron_lbaas.common.cert_manager.cert_manager_opts, + neutron_lbaas.common.cert_manager.local_cert_manager. + local_cert_manager_opts) + ) + ] + + +def list_service_opts(): + return [ + ('radware', + neutron_lbaas.services.loadbalancer.drivers.radware.driver. + driver_opts), + ('radwarev2', + neutron_lbaas.drivers.radware.base_v2_driver.driver_opts), + ('radwarev2_debug', + neutron_lbaas.drivers.radware.base_v2_driver.driver_debug_opts), + ('netscaler_driver', + neutron_lbaas.services.loadbalancer.drivers.netscaler. + netscaler_driver.NETSCALER_CC_OPTS), + ('haproxy', + itertools.chain( + neutron.agent.common.config.INTERFACE_DRIVER_OPTS, + neutron_lbaas.agent.agent.OPTS, + neutron_lbaas.services.loadbalancer.drivers.haproxy. + namespace_driver.OPTS, + neutron_lbaas.services.loadbalancer.drivers.haproxy.jinja_cfg. + jinja_opts) + ), + ('octavia', + neutron_lbaas.drivers.octavia.driver.OPTS) + ] diff --git a/releasenotes/notes/config-file-generation-cddf85d9d4022e2d.yaml b/releasenotes/notes/config-file-generation-cddf85d9d4022e2d.yaml new file mode 100644 index 000000000..cb4b1cb13 --- /dev/null +++ b/releasenotes/notes/config-file-generation-cddf85d9d4022e2d.yaml @@ -0,0 +1,7 @@ +--- +prelude: > + Generation of sample Neutron LBaaS configuration files. +features: + - Neutron LBaaS no longer includes static example configuration files. + Instead, use tools/generate_config_file_samples.sh to generate them. + The files are generated with a .sample extension. diff --git a/setup.cfg b/setup.cfg index ac4874619..6edb29b3c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,6 +54,10 @@ neutron.db.alembic_migrations = neutron_lbaas.cert_manager.backend = barbican = neutron_lbaas.common.cert_manager.barbican_cert_manager local = neutron_lbaas.common.cert_manager.local_cert_manager +oslo.config.opts = + neutron.lbaas = neutron_lbaas.opts:list_opts + neutron.lbaas.agent = neutron_lbaas.opts:list_agent_opts + neutron.lbaas.service = neutron_lbaas.opts:list_service_opts [build_sphinx] all_files = 1 diff --git a/tools/generate_config_file_samples.sh b/tools/generate_config_file_samples.sh new file mode 100755 index 000000000..6b0f4ec2e --- /dev/null +++ b/tools/generate_config_file_samples.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# +# 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 -e + +GEN_CMD=oslo-config-generator + +if ! type "$GEN_CMD" > /dev/null; then + echo "ERROR: $GEN_CMD not installed on the system." + exit 1 +fi + +for file in `ls etc/oslo-config-generator/*`; do + $GEN_CMD --config-file=$file +done + +set -x diff --git a/tox.ini b/tox.ini index 027624af1..7e4d28615 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,7 @@ deps = commands = flake8 neutron-db-manage --subproject neutron-lbaas --config-file neutron_lbaas/tests/etc/neutron.conf check_migration + {[testenv:genconfig]commands} whitelist_externals = sh [testenv:i18n] @@ -101,3 +102,6 @@ passenv = TEMPEST_CONFIG_DIR setenv = OS_TEST_PATH={toxinidir}/neutron_lbaas/tests/tempest/v2/ddt OS_TESTR_CONCURRENCY=1 + +[testenv:genconfig] +commands = {toxinidir}/tools/generate_config_file_samples.sh