From c034b19b52caf64fb45240a5a2f619f7bf119a01 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 15 Sep 2025 01:45:20 +0900 Subject: [PATCH] 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 --- spec/classes/nova_compute_provider_spec.rb | 208 +++++++++--------- .../nova_compute_libvirt_secret_ceph_spec.rb | 26 +-- templates/provider.yaml.erb | 34 +-- 3 files changed, 129 insertions(+), 139 deletions(-) diff --git a/spec/classes/nova_compute_provider_spec.rb b/spec/classes/nova_compute_provider_spec.rb index a20cfd3bf..9f785172f 100644 --- a/spec/classes/nova_compute_provider_spec.rb +++ b/spec/classes/nova_compute_provider_spec.rb @@ -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( < 'root', :mode => '0600', :require => 'Anchor[nova::config::begin]', + :content => < + + client.openstack + + 4f515eff-47e4-425c-b24d-9c6adc56401c + +EOS )} - it { - verify_contents(catalogue, '/tmp/libvirt-secret-4f515eff-47e4-425c-b24d-9c6adc56401c.xml', [ - "", - " ", - " client.openstack", - " ", - " 4f515eff-47e4-425c-b24d-9c6adc56401c", - "" - ]) - } - 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', diff --git a/templates/provider.yaml.erb b/templates/provider.yaml.erb index 8278698a6..b3772810f 100644 --- a/templates/provider.yaml.erb +++ b/templates/provider.yaml.erb @@ -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 -%>