From f5751893b72519e8ef21cfcfa69e6696d36ccbff Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 29 Apr 2014 11:13:51 -0700 Subject: [PATCH 1/5] add megacli_version fact --- lib/facter/megacli_version.rb | 13 ++++++++ .../fixtures/megacli/version-cli-aall-8.07.07 | 7 +++++ spec/unit/facts/megacli_version_spec.rb | 31 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/facter/megacli_version.rb create mode 100644 spec/fixtures/megacli/version-cli-aall-8.07.07 create mode 100644 spec/unit/facts/megacli_version_spec.rb diff --git a/lib/facter/megacli_version.rb b/lib/facter/megacli_version.rb new file mode 100644 index 0000000..affaeee --- /dev/null +++ b/lib/facter/megacli_version.rb @@ -0,0 +1,13 @@ +Facter.add(:megacli_version) do + megacli = Facter.value(:megacli) + + setcode do + unless megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -Version -Cli -aALL") + next if output.nil? + m = output.match(/MegaCLI SAS RAID Management Tool Ver ([\d\.]+)/) + next unless m.size == 2 + m[1] + end + end +end diff --git a/spec/fixtures/megacli/version-cli-aall-8.07.07 b/spec/fixtures/megacli/version-cli-aall-8.07.07 new file mode 100644 index 0000000..e9d627c --- /dev/null +++ b/spec/fixtures/megacli/version-cli-aall-8.07.07 @@ -0,0 +1,7 @@ + + + MegaCLI SAS RAID Management Tool Ver 8.07.07 Dec 19, 2012 + + (c)Copyright 2011, LSI Corporation, All Rights Reserved. + +Exit Code: 0x00 diff --git a/spec/unit/facts/megacli_version_spec.rb b/spec/unit/facts/megacli_version_spec.rb new file mode 100644 index 0000000..0cd8447 --- /dev/null +++ b/spec/unit/facts/megacli_version_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'megacli_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(:megacli_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(:megacli_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 -Cli -aALL'). + returns(File.read(fixtures('megacli', 'version-cli-aall-8.07.07'))) + Facter.fact(:megacli_version).value.should == '8.07.07' + end + end + +end + From 512d90e23f7cfd8ba01661fdc6f18262703b99cd Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 29 Apr 2014 11:25:36 -0700 Subject: [PATCH 2/5] add megaraid_product_name fact --- lib/facter/megaraid_product_name.rb | 13 ++++++++ .../megacli/version-ctrl-aall-8.07.07 | 10 ++++++ spec/unit/facts/megaraid_product_name_spec.rb | 31 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 lib/facter/megaraid_product_name.rb create mode 100644 spec/fixtures/megacli/version-ctrl-aall-8.07.07 create mode 100644 spec/unit/facts/megaraid_product_name_spec.rb diff --git a/lib/facter/megaraid_product_name.rb b/lib/facter/megaraid_product_name.rb new file mode 100644 index 0000000..b1cce05 --- /dev/null +++ b/lib/facter/megaraid_product_name.rb @@ -0,0 +1,13 @@ +Facter.add(:megaraid_product_name) 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(/Product Name : (.+)\s*$/) + next unless m.size == 2 + m[1] + end + end +end diff --git a/spec/fixtures/megacli/version-ctrl-aall-8.07.07 b/spec/fixtures/megacli/version-ctrl-aall-8.07.07 new file mode 100644 index 0000000..6e62a8d --- /dev/null +++ b/spec/fixtures/megacli/version-ctrl-aall-8.07.07 @@ -0,0 +1,10 @@ + + CTRL VERSION: + ================ + +Product Name : LSI MegaRAID SAS 9286CV-8e +Serial No : SV22925366 +Fw Package Build : 23.22.0-0012 +FW Version : 3.340.05-2939 + +Exit Code: 0x00 diff --git a/spec/unit/facts/megaraid_product_name_spec.rb b/spec/unit/facts/megaraid_product_name_spec.rb new file mode 100644 index 0000000..b359fd7 --- /dev/null +++ b/spec/unit/facts/megaraid_product_name_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'megaraid_product_name', :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_product_name).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_product_name).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_product_name).value.should == 'LSI MegaRAID SAS 9286CV-8e' + end + end + +end + From 735876973173240ee5e78683c68e3cb9b1e42210 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 29 Apr 2014 11:29:07 -0700 Subject: [PATCH 3/5] add megaraid_serial fact --- lib/facter/megaraid_serial.rb | 13 +++++++++++ spec/unit/facts/megaraid_serial_spec.rb | 31 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/facter/megaraid_serial.rb create mode 100644 spec/unit/facts/megaraid_serial_spec.rb diff --git a/lib/facter/megaraid_serial.rb b/lib/facter/megaraid_serial.rb new file mode 100644 index 0000000..daa3166 --- /dev/null +++ b/lib/facter/megaraid_serial.rb @@ -0,0 +1,13 @@ +Facter.add(:megaraid_serial) 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(/Serial No : (\S+)\s*$/) + next unless m.size == 2 + m[1] + end + end +end diff --git a/spec/unit/facts/megaraid_serial_spec.rb b/spec/unit/facts/megaraid_serial_spec.rb new file mode 100644 index 0000000..a61bdae --- /dev/null +++ b/spec/unit/facts/megaraid_serial_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'megaraid_serial', :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_serial).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_serial).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_serial).value.should == 'SV22925366' + end + end + +end + From 2d12260905b177de829566253e6f1a51e0e67165 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 29 Apr 2014 11:31:18 -0700 Subject: [PATCH 4/5] add megaraid_fw_package_build fact --- lib/facter/megaraid_fw_package_build.rb | 13 ++++++++ .../facts/megaraid_fw_package_build_spec.rb | 31 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/facter/megaraid_fw_package_build.rb create mode 100644 spec/unit/facts/megaraid_fw_package_build_spec.rb diff --git a/lib/facter/megaraid_fw_package_build.rb b/lib/facter/megaraid_fw_package_build.rb new file mode 100644 index 0000000..b052276 --- /dev/null +++ b/lib/facter/megaraid_fw_package_build.rb @@ -0,0 +1,13 @@ +Facter.add(:megaraid_fw_package_build) 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 Package Build : ([\d\.\-]+)\s*$/) + next unless m.size == 2 + m[1] + end + end +end diff --git a/spec/unit/facts/megaraid_fw_package_build_spec.rb b/spec/unit/facts/megaraid_fw_package_build_spec.rb new file mode 100644 index 0000000..4af4f71 --- /dev/null +++ b/spec/unit/facts/megaraid_fw_package_build_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'megaraid_fw_package_build', :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_package_build).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_package_build).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_package_build).value.should == '23.22.0-0012' + end + end + +end + From 04d71cc37214e439bbecc5b2783ea0541cdc192a Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 29 Apr 2014 11:33:35 -0700 Subject: [PATCH 5/5] 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 +