Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODULES-1619 Add haproxy version fact #144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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