This repository has been archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
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 #50 from petems/add_version_facts
Add version facts
- Loading branch information
Showing
9 changed files
with
186 additions
and
56 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "cardboard", "~> 1.0" | ||
gem "cardboard", "~> 2.1.0" |
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 |
---|---|---|
@@ -1,75 +1,80 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.3.5) | ||
CFPropertyList (2.2.8) | ||
addressable (2.3.6) | ||
ansi (1.4.3) | ||
boxen (1.5.2) | ||
boxen (2.7.0) | ||
ansi (~> 1.4) | ||
hiera (~> 1.0) | ||
highline (~> 1.6) | ||
json_pure (>= 1.7.7, < 2.0) | ||
librarian-puppet (~> 0.9.9) | ||
octokit (~> 1.15) | ||
puppet (~> 3.0) | ||
cardboard (1.0.4) | ||
boxen (~> 1.0) | ||
librarian-puppet (~> 1.0.0) | ||
octokit (~> 2.7, >= 2.7.1) | ||
puppet (~> 3.7) | ||
cardboard (2.1.0) | ||
boxen (~> 2.1) | ||
puppet-lint (~> 0.3) | ||
puppetlabs_spec_helper (~> 0.4) | ||
rspec-puppet (~> 0.1) | ||
diff-lcs (1.2.4) | ||
facter (1.7.2) | ||
faraday (0.8.8) | ||
multipart-post (~> 1.2.0) | ||
faraday_middleware (0.9.0) | ||
faraday (>= 0.7.4, < 0.9) | ||
hashie (2.0.5) | ||
hiera (1.2.1) | ||
rspec-puppet (~> 1.0) | ||
diff-lcs (1.2.5) | ||
facter (2.3.0) | ||
CFPropertyList (~> 2.2.6) | ||
faraday (0.9.0) | ||
multipart-post (>= 1.2, < 3) | ||
hiera (1.3.4) | ||
json_pure | ||
highline (1.6.19) | ||
json (1.8.0) | ||
json_pure (1.8.0) | ||
librarian-puppet (0.9.10) | ||
json | ||
highline (1.6.21) | ||
json (1.8.1) | ||
json_pure (1.8.1) | ||
librarian (0.1.2) | ||
highline | ||
thor (~> 0.15) | ||
metaclass (0.0.1) | ||
mocha (0.14.0) | ||
librarian-puppet (1.0.9) | ||
json | ||
librarian (>= 0.1.2) | ||
metaclass (0.0.4) | ||
mocha (1.1.0) | ||
metaclass (~> 0.0.1) | ||
multi_json (1.7.9) | ||
multipart-post (1.2.0) | ||
netrc (0.7.7) | ||
octokit (1.25.0) | ||
addressable (~> 2.2) | ||
faraday (~> 0.8) | ||
faraday_middleware (~> 0.9) | ||
hashie (~> 2.0) | ||
multi_json (~> 1.3) | ||
netrc (~> 0.7.7) | ||
puppet (3.2.4) | ||
facter (~> 1.6) | ||
multipart-post (2.0.0) | ||
octokit (2.7.2) | ||
sawyer (~> 0.5.2) | ||
puppet (3.7.3) | ||
facter (> 1.6, < 3) | ||
hiera (~> 1.0) | ||
rgen (~> 0.6.5) | ||
json_pure | ||
puppet-lint (0.3.2) | ||
puppetlabs_spec_helper (0.4.1) | ||
mocha (>= 0.10.5) | ||
puppet-syntax (1.3.0) | ||
rake | ||
rspec (>= 2.9.0) | ||
rspec-puppet (>= 0.1.1) | ||
rake (10.1.0) | ||
rgen (0.6.5) | ||
rspec (2.14.1) | ||
rspec-core (~> 2.14.0) | ||
rspec-expectations (~> 2.14.0) | ||
rspec-mocks (~> 2.14.0) | ||
rspec-core (2.14.5) | ||
rspec-expectations (2.14.2) | ||
diff-lcs (>= 1.1.3, < 2.0) | ||
rspec-mocks (2.14.3) | ||
rspec-puppet (0.1.6) | ||
puppetlabs_spec_helper (0.8.2) | ||
mocha | ||
puppet-lint | ||
puppet-syntax | ||
rake | ||
rspec | ||
rspec-puppet | ||
rake (10.4.2) | ||
rspec (3.1.0) | ||
rspec-core (~> 3.1.0) | ||
rspec-expectations (~> 3.1.0) | ||
rspec-mocks (~> 3.1.0) | ||
rspec-core (3.1.7) | ||
rspec-support (~> 3.1.0) | ||
rspec-expectations (3.1.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.1.0) | ||
rspec-mocks (3.1.3) | ||
rspec-support (~> 3.1.0) | ||
rspec-puppet (1.0.1) | ||
rspec | ||
thor (0.18.1) | ||
rspec-support (3.1.2) | ||
sawyer (0.5.5) | ||
addressable (~> 2.3.5) | ||
faraday (~> 0.8, < 0.10) | ||
thor (0.19.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
cardboard (~> 1.0) | ||
cardboard (~> 2.1.0) |
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: java_patch_level | ||
# | ||
# Purpose: get Java's patch level | ||
# | ||
# Resolution: | ||
# Uses java_version fact splits on the patch number (after _) | ||
# | ||
# Caveats: | ||
# none | ||
# | ||
# Notes: | ||
# None | ||
Facter.add(:java_patch_level) do | ||
setcode do | ||
java_version = Facter.value(:java_version) | ||
if java_version.nil? | ||
"JAVA_NOT_INSTALLED" | ||
else | ||
java_patch_level = java_version.strip.split('_')[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,19 @@ | ||
# Fact: java_version | ||
# | ||
# Purpose: store java versions in the config DB | ||
# | ||
# Resolution: | ||
# Tests for presence of java, returns nil if not present | ||
# returns output of "java -version" and splits on \n + '"' | ||
# | ||
# Caveats: | ||
# none | ||
# | ||
# Notes: | ||
# None | ||
Facter.add(:java_version) do | ||
setcode do | ||
t_java = Facter::Util::Resolution.exec("java -version 2>&1") | ||
java_version = t_java.to_s.lines.first.strip.split(/version/)[1].gsub(/"/, "").strip | ||
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
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
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
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,31 @@ | ||
require "spec_helper" | ||
|
||
describe Facter::Util::Fact do | ||
before { | ||
Facter.clear | ||
} | ||
|
||
describe "java_patch_level" do | ||
context "if java is installed" do | ||
context 'returns java patch version extracted from java_version fact' do | ||
before :each do | ||
allow(Facter.fact(:java_version)).to receive(:value).and_return("1.7.0_71") | ||
end | ||
it do | ||
Facter.fact(:java_patch_level).value.should == "71" | ||
end | ||
end | ||
end | ||
|
||
context "if java is installed" do | ||
context 'returns java patch version extracted from java_version fact' do | ||
before :each do | ||
allow(Facter.fact(:java_version)).to receive(:value).and_return(nil) | ||
end | ||
it do | ||
Facter.fact(:java_patch_level).value.should == "JAVA_NOT_INSTALLED" | ||
end | ||
end | ||
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,33 @@ | ||
require "spec_helper" | ||
|
||
describe Facter::Util::Fact do | ||
before { | ||
Facter.clear | ||
allow(Facter::Util::Resolution).to receive(:exec).with(anything()).and_return(nil) | ||
allow(Facter.fact(:kernel)).to receive(:value).and_return("Darwin") | ||
} | ||
|
||
describe "java_version" do | ||
context 'returns java version when java present' do | ||
it do | ||
java_version_output = <<-EOS | ||
java version "1.7.0_71" | ||
Java(TM) SE Runtime Environment (build 1.7.0_71-b14) | ||
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode) | ||
EOS | ||
allow(Facter::Util::Resolution).to receive(:exec).with("java -version 2>&1"). | ||
and_return(java_version_output) | ||
Facter.fact(:java_version).value.should == "1.7.0_71" | ||
end | ||
end | ||
|
||
context 'returns nil when java present' do | ||
it do | ||
java_version_output = "bash: java: command not found" | ||
allow(Facter::Util::Resolution).to receive(:exec).with("java -version 2>&1"). | ||
and_return(java_version_output) | ||
Facter.fact(:java_version).value.should be_nil | ||
end | ||
end | ||
end | ||
end |