placement/placement/db/sqlalchemy/alembic
Chris Dent 6fa9eabb79 Stop using global oslo_config
This change was driven out of trying to get nova functional tests
working with an extracted placement, starting with getting the
database fixture cleaner.

Perhaps not surprisingly, trying to share the same 'cfg.CONF' between
two services is rather fraught. Rather than trying to tease out all the
individual issues, which is a very time consuming effort for not much
gain, a different time consuming effort with great gain was tried
instead.

This patch removes the use of the default global cfg.CONF that
oslo_config (optionally) provides and instead ensures that at
the various ways in which one might enter placement: wsgi, cli,
tests, the config is generated and managed in a more explicit
fashion.

Unfortunately this is a large change, but there's no easy way to do it
in incremental chunks without getting very confused and having tests
pass. There are a few classes of changes here, surrounded by various
cleanups to address their addition. Quite a few holes were found in how
config is managed, especially in tests where often we were getting what
we wanted pretty much by accident.

The big changes:

* Importing placement.conf does not automatically register options
  with the global conf. Instead there is a now a register_opts method
  to which a ConfigOpts() is required.

* Because of policy enforcement wanting access to conf, a convenient way
  of having the config pass through context.can() was needed. At
  the start of PlacementHandler (the main dispatch routine) the
  current config (provided to the PlacementHandler at application
  configuration time) is set as an attribute on the RequestContext.
  This is also used where CONF is required in the objects, such as
  randomizing the limited allocation canidates.

* Passing in config to PlacementHandler changes the way the gabbi fixture
  loads the WSGI application. To work around a shortcoming in gabbi
  the fixture needs to CONF global. This is _not_ an
  oslo_config.cfg.CONF global, but something used locally in the fixture
  to set a different config per gabbi test suite.

* The --sql command for alembic commands has been disabled. We don't
  really need that and it would require some messing about with config.
  The command lets you dump raw sql intead of migration files.

* PlacementFixture, for use by nova, has been expanded to create and
  manage its config, database and policy requirements using non-global
  config. It can also accept a previously prepared config.

* The Database fixtures calls 'reset()' in both setUp and cleanUp to be
  certain we are both starting and ending in a known state that will
  not disturb or be disturbed by other tests. This adds confidence (but
  not a guarantee) that in tests that run with eventlet (as in nova)
  things are in more consistent state.

* Configuring the db in the Database fixture is moved into setUp where
  it should have been all along, but is important to be there _after_
  'reset()'.

These of course cascade other changes all over the place. Especially the
need to manually register_opts. There are probably refactorings that can
be done or base classes that can be removed.

Command line tools (e.g. status) which are mostly based on external
libraries continue to use config in the pre-existing way.

A lock fixture for the opportunistic migration tests has been added.
There was a lock fixture previously, provided by oslo_concurrency, but
it, as far as I can tell, requires global config. We don't want that.

Things that will need to be changed as a result of these changes:

* The goals doc at https://review.openstack.org/#/c/618811/ will
  need to be changed to say "keep it this way" rather than "get it
  this way".

Change-Id: Icd629d7cd6d68ca08f9f3b4f0465c3d9a1efeb22
2018-11-30 14:51:23 +00:00
..
versions Fix comment in earlier patch 2018-11-15 05:12:01 -05:00
env.py Stop using global oslo_config 2018-11-30 14:51:23 +00:00
script.py.mako Added alembic environment 2018-11-14 15:26:13 +00:00