cfg: make reset() clear defaults and overrides

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
Tests to cover various mailmap formats.

Bug: 994957

Mailmap might include entries in different format:
   Full Name <email@foo.com> Full Name <email@bar.com>
   Firstname <email@foo.com> Firstname <email@bar.com>
   <email@foo.com> <email@bar.com>

This commit adds a test case to parse these entries.

* tests/unit/test_setup.py
  Remove unused imports.
  Import os and setup methods to verify.

  SetupTest: Define unique test case name.
  setUp(): New method to define temporary mailmap file.
  tearDown(): New method to remove the temporary mailmap file.
  test_mailmap_with_fullname(): New method to test mailmap entry
  with fullname.
  test_mailmap_with_firstname(): New method to test mailmap entry
  with first name only.
  test_mailmap_with_noname(): New method to test mailmap entry with
  just email addresses.

Change-Id: Icc018d4b2692ce7a7de757f02d1dd49241c30a6c
Merge "cfg: make reset() clear defaults and overrides"
Remove unused imports.

This patch removes a couple of unused impots from test_utils.

Change-Id: I40a2f4086e33dbcdb2eceb699c82a1350665c181
Alphabetize imports in openstack/common/cfg.py

In preparation for enabling alphabetized import checking in Nova

Change-Id: I709fca6a121ba44df193757e5ad838de710c2f15
Merge "Alphabetize imports in openstack/common/cfg.py"
Create openstack.common.jsonutils.

This patch creates a new module, jsonutils.  It is based on some code
from nova.utils that is used by nova.rpc.  It is being added to
openstack-common as another step toward being able to eventually move
nova.rpc to openstack-common.

This module provides a few things:

1) A handy function for getting an object down to something that can
be JSON serialized.  See to_primitive().

2) Wrappers around loads() and dumps().  The dumps() wrapper will
automatically use to_primitive() for you if needed.

3) This sets up anyjson to use the loads() and dumps() wrappers if
anyjson is available.

Change-Id: I41e5759360d515ed53defe69f3e8247aafbcc83a
Run pep8 on tests.

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
Backslash continuation removal (common folsom-1)

Fixes bug #1001361

Removes backslash continuations

Change-Id: I86fbb950b48a7681b3c1a010b0d0007cd2f12632
Added support for proper bare URLs.

If we want to use github zipballs as a source of depends sometimes
(which we do) - we need to have the pip-requires parsing understand
that lines starting with http:// or https:// are urls and should go
to dependency_links.

Change-Id: I9218159872d6edfebd4b820e6db912e9aabdf7d7
cfg: move constructor args to __call__() args

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
cfg: add generators for iterating over all options

We have a few places now where we do:

  for opt in self.opts:
      foo(opt)

  for group in self.groups:
      for opt in group.opts:
          foo(opt, group)

Use generators to turn this into simply:

  for opt, group in self.all_opts():
      foo(opt, group)

Change-Id: I7a32779c20caeb1bacb85528d7e36c3c18c6c16a
cfg: add a global CONF object

Implements blueprint cfg-global-object

Add an instance of the CommonConfigOpts class to the cfg module's
global namespace.

The usage pattern is:

  from openstack.common import cfg

  opts = [
      cfg.StrOpt('foo', default='blaa'),
      cfg.StrOpt('bar', default='blaa'),
      ]

  CONF = cfg.CONF
  CONF.register_opts(opts)

  def do_something_later():
      print CONF.foo, CONF.bar

  def main():
      CONF(project='pulsar')

Change-Id: I77e87b1e186c243b2638a4b1c202f865249dafce
Add a load function wrapper to jsonutils

Fixes bug #1008065

Change-Id: I72aba29eea4637643cb7742f2fd4b1f05d15667f
Fix pep8 errors.

Fixes a couple of pep8 errors that appeared due to a pep8 tool update.

Change-Id: Ida70b1fb962529d3a157f44dcf2e71af773a4431
Common-ize policies.

Both Glance and Nova make use of (almost) the same policy system,
defined in glance/common/policy.py and nova/common/policy.py,
respectively.  They also have independent glue code
(glance/api/policy.py and nova/policy.py), so that the common
policy system is substantially similar.  This makes policies a
perfect candidate for incorporation into openstack-common,
particularly given that this same code will soon be used by
Quantum.

This change adds the common policy module (along with some minor
interface changes and bug fixes) to openstack-common, along with
a test suite.

Change-Id: I0022a91f16ded28f9dc6b4975ef1b6e4cc8460ac
Create testutils with skip decorators.

This patch creates openstack.common.testutils which includes some
decorators used to conditionally skip tests.  This is needed for the
rpc unit tests.

Change-Id: Ic6bc8d58f7dfcd9eb3acd2749c475b9d760b9578
Merge "Create testutils with skip decorators."
Replace datetime.utcnow with timeutils.utcnow

Fixes bug #1008064

Replaced datetime.utcnow usage with timeutils.utcnow

Change-Id: I8bfdc1abefc3891497554335a3078d4028ef8ac9
Add nova time util functions to timeutils

Fixes bug #1009410

1. Add the following functions from nova/utils.py
- strtime
- parse_strtime
- is_older_than
- utcnow_ts
- advance_time_delta
- advance_time_seconds

2. Write unittests in tests/unit/test_timeutils.py

Change-Id: Ie0bba90833e2ed31bb5ab867a7c1a76a9901cacb