forked from glarizza/puppet-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from petems/MODULES-1619-add_haproxy_version_…
…fact MODULES-1619 Add haproxy version fact
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |