policy: Raise error when file_path and file_format are inconsistent

We have replaced policy.yaml with policy.json following the community
goal[1], but it might be possible that users are not aware of that
migration and still expect json files.
This change ensures that users are not expecting json file based on
the given file path.

[1] https://governance.openstack.org/tc/goals/selected/wallaby/migrate-policy-format-from-json-to-yaml.html

Change-Id: Ie2e5a6798e8603585c20b947eb91bbad5453934b
This commit is contained in:
Takashi Kajinami 2021-03-25 19:05:06 +09:00
parent 39c5618009
commit 61aeda0b48
2 changed files with 26 additions and 0 deletions

View File

@ -78,6 +78,12 @@ define openstacklib::policy::base (
~> Augeas<| title == "${file_path}-${key}-${value}" |>
}
'yaml': {
if stdlib::extname($file_path) == '.json' {
# NOTE(tkajinam): It is likely that user is not aware of migration from
# policy.json to policy.yaml
fail("file_path: ${file_path} should be a yaml file instead of a json file")
}
ensure_resource('file', $file_path, {
mode => $file_mode,
owner => $file_user,

View File

@ -72,6 +72,26 @@ describe 'openstacklib::policy::base' do
) }
end
context 'with json file_path and yaml file format' do
let :title do
'nova-contest_is_admin'
end
let :params do
{
:file_path => '/etc/nova/policy.json',
:key => 'context_is_admin or owner',
:value => 'foo:bar',
:file_mode => '0644',
:file_user => 'foo',
:file_group => 'bar',
:file_format => 'yaml',
}
end
it { should raise_error(Puppet::Error) }
end
end
on_supported_os({