summaryrefslogtreecommitdiffstats
path: root/tests/unit/test_cfg.py
Commit message (Collapse)AuthorAgeFilesLines
* Use oslo-config-2013.1b3Mark McLoughlin2013-02-171-1785/+0
| | | | | | | | | | | | | | | The cfg API is now available via the oslo-config library, so switch to it and remove the copied-and-pasted version. Add the 2013.1b3 tarball to tools/pip-requires - this will be changed to 'oslo-config>=2013.1' when oslo-config is published to pypi. This will happen in time for grizzly final. Remove the 'deps = pep8==1.3.3' and 'deps = pyflakes' from tox.ini as it means all the other deps get installed with easy_install which can't install oslo-config from the URL. Change-Id: I4815aeb8a9341a31a250e920157f15ee15cfc5bc
* Implements import_groupZhongyue Luo2013-01-311-0/+17
| | | | | | | | | Created import_group method in cfg.py Added testcases Fixes bug #1107843 Change-Id: I427d4069dacbb6e586687370adbb08b5d50f7b63
* Replaced direct usage of stubout with BaseTestCase.Monty Taylor2013-01-241-7/+4
| | | | | | | | BaseTestCase properly hooks stubout into fixtures. Just use that. Part of blueprint grizzly-testtools. Change-Id: I4bf6b92b9b16d051d8c6ecaf52cf70925848ed8c
* Use testtools as test base class.Monty Taylor2013-01-241-22/+16
| | | | | | | | | | | | | On the path to testr migration, we need to replace the unittest base classes with testtools. Replace tearDown with addCleanup, addCleanup is more resilient than tearDown. The fixtures library has excellent support for managing and cleaning tempfiles. Use it. Replace skip_ with testtools.skipTest Part of blueprint grizzly-testtools. Change-Id: I45e11bbb1ff9b31f3278d3b016737dcb7850cd98
* Move logging config options into the log moduleMark McLoughlin2013-01-211-56/+0
| | | | | | | | | | | | | | | | | | We learned a lesson in Nova - it's best to declare and use config options within a single module if possible. Globally declared and use config options grow like weeds and it becomes harder to find out if, where and how individual options are used. Strangely, in cfg itself, we randomly declare a bunch of logging options which are only used within the openstack.common.log module - let's move the options there and remove the CommonConfigOpts class before they become part of the API we commit to when oslo-config is released. A minor detail in the patch - the logfile and logdir options are already deprecated in favour of log_file and log_dir, but we never got around to removing all other traces of the deprecated options. Change-Id: I3913ea54465658d93dc56e014dfe5d911b0541d6
* Fixes import order errorsZhongyue Luo2013-01-181-1/+1
| | | | Change-Id: I3e35230dd2d96ab9f5a8c11b9ec1cd8d2d00e347
* Revert "Support lookup of value using "group.key""Mark McLoughlin2013-01-081-6/+0
| | | | | | | | | | | | | | | This reverts commit 525ac47. There are already two ways to reference an option in a group: CONF.group.key CONF[group].key Adding a third variant doesn't seem ideal. Also, for the specific case of LazyPluggable in Nova, we can easily just pass an optional config group name to the constructor. Change-Id: I1a29a18d90e8af3ce2563bd1b3eeb64422140016
* Support lookup of value using "group.key"Davanum Srinivas2013-01-021-0/+6
| | | | | | | | | | | | Let us check if the opt_name has a '.', if it does then split it into a group/key and try lookup using that combination. Since LazyPluggable uses "CONF[self.__pivot]" if we just add this capability to cfg, we get "LazyPluggable doesn't support option groups" for free. Fixes LP #1093043 Change-Id: I9cedcf22014038e9fe4ed5e66ca5427aa99b5091
* Merge "Add deprecated --logdir common opt"Jenkins2012-12-081-2/+11
|\
| * Add deprecated --logdir common optMark McLoughlin2012-12-071-2/+11
| | | | | | | | | | | | | | | | --logfile and --logdir are aliases Nova has for the --log-file and --log-dir. If we're to support --logfile as a deprecated common option, we should do the same for --logdir. Change-Id: I16485a93070d9ad7789a287d5b035c6f270ffead
* | Merge "Add deprecated --logfile common opt."Jenkins2012-12-071-0/+11
|\|
| * Add deprecated --logfile common opt.Dan Prince2012-12-061-0/+11
| | | | | | | | | | | | | | | | | | This adds a deprecated common options for --logfile which is an alias for --log_file. This resolves some backwards compatability issues with the most recent oslo common code where --logfile was no longer a valid opt. Change-Id: I17b1277da94a2d81ae439d650a6d7321420dfe14
* | Merge "Allow nova and others to override some logging defaults"Jenkins2012-12-061-0/+45
|\ \ | |/ |/|
| * Allow nova and others to override some logging defaultsDavanum Srinivas2012-12-061-0/+45
| | | | | | | | | | | | | | | | | | | | | | | | - In log.py, indicate that logging module allows tweaking of just logging_context_format_string option - In cfg.py, add a method that can alter the default given the options and new default - add testcases for log.set_defaults and cfg.set_defaults Fixes LP #1083218 Change-Id: Iefdbce8505eb7a07f2b59d4ed7564b0146f1b0cd
* | Merge "Fixing the trim for ListOp when reading from config file"Jenkins2012-12-061-0/+6
|\ \ | |/ |/|
| * Fixing the trim for ListOp when reading from config fileMichael Basnight2012-12-051-0/+6
| | | | | | | | | | | | Fixes Bug 1087018 Change-Id: I1c2d34166ae85add86daab6a7483b63297d00f66
* | Merge "Fix set_default() with boolean CLI options"Jenkins2012-12-031-0/+22
|\ \
| * | Fix set_default() with boolean CLI optionsMark McLoughlin2012-12-031-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Porting to argparse broke set_default() with boolean CLI options. The new test case shows this borkage. The issue is that, by default, argparse differs subtly from optparse in its handling of defaults for boolean options. Compare: >>> p = optparse.OptionParser() >>> p.add_option('--foo', action='store_true') >>> p.add_option('--bar', action='store_true', default=False) >>> p.parse_args([]) (<Values at 0x7f28aba066c8: {'foo': None, 'bar': False}>, []) to: >>> p = argparse.ArgumentParser() >>> p.add_argument('--foo', action='store_true') >>> p.add_argument('--bar', action='store_true', default=False) >>> p.add_argument('--blaa', action='store_true', default=None) >>> p.parse_args([]) Namespace(bar=False, blaa=None, foo=False) i.e. unless you specify a default for a boolean option, optparse defaults to None whereas argparse defaults to False. To get the same optparse behaviour with argparse, you need default=None. Change-Id: Ifc92a834c4ba59e939d80ac5de24d7051232f5b5
* | | Merge "Improve cfg's argparse sub-parsers support"Jenkins2012-12-031-42/+107
|\| | | |/ |/|
| * Improve cfg's argparse sub-parsers supportMark McLoughlin2012-11-291-42/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order for sub-parsers to be useful, you need some way of knowing which sub-parser was chosen during argument parsing. It's pretty obvious from the current sub-parsers test case that we don't have a convenient interface for this. One way of doing it is to use the 'dest' argument when adding sub-parsers: >>> subparsers = parser.add_subparsers(dest='cmd') >>> subparsers.add_parser('a') >>> subparsers.add_parser('b') >>> parser.parse_args(['a']) Namespace(cmd='a') The most sensible way to map this into cfg concepts is to register sub-parsers as an Opt. This way, we can make name and argument values of the sub-parser as an attribute on the ConfigOpts object: >>> def add_parsers(subparsers): ... a = subparsers.add_parser('a') ... a.add_argument('id') ... b = subparsers.add_parser('b') ... >>> CONF.register_cli_opt(SubCommandOpt('cmd', handler=add_parsers)) True >>> CONF(['a', '10']) >>> CONF.cmd.name, CONF.cmd.id ('a', '10') The handler method is a bit awkward, but each time cfg is to parse command line args it takes all the registered opts and creates a new argparse parser. So we need to be able to re-add the sub-parsers each time. Change-Id: I01bfd01bf8853cf57a9248b1663eb3da142366a4
* | Merge "Hide the GroupAttr conf and group attributes"Jenkins2012-11-291-0/+12
|\ \
| * | Hide the GroupAttr conf and group attributesMark McLoughlin2012-11-231-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There's no reason why an option group shouldn't have options called 'group' or 'conf'. Add a test case which would have failed because the 'conf' attribute would have been a ConfigOpts instance and fix it by making those attributes private. Change-Id: Ic3e41a546c0d1b7b6aae04e1dbac2933ac661f57
* | | Merge "Fix regression with cfg CLI arguments"Jenkins2012-11-291-0/+2
|\ \ \ | | |/ | |/|
| * | Fix regression with cfg CLI argumentsMark McLoughlin2012-11-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes bug #1082279 Only options registered using register_cli_opt() should be available via the CLI, but since e42276a all options are added to the CLI. Also modify one of the existing unit tests to catch this problem. Change-Id: I742a4ae4e0fc17cd9ae5e4424c2edd38e2bc50a2
* | | Merge "Add another duplicate opt test case"Jenkins2012-11-291-0/+5
|\ \ \
| * | | Add another duplicate opt test caseMark McLoughlin2012-11-231-0/+5
| | |/ | |/| | | | | | | | | | | | | This gets the code coverage of the tests back up to 100%. Change-Id: I737c1cfa52d10b3813237a9cb88b15211e0872c1
* | | Merge "Fix broken --help with CommonConfigOpts"Jenkins2012-11-291-0/+9
|\ \ \ | |_|/ |/| |
| * | Fix broken --help with CommonConfigOptsMark McLoughlin2012-11-231-0/+9
| |/ | | | | | | | | | | | | | | | | | | Since we switched to argparse, the way help strings are interpolated have changed and broken --help with the options registered by CommonConfigOpts. Fix and add a new test case which would catch the issue. Change-Id: I10e42efe4721e22ff41d0efbf390c805ccb9a6a0
* / Fix ListOpt to trim whitespaceDavanum Srinivas2012-11-241-0/+4
|/ | | | | | | | | - throw in an extra strip() in the list parsing code - add a test case to verify that it works! Fixes LP #1079299 Change-Id: I4f0864c72ecd2569d0461c301acda395c87a93e0
* Add support for positional argumentsMark McLoughlin2012-11-151-12/+65
| | | | | | | | | | | | | | | | | | argparse makes it awkward to implement the current cfg API where we simply return the leftover arguments to the caller. Very few cfg users actually rely on this functionality and for those cases it probably makes more sense for them to explicitly register positional arguments or sub-parsers. Add support for positional arguments via a 'required' Opt attribute: opt = StrOpt('foo', positional=True) conf.register_cli_opt(opt) conf(['bar']) conf.foo == 'bar' Change-Id: Iea746d710237e1ea26c1ef4871643941d1df09bd
* Use stock argparse behaviour for optional argsMark McLoughlin2012-11-151-2/+2
| | | | | | | | optparse would print "Options" but argparse prints "optional arguments". The default argparse behaviour is fine, let's stick with that. Change-Id: Ib53a2581af9d776e9a7c1cd90eebe89b70034e57
* Use stock argparse --usage behaviourMark McLoughlin2012-11-151-3/+3
| | | | | | | | | | | optparse would substitute the program name for %prog, but argparse requires %(prog)s. Also, optparse would print 'Usage:' whereas argparse prints 'usage:'. Neither optparse behaviour that's worth retaining, let's just use the default argparse behaviour. Change-Id: Ied2acb37c366f1a45aed72b6b76f11e2de23828e
* Use stock argparse --version behaviourMark McLoughlin2012-11-151-2/+2
| | | | | | | | | | optparse prints the version to stdout, argparse prints the version to stderr. There's no need to preserve the old optparse behaviour, let's just stick with argparse behaviour. Change-Id: Ie141c72112a63149d098afa9db55a95a309e79d7
* Completely remove cfg's disable_interspersed_args()Mark McLoughlin2012-11-151-12/+0
| | | | | | | | The use case for disable_interspersed_args() is that nova-manage needs to be able to parse sub-commands. We now have a add_cli_subparsers() method which better supports this use case. Change-Id: I1fcd15889745fe4ddff0ac4bacf385004f9b61af
* argparse support for cfgLaurence Miao2012-11-151-2/+47
| | | | | | | | | | | | | | | | | | | | | | * openstack/common/cfg.py Optparse is fading out since python 2.7, this patch will help openstack/common work on more advanded version of python(argparse). Now, disable_interspersed_args() has no effect. Added new method add_cli_subparsers, return argparse subparser, for usages such as subcommand. * tests/unit/test_cfg.py SubcommandTestCase added. Disabled test_disable_interspersed_args test entry for happiness of tox, temporarily. Modified test_help for port of argparse. * tools/pip-requires include argparse module for python 2.6 Change-Id: Ie5cbde1a92a92786d64dea0ddfcfbf288c29f960
* cfg: fix required if option has a dashJulien Danjou2012-10-261-0/+8
| | | | | | | | | If an option has a dash in it and is required, the check fails because it tries to self._get() on the name (with dash) rather than the dest (with underscore). Change-Id: I6448019f70f98bc2e58a325d0cf9ce88b8bb085b Signed-off-by: Julien Danjou <julien@danjou.info>
* Merge "Allow set_default and set_override to use None"Jenkins2012-08-131-2/+29
|\
| * Allow set_default and set_override to use NoneVishvananda Ishaya2012-08-111-2/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current implementation interprets set_default('foo', None) and set_override('foo', None) as 'clear the existing default or override', which makes it impossible to override a value with None. This patch adds support for overriding with a None value by adding a special internal class. set_override('foo', None) will now override the existing value with None. This is a slight change to the existing behavior, so this patch adds two calls for the old functionality of clearing defaults and overrides. Example syntax for the new calls are shown below: conf.clear_default('foo') conf.clear_override('foo') The patch also updates the tests to reflect the change in functionality and adds new tests to verify the new functionality. Fixes bug 1035478 Change-Id: Iee5e20e44da9bef6b86e0483ab0b48b625fe503c
* | Tilde expansion for --config-file and --config-dirMark McLoughlin2012-08-111-0/+40
|/ | | | | | | | | Fixes bug #1012671 Allow a filename starting with ~ or ~user to be passed for --config-file or --config-dir. Change-Id: I67705401ed1c35c0cc2161095e36616552740aba
* Add import_opt() method to ConfigOptsMark McLoughlin2012-07-311-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Related to blueprint cfg-global-object When using the global config object pattern, you often have modules which define options that are referenced in other options. So, for example if module A defined option 'foo' and module be needed to reference that option, you might do: import A print CONF.foo However, this makes it entirely unclear to the casual reader why module A was imported. Nova has a flags.DECLARE() function that helps with this problem by allowing you to do: flags.DECLARE('foo', 'A') The function simply imports module A and checks that the 'foo' option is now defined in the global config object. This is fine, but it is also implicit that this function applies to the global config object. Instead, let's do the following: CONF.import_opt('foo', 'A') Change-Id: I7b98f5be71068bbde70cc0eab991eaebb577de52
* Modifies _is_opt_registered fcn to check for duplicate optsGiampaolo Lauria2012-07-241-6/+2
| | | | | | | | | | This change fixes bug 999307 Currently, the check for duplicate options is done by checking whether they are the same object. The proposed fix is to check whether all the object fields have the same value. Change-Id: I2b72d630a0c8821df1d81e25d316d8d9195be492
* Update common code to support pep 1.3.Gary Kotton2012-06-181-23/+20
| | | | | | bug 1014216 Change-Id: I3f8fa2e11c9d3f3d34fb20f65ce886bb9c94463d
* Add support to include config aliasesJoe Gordon2012-06-061-1/+144
| | | | | | | | | | Implements blueprint config-aliases * Supports loading deprecated aliased options from a config file * Supports using deprecated aliased CLI options * For MultiStrOpt Can use mix of name and alias Change-Id: I04678880bc8ee1f85335f5656367bd1437245c6e
* Fix pep8 errors.Kevin L. Mitchell2012-06-041-1/+1
| | | | | | Fixes a couple of pep8 errors that appeared due to a pep8 tool update. Change-Id: Ida70b1fb962529d3a157f44dcf2e71af773a4431
* cfg: move constructor args to __call__() argsMark McLoughlin2012-05-291-8/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to effectively use a global ConfigOpts object, you need to be able to initialize the global object with none of the information we currently require at construction. By moving those constructor args to the __call__() method, we enable the global object usage model but also make the API generally more flexible. For example, you can now reset the object and re-use it for parsing a different set of config files with the same options. There are a couple of other minor behavior changes as a result: - print_usage() and print_help() no longer works before the object has been called to parse options - registration of duplicate short options are no longer detected until the options are parsed - the --config-file and --config-dir options aren't registered until just before parsing the options since the default set of config files can be specified at that time - find_file() can't be used until after the options have been parsed, again because of the late registration of --config-file and --config-dir Finally, an unregister_opt() method is added to support the re-registeration of the --config-file and --config-dir options. Change-Id: I650d8e299e92cbc5d10da47a7ce1b73ca8066bd0
* Run pep8 on tests.Russell Bryant2012-05-161-1/+2
| | | | | | | I noticed that pep8 wasn't running on the tests. This patch fixes that, as well as a couple of pep8 errors in test_cfg. Change-Id: I4429bfe6813a2e9394efb1753cbebbadb9f23833
* cfg: make reset() clear defaults and overridesMark McLoughlin2012-05-121-0/+42
| | | | | | | | | | | | Fixes bug #998396 Both Nova and Keystone need to clear the overrides on their config object between test runs. It's reasonable to expect the reset() method would do this, so let's make it so. Also add a clear() method with the old behaviour. Change-Id: I192c5bb07e81f0fb844fa2fd429dc2e7133800de
* Merge "cfg: automatically create option groups"Jenkins2012-05-101-1/+11
|\
| * cfg: automatically create option groupsMark McLoughlin2012-05-101-1/+11
| | | | | | | | | | | | | | | | | | | | Implements blueprint cfg-auto-create-groups Remove the restriction that groups must be explicitly created. Often you only need a group to have a name (not e.g. a title or help string) so we can easily just auto-create groups for that case. Change-Id: I150ab3900e3aad0068b93487c8d396d21d26cfea
* | cfg: allow options to be marked as requiredMark McLoughlin2012-05-101-0/+93
|/ | | | | | | | | | | | | | Implements blueprint cfg-required-options Add a 'required' flag to option schemas: StrOpt('foo', required=True) which causes a RequiredOptError exception to be raised if the user fails to supply a value for the option on the CLI or in a config file. Change-Id: Ied7bb25f0c1582c4991d0f212f4871b9358b73fb