Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #50 from petems/add_version_facts
Browse files Browse the repository at this point in the history
Add version facts
  • Loading branch information
dgoodlad committed Dec 23, 2014
2 parents 6b67fd7 + 33579cf commit abb8949
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Gemfile
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"
111 changes: 58 additions & 53 deletions Gemfile.lock
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)
22 changes: 22 additions & 0 deletions lib/facter/java_patch_level.rb
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
19 changes: 19 additions & 0 deletions lib/facter/java_version.rb
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
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
$jdk_dir = "/Library/Java/JavaVirtualMachines/jdk1.7.0_${update_version}.jdk"
$sec_dir = "${jdk_dir}/Contents/Home/jre/lib/security"

if ((versioncmp($::macosx_productversion_major, '10.10') >= 0) and
versioncmp($update_version, '71') < 0)
{
fail('Yosemite Requires Java 7 with a patch level >= 71 (Bug JDK-8027686)')
}

package {
"jre-7u${update_version}.dmg":
ensure => present,
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/java_idrac7_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:facts) { default_test_facts }

it do
should include_class('java')
should contain_class('java')

['.java', '.java/deployment', '.java/deployment/security'].each do |dir|
should contain_file("/Users/testuser/#{dir}").with({
Expand Down
16 changes: 15 additions & 1 deletion spec/classes/java_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

it do
should include_class('boxen::config')
should contain_class('boxen::config')

should contain_package('jre-7u42.dmg').with({
:ensure => 'present',
Expand All @@ -32,4 +32,18 @@
:require => 'Package[java]'
})
end

context 'fails when java version has Yosemite relevant bug' do
let(:facts) { default_test_facts.merge({ :macosx_productversion_major => '10.10' }) }
let(:params) {
{
:update_version => '51',
}
}
it do
expect {
should contain_class('java')
}.to raise_error(/Yosemite Requires Java 7 with a patch level >= 71 \(Bug JDK\-8027686\)/)
end
end
end
31 changes: 31 additions & 0 deletions spec/unit/facter/java_patch_level_spec.rb
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
33 changes: 33 additions & 0 deletions spec/unit/facter/java_version_spec.rb
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

0 comments on commit abb8949

Please sign in to comment.