Sort dictionary values

... to make provider.yaml content predictable.

Also replace verify_contents, because this utility is provided by
puppetlabs_spec_helper which we aim to replace by voxpupuli-test.
More strict assertion allows us to detect wrong orders.

Change-Id: Id9c834b822ba4897b92b43733c6ad557ec586a93
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2025-09-15 01:45:20 +09:00
parent 5f745d39e3
commit c034b19b52
3 changed files with 129 additions and 139 deletions

View File

@@ -55,30 +55,30 @@ describe 'nova::compute::provider' do
end end
it 'configure provider.yaml on compute nodes' do it 'configure provider.yaml on compute nodes' do
is_expected.to contain_file('/etc/nova/provider_config/provider.yaml') is_expected.to contain_file('/etc/nova/provider_config/provider.yaml').with_content( <<EOS
verify_contents(catalogue, '/etc/nova/provider_config/provider.yaml', [ meta:
"meta:", schema_version: '1.0'
" schema_version: \'1.0\'", providers:
"providers:", # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html
" # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html", - identification:
" - identification:", uuid: '$COMPUTE_NODE'
" uuid: \'$COMPUTE_NODE\'", inventories:
" inventories:", additional:
" additional:", - CUSTOM_EXAMPLE_RESOURCE_CLASS_1:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS_1:", allocation_ratio: 1.0
" allocation_ratio: 1.0", max_unit: 10
" max_unit: 10", min_unit: 1
" min_unit: 1", reserved: 0
" reserved: 0", step_size: 1
" step_size: 1", total: 100
" total: 100", - CUSTOM_EXAMPLE_RESOURCE_CLASS_2:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS_2:", total: 100
" total: 100", traits:
" traits:", additional:
" additional:", - 'CUSTOM_P_STATE_ENABLED'
" - \'CUSTOM_P_STATE_ENABLED\'", - 'CUSTOM_C_STATE_ENABLED'
" - \'CUSTOM_C_STATE_ENABLED\'" EOS
]) )
end end
end end
@@ -111,30 +111,30 @@ describe 'nova::compute::provider' do
end end
it 'configure provider.yaml on compute nodes' do it 'configure provider.yaml on compute nodes' do
is_expected.to contain_file('/etc/nova/provider_config/provider.yaml') is_expected.to contain_file('/etc/nova/provider_config/provider.yaml').with_content( <<EOS
verify_contents(catalogue, '/etc/nova/provider_config/provider.yaml', [ meta:
"meta:", schema_version: '1.0'
" schema_version: \'1.0\'", providers:
"providers:", # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html
" # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html", - identification:
" - identification:", uuid: '5213b75d-9260-42a6-b236-f39b0fd10561'
" uuid: \'5213b75d-9260-42a6-b236-f39b0fd10561\'", inventories:
" inventories:", additional:
" additional:", - CUSTOM_EXAMPLE_RESOURCE_CLASS_1:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS_1:", allocation_ratio: 1.0
" allocation_ratio: 1.0", max_unit: 10
" max_unit: 10", min_unit: 1
" min_unit: 1", reserved: 0
" reserved: 0", step_size: 1
" step_size: 1", total: 100
" total: 100", - CUSTOM_EXAMPLE_RESOURCE_CLASS_2:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS_2:", total: 100
" total: 100", traits:
" traits:", additional:
" additional:", - 'CUSTOM_P_STATE_ENABLED'
" - \'CUSTOM_P_STATE_ENABLED\'", - 'CUSTOM_C_STATE_ENABLED'
" - \'CUSTOM_C_STATE_ENABLED\'" EOS
]) )
end end
end end
@@ -167,30 +167,30 @@ describe 'nova::compute::provider' do
end end
it 'configure provider.yaml on compute nodes' do it 'configure provider.yaml on compute nodes' do
is_expected.to contain_file('/etc/nova/provider_config/provider.yaml') is_expected.to contain_file('/etc/nova/provider_config/provider.yaml').with_content( <<EOS
verify_contents(catalogue, '/etc/nova/provider_config/provider.yaml', [ meta:
"meta:", schema_version: '1.0'
" schema_version: \'1.0\'", providers:
"providers:", # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html
" # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html", - identification:
" - identification:", name: 'EXAMPLE_RESOURCE_PROVIDER'
" name: \'EXAMPLE_RESOURCE_PROVIDER\'", inventories:
" inventories:", additional:
" additional:", - CUSTOM_EXAMPLE_RESOURCE_CLASS_1:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS_1:", allocation_ratio: 1.0
" allocation_ratio: 1.0", max_unit: 10
" max_unit: 10", min_unit: 1
" min_unit: 1", reserved: 0
" reserved: 0", step_size: 1
" step_size: 1", total: 100
" total: 100", - CUSTOM_EXAMPLE_RESOURCE_CLASS_2:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS_2:", total: 100
" total: 100", traits:
" traits:", additional:
" additional:", - 'CUSTOM_P_STATE_ENABLED'
" - \'CUSTOM_P_STATE_ENABLED\'", - 'CUSTOM_C_STATE_ENABLED'
" - \'CUSTOM_C_STATE_ENABLED\'" EOS
]) )
end end
end end
@@ -231,39 +231,37 @@ describe 'nova::compute::provider' do
end end
it 'configure provider.yaml on compute nodes' do it 'configure provider.yaml on compute nodes' do
is_expected.to contain_file('/etc/nova/provider_config/provider.yaml') is_expected.to contain_file('/etc/nova/provider_config/provider.yaml').with_content( <<EOS
verify_contents(catalogue, '/etc/nova/provider_config/provider.yaml', [ meta:
"meta:", schema_version: '1.0'
" schema_version: \'1.0\'", providers:
"providers:", # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html
" # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html", - identification:
" - identification:", uuid: '$COMPUTE_NODE'
" uuid: \'$COMPUTE_NODE\'", inventories:
" inventories:", additional:
" additional:", - CUSTOM_EXAMPLE_RESOURCE_CLASS_1:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS_1:", allocation_ratio: 1.0
" allocation_ratio: 1.0", max_unit: 10
" max_unit: 10", min_unit: 1
" min_unit: 1", reserved: 0
" reserved: 0", step_size: 1
" step_size: 1", total: 100
" total: 100", - CUSTOM_EXAMPLE_RESOURCE_CLASS_2:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS_2:", total: 100
" total: 100", traits:
" traits:", additional:
" additional:", - 'CUSTOM_P_STATE_ENABLED'
" - \'CUSTOM_P_STATE_ENABLED\'", - 'CUSTOM_C_STATE_ENABLED'
" - \'CUSTOM_C_STATE_ENABLED\'", - identification:
" - identification:", name: 'EXAMPLE_RESOURCE_PROVIDER'
" name: \'EXAMPLE_RESOURCE_PROVIDER\'", inventories:
" inventories:", additional:
" additional:", - CUSTOM_EXAMPLE_RESOURCE_CLASS:
" - CUSTOM_EXAMPLE_RESOURCE_CLASS:", reserved: 100
" reserved: 100", total: 10000
" total: 10000", EOS
" traits:", )
" additional:"
])
end end
end end
end end

View File

@@ -26,19 +26,16 @@ describe 'nova::compute::libvirt::secret_ceph' do
:group => 'root', :group => 'root',
:mode => '0600', :mode => '0600',
:require => 'Anchor[nova::config::begin]', :require => 'Anchor[nova::config::begin]',
:content => <<EOS
<secret ephemeral='no' private='no'>
<usage type='ceph'>
<name>client.openstack</name>
</usage>
<uuid>4f515eff-47e4-425c-b24d-9c6adc56401c</uuid>
</secret>
EOS
)} )}
it {
verify_contents(catalogue, '/tmp/libvirt-secret-4f515eff-47e4-425c-b24d-9c6adc56401c.xml', [
"<secret ephemeral=\'no\' private=\'no\'>",
" <usage type=\'ceph\'>",
" <name>client.openstack</name>",
" </usage>",
" <uuid>4f515eff-47e4-425c-b24d-9c6adc56401c</uuid>",
"</secret>"
])
}
it { is_expected.to contain_file('/tmp/libvirt-secret-4f515eff-47e4-425c-b24d-9c6adc56401c.secret').with( it { is_expected.to contain_file('/tmp/libvirt-secret-4f515eff-47e4-425c-b24d-9c6adc56401c.secret').with(
:ensure => 'file', :ensure => 'file',
:owner => 'root', :owner => 'root',
@@ -46,14 +43,9 @@ describe 'nova::compute::libvirt::secret_ceph' do
:mode => '0600', :mode => '0600',
:show_diff => false, :show_diff => false,
:require => 'Anchor[nova::config::begin]', :require => 'Anchor[nova::config::begin]',
:content => 'AQBHCbtT6APDHhAA5W00cBchwkQjh3dkKsyPjw==',
)} )}
it {
verify_contents(catalogue, '/tmp/libvirt-secret-4f515eff-47e4-425c-b24d-9c6adc56401c.secret', [
"AQBHCbtT6APDHhAA5W00cBchwkQjh3dkKsyPjw==",
])
}
it { is_expected.to contain_exec('get-or-set virsh secret 4f515eff-47e4-425c-b24d-9c6adc56401c').with( it { is_expected.to contain_exec('get-or-set virsh secret 4f515eff-47e4-425c-b24d-9c6adc56401c').with(
:command => [ :command => [
'/usr/bin/virsh', 'secret-define', '--file', '/tmp/libvirt-secret-4f515eff-47e4-425c-b24d-9c6adc56401c.xml', '/usr/bin/virsh', 'secret-define', '--file', '/tmp/libvirt-secret-4f515eff-47e4-425c-b24d-9c6adc56401c.xml',

View File

@@ -4,28 +4,28 @@ providers:
# for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html # for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html
<% @custom_inventories.each do |provider| -%> <% @custom_inventories.each do |provider| -%>
- identification: - identification:
<% if provider['name'] -%> <%- if provider['name'] -%>
name: '<%= provider['name'] %>' name: '<%= provider['name'] %>'
<% elsif provider['uuid'] -%> <%- elsif provider['uuid'] -%>
uuid: '<%= provider['uuid'] %>' uuid: '<%= provider['uuid'] %>'
<% else -%> <%- else -%>
uuid: '$COMPUTE_NODE' uuid: '$COMPUTE_NODE'
<% end -%> <%- end -%>
<% unless provider['inventories'].nil? -%> <%- if !provider['inventories'].nil? -%>
inventories: inventories:
additional: additional:
<% provider['inventories'].each do |key,inventory| -%> <%- provider['inventories'].sort.each do |inventory| -%>
- <%= key %>: - <%= inventory[0] %>:
<% inventory.each do |key,value| -%> <%- inventory[1].sort.each do |resource| -%>
<%= key %>: <%= value %> <%= resource[0] %>: <%= resource[1] %>
<% end -%> <%- end -%>
<% end -%> <%- end -%>
<% end -%> <%- end -%>
<% unless provider['traits'].nil? -%> <%- if !provider['traits'].nil? -%>
traits: traits:
additional: additional:
<% provider['traits'].each do |trait| -%> <%- provider['traits'].each do |trait| -%>
- '<%= trait %>' - '<%= trait %>'
<% end -%> <%- end -%>
<% end -%> <%- end -%>
<% end -%> <%- end -%>