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

View File

@@ -26,19 +26,16 @@ describe 'nova::compute::libvirt::secret_ceph' do
:group => 'root',
:mode => '0600',
: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(
:ensure => 'file',
:owner => 'root',
@@ -46,14 +43,9 @@ describe 'nova::compute::libvirt::secret_ceph' do
:mode => '0600',
:show_diff => false,
: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(
:command => [
'/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
<% @custom_inventories.each do |provider| -%>
- identification:
<% if provider['name'] -%>
<%- if provider['name'] -%>
name: '<%= provider['name'] %>'
<% elsif provider['uuid'] -%>
<%- elsif provider['uuid'] -%>
uuid: '<%= provider['uuid'] %>'
<% else -%>
<%- else -%>
uuid: '$COMPUTE_NODE'
<% end -%>
<% unless provider['inventories'].nil? -%>
<%- end -%>
<%- if !provider['inventories'].nil? -%>
inventories:
additional:
<% provider['inventories'].each do |key,inventory| -%>
- <%= key %>:
<% inventory.each do |key,value| -%>
<%= key %>: <%= value %>
<% end -%>
<% end -%>
<% end -%>
<% unless provider['traits'].nil? -%>
<%- provider['inventories'].sort.each do |inventory| -%>
- <%= inventory[0] %>:
<%- inventory[1].sort.each do |resource| -%>
<%= resource[0] %>: <%= resource[1] %>
<%- end -%>
<%- end -%>
<%- end -%>
<%- if !provider['traits'].nil? -%>
traits:
additional:
<% provider['traits'].each do |trait| -%>
<%- provider['traits'].each do |trait| -%>
- '<%= trait %>'
<% end -%>
<% end -%>
<% end -%>
<%- end -%>
<%- end -%>
<%- end -%>