summaryrefslogtreecommitdiff
path: root/tests/test_cfg.py
Commit message (Collapse)AuthorAgeFilesLines
* Remove oslo namespace packageDoug Hellmann2015-07-131-3538/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix use of mock for 1.1.0Doug Hellmann2015-07-121-3/+3
| | | | | | | | | 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
* Expose min and max to IntOptEric Brown2015-07-071-0/+13
| | | | | | | | | | | | | | | | | 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
* cfg: support interpolation of config option from other groupsJulien Danjou2015-05-111-5/+2
| | | | | | | This patch adds support for config variable interpolation with values coming form… other groups than the current/default one! Change-Id: Iddd21aa2da71fe332868049d4b94b75b562b61cd
* Update hacking to kilo levelDoug Hellmann2015-04-031-1/+1
| | | | | | | Update the hacking requirement to the version used by kilo, and fix code that fails the new tests. Change-Id: I6e18878e4ba826528af82438f4e4394cc644d623
* Clear up MultiStrOpt and related documentation1.6.1Ian Wienand2015-02-121-0/+17
| | | | | | | | | | | | | | | | | | | | | | For a person entering documentation wondering what MultiStrOpt semantics are, the existing documentation isn't much help. Without an explanation of its parent class MultiOpt, MultiStringOpt doesn't make much sense. The "kept for backwards-compatibility" is also rather confusing as it makes not mention why. This adds MultiOpt to the documentation and explains its role. I couldn't see where it was being tested at all, so some minimal test-cases are added for MultiOpt. The other options are brought into line with the updated MultiStrOpt, giving a link to the type they pass to Opt() and a better backwards-compatibility message. The Option Types section is also clarified a bit, and includes links to relevant places. Change-Id: Iae65ffd31e7319938f03d120b3ed3ad55f2dbcaf
* Fix of wrong cli opts unregistrationMike Fedosin2015-01-061-10/+29
| | | | | | | | | This code allows to unregister a cli option by passing to the method any Opt object with 'dest' field and not exactly the one that was used during creation. Change-Id: Icebbf3ce2bdf0d2deae9b057bd70ab706aad820e Closes-Bug: 1407950
* Move files out of the namespace packageDoug Hellmann2014-12-121-46/+3
| | | | | | | | | | Move the public API out of oslo.config to oslo_config. Retain the ability to import from the old namespace package for backwards compatibility for this release cycle. bp/drop-namespace-packages Change-Id: I56274336802036de050efc62eb2ee6b5d4ede77b
* Merge "Fix wrong order of positional args in cli"Jenkins2014-12-041-0/+56
|\
| * Fix wrong order of positional args in cliMike Fedosin2014-12-041-0/+56
| | | | | | | | | | | | | | | | | | | | | | Positional arguments were incorrectly parsed because instead of original order there was an alphabetical. This patch brings a positional field in Opt class and then sorts all arguments by position-name. Change-Id: Ia22654442b895c3f62834428f0ec6c3e8af22ebb Closes-Bug: 1392428
* | add tests coverage for an oslo.messaging use caseMehdi Abaakouk2014-11-271-0/+39
|/ | | | | | | | | This change adds tests to checks the behavior when an option in two groups shares the same deprecated group. oslo.messaging usage: https://review.openstack.org/#/c/120038/ Change-Id: I47b4fae15bc6f4581b513e9c10a564f4f4a88e2f
* Merge "delay formatting debug log message"Jenkins2014-10-131-2/+5
|\
| * delay formatting debug log messageDoug Hellmann2014-10-081-2/+5
| | | | | | | | | | | | | | Pass arguments to the logger and let it assemble the formatted message if it will be emitted. Change-Id: I2cf66dcc98bb2324f34442e51e47691ec445d280
* | Merge "Check config default value is correct type"Jenkins2014-10-131-22/+18
|\ \ | |/
| * Check config default value is correct typeTom Cammann2014-10-081-22/+18
| | | | | | | | | | | | | | | | | | | | | | Given a type of Opt, check that the default value supplied to the Opt is of the same type as the Opt. E.g. cfg.StrOpt('user_attribute_ignore', default=99) will log a warning as the default is not of type string. Closes-Bug: 1261792 Change-Id: I12cd5f4be82ac5ed0ebb348b358dd8eaf04e4e0d
* | Report permission denied when parsing configRyan Moore2014-10-081-1/+14
|/ | | | | | | | Previously was returning ConfigFilesNotFoundError, when underlying error was 13 - Permission Denied Change-Id: I2c418f023c510205aa12a3acb9b09e6b1681f0d4 Closes-Bug: #1071799
* Looks for variable subtitution in the same groupMehdi Abaakouk2014-09-101-0/+47
| | | | | | | | | | | | When we do a variable subtitution we must try to look if the option is avialable into the same group and then into the default one for backward compatibilty. Otherwise variable subtitution doesn't works when we change the group of an option and deprecated the DEFAULT group. Change-Id: Ie5750ee028a58fba6da225a8c4b4221e23db829f Closes-bug: #1367790
* Log a fixed length string of asterisks for obfuscationZhongyue Luo2014-08-051-1/+1
| | | | | Change-Id: I98e95dbc92712bebb18dcf0d29af7cfe7f2c8124 Closes-bug: #1341774
* Changes imports order to pass H305, enables checkPetr Blaho2014-07-091-1/+1
| | | | | | | Changes imports order to pass H305 check with hacking 0.9.x Removes H305 check from ignore line in tox.ini Change-Id: I47bbe74f4178f46ea21fc37b69f53ea2d148a65e
* Introduce Opts for IP addressesJakub Libosvar2014-06-301-0/+20
| | | | | | | | | | | | In order to validate correct input values for IP addresses new Opt was introduced. Validation is done on parsing level so there is no need to explicitly check for valid ip address in the code. Requirement for netaddr package was added. DocImpact Change-Id: I9adc30d9b989e8c636fefd435885c4c363ca540c Partial-Bug: #1284684
* Merge "Add more tests for positional CLI opts"Jenkins2014-06-191-1/+28
|\
| * Add more tests for positional CLI optsMark McLoughlin2014-06-161-1/+28
| | | | | | | | | | | | | | Add tests to ensure that e.g. default=None, default=[], etc. works as expected. Change-Id: I66f5df6e622a66faa1d00ee0846cbec5eb119283
* | Add test case for hyphenated option namesMark McLoughlin2014-06-151-1/+128
|/ | | | | | | | Add some tests to show the broken behaviour in #127993 and to help ensure that fixing it doesn't break correct behaviour in other places. Related-Bug: #1279973 Change-Id: I69b2c4e3f27a3e193ca10cef32dd752d6a6fcc8b
* Fix deprecated_opts for cli optionsYAMAMOTO Takashi2014-05-071-0/+44
| | | | | | | | | | | | | | | | | | | | The following simple program raises DuplicateOptError. This commit fixes it. oslo.config.cfg.DuplicateOptError: duplicate option: argument --bar-foo: conflicting option string(s): --bar-foo from oslo.config import cfg conf = cfg.ConfigOpts() oldopts = [ cfg.DeprecatedOpt(name='oldfoo', group='oldbar'), ] conf.register_cli_opt(cfg.StrOpt(name='foo', deprecated_opts=oldopts), group='bar') conf() Change-Id: I022ed0236de97db42568106bc90c696732a05ef2 Closes-Bug: #1283960
* Reject option names prefixed with '_'YAMAMOTO Takashi2014-05-021-0/+3
| | | | | | | Such names are used for _Namespace's internal purposes. Change-Id: I08c24f05ec3ef626b253ca3682439c1a162959e5 Related-Bug: #1284969
* Fix test_version on Python 3.4Cyril Roelandt2014-04-251-2/+9
| | | | | | | | | | Since Python 3.4, argparse has been printing the version on stdout rather than on stderr as it used to. We should fix this now because: - this is an issue when packaging oslo-config in Debian Sid, which uses Python 3.4; - it will be needed when Openstack switches to 3.4 anyway. Change-Id: I6a84009acb8621d62465c4cd2573200a07b6b4ab
* Do substitution on overrides and defaults tooBen Nemec2014-02-281-0/+18
| | | | | | | | | | Some of our consuming projects are setting defaults or overrides on config objects that look like $state_path/some/file and we're no longer handling that correctly since commit 2422d4118c97734067ea0b37ae159bc2e3c492c5 Change-Id: I4324bda6f3de3cdf05f8eb3cf16052c04018dec8 Closes-Bug: #1282250
* Convert to oslo.testJonathan LaCour2014-02-241-5/+5
| | | | | | bp graduate-oslo-test Change-Id: I7769934c2ebce46f9f364bab1a34be95f7452f49
* Remove extraneous vim configuration commentsllg82122014-02-131-2/+0
| | | | | | | | | Remove line containing comment - # vim: tabstop=4 shiftwidth=4 softtabstop=4 Change-Id: I6e486876d5743bfbfb3a93c89f6da81c32d22ffd Closes-Bug:#1229324
* Throw exception if --config-dir doesn't existJay S. Bryant2014-01-271-20/+34
| | | | | | | | | | | | | | | | | | | Currently an invalid --config-dir option is silently ignored. This means that a user could accidentally enter the wrong directory or have a typo which would cause the desired config files to not be used and no indication of the error would be produced. This change adds a ConfigDirNotFoundError exception that can be raised when the requested --config-dir isn't found. While working out the unit tests for this it was discovered that the test_config_dir_tilde test case was not correct. It could still pass when it should fail. This commit includes a fix for that issue as well. Closes-bug: 1255354 Change-Id: I386b2419d04572b14ccf11b527f871a237304e53
* Merge "Implemented support for custom opt types"Jenkins2014-01-221-0/+111
|\
| * Implemented support for custom opt typesMaxim Kulkin2014-01-161-0/+111
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Motivation: Currently oslo.config supports only basic set of types: strings, integers, floats, booleans, lists of strings and dictionaries of strings. The reason of existence of types other than string is to provide some kind of value validation (e.g. that integer contains only digits). There is a demand in community to have more complex value checks, e.g. that a port configuration option contains integer value that fits in certain range, host ip address conforms to ip address format, etc. Solution: This patch introduces support for custom Opt types that will allow a better control of value conversion and validation. Custom types are presented as type constructors - callable objects that take a string and either return converted value or raise ValueError in case value can't be converted. This concept is similar to argument types in 'argparse' library. Type constructor can be a class which instances are callable, a function or any callable object (which allows usage of parametriezed type class instances). Details: Oslo.config has Opt subclasses that control value conversion and validation: StrOpt, IntOpt, FloatOpt, etc. The type information is added to the base class - Opt - cause otherwise it would introduce confusion on what class to use when introducing e.g. NetworkPort: StrOpt or IntOpt. For each existing Opt subclass a corresponding type was implemented (see oslo.config.types). StrOpt, IntOpt, etc. classes are left for backward compatibility and present an Opt class parametrized with particular type. There are two exceptions of this rule: BoolOpt and MultiStrOpt. Those classes define a special logic for parsing values. BoolOpt was left unchanged and should be used when someone wants a Boolean option that is available through CLI. MultiStrOpt has logic to accumulate values. As it was bound to String type only, it's logic was extracted into a MultiOpt class and MultiStrOpt was left as a subclass parametrized with String type. Opt values allow value substitution. Previously it worked only for string types but now this feature only makes sense if it would work on any type. _substitute() and _do_get() methods of ConfigOpts class were updated to cover that. Also, TemplateSubstitution tests were updated to ensure that substitution is done before type conversion kicks in or otherwise type conversion will fail (e.g. if Integer type converted will get something like '$listen_port'). Advised review steps: 1. New type classes (oslo/config/types.py) and their tests (tests/test_types.py); 2. Changes to Str/Bool/Int/etc-Opt classes (those are pretty straight forward); 3. Other changes that add support for new types into existing infrastructure; 4. New cfg test cases added (mostly related to changes in substitution mechanics). blueprint oslo-config-options-validation Change-Id: I6910f1efa540cfe757b2be6da0aec072f8ed28fa
* | Merge "Fix for parsing error with Dollar Sign ($) in values"Jenkins2014-01-111-0/+24
|\ \
| * | Fix for parsing error with Dollar Sign ($) in valuesDavanum Srinivas2014-01-071-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Python String template uses '$$' as an escape when a '$' is required in the value. So add a test case to make sure that works. Many users end up trying a backslash to escape as well, let's add support and a test case for that as well DocImpact Change-Id: I403cc98505a95f633b5f29ba8f819a2e9c7d58a6 Closes-Bug: #1259729
* | | Utilizes assertIsNone and assertIsNotNoneZhongyue Luo2014-01-031-21/+21
|/ / | | | | | | | | | | | | | | | | Using assertEqual/assertNotEqual to test if an element is or is not None is too python2.4. Our unit testing framework supports assertIsNone and assertIsNotNone which were created for these types of tests. Change-Id: I969ee943e31b4fa0291f6cb9e21e2f654e88e66e
* | Added support of operator '=='Lianhao Lu2013-12-191-0/+13
|/ | | | | | | Implemented method __eq__ for cfg.Opt. Change-Id: Ia6a3d82d19b7d239ffc0b42a47e1ce7383f10564 Partial-Bug: 1262148
* Fix to make ConfigOpts no longer obscure IOErrorsLars Butler2013-11-011-0/+13
| | | | | | | | | | | | | | This changes ConfigParser._parse_file such that it no longer interprets all IOErrors as 'No such file or directory', and instead allows these errors to propagate normally. The current behavior with respect to ConfigOpts does not change for IOErrors indicating 'No such file' or 'Permission denied'. Also added a test to exercise the case where IOErrors are reraised. The 'No such file' case is already covered by existing tests. Change-Id: I10e4e5965212737a19f4f17153143f62b5c0c83e Closes-Bug: #1244674
* Replace assertEquals with assertEqualZhongyue Luo2013-10-231-12/+12
| | | | | | | | | The method assertEquals has been deprecated since python 2.7. http://docs.python.org/2/library/unittest.html#deprecated-aliases Also in Python 3, a deprecated warning is raised when using assertEquals. Change-Id: I04dfff271ddadaa0e5499d443948acd984ed998b
* Add the ability to validate default options valueJulien Danjou2013-10-091-1/+36
| | | | | | | | | | | | | | | | | | | Currently, the default options value provided are not validated, which can trigger fun things like a IntOpt having a "foobar" as default value, with code failing later when the option is being used. This patch introduces a _validate_value method that can be used to validate the default value to the expected type. ConfigOpts.__call__ gains a validate_default_values arguments that can trigger default value validation. The argument is False by default in order to not break existing code. Ultimately, we could in a later version validate the default at Opt object creation time, which would be much better, but that may break existing code, so we'll see. Change-Id: I6c1998a3be3f1579139317cd85d56b42cabf89db
* Fix subparsers add_parser() regressionMark McLoughlin2013-09-251-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | With SubCommandOpt, the handler() callback gets invoked with a subparsers object which has a add_parser() method. The arguments to this method match the arguments to the ArgumentParser constructor and the arguments are passed to the class for our ArgumentParser instance. However, we added a ArgumentParser subclass (_CachedArgumentParser) so that we could sort the output of --help ... but the subclass doesn't support all the arguments of the parent class. glance-control is the only known example of a SubCommandOpt user which passes unusual arguments to subparsers.add_parser(). It uses the parent arg and blows up at startup with: File "./bin/glance-control", line 276, in add_command_parsers parser = subparsers.add_parser(server, parents=[cmd_parser]) File "/usr/lib64/python2.7/argparse.py", line 1064, in add_parser parser = self._parser_class(**kwargs) TypeError: __init__() got an unexpected keyword argument 'parents' It appears we broke glance-control back in June (commit 2951391), but nobody noticed it until 1.2.0 was released and broke stable/grizzly because we stopped using glance-control in the Havana glance unit tests before this regression. Closes-Bug: #1230416 Change-Id: I8d1b52e5390295726eb49af32eb7cab14c29592c
* Raises error if duplicate keys found in DictOptZhongyue Luo2013-09-231-0/+24
| | | | | | | | | | | | DictOpt didn't report when the input values had duplicate keys. This would be a problem if the user had put in duplicate keys in the conf file and the service didn't work as expected. (c.f) Neutrons provider network mapping options This patch raises a ConfigFileValueError when duplicate keys are found. Fixes bug #1228995 Change-Id: I91e1bd0eda4ed4fd6c7eb6ea5d4a89d583d1305e
* Fix DictOpt to split only the first colonZhongyue Luo2013-09-171-0/+12
| | | | | | | | | | | | I've encountered a ValueError when adapting DictOpt to neutron's network_vlan_ranges. https://github.com/openstack/neutron/blob/master/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini#L23 This patch makes dictopt to split only the first colon for every value Fixes bug #1223667 Change-Id: Iee4011f2a45be933dad393c72df099d6a8116849
* Fix first param in __eq__ impl to be self1.2.0a4Davanum Srinivas2013-08-181-0/+13
| | | | | | | first parameter of a method should be named 'self'. Added a test case as well Change-Id: I03a993a9f84af354dcf7e358ed0e5e126eda48af
* Add auto-create support for OptGroup instancesFlaper Fesp2013-08-141-6/+11
| | | | | | | | | | | | | | | | | | | | | Currently, it is possible to auto-create groups by passing a group name to register_opt or register_opts. However, it is not possible to auto-register groups when a OptGroup instance is passed instead. This patch adds support for that to the _get_group method. There are some advantages introduced by this patch: * It keeps consistency of oslo.config's public API. * It allow users to auto-register a group a group and re-use the instance: group = cfg.OptGroup("test") cfg.register_opts(..., group=group) # do something with the group * It allows users to auto-register groups with descriptions. DocImpact Change-Id: I9b9a74688c906d6bdea9c42044b47dc52e48c19d
* NoSuchOptError should be used not AttributeErrorDavanum Srinivas2013-08-011-0/+1
| | | | | | | | | Switch back to previous behavior. Looks like we are missing a test to enforce the old behavior that everyone depends on Fixes LP# 1207541 Change-Id: I79c58cfcf619a461f6a42a4dccfa9141bc1033a0
* Fixes six importsZhongyue Luo2013-07-281-2/+2
| | | | Change-Id: I4ee63d990bf95d74cadd1d65ad75f7fe26cc8fbd
* Add Python 3 supportJulien Danjou2013-07-161-5/+11
| | | | | | | These are the final changes needed to have the full py33 tox environment running and passing all tests. Change-Id: I3ac149345561a5bb99e017022ba2e2be10154584
* Raise an exception when _oparser is not initializedDavanum Srinivas2013-07-111-0/+17
| | | | | | | | | | Throw an exception when print_help and print_usage are called before __call__() is invoked on ConfigOpts object Fixes LP# 1196601 Change-Id: I2c3b412c5aa9adef87a92103b9749cc66158a3e4
* Merge "Add reload_config_files function"Jenkins2013-06-241-0/+99
|\
| * Add reload_config_files functionFengqian.Gao2013-06-241-0/+99
| | | | | | | | | | | | | | | | | | Add reload_config_files function for ConfigOpts instance to reload all configuration files. Implements blueprint cfg-reload-config-files Change-Id: Ia4d96be170d1ddfaa70b8e467b9a19ed45dc4060