Skip to content

Commit

Permalink
Fix oslo policy file genrator tool for Magnum
Browse files Browse the repository at this point in the history
oslo tool to generate the policy or sample policy file does not work for magnum service.

``oslopolicy-policy-generator --namespace magnum``  end up with
below error:
    ModuleNotFoundError: No module named 'magnum.policy'

same error with oslopolicy-sample-generator --namespace magnum

oslo.policy policy generator tool look for the service oslo policy enforcer
entry and does not find it. setup.cfg file is missing the entry point for
magnum oslo policy enforcer.

- https://lists.openstack.org/archives/list/[email protected]/thread/5ZRWWL3YKWX3XCFGTC4G2KP6PCJMBL64/

Closes-Bug: #2068519
Change-Id: Iff94f7dea491b0ea465b17cd60c37423224f9ffa
(cherry picked from commit 8d09169)
(cherry picked from commit 2045ffb)
(cherry picked from commit f3cfcfd)
  • Loading branch information
gmannos authored and waipeng committed Jun 7, 2024
1 parent 30ab9c9 commit 77293ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions magnum/common/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ def add_policy_attributes(target):
return target


def get_enforcer():
# This method is used by oslopolicy CLI scripts in order to generate policy
# files from overrides on disk and defaults in code.
cfg.CONF([], project='magnum')
init()
return _ENFORCER


def check_is_admin(context):
"""Whether or not user is admin according to policy setting.
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ oslo.config.opts =
oslo.config.opts.defaults =
magnum = magnum.common.config:set_config_defaults

oslo.policy.enforcer =
magnum = magnum.common.policy:get_enforcer

oslo.policy.policies =
magnum = magnum.common.policies:list_rules

Expand Down

0 comments on commit 77293ee

Please sign in to comment.