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
(cherry picked from commit 3d877926f0)
This commit is contained in:
Alex Schultz 2018-10-24 12:17:55 -06:00
parent 8ab435c9e2
commit c40a994fe2
2 changed files with 5 additions and 11 deletions

View File

@ -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 = []

View File

@ -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