diff --git a/lib/puppet/provider/zfs/solaris.rb b/lib/puppet/provider/zfs/solaris.rb index 9aec9d801..b783f9e01 100644 --- a/lib/puppet/provider/zfs/solaris.rb +++ b/lib/puppet/provider/zfs/solaris.rb @@ -1,45 +1,45 @@ Puppet::Type.type(:zfs).provide(:solaris) do desc "Provider for Solaris zfs." commands :zfs => "/usr/sbin/zfs" defaultfor :operatingsystem => :solaris def add_properties properties = [] Puppet::Type.type(:zfs).validproperties.each do |property| next if property == :ensure if value = @resource[property] and value != "" properties << "-o" << "#{property}=#{value}" end end properties end def create zfs *([:create] + add_properties + [@resource[:name]]) end def destroy zfs(:destroy, @resource[:name]) end def exists? if zfs(:list).split("\n").detect { |line| line.split("\s")[0] == @resource[:name] } true else false end end - [:mountpoint, :recordsize, :aclmode, :aclinherit, :primarycache, :secondarycache, :compression, :copies, :quota, :reservation, :sharenfs, :snapdir].each do |field| + [:aclinherit, :aclmode, :atime, :canmount, :checksum, :compression, :copies, :devices, :exec, :logbias, :mountpoint, :nbmand, :primarycache, :quota, :readonly, :recordsize, :refquota, :refreservation, :reservation, :secondarycache, :setuid, :shareiscsi, :sharenfs, :sharesmb, :snapdir, :version, :volsize, :vscan, :xattr, :zoned, :vscan].each do |field| define_method(field) do zfs(:get, "-H", "-o", "value", field, @resource[:name]).strip end define_method(field.to_s + "=") do |should| zfs(:set, "#{field}=#{should}", @resource[:name]) end end end diff --git a/lib/puppet/type/zfs.rb b/lib/puppet/type/zfs.rb old mode 100755 new mode 100644 index 7123f8ac9..75f821787 --- a/lib/puppet/type/zfs.rb +++ b/lib/puppet/type/zfs.rb @@ -1,72 +1,144 @@ module Puppet newtype(:zfs) do @doc = "Manage zfs. Create destroy and set properties on zfs instances. **Autorequires:** If Puppet is managing the zpool at the root of this zfs instance, the zfs resource will autorequire it. If Puppet is managing any parent zfs instances, the zfs resource will autorequire them." ensurable newparam(:name) do desc "The full name for this filesystem. (including the zpool)" end - newproperty(:mountpoint) do - desc "The mountpoint property." - end - - newproperty(:recordsize) do - desc "The recordsize property." + newproperty(:aclinherit) do + desc "The aclinherit property. Values: discard | noallow | restricted | passthrough | passthrough-x" end newproperty(:aclmode) do - desc "The aclmode property." + desc "The aclmode property. Values: discard | groupmask | passthrough" end - newproperty(:aclinherit) do - desc "The aclinherit property." + newproperty(:atime) do + desc "The atime property. Values: on | off" end - newproperty(:primarycache) do - desc "The primarycache property." + newproperty(:canmount) do + desc "The canmount property. Values: on | off | noauto" end - newproperty(:secondarycache) do - desc "The secondarycache property." + newproperty(:checksum) do + desc "The checksum property. Values: on | off | fletcher2 | fletcher4 | sha256" end newproperty(:compression) do - desc "The compression property." + desc "The compression property. Values: on | off | lzjb | gzip | gzip-[1-9] | zle" end newproperty(:copies) do - desc "The copies property." + desc "The copies property. Values: 1 | 2 | 3" + end + + newproperty(:devices) do + desc "The devices property. Values: on | off" + end + + newproperty(:exec) do + desc "The exec property. Values: on | off" + end + + newproperty(:logbias) do + desc "The logbias property. Values: latency | throughput" + end + + newproperty(:mountpoint) do + desc "The mountpoint property. Values: | legacy | none" + end + + newproperty(:nbmand) do + desc "The nbmand property. Values: on | off" + end + + newproperty(:primarycache) do + desc "The primarycache property. Values: all | none | metadata" end newproperty(:quota) do - desc "The quota property." + desc "The quota property. Values: | none" + end + + newproperty(:readonly) do + desc "The readonly property. Values: on | off" + end + + newproperty(:recordsize) do + desc "The recordsize property. Values: 512 to 128k, power of 2" + end + + newproperty(:refquota) do + desc "The refquota property. Values: | none" + end + + newproperty(:refreservation) do + desc "The refreservation property. Values: | none" end newproperty(:reservation) do - desc "The reservation property." + desc "The reservation property. Values: | none" + end + + newproperty(:secondarycache) do + desc "The secondarycache property. Values: all | none | metadata" + end + + newproperty(:setuid) do + desc "The setuid property. Values: on | off" + end + + newproperty(:shareiscsi) do + desc "The shareiscsi property. Values: on | off | type=" end newproperty(:sharenfs) do - desc "The sharenfs property." + desc "The sharenfs property. Values: on | off | share(1M) options" + end + + newproperty(:sharesmb) do + desc "The sharesmb property. Values: on | off | sharemgr(1M) options" end newproperty(:snapdir) do - desc "The snapdir property." + desc "The snapdir property. Values: hidden | visible" + end + + newproperty(:version) do + desc "The version property. Values: 1 | 2 | 3 | 4 | current" + end + + newproperty(:volsize) do + desc "The volsize property. Values: " + end + + newproperty(:vscan) do + desc "The vscan property. Values: on | off" + end + + newproperty(:xattr) do + desc "The xattr property. Values: on | off" + end + + newproperty(:zoned) do + desc "The zoned property. Values: on | off" 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/provider/zfs/solaris_spec.rb b/spec/unit/provider/zfs/solaris_spec.rb index 4998ba6fe..84a2be9f6 100755 --- a/spec/unit/provider/zfs/solaris_spec.rb +++ b/spec/unit/provider/zfs/solaris_spec.rb @@ -1,99 +1,100 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') provider_class = Puppet::Type.type(:zfs).provider(:solaris) describe provider_class do before do @resource = stub("resource", :name => "myzfs") @resource.stubs(:[]).with(:name).returns "myzfs" @resource.stubs(:[]).returns "shouldvalue" @provider = provider_class.new(@resource) end it "should have a create method" do @provider.should respond_to(:create) end it "should have a destroy method" do @provider.should respond_to(:destroy) end it "should have an exists? method" do @provider.should respond_to(:exists?) end describe "when calling add_properties" do it "should add -o and the key=value for each properties with a value" do @resource.stubs(:[]).with(:quota).returns "" + @resource.stubs(:[]).with(:refquota).returns "" @resource.stubs(:[]).with(:mountpoint).returns "/foo" properties = @provider.add_properties properties.include?("-o").should == true properties.include?("mountpoint=/foo").should == true properties.detect { |a| a.include?("quota") }.should == nil end end describe "when calling create" do it "should call add_properties" do @provider.stubs(:zfs) @provider.expects(:add_properties).returns([]) @provider.create end it "should call zfs with create, properties and this zfs" do @provider.stubs(:add_properties).returns(%w{a b}) @provider.expects(:zfs).with(:create, "a", "b", @resource[:name]) @provider.create end end describe "when calling destroy" do it "should call zfs with :destroy and this zfs" do @provider.expects(:zfs).with(:destroy, @resource[:name]) @provider.destroy end end describe "when calling exist?" do it "should call zfs with :list" do #return stuff because we have to slice and dice it @provider.expects(:zfs).with(:list).returns("NAME USED AVAIL REFER MOUNTPOINT\nmyzfs 100K 27.4M /myzfs") @provider.exists? end it "should return true if returned values match the name" do @provider.stubs(:zfs).with(:list).returns("NAME USED AVAIL REFER MOUNTPOINT\n#{@resource[:name]} 100K 27.4M /myzfs") @provider.exists?.should == true end it "should return false if returned values don't match the name" do @provider.stubs(:zfs).with(:list).returns("no soup for you") @provider.exists?.should == false end end [:mountpoint, :recordsize, :aclmode, :aclinherit, :primarycache, :secondarycache, :compression, :copies, :quota, :reservation, :sharenfs, :snapdir].each do |prop| describe "when getting the #{prop} value" do it "should call zfs with :get, #{prop} and this zfs" do @provider.expects(:zfs).with(:get, "-H", "-o", "value", prop, @resource[:name]).returns("value\n") @provider.send(prop) end it "should get the third value of the second line from the output" do @provider.stubs(:zfs).with(:get, "-H", "-o", "value", prop, @resource[:name]).returns("value\n") @provider.send(prop).should == "value" end end describe "when setting the #{prop} value" do it "should call zfs with :set, #{prop}=value and this zfs" do @provider.expects(:zfs).with(:set, "#{prop}=value", @resource[:name]) @provider.send("#{prop}=".intern, "value") end end end end