72 Commits

Author SHA1 Message Date
Doug Hellmann
b270375dd8 Demonstrate that MultiStr values from multiple sources are merged
Add a test to show that when we encounter the same MultiStrOption in
several sources, the values are merged into one list.

Related-Bug: #1490990
Change-Id: Ie0324572191f084a3646d8bfb1d214d14221244d
2015-09-14 18:03:50 +00:00
John L. Villalovos
85eee67b99 Make Integer type class honor zero for min/max
The Integer type class has an option for setting a min or max value for the
integer. But the class would not recognize zero as a valid value and not
check it.

Make the Integer class honor zero as a valid value for min and/or max.

Add test cases for using zero for min and/or max.

Change-Id: I395dea133d2a92e5ca4fab913aa17483a38f7ba1
Closes-Bug: #1489688
2015-08-27 20:38:19 -07:00
Doug Hellmann
bc13758bd6 Add sphinx extension to embed pretty descriptions of options
Add a new `show-options` directive for use in sphinx documentation to
embed the help and metadata about options in the output of the rendered
docs.

Change-Id: I549c8db98bf548dd0a7e8869a57301fa4096f78c
2015-08-22 16:58:38 +00:00
Matthew Treinish
006415f41b
Add sphinx extension to build sample config
This commit adds a sphinx extension which can be loaded in a sphinx
config.py to generate a sample config file using oslo-config-generator
during each sphinx build. This can then be incorporated into
documentation as necessary.

Co-Authored-By: Doug Hellmann <doug@doughellmann.com>
Change-Id: I2561155749fc8c6a8e31df1614ca6cdb50b4c001
2015-08-11 10:18:40 -04:00
Markus Zoeller
257de47935 preserve preformatted help text
The config options are an interface to a subset of users. These users
need to read and understand the help text of the options. To make it
easier to read, it should be possible to preformat the text. This
patch set keeps the preformat with line breaks.

Change-Id: I8aa871001f7da3cefcd9aa93992d50d0d9140157
2015-07-24 18:38:50 -05:00
Jenkins
ac505d83e4 Merge "Add enforce_type option when setting an override" 2015-07-24 18:39:53 +00:00
Jenkins
868281b41c Merge "Add regex validation to String type" 2015-07-20 22:08:33 +00:00
Chris St. Pierre
3f7b642c60 Add regex validation to String type
This lets you specify a regex that string options must match
(unanchored).

Change-Id: I0be613ee38a4752b135de5ee7f189621670d1071
2015-07-20 11:50:36 -05:00
Roxana Gherle
67c3abb048 Add enforce_type option when setting an override
The 'override' value of an option is currently stored and retrieved
with the exact value that is set through set_override method - not
taking into account the type of that option. Sometimes we want the type
of the override value to be the same as the option type and therefore
we will add an optional parameter to the set_override method that will
enforce the option value type.

Closes-Bug: #1461299
Change-Id: I008b76d3292f76d0699f0063930a3b190539740f
2015-07-17 12:50:12 -07:00
Doug Hellmann
59fd48b3f0 Remove oslo namespace package
Blueprint remove-namespace-packages

Depends-on: I77e50f2f14345321d1b5319343c5872a92977936
for openstack/murano-agent
Depends-on: If51059c31c82d5235e2ae21143911b5561783ca6
for openstack/os-collect-config
Depends-on: I324ca86a21c27ce43cebf255b3c075b8fe110820
for openstack/sahara-dashboard
Depends-on: Icfc882db41883410f7b40fc5a22bfaae1a65dedc
for openstack/tempest
Depends-on: I396a64aa7610b5fcc0bab05bff442ae6b43c6164
for openstack/congress
Depends-on: I749f43bd6dc15717154475cc1a776ffd6164b7fa
for openstack/octavia
Depends-on: I892c0b64ff6bab666f1f23f5e7aeb2da088ea087
for stackforge/python-solumclient
Depends-on: I09b3bec4c68c7fe9379b3d5fefbceaa86ffe994e
for openstack/congress

Related fixes for projects that can't build for other reasons:
I7d35c85926c8f098e2e47051ff44b714478df1b7 for stackforge/magnetodb

needed for the gate:
Depends-On: I0f07858e96ea3baf46f8a453e253b9ed29c7f7e2
Depends-On: I33bd2d9dff9cb7dc1a50177db7286b7317966784

Change-Id: Ibe16f8d7f73234845cab94c8e351f41954eecb0a
2015-07-13 22:23:36 +00:00
Doug Hellmann
061ab83996 Fix use of mock for 1.1.0
Correctly assert the number of calls to a mocked method.

Combine this with the change to pin the version of mock used for python
2.6 and raise the minimum version of mock used elsewhere.

Change-Id: I8cf1936f06f489561a59ec3cc75a1a8d6419a9ef
2015-07-12 19:03:45 +00:00
Jenkins
781868f2da Merge "Expose min and max to IntOpt" 2015-07-09 18:11:55 +00:00
Eric Brown
366ca45ef2 Expose min and max to IntOpt
The IntOpt class utilizes the types.Integer class which has
parameters for setting the minimum and maximum value.  These min
and max values are not exposed through IntOpt and should be ideally.

In the docstring help for cfg.py, it gives an example of creating a
PortType instance of types.Integer to create a new type with a range.
Rather than projects having to define this new instance, seems better
to just expose the min and max to IntOpt.

Another advantage of adding min and max to IntOpt is the ability to
generate a useful sample config file that displays the range of
valid integer values.

Change-Id: Icce7b6799061711ea512d60facc57bf7d6f6c9cc
2015-07-07 00:12:11 -07:00
ChangBo Guo(gcb)
2576dd3eb1 Don't convert ValueError into NoSuchOptError in ConfigOpts
In method __getattr__ of ConfigOpts, we catch all exceptions and convert
it to NoSuchOptError. This is wrong, we need allow raise ValueError to
provide more details about the error.

Change-Id: Ic08b812424ff9ad79f03a9069877b610fcbd4172
Closes-Bug: #1471149
2015-07-03 16:54:10 +08:00
Jenkins
985ac6257b Merge "Add set_default() method to fixture" 2015-07-01 09:25:51 +00:00
Jenkins
239cbdd471 Merge "Fixes example for cfg" 2015-07-01 02:38:28 +00:00
Doug Hellmann
427de804c3 Add set_default() method to fixture
Add a set_default() method to the fixture to allow it to be passed to
set_default() functions in other oslo libraries that expect to be given
a ConfigObj instance. This lets tests in one project use a fixture to
set defaults for options in code they don't own, and unset those
defaults when the test is cleaned up.

Change-Id: Ifa9e6e2ab4ab4f93a7dc22d786ee6fd6ae7224ae
2015-06-30 21:40:55 +00:00
Doug Hellmann
d86fd9b03f fix fixture tests for fixtures 1.3.x
The latest releases of fixtures do not allow a fixture to be cleaned up
more than once, so rewrite the fixture tests to manage the fixture by
hand and not clean it up unless that is part of the test being run.

Change-Id: I1e2aaa59e713eca231a315860ef84bc272bbe280
2015-06-30 20:25:09 +00:00
liyingjun
abd4a76cd0 Fixes example for cfg
`type=PortType()` should be `type=PortType` in the example of cfg module

Change-Id: I1e1449e1853fe48a280964b2b69cb2e6c283dda3
Closes-bug: #1468481
2015-06-25 19:43:58 +08:00
Ilya Shakhat
40676e2c74 Fix sorting of optional arguments
When there are no positional arguments only N-1 arguments
were sorted. The original unit test covered this case, but
had no luck to catch the issue.

Closes bug 1466061

Change-Id: I54ac8d5b6b20dd42b6c49873e5b0000fe7b92057
2015-06-17 14:53:05 +03:00
Jenkins
11cc8fa98b Merge "Fix typo in Opt class doc string" 2015-06-10 01:15:15 +00:00
Thomas Herve
0c9113f682 Fix sorting issue in python 3
Fix an error appear when trying to sort options when having many options
and many groups in python 3.4.

Change-Id: Iec7447e004f3708d92bd30aad94a17378fc25f31
Closes-Bug: #1463025
2015-06-08 16:26:16 +02:00
LingxianKong
a62654a4f5 Fix typo in Opt class doc string
s/iff/if

Change-Id: Ie8d7b0b2a51ebd0c8618896d0b72fda7fe923aae
2015-06-02 14:40:16 +08:00
Brant Knudson
5f62407025 Document properties as properties
Sphinx has a directive for python object properties (it calls them
attributes)[1]. This should be used for properties since then they
can be referenced.

[1] http://sphinx-doc.org/domains.html#directive-py:attribute

Change-Id: I8c022356f88a21f5a79f1b1c0ae6e315a76d3f3b
2015-05-25 19:56:11 -05:00
Tong Damon Da
f1f972aeb7 make registering a cli opt on a filter object work.
Change the behaviour of ConfigFilter.register_cli_opt to:

1. If the opt is already registered before parsing, then registering
just import it.
2. if the opt is not registered before, then raise an exception named

CliOptRegisteredError.
By adding this modification, the behaviour of
ConfigFilter.register_cli_opt looks more consistent to
ConfigOpts.register_cli_opt. The solution to the question mentioned in
Bug#1366946 should be like this:

from oslo_config import cfg
from oslo_config import cfgfilter

import sys

c = cfg.CONF
c.register_cli_opt(
cfg.BoolOpt('myflag',
default=False,
help='turn on myflag',
)
)
c(sys.argv[1:])

f = cfgfilter.ConfigFilter(c)
f.register_cli_opt(
cfg.BoolOpt('myflag',
default=False,
help='turn on myflag',
)
)

print f.myflag

Closes-Bug: #1366946
Change-Id: I94df9409f72807461370b4aaf8eb2543c52a89bb
2015-05-23 12:39:12 +08:00
Jenkins
8aa2947ef6 Merge "Allow loading custom config files into Config Fixture." 2015-05-12 20:02:20 +00:00
Jenkins
84a8666279 Merge "Fix logging of deprecated opts with dest override" 2015-05-12 19:57:08 +00:00
Julien Danjou
a5afcc22aa cfg: support interpolation of config option from other groups
This patch adds support for config variable interpolation with values
coming form… other groups than the current/default one!

Change-Id: Iddd21aa2da71fe332868049d4b94b75b562b61cd
2015-05-11 16:33:20 +02:00
Paul Belanger
21d05c0757 Fix issue when generating code with cfg.OptGroup
There seems to be an issue when using oslo-config-generator with
cfg.OptGroup.  It seems the generator was not checking if the group
was an object or not.  Resulting in section names as the following:

  [DEFAULT]

  [<oslo_config.cfg.OptGroup object at 0x325c350>]

Change-Id: I946d55fcd713369dda4cdf490391a75901bded22
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
2015-05-06 16:42:46 -04:00
Mark Vanderwiel
1c62e02af7 Option name missing from ConfigFileValueError
It's sometimes hard to find the option with a bad value.  In a
couple ConfigFileValueError cases, the option is not included in
the log message.

Change-Id: Ib373f5184b7339ebd59a6d7eb53f3b02a5d59f4f
Closes-Bug: #1451479
2015-05-04 11:22:03 -05:00
Ihar Hrachyshka
7b1e157aee Enforce alphabetic loading order for --config-dir contents
Deployers may want to rely on specific order of the files being loaded,
so we should make sure it's not changed, and that it's documented.

Note: test_config_dir already checks for the sorting order of
configuration files, so there is no need for a new test case.

Change-Id: Idc26b926601554b5592e13da92fbe81db99eb6e0
2015-04-17 16:02:08 +02:00
Michael Krotscheck
ba3aebe39b Allow loading custom config files into Config Fixture.
This patch adds a set_config_files option that allows a tester to
force load a specific list of configuration files. It will override the
existing set of files, and trigger a reload of those configuration
files.

Note: This _does_ trigger the autodetection mechanism, as the
present state of oslo_config makes it so __call__ is the only thing
that sets self._args. After triggering, however, it immediately
overrides the detected file list and replaces it with the provided one.

Tests provided.

Change-Id: I0bcea8be9d2527c61bd8d150e9ed606fabdd290e
2015-04-10 13:53:37 -07:00
Jenkins
3ab403925e Merge "Added Raw Value Loading to Test Fixture" 2015-04-10 20:12:11 +00:00
Jenkins
ec4b6a69cc Merge "Generate docs for constructor" 2015-04-10 16:41:43 +00:00
Jenkins
ef72ab4db1 Merge "Fix doc build warning" 2015-04-09 23:08:19 +00:00
Jenkins
e9fb0ba73f Merge "Add deprecated_for_removal support to the config generator" 2015-04-09 23:02:47 +00:00
Michael Krotscheck
e30131a1ef Added Raw Value Loading to Test Fixture
This patch adds a method by which raw key/value pairs may be
loaded into the test fixture, without them being registered
first. Tests have been provided.

Change-Id: I53d77e4782bf97aefee11edd489ff1c9ff6c69a3
2015-04-09 07:56:44 -07:00
Doug Hellmann
1e9033aa80 Update hacking to kilo level
Update the hacking requirement to the version used by kilo, and fix code
that fails the new tests.

Change-Id: I6e18878e4ba826528af82438f4e4394cc644d623
2015-04-03 13:55:07 +00:00
Ben Nemec
8ddd918096 Fix logging of deprecated opts with dest override
When a deprecated opt is used and the new opt name has the dest
property overridden, we were logging the dest property instead of
the actual opt name in the deprecation warning.  This is confusing
because it leads to log messages such as:

Option "username" from group "nova" is deprecated. Use option
"username" from group "nova".

This is nonsense.  In this case the proper new name was "user-name"
but because it had a dest override of "username" that's what was
logged.

Because the deprecation check code does not have access to the
actual opt itself, we need to pass the undeprecated name down from
the opt into the namespace code that does the check.

I also tried simply adding a (group, name) tuple to the beginning
of the names list, but this subtly broke the CLI opt tests because
there are specific combinations of - and _ variants expected, and
this seems to violate those assumptions.  I did not pursue it any
further because I felt it was better to simply be explicit about
the current name and not mess around with adding non-existent opt
names to the lookup list solely for logging purposes.

Change-Id: Ib1ea8ae2d60a9c508935bad27d7ddc2cdb5ab505
Closes-Bug: #1438314
2015-03-31 15:37:25 +00:00
Brant Knudson
abe1727330 Add deprecated_for_removal support to the config generator
When an option is deprecated for removal, the sample config file
should mention it, too.

Change-Id: Ide213b8c0783a128c7c4f7123d1cd2965588a81a
2015-03-30 20:16:00 -05:00
Brant Knudson
aa0a08b9b6 Generate docs for constructor
The docs for the class constructor parameters for several
classes weren't rendered because they were on the __init__
method, which sphinx doesn't render. When the docs are generated
for the class the __init__ parameters are shown after the class
name, so the parameters should be documented on the class where
they'll be rendered rather than on __init__.

Change-Id: I674ff76495aa4b30273083201f365bce790f447e
2015-03-30 20:04:16 -05:00
Brant Knudson
2761029c73 Fix doc build warning
Docs were generating warnings

 oslo_config/cfg.py:docstring of oslo_config.cfg.DeprecatedOpt:23: WARNING: Definition list ends without a blank line; unexpected unindent.
 oslo_config/cfg.py:docstring of oslo_config.cfg.DeprecatedOpt:25: ERROR: Unexpected indentation.

because the rst was invalid.

Change-Id: I273dcc8085019d13230dfce2f069863295282166
2015-03-30 19:49:34 -05:00
Jenkins
5a71eede79 Merge "Expand and clean up documentation for the config generator" 2015-03-28 05:52:03 +00:00
Davanum Srinivas
3c51838cdf Switch to non-namespaced module imports
Change-Id: I2758ec2fb4f8e17652b2ab047b8d4bdeb5cff31a
2015-03-12 07:11:09 -04:00
Davanum Srinivas
dc28858f35 print better message when choices has an empty string
Follow on to:
I3bb3621420915a6a2990440294a389b45a23c519

choices can have None (as a default) or an empty string "" (as a
default value or when read from a config file). We need to print
better message in the sample config for these two cases.

Change-Id: Iba483c0e4180fc95181b161f996cce5e627035f5
2015-03-10 00:35:32 +00:00
Davanum Srinivas
9db52476f6 None in config choices breaks oslo-config-generator
Tempest using StrOpt with choices
choices=[None, 'normal', 'direct', 'macvtap']

And oslo-config-generator does not like it. We need to
print "<None>" when we encounter None as a choice.

Closes-Bug: #1429981
Change-Id: I3bb3621420915a6a2990440294a389b45a23c519
2015-03-09 15:35:24 -04:00
Eric Brown
0f550d7c79 Generate help text indicating possible values
Since the introduction of choices, the help text does not indicate
possible values of these choices.  This patch adds to the help a
list of all values that are accepted.

Change-Id: I68edda59ad7a690918f8e45abe2b3b56cd01ada7
Closes-Bug: 1427913
2015-03-05 15:17:49 -08:00
Doug Hellmann
7da430b9f4 Expand and clean up documentation for the config generator
Add some section headings, clean up some of the formatting, and add
information about how to handle modules with optional dependencies.

Change-Id: I731fd7b191e834e22a99516f1b4b584bad6868fd
2015-03-05 17:35:40 -05:00
Jenkins
d1ccc438d6 Merge "Add ability to deprecate opts for removal" 2015-03-04 18:05:49 +00:00
Ben Nemec
dacc035719 Add ability to deprecate opts for removal
Previously opts could only be deprecated by renaming them, but there
are circumstances where we may want to remove an opt completely, and
we need a way to notify users before this happens.  This change adds
a deprecated_for_removal parameter to the Opt constructor that can
be used to mark opts for which this is planned.  When such opts are
referenced it will log a message, but only if the default value has
been overridden.

Change-Id: I0165895d58530f5fce58cbf8a1bbe2acd90e9063
2015-03-03 18:53:17 +00:00