Updated from global requirements

Change-Id: I98764a5281f5ae786bb6b56c1ad9d086e67df8b9
Add the ability to validate default options value

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
Updated from global requirements

Change-Id: I4f26d3a8790c799e5c1f7f81031406e0c57545f9

Change-Id: Ica7315effe308bd739e90f885849fac27a3c542b
Replace assertEquals with assertEqual

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
Fix to make ConfigOpts no longer obscure IOErrors

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
Updated from global requirements

Change-Id: I19a010d58c9a3135c5fe1051ced64772f3673f46
Updated from global requirements

Change-Id: Ib90882a1b17b75a042fb8832e6b49d32d43c5cd4
Added support of operator '=='

Implemented method __eq__ for cfg.Opt.

Change-Id: Ia6a3d82d19b7d239ffc0b42a47e1ce7383f10564
Partial-Bug: 1262148
Fix spelling errors in docstrings and comments

Change-Id: I20f133769b953fd3c0ab3d6904c9d7f773052214
Utilizes assertIsNone and assertIsNotNone

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
Fix for parsing error with Dollar Sign ($) in values

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
Merge "Fix spelling errors in docstrings and comments"
Merge "Fix for parsing error with Dollar Sign ($) in values"
Implemented support for custom opt types

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
Remove copyright from empty files

According to policy change in HACKING:
http://docs.openstack.org/developer/hacking/#openstack-licensing
empty files should no longer contain copyright notices.

Closes-Bug: #1262424
Change-Id: Id6396fc396376c7e8bb0c8eb4abe472a97c014c5
Merge "Implemented support for custom opt types"
Throw exception if --config-dir doesn't exist

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 "Remove copyright from empty files"
Merge "Throw exception if --config-dir doesn't exist"
Add docs for types

Add a page to pull in the docstrings for the option types,
and make the docstring changes in the module necessary for
that to work properly.

Also fix a formatting issue in the docs for the cfg module.

Change-Id: Ib1cf24e59ecc3592d3b703f99659f4a0fdbc7f5c