Skip to content

Commit

Permalink
CHEF-2935: Add metadata option to the mdadm resource
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh authored and aglarond committed Apr 11, 2012
1 parent 0ce0413 commit 13e4cd9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions chef/lib/chef/provider/mdadm.rb
Expand Up @@ -26,7 +26,7 @@ class Mdadm < Chef::Provider

#include Chef::Mixin::Command
include Chef::Mixin::ShellOut

def popen4
raise Exception, "deprecated, bitches"
end
Expand All @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion chef/lib/chef/resource/mdadm.rb
Expand Up @@ -21,7 +21,7 @@
class Chef
class Resource
class Mdadm < Chef::Resource

def initialize(name, run_context=nil)
super
@resource_name = :mdadm
Expand All @@ -30,6 +30,7 @@ def initialize(name, run_context=nil)
@devices = []
@exists = false
@level = 1
@metadata = "0.90"
@raid_device = name

@action = :create
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions chef/spec/unit/provider/mdadm_spec.rb
Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions chef/spec/unit/resource/mdadm_spec.rb
Expand Up @@ -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"])
Expand Down

0 comments on commit 13e4cd9

Please sign in to comment.