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

Commit abb8949

Browse files
committed
Merge pull request #50 from petems/add_version_facts
Add version facts
2 parents 6b67fd7 + 33579cf commit abb8949

File tree

9 files changed

+186
-56
lines changed

9 files changed

+186
-56
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
source "https://rubygems.org"
22

3-
gem "cardboard", "~> 1.0"
3+
gem "cardboard", "~> 2.1.0"

Gemfile.lock

+58-53
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,80 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
addressable (2.3.5)
4+
CFPropertyList (2.2.8)
5+
addressable (2.3.6)
56
ansi (1.4.3)
6-
boxen (1.5.2)
7+
boxen (2.7.0)
78
ansi (~> 1.4)
89
hiera (~> 1.0)
910
highline (~> 1.6)
1011
json_pure (>= 1.7.7, < 2.0)
11-
librarian-puppet (~> 0.9.9)
12-
octokit (~> 1.15)
13-
puppet (~> 3.0)
14-
cardboard (1.0.4)
15-
boxen (~> 1.0)
12+
librarian-puppet (~> 1.0.0)
13+
octokit (~> 2.7, >= 2.7.1)
14+
puppet (~> 3.7)
15+
cardboard (2.1.0)
16+
boxen (~> 2.1)
1617
puppet-lint (~> 0.3)
1718
puppetlabs_spec_helper (~> 0.4)
18-
rspec-puppet (~> 0.1)
19-
diff-lcs (1.2.4)
20-
facter (1.7.2)
21-
faraday (0.8.8)
22-
multipart-post (~> 1.2.0)
23-
faraday_middleware (0.9.0)
24-
faraday (>= 0.7.4, < 0.9)
25-
hashie (2.0.5)
26-
hiera (1.2.1)
19+
rspec-puppet (~> 1.0)
20+
diff-lcs (1.2.5)
21+
facter (2.3.0)
22+
CFPropertyList (~> 2.2.6)
23+
faraday (0.9.0)
24+
multipart-post (>= 1.2, < 3)
25+
hiera (1.3.4)
2726
json_pure
28-
highline (1.6.19)
29-
json (1.8.0)
30-
json_pure (1.8.0)
31-
librarian-puppet (0.9.10)
32-
json
27+
highline (1.6.21)
28+
json (1.8.1)
29+
json_pure (1.8.1)
30+
librarian (0.1.2)
31+
highline
3332
thor (~> 0.15)
34-
metaclass (0.0.1)
35-
mocha (0.14.0)
33+
librarian-puppet (1.0.9)
34+
json
35+
librarian (>= 0.1.2)
36+
metaclass (0.0.4)
37+
mocha (1.1.0)
3638
metaclass (~> 0.0.1)
37-
multi_json (1.7.9)
38-
multipart-post (1.2.0)
39-
netrc (0.7.7)
40-
octokit (1.25.0)
41-
addressable (~> 2.2)
42-
faraday (~> 0.8)
43-
faraday_middleware (~> 0.9)
44-
hashie (~> 2.0)
45-
multi_json (~> 1.3)
46-
netrc (~> 0.7.7)
47-
puppet (3.2.4)
48-
facter (~> 1.6)
39+
multipart-post (2.0.0)
40+
octokit (2.7.2)
41+
sawyer (~> 0.5.2)
42+
puppet (3.7.3)
43+
facter (> 1.6, < 3)
4944
hiera (~> 1.0)
50-
rgen (~> 0.6.5)
45+
json_pure
5146
puppet-lint (0.3.2)
52-
puppetlabs_spec_helper (0.4.1)
53-
mocha (>= 0.10.5)
47+
puppet-syntax (1.3.0)
5448
rake
55-
rspec (>= 2.9.0)
56-
rspec-puppet (>= 0.1.1)
57-
rake (10.1.0)
58-
rgen (0.6.5)
59-
rspec (2.14.1)
60-
rspec-core (~> 2.14.0)
61-
rspec-expectations (~> 2.14.0)
62-
rspec-mocks (~> 2.14.0)
63-
rspec-core (2.14.5)
64-
rspec-expectations (2.14.2)
65-
diff-lcs (>= 1.1.3, < 2.0)
66-
rspec-mocks (2.14.3)
67-
rspec-puppet (0.1.6)
49+
puppetlabs_spec_helper (0.8.2)
50+
mocha
51+
puppet-lint
52+
puppet-syntax
53+
rake
54+
rspec
55+
rspec-puppet
56+
rake (10.4.2)
57+
rspec (3.1.0)
58+
rspec-core (~> 3.1.0)
59+
rspec-expectations (~> 3.1.0)
60+
rspec-mocks (~> 3.1.0)
61+
rspec-core (3.1.7)
62+
rspec-support (~> 3.1.0)
63+
rspec-expectations (3.1.2)
64+
diff-lcs (>= 1.2.0, < 2.0)
65+
rspec-support (~> 3.1.0)
66+
rspec-mocks (3.1.3)
67+
rspec-support (~> 3.1.0)
68+
rspec-puppet (1.0.1)
6869
rspec
69-
thor (0.18.1)
70+
rspec-support (3.1.2)
71+
sawyer (0.5.5)
72+
addressable (~> 2.3.5)
73+
faraday (~> 0.8, < 0.10)
74+
thor (0.19.1)
7075

7176
PLATFORMS
7277
ruby
7378

7479
DEPENDENCIES
75-
cardboard (~> 1.0)
80+
cardboard (~> 2.1.0)

lib/facter/java_patch_level.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Fact: java_patch_level
2+
#
3+
# Purpose: get Java's patch level
4+
#
5+
# Resolution:
6+
# Uses java_version fact splits on the patch number (after _)
7+
#
8+
# Caveats:
9+
# none
10+
#
11+
# Notes:
12+
# None
13+
Facter.add(:java_patch_level) do
14+
setcode do
15+
java_version = Facter.value(:java_version)
16+
if java_version.nil?
17+
"JAVA_NOT_INSTALLED"
18+
else
19+
java_patch_level = java_version.strip.split('_')[1]
20+
end
21+
end
22+
end

lib/facter/java_version.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Fact: java_version
2+
#
3+
# Purpose: store java versions in the config DB
4+
#
5+
# Resolution:
6+
# Tests for presence of java, returns nil if not present
7+
# returns output of "java -version" and splits on \n + '"'
8+
#
9+
# Caveats:
10+
# none
11+
#
12+
# Notes:
13+
# None
14+
Facter.add(:java_version) do
15+
setcode do
16+
t_java = Facter::Util::Resolution.exec("java -version 2>&1")
17+
java_version = t_java.to_s.lines.first.strip.split(/version/)[1].gsub(/"/, "").strip
18+
end
19+
end

manifests/init.pp

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
$jdk_dir = "/Library/Java/JavaVirtualMachines/jdk1.7.0_${update_version}.jdk"
1616
$sec_dir = "${jdk_dir}/Contents/Home/jre/lib/security"
1717

18+
if ((versioncmp($::macosx_productversion_major, '10.10') >= 0) and
19+
versioncmp($update_version, '71') < 0)
20+
{
21+
fail('Yosemite Requires Java 7 with a patch level >= 71 (Bug JDK-8027686)')
22+
}
23+
1824
package {
1925
"jre-7u${update_version}.dmg":
2026
ensure => present,

spec/classes/java_idrac7_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
let(:facts) { default_test_facts }
55

66
it do
7-
should include_class('java')
7+
should contain_class('java')
88

99
['.java', '.java/deployment', '.java/deployment/security'].each do |dir|
1010
should contain_file("/Users/testuser/#{dir}").with({

spec/classes/java_spec.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111

1212
it do
13-
should include_class('boxen::config')
13+
should contain_class('boxen::config')
1414

1515
should contain_package('jre-7u42.dmg').with({
1616
:ensure => 'present',
@@ -32,4 +32,18 @@
3232
:require => 'Package[java]'
3333
})
3434
end
35+
36+
context 'fails when java version has Yosemite relevant bug' do
37+
let(:facts) { default_test_facts.merge({ :macosx_productversion_major => '10.10' }) }
38+
let(:params) {
39+
{
40+
:update_version => '51',
41+
}
42+
}
43+
it do
44+
expect {
45+
should contain_class('java')
46+
}.to raise_error(/Yosemite Requires Java 7 with a patch level >= 71 \(Bug JDK\-8027686\)/)
47+
end
48+
end
3549
end
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require "spec_helper"
2+
3+
describe Facter::Util::Fact do
4+
before {
5+
Facter.clear
6+
}
7+
8+
describe "java_patch_level" do
9+
context "if java is installed" do
10+
context 'returns java patch version extracted from java_version fact' do
11+
before :each do
12+
allow(Facter.fact(:java_version)).to receive(:value).and_return("1.7.0_71")
13+
end
14+
it do
15+
Facter.fact(:java_patch_level).value.should == "71"
16+
end
17+
end
18+
end
19+
20+
context "if java is installed" do
21+
context 'returns java patch version extracted from java_version fact' do
22+
before :each do
23+
allow(Facter.fact(:java_version)).to receive(:value).and_return(nil)
24+
end
25+
it do
26+
Facter.fact(:java_patch_level).value.should == "JAVA_NOT_INSTALLED"
27+
end
28+
end
29+
end
30+
end
31+
end

spec/unit/facter/java_version_spec.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require "spec_helper"
2+
3+
describe Facter::Util::Fact do
4+
before {
5+
Facter.clear
6+
allow(Facter::Util::Resolution).to receive(:exec).with(anything()).and_return(nil)
7+
allow(Facter.fact(:kernel)).to receive(:value).and_return("Darwin")
8+
}
9+
10+
describe "java_version" do
11+
context 'returns java version when java present' do
12+
it do
13+
java_version_output = <<-EOS
14+
java version "1.7.0_71"
15+
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
16+
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
17+
EOS
18+
allow(Facter::Util::Resolution).to receive(:exec).with("java -version 2>&1").
19+
and_return(java_version_output)
20+
Facter.fact(:java_version).value.should == "1.7.0_71"
21+
end
22+
end
23+
24+
context 'returns nil when java present' do
25+
it do
26+
java_version_output = "bash: java: command not found"
27+
allow(Facter::Util::Resolution).to receive(:exec).with("java -version 2>&1").
28+
and_return(java_version_output)
29+
Facter.fact(:java_version).value.should be_nil
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)