Merge branch 'master' into jce_link

This commit is contained in:
Hielke Jager
2019-04-18 19:46:07 +02:00
committed by GitHub
23 changed files with 664 additions and 442 deletions

2
.gitignore vendored
View File

@@ -22,3 +22,5 @@
/convert_report.txt
/update_report.txt
.DS_Store
.envrc
/inventory.yaml

View File

@@ -22,6 +22,8 @@
/convert_report.txt
/update_report.txt
.DS_Store
.envrc
/inventory.yaml
/appveyor.yml
/.fixtures.yml
/Gemfile
@@ -30,8 +32,10 @@
/.gitlab-ci.yml
/.pdkignore
/Rakefile
/rakelib/
/.rspec
/.rubocop.yml
/.travis.yml
/.yardopts
/spec/
/.vscode/

View File

@@ -1,4 +1,11 @@
---
.gitignore:
required:
- ---.project
.gitlab-ci.yml:
unmanaged: true
.travis.yml:
docker_sets:
- set: docker/centos-7
@@ -9,6 +16,9 @@
branches:
- release
appveyor.yml:
delete: true
Gemfile:
optional:
':development':
@@ -26,8 +36,6 @@ Gemfile:
- mingw
- x64_mingw
appveyor.yml:
delete: true
.gitlab-ci.yml:
unmanaged: true
spec/spec_helper.rb:
mock_with: ':rspec'
coverage_report: true

View File

@@ -1,5 +1,4 @@
---
dist: trusty
language: ruby
cache: bundler
before_install:
@@ -12,10 +11,14 @@ script:
- 'bundle exec rake $CHECK'
bundler_args: --without system_tests
rvm:
- 2.5.1
env:
global:
- BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0"
- 2.5.3
stages:
- static
- spec
- acceptance
-
if: tag =~ ^v\d
name: deploy
matrix:
fast_finish: true
include:
@@ -23,25 +26,34 @@ matrix:
bundler_args:
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/centos-7 BEAKER_TESTMODE=apply
rvm: 2.5.1
rvm: 2.5.3
script: bundle exec rake beaker
services: docker
stage: acceptance
sudo: required
-
bundler_args:
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/ubuntu-14.04 BEAKER_TESTMODE=apply
rvm: 2.5.1
rvm: 2.5.3
script: bundle exec rake beaker
services: docker
stage: acceptance
sudo: required
-
env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop"
-
env: CHECK=parallel_spec
env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint"
stage: static
-
env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec
rvm: 2.4.4
rvm: 2.4.5
stage: spec
-
env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
rvm: 2.5.3
stage: spec
-
env: DEPLOY_TO_FORGE=yes
stage: deploy
branches:
only:
- master

View File

@@ -70,96 +70,32 @@ java::oracle { 'jdk8' :
}
```
To install Oracle Java to a non-default basedir (defaults: /usr/lib/jvm for Debian; /usr/java for RedHat):
```puppet
java::oracle { 'jdk8' :
ensure => 'present',
version_major => '8u101',
version_minor => 'b13',
java_se => 'jdk',
basedir => '/custom/java',
}
```
To ensure that a custom basedir is a directory before Oracle Java is installed (note: manage separately for custom ownership or perms):
```puppet
java::oracle { 'jdk8' :
ensure => 'present',
version_major => '8u101',
version_minor => 'b13',
java_se => 'jdk',
manage_basedir => true,
basedir => '/custom/java',
}
```
## Reference
### Classes
#### Public classes
* `java`: Installs and manages the Java package.
#### Private classes
* `java::config`: Configures the Java alternatives.
* `java::params`: Builds a hash of jdk/jre packages for all compatible operating systems.
#### Parameters
The following parameters are available in `java`:
##### `distribution`
Specifies the Java distribution to install.
Valid options: 'jdk', 'jre', or, where the platform supports alternative packages, 'sun-jdk', 'sun-jre', 'oracle-jdk', 'oracle-jre'. Default: 'jdk'.
##### `java_alternative`
Specifies the name of the Java alternative to use. If you set this parameter, *you must also set the `java_alternative_path`.*
Valid options: Run command `update-java-alternatives -l` for a list of available choices. Default: OS and distribution dependent defaults on *deb systems, undef on others.
##### `java_alternative_path`
*Required when `java_alternative` is specified.* Defines the path to the `java` command.
Valid option: String. Default: OS and distribution dependent defaults on *deb systems, undef on others.
##### `package`
Specifies the name of the Java package. This is configurable in case you want to install a non-standard Java package. If not set, the module installs the appropriate package for the `distribution` parameter and target platform. If you set `package`, the `distribution` parameter does nothing.
Valid option: String. Default: undef.
##### `version`
Sets the version of Java to install, if you want to ensure a particular version.
Valid options: 'present', 'installed', 'latest', or a string matching `/^[.+_0-9a-zA-Z:-]+$/`. Default: 'present'.
#### Public defined types
* `java::oracle`: Installs specified version of Oracle Java SE. You may install multiple versions of Oracle Jave SE on the same node using this defined type.
#### Parameters
The following parameters are available in `java::oracle`:
##### `version`
Version of Java Standard Edition (SE) to install. 6, 7 or 8.
##### `version_major`
Major version of the Java Standard Edition (SE) to install. Must be used together with `version_minor`. For example, '8u101'.
##### `version_minor`
Minor version (or build version) of the Java Standard Edition (SE) to install. Must be used together with `version_major`. For example, 'b13'.
##### `java_se`
Type of Java SE to install, jdk or jre.
##### `ensure`
Install or remove the package.
##### `oracle_url`
Official Oracle URL to download the binaries from.
##### `proxy_server`
Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive)
##### `proxy_type`
Proxy server type (none|http|https|ftp). (passed to archive)
##### `url`
Pass an entire URL to download the installer from rather than building the complete URL from other parameters. This will allow the module to be used even if the URLs are changed by Oracle. If this parameter is used, matching `version_major` and `version_minor` parameters must also be passed to the class.
##### `url_hash`
Directory hash used by the download.oracle.com site. This value is a 32 character string which is part of the file URL returned by the JDK download site.
For information on the classes and types, see the [REFERENCE.md](https://github.com/puppetlabs/puppetlabs-java/blob/master/REFERENCE.md). For information on the facts, see below.
### Facts

257
REFERENCE.md Normal file
View File

@@ -0,0 +1,257 @@
# Reference
<!-- DO NOT EDIT: This document was generated by Puppet Strings -->
## Table of Contents
**Classes**
_Public Classes_
* [`java`](#java): This module manages the Java runtime package
_Private Classes_
* `java::config`:
* `java::params`: This class builds a hash of JDK/JRE packages and (for Debian)
alternatives. For wheezy/precise, we provide Oracle JDK/JRE
options, even though those are not in the package repositories.
**Defined types**
* [`java::oracle`](#javaoracle): Installs Oracle Java. By using this module you agree to the Oracle licensing
agreement.
## Classes
### java
This module manages the Java runtime package
#### Parameters
The following parameters are available in the `java` class.
##### `distribution`
Data type: `String`
The java distribution to install. Can be one of "jdk" or "jre",
or other platform-specific options where there are multiple
implementations available (eg: OpenJDK vs Oracle JDK).
Default value: 'jdk'
##### `version`
Data type: `Pattern[/present|installed|latest|^[.+_0-9a-zA-Z:~-]+$/]`
The version of java to install. By default, this module simply ensures
that java is present, and does not require a specific version.
Default value: 'present'
##### `package`
Data type: `Optional[String]`
The name of the java package. This is configurable in case a non-standard
java package is desired.
Default value: `undef`
##### `package_options`
Data type: `Optional[Array]`
Array of strings to pass installation options to the 'package' Puppet resource.
Options available depend on the 'package' provider for the target OS.
Default value: `undef`
##### `java_alternative`
Data type: `Optional[String]`
The name of the java alternative to use on Debian systems.
"update-java-alternatives -l" will show which choices are available.
If you specify a particular package, you will almost always also
want to specify which java_alternative to choose. If you set
this, you also need to set the path below.
Default value: `undef`
##### `java_alternative_path`
Data type: `Optional[String]`
The path to the "java" command on Debian systems. Since the
alternatives system makes it difficult to verify which
alternative is actually enabled, this is required to ensure the
correct JVM is enabled.
Default value: `undef`
##### `java_home`
Data type: `Optional[String]`
The path to where the JRE is installed. This will be set as an
environment variable.
Default value: `undef`
## Defined types
### java::oracle
Defined Type java::oracle
Install one or more versions of Oracle Java.
Uses the following to download the package and automatically accept
the licensing terms:
```
wget --no-cookies --no-check-certificate --header \
"Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz"
```
#### Parameters
The following parameters are available in the `java::oracle` defined type.
##### `ensure`
Data type: `Any`
Install or remove the package.
Default value: 'present'
##### `version`
Data type: `Any`
Version of Java to install, e.g. '7' or '8'. Default values for major and minor versions will be used.
Default value: '8'
##### `version_major`
Data type: `Any`
Major version which should be installed, e.g. '8u101'. Must be used together with version_minor.
Default value: `undef`
##### `version_minor`
Data type: `Any`
Minor version which should be installed, e.g. 'b12'. Must be used together with version_major.
Default value: `undef`
##### `java_se`
Data type: `Any`
Type of Java Standard Edition to install, jdk or jre.
Default value: 'jdk'
##### `oracle_url`
Data type: `Any`
Official Oracle URL to download binaries from.
Default value: 'http://download.oracle.com/otn-pub/java/jdk/'
##### `proxy_server`
Data type: `Any`
Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive)
Default value: `undef`
##### `proxy_type`
Data type: `Any`
Proxy server type (none|http|https|ftp). (passed to archive)
Default value: `undef`
##### `url`
Data type: `Any`
Full URL, including oracle_url, release_major, release_minor and package_name, to
download the Oracle java_se installer. Originally present but not used, activated
to workaround MODULES-5058.
Default value: `undef`
##### `url_hash`
Data type: `Any`
Directory hash used by the download.oracle.com site. This value is a 32 character string
which is part of the file URL returned by the JDK download site.
Default value: `undef`
##### `jce`
Data type: `Any`
Install Oracles Java Cryptographic Extensions into the JRE or JDK
Default value: `false`
##### `basedir`
Data type: `Any`
Directory under which the installation will occur. If not set, defaults to
/usr/lib/jvm for Debian and /usr/java for RedHat.
Default value: `undef`
##### `manage_basedir`
Data type: `Any`
Whether to manage the basedir directory. Defaults to false.
Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter.
Default value: `false`
##### `package_type`
Data type: `Any`
Type of installation package for specified version of java_se. java_se 6 comes
in a few installation package flavors and we need to account for them.
Optional forced package types: rpm, rpmbin, tar.gz
Default value: `undef`
##### `manage_symlink`
Data type: `Any`
Whether to manage a symlink that points to the installation directory. Defaults to false.
Default value: `false`
##### `symlink_name`
Data type: `Any`
The name for the optional symlink in the installation directory.
Default value: `undef`

View File

@@ -22,7 +22,7 @@ end
def changelog_future_release
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = JSON.load(File.read('metadata.json'))['version']
returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version']
raise "unable to find the future_release (version) in metadata.json" if returnVal.nil?
puts "GitHubChangelogGenerator future_release:#{returnVal}"
returnVal

View File

@@ -1,4 +1,4 @@
# On Debian systems, if alternatives are set, manually assign them.
# @api private
class java::config ( ) {
case $::osfamily {
'Debian': {

View File

@@ -1,49 +1,40 @@
# Class: java
# @summary
# This module manages the Java runtime package
#
# This module manages the Java runtime package
#
# Parameters:
#
# [*distribution*]
# @param distribution
# The java distribution to install. Can be one of "jdk" or "jre",
# or other platform-specific options where there are multiple
# implementations available (eg: OpenJDK vs Oracle JDK).
#
# [*version*]
# @param version
# The version of java to install. By default, this module simply ensures
# that java is present, and does not require a specific version.
#
# [*package*]
# @param package
# The name of the java package. This is configurable in case a non-standard
# java package is desired.
#
# [*package_options*]
# @param package_options
# Array of strings to pass installation options to the 'package' Puppet resource.
# Options available depend on the 'package' provider for the target OS.
#
# [*java_alternative*]
# @param java_alternative
# The name of the java alternative to use on Debian systems.
# "update-java-alternatives -l" will show which choices are available.
# If you specify a particular package, you will almost always also
# want to specify which java_alternative to choose. If you set
# this, you also need to set the path below.
#
# [*java_alternative_path*]
# @param java_alternative_path
# The path to the "java" command on Debian systems. Since the
# alternatives system makes it difficult to verify which
# alternative is actually enabled, this is required to ensure the
# correct JVM is enabled.
#
# [*java_home*]
# @param java_home
# The path to where the JRE is installed. This will be set as an
# environment variable.
#
# Actions:
#
# Requires:
#
# Sample Usage:
#
class java(
String $distribution = 'jdk',
Pattern[/present|installed|latest|^[.+_0-9a-zA-Z:~-]+$/] $version = 'present',

View File

@@ -1,114 +1,95 @@
# Defined Type java::oracle
#
# Description
# Installs Oracle Java. By using this module you agree to the Oracle licensing
# agreement.
# @summary
# Installs Oracle Java. By using this module you agree to the Oracle licensing
# agreement.
#
# Install one or more versions of Oracle Java.
#
# uses the following to download the package and automatically accept
# the licensing terms.
# Uses the following to download the package and automatically accept
# the licensing terms:
#```
# wget --no-cookies --no-check-certificate --header \
# "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
# "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz"
#```
#
# Parameters
# [*version*]
# Version of Java to install, e.g. '7' or '8'. Default values for major and minor
# versions will be used.
# @param ensure
# Install or remove the package.
#
# [*version_major*]
# Major version which should be installed, e.g. '8u101'. Must be used together with
# version_minor.
# @param version
# Version of Java to install, e.g. '7' or '8'. Default values for major and minor versions will be used.
#
# [*version_minor*]
# Minor version which should be installed, e.g. 'b12'. Must be used together with
# version_major.
# @param version_major
# Major version which should be installed, e.g. '8u101'. Must be used together with version_minor.
#
# [*java_se*]
# Type of Java Standard Edition to install, jdk or jre.
# @param version_minor
# Minor version which should be installed, e.g. 'b12'. Must be used together with version_major.
#
# [*ensure*]
# Install or remove the package.
# @param java_se
# Type of Java Standard Edition to install, jdk or jre.
#
# [*oracle_url*]
# Official Oracle URL to download binaries from.
# @param oracle_url
# Official Oracle URL to download binaries from.
#
# [*proxy_server*]
# Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive)
# @param proxy_server
# Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive)
#
# [*proxy_type*]
# Proxy server type (none|http|https|ftp). (passed to archive)
# @param proxy_type
# Proxy server type (none|http|https|ftp). (passed to archive)
#
# Variables
# [*release_major*]
# Major version release number for java_se. Used to construct download URL.
# @param url
# Full URL, including oracle_url, release_major, release_minor and package_name, to
# download the Oracle java_se installer. Originally present but not used, activated
# to workaround MODULES-5058.
#
# [*release_minor*]
# Minor version release number for java_se. Used to construct download URL.
# @param url_hash
# Directory hash used by the download.oracle.com site. This value is a 32 character string
# which is part of the file URL returned by the JDK download site.
#
# [*install_path*]
# Base install path for specified version of java_se. Used to determine if java_se
# has already been installed.
# @param jce
# Install Oracles Java Cryptographic Extensions into the JRE or JDK
#
# [*package_type*]
# Type of installation package for specified version of java_se. java_se 6 comes
# in a few installation package flavors and we need to account for them.
# @param jce_url
# Full URL to the jce zip file
#
# [*os*]
# Oracle java_se OS type.
# @param basedir
# Directory under which the installation will occur. If not set, defaults to
# /usr/lib/jvm for Debian and /usr/java for RedHat.
#
# [*destination*]
# Destination directory to save java_se installer to. Usually /tmp on Linux and
# C:\TEMP on Windows.
# @param manage_basedir
# Whether to manage the basedir directory. Defaults to false.
# Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter.
#
# [*creates_path*]
# Fully qualified path to java_se after it is installed. Used to determine if
# java_se is already installed.
# @param package_type
# Type of installation package for specified version of java_se. java_se 6 comes
# in a few installation package flavors and we need to account for them.
# Optional forced package types: rpm, rpmbin, tar.gz
#
# [*arch*]
# Oracle java_se architecture type.
# @param manage_symlink
# Whether to manage a symlink that points to the installation directory. Defaults to false.
#
# [*package_name*]
# Name of the java_se installation package to download from Oracle's website.
#
# [*install_command*]
# Installation command used to install Oracle java_se. Installation commands
# differ by package_type. 'bin' types are installed via shell command. 'rpmbin'
# types have the rpms extracted and then forcibly installed. 'rpm' types are
# forcibly installed.
#
# [*url*]
# Full URL, including oracle_url, release_major, release_minor and package_name, to
# download the Oracle java_se installer. Originally present but not used, activated
# to workaround MODULES-5058
#
# [*url_hash*]
# Directory hash used by the download.oracle.com site. This value is a 32 character string
# which is part of the file URL returned by the JDK download site.
#
# [*jce*]
# Install Oracles Java Cryptographic Extensions into the JRE or JDK
#
# [*jce_url*]
# Full URL to the jce zip file
#
# ### Author
# mike@marseglia.org
# @param symlink_name
# The name for the optional symlink in the installation directory.
#
define java::oracle (
$ensure = 'present',
$version = '8',
$version_major = undef,
$version_minor = undef,
$java_se = 'jdk',
$oracle_url = 'http://download.oracle.com/otn-pub/java/jdk/',
$proxy_server = undef,
$proxy_type = undef,
$url = undef,
$url_hash = undef,
$jce = false,
$jce_url = undef,
$ensure = 'present',
$version = '8',
$version_major = undef,
$version_minor = undef,
$java_se = 'jdk',
$oracle_url = 'http://download.oracle.com/otn-pub/java/jdk/',
$proxy_server = undef,
$proxy_type = undef,
$url = undef,
$url_hash = undef,
$jce = false,
$jce_url = undef,
$basedir = undef,
$manage_basedir = false,
$package_type = undef,
$manage_symlink = false,
$symlink_name = undef,
) {
# archive module is used to download the java package
@@ -137,14 +118,16 @@ define java::oracle (
# determine Oracle Java major and minor version, and installation path
if $version_major and $version_minor {
$label = $version_major
$release_major = $version_major
$release_minor = $version_minor
$release_hash = $url_hash
if $release_major =~ /(\d+)u(\d+)/ {
# Required for CentOS systems where Java8 update number is >= 171 to ensure
# the package is visible to Puppet
if $facts['os']['family'] == 'RedHat' and $2 >= '171' {
# the package is visible to Puppet. This is only true for installations that
# don't use the tar.gz package type.
if $facts['os']['family'] == 'RedHat' and $2 >= '171' and $package_type != 'tar.gz' {
$install_path = "${java_se}1.${1}.0_${2}-amd64"
} else {
$install_path = "${java_se}1.${1}.0_${2}"
@@ -154,6 +137,7 @@ define java::oracle (
}
} else {
# use default versions if no specific major and minor version parameters are provided
$label = $version
case $version {
'6' : {
$release_major = '6u45'
@@ -168,16 +152,16 @@ define java::oracle (
$release_hash = undef
}
'8' : {
$release_major = '8u192'
$release_minor = 'b12'
$install_path = "${java_se}1.8.0_192"
$release_hash = '750e1c8617c5452694857ad95c3ee230'
$release_major = '8u201'
$release_minor = 'b09'
$install_path = "${java_se}1.8.0_201"
$release_hash = '42970487e3af4f5aa5bca3f542482c60'
}
default : {
$release_major = '8u192'
$release_minor = 'b12'
$install_path = "${java_se}1.8.0_192"
$release_hash = '750e1c8617c5452694857ad95c3ee230'
$release_major = '8u201'
$release_minor = 'b09'
$install_path = "${java_se}1.8.0_201"
$release_hash = '42970487e3af4f5aa5bca3f542482c60'
}
}
}
@@ -188,21 +172,36 @@ define java::oracle (
case $facts['os']['family'] {
'RedHat', 'Amazon' : {
# Oracle Java 6 comes in a special rpmbin format
if $version == '6' {
$package_type = 'rpmbin'
if $package_type {
$_package_type = $package_type
} elsif $version == '6' {
$_package_type = 'rpmbin'
} else {
$package_type = 'rpm'
$_package_type = 'rpm'
}
if $basedir {
$_basedir = $basedir
} else {
$_basedir = '/usr/java'
}
$creates_path = "/usr/java/${install_path}"
}
'Debian' : {
$package_type = 'tar.gz'
$creates_path = "/usr/lib/jvm/${install_path}"
if $package_type {
$_package_type = $package_type
} else {
$_package_type = 'tar.gz'
}
if $basedir {
$_basedir = $basedir
} else {
$_basedir = '/usr/lib/jvm'
}
}
default : {
fail ("unsupported platform ${$facts['os']['name']}") }
}
$creates_path = "${_basedir}/${install_path}"
$os = 'linux'
$destination_dir = '/tmp/'
}
@@ -237,7 +236,7 @@ define java::oracle (
# http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586-rpm.bin
# http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin
# package name to download from Oracle's website
case $package_type {
case $_package_type {
'bin' : {
$package_name = "${java_se}-${release_major}-${os}-${arch}.bin"
}
@@ -270,7 +269,7 @@ define java::oracle (
$destination = "${destination_dir}${package_name}"
notice ("Destination is ${destination}")
case $package_type {
case $_package_type {
'bin' : {
$install_command = "sh ${destination}"
}
@@ -281,7 +280,7 @@ define java::oracle (
$install_command = "rpm --force -iv ${destination}"
}
'tar.gz' : {
$install_command = "tar -zxf ${destination} -C /usr/lib/jvm"
$install_command = "tar -zxf ${destination} -C ${_basedir}"
}
default : {
$install_command = "rpm -iv ${destination}"
@@ -304,15 +303,20 @@ define java::oracle (
'Linux' : {
case $facts['os']['family'] {
'Debian' : {
ensure_resource('file', '/usr/lib/jvm', {
ensure_resource('file', $_basedir, {
ensure => directory,
})
$install_requires = [Archive[$destination], File['/usr/lib/jvm']]
$install_requires = [Archive[$destination], File[$_basedir]]
}
default : {
$install_requires = [Archive[$destination]]
}
}
if $manage_basedir {
ensure_resource('file', $_basedir, {'ensure' => 'directory', 'before' => Exec["Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}"]})
}
exec { "Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}" :
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
command => $install_command,
@@ -320,6 +324,14 @@ define java::oracle (
require => $install_requires
}
if ($manage_symlink and $symlink_name) {
file { "${_basedir}/${symlink_name}":
ensure => link,
target => $creates_path,
require => Exec["Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}"]
}
}
if ($jce and $jce_download != undef) {
$jce_path = $java_se ? {
'jre' => "${creates_path}/lib/security",
@@ -351,5 +363,4 @@ define java::oracle (
notice ("Action ${ensure} not supported.")
}
}
}

View File

@@ -1,15 +1,9 @@
# Class: java::params
# @summary
# This class builds a hash of JDK/JRE packages and (for Debian)
# alternatives. For wheezy/precise, we provide Oracle JDK/JRE
# options, even though those are not in the package repositories.
#
# This class builds a hash of JDK/JRE packages and (for Debian)
# alternatives. For wheezy/precise, we provide Oracle JDK/JRE
# options, even though those are not in the package repositories.
#
# For more info on how to package Oracle JDK/JRE, see the Debian wiki:
# http://wiki.debian.org/JavaPackage
#
# Because the alternatives system makes it very difficult to tell
# which Java alternative is enabled, we hard code the path to bin/java
# for the config class to test if it is enabled.
# @api private
class java::params {
case $::osfamily {

View File

@@ -74,10 +74,10 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 4.7.0 < 7.0.0"
"version_requirement": ">= 5.5.10 < 7.0.0"
}
],
"template-url": "https://github.com/puppetlabs/pdk-templates/",
"template-ref": "1.9.0-0-g7281db5",
"pdk-version": "1.9.0"
"template-url": "https://github.com/puppetlabs/pdk-templates#master",
"template-ref": "heads/master-0-gf778803",
"pdk-version": "1.10.0"
}

View File

@@ -2,32 +2,6 @@ require 'spec_helper_acceptance'
include Unix::File
# RedHat, CentOS, Scientific, Oracle prior to 5.0 : Sun Java JDK/JRE 1.6
# RedHat, CentOS, Scientific, Oracle 5.0 < x < 6.3 : OpenJDK Java JDK/JRE 1.6
# RedHat, CentOS, Scientific, Oracle after 6.3 : OpenJDK Java JDK/JRE 1.7
# Debian Jesse & Ubuntu 14.04 : OpenJDK Java JDK/JRE 1.7 or Oracle Java JDK/JRE 1.6
# Solaris (what versions?) : Java JDK/JRE 1.7
# OpenSuSE : OpenJDK Java JDK/JRE 1.7
# SLES : IBM Java JDK/JRE 1.6
# C14677
# C14678
# C14679
# C14680
# C14681
# C14682
# C14684
# C14687
# C14692
# C14696
# C14697
# C14700 check on solaris 11
# C14701 check on sles 11
# C14703
# C14723 Where is oracle linux 5?
# C14724 Where is oracle linux 5?
# C14771 Where is redhat 7? Centos 7?
java_class_jre = "class { 'java':\n"\
" distribution => 'jre',\n"\
'}'
@@ -56,10 +30,6 @@ oracle_jdk = "class { 'java':\n"\
" distribution => 'oracle-jdk',\n"\
'}'
incorrect_version = "class { 'java':\n"\
" version => '14.5',\n"\
'}'
blank_version = "class { 'java':\n"\
" version => '',\n"\
'}'
@@ -87,11 +57,11 @@ bogus_alternative = "class { 'java':\n"\
oracle_enabled = false
oracle_version_major = '8'
oracle_version_minor = '192'
oracle_version_build = '12'
oracle_hash = '750e1c8617c5452694857ad95c3ee230'
oracle_version_minor = '201'
oracle_version_build = '09'
oracle_hash = '42970487e3af4f5aa5bca3f542482c60'
install_oracle_jre = <<EOL
install_oracle_jdk_jre = <<EOL
java::oracle {
'test_oracle_jre':
version => '#{oracle_version_major}',
@@ -100,9 +70,6 @@ install_oracle_jre = <<EOL
url_hash => '#{oracle_hash}',
java_se => 'jre',
}
EOL
install_oracle_jdk = <<EOL
java::oracle {
'test_oracle_jdk':
version => '#{oracle_version_major}',
@@ -123,6 +90,7 @@ install_oracle_jre_jce = <<EOL
java_se => 'jre',
jce => true,
}
EOL
install_oracle_jdk_jce = <<EOL
@@ -139,21 +107,16 @@ EOL
context 'installing java jre', unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'installs jre' do
apply_manifest(java_class_jre, catch_failures: true)
apply_manifest(java_class_jre, catch_changes: true)
idempotent_apply(default, java_class_jre)
end
end
context 'installing java jdk', unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'installs jdk' do
apply_manifest(java_class, catch_failures: true)
apply_manifest(java_class, catch_changes: true)
idempotent_apply(default, java_class)
end
end
# C14704
# C14705
# C15006
context 'oracle', if: (
(fact('operatingsystem') == 'Ubuntu') && fact('operatingsystemrelease').match(%r{^14\.04})
) do
@@ -174,37 +137,22 @@ context 'oracle', if: (
end
context 'with failure cases' do
# C14711
# SLES 10 returns an exit code of 0 on zypper failure
unless fact('operatingsystem') == 'SLES' && fact('operatingsystemrelease') < '11'
it 'fails to install java with an incorrect version' do
apply_manifest(incorrect_version, expect_failures: true)
end
end
# C14712
it 'fails to install java with a blank version' do
apply_manifest(blank_version, expect_failures: true)
end
# C14713
it 'fails to install java with an incorrect distribution' do
apply_manifest(incorrect_distro, expect_failures: true)
end
# C14714
it 'fails to install java with a blank distribution' do
apply_manifest(blank_distro, expect_failures: true)
end
# C14715
it 'fails to install java with an incorrect package' do
apply_manifest(incorrect_package, expect_failures: true)
end
# C14717
# C14719
# C14725
it 'fails on debian or RHEL when passed fake java_alternative and path' do
if fact('osfamily') == 'Debian' || fact('osfamily') == 'RedHat'
apply_manifest(bogus_alternative, expect_failures: true)
@@ -214,35 +162,31 @@ context 'with failure cases' do
end
end
# Test oracle java installs
context 'java::oracle', if: oracle_enabled, unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
install_path = '/usr/lib/jvm'
version_suffix = ''
if fact('osfamily') == 'RedHat' || fact('osfamily') == 'Amazon'
install_path = '/usr/java'
version_suffix = '-amd64'
let(:install_path) do
(fact('osfamily') == 'RedHat') ? '/usr/java' : '/usr/lib/jvm'
end
it 'installs oracle jdk' do
apply_manifest(install_oracle_jdk, catch_failures: true)
apply_manifest(install_oracle_jdk, catch_changes: true)
result = shell("test ! -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar")
expect(result.exit_code).to eq(0)
let(:version_suffix) do
(fact('osfamily') == 'RedHat') ? '-amd64' : ''
end
it 'installs oracle jre' do
apply_manifest(install_oracle_jre, catch_failures: true)
apply_manifest(install_oracle_jre, catch_changes: true)
result = shell("test ! -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar")
expect(result.exit_code).to eq(0)
it 'installs oracle jdk and jre' do
idempotent_apply(default, install_oracle_jdk_jre)
jdk_result = shell("test ! -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar")
jre_result = shell("test ! -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar")
expect(jdk_result.exit_code).to eq(0)
expect(jre_result.exit_code).to eq(0)
end
it 'installs oracle jdk with jce' do
apply_manifest(install_oracle_jdk_jce, catch_failures: true)
apply_manifest(install_oracle_jdk_jce, catch_changes: true)
idempotent_apply(default, install_oracle_jdk_jce)
result = shell("test -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar")
expect(result.exit_code).to eq(0)
end
it 'installs oracle jre with jce' do
apply_manifest(install_oracle_jre_jce, catch_failures: true)
apply_manifest(install_oracle_jre_jce, catch_changes: true)
idempotent_apply(default, install_oracle_jre_jce)
result = shell("test -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar")
expect(result.exit_code).to eq(0)
end

View File

@@ -53,20 +53,20 @@ describe 'java', type: :class do
it { is_expected.not_to contain_exec('update-java-alternatives') }
end
context 'when select jdk for Ubuntu Vivid (15.04)' do
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistcodename: 'vivid', operatingsystemrelease: '15.04', architecture: 'amd64' } }
context 'when select jdk for Ubuntu Trusty (14.04)' do
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistcodename: 'trusty', operatingsystemrelease: '14.04', architecture: 'amd64' } }
let(:params) { { 'distribution' => 'jdk' } }
it { is_expected.to contain_package('java').with_name('openjdk-8-jdk') }
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/') }
it { is_expected.to contain_package('java').with_name('openjdk-7-jdk') }
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64/') }
end
context 'when select jre for Ubuntu Vivid (15.04)' do
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistcodename: 'vivid', operatingsystemrelease: '15.04', architecture: 'amd64' } }
context 'when select jre for Ubuntu Trusty (14.04)' do
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistcodename: 'trusty', operatingsystemrelease: '14.04', architecture: 'amd64' } }
let(:params) { { 'distribution' => 'jre' } }
it { is_expected.to contain_package('java').with_name('openjdk-8-jre-headless') }
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/') }
it { is_expected.to contain_package('java').with_name('openjdk-7-jre-headless') }
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64/') }
end
context 'when select jdk for Ubuntu xenial (16.04) on ARM' do
@@ -85,20 +85,6 @@ describe 'java', type: :class do
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-arm64/') }
end
context 'when select openjdk for Amazon Linux' do
let(:facts) { { osfamily: 'RedHat', operatingsystem: 'Amazon', operatingsystemrelease: '3.4.43-43.43.amzn1.x86_64', architecture: 'x86_64' } }
it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk-devel') }
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-x86_64/') }
end
context 'when select passed value for Amazon Linux' do
let(:facts) { { osfamily: 'RedHat', operatingsystem: 'Amazon', operatingsystemrelease: '5.3.4.43-43.43.amzn1.x86_64', architecture: 'x86_64' } }
let(:params) { { 'distribution' => 'jre' } }
it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') }
end
context 'when select openjdk for Oracle Linux' do
let(:facts) { { osfamily: 'RedHat', operatingsystem: 'OracleLinux', operatingsystemrelease: '6.4', architecture: 'x86_64' } }
@@ -169,20 +155,6 @@ describe 'java', type: :class do
it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/') }
end
context 'when select jdk for OpenBSD' do
let(:facts) { { osfamily: 'OpenBSD', architecture: 'x86_64' } }
it { is_expected.to contain_package('java').with_name('jdk') }
it { is_expected.not_to contain_file_line('java-home-environment') }
end
context 'when select jre for OpenBSD' do
let(:facts) { { osfamily: 'OpenBSD', architecture: 'x86_64' } }
let(:params) { { 'distribution' => 'jre' } }
it { is_expected.to contain_package('java').with_name('jre') }
end
describe 'custom java package' do
let(:facts) { { osfamily: 'Debian', operatingsystem: 'Debian', lsbdistcodename: 'jessie', operatingsystemrelease: '8.6', architecture: 'amd64' } }
@@ -218,31 +190,26 @@ describe 'java', type: :class do
describe 'incompatible OSs' do
[
{
# C14706
osfamily: 'windows',
operatingsystem: 'windows',
operatingsystemrelease: '8.1',
},
{
# C14707
osfamily: 'Darwin',
operatingsystem: 'Darwin',
operatingsystemrelease: '13.3.0',
},
{
# C14708
osfamily: 'AIX',
operatingsystem: 'AIX',
operatingsystemrelease: '7100-02-00-000',
},
{
# C14708
osfamily: 'AIX',
operatingsystem: 'AIX',
operatingsystemrelease: '6100-07-04-1216',
},
{
# C14708
osfamily: 'AIX',
operatingsystem: 'AIX',
operatingsystemrelease: '5300-12-01-1016',

View File

@@ -1,6 +1,6 @@
require 'spec_helper'
oracle_url = 'http://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-linux-x64.tar.gz'
oracle_url = 'http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz'
describe 'java::oracle', type: :define do
context 'with CentOS 64-bit' do
@@ -28,9 +28,9 @@ describe 'java::oracle', type: :define do
let(:params) { { ensure: 'present', version: '8', java_se: 'jdk' } }
let(:title) { 'jdk8' }
it { is_expected.to contain_archive('/tmp/jdk-8u192-linux-x64.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u192 b12').with_command('rpm --force -iv /tmp/jdk-8u192-linux-x64.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u192 b12').that_requires('Archive[/tmp/jdk-8u192-linux-x64.rpm]') }
it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u201 b09').with_command('rpm --force -iv /tmp/jdk-8u201-linux-x64.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u201 b09').that_requires('Archive[/tmp/jdk-8u201-linux-x64.rpm]') }
end
context 'when Oracle Java SE 6 JRE' do
@@ -55,27 +55,27 @@ describe 'java::oracle', type: :define do
let(:params) { { ensure: 'present', version: '8', java_se: 'jre' } }
let(:title) { 'jre8' }
it { is_expected.to contain_archive('/tmp/jre-8u192-linux-x64.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u192 b12').with_command('rpm --force -iv /tmp/jre-8u192-linux-x64.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u192 b12').that_requires('Archive[/tmp/jre-8u192-linux-x64.rpm]') }
it { is_expected.to contain_archive('/tmp/jre-8u201-linux-x64.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u201 b09').with_command('rpm --force -iv /tmp/jre-8u201-linux-x64.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u201 b09').that_requires('Archive[/tmp/jre-8u201-linux-x64.rpm]') }
end
context 'when passing URL to url parameter' do
let(:params) do
{
ensure: 'present',
version_major: '8u192',
version_minor: 'b12',
version_major: '8u201',
version_minor: 'b09',
java_se: 'jdk',
url: 'http://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-linux-x64.rpm',
url: 'http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm',
url_hash: 'ignored',
}
end
let(:title) { 'jdk8' }
it {
is_expected.to contain_archive('/tmp/jdk-8u192-linux-x64.rpm')
.with_source('http://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-linux-x64.rpm')
is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.rpm')
.with_source('http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm')
}
end
@@ -83,17 +83,17 @@ describe 'java::oracle', type: :define do
let(:params) do
{
ensure: 'present',
version_major: '8u192',
version_minor: 'b12',
version_major: '8u201',
version_minor: 'b09',
java_se: 'jdk',
url_hash: '750e1c8617c5452694857ad95c3ee230',
url_hash: '42970487e3af4f5aa5bca3f542482c60',
}
end
let(:title) { 'jdk8' }
it {
is_expected.to contain_archive('/tmp/jdk-8u192-linux-x64.rpm')
.with_source('http://download.oracle.com/otn-pub/java/jdk//8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-linux-x64.rpm')
is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.rpm')
.with_source('http://download.oracle.com/otn-pub/java/jdk//8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm')
}
end
@@ -101,10 +101,10 @@ describe 'java::oracle', type: :define do
let(:params) do
{
ensure: 'present',
version_major: '8u192',
version_minor: 'b12',
version_major: '8u201',
version_minor: 'b09',
java_se: 'jdk',
url_hash: '750e1c8617c5452694857ad95c3ee230',
url_hash: '42970487e3af4f5aa5bca3f542482c60',
}
end
let(:title) { 'jdk8' }
@@ -144,6 +144,52 @@ describe 'java::oracle', type: :define do
is_expected.to contain_archive('/tmp/jce-6.zip').with_extract_path('/usr/java/jdk1.6.0_99-amd64/jre/lib/security')
end
end
context 'when specifying package_type tar.gz and basedir' do
let(:params) do
{
ensure: 'present',
version: '6',
java_se: 'jdk',
basedir: '/usr/java',
package_type: 'tar.gz',
}
end
let(:title) { 'jdk6' }
it { is_expected.to contain_archive('/tmp/jdk-6u45-linux-x64.tar.gz') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 6 6u45 b06').with_command('tar -zxf /tmp/jdk-6u45-linux-x64.tar.gz -C /usr/java') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 6 6u45 b06').that_requires('Archive[/tmp/jdk-6u45-linux-x64.tar.gz]') }
end
context 'when manage_basedir is set to true' do
let(:params) do
{
ensure: 'present',
version: '6',
java_se: 'jdk',
basedir: '/usr/java',
manage_basedir: true,
}
end
let(:title) { 'jdk6' }
it { is_expected.to contain_file('/usr/java') }
end
context 'when manage_symlink is set to true' do
let(:params) do
{
ensure: 'present',
version: '6',
java_se: 'jdk',
basedir: '/usr/java',
manage_symlink: true,
symlink_name: 'java_home',
}
end
let(:title) { 'jdk6' }
it { is_expected.to contain_file('/usr/java/java_home') }
end
end
context 'when on CentOS 32-bit' do
@@ -171,9 +217,9 @@ describe 'java::oracle', type: :define do
let(:params) { { ensure: 'present', version: '8', java_se: 'jdk' } }
let(:title) { 'jdk8' }
it { is_expected.to contain_archive('/tmp/jdk-8u192-linux-i586.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u192 b12').with_command('rpm --force -iv /tmp/jdk-8u192-linux-i586.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u192 b12').that_requires('Archive[/tmp/jdk-8u192-linux-i586.rpm]') }
it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-i586.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u201 b09').with_command('rpm --force -iv /tmp/jdk-8u201-linux-i586.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u201 b09').that_requires('Archive[/tmp/jdk-8u201-linux-i586.rpm]') }
end
context 'when selecting Oracle Java SE 6 JRE on RedHat family, 32-bit' do
@@ -198,19 +244,19 @@ describe 'java::oracle', type: :define do
let(:params) { { ensure: 'present', version: '8', java_se: 'jre' } }
let(:title) { 'jdk8' }
it { is_expected.to contain_archive('/tmp/jre-8u192-linux-i586.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u192 b12').with_command('rpm --force -iv /tmp/jre-8u192-linux-i586.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u192 b12').that_requires('Archive[/tmp/jre-8u192-linux-i586.rpm]') }
it { is_expected.to contain_archive('/tmp/jre-8u201-linux-i586.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u201 b09').with_command('rpm --force -iv /tmp/jre-8u201-linux-i586.rpm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u201 b09').that_requires('Archive[/tmp/jre-8u201-linux-i586.rpm]') }
end
context 'when installing multiple versions' do
let(:params) do
{
ensure: 'present',
version_major: '8u192',
version_minor: 'b12',
version_major: '8u201',
version_minor: 'b09',
java_se: 'jdk',
url_hash: '750e1c8617c5452694857ad95c3ee230',
url_hash: '42970487e3af4f5aa5bca3f542482c60',
}
end
let(:title) { 'jdk8' }
@@ -277,9 +323,9 @@ describe 'java::oracle', type: :define do
let(:params) { { ensure: 'present', version: '8', java_se: 'jdk' } }
let(:title) { 'jdk8' }
it { is_expected.to contain_archive('/tmp/jdk-8u192-linux-x64.tar.gz') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u192 b12').with_command('tar -zxf /tmp/jdk-8u192-linux-x64.tar.gz -C /usr/lib/jvm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u192 b12').that_requires('Archive[/tmp/jdk-8u192-linux-x64.tar.gz]') }
it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.tar.gz') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u201 b09').with_command('tar -zxf /tmp/jdk-8u201-linux-x64.tar.gz -C /usr/lib/jvm') }
it { is_expected.to contain_exec('Install Oracle java_se jdk 8 8u201 b09').that_requires('Archive[/tmp/jdk-8u201-linux-x64.tar.gz]') }
end
context 'with Oracle Java SE 6 JRE' do
@@ -304,26 +350,26 @@ describe 'java::oracle', type: :define do
let(:params) { { ensure: 'present', version: '8', java_se: 'jre' } }
let(:title) { 'jre8' }
it { is_expected.to contain_archive('/tmp/jre-8u192-linux-x64.tar.gz') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u192 b12').with_command('tar -zxf /tmp/jre-8u192-linux-x64.tar.gz -C /usr/lib/jvm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u192 b12').that_requires('Archive[/tmp/jre-8u192-linux-x64.tar.gz]') }
it { is_expected.to contain_archive('/tmp/jre-8u201-linux-x64.tar.gz') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u201 b09').with_command('tar -zxf /tmp/jre-8u201-linux-x64.tar.gz -C /usr/lib/jvm') }
it { is_expected.to contain_exec('Install Oracle java_se jre 8 8u201 b09').that_requires('Archive[/tmp/jre-8u201-linux-x64.tar.gz]') }
end
context 'when passing URL to url parameter' do
let(:params) { { ensure: 'present', version_major: '8u192', version_minor: 'b12', java_se: 'jdk', url: oracle_url.to_s } }
let(:params) { { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: oracle_url.to_s } }
let(:title) { 'jdk8' }
it { is_expected.to contain_archive('/tmp/jdk-8u192-linux-x64.tar.gz') }
it { is_expected.to contain_archive('/tmp/jdk-8u201-linux-x64.tar.gz') }
end
context 'when installing multiple versions' do
let(:params) do
{
ensure: 'present',
version_major: '8u192',
version_minor: 'b12',
version_major: '8u201',
version_minor: 'b09',
java_se: 'jdk',
url_hash: '750e1c8617c5452694857ad95c3ee230',
url_hash: '42970487e3af4f5aa5bca3f542482c60',
}
end
let(:title) { 'jdk8' }
@@ -367,7 +413,6 @@ describe 'java::oracle', type: :define do
describe 'incompatible OSes' do
[
{
# C14706
kernel: 'Windows',
os: {
family: 'Windows',
@@ -378,7 +423,6 @@ describe 'java::oracle', type: :define do
},
},
{
# C14707
kernel: 'Darwin',
os: {
family: 'Darwin',
@@ -389,7 +433,6 @@ describe 'java::oracle', type: :define do
},
},
{
# C14708
kernel: 'AIX',
os: {
family: 'AIX',
@@ -400,7 +443,6 @@ describe 'java::oracle', type: :define do
},
},
{
# C14709
kernel: 'AIX',
os: {
family: 'AIX',
@@ -411,7 +453,6 @@ describe 'java::oracle', type: :define do
},
},
{
# C14710
kernel: 'AIX',
os: {
family: 'AIX',

View File

@@ -1,3 +1,7 @@
RSpec.configure do |c|
c.mock_with :rspec
end
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
@@ -19,7 +23,7 @@ default_fact_files.each do |f|
next unless File.exist?(f) && File.readable?(f) && File.size?(f)
begin
default_facts.merge!(YAML.safe_load(File.read(f)))
default_facts.merge!(YAML.safe_load(File.read(f), [], [], true))
rescue => e
RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}"
end
@@ -34,6 +38,7 @@ RSpec.configure do |c|
end
c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT']
c.after(:suite) do
RSpec::Puppet::Coverage.report!(0)
end
end

View File

@@ -21,3 +21,17 @@ RSpec.configure do |c|
# Readable test descriptions
c.formatter = :documentation
end
def idempotent_apply(hosts, manifest, opts = {}, &block)
block_on hosts, opts do |host|
file_path = host.tmpfile('apply_manifest.pp')
create_remote_file(host, file_path, manifest + "\n")
puppet_apply_opts = { :verbose => nil, 'detailed-exitcodes' => nil }
on_options = { acceptable_exit_codes: [0, 2] }
on host, puppet('apply', file_path, puppet_apply_opts), on_options, &block
puppet_apply_opts2 = { :verbose => nil, 'detailed-exitcodes' => nil }
on_options2 = { acceptable_exit_codes: [0] }
on host, puppet('apply', file_path, puppet_apply_opts2), on_options2, &block
end
end

28
spec/spec_helper_local.rb Normal file
View File

@@ -0,0 +1,28 @@
if ENV['COVERAGE'] == 'yes'
require 'simplecov'
require 'simplecov-console'
require 'codecov'
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console,
SimpleCov::Formatter::Codecov,
]
SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter '/spec'
# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
# do not track gitignored files
# this adds about 4 seconds to the coverage check
# this could definitely be optimized
add_filter do |f|
# system returns true if exit status is 0, which with git-check-ignore means file is ignored
system("git check-ignore --quiet #{f.filename}")
end
end
end

View File

@@ -15,15 +15,15 @@ end
def symlink_and_test(symlink_path, java_home)
File.symlink(symlink_path, './java_test')
Facter::Util::Resolution.expects(:which).with('java').returns('./java_test')
File.expects(:realpath).with('./java_test').returns(symlink_path)
expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('./java_test')
expect(File).to receive(:realpath).with('./java_test').and_return(symlink_path)
expect(Facter.value(:java_default_home)).to eql java_home
end
describe 'java_default_home' do
before(:each) do
Facter.clear
Facter.fact(:kernel).stubs(:value).returns('Linux')
allow(Facter.fact(:kernel)).to receive(:value).once.and_return('Linux')
end
context 'when java found in PATH' do
@@ -46,8 +46,8 @@ describe 'java_default_home' do
context 'when java not present, return nil' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with('java').at_least(1).returns(false)
allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
expect(Facter::Util::Resolution).to receive(:which).with('java').at_least(1).and_return(nil)
expect(Facter.value(:java_default_home)).to be_nil
end
end

View File

@@ -1,17 +1,25 @@
require 'spec_helper'
describe 'java_libjvm_path' do
let(:java_default_home) { '/usr/lib/jvm/java-8-openjdk-amd64' }
before(:each) do
Facter.clear
Facter.fact(:kernel).stubs(:value).returns('Linux')
java_default_home = '/usr/lib/jvm/java-8-openjdk-amd64'
Facter.fact(:java_default_home).stubs(:value).returns(java_default_home)
Dir.stubs(:glob).with("#{java_default_home}/jre/lib/**/libjvm.so").returns(['/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so'])
allow(Facter.fact(:kernel)).to receive(:value).once.and_return('Linux')
allow(Facter.fact(:java_default_home)).to receive(:value).once.and_return(java_default_home)
end
context 'when on Linux, return libjvm path' do
context 'when libjvm exists' do
it do
allow(Dir).to receive(:glob).with("#{java_default_home}/jre/lib/**/libjvm.so").and_return(['/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so'])
expect(Facter.value(:java_libjvm_path)).to eql '/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server'
end
end
context 'when libjvm does not exist' do
it do
allow(Dir).to receive(:glob).with("#{java_default_home}/jre/lib/**/libjvm.so").and_return([])
expect(Facter.value(:java_libjvm_path)).to be nil
end
end
end

View File

@@ -7,7 +7,7 @@ describe 'java_major_version' do
context 'when java_version fact present, returns major version' do
before :each do
Facter.fact(:java_version).stubs(:value).returns('1.7.0_71')
allow(Facter.fact(:java_version)).to receive(:value).and_return('1.7.0_71')
end
it do
expect(Facter.fact(:java_major_version).value).to eq('7')
@@ -16,7 +16,7 @@ describe 'java_major_version' do
context 'when java not present, returns nil' do
before :each do
Facter.fact(:java_version).stubs(:value).returns(nil)
allow(Facter.fact(:java_version)).to receive(:value).and_return('nil')
end
it do
expect(Facter.fact(:java_major_version).value).to be_nil

View File

@@ -7,7 +7,7 @@ describe 'java_patch_level' do
context 'when java is installed returns java patch version extracted from java_version fact' do
before :each do
Facter.fact(:java_version).stubs(:value).returns('1.7.0_71')
allow(Facter.fact(:java_version)).to receive(:value).and_return('1.7.0_71')
end
it do
expect(Facter.fact(:java_patch_level).value).to eq('71')
@@ -16,7 +16,7 @@ describe 'java_patch_level' do
context 'when java is not installed returns nil' do
before :each do
Facter.fact(:java_version).stubs(:value).returns(nil)
allow(Facter.fact(:java_version)).to receive(:value).and_return('nil')
end
it do
expect(Facter.fact(:java_patch_level).value).to be_nil

View File

@@ -18,37 +18,37 @@ describe 'java_version' do
context 'when java present, returns java version' do
context 'on OpenBSD', with_env: true do
before(:each) do
Facter.fact(:operatingsystem).stubs(:value).returns('OpenBSD')
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD')
end
let(:facts) { { operatingsystem: 'OpenBSD' } }
it do
Facter::Util::Resolution.expects(:which).with('java').returns('/usr/local/jdk-1.7.0/jre/bin/java')
Facter::Util::Resolution.expects(:exec).with('java -Xmx12m -version 2>&1').returns(openjdk_7_output)
expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('/usr/local/jdk-1.7.0/jre/bin/java')
expect(Facter::Util::Resolution).to receive(:exec).with('java -Xmx12m -version 2>&1').and_return(openjdk_7_output)
expect(Facter.value(:java_version)).to eq('1.7.0_71')
end
end
context 'when on Darwin' do
before(:each) do
Facter.fact(:operatingsystem).stubs(:value).returns('Darwin')
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin')
end
let(:facts) { { operatingsystem: 'Darwin' } }
it do
Facter::Util::Resolution.expects(:exec).with('/usr/libexec/java_home --failfast 2>&1').returns('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home')
Facter::Util::Resolution.expects(:exec).with('java -Xmx12m -version 2>&1').returns(jdk_7_hotspot_output)
expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').and_return('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home')
expect(Facter::Util::Resolution).to receive(:exec).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output)
expect(Facter.value(:java_version)).to eql '1.7.0_71'
end
end
context 'when on other systems' do
before(:each) do
Facter.fact(:operatingsystem).stubs(:value).returns('MyOS')
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS')
end
let(:facts) { { operatingsystem: 'MyOS' } }
it do
Facter::Util::Resolution.expects(:which).with('java').returns('/path/to/java')
Facter::Util::Resolution.expects(:exec).with('java -Xmx12m -version 2>&1').returns(jdk_7_hotspot_output)
expect(Facter::Util::Resolution).to receive(:which).with('java').and_return('/path/to/java')
expect(Facter::Util::Resolution).to receive(:exec).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output)
expect(Facter.value(:java_version)).to eq('1.7.0_71')
end
end
@@ -57,34 +57,34 @@ describe 'java_version' do
context 'when java not present, returns nil' do
context 'on OpenBSD', with_env: true do
before(:each) do
Facter.fact(:operatingsystem).stubs(:value).returns('OpenBSD')
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD')
end
let(:facts) { { operatingsystem: 'OpenBSD' } }
it do
Facter::Util::Resolution.stubs(:exec)
allow(Facter::Util::Resolution).to receive(:exec) # Catch all other calls
expect(Facter.value(:java_version)).to be_nil
end
end
context 'when on Darwin' do
before(:each) do
Facter.fact(:operatingsystem).stubs(:value).returns('Darwin')
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Darwin')
end
let(:facts) { { operatingsystem: 'Darwin' } }
it do
Facter::Util::Resolution.expects(:exec).at_least(1).with('/usr/libexec/java_home --failfast 2>&1').returns('Unable to find any JVMs matching version "(null)".')
expect(Facter::Util::Resolution).to receive(:exec).with('/usr/libexec/java_home --failfast 2>&1').at_least(1).and_return('Unable to find any JVMs matching version "(null)".')
expect(Facter.value(:java_version)).to be_nil
end
end
context 'when on other systems' do
before(:each) do
Facter.fact(:operatingsystem).stubs(:value).returns('MyOS')
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS')
end
let(:facts) { { operatingsystem: 'MyOS' } }
it do
Facter::Util::Resolution.expects(:which).at_least(1).with('java').returns(false)
expect(Facter::Util::Resolution).to receive(:which).at_least(1).with('java').and_return(false)
expect(Facter.value(:java_version)).to be_nil
end
end