Add debug log in pick_default_policy_file

We have many if else condition to pick the
right policy filebut there is no debugging log
to have useful info to know if expected policy file
is not picked.

Change-Id: I507c58a6dca06d0cc6f306bcd063c700c18cc5f7
This commit is contained in:
Ghanshyam Mann 2021-01-28 10:17:38 -06:00 committed by Ghanshyam
parent e103baa002
commit b7489eb75a
1 changed files with 12 additions and 2 deletions

View File

@ -370,15 +370,25 @@ def pick_default_policy_file(conf, fallback_to_json_file=True):
new_default_policy_file = 'policy.yaml'
old_default_policy_file = 'policy.json'
policy_file = None
if ((conf.oslo_policy.policy_file == new_default_policy_file) and
fallback_to_json_file):
location = conf.get_location('policy_file', 'oslo_policy').location
if conf.find_file(conf.oslo_policy.policy_file):
return conf.oslo_policy.policy_file
policy_file = conf.oslo_policy.policy_file
elif location in [cfg.Locations.opt_default,
cfg.Locations.set_default]:
LOG.debug('Searching old policy.json file.')
if conf.find_file(old_default_policy_file):
return old_default_policy_file
policy_file = old_default_policy_file
if policy_file:
LOG.debug(
'Picking default policy file: %s. Config location: %s',
policy_file, location)
return policy_file
LOG.debug(
'No default policy file present, picking the configured '
'one: %s.', conf.oslo_policy.policy_file)
# Return overridden policy file
return conf.oslo_policy.policy_file