From 3d877926f09d9c0c0f331025256c4b55214c1269 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Wed, 24 Oct 2018 12:17:55 -0600 Subject: [PATCH] Fixup functions for 5.5.7+ Recent changes to Puppet (5.5.7+) has broken some of the legacy function items we were doing in puppet-nova. We'll likely need to update all the functions to the new syntax but for now this change is to address current issues. Change-Id: If1d675cec6fe64e8a812fb638078b0ab1c66b5de Closes-Bug: #1799757 --- .../parser/functions/to_array_of_json_strings.rb | 10 +--------- spec/classes/nova_migration_libvirt_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/puppet/parser/functions/to_array_of_json_strings.rb b/lib/puppet/parser/functions/to_array_of_json_strings.rb index 3a6cd26aa..72e3206d9 100644 --- a/lib/puppet/parser/functions/to_array_of_json_strings.rb +++ b/lib/puppet/parser/functions/to_array_of_json_strings.rb @@ -1,13 +1,5 @@ require 'json' -def array_of_hash?(list) - return false unless list.class == Array - list.each do |e| - return false unless e.class == Hash - end - true -end - module Puppet::Parser::Functions newfunction(:to_array_of_json_strings, :arity =>1, :type => :rvalue, :doc => "Convert input array of hashes (optionally JSON encoded) to a puppet Array of JSON encoded Strings") do |arg| @@ -26,7 +18,7 @@ module Puppet::Parser::Functions raise Puppet::ParseError, "Syntax error: #{arg[0]} is not valid" end end - unless array_of_hash?(list) + unless list.class == Array or (list.each { |e| return false unless e.class == Hash }) raise Puppet::ParseError, "Syntax error: #{arg[0]} is not an Array or JSON encoded String" end rv = [] diff --git a/spec/classes/nova_migration_libvirt_spec.rb b/spec/classes/nova_migration_libvirt_spec.rb index 79a66fff9..d500d2340 100644 --- a/spec/classes/nova_migration_libvirt_spec.rb +++ b/spec/classes/nova_migration_libvirt_spec.rb @@ -23,7 +23,7 @@ require 'spec_helper' describe 'nova::migration::libvirt' do generate = {} - + # needed for Puppet 4.x before(:each) { Puppet::Parser::Functions.newfunction(:generate, :type => :rvalue) { |args| generate.call() @@ -31,8 +31,10 @@ describe 'nova::migration::libvirt' do generate.stubs(:call).returns('0000-111-111') } + # function here is needed for Puppet 5.5.7+ let :pre_condition do - 'include nova + 'function generate($a, $b) { return "0000-111-111" } + include nova include nova::compute include nova::compute::libvirt' end