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:
Chris Hoge 2014-05-01 14:51:23 -07:00
parent da0cedce6f
commit 8115642f4d
4 changed files with 91 additions and 2 deletions

View File

@ -8,5 +8,5 @@ description 'Puppet module to install and configure the OpenStack Horizon dashb
project_page 'https://launchpad.net/puppet-horizon' project_page 'https://launchpad.net/puppet-horizon'
dependency 'puppetlabs/apache', '>= 1.0.0 <2.0.0' 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' dependency 'saz/memcached', '>= 2.0.2 <3.0.0'

View 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 :

View File

@ -123,7 +123,7 @@ class horizon::wsgi::apache (
$default_vhost_conf = { $default_vhost_conf = {
ip => $bind_address, ip => $bind_address,
servername => $servername, servername => $servername,
serveraliases => any2array($fqdn), serveraliases => os_any2array($fqdn),
docroot => '/var/www/', docroot => '/var/www/',
access_log_file => 'horizon_access.log', access_log_file => 'horizon_access.log',
error_log_file => 'horizon_error.log', error_log_file => 'horizon_error.log',

View 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