Skip to content

Commit

Permalink
Merge pull request jhoblitt#14 from jhoblitt/refactor_facts
Browse files Browse the repository at this point in the history
refactor megaraid facts + add fact tests
  • Loading branch information
Joshua Hoblitt committed Dec 21, 2013
2 parents dbdbd4a + 2076ecc commit edf71eb
Show file tree
Hide file tree
Showing 18 changed files with 3,692 additions and 125 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
25 changes: 8 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,21 @@ rvm:
- 1.8.7
- 1.9.3
- 2.0.0
- ruby-head
env:
- PUPPET_GEM_VERSION="~> 2.7.0"
- PUPPET_GEM_VERSION="~> 3.0.0"
- PUPPET_GEM_VERSION="~> 3.1.0"
- PUPPET_GEM_VERSION="~> 3.2.1"
- PUPPET_GEM_VERSION="~> 3.3.0"
- PUPPET_GEM_VERSION="2.7.14"
- PUPPET_GEM_VERSION="~> 2.7"
- PUPPET_GEM_VERSION="~> 3.3"
matrix:
allow_failures:
- rvm: ruby-head
exclude:
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 2.7.0"
env: PUPPET_GEM_VERSION="2.7.14"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.0.0"
env: PUPPET_GEM_VERSION="2.7.14"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 2.7"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.1.0"
- rvm: ruby-head
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: ruby-head
env: PUPPET_GEM_VERSION="~> 3.0.0"
- rvm: ruby-head
env: PUPPET_GEM_VERSION="~> 3.1.0"
env: PUPPET_GEM_VERSION="~> 2.7"
notifications:
email: false
14 changes: 7 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ else
gem 'puppet', :require => false
end

gem 'rake'
gem 'puppetlabs_spec_helper'
gem 'puppet-lint'
gem 'puppet-syntax'
gem 'rspec-system', :require => false
gem 'rspec-system-puppet', :require => false
gem 'rake', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'puppet-syntax', :require => false
gem 'rspec-system', :require => false
gem 'rspec-system-puppet', :require => false
gem 'rspec-system-serverspec', :require => false
gem 'serverspec', :require => false
gem 'serverspec', :require => false

# vim:ft=ruby
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/params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
shared_examples 'osfamily' do |family|
let(:facts) {{ :osfamily => family }}

it { should include_class('smartd::params') }
it { should contain_class('smartd::params') }
end

describe 'for osfamily RedHat' do
Expand All @@ -29,7 +29,7 @@
end

it 'should fail' do
expect { should include_class('smartd::params') }.
expect { should contain_class('smartd::params') }.
to raise_error(Puppet::Error, /not supported on Solaris/)
end
end
Expand Down
8 changes: 4 additions & 4 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 All @@ -299,8 +299,8 @@
end

it do
should include_class('smartd')
should include_class('smartd::params')
should contain_class('smartd')
should contain_class('smartd::params')
should contain_package('smartmontools')
should contain_service('smartd')
should contain_file('/etc/smartd.conf')\
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 edf71eb

Please sign in to comment.