Vendor any2array function to support stdlib 3.2
Many installations are pinned to stdlib 3.2. This change vendors the any2arry function from stdlib 4 until Puppet Enterprise catches up. At that point the vendored function will be removed. Change-Id: Ide8a9c526ba36a0641c0e118c3280be0e766bd14
This commit is contained in:
parent
da0cedce6f
commit
8115642f4d
@ -8,5 +8,5 @@ description 'Puppet module to install and configure the OpenStack Horizon dashb
|
||||
project_page 'https://launchpad.net/puppet-horizon'
|
||||
|
||||
dependency 'puppetlabs/apache', '>= 1.0.0 <2.0.0'
|
||||
dependency 'puppetlabs/stdlib', '>= 4.0.0'
|
||||
dependency 'puppetlabs/stdlib', '>= 3.2.0'
|
||||
dependency 'saz/memcached', '>= 2.0.2 <3.0.0'
|
||||
|
34
lib/puppet/parser/functions/os_any2array.rb
Normal file
34
lib/puppet/parser/functions/os_any2array.rb
Normal file
@ -0,0 +1,34 @@
|
||||
#
|
||||
# os_any2array.rb
|
||||
#
|
||||
# TODO: Remove this function when puppetlabs-stdlib 4.0.0 is in wider use
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:os_any2array, :type => :rvalue, :doc => <<-EOS
|
||||
This converts any object to an array containing that object. Empty argument
|
||||
lists are converted to an empty array. Arrays are left untouched. Hashes are
|
||||
converted to arrays of alternating keys and values.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if arguments.empty?
|
||||
return []
|
||||
end
|
||||
|
||||
if arguments.length == 1
|
||||
if arguments[0].kind_of?(Array)
|
||||
return arguments[0]
|
||||
elsif arguments[0].kind_of?(Hash)
|
||||
result = []
|
||||
arguments[0].each do |key, value|
|
||||
result << key << value
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
return arguments
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -123,7 +123,7 @@ class horizon::wsgi::apache (
|
||||
$default_vhost_conf = {
|
||||
ip => $bind_address,
|
||||
servername => $servername,
|
||||
serveraliases => any2array($fqdn),
|
||||
serveraliases => os_any2array($fqdn),
|
||||
docroot => '/var/www/',
|
||||
access_log_file => 'horizon_access.log',
|
||||
error_log_file => 'horizon_error.log',
|
||||
|
55
spec/unit/puppet/parser/functions/os_any2array_spec.rb
Normal file
55
spec/unit/puppet/parser/functions/os_any2array_spec.rb
Normal file
@ -0,0 +1,55 @@
|
||||
#! /usr/bin/env ruby -S rspec
|
||||
require 'spec_helper'
|
||||
|
||||
describe "the os_any2array function" do
|
||||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||||
|
||||
it "should exist" do
|
||||
Puppet::Parser::Functions.function("os_any2array").should == "function_os_any2array"
|
||||
end
|
||||
|
||||
it "should return an empty array if there is less than 1 argument" do
|
||||
result = scope.function_os_any2array([])
|
||||
result.should(eq([]))
|
||||
end
|
||||
|
||||
it "should convert boolean true to [ true ] " do
|
||||
result = scope.function_os_any2array([true])
|
||||
result.should(eq([true]))
|
||||
end
|
||||
|
||||
it "should convert one object to [object]" do
|
||||
result = scope.function_os_any2array(['one'])
|
||||
result.should(eq(['one']))
|
||||
end
|
||||
|
||||
it "should convert multiple objects to [objects]" do
|
||||
result = scope.function_os_any2array(['one', 'two'])
|
||||
result.should(eq(['one', 'two']))
|
||||
end
|
||||
|
||||
it "should return empty array it was called with" do
|
||||
result = scope.function_os_any2array([[]])
|
||||
result.should(eq([]))
|
||||
end
|
||||
|
||||
it "should return one-member array it was called with" do
|
||||
result = scope.function_os_any2array([['string']])
|
||||
result.should(eq(['string']))
|
||||
end
|
||||
|
||||
it "should return multi-member array it was called with" do
|
||||
result = scope.function_os_any2array([['one', 'two']])
|
||||
result.should(eq(['one', 'two']))
|
||||
end
|
||||
|
||||
it "should return members of a hash it was called with" do
|
||||
result = scope.function_os_any2array([{ 'key' => 'value' }])
|
||||
result.should(eq(['key', 'value']))
|
||||
end
|
||||
|
||||
it "should return an empty array if it was called with an empty hash" do
|
||||
result = scope.function_os_any2array([{ }])
|
||||
result.should(eq([]))
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user