-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from jhoblitt/feature/megaraid_facts
add megaraid_physical_drives_{sata,sas} facts
- Loading branch information
Showing
6 changed files
with
278 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Facter.add(:megaraid_physical_drives_sas) do | ||
confine :kernel => 'Linux' | ||
|
||
setcode do | ||
megacli = Facter.value(:megacli) | ||
megaraid_adapters = Facter.value(:megaraid_adapters) | ||
|
||
if megacli.nil? || | ||
megaraid_adapters.nil? || (megaraid_adapters == 0) | ||
next nil | ||
end | ||
|
||
# XXX there is no support for handling more than one adapter | ||
pds = [] | ||
list = Facter::Util::Resolution.exec("#{megacli} -PDList -aALL -NoLog") | ||
next if list.nil? | ||
|
||
dev_id = nil | ||
list.each_line do |line| | ||
if line =~ /^Device Id:\s+(\d+)/ | ||
dev_id = $1 | ||
end | ||
if line =~ /^PD Type:\s+(\w+)/ | ||
type = $1 | ||
if type == 'SAS' | ||
pds.push(dev_id) | ||
end | ||
end | ||
end | ||
|
||
# sort the device IDs numerically on the assumption that they are always | ||
# integers | ||
pds.sort {|a,b| a.to_i <=> b.to_i}.join(",") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Facter.add(:megaraid_physical_drives_sata) do | ||
confine :kernel => 'Linux' | ||
|
||
setcode do | ||
megacli = Facter.value(:megacli) | ||
megaraid_adapters = Facter.value(:megaraid_adapters) | ||
|
||
if megacli.nil? || | ||
megaraid_adapters.nil? || (megaraid_adapters == 0) | ||
next nil | ||
end | ||
|
||
# XXX there is no support for handling more than one adapter | ||
pds = [] | ||
list = Facter::Util::Resolution.exec("#{megacli} -PDList -aALL -NoLog") | ||
next if list.nil? | ||
|
||
dev_id = nil | ||
list.each_line do |line| | ||
if line =~ /^Device Id:\s+(\d+)/ | ||
dev_id = $1 | ||
end | ||
if line =~ /^PD Type:\s+(\w+)/ | ||
type = $1 | ||
if type == 'SATA' | ||
pds.push(dev_id) | ||
end | ||
end | ||
end | ||
|
||
# sort the device IDs numerically on the assumption that they are always | ||
# integers | ||
pds.sort {|a,b| a.to_i <=> b.to_i}.join(",") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'spec_helper' | ||
|
||
describe 'megaraid_physical_drives_sas', :type => :fact do | ||
before(:each) { Facter.clear } | ||
|
||
describe 'on linux' do | ||
context 'megacli not in path' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns(nil) | ||
|
||
Facter.fact(:megaraid_physical_drives_sas).value.should be_nil | ||
end | ||
end | ||
|
||
context 'megacli is broken' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') | ||
Facter.fact(:megaraid_adapters).stubs(:value).returns(nil) | ||
|
||
Facter.fact(:megaraid_physical_drives_sas).value.should be_nil | ||
end | ||
|
||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') | ||
Facter.fact(:megaraid_adapters).stubs(:value).returns('1') | ||
Facter::Util::Resolution.stubs(:exec).with('/usr/bin/MegaCli -PDList -aALL -NoLog'). | ||
returns(nil) | ||
|
||
Facter.fact(:megaraid_physical_drives_sas).value.should be_nil | ||
end | ||
end | ||
|
||
context 'no adapters' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') | ||
Facter.fact(:megaraid_adapters).stubs(:value).returns('0') | ||
|
||
Facter.fact(:megaraid_physical_drives_sas).value.should be_nil | ||
end | ||
end | ||
|
||
context '1 adapter' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') | ||
Facter.fact(:megaraid_adapters).stubs(:value).returns('1') | ||
Facter::Util::Resolution.stubs(:exec).with('/usr/bin/MegaCli -PDList -aALL -NoLog'). | ||
returns(File.read(fixtures('megacli', 'pdlistaall'))) | ||
|
||
Facter.fact(:megaraid_physical_drives_sas).value.should == '188,189,190,192,194,197,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214' | ||
end | ||
end | ||
end # on linux | ||
|
||
context 'not on linux' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Solaris') | ||
|
||
Facter.fact(:megaraid_physical_drives_sas).value.should be_nil | ||
end | ||
end # not on linux | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'spec_helper' | ||
|
||
describe 'megaraid_physical_drives_sata', :type => :fact do | ||
before(:each) { Facter.clear } | ||
|
||
describe 'on linux' do | ||
context 'megacli not in path' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns(nil) | ||
|
||
Facter.fact(:megaraid_physical_drives_sata).value.should be_nil | ||
end | ||
end | ||
|
||
context 'megacli is broken' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') | ||
Facter.fact(:megaraid_adapters).stubs(:value).returns(nil) | ||
|
||
Facter.fact(:megaraid_physical_drives_sata).value.should be_nil | ||
end | ||
|
||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') | ||
Facter.fact(:megaraid_adapters).stubs(:value).returns('1') | ||
Facter::Util::Resolution.stubs(:exec).with('/usr/bin/MegaCli -PDList -aALL -NoLog'). | ||
returns(nil) | ||
|
||
Facter.fact(:megaraid_physical_drives_sata).value.should be_nil | ||
end | ||
end | ||
|
||
context 'no adapters' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') | ||
Facter.fact(:megaraid_adapters).stubs(:value).returns('0') | ||
|
||
Facter.fact(:megaraid_physical_drives_sata).value.should be_nil | ||
end | ||
end | ||
|
||
context '1 adapter' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Linux') | ||
Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') | ||
Facter.fact(:megaraid_adapters).stubs(:value).returns('1') | ||
Facter::Util::Resolution.stubs(:exec).with('/usr/bin/MegaCli -PDList -aALL -NoLog'). | ||
returns(File.read(fixtures('megacli', 'pdlistaall'))) | ||
|
||
Facter.fact(:megaraid_physical_drives_sata).value.should == '10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,184,185' | ||
end | ||
end | ||
end # on linux | ||
|
||
context 'not on linux' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Solaris') | ||
|
||
Facter.fact(:megaraid_physical_drives_sata).value.should be_nil | ||
end | ||
end # not on linux | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters