Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-08 Thread Matthew Booth
On 07/08/14 18:54, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 17:46 +0100, Matthew Booth wrote: In any case, the operative point is that CONF.attribute must always be evaluated inside run-time code, never at module load time. ...unless you call register_opts() safely, which is what I'm

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-08 Thread Matthew Booth
On 07/08/14 19:02, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 17:41 +0100, Matthew Booth wrote: ... or arg is an object which defines __nonzero__(), or defines __getattr__() and then explodes because of the unexpected lookup of a __nonzero__ attribute. Or it's False (no quotes when printed

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-08 Thread Matthew Booth
On 08/08/14 11:04, Matthew Booth wrote: On 07/08/14 18:54, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 17:46 +0100, Matthew Booth wrote: In any case, the operative point is that CONF.attribute must always be evaluated inside run-time code, never at module load time. ...unless you call

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Doug Hellmann
On Aug 7, 2014, at 12:39 PM, Kevin L. Mitchell kevin.mitch...@rackspace.com wrote: On Thu, 2014-08-07 at 17:27 +0100, Matthew Booth wrote: On 07/08/14 16:27, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 12:15 +0100, Matthew Booth wrote: A (the?) solution is to register_opts() in foo

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Brant Knudson
On Thu, Aug 7, 2014 at 12:54 PM, Kevin L. Mitchell kevin.mitch...@rackspace.com wrote: On Thu, 2014-08-07 at 17:46 +0100, Matthew Booth wrote: In any case, the operative point is that CONF.attribute must always be evaluated inside run-time code, never at module load time. ...unless

[openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Matthew Booth
I'm sure this is well known, but I recently encountered this problem for the second time. --- foo: import oslo.config as cfg import bar CONF = cfg.CONF CONF.register_opts('foo_opt') --- bar: import oslo.config as cfg CONF = cfg.CONF def bar_func(arg=CONF.foo_opt): pass --- importing foo

Re: [openstack-dev] [nova][oslo] oslo.config and import chains (a proposal to update the style guidelines for imports)

2014-08-07 Thread Matthew Booth
On 07/08/14 12:15, Matthew Booth wrote: I'm sure this is well known, but I recently encountered this problem for the second time. --- foo: import oslo.config as cfg import bar CONF = cfg.CONF CONF.register_opts('foo_opt') --- bar: import oslo.config as cfg CONF = cfg.CONF

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Kevin L. Mitchell
On Thu, 2014-08-07 at 12:15 +0100, Matthew Booth wrote: A (the?) solution is to register_opts() in foo before importing any modules which might also use oslo.config. Actually, I disagree. The real problem here is the definition of bar_func(). The default value of the parameter arg will likely

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Matt Riedemann
On 8/7/2014 10:27 AM, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 12:15 +0100, Matthew Booth wrote: A (the?) solution is to register_opts() in foo before importing any modules which might also use oslo.config. Actually, I disagree. The real problem here is the definition of bar_func().

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Kevin L. Mitchell
On Thu, 2014-08-07 at 10:55 -0500, Matt Riedemann wrote: On 8/7/2014 10:27 AM, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 12:15 +0100, Matthew Booth wrote: A (the?) solution is to register_opts() in foo before importing any modules which might also use oslo.config. Actually, I

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Matthew Booth
On 07/08/14 16:27, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 12:15 +0100, Matthew Booth wrote: A (the?) solution is to register_opts() in foo before importing any modules which might also use oslo.config. Actually, I disagree. The real problem here is the definition of bar_func().

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Dan Smith
That's different behaviour, because you can no longer pass arg=None. The fix isn't to change the behaviour of the code. So use a sentinel... --Dan signature.asc Description: OpenPGP digital signature ___ OpenStack-dev mailing list

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Kevin L. Mitchell
On Thu, 2014-08-07 at 17:27 +0100, Matthew Booth wrote: On 07/08/14 16:27, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 12:15 +0100, Matthew Booth wrote: A (the?) solution is to register_opts() in foo before importing any modules which might also use oslo.config. Actually, I

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Matthew Booth
On 07/08/14 17:11, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 10:55 -0500, Matt Riedemann wrote: On 8/7/2014 10:27 AM, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 12:15 +0100, Matthew Booth wrote: A (the?) solution is to register_opts() in foo before importing any modules which might

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Matthew Booth
On 07/08/14 17:34, Dan Smith wrote: That's different behaviour, because you can no longer pass arg=None. The fix isn't to change the behaviour of the code. So use a sentinel... That would also be a change to the behaviour of the code, because you can no longer pass in the sentinel. These

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Matthew Booth
On 07/08/14 17:39, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 17:27 +0100, Matthew Booth wrote: On 07/08/14 16:27, Kevin L. Mitchell wrote: On Thu, 2014-08-07 at 12:15 +0100, Matthew Booth wrote: A (the?) solution is to register_opts() in foo before importing any modules which might also

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Kevin L. Mitchell
On Thu, 2014-08-07 at 17:44 +0100, Matthew Booth wrote: These are tricky, case-by-case workarounds to a general problem which can be solved by simply calling register_opts() in a place where it's guaranteed to be safe. No, THE CODE IS WRONG. It is evaluating a configuration value at _module

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Kevin L. Mitchell
On Thu, 2014-08-07 at 17:46 +0100, Matthew Booth wrote: In any case, the operative point is that CONF.attribute must always be evaluated inside run-time code, never at module load time. ...unless you call register_opts() safely, which is what I'm proposing. No, calling register_opts() at

Re: [openstack-dev] [nova][oslo] oslo.config and import chains

2014-08-07 Thread Kevin L. Mitchell
On Thu, 2014-08-07 at 17:41 +0100, Matthew Booth wrote: ... or arg is an object which defines __nonzero__(), or defines __getattr__() and then explodes because of the unexpected lookup of a __nonzero__ attribute. Or it's False (no quotes when printed by the debugger), but has a unicode type