From 18589cc1fa3b62e6de133045011607651aa6971b Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Mon, 26 Jan 2015 18:07:13 -0500 Subject: [PATCH] Support ancient versions of MegaCli At around version 8.02.16 some arguments to MegaCli changed. This change attempts to determine whether MegaCli is modern (8.02.16 or newer) or legacy (everything else). Facts affected by the changed arguments are gated using a confine statement. This change also handles cases where the MegaCli binary is lowercase (megacli). --- lib/facter/megacli.rb | 10 +- lib/facter/megacli_legacy.rb | 21 ++ lib/facter/megacli_version.rb | 16 +- lib/facter/megaraid_fw_package_build.rb | 31 ++- lib/facter/megaraid_fw_version.rb | 31 ++- lib/facter/megaraid_product_name.rb | 31 ++- lib/facter/megaraid_serial.rb | 32 ++- lib/facter/megaraid_virtual_drives.rb | 2 +- spec/fixtures/megacli/adpallinfo-aall-8.00.11 | 259 ++++++++++++++++++ .../adpallinfo-aall-8.00.11-dell_no_serial | 8 + spec/fixtures/megacli/invalid-input-8.00.11 | 3 + spec/fixtures/megacli/version-aall-8.00.11 | 7 + spec/unit/facts/megacli_spec.rb | 16 +- spec/unit/facts/megacli_version_spec.rb | 13 +- .../facts/megaraid_fw_package_build_spec.rb | 26 +- spec/unit/facts/megaraid_fw_version_spec.rb | 26 +- spec/unit/facts/megaraid_product_name_spec.rb | 26 +- spec/unit/facts/megaraid_serial_spec.rb | 49 +++- 18 files changed, 540 insertions(+), 67 deletions(-) create mode 100644 lib/facter/megacli_legacy.rb create mode 100644 spec/fixtures/megacli/adpallinfo-aall-8.00.11 create mode 100644 spec/fixtures/megacli/adpallinfo-aall-8.00.11-dell_no_serial create mode 100644 spec/fixtures/megacli/invalid-input-8.00.11 create mode 100644 spec/fixtures/megacli/version-aall-8.00.11 diff --git a/lib/facter/megacli.rb b/lib/facter/megacli.rb index 666afa7..1dc9000 100644 --- a/lib/facter/megacli.rb +++ b/lib/facter/megacli.rb @@ -1,7 +1,15 @@ Facter.add(:megacli) do confine :kernel => :linux + megacli_binaries = ['MegaCli', 'megacli'] + setcode do - Facter::Util::Resolution.which('MegaCli') + path = nil + megacli_binaries.each do |bin| + path = Facter::Util::Resolution.which(bin) + next if path.nil? + break + end + path end end diff --git a/lib/facter/megacli_legacy.rb b/lib/facter/megacli_legacy.rb new file mode 100644 index 0000000..cbe9fec --- /dev/null +++ b/lib/facter/megacli_legacy.rb @@ -0,0 +1,21 @@ +require 'semver' + +# Legacy versions of MegaCLI require different arguments to determine certain +# software and firmware versions. +Facter.add(:megacli_legacy) do + megacli = Facter.value(:megacli) + megacli_version = Facter.value(:megacli_version) + + setcode do + next if megacli.nil? + next if megacli_version.nil? + + # Modern version assumed from changelog at + # http://www.lsi.com/downloads/Public/RAID%20Controllers/RAID%20Controllers%20Common%20Files/Linux%20MegaCLI%208.07.10.txt + actual_version = SemVer.new(megacli_version) + modern_version = SemVer.new('8.02.16') + + actual_version < modern_version + + end +end diff --git a/lib/facter/megacli_version.rb b/lib/facter/megacli_version.rb index 4339db0..44fb91c 100644 --- a/lib/facter/megacli_version.rb +++ b/lib/facter/megacli_version.rb @@ -1,13 +1,23 @@ Facter.add(:megacli_version) do megacli = Facter.value(:megacli) + version_commands = ["#{megacli} -Version -Cli -aALL -NoLog", + "#{megacli} -v -aALL -NoLog"] setcode do - unless megacli.nil? - output = Facter::Util::Resolution.exec("#{megacli} -Version -Cli -aALL -NoLog") + next if megacli.nil? + + version = nil + # This is a bit hacky, but we need to try different commands to ascertain + # the version of the megacli binary. + version_commands.each do |cmd| + output = Facter::Util::Resolution.exec(cmd) next if output.nil? m = output.match(/MegaCLI SAS RAID Management Tool Ver ([\d\.]+)/) + next if m.nil? next unless m.size == 2 - m[1] + version = m[1] + break end + version end end diff --git a/lib/facter/megaraid_fw_package_build.rb b/lib/facter/megaraid_fw_package_build.rb index 9904504..e0717b8 100644 --- a/lib/facter/megaraid_fw_package_build.rb +++ b/lib/facter/megaraid_fw_package_build.rb @@ -1,13 +1,30 @@ Facter.add(:megaraid_fw_package_build) do + confine :megacli_legacy => false + megacli = Facter.value(:megacli) + setcode do + next if megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog") + next if output.nil? + m = output.match(/F[wW] Package Build\s*:\s*([\d\.\-]+)\s*$/) + next if m.nil? + next unless m.size == 2 + m[1] + end +end + +Facter.add(:megaraid_fw_package_build) do + confine :megacli_legacy => true + + megacli = Facter.value(:megacli) setcode do - unless megacli.nil? - output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog") - next if output.nil? - m = output.match(/Fw Package Build : ([\d\.\-]+)\s*$/) - next unless m.size == 2 - m[1] - end + next if megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -AdpAllInfo -aALL -NoLog") + next if output.nil? + m = output.match(/F[wW] Package Build\s*:\s*([\d\.\-]+)\s*$/) + next if m.nil? + next unless m.size == 2 + m[1] end end diff --git a/lib/facter/megaraid_fw_version.rb b/lib/facter/megaraid_fw_version.rb index c0799d4..2f4adb1 100644 --- a/lib/facter/megaraid_fw_version.rb +++ b/lib/facter/megaraid_fw_version.rb @@ -1,13 +1,30 @@ Facter.add(:megaraid_fw_version) do + confine :megacli_legacy => false + megacli = Facter.value(:megacli) + setcode do + next if megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog") + next if output.nil? + m = output.match(/FW Version\s*:\s*([\d\.\-]+)\s*$/) + next if m.nil? + next unless m.size == 2 + m[1] + end +end + +Facter.add(:megaraid_fw_version) do + confine :megacli_legacy => true + + megacli = Facter.value(:megacli) setcode do - unless megacli.nil? - output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog") - next if output.nil? - m = output.match(/FW Version : ([\d\.\-]+)\s*$/) - next unless m.size == 2 - m[1] - end + next if megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -AdpAllInfo -aALL -NoLog") + next if output.nil? + m = output.match(/FW Version\s*:\s*([\d\.\-]+)\s*$/) + next if m.nil? + next unless m.size == 2 + m[1] end end diff --git a/lib/facter/megaraid_product_name.rb b/lib/facter/megaraid_product_name.rb index 35f3135..c5dc819 100644 --- a/lib/facter/megaraid_product_name.rb +++ b/lib/facter/megaraid_product_name.rb @@ -1,13 +1,30 @@ Facter.add(:megaraid_product_name) do + confine :megacli_legacy => false + megacli = Facter.value(:megacli) + setcode do + next if megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog") + next if output.nil? + m = output.match(/Product Name\s*:\s*(.+)\s*$/) + next if m.nil? + next unless m.size == 2 + m[1] + end +end + +Facter.add(:megaraid_product_name) do + confine :megacli_legacy => true + + megacli = Facter.value(:megacli) setcode do - unless megacli.nil? - output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog") - next if output.nil? - m = output.match(/Product Name : (.+)\s*$/) - next unless m.size == 2 - m[1] - end + next if megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -AdpAllInfo -aALL -NoLog") + next if output.nil? + m = output.match(/Product Name\s*:\s*(.+)\s*$/) + next if m.nil? + next unless m.size == 2 + m[1] end end diff --git a/lib/facter/megaraid_serial.rb b/lib/facter/megaraid_serial.rb index 12bd690..433408a 100644 --- a/lib/facter/megaraid_serial.rb +++ b/lib/facter/megaraid_serial.rb @@ -1,14 +1,30 @@ Facter.add(:megaraid_serial) do + confine :megacli_legacy => false + megacli = Facter.value(:megacli) + setcode do + next if megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog") + next if output.nil? + m = output.match(/Serial No\s*:\s*(\S+)\s*$/) + next if m.nil? + next unless m.size == 2 + m[1] + end +end + +Facter.add(:megaraid_serial) do + confine :megacli_legacy => true + + megacli = Facter.value(:megacli) setcode do - unless megacli.nil? - output = Facter::Util::Resolution.exec("#{megacli} -Version -Ctrl -aALL -NoLog") - next if output.nil? - m = output.match(/Serial No : (\S+)\s*$/) - next if m.nil? - next unless m.size == 2 - m[1] - end + next if megacli.nil? + output = Facter::Util::Resolution.exec("#{megacli} -AdpAllInfo -aALL -NoLog") + next if output.nil? + m = output.match(/Serial No\s*:\s*(\S+)\s*$/) + next if m.nil? + next unless m.size == 2 + m[1] end end diff --git a/lib/facter/megaraid_virtual_drives.rb b/lib/facter/megaraid_virtual_drives.rb index a8d0dcd..8b7dfb2 100644 --- a/lib/facter/megaraid_virtual_drives.rb +++ b/lib/facter/megaraid_virtual_drives.rb @@ -24,7 +24,7 @@ devices.each do |dev| vendor = Facter.value("blockdevice_#{dev}_vendor") case vendor - when 'LSI', 'SMC' + when 'LSI', 'SMC', 'DELL' vds << dev end end diff --git a/spec/fixtures/megacli/adpallinfo-aall-8.00.11 b/spec/fixtures/megacli/adpallinfo-aall-8.00.11 new file mode 100644 index 0000000..0c13d25 --- /dev/null +++ b/spec/fixtures/megacli/adpallinfo-aall-8.00.11 @@ -0,0 +1,259 @@ + + +Adapter #0 + +============================================================================== + Versions + ================ +Product Name : PERC H310 Mini +Serial No : 34A03AB +FW Package Build: 20.12.0-0004 + + Mfg. Data + ================ +Mfg. Date : 04/14/13 +Rework Date : 04/14/13 +Revision No : A01 +Battery FRU : N/A + + Image Versions in Flash: + ================ +BIOS Version : 4.34.00_4.12.05.00_0x05260000 +Preboot CLI Version: 03.02-015:#%00008 +Ctrl-R Version : 3.00-0022 +NVDATA Version : 3.09.03-0038 +FW Version : 2.120.14-2138 +Boot Block Version : 2.02.00.00-0001 + + Pending Images in Flash + ================ +None + + PCI Info + ================ +Vendor Id : 1000 +Device Id : 0073 +SubVendorId : 1028 +SubDeviceId : 1f51 + +Host Interface : PCIE + +Number of Frontend Port: 0 +Device Interface : PCIE + +Number of Backend Port: 8 +Port : Address +0 500056b37789abff +1 0000000000000000 +2 0000000000000000 +3 0000000000000000 +4 0000000000000000 +5 0000000000000000 +6 0000000000000000 +7 0000000000000000 + + HW Configuration + ================ +SAS Address : 5b8ca3a0e6a98700 +BBU : Absent +Alarm : Absent +NVRAM : Present +Serial Debugger : Present +Memory : Absent +Flash : Present +Memory Size : 0MB +TPM : Absent +On board Expander: Absent + + Settings + ================ +Current Time : 22:39:25 1/29, 2015 +Predictive Fail Poll Interval : 300sec +Interrupt Throttle Active Count : 16 +Interrupt Throttle Completion : 50us +Rebuild Rate : 30% +PR Rate : 30% +BGI Rate : 30% +Check Consistency Rate : 30% +Reconstruction Rate : 30% +Cache Flush Interval : 4s +Max Drives to Spinup at One Time : 4 +Delay Among Spinup Groups : 12s +Physical Drive Coercion Mode : 128MB +Cluster Mode : Disabled +Alarm : Disabled +Auto Rebuild : Enabled +Battery Warning : Disabled +Ecc Bucket Size : 15 +Ecc Bucket Leak Rate : 1440 Minutes +Restore HotSpare on Insertion : Disabled +Expose Enclosure Devices : Disabled +Maintain PD Fail History : Disabled +Host Request Reordering : Enabled +Auto Detect BackPlane Enabled : SGPIO/i2c SEP +Load Balance Mode : Auto +Use FDE Only : Yes +Security Key Assigned : No +Security Key Failed : No +Security Key Not Backedup : No +Any Offline VD Cache Preserved : No +Allow Boot with Preserved Cache : No +Disable Online Controller Reset : No + + Capabilities + ================ +RAID Level Supported : RAID0, RAID1, RAID5, RAID10, RAID50, PRL 11, PRL 11 with spanning +Supported Drives : SAS, SATA + +Allowed Mixing: + +Mix in Enclosure Allowed + + Status + ================ +ECC Bucket Count : 0 + + Limitations + ================ +Max Arms Per VD : 16 +Max Spans Per VD : 8 +Max Arrays : 16 +Max Number of VDs : 16 +Max Parallel Commands : 31 +Max SGE Count : 60 +Max Data Transfer Size : 8192 sectors +Max Strips PerIO : 20 +Min Stripe Size : 64 KB +Max Stripe Size : 64 KB +Max Configurable SSC Size: 0 GB +Current Size of SSC : 0 GB + + Device Present + ================ +Virtual Drives : 1 + Degraded : 0 + Offline : 0 +Physical Devices : 4 + Disks : 2 + Critical Disks : 0 + Failed Disks : 0 + + Supported Adapter Operations + ================ +Rebuild Rate : Yes +CC Rate : Yes +BGI Rate : Yes +Reconstruct Rate : Yes +Patrol Read Rate : Yes +Alarm Control : Yes +Cluster Support : No +BBU : No +Spanning : Yes +Dedicated Hot Spare : Yes +Revertible Hot Spares : Yes +Foreign Config Import : Yes +Self Diagnostic : Yes +Allow Mixed Redundancy on Array : No +Global Hot Spares : Yes +Deny SCSI Passthrough : No +Deny SMP Passthrough : No +Deny STP Passthrough : No +Support Security : No +Snapshot Enabled : No +Support the OCE without adding drives : Yes + + Supported VD Operations + ================ +Read Policy : No +Write Policy : No +IO Policy : No +Access Policy : Yes +Disk Cache Policy : Yes +Reconstruction : Yes +Deny Locate : No +Deny CC : No +Allow Ctrl Encryption: No +Enable LDBBM : Yes + + Supported PD Operations + ================ +Force Online : Yes +Force Offline : Yes +Force Rebuild : Yes +Deny Force Failed : No +Deny Force Good/Bad : No +Deny Missing Replace : No +Deny Clear : Yes +Deny Locate : No +Disable Copyback : No +Enable JBOD : Yes +Enable Copyback on SMART : No +Enable Copyback to SSD on SMART Error : No +Enable SSD Patrol Read : No +PR Correct Unconfigured Areas : Yes +Enable Spin Down of UnConfigured Drives : No +Disable Spin Down of hot spares : Yes +Spin Down time : 30 + Error Counters + ================ +Memory Correctable Errors : 0 +Memory Uncorrectable Errors : 0 + + Cluster Information + ================ +Cluster Permitted : No +Cluster Active : No + + Default Settings + ================ +Phy Polarity : 0 +Phy PolaritySplit : 0 +Background Rate : 30 +Stripe Size : 64kB +Flush Time : 4 seconds +Write Policy : WT +Read Policy : None +Cache When BBU Bad : Disabled +Cached IO : No +SMART Mode : Mode 6 +Alarm Disable : No +Coercion Mode : 128MB +ZCR Config : Unknown +Dirty LED Shows Drive Activity : No +BIOS Continue on Error : No +Spin Down Mode : None +Allowed Device Type : SAS/SATA Mix +Allow Mix in Enclosure : Yes +Allow HDD SAS/SATA Mix in VD : No +Allow SSD SAS/SATA Mix in VD : No +Allow HDD/SSD Mix in VD : No +Allow SATA in Cluster : No +Max Chained Enclosures : 4 +Disable Ctrl-R : No +Enable Web BIOS : No +Direct PD Mapping : Yes +BIOS Enumerate VDs : Yes +Restore Hot Spare on Insertion : No +Expose Enclosure Devices : No +Maintain PD Fail History : No +Disable Puncturing : No +Zero Based Enclosure Enumeration : Yes +PreBoot CLI Enabled : No +LED Show Drive Activity : Yes +Cluster Disable : Yes +SAS Disable : No +Auto Detect BackPlane Enable : SGPIO/i2c SEP +Use FDE Only : Yes +Enable Led Header : No +Delay during POST : 0 +EnableCrashDump : No +Disable Online Controller Reset : No +EnableLDBBM : Yes +Un-Certified Hard Disk Drives : Allow +Treat Single span R1E as R10 : Yes +Max LD per array : 16 +Power Saving option : Not Defined +Default spin down time in minutes: 30 +Enable JBOD : Yes + +Exit Code: 0x00 diff --git a/spec/fixtures/megacli/adpallinfo-aall-8.00.11-dell_no_serial b/spec/fixtures/megacli/adpallinfo-aall-8.00.11-dell_no_serial new file mode 100644 index 0000000..a9bbe12 --- /dev/null +++ b/spec/fixtures/megacli/adpallinfo-aall-8.00.11-dell_no_serial @@ -0,0 +1,8 @@ +Adapter #0 + +============================================================================== + Versions + ================ +Product Name : PERC H310 Mini +Serial No : +FW Package Build: 20.12.0-0004 diff --git a/spec/fixtures/megacli/invalid-input-8.00.11 b/spec/fixtures/megacli/invalid-input-8.00.11 new file mode 100644 index 0000000..34480f8 --- /dev/null +++ b/spec/fixtures/megacli/invalid-input-8.00.11 @@ -0,0 +1,3 @@ +Invalid input at or near token -Version + +Exit Code: 0x01 diff --git a/spec/fixtures/megacli/version-aall-8.00.11 b/spec/fixtures/megacli/version-aall-8.00.11 new file mode 100644 index 0000000..942e98d --- /dev/null +++ b/spec/fixtures/megacli/version-aall-8.00.11 @@ -0,0 +1,7 @@ + + + MegaCLI SAS RAID Management Tool Ver 8.00.11 December 21, 2009 + + (c)Copyright 2009, LSI Corporation, All Rights Reserved. + +Exit Code: 0x00 diff --git a/spec/unit/facts/megacli_spec.rb b/spec/unit/facts/megacli_spec.rb index 1dddcef..b8e880b 100644 --- a/spec/unit/facts/megacli_spec.rb +++ b/spec/unit/facts/megacli_spec.rb @@ -6,19 +6,29 @@ context 'on linux' do context 'not in path' do it do - Facter.fact(:kernel).stubs(:value).returns('Linux') + Facter.fact(:kernel).stubs(:value).returns('Linux') Facter::Util::Resolution.stubs(:which).with('MegaCli').returns(nil) + Facter::Util::Resolution.stubs(:which).with('megacli').returns(nil) Facter.fact(:megacli).value.should be_nil end end - context 'in path' do + context 'in path mixed case' do it do - Facter.fact(:kernel).stubs(:value).returns('Linux') + Facter.fact(:kernel).stubs(:value).returns('Linux') Facter::Util::Resolution.stubs(:which).with('MegaCli').returns('/usr/bin/MegaCli') Facter.fact(:megacli).value.should == '/usr/bin/MegaCli' end end + + context 'in path lower case' do + it do + Facter.fact(:kernel).stubs(:value).returns('Linux') + Facter::Util::Resolution.stubs(:which).with('MegaCli').returns(nil) + Facter::Util::Resolution.stubs(:which).with('megacli').returns('/usr/bin/megacli') + Facter.fact(:megacli).value.should == '/usr/bin/megacli' + end + end end end diff --git a/spec/unit/facts/megacli_version_spec.rb b/spec/unit/facts/megacli_version_spec.rb index 2cf8be4..9aad88e 100644 --- a/spec/unit/facts/megacli_version_spec.rb +++ b/spec/unit/facts/megacli_version_spec.rb @@ -18,13 +18,24 @@ end context 'megacli fact is working' do - it 'should get the version string' do + it 'should get the version string using modern binary' do Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') Facter::Util::Resolution.stubs(:exec). with('/usr/bin/MegaCli -Version -Cli -aALL -NoLog'). returns(File.read(fixtures('megacli', 'version-cli-aall-8.07.07'))) Facter.fact(:megacli_version).value.should == '8.07.07' end + + it 'should get the version string using legacy binary' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -Version -Cli -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'invalid-input-8.00.11'))) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -v -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'version-aall-8.00.11'))) + Facter.fact(:megacli_version).value.should == '8.00.11' + 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 index 6faad41..713e44c 100644 --- a/spec/unit/facts/megaraid_fw_package_build_spec.rb +++ b/spec/unit/facts/megaraid_fw_package_build_spec.rb @@ -18,12 +18,26 @@ 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 -NoLog'). - returns(File.read(fixtures('megacli', 'version-ctrl-aall-8.07.07'))) - Facter.fact(:megaraid_fw_package_build).value.should == '23.22.0-0012' + context 'and modern' do + it 'should get the version string using modern binary' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(false) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -Version -Ctrl -aALL -NoLog'). + 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 + + context 'and legacy' do + it 'should get the version string using legacy binary' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(true) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -AdpAllInfo -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'adpallinfo-aall-8.00.11'))) + Facter.fact(:megaraid_fw_package_build).value.should == '20.12.0-0004' + end end end diff --git a/spec/unit/facts/megaraid_fw_version_spec.rb b/spec/unit/facts/megaraid_fw_version_spec.rb index 8578497..b2a66c8 100644 --- a/spec/unit/facts/megaraid_fw_version_spec.rb +++ b/spec/unit/facts/megaraid_fw_version_spec.rb @@ -18,12 +18,26 @@ 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 -NoLog'). - returns(File.read(fixtures('megacli', 'version-ctrl-aall-8.07.07'))) - Facter.fact(:megaraid_fw_version).value.should == '3.340.05-2939' + context 'and modern' do + it 'should get the version string using modern binary' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(false) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -Version -Ctrl -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'version-ctrl-aall-8.07.07'))) + Facter.fact(:megaraid_fw_version).value.should == '3.340.05-2939' + end + end + + context 'and legacy' do + it 'should get the version string using legacy binary' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(true) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -AdpAllInfo -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'adpallinfo-aall-8.00.11'))) + Facter.fact(:megaraid_fw_version).value.should == '2.120.14-2138' + end end end diff --git a/spec/unit/facts/megaraid_product_name_spec.rb b/spec/unit/facts/megaraid_product_name_spec.rb index 29441e8..02a1839 100644 --- a/spec/unit/facts/megaraid_product_name_spec.rb +++ b/spec/unit/facts/megaraid_product_name_spec.rb @@ -18,12 +18,26 @@ 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 -NoLog'). - returns(File.read(fixtures('megacli', 'version-ctrl-aall-8.07.07'))) - Facter.fact(:megaraid_product_name).value.should == 'LSI MegaRAID SAS 9286CV-8e' + context 'and modern' do + it 'should get the product name string using the modern binary' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(false) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -Version -Ctrl -aALL -NoLog'). + 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 + + context 'and legacy' do + it 'should get the product name string using legacy binary' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(true) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -AdpAllInfo -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'adpallinfo-aall-8.00.11'))) + Facter.fact(:megaraid_product_name).value.should == 'PERC H310 Mini' + end end end diff --git a/spec/unit/facts/megaraid_serial_spec.rb b/spec/unit/facts/megaraid_serial_spec.rb index d84beda..c8664a1 100644 --- a/spec/unit/facts/megaraid_serial_spec.rb +++ b/spec/unit/facts/megaraid_serial_spec.rb @@ -18,23 +18,50 @@ 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 -NoLog'). - returns(File.read(fixtures('megacli', 'version-ctrl-aall-8.07.07'))) - Facter.fact(:megaraid_serial).value.should == 'SV22925366' + context 'and modern' do + it 'should get the serial number using modern binary' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(false) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -Version -Ctrl -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'version-ctrl-aall-8.07.07'))) + Facter.fact(:megaraid_serial).value.should == 'SV22925366' + end + + context 'but megacli output is missing serial number' do + it 'should return nil' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(false) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -Version -Ctrl -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'version-ctrl-aall-sm_no_serial'))) + Facter.fact(:megaraid_serial).value.should be_nil + end + end end - context 'megacli output is missing serial number' do - it 'should get the version string' do + context 'and legacy' do + it 'should get the serial number using legacy binary' do Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(true) Facter::Util::Resolution.stubs(:exec). - with('/usr/bin/MegaCli -Version -Ctrl -aALL -NoLog'). - returns(File.read(fixtures('megacli', 'version-ctrl-aall-sm_no_serial'))) - Facter.fact(:megaraid_serial).value.should be_nil + with('/usr/bin/MegaCli -AdpAllInfo -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'adpallinfo-aall-8.00.11'))) + Facter.fact(:megaraid_serial).value.should == '34A03AB' + end + + context 'but megacli output is missing serial number' do + it 'should return nil' do + Facter.fact(:megacli).stubs(:value).returns('/usr/bin/MegaCli') + Facter.fact(:megacli_legacy).stubs(:value).returns(true) + Facter::Util::Resolution.stubs(:exec). + with('/usr/bin/MegaCli -AdpAllInfo -aALL -NoLog'). + returns(File.read(fixtures('megacli', 'adpallinfo-aall-8.00.11-dell_no_serial'))) + Facter.fact(:megaraid_serial).value.should be_nil + end end end + end end