Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature/hash merging #14

Closed
wants to merge 11 commits into from

1 participant

@haf
Collaborator

Let's continue the discussion about the code that I am changing in this issue/PR.

Takes over discussions from #8.

haf added some commits
@haf haf adding initial implementation of function 8406014
@haf haf a unit test for the new function.
Unfortunately Puppet doesn't install nicely on Windows,
so I can't run the tests at this moment.
aebdbd9
@haf haf using new function: merge_hashes.
Relates to issue #8.

@jsmartin, @andrewjstone, @Iristyle - could you please verify that this branch
solves the problem?
064c0fd
@haf haf Moving merge_hashes file to the correct location. Issue #8 7a24f35
@haf haf moving array check to top fb8b683
haf added some commits
@haf haf Merge pull request #17 from basho/feature/ulimit-centos
ulimit simple implementation

This relates to issue #13 - @Iristyle - could you check which of the options - `/etc/default/riak` or `/etc/pam.d/common-session` should be used and whether that differs between versions of debian/ubuntu?
cbffe46
@haf haf upgraded vagrantfile f622dfa
@haf haf Merge remote-tracking branch 'origin/feature/hash-merging' into maint…
…/upgrade-vagrant
698b1eb
@haf haf working merging c45db72
@haf
Collaborator

Works on my (virtual) machine.

@haf haf closed this pull request from a commit
@haf haf Merge branch 'feature/hash-merging'
Fixes #14, related to #8.

Cheerio to: @andrewjstone, @Iristyle, @antonlindstrom - I have tried this
on my virtual machine and it overrides.

One case I don't have a really good solution for right now, is overriding
IPs, like this:

``` puppet
node default {
  class { 'riak':
    cfg => {
      riak_core => {
        http => {
          '__string_10.42.0.6' => 8098
        }
      }
    }
  }
}
```

then you will get a config like this, due to the defaults:

``` erlang
[ ...
  {riak_core, [
    {dtrace_support, false},
    {handoff_port, 8099},
    {http, [
      {"10.0.2.15", 8098},
      {"10.42.0.6", 8098}
    ]},
  ...
]
```

i.e. I miss a way to delete defaults over than overwriting the key. Perhaps
adding an option to merge_hashes(kvs1, kvs2, blast_level), where blast_level
removes all other keys than those passed in kvs2 from the level = blast_level
and downwards.
0aed80f
@haf haf closed this in 0aed80f
@mjbrender mjbrender deleted the feature/hash-merging branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2013
  1. @haf
  2. @haf

    a unit test for the new function.

    haf authored
    Unfortunately Puppet doesn't install nicely on Windows,
    so I can't run the tests at this moment.
  3. @haf

    using new function: merge_hashes.

    haf authored
    Relates to issue #8.
    
    @jsmartin, @andrewjstone, @Iristyle - could you please verify that this branch
    solves the problem?
Commits on Mar 28, 2013
  1. @haf
  2. @haf

    moving array check to top

    haf authored
Commits on Apr 4, 2013
  1. @haf

    Merge pull request #17 from basho/feature/ulimit-centos

    haf authored
    ulimit simple implementation
    
    This relates to issue #13 - @Iristyle - could you check which of the options - `/etc/default/riak` or `/etc/pam.d/common-session` should be used and whether that differs between versions of debian/ubuntu?
Commits on Apr 11, 2013
  1. @haf

    upgraded vagrantfile

    haf authored
  2. @haf
  3. @haf

    working merging

    haf authored
  4. @haf

    ignore dotfiles

    haf authored
  5. @haf

    properly mapping folders

    haf authored
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -10,3 +10,4 @@ files/packages/
graphs/
metadata.json
.project
+*.dot
View
30 Vagrantfile
@@ -3,25 +3,22 @@
require 'fileutils'
-Vagrant::Config.run do |config|
+Vagrant.configure("2") do |config|
# choices for virtual machines:
#config.vm.box = 'precise64'
#config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
#config.vm.box = 'debian-6.0'
#config.vm.box_url = 'http://puppetlabs.s3.amazonaws.com/pub/Squeeze64.box'
- config.vm.box = 'centos 6.3'
- config.vm.box_url = 'https://dl.dropbox.com/u/7225008/Vagrant/CentOS-6.3-x86_64-minimal.box'
+ config.vm.box = 'CentOS-6.3_x86_64-small'
+ config.vm.box_url = 'https://1412126a-vagrant.s3.amazonaws.com/CentOS-6.3-x86_64-reallyminimal.box'
- config.vm.share_folder 'riak-module', "#{FileUtils.pwd}", "."
+ config.vm.synced_folder ".", "/etc/puppet/modules/riak"
- # Plugins:
- #config.hiera.config_path = './tests/config'
- #config.hiera.config_file = 'vagrant-hiera.yaml'
- #config.hiera.data_path = './tests/data'
- #config.hiera.apt_opts = ''
-
- config.vbguest.auto_update = false
+ # give all nodes a little bit more memory:
+ config.vm.provider "virtualbox" do |v|
+ v.customize ["modifyvm", :id, "--memory", 1024]
+ end
# specify all Riak VMs:
nodes = 1
@@ -30,21 +27,18 @@ Vagrant::Config.run do |config|
ip = "10.42.0.#{baseip + n.to_i}"
name = "riak-#{n}.local"
config.vm.define name do |cfg|
- cfg.vm.host_name = name
- cfg.vm.network :hostonly, ip
-
- # give all nodes a little bit more memory:
- cfg.vm.customize ["modifyvm", :id, "--memory", 1024]
+ #cfg.vm.host_name = name
+ cfg.vm.network :private_network, ip: "#{ip}"
#get those gems installed
- cfg.vm.provision :shell, :path => "shellprovision/bootstrap.sh"
+ #cfg.vm.provision :shell, :path => "shellprovision/bootstrap.sh"
# specify puppet for provisioning
cfg.vm.provision :puppet do |puppet|
puppet.manifests_path = File.join 'spec', 'fixtures', 'manifests'
puppet.module_path = File.join 'spec', 'fixtures', 'modules'
puppet.manifest_file = 'vagrant-riak.pp'
# '--trace', '--debug', '--verbose',
- puppet.options = ['--trace', '--debug', '--verbose','--graph', '--graphdir /vagrant/graphs/']
+ puppet.options = ['--trace', '--debug', '--verbose','--graph', '--graphdir /vagrant']
end
end
View
21 lib/puppet/parser/functions/merge_hashes.rb
@@ -0,0 +1,21 @@
+require File.join(File.dirname(__FILE__), '/../util/merger')
+
+module Puppet::Parser::Functions
+ newfunction(:merge_hashes, :type => :rvalue, :doc => <<-DOC) do |*args|
+ Merge two hierarchial hashes together, keeping
+ values from the first hash which are not overridden in the second
+ hash, while adding values not existent in the first hash from the second
+ hash, to produce a final hash. Have a look at the source code
+ for further comments and documentation.
+ DOC
+
+ if args[0].is_a? Array
+ args = args[0]
+ end
+
+ raise(Puppet::ParseError, "merge_hashes/2: Wrong number of arguments " +
+ "given (#{args.size} instead of 2.)") unless args.size == 2
+
+ ::Puppet::Parser::Util::Merger.new(args[0], args[1]).compute
+ end
+end
View
1  lib/puppet/parser/functions/write_erl_args.rb
@@ -18,6 +18,5 @@ module Puppet::Parser::Functions
s = (args.length == 2 && args[1]) || :pp # symbol
::Puppet::Parser::Util::Args.new(h).send(s)
-
end
end
View
35 lib/puppet/parser/util/merger.rb
@@ -0,0 +1,35 @@
+module Puppet::Parser::Util
+ class Merger
+
+ attr_reader :h1, :h2
+
+ def initialize h1, h2
+ @h1, @h2 = h1, h2
+ raise ArgumentError unless is_hashish?(h1)
+ raise ArgumentError unless is_hashish?(h2)
+ end
+ def compute
+ compute_inner h1, h2
+ end
+ def compute_inner kvs1, kvs2
+ # if kvs2 didn't have value, return kvs1
+ return kvs1 if kvs2.nil?
+
+ merged = kvs1.map { |k, v|
+ # recurse on those keys that have hashish values
+ is_hashish?(v) && is_hashish?(kvs2.fetch(k, nil)) ?
+ # recurse
+ [k, compute_inner(v, kvs2.fetch(k, nil))] :
+ # get the value from kvs2, defaulting to value from kvs1
+ [k, kvs2.fetch(k, v)]
+ # union merge all items of kvs2
+ } | kvs2.reject { |k, v| kvs1.has_key? k }.to_a
+
+ Hash[ merged ]
+ end
+ def is_hashish? thing
+ return false if thing.nil?
+ [:each, :fetch, :"has_key?", :reject].all? { |m| thing.respond_to? m }
+ end
+ end
+end
View
2  manifests/appconfig.pp
@@ -33,7 +33,7 @@
# merge the given $cfg parameter with the default,
# favoring the givens, rather than the defaults
- $appcfg = merge({
+ $appcfg = merge_hashes({
kernel => {
inet_dist_listen_min => 6000,
inet_dist_listen_max => 7999,
View
7 spec/functions/merge_hashes.rb
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe 'merge_hashes', :type => :puppet_function do
+ let(:kvs1) { { :a => 1, :b => { :c => { :x => 2 }, :d => 3, :z => 4 } } }
+ let(:kvs2) { { :b => { :c => { :x => 5 }, :d => 6 }, :e => 7 } }
+ it { subject.call([ kvs1, kvs2 ]).should eq({:a=>1, :b=>{:c=>{:x=>5}, :d=>6, :z=>4}, :e=>7}) }
+end
Something went wrong with that request. Please try again.