Skip to content

Commit

Permalink
add megaraid_serial fact
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Apr 29, 2014
1 parent 512d90e commit 7358769
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/facter/megaraid_serial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Facter.add(:megaraid_serial) do
megacli = Facter.value(:megacli)

setcode do
unless megacli.nil?
output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL")
next if output.nil?
m = output.match(/Serial No : (\S+)\s*$/)
next unless m.size == 2
m[1]
end
end
end
31 changes: 31 additions & 0 deletions spec/unit/facts/megaraid_serial_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'

describe 'megaraid_serial', :type => :fact do
before(:each) { Facter.clear }

context 'megacli fact not set' do
it 'should return nil' do
Facter.fact(:megacli).stubs(:value).returns(nil)
Facter.fact(:megaraid_serial).value.should be_nil
end
end

context 'megacli fact is broken' do
it 'should return nil' do
Facter.fact(:megacli).stubs(:value).returns('foobar')
Facter.fact(:megaraid_serial).value.should be_nil
end
end

context 'megacli fact is working' do
it 'should get the version string' do
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli')
Facter::Util::Resolution.stubs(:exec).
with('/usr/bin/MegaCli -Version -Ctrl -aALL').
returns(File.read(fixtures('megacli', 'version-ctrl-aall-8.07.07')))
Facter.fact(:megaraid_serial).value.should == 'SV22925366'
end
end

end

0 comments on commit 7358769

Please sign in to comment.