diff --git a/lib/puppet/provider/zfs/solaris.rb b/lib/puppet/provider/zfs/solaris.rb index 4d382cfad..256e4e9b4 100644 --- a/lib/puppet/provider/zfs/solaris.rb +++ b/lib/puppet/provider/zfs/solaris.rb @@ -1,56 +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 arrayify_second_line_on_whitespace(text) - if second_line = text.split("\n")[1] - second_line.split("\s") - else - [] - end - end - def create zfs *([:create] + add_properties + [@resource[:name]]) end def delete 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, :compression, :copies, :quota, :reservation, :sharenfs, :snapdir].each do |field| define_method(field) do - #special knowledge of format - #the command returns values in this format with the header - #NAME PROPERTY VALUE SOURCE - arrayify_second_line_on_whitespace(zfs(:get, field, @resource[:name]))[2] + 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/spec/unit/provider/zfs/solaris.rb b/spec/unit/provider/zfs/solaris.rb index 63aefcdc4..9189e44f0 100755 --- a/spec/unit/provider/zfs/solaris.rb +++ b/spec/unit/provider/zfs/solaris.rb @@ -1,87 +1,87 @@ #!/usr/bin/env ruby require 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 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(: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 delete" do it "should call zfs with :destroy and this zfs" do @provider.expects(:zfs).with(:destroy, @resource[:name]) @provider.delete 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, :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, prop, @resource[:name]).returns("NAME PROPERTY VALUE SOURCE\nmyzfs name value blah") + @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, prop, @resource[:name]).returns("NAME PROPERTY VALUE SOURCE\nmyzfs name value blah") + @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