Skip to content

Commit

Permalink
Merge pull request #144 from petems/MODULES-1619-add_haproxy_version_…
Browse files Browse the repository at this point in the history
…fact

MODULES-1619 Add haproxy version fact
  • Loading branch information
cmurphy committed Jan 8, 2015
2 parents f74d749 + de4a194 commit decd2de
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/facter/haproxy_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Fact: haproxy_version
#
# Purpose: get haproxy's current version
#
# Resolution:
# Uses haproxy's -v flag and parses the result from 'version'
#
# Caveats:
# none
#
# Notes:
# None
if Facter::Util::Resolution.which('haproxy')
Facter.add('haproxy_version') do
haproxy_version_cmd = 'haproxy -v 2>&1'
haproxy_version_result = Facter::Util::Resolution.exec(haproxy_version_cmd)
setcode do
haproxy_version_result.to_s.lines.first.strip.split(/HA-Proxy/)[1].strip.split(/version/)[1].strip.split(/((\d+\.){2,}\d+).*/)[1]
end
end
end

27 changes: 27 additions & 0 deletions spec/unit/facter/haproxy_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "spec_helper"

describe Facter::Util::Fact do
before {
Facter.clear
}

context "haproxy present" do
it do
haproxy_version_output = <<-EOS
HA-Proxy version 1.5.3 2014/07/25
Copyright 2000-2014 Willy Tarreau <w@1wt.eu>
EOS
Facter::Util::Resolution.expects(:which).with("haproxy").returns(true)
Facter::Util::Resolution.expects(:exec).with("haproxy -v 2>&1").returns(haproxy_version_output)
Facter.fact(:haproxy_version).value.should == "1.5.3"
end
end

context "haproxy not present" do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with("haproxy").returns(false)
Facter.fact(:haproxy_version).should be_nil
end
end
end

0 comments on commit decd2de

Please sign in to comment.