Browse Source

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
changes/38/613138/2
Alex Schultz 4 years ago
parent
commit
3d877926f0
  1. 10
      lib/puppet/parser/functions/to_array_of_json_strings.rb
  2. 6
      spec/classes/nova_migration_libvirt_spec.rb

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

6
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

Loading…
Cancel
Save