summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Shubin <james@shubin.ca>2014-10-21 14:15:40 -0400
committerJames Shubin <james@shubin.ca>2014-10-21 14:15:40 -0400
commit06af205a562d543bbeb7c4d5c55143ade3bdb4e6 (patch)
treef54817a7c0ec6024c67e0164a95f35306030878f
parente99afc506680bdb9225fe0473cbf366aad451d23 (diff)
downloadpuppet-gluster-06af205a562d543bbeb7c4d5c55143ade3bdb4e6.tar.gz
puppet-gluster-06af205a562d543bbeb7c4d5c55143ade3bdb4e6.tar.xz
puppet-gluster-06af205a562d543bbeb7c4d5c55143ade3bdb4e6.zip
Split brick_str_to_hash into separate function.
This should work around a regression introduced in a recent version of puppet. (Perhaps 3.7.1?) Allowing custom helper functions in ruby was apparently never "supposed" to work, and was removed silently... :( binford2k: it was an accidental loophole got closed during code cleanup The bug about this issue is: https://tickets.puppetlabs.com/browse/PUP-3404 Thanks to binford2k for tracking down this bug. His URL finding skills are impeccable! Thanks to my puppet-gluster users for finding the issue!
-rw-r--r--lib/puppet/parser/functions/brick_layout_chained.rb20
-rw-r--r--lib/puppet/parser/functions/brick_layout_simple.rb17
-rw-r--r--lib/puppet/parser/functions/brick_str_to_hash.rb48
3 files changed, 53 insertions, 32 deletions
diff --git a/lib/puppet/parser/functions/brick_layout_chained.rb b/lib/puppet/parser/functions/brick_layout_chained.rb
index 18d5ef3..ce27230 100644
--- a/lib/puppet/parser/functions/brick_layout_chained.rb
+++ b/lib/puppet/parser/functions/brick_layout_chained.rb
@@ -29,6 +29,7 @@ module Puppet::Parser::Functions
ENDHEREDOC
Puppet::Parser::Functions.function('warning') # load function
+ Puppet::Parser::Functions.function('brick_str_to_hash') # load function
# signature: replica, bricks -> bricks
unless args.length == 2
raise Puppet::ParseError, "brick_layout_chained(): wrong number of arguments (#{args.length}; must be 2)"
@@ -44,23 +45,6 @@ module Puppet::Parser::Functions
replica = args[0].to_i # convert from string if needed
bricks = args[1]
- # TODO: these functions could be in separate puppet files
- # eg: Puppet::Parser::Functions.function('myfunc')
- # function_myfunc(...)
- def brick_str_to_hash(bricks)
- # this loop converts brick strings to brick dict's...
- result = []
- bricks.each do |x|
- a = x.split(':')
- #assert a.length == 2 # TODO
- p = a[1]
- p = ((p[-1, 1] == '/') ? p : (p+'/')) # endswith
-
- result.push({'host'=> a[0], 'path'=> p})
- end
- return result
- end
-
def get_hostlist(bricks)
hosts = []
bricks.each do |x|
@@ -99,7 +83,7 @@ module Puppet::Parser::Functions
final = []
pointer = 0
- parsed = brick_str_to_hash(bricks)
+ parsed = function_brick_str_to_hash([bricks])
# TODO: there should probably be a proper 'sorted' function for
# hostnames, in case they aren't numbered sanely _WITH_ padding.
hosts = get_hostlist(parsed).sort
diff --git a/lib/puppet/parser/functions/brick_layout_simple.rb b/lib/puppet/parser/functions/brick_layout_simple.rb
index d91a472..761b58e 100644
--- a/lib/puppet/parser/functions/brick_layout_simple.rb
+++ b/lib/puppet/parser/functions/brick_layout_simple.rb
@@ -34,6 +34,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ Puppet::Parser::Functions.function('brick_str_to_hash') # load function
+
# signature: replica, bricks -> bricks
unless args.length == 2
raise Puppet::ParseError, "brick_layout_simple(): wrong number of arguments (#{args.length}; must be 2)"
@@ -52,22 +54,9 @@ module Puppet::Parser::Functions
# TODO: these functions could be in separate puppet files
# eg: Puppet::Parser::Functions.function('myfunc')
# function_myfunc(...)
- def brick_str_to_hash(bricks)
- # this loop converts brick strings to brick dict's...
- result = []
- bricks.each do |x|
- a = x.split(':')
- #assert a.length == 2 # TODO
- p = a[1]
- p = ((p[-1, 1] == '/') ? p : (p+'/')) # endswith
-
- result.push({'host'=> a[0], 'path'=> p})
- end
- return result
- end
collect = {}
- parsed = brick_str_to_hash(bricks)
+ parsed = function_brick_str_to_hash([bricks])
parsed.each do |x|
key = x['host']
val = x['path']
diff --git a/lib/puppet/parser/functions/brick_str_to_hash.rb b/lib/puppet/parser/functions/brick_str_to_hash.rb
new file mode 100644
index 0000000..c33bd93
--- /dev/null
+++ b/lib/puppet/parser/functions/brick_str_to_hash.rb
@@ -0,0 +1,48 @@
+# GlusterFS module by James
+# Copyright (C) 2010-2013+ James Shubin
+# Written by James Shubin <james@shubin.ca>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+module Puppet::Parser::Functions
+ newfunction(:brick_str_to_hash, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ Helper function for the brick layout algorithms.
+
+ ENDHEREDOC
+
+ # signature: replica, bricks -> bricks
+ unless args.length == 1
+ raise Puppet::ParseError, "brick_str_to_hash(): wrong number of arguments (#{args.length}; must be 1)"
+ end
+ unless args[0].is_a?(Array)
+ raise Puppet::ParseError, "brick_str_to_hash(): expects the first argument to be an array, got #{args[0].inspect} which is of type #{args[0].class}"
+ end
+
+ bricks = args[0]
+ # this loop converts brick strings to brick dict's...
+ result = []
+ bricks.each do |x|
+ a = x.split(':')
+ #assert a.length == 2 # TODO
+ p = a[1]
+ p = ((p[-1, 1] == '/') ? p : (p+'/')) # endswith
+
+ result.push({'host'=> a[0], 'path'=> p})
+ end
+
+ result # return
+ end
+end
+
+# vim: ts=8