From da69e6bd4faa30224af8d759fffa9a9d8782c8d7 Mon Sep 17 00:00:00 2001 From: Sergey Kolekonov Date: Tue, 19 Apr 2016 16:52:24 +0300 Subject: [PATCH] Make allocated_hugepages compatible with Ruby 2.0 To make allocated_hugepages fact compatible with different Ruby versions (1.9.3, 2.0) it's safer to return a hash as JSON and then parse to avoid different types conversion Change-Id: If7adadd2de2cc7154281a0d9cbadf825dffe5d2c Closes-bug: #1572110 (cherry picked from commit fb899cc93c4583ae8ad90044aeb2a8901e427211) --- .../openstack_tasks/lib/facter/allocated_hugepages.rb | 2 +- .../puppet/openstack_tasks/manifests/roles/compute.pp | 5 +++-- tests/noop/spec/hosts/roles/compute_spec.rb | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/deployment/puppet/openstack_tasks/lib/facter/allocated_hugepages.rb b/deployment/puppet/openstack_tasks/lib/facter/allocated_hugepages.rb index f94eee6e69..1052466b70 100644 --- a/deployment/puppet/openstack_tasks/lib/facter/allocated_hugepages.rb +++ b/deployment/puppet/openstack_tasks/lib/facter/allocated_hugepages.rb @@ -13,6 +13,6 @@ end Facter.add(:allocated_hugepages) do setcode do - hugepages + hugepages.to_json end end diff --git a/deployment/puppet/openstack_tasks/manifests/roles/compute.pp b/deployment/puppet/openstack_tasks/manifests/roles/compute.pp index 3c47cda279..5aedbd2d93 100644 --- a/deployment/puppet/openstack_tasks/manifests/roles/compute.pp +++ b/deployment/puppet/openstack_tasks/manifests/roles/compute.pp @@ -52,8 +52,9 @@ class openstack_tasks::roles::compute { $ssl_hash = hiera_hash('use_ssl', {}) $node_hash = hiera_hash('node', {}) $use_huge_pages = pick($node_hash['nova_hugepages_enabled'], false) - $use_2m_huge_pages = $::allocated_hugepages['2M'] - $use_1g_huge_pages = $::allocated_hugepages['1G'] + $allocated_hugepages = parsejson($::allocated_hugepages) + $use_2m_huge_pages = $allocated_hugepages['2M'] + $use_1g_huge_pages = $allocated_hugepages['1G'] $libvirt_type = hiera('libvirt_type', undef) $kombu_compression = hiera('kombu_compression', '') diff --git a/tests/noop/spec/hosts/roles/compute_spec.rb b/tests/noop/spec/hosts/roles/compute_spec.rb index 2160bfcd59..53fe4b8d12 100644 --- a/tests/noop/spec/hosts/roles/compute_spec.rb +++ b/tests/noop/spec/hosts/roles/compute_spec.rb @@ -26,7 +26,7 @@ describe manifest do let(:facts) { Noop.ubuntu_facts.merge({ :libvirt_uuid => '0251bf3e0a3f48da8cdf8daad5473a7f', - :allocated_hugepages => {'2M' => true, '1G' => true}, + :allocated_hugepages => '{"1G":true,"2M":true}', }) } @@ -180,8 +180,9 @@ describe manifest do let(:node_hash) { Noop.hiera_hash 'node' } let(:enable_hugepages) { node_hash.fetch('nova_hugepages_enabled', false) } let(:enable_cpu_pinning) { node_hash.fetch('nova_cpu_pinning_enabled', false) } - let(:use_1g_huge_pages) { facts[:allocated_hugepages]['1G'] } - let(:use_2m_huge_pages) { facts[:allocated_hugepages]['2M'] } + let(:allocated_hugepages) { Noop.puppet_function 'parsejson', facts[:allocated_hugepages] } + let(:use_1g_huge_pages) { allocated_hugepages['1G'] } + let(:use_2m_huge_pages) { allocated_hugepages['2M'] } it 'should configure vcpu_pin_set for nova' do if enable_cpu_pinning