Skip to content

Commit

Permalink
refactor megaraid facts + add fact tests
Browse files Browse the repository at this point in the history
* stop checking for megaraid `/dev/*` files and instead let megacli tell us if it can find any raid controllers
* use blockdevice facts instead of exec'ing `lsscsi`, inspired by Kyle Anderson's [gist](https://gist.github.com/solarkennedy/7606943)
* split each fact into it's own .rb file
* add rspec test coverage of all facts
* remove non-functioning freebsd facts completely
  • Loading branch information
Joshua Hoblitt committed Dec 21, 2013
1 parent dbdbd4a commit 0d15b7e
Show file tree
Hide file tree
Showing 15 changed files with 3,673 additions and 97 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pkg/
spec/fixtures/
spec/fixtures/manifests/
spec/fixtures/modules/
Gemfile.lock
*.orig
*.rej
*.patch
.rspec_system/
*.swp
7 changes: 7 additions & 0 deletions lib/facter/megacli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Facter.add(:megacli) do
confine :kernel => :linux

setcode do
Facter::Util::Resolution.which('MegaCli')
end
end
93 changes: 0 additions & 93 deletions lib/facter/megaraid.rb

This file was deleted.

22 changes: 22 additions & 0 deletions lib/facter/megaraid_adapters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Figure out if this machine has AMI/LSI MegaRAID aka Dell PERC
# storage controllers, and if so, how many physical disks are
# attached. Currently implemented only on Linux because none of
# our FreeBSD machines use these controllers, so I don't have an
# example "mfiutil show config" to write a parser for and test
# against.

Facter.add(:megaraid_adapters) do
confine :kernel => 'Linux'

setcode do
megacli = Facter.value(:megacli)

if megacli.nil?
next nil
end

# -adpCount sends it's entire output to the stderr
count = Facter::Util::Resolution.exec("#{megacli} -adpCount 2>&1")
count =~ /Controller Count:\s+(\d+)\./ ? $1 : '0'
end
end
27 changes: 27 additions & 0 deletions lib/facter/megaraid_physical_drives.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Facter.add(:megaraid_physical_drives) 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")
next if list.nil?
list.each_line do |line|
if line =~ /^Device Id:\s+(\d+)/
pds.push($1)
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
34 changes: 34 additions & 0 deletions lib/facter/megaraid_virtual_drives.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Try to figure out what should be used as the "device" parameter
# for smartd. On FreeBSD it's simple, just use /dev/mfi%d, but
# on Linux we have to find a block device that corresponds to a
# *logical* drive on the controller. Any logical drive will do,
# so long as it's on the same controller. We only support one
# controller for now.
Facter.add(:megaraid_virtual_drives) do
confine :kernel => 'Linux'

setcode do
megacli = Facter.value(:megacli)
megaraid_adapters = Facter.value(:megaraid_adapters)
blockdevices = Facter.value(:blockdevices)

if megacli.nil? ||
megaraid_adapters.nil? || (megaraid_adapters == 0) ||
blockdevices.nil?
next nil
end

vds = []

devices = blockdevices.split(',')
devices.each do |dev|
vendor = Facter.value("blockdevice_#{dev}_vendor")
case vendor
when 'LSI', 'SMC'
vds << dev
end
end

vds.sort.join(',')
end
end
4 changes: 2 additions & 2 deletions spec/classes/smartd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
{
:osfamily=> 'RedHat',
:megaraid_adapters => '1',
:megaraid_virtual_drives => '/dev/sdb,/dev/sda',
:megaraid_virtual_drives => 'sdb,sda',
:megaraid_physical_drives => '2,1',
}
end
Expand All @@ -288,7 +288,7 @@
{
:osfamily=> 'RedHat',
:megaraid_adapters => '1',
:megaraid_virtual_drives => '/dev/sdb,/dev/sda',
:megaraid_virtual_drives => 'sdb,sda',
:megaraid_physical_drives => '2,1',
}
end
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/megacli/adpcount-count_0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


Controller Count: 0.

Exit Code: 0x00

5 changes: 5 additions & 0 deletions spec/fixtures/megacli/adpcount-count_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


Controller Count: 1.

Exit Code: 0x01
Loading

0 comments on commit 0d15b7e

Please sign in to comment.