forked from jhoblitt/puppet-smartd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a fact exposing the sizes of physical disks
- Loading branch information
Nic Cope
committed
Feb 3, 2015
1 parent
e80c3aa
commit b3cf2b8
Showing
2 changed files
with
103 additions
and
0 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,25 @@ | ||
Facter.add(:megaraid_physical_drives_size) 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 | ||
sizes = [] | ||
list = Facter::Util::Resolution.exec("#{megacli} -PDList -aALL -NoLog") | ||
next if list.nil? | ||
list.each_line do |line| | ||
if line =~ /Raw Size: ([\.\d]+ [A-Z]?B)/ | ||
sizes.push($1) | ||
end | ||
end | ||
|
||
sizes.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,78 @@ | ||
require 'spec_helper' | ||
|
||
describe 'megaraid_physical_drives_size', :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_size).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_size).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_size).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_size).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'))) | ||
|
||
sizes = '3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,186.310 GB,' + | ||
'186.310 GB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,' + | ||
'3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB,3.638 TB' | ||
Facter.fact(:megaraid_physical_drives_size).value.should == sizes | ||
end | ||
end | ||
end # on linux | ||
|
||
context 'not on linux' do | ||
it do | ||
Facter.fact(:kernel).stubs(:value).returns('Solaris') | ||
|
||
Facter.fact(:megaraid_physical_drives_size).value.should be_nil | ||
end | ||
end # not on linux | ||
end | ||
|