diff --git a/.fixtures.yml b/.fixtures.yml index 7fa5bb4..4cc9072 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,13 @@ fixtures: repositories: - "puppi": "git://github.com/example42/puppi.git" - "monitor": "git://github.com/example42/puppet-monitor.git" - "firewall": "git://github.com/example42/puppet-firewall.git" - "iptables": "git://github.com/example42/puppet-iptables.git" - "concat": "git://github.com/example42/puppet-concat.git" + concat: + repo: 'https://github.com/puppetlabs/puppetlabs-concat.git' + ref: '2.1.0' + puppi: + repo: 'https://github.com/example42/puppi.git' + ref: 'v2.1.13' + stdlib: + repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' + ref: '4.6.0' symlinks: - "java": "#{source_dir}" - + java: "#{source_dir}" diff --git a/.travis.yml b/.travis.yml index 9f85bab..6fb0ec0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,61 @@ +--- language: ruby + bundler_args: --without development + rvm: - 1.8.7 - 1.9.3 - - 2.1.4 -script: - - "bundle exec rake lint spec SPEC_OPTS='--format documentation'" + - 2.0.0 + - 2.1.0 + env: - - PUPPET_VERSION="~> 2.7.0" - - PUPPET_VERSION="~> 3.0.0" - - PUPPET_VERSION="~> 3.1.0" - - PUPPET_VERSION="~> 3.8.0" - - PUPPET_VERSION="~> 4.2" + matrix: + - PUPPET_GEM_VERSION="~> 3.1.0" + - PUPPET_GEM_VERSION="~> 3.2.0" + - PUPPET_GEM_VERSION="~> 3.3.0" + - PUPPET_GEM_VERSION="~> 3.4.0" + - PUPPET_GEM_VERSION="~> 3.5.0" + - PUPPET_GEM_VERSION="~> 3.6.0" + - PUPPET_GEM_VERSION="~> 3.7.0" + - PUPPET_GEM_VERSION="~> 3.8.0" + - PUPPET_GEM_VERSION="~> 3" FUTURE_PARSER="yes" + - PUPPET_GEM_VERSION="~> 4.0.0" + - PUPPET_GEM_VERSION="~> 4.1.0" + - PUPPET_GEM_VERSION="~> 4.2.0" + - PUPPET_GEM_VERSION="~> 4.3.0" + - PUPPET_GEM_VERSION="~> 4.4.0" + - PUPPET_GEM_VERSION="~> 4" + +sudo: false + +script: 'bundle exec rake metadata_lint && bundle exec rake validate && bundle exec rake lint && SPEC_OPTS="--format documentation" bundle exec rake spec' + matrix: + fast_finish: true exclude: + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.1.0" + - rvm: 2.1.0 + env: PUPPET_GEM_VERSION="~> 3.1.0" + - rvm: 2.1.0 + env: PUPPET_GEM_VERSION="~> 3.2.0" + - rvm: 2.1.0 + env: PUPPET_GEM_VERSION="~> 3.3.0" + - rvm: 2.1.0 + env: PUPPET_GEM_VERSION="~> 3.4.0" - rvm: 1.8.7 - env: PUPPET_VERSION="~> 4.2" - - rvm: 1.9.3 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.1.4 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.1.4 - env: PUPPET_VERSION="~> 3.0.0" - - rvm: 2.1.4 - env: PUPPET_VERSION="~> 3.1.0" + env: PUPPET_GEM_VERSION="~> 4.0.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4.1.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4.2.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4.3.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4.4.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4" -sudo: false notifications: - email: - - al@lab42.it + email: false diff --git a/Gemfile b/Gemfile index be1c34c..b5c5871 100644 --- a/Gemfile +++ b/Gemfile @@ -1,18 +1,32 @@ source 'https://rubygems.org' -puppetversion = ENV['PUPPET_VERSION'] +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end -is_ruby18 = RUBY_VERSION.start_with? '1.8' +gem 'metadata-json-lint' +gem 'puppetlabs_spec_helper', '>= 1.1.1' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' +gem 'puppet-lint', :git => 'https://github.com/rodjek/puppet-lint.git' +gem 'puppet-lint-absolute_classname-check' +gem 'puppet-lint-alias-check' +gem 'puppet-lint-file_ensure-check' +gem 'puppet-lint-file_source_rights-check' +gem 'puppet-lint-leading_zero-check' +gem 'puppet-lint-spaceship_operator_without_tag-check' +gem 'puppet-lint-trailing_comma-check' +gem 'puppet-lint-unquoted_string-check' +gem 'puppet-lint-variable_contains_upcase' -if is_ruby18 - gem 'rspec', "~> 3.1.0", :require => false - gem 'rake', '~> 10.5.0', :require => false +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9' + # rake >=11 does not support ruby 1.8.7 + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' end -gem 'puppet', puppetversion, :require => false -gem 'puppet-lint' -gem 'puppetlabs_spec_helper', '>= 0.1.0' -gem 'rspec-puppet' -gem 'metadata-json-lint' group :development do gem 'puppet-blacksmith' diff --git a/README.md b/README.md index 6c6ddad..e21859f 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,25 @@ ####Table of Contents 1. [Overview](#overview) -2. [Setup](#setup) -3. [Usage](#usage) +1. [Compatibility](#compatibility) +1. [Setup](#setup) +1. [Usage](#usage) ##Overview This module installs java (JDK + JRE) versions +##Compatibility +Puppet v3 (with and without the future parser) and Puppet v4 with Ruby versions +1.8.7, 1.9.3, 2.0.0 and 2.1.0 where supported by Puppet. + +* Debian 6 +* EL 6 +* Solaris 10 +* Solaris 11 +* Ubuntu 14.04 + ##Setup ###Setup Requirements @@ -23,10 +34,12 @@ This module installs java (JDK + JRE) versions The main class is used only. - class { 'java': - jdk => false, # default - whether to install the jdk or the jre only - version => '6', # Java version to install - } +```puppet +class { 'java': + jdk => false, # default - whether to install the jdk or the jre only + version => '6', # Java version to install +} +``` ##Development diff --git a/Rakefile b/Rakefile index 1a8a8a0..f6da6e7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,7 @@ -require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint' +require 'puppet-lint/tasks/puppet-lint' PuppetLint.configuration.send("disable_80chars") +PuppetLint.configuration.send("disable_140chars") PuppetLint.configuration.send('disable_class_parameter_defaults') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] diff --git a/manifests/init.pp b/manifests/init.pp index 2de6b57..9876a63 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -19,67 +19,73 @@ $bool_jdk=any2bool($jdk) $bool_debug=any2bool($debug) + if $package != undef { validate_string($package) } + if $package_jdk != undef { validate_string($package_jdk) } + ### Definition of some variables used in the module - $manage_package = $java::bool_absent ? { + $manage_package = $bool_absent ? { true => 'absent', false => 'present', } - $manage_file = $java::bool_absent ? { + $manage_file = $bool_absent ? { true => 'absent', default => 'present', } - $headless_suffix = $java::bool_headless ? { + validate_absolute_path($java_home_base) + validate_string($version) + + $headless_suffix = $bool_headless ? { true => '-headless', default => '', } $real_package = $package ? { - '' => $::operatingsystem ? { + '' => $::operatingsystem ? { /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jre${headless_suffix}", /(?i:SLES)/ => "java-1_${version}_0-ibm", /(?i:OpenSuSE)/ => "java-1_${version}_0-openjdk", - /(?i:Solaris)/ => $::operatingsystemmajrelease ? { - '10' => "CSWjre${version}", - '11' => "jre-${version}", - '5' => "jre-${version}", + /(?i:Solaris)/ => $::operatingsystemmajrelease ? { + '10' => "CSWjre${version}", + '11' => "jre-${version}", + '5' => "jre-${version}", }, - default => "java-1.${version}.0-openjdk", + default => "java-1.${version}.0-openjdk", }, default => $package, } $real_package_jdk = $package_jdk ? { - '' => $::operatingsystem ? { + '' => $::operatingsystem ? { /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jdk", /(?i:SLES)/ => "java-1_${version}_0-ibm", /(?i:OpenSuSE)/ => "java-1_${version}_0-openjdk-devel", - /(?i:Solaris)/ => $::operatingsystemmajrelease ? { - '10' => "CSWjdk${version}", - '11' => "jdk-${version}", - '5' => "jdk-${version}", + /(?i:Solaris)/ => $::operatingsystemmajrelease ? { + '10' => "CSWjdk${version}", + '11' => "jdk-${version}", + '5' => "jdk-${version}", }, - default => "java-1.${version}.0-openjdk-devel", + default => "java-1.${version}.0-openjdk-devel", }, default => $package_jdk, } ### Managed resources package { 'java': - ensure => $java::manage_package, - name => $java::real_package, + ensure => $manage_package, + name => $real_package, } - if $java::bool_jdk == true { + if $bool_jdk == true { package { 'java-jdk': - ensure => $java::manage_package, - name => $java::real_package_jdk, + ensure => $manage_package, + name => $real_package_jdk, } } ### Debugging, if enabled ( debug => true ) - if $java::bool_debug == true { + if $bool_debug == true { file { 'debug_java': - ensure => $java::manage_file, + ensure => $manage_file, path => "${settings::vardir}/debug-java", mode => '0640', owner => 'root', @@ -92,5 +98,4 @@ if $java::my_class { include $java::my_class } - } diff --git a/manifests/install.pp b/manifests/install.pp index f4bdf3f..d9bdcfd 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -16,7 +16,7 @@ # Installation method ('package' or 'source'). Default 'package'. # # [*install_source*] -# Source URL (when install='source'). Not default. +# Source URL (when install='source'). Default: '' # # [*package*] # Name of the package to install (when install='package'). If not default it's @@ -58,14 +58,13 @@ case $install { - package: { - + 'package': { $headless_suffix = $bool_headless ? { true => '-headless', default => '', } $real_package = $package ? { - '' => $bool_jdk ? { + '' => $bool_jdk ? { false => $::operatingsystem ? { /(?i:RedHat|Centos|Fedora|Scientific|Amazon|Linux)/ => "java-1.${version}.0-openjdk", /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jre${headless_suffix}", @@ -74,11 +73,11 @@ /(?i:Solaris)/ => $::operatingsystemmajrelease ? { '10' => "CSWjre${version}", '11' => "jre-${version}", - '5' => undef, + '5' => '', }, default => fail("OperatingSystem ${::operatingsystem} not supported"), }, - true => $::operatingsystem ? { + true => $::operatingsystem ? { /(?i:RedHat|Centos|Fedora|Scientific|Amazon|Linux)/ => "java-1.${version}.0-openjdk-devel", /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jdk", /(?i:SLES)/ => "java-1_${version}_0-ibm", @@ -86,9 +85,9 @@ /(?i:Solaris)/ => $::operatingsystemmajrelease ? { '10' => "CSWjdk${version}", '11' => "jdk-${version}", - '5' => "jdk", + '5' => 'jdk', }, - default => fail("OperatingSystem ${::operatingsystem} not supported"), + default => fail("OperatingSystem ${::operatingsystem} not supported"), } }, default => $package, @@ -105,10 +104,8 @@ responsefile => $package_responsefile, provider => $package_provider, } - } - - source: { + 'source': { if (!$install_source) { fail('Required arguement: install_source') } @@ -130,10 +127,9 @@ target => $created_dir, require => Puppi::Netinstall["netinstall_java_${name}"], } - } - - default: { } - + default: { + fail("java::install::${name}::install is <${install}> and must be 'package' or 'source'.") + } } } diff --git a/manifests/params.pp b/manifests/params.pp index 3da1fc3..e45726c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -32,16 +32,9 @@ default => '/usr/lib/jvm', } - - # Real package names are computed in java class - $package = '' - $package_jdk = '' - # General Settings - $my_class = '' $absent = false $puppi = false $puppi_helper = 'standard' $debug = false - } diff --git a/metadata.json b/metadata.json index e16e237..ba2de55 100644 --- a/metadata.json +++ b/metadata.json @@ -4,8 +4,6 @@ "summary": "Puppet module to manage Java", "license": "Apache-2.0", "author": "Alessandro Franceschi, Martin Alfke", - "checksums": { - }, "source": "https://github.com/example42/puppet-java", "project_page": "https://github.com/example42/puppet-java", "issues_url": "https://github.com/example42/puppet-java/issues", @@ -43,27 +41,12 @@ } ], "requirements": [ - { - "name": "pe", - "version_requirement": ">= 3.0.0 < 5.0.0" - }, - { - "name": "puppet", - "version_requirement": ">= 3.0.0 < 5.0.0" - } + { "name": "pe", "version_requirement": ">= 3.0.0 < 5.0.0" }, + { "name": "puppet", "version_requirement": ">= 3.0.0 < 5.0.0" } ], "dependencies": [ - { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 3.2.0 < 5.0.0" - }, - { - "name": "example42/puppi", - "version_requirement": ">= 2.0.0" - }, - { - "name": "puppetlabs/concat", - "version_requirement": ">= 1.0.0" - } + { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.6.0 < 5.0.0" }, + { "name": "example42/puppi", "version_requirement": ">= 2.0.0 < 3.0.0" }, + { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 < 2.0.0" } ] } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..b70b073 --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper' + + describe 'java' do + let(:facts) do + { :osfamily => 'Debian', + :operatingsystemmajrelease => '6', + } + end + + context 'with defaults for all parameters' do + it { should contain_class('java') } + + it { should compile.with_all_deps } + end + + + describe 'variable type and content validations' do + # set needed custom facts and variables + let(:facts) do + { + :operatingsystem => 'Ubuntu', + :operatingsystemrelease => '14.04', + } + end + let(:mandatory_params) do + { + #:param => 'value', + } + end + + validations = { + 'absolute_path' => { + :name => %w(java_home_base), + :valid => ['/absolute/filepath', '/absolute/directory/', %w(/array /with_paths)], + :invalid => ['../invalid', 3, 2.42, %w(array), { 'ha' => 'sh' }, true, false, nil], + :message => 'is not an absolute path', + }, + 'string' => { + :name => %w(package package_jdk version), + :valid => ['string'], + :invalid => [%w(array), { 'ha' => 'sh' }, 3, 2.42, true, false], + :params => { :jdk => true }, + :message => 'is not a string', + }, + 'bool_stringified' => { + :name => %w(jdk headless absent debug), + #:valid => [true, false, 'true', 'false'], + :valid => [true, false], + :invalid => ['invalid', %w(array), { 'ha' => 'sh' }, 3, 2.42, nil], + :message => '(Unknown type of boolean|str2bool\(\): Requires either string to work with)', + }, + } + + validations.sort.each do |type, var| + var[:name].each do |var_name| + var[:params] = {} if var[:params].nil? + var[:valid].each do |valid| + context "when #{var_name} (#{type}) is set to valid #{valid} (as #{valid.class})" do + let(:params) { [mandatory_params, var[:params], { :"#{var_name}" => valid, }].reduce(:merge) } + it { should compile } + end + end + + var[:invalid].each do |invalid| + context "when #{var_name} (#{type}) is set to invalid #{invalid} (as #{invalid.class})" do + let(:params) { [mandatory_params, var[:params], { :"#{var_name}" => invalid, }].reduce(:merge) } + it 'should fail' do + expect { should contain_class(subject) }.to raise_error(Puppet::Error, /#{var[:message]}/) + end + end + end + end # var[:name].each + end # validations.sort.each + end # describe 'variable type and content validations' +end