diff --git a/lib/puppet/type/zfs.rb b/lib/puppet/type/zfs.rb index d3af3a461..3a8806a5e 100755 --- a/lib/puppet/type/zfs.rb +++ b/lib/puppet/type/zfs.rb @@ -1,45 +1,51 @@ module Puppet newtype(:zfs) do @doc = "Manage zfs. Create destroy and set properties on zfs instances." ensurable newparam(:name) do desc "The full name for this filesystem. (including the zpool)" end newproperty(:mountpoint) do desc "The mountpoint property." end newproperty(:compression) do desc "The compression property." end newproperty(:copies) do desc "The copies property." end newproperty(:quota) do desc "The quota property." end newproperty(:reservation) do desc "The reservation property." end newproperty(:sharenfs) do desc "The sharenfs property." end newproperty(:snapdir) do desc "The sharenfs property." end autorequire(:zpool) do #strip the zpool off the zfs name and autorequire it [@parameters[:name].value.split('/')[0]] end + + autorequire(:zfs) do + #slice and dice, we want all the zfs before this one + names = @parameters[:name].value.split('/') + names.slice(1..-2).inject([]) { |a,v| a << "#{a.last}/#{v}" }.collect { |fs| names[0] + fs } + end end end diff --git a/spec/unit/type/zfs.rb b/spec/unit/type/zfs.rb index 434415e24..bce6500b1 100755 --- a/spec/unit/type/zfs.rb +++ b/spec/unit/type/zfs.rb @@ -1,28 +1,45 @@ #!/usr/bin/env ruby Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } zpool = Puppet::Type.type(:zfs) describe zpool do before do @provider = stub 'provider' @resource = stub 'resource', :resource => nil, :provider => @provider, :line => nil, :file => nil end properties = [:ensure, :mountpoint, :compression, :copies, :quota, :reservation, :sharenfs, :snapdir] properties.each do |property| it "should have a %s property" % property do zpool.attrclass(property).ancestors.should be_include(Puppet::Property) end end parameters = [:name] parameters.each do |parameter| it "should have a %s parameter" % parameter do zpool.attrclass(parameter).ancestors.should be_include(Puppet::Parameter) end end + + it "should autorequire the containing zfss and the zpool" do + #this is a little funky because the autorequire depends on a property with a feature + foo_pool = Puppet.type(:zpool).create(:name => "foo") + + foo_bar_zfs = Puppet.type(:zfs).create(:name => "foo/bar") + foo_bar_baz_zfs = Puppet.type(:zfs).create(:name => "foo/bar/baz") + foo_bar_baz_buz_zfs = Puppet.type(:zfs).create(:name => "foo/bar/baz/buz") + + config = Puppet::Node::Catalog.new :testing do |conf| + [foo_pool, foo_bar_zfs, foo_bar_baz_zfs, foo_bar_baz_buz_zfs].each { |resource| conf.add_resource resource } + end + + req = foo_bar_baz_buz_zfs.autorequire.collect { |edge| edge.source.ref } + + [foo_pool.ref, foo_bar_zfs.ref, foo_bar_baz_zfs.ref].each { |ref| req.include?(ref).should == true } + end end