Accept oslopolicy-policy-generator path arguments

The Octavia policy enforcer object used by the oslopolicy-policy-generator
must pass the --config-file or --config-dir command line arguments to
oslo.config, otherwise those arguments are ignored.

Change-Id: Ic638c056715f8fcea3b095726964e7224c38eae2
Task: 37743
Story: 2006983
(cherry picked from commit 8800e85987)
This commit is contained in:
Stefan Nica 2019-12-04 15:39:27 +01:00
parent 567a388b95
commit 9904b26a9c
1 changed files with 12 additions and 1 deletions

View File

@ -12,6 +12,8 @@
"""Policy Engine For Octavia."""
import sys
from oslo_config import cfg
from oslo_log import log as logging
from oslo_policy import policy as oslo_policy
@ -151,5 +153,14 @@ class IsAdminCheck(oslo_policy.Check):
# This is used for the oslopolicy-policy-generator tool
def get_no_context_enforcer():
config.init([])
# oslo.config needs access to the --config-dir and --config-file
# command line args
filtered_args = ['--config-dir', '--config-file']
# Start at 1 because cfg.CONF expects the equivalent of sys.argv[1:]
conf_args = [arg for idx, arg in enumerate(sys.argv[1:])
if (arg in filtered_args or
sys.argv[idx] in filtered_args)]
config.init(conf_args)
return Policy()