Skip to content

Commit 1450bed

Browse files
jgaworSean OMeara
authored andcommitted
[COOK-3764] - IBM Java installer needs 'rpm' package on Ubuntu
Signed-off-by: Sean OMeara <someara@opscode.com>
1 parent c16c7d0 commit 1450bed

6 files changed

Lines changed: 152 additions & 1 deletion

File tree

attributes/default.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
end
6060

6161
case node['java']['install_flavor']
62-
when 'ibm'
62+
when 'ibm', 'ibm_tar'
6363
default['java']['ibm']['url'] = nil
6464
default['java']['ibm']['checksum'] = nil
6565
default['java']['ibm']['accept_ibm_download_terms'] = false

recipes/ibm.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# limitations under the License.
1818

1919
require 'uri'
20+
2021
source_url = node['java']['ibm']['url']
2122
jdk_uri = ::URI.parse(source_url)
2223
jdk_filename = ::File.basename(jdk_uri.path)
@@ -25,6 +26,13 @@
2526
raise "You must set the attribute `node['java']['ibm']['url']` to a valid HTTP URI"
2627
end
2728

29+
# "installable package" installer needs rpm on Ubuntu
30+
if platform_family?('debian') && jdk_filename !~ /archive/
31+
package "rpm" do
32+
action :install
33+
end
34+
end
35+
2836
template "#{Chef::Config[:file_cache_path]}/installer.properties" do
2937
source "ibm_jdk.installer.properties.erb"
3038
only_if { node['java']['ibm']['accept_ibm_download_terms'] }

recipes/ibm_tar.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Cookbook Name:: java
2+
# Recipe:: ibm_tar
3+
#
4+
# Copyright 2013, Opscode, Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
require 'uri'
19+
20+
source_url = node['java']['ibm']['url']
21+
jdk_uri = ::URI.parse(source_url)
22+
jdk_filename = ::File.basename(jdk_uri.path)
23+
24+
unless valid_ibm_jdk_uri?(source_url)
25+
raise "You must set the attribute `node['java']['ibm']['url']` to a valid URI"
26+
end
27+
28+
unless jdk_filename =~ /\.(tar.gz|tgz)$/
29+
raise "The attribute `node['java']['ibm']['url']` must specify a .tar.gz file"
30+
end
31+
32+
remote_file "#{Chef::Config[:file_cache_path]}/#{jdk_filename}" do
33+
source source_url
34+
mode 00755
35+
if node['java']['ibm']['checksum']
36+
checksum node['java']['ibm']['checksum']
37+
action :create
38+
else
39+
action :create_if_missing
40+
end
41+
notifies :create, "directory[create-java-home]", :immediately
42+
notifies :run, "execute[untar-ibm-java]", :immediately
43+
end
44+
45+
directory "create-java-home" do
46+
path node['java']['java_home']
47+
mode 00755
48+
recursive true
49+
end
50+
51+
execute "untar-ibm-java" do
52+
cwd Chef::Config[:file_cache_path]
53+
command "tar xzf ./#{jdk_filename} -C #{node['java']['java_home']} --strip 1"
54+
creates "#{node['java']['java_home']}/jre/bin/java"
55+
end
56+
57+
include_recipe "java::set_java_home"

spec/default_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,17 @@
6565
end
6666
end
6767

68+
context 'ibm_tar' do
69+
let(:chef_run) do
70+
runner = ChefSpec::ChefRunner.new
71+
runner.node.set['java']['install_flavor'] = 'ibm_tar'
72+
runner.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.tar.gz'
73+
runner.converge('java::default')
74+
end
75+
76+
it 'should include the ibm_tar recipe' do
77+
expect(chef_run).to include_recipe('java::ibm_tar')
78+
end
79+
end
80+
6881
end

spec/ibm_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,49 @@
2525
it 'includes the set_java_home recipe' do
2626
expect(chef_run).to include_recipe('java::set_java_home')
2727
end
28+
29+
context 'install on ubuntu' do
30+
let(:chef_run) do
31+
runner = ChefSpec::ChefRunner.new(:platform => 'ubuntu', :version => '12.04')
32+
runner.node.set['java']['install_flavor'] = 'ibm'
33+
runner.node.set['java']['ibm']['checksum'] = 'deadbeef'
34+
runner.node.set['java']['ibm']['accept_ibm_download_terms'] = true
35+
runner
36+
end
37+
38+
it 'install rpm for installable package' do
39+
chef_run.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.bin'
40+
chef_run.converge('java::ibm')
41+
expect(chef_run).to install_package('rpm')
42+
end
43+
44+
it 'no need to install rpm for tgz package' do
45+
chef_run.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java-archive.bin'
46+
chef_run.converge('java::ibm')
47+
expect(chef_run).not_to install_package('rpm')
48+
end
49+
end
50+
51+
context 'install on centos' do
52+
let(:chef_run) do
53+
runner = ChefSpec::ChefRunner.new(:platform => 'centos', :version => '5.8')
54+
runner.node.set['java']['install_flavor'] = 'ibm'
55+
runner.node.set['java']['ibm']['checksum'] = 'deadbeef'
56+
runner.node.set['java']['ibm']['accept_ibm_download_terms'] = true
57+
runner
58+
end
59+
60+
it 'no need to install rpm for installable package' do
61+
chef_run.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.bin'
62+
chef_run.converge('java::ibm')
63+
expect(chef_run).not_to install_package('rpm')
64+
end
65+
66+
it 'no need to install rpm for tgz package' do
67+
chef_run.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java-archive.bin'
68+
chef_run.converge('java::ibm')
69+
expect(chef_run).not_to install_package('rpm')
70+
end
71+
end
72+
2873
end

spec/ibm_tar_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'spec_helper'
2+
3+
describe 'java::ibm_tar' do
4+
let(:chef_run) do
5+
runner = ChefSpec::ChefRunner.new
6+
runner.node.set['java']['java_home'] = '/home/java'
7+
runner.node.set['java']['install_flavor'] = 'ibm'
8+
runner.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.tar.gz'
9+
runner.node.set['java']['ibm']['checksum'] = 'deadbeef'
10+
runner.converge('java::ibm_tar')
11+
end
12+
13+
it 'downloads the remote jdk file' do
14+
expect(chef_run).to create_remote_file('/var/chef/cache/ibm-java.tar.gz')
15+
end
16+
17+
it 'create java_home directory' do
18+
expect(chef_run).to create_directory('/home/java')
19+
end
20+
21+
it 'untar the jdk file' do
22+
expect(chef_run).to execute_command('tar xzf ./ibm-java.tar.gz -C /home/java --strip 1')
23+
end
24+
25+
it 'includes the set_java_home recipe' do
26+
expect(chef_run).to include_recipe('java::set_java_home')
27+
end
28+
end

0 commit comments

Comments
 (0)