From 04d71cc37214e439bbecc5b2783ea0541cdc192a Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 29 Apr 2014 11:33:35 -0700 Subject: [PATCH] add megaraid_fw_version fact --- lib/facter/megaraid_fw_version.rb | 13 +++++++++ spec/unit/facts/megaraid_fw_version_spec.rb | 31 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/facter/megaraid_fw_version.rb create mode 100644 spec/unit/facts/megaraid_fw_version_spec.rb diff --git a/lib/facter/megaraid_fw_version.rb b/lib/facter/megaraid_fw_version.rb new file mode 100644 index 0000000..9dfaf30 --- /dev/null +++ b/lib/facter/megaraid_fw_version.rb @@ -0,0 +1,13 @@ +Facter.add(:megaraid_fw_version) 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(/FW Version : ([\d\.\-]+)\s*$/) + next unless m.size == 2 + m[1] + end + end +end diff --git a/spec/unit/facts/megaraid_fw_version_spec.rb b/spec/unit/facts/megaraid_fw_version_spec.rb new file mode 100644 index 0000000..054c1ed --- /dev/null +++ b/spec/unit/facts/megaraid_fw_version_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'megaraid_fw_version', :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_fw_version).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_fw_version).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_fw_version).value.should == '3.340.05-2939' + end + end + +end +