← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 2081009] Re: oslo_config.cfg.NotInitializedError when switching default policy_file in oslo.policy

 

Reviewed:  https://review.opendev.org/c/openstack/glance/+/929720
Committed: https://opendev.org/openstack/glance/commit/562a2eb48b4fc10cf97bd65d9a2f2e6d2a739eba
Submitter: "Zuul (22348)"
Branch:    master

commit 562a2eb48b4fc10cf97bd65d9a2f2e6d2a739eba
Author: Takashi Kajinami <kajinamit@xxxxxxxxxxxxxxx>
Date:   Wed Sep 18 13:49:47 2024 +0900

    Do not call Enforcer.__call__ at module level
    
    ... because the method may need to user some functionalities which can
    be used after CONF instance is initialized and module level import
    makes it difficult to guarantee the order.
    
    Closes-Bug: #2081009
    Change-Id: Id40ceab2a84bb7047dfd130bf8c1ac4c8073b79b


** Changed in: glance
       Status: In Progress => Fix Released

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to Glance.
https://bugs.launchpad.net/bugs/2081009

Title:
  oslo_config.cfg.NotInitializedError when switching default policy_file
  in oslo.policy

Status in Glance:
  Fix Released

Bug description:
  While we attempted to update the default policy file in
  https://review.opendev.org/c/openstack/oslo.policy/+/929714 , we
  observed the glance-api can't start and complains the error below.

  ```
  Traceback (most recent call last):
    File "/opt/stack/data/venv/bin/glance-wsgi-api", line 6, in <module>
      from glance.common.wsgi_app import init_app
    File "/opt/stack/glance/glance/common/wsgi_app.py", line 24, in <module>
      from glance.common import config
    File "/opt/stack/glance/glance/common/config.py", line 643, in <module>
      policy.Enforcer(CONF)
    File "/opt/stack/oslo.policy/oslo_policy/policy.py", line 543, in __init__
      self.policy_file = policy_file or pick_default_policy_file(
    File "/opt/stack/oslo.policy/oslo_policy/policy.py", line 378, in pick_default_policy_file
      if conf.find_file(conf.oslo_policy.policy_file):
    File "/opt/stack/data/venv/lib/python3.10/site-packages/oslo_config/cfg.py", line 2782, in find_file
  Traceback (most recent call last):
    File "/opt/stack/data/venv/bin/glance-wsgi-api", line 6, in <module>
      from glance.common.wsgi_app import init_app
    File "/opt/stack/glance/glance/common/wsgi_app.py", line 24, in <module>
      from glance.common import config
    File "/opt/stack/glance/glance/common/config.py", line 643, in <module>
      policy.Enforcer(CONF)
    File "/opt/stack/oslo.policy/oslo_policy/policy.py", line 543, in __init__
      self.policy_file = policy_file or pick_default_policy_file(
    File "/opt/stack/oslo.policy/oslo_policy/policy.py", line 378, in pick_default_policy_file
      raise NotInitializedError()
  oslo_config.cfg.NotInitializedError: call expression on parser has not been invoked
  ```

  The problem here is that Enforcer() is called directly at the module
  level in glance.common.config and we can't guarantee the module is
  imported after CONF instance is initialized.

To manage notifications about this bug go to:
https://bugs.launchpad.net/glance/+bug/2081009/+subscriptions



References