diff --git a/chef/lib/chef/provider/mdadm.rb b/chef/lib/chef/provider/mdadm.rb index 4c1905f6fca..0f9712b6bca 100644 --- a/chef/lib/chef/provider/mdadm.rb +++ b/chef/lib/chef/provider/mdadm.rb @@ -26,7 +26,7 @@ class Mdadm < Chef::Provider #include Chef::Mixin::Command include Chef::Mixin::ShellOut - + def popen4 raise Exception, "deprecated, bitches" end @@ -51,7 +51,7 @@ def load_current_resource def action_create unless @current_resource.exists - command = "yes | mdadm --create #{@new_resource.raid_device} --chunk=#{@new_resource.chunk} --level #{@new_resource.level} --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.join(" ")}" + command = "yes | mdadm --create #{@new_resource.raid_device} --chunk=#{@new_resource.chunk} --level #{@new_resource.level} --metadata=#{@new_resource.metadata} --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.join(" ")}" Chef::Log.debug("#{@new_resource} mdadm command: #{command}") #pid, stdin, stdout, stderr = popen4(command) shell_out!(command) diff --git a/chef/lib/chef/resource/mdadm.rb b/chef/lib/chef/resource/mdadm.rb index dbbd537d984..25f6d29cbc5 100644 --- a/chef/lib/chef/resource/mdadm.rb +++ b/chef/lib/chef/resource/mdadm.rb @@ -21,7 +21,7 @@ class Chef class Resource class Mdadm < Chef::Resource - + def initialize(name, run_context=nil) super @resource_name = :mdadm @@ -30,6 +30,7 @@ def initialize(name, run_context=nil) @devices = [] @exists = false @level = 1 + @metadata = "0.90" @raid_device = name @action = :create @@ -68,6 +69,14 @@ def level(arg=nil) ) end + def metadata(arg=nil) + set_or_return( + :metadata, + arg, + :kind_of => [ String ] + ) + end + def raid_device(arg=nil) set_or_return( :raid_device, diff --git a/chef/spec/unit/provider/mdadm_spec.rb b/chef/spec/unit/provider/mdadm_spec.rb index 68bd1fd9359..9eae4f1faf8 100644 --- a/chef/spec/unit/provider/mdadm_spec.rb +++ b/chef/spec/unit/provider/mdadm_spec.rb @@ -40,7 +40,7 @@ # @stderr = mock("STDERR", :null_object => true) # @pid = mock("PID", :null_object => true) end - + describe "when determining the current metadevice status" do it "should set the current resources mount point to the new resources mount point" do @@ -49,14 +49,14 @@ @provider.current_resource.name.should == '/dev/md1' @provider.current_resource.raid_device.should == '/dev/md1' end - + it "determines that the metadevice exists when mdadm output shows the metadevice" do @provider.stub!(:shell_out!).with("mdadm --detail --scan").and_return(OpenStruct.new(:stdout => '/dev/md1')) @provider.load_current_resource @provider.current_resource.exists.should be_true end end - + describe "after the metadevice status is known" do before(:each) do @current_resource = Chef::Resource::Mdadm.new('/dev/md1') @@ -67,11 +67,11 @@ @provider.current_resource = @current_resource end - + describe "when creating the metadevice" do it "should create the raid device if it doesnt exist" do @current_resource.exists(false) - expected_command = "yes | mdadm --create /dev/md1 --chunk=256 --level 1 --raid-devices 2 /dev/sdz1 /dev/sdz2" + expected_command = "yes | mdadm --create /dev/md1 --chunk=256 --level 1 --metadata=0.90 --raid-devices 2 /dev/sdz1 /dev/sdz2" @provider.should_receive(:shell_out!).with(expected_command) @provider.action_create end diff --git a/chef/spec/unit/resource/mdadm_spec.rb b/chef/spec/unit/resource/mdadm_spec.rb index 7d24ffd0bae..f6e77b9ff98 100644 --- a/chef/spec/unit/resource/mdadm_spec.rb +++ b/chef/spec/unit/resource/mdadm_spec.rb @@ -58,6 +58,11 @@ @resource.level.should eql(1) end + it "should allow you to set the metadata attribute" do + @resource.metadata "1.2" + @resource.metadata.should eql("1.2") + end + it "should allow you to set the devices attribute" do @resource.devices ["/dev/sda", "/dev/sdb"] @resource.devices.should eql(["/dev/sda", "/dev/sdb"])