Skip to content

Commit

Permalink
reworking the management of the jre installation
Browse files Browse the repository at this point in the history
  • Loading branch information
liamjbennett committed May 19, 2015
1 parent 7019c71 commit 5b304fe
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ spec/fixtures/
coverage/
*.iml
.idea/
log/
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ end
group :system_tests do
gem "beaker"
gem "beaker-rspec"
gem "vagrant-wrapper"
end
13 changes: 0 additions & 13 deletions files/rundeck_version

This file was deleted.

10 changes: 0 additions & 10 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,6 @@
require => File[$properties_dir]
}

ensure_resource('file', ['/etc/facter', '/etc/facter/facts.d'], {'ensure' => 'directory'})

file { '/etc/facter/facts.d/rundeck_version':
ensure => present,
source => 'puppet:///modules/rundeck/rundeck_version',
owner => root,
group => root,
mode => '0755'
}

class { 'rundeck::config::global::framework': } ->
class { 'rundeck::config::global::project': } ->
class { 'rundeck::config::global::rundeck_config': } ->
Expand Down
42 changes: 42 additions & 0 deletions manifests/facts.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# == Class: rundeck::facts
#
# Class to add some facts for rundeck. They have been added as an external fact
# because we do not want to distrubute these facts to all systems.
#
# === Parameters
#
# [*ensure*] - ensure that these facts are added to the system
#
# === Examples
#
# class { 'rundeck::facts': }
#
class rundeck::facts(
$ensure = 'present',
) {

if $::puppetversion =~ /Puppet Enterprise/ {
$ruby_bin = '/opt/puppet/bin/ruby'
$dir = 'puppetlabs/'
} else {
$ruby_bin = '/usr/bin/env ruby'
$dir = ''
}

if ! defined(File["/etc/${dir}facter"]) {
file { "/etc/${dir}facter":
ensure => directory,
}
}
if ! defined(File["/etc/${dir}facter/facts.d"]) {
file { "/etc/${dir}facter/facts.d":
ensure => directory,
}
}

file { "/etc/${dir}facter/facts.d/rundeck_facts.rb":
ensure => $ensure,
content => template('rundeck/facts.rb.erb'),
mode => '0500',
}
}
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
validate_string($group)
validate_absolute_path($rdeck_home)

class { 'rundeck::facts': } ->
class { 'rundeck::install': } ->
class { 'rundeck::config': } ->
class { 'rundeck::service': } ->
Expand Down
30 changes: 28 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,33 @@
$projects_dir = $framework_config['framework.projects.dir']

if $jre_manage {
ensure_resource('package', $jre_name, {'ensure' => $jre_ensure} )

if "x${jre_name}x" == 'xx' {
case $::osfamily {
'Debian': {
if versioncmp($package_ensure, '2.4') < 0 {
$jre_package_name = 'openjdk-6-jre'
} else {
$jre_package_name = 'openjdk-7-jre'
}
}
'RedHat', 'Amazon': {
if versioncmp($package_ensure, '2.4') < 0 {
$jre_package_name = 'java-1.6.0-openjdk'
} else {
$jre_package_name = 'java-1.7.0-openjdk'
}
}
default: {
err("The osfamily: ${::osfamily} is not supported")
}
}
} else {
$jre_package_name = $jre_name
}

notify { "jre_name: ${jre_package_name}": }
ensure_resource('package', $jre_package_name, {'ensure' => $jre_ensure} )
}

$user = $rundeck::user
Expand Down Expand Up @@ -63,7 +89,7 @@
exec { 'install rundeck package':
command => "/usr/bin/dpkg --force-confold -i /tmp/rundeck-${package_ensure}.deb",
unless => "/usr/bin/dpkg -l | grep rundeck | grep ${version}",
require => [ Exec['download rundeck package'], Exec['stop rundeck service'], Package[$jre_name] ]
require => [ Exec['download rundeck package'], Exec['stop rundeck service'], Package[$jre_package_name] ]
}
}

Expand Down
6 changes: 3 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
case $::osfamily {
'Debian': {
$package_name = 'rundeck'
$package_ensure = '2.2.3-1-GA'
$package_ensure = '2.5.0-1-GA'
$service_name = 'rundeckd'
$jre_name = 'openjdk-6-jre'
$jre_name = ''
$jre_ensure = 'installed'
$manage_yum_repo = false
}
'RedHat', 'Amazon': {
$package_name = 'rundeck'
$package_ensure = 'installed'
$service_name = 'rundeckd'
$jre_name = 'java-1.7.0-openjdk'
$jre_name = ''
$jre_ensure = 'installed'
$manage_yum_repo = true
}
Expand Down
10 changes: 0 additions & 10 deletions spec/acceptance/nodesets/centos-59-x64.yml

This file was deleted.

10 changes: 0 additions & 10 deletions spec/acceptance/nodesets/ubuntu-server-10044-x64.yml

This file was deleted.

63 changes: 63 additions & 0 deletions spec/acceptance/rundeck_old_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'spec_helper_acceptance'

describe 'rundeck class' do

context 'older package version', :if => fact('osfamily').eql?('Debian') do
it 'should work with no errors' do

puppet('resource', 'package', 'rundeck', 'ensure=absent')
puppet('resource', 'file', '/var/lib/rundeck', 'ensure=absent')

pp = <<-EOS
class { 'rundeck':
package_ensure => '2.0.0-1-GA'
}
EOS

# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end

describe package('openjdk-6-jre') do
it { should be_installed }
end

describe package('rundeck') do
it { should be_installed.with_version('2.0.0') }
end

describe service('rundeckd') do
it { should be_running }
end
end

context 'older package version', :if => fact('osfamily').eql?('RedHat') do
it 'should work with no errors' do

puppet('resource', 'package', 'rundeck', 'ensure=absent')

pp = <<-EOS
class { 'rundeck':
package_ensure => '2.0.0-1.8.GA'
}
EOS

# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end

describe package('java-1.6.0-openjdk') do
it { should be_installed }
end

describe package('rundeck') do
it { should be_installed.with_version('2.0.0') }
end

describe service('rundeckd') do
it { should be_running }
end
end
end
54 changes: 8 additions & 46 deletions spec/acceptance/rundeck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class { 'rundeck': }
expect(apply_manifest(pp).exit_code).to eq(0)
end

describe package('openjdk-6-jre') do
describe package('openjdk-7-jre') do
it { should be_installed }
end

Expand All @@ -25,7 +25,7 @@ class { 'rundeck': }
it { should be_running }
end
end

context 'default parameters on centos', :if => fact('osfamily').eql?('RedHat') do
it 'should work with no errors' do
pp = <<-EOS
Expand All @@ -50,56 +50,18 @@ class { 'rundeck': }
end
end

context 'older package version', :if => fact('osfamily').eql?('Debian') do
it 'should work with no errors' do

puppet('resource', 'package', 'rundeck', 'ensure=absent')

pp = <<-EOS
class { 'rundeck':
package_ensure => '2.0.0-1-GA'
}
EOS

# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end

describe package('rundeck') do
it { should be_installed.with_version('2.0.0') }
end
end

context 'older package version', :if => fact('osfamily').eql?('RedHat') do
it 'should work with no errors' do

puppet('resource', 'package', 'rundeck', 'ensure=absent')

pp = <<-EOS
class { 'rundeck':
package_ensure => '2.0.0-1.8.GA'
}
EOS

# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end

describe package('rundeck') do
it { should be_installed.with_version('2.0.0') }
end
end

context 'different jre version on ubuntu', :if => fact('osfamily').eql?('Debain') do
it 'should work with no errors' do
pp = <<-EOS
class { 'rundeck':
jre_name => 'openjdk-7-jre',
jre_ensure => '7u51-2.4.4-0ubuntu0.12.04.2'
jre_name => 'openjdk-8-jre',
jre_ensure => '8u45-b14-1~12.04'
}
EOS

on host, "apt-get -q -y install python-software-properties"
on host, "add-apt-repository ppa:openjdk-r/ppa -y"
on host, "apt-get update"

# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/rundeck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
if osfamily.eql?('RedHat')
it { should contain_package('java-1.7.0-openjdk') }
else
it { should contain_package('openjdk-6-jre') }
it { should contain_package('openjdk-7-jre') }
end

end
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
require 'puppetlabs_spec_helper/module_spec_helper'

RSpec.configure do |c|
c.default_facts = {
:puppetversion => '3.7.4',
}
end
11 changes: 3 additions & 8 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@


hosts.each do |host|


version = ENV['PUPPET_GEM_VERSION']
install_puppet(:version => version)
end

Spec.configure do |c|
RSpec.configure do |c|
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

c.formatter = :documentation

c.before :suite do
#The gets around a bug where windows can't validate the cert when using https
#forge_repo = '--module_repository=http://forge.puppetlabs.com'
forge_repo = ''

hosts.each do |host|
c.host = host
Expand All @@ -27,9 +22,9 @@

copy_module_to(host, :source => proj_root, :module_name => name)

on host, puppet('module','install', forge_repo, "puppetlabs-stdlib"), { :acceptable_exit_codes => [0,1] }
on host, puppet('module','install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }

on host, puppet('module','install', forge_repo, "puppetlabs-inifile"), { :acceptable_exit_codes => [0,1] }
on host, puppet('module','install', 'puppetlabs-inifile'), { :acceptable_exit_codes => [0,1] }
end
end
end
13 changes: 13 additions & 0 deletions templates/facts.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!<%= @ruby_bin %>
# Fact: rundeck_version
#
# Purpose: Return facts for the running version of rundeck.
#

if File.exists?('/etc/debian_version')
version = %["dpkg-query -W -f 'rundeck_version=${Version}\n' rundeck"]
puts version
elsif File.exists?('/etc/redhat-release') or File.exists?('/etc/centos-release')
version = %["rpm -q --qf 'rundeck_version=%{VERSION}\n' rundeck"]
puts version
end

0 comments on commit 5b304fe

Please sign in to comment.