Skip to content

Commit

Permalink
prune mdadmversion fact value
Browse files Browse the repository at this point in the history
Instead of returning the literal string returned by `mdadm --version`,
parse out and return only the version number.
  • Loading branch information
Joshua Hoblitt committed May 20, 2014
1 parent a0dbd6b commit 28cecec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/facter/mdadmversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
setcode do
unless mdadm.nil?
# `mdadm --version` sends it's output to stderr
Facter::Util::Resolution.exec("#{mdadm} --version 2>&1")
output = Facter::Util::Resolution.exec("#{mdadm} --version 2>&1")
next if output.nil?
m = output.match(/mdadm - v([\d\.]+) -/)
next unless m.size == 2
m[1]
end
end
end
34 changes: 28 additions & 6 deletions spec/unit/facts/mdadmversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,36 @@
describe 'mdadmversion', :type => :fact do
before(:each) { Facter.clear }

context 'mdadm fact => /sbin/madam' do
it 'should get the version string' do
Facter.fact(:mdadm).stubs(:value).returns('/sbin/mdadm')
Facter::Util::Resolution.stubs(:exec).with('/sbin/mdadm --version 2>&1').returns('mdadm - v3.2.3 - 23rd December 2011')
context 'el5.x versions' do
context 'mdadm fact => /sbin/madam' do
it 'should get the version string' do
Facter.fact(:mdadm).stubs(:value).returns('/sbin/mdadm')
Facter::Util::Resolution.stubs(:exec).with('/sbin/mdadm --version 2>&1').returns('mdadm - v2.6.9 - 10th March 2009')

Facter.fact(:mdadmversion).value.should == 'mdadm - v3.2.3 - 23rd December 2011'
Facter.fact(:mdadmversion).value.should == '2.6.9'
end
end
end
end # el5.x versions

context 'el6.x versions' do
context 'mdadm fact => /sbin/madam' do
it 'should get the version string' do
Facter.fact(:mdadm).stubs(:value).returns('/sbin/mdadm')
Facter::Util::Resolution.stubs(:exec).with('/sbin/mdadm --version 2>&1').returns('mdadm - v3.2.3 - 23rd December 2011')

Facter.fact(:mdadmversion).value.should == '3.2.3'
end
end

context 'mdadm fact => /sbin/madam' do
it 'should get the version string' do
Facter.fact(:mdadm).stubs(:value).returns('/sbin/mdadm')
Facter::Util::Resolution.stubs(:exec).with('/sbin/mdadm --version 2>&1').returns('mdadm - v3.2.6 - 25th October 2012')

Facter.fact(:mdadmversion).value.should == '3.2.6'
end
end
end # el6.x versions

context 'mdadm fact not set' do
it 'should return nil' do
Expand Down

0 comments on commit 28cecec

Please sign in to comment.