[openstack-dev] [oslo.config] Config files overriding CLI: The path of most surprise.
markmc at redhat.com
Tue Jul 2 07:51:49 UTC 2013
On Tue, 2013-07-02 at 00:24 -0700, Clint Byrum wrote:
> Excerpts from Mark McLoughlin's message of 2013-07-01 15:12:51 -0700:
> > On Mon, 2013-07-01 at 14:52 -0700, Clint Byrum wrote:
> > > Last week I went to use oslo.config in a utility I am writing called
> > > os-collect-config...
> > >
> > > While running unit tests on the main() method that is used for the CLI,
> > > I was surprised to find that my unit tests were picking up values from
> > > a config file I had created just as a test. The tests can be fixed to
> > > disable config file lookups, but what was more troublesome was that the
> > > config file was overriding values I was passing in as sys.argv.
> > >
> > > I have read the thread which suggest that CLI should defer to config
> > > file because config files are somehow less permanent than the CLI.
> > >
> > > I am writing today to challenge that notion, and also to suggest that even
> > > if that is the case, it is inappropriate to have oslo.config operate in
> > > such a profoundly different manner than basically any other config library
> > > or system software in general use. CLI options are _for config files_
> > > and if packagers are shipping configurations in systemd unit files,
> > > upstart jobs, or sysvinits, they are doing so to control the concerns
> > > of that particular invocation of whatever command they are running,
> > > and not to configure the software entirely.
> > >
> > > CLI args are by definition ephemeral, even if somebody might make them
> > > "permanent" in their system, I doubt any packager would then expect that
> > > these CLI args would be overridden by any config files. This default is
> > > just wrong, and needs to be fixed.
> > Have you seen this?
> > https://review.openstack.org/#/c/29459/
> I had not, but this only provides a workaround, I think. If I read
> it right, it means I have to specify --config-file to change the
> precedence. So running:
> 'program --config-file /etc/program/program.conf --foo'
> is different than
> 'program --foo --config-file /etc/program/program.conf'
That's correct, yes.
> This is a passable workaround, but it doesn't change the fact that
> the default behavior is to read the config files last if they are not
> specified on the command line.
Nope, config files are read first:
$> cat t.py
from oslo.config import cfg
print cfg.CONF.config_file, cfg.CONF.debug
$> cat ~/t.conf
debug = True
$> python t.py
$> python t.py --nodebug
More information about the OpenStack-dev