14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## Supported Release 1.4.0
###Summary

Small release for bug with multiple Realms in the same parent path.

#### Features
- Improved documentation for purging connectors.
- Improved documentation for purging realms.
- Added package_options to tomcat::instance

#### Bugfixes
- Fixed bug where multiple Realms in the same parent would corrupt data.
- Added work-around for Augeas bug when purging Realms.

## Supported Release 1.3.3
###Summary

Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,13 @@ Determines whether to create the specified user, if it doesn't exist. Uses Puppe

#####`purge_connectors`

Specifies whether to purge any unmanaged Connector elements from the configuration file. Valid options: 'true' and 'false'. Default: 'false'.
Specifies whether to purge any unmanaged Connector elements that match
defined protocol but have a different port
from the configuration file. Valid options: 'true' and 'false'. Default: 'false'.

#####`purge_realms`

Specifies whether to purge any unmanaged Realm elements from the configuration file. Valid options: 'true' and 'false'. Default: 'false'.
Specifies whether to purge any unmanaged Realm elements from the configuration file. Valid options: 'true' and 'false'. Default: 'false'. If two Realms are defined for a specific server config only use purge_realms for the first realm and ensure the realms enforce a strict order between each other.

#####`user`

Expand Down Expand Up @@ -331,6 +333,10 @@ Specifies which Service element the Connector should nest under. Valid options:

Specifies a protocol to use for handling incoming traffic. Maps to the [protocol XML attribute](http://tomcat.apache.org/tomcat-8.0-doc/config/http.html#Common_Attributes). Valid options: a string. Default: $name.

#####`purge_connectors`

Specifies whether to purge any unmanaged Connector elements that match defined protocol but have a different port from the configuration file. Valid options: 'true' and 'false'. Default: 'false'.

#####`server_config`

Specifies a server.xml file to manage. Valid options: a string containing an absolute path. Default: '${catalina_base}/config/server.xml'.
Expand Down Expand Up @@ -657,6 +663,10 @@ Determines whether the specified package should be installed. Only valid if `ins

*Required if `install_from_source` is set to 'false'.* Specifies the package to install. Valid options: a string containing a valid package name.

#####`package_options`

*Unused if `install_from_source` is set to 'true'.* Specify additional options to use on the generated package resource. See the documentation of the [`package` resource type](https://docs.puppetlabs.com/references/latest/type.html#package-attribute-install_options) for possible values.

#####`source_strip_first_dir`

Specifies whether to strip the topmost directory of the tarball when unpacking it. Only valid if `install_from_source` is set to 'true'. Valid options: 'true' and 'false'. Default: 'true'.
Expand Down
4 changes: 2 additions & 2 deletions manifests/config/server/connector.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
validate_hash($additional_attributes)
validate_bool($purge_connectors)
validate_re($catalina_base, '^.*[^/]$', '$catalina_base must not end in a /!')

if $protocol {
$_protocol = $protocol
} else {
Expand All @@ -44,7 +44,7 @@
$path = "Server/Service[#attribute/name='${parent_service}']"

if $purge_connectors {
$_purge_connectors = "rm Server//Connector[#attribute/protocol='${_protocol}']"
$_purge_connectors = "rm Server//Connector[#attribute/protocol='${_protocol}'][#attribute/port!='${port}']"
} else {
$_purge_connectors = undef
}
Expand Down
12 changes: 10 additions & 2 deletions manifests/config/server/realm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@
}

if $purge_realms {
$_purge_realms = 'rm Server//Realm'
# Perform deletions in reverse depth order as workaround for
# https://github.com/hercules-team/augeas/issues/319
$_purge_realms = [
'rm //Realm//Realm',
'rm //Context//Realm',
'rm //Host//Realm',
'rm //Engine//Realm',
'rm //Server//Realm',
]
} else {
$_purge_realms = undef
}
Expand Down Expand Up @@ -79,7 +87,7 @@
}
else {

$_class_name = "set ${path}/#attribute/className ${class_name}"
$_class_name = "set ${path}[#attribute/className='${class_name}']/#attribute/className ${class_name}"

if ! empty($additional_attributes) {
$_additional_attributes = suffix(prefix(join_keys_to_values($additional_attributes, " '"), "set ${path}[#attribute/className='${class_name}']/#attribute/"), "'")
Expand Down
5 changes: 4 additions & 1 deletion manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# to in the package resource.
# - $package_name is the name of the package you want to install. Required if
# $install_from_source is false.
# - $package_options to pass extra options to the package resource.
define tomcat::instance (
$catalina_home = undef,
$catalina_base = undef,
Expand All @@ -25,6 +26,7 @@
$source_strip_first_dir = undef,
$package_ensure = undef,
$package_name = undef,
$package_options = undef,
) {

if $install_from_source {
Expand Down Expand Up @@ -74,7 +76,8 @@
}
} else {
tomcat::instance::package { $package_name:
package_ensure => $package_ensure,
package_ensure => $package_ensure,
package_options => $package_options,
}
}

Expand Down
9 changes: 6 additions & 3 deletions manifests/instance/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# Parameters:
# - $package_ensure is the ensure passed to the package resource.
# - The $package_name you want to install.
# - $package_options to pass extra options to the package resource.
define tomcat::instance::package (
$package_ensure = 'installed',
$package_name = undef,
$package_ensure = 'installed',
$package_name = undef,
$package_options = undef,
) {
if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
Expand All @@ -20,7 +22,8 @@
}

package { $_package_name:
ensure => $package_ensure
ensure => $package_ensure,
install_options => $package_options,
}

}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-tomcat",
"version": "1.3.3",
"version": "1.4.0",
"author": "puppetlabs",
"summary": "Installs, deploys, and configures Apache Tomcat web services.",
"license": "Apache 2.0",
Expand Down
95 changes: 95 additions & 0 deletions spec/acceptance/acceptance_4_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
require 'spec_helper_acceptance'

#fact based two stage confine

#confine array
confine_array = [
(fact('operatingsystem') == 'Ubuntu' && fact('operatingsystemrelease') == '10.04'),
(fact('osfamily') == 'RedHat' && fact('operatingsystemmajrelease') == '5'),
(fact('operatingsystem') == 'Debian' && fact('operatingsystemmajrelease') == '6'),
fact('osfamily') == 'Suse'
]

stop_test = false
stop_test = true if UNSUPPORTED_PLATFORMS.any?{ |up| fact('osfamily') == up} || confine_array.any?

describe 'Use two realms within a configuration', :unless => stop_test do

shell("curl -k -o /tmp/sample.war '#{SAMPLE_WAR}'", :acceptable_exit_codes => 0)

context 'Initial install Tomcat and verification' do
it 'Should apply the manifest without error' do
pp = <<-EOS
class { 'tomcat':}
class { 'java':}
tomcat::instance { 'tomcat40':
source_url => '#{TOMCAT7_RECENT_SOURCE}',
catalina_base => '/opt/apache-tomcat/tomcat40',
}->
tomcat::config::server { 'tomcat40':
catalina_base => '/opt/apache-tomcat/tomcat40',
port => '8105',
}->
tomcat::config::server::connector { 'tomcat40-http':
catalina_base => '/opt/apache-tomcat/tomcat40',
port => '8180',
protocol => 'HTTP/1.1',
additional_attributes => {
'redirectPort' => '8543'
},
}->
tomcat::config::server::connector { 'tomcat40-ajp':
catalina_base => '/opt/apache-tomcat/tomcat40',
port => '8109',
protocol => 'AJP/1.3',
additional_attributes => {
'redirectPort' => '8543'
},
}->
tomcat::war { 'tomcat40-sample.war':
catalina_base => '/opt/apache-tomcat/tomcat40',
war_source => '/tmp/sample.war',
war_name => 'tomcat40-sample.war',
}->
tomcat::service { 'tomcat40':
catalina_base => '/opt/apache-tomcat/tomcat40',
}->
tomcat::config::server::realm { 'org.apache.catalina.realm.MyRealm1':
realm_ensure => present,
server_config => '/opt/apache-tomcat/tomcat40/conf/server.xml',
additional_attributes => {
resourceName => "MyRealm1",
}
}->
tomcat::config::server::realm { 'org.apache.catalina.realm.MyRealm2':
realm_ensure => present,
server_config => '/opt/apache-tomcat/tomcat40/conf/server.xml',
additional_attributes => {
resourceName => "MyRealm2",
}
}
EOS
apply_manifest(pp, :catch_failures => true, :acceptable_exit_codes => [0,2])
shell('sleep 15')
end
it 'Should contain two realms in config file' do
shell('cat /opt/apache-tomcat/tomcat40/conf/server.xml', :acceptable_exit_codes => 0) do |r|
r.stdout.should match(/<Realm className="org.apache.catalina.realm.MyRealm1" resourceName="MyRealm1"><\/Realm>/)
r.stdout.should match(/<Realm className="org.apache.catalina.realm.MyRealm2" resourceName="MyRealm2"><\/Realm>/)
end
end
it 'should be idempotent' do
pp = <<-EOS
class{ 'tomcat':}
tomcat::config::server::realm { 'org.apache.catalina.realm.MyRealm2':
realm_ensure => present,
server_config => '/opt/apache-tomcat/tomcat40/conf/server.xml',
additional_attributes => {
resourceName => "MyRealm2",
}
}
EOS
apply_manifest(pp, :catch_changes => true)
end
end
end
2 changes: 1 addition & 1 deletion spec/defines/config/server/connector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
'rm Server//Connector[#attribute/protocol=\'AJP/1.3\']',
'rm Server//Connector[#attribute/protocol=\'AJP/1.3\'][#attribute/port!=\'8180\']',
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/port 8180',
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/protocol AJP/1.3',
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/redirectPort \'8543\'',
Expand Down
20 changes: 12 additions & 8 deletions spec/defines/config/server/realm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/server.xml',
'changes' => [
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/connectionURL 'ldap://localhost'",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/roleName 'cn'",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/roleSearch 'member={0}'",
Expand Down Expand Up @@ -70,8 +70,12 @@
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
"rm Server//Realm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm/#attribute/className org.apache.catalina.realm.JNDIRealm",
"rm //Realm//Realm",
"rm //Context//Realm",
"rm //Host//Realm",
"rm //Engine//Realm",
"rm //Server//Realm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/connectionURL 'ldap://localhost'",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/roleName 'cn'",
"rm Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/foo",
Expand All @@ -94,7 +98,7 @@
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/className org.apache.catalina.realm.JNDIRealm",
]
)
}
Expand Down Expand Up @@ -153,7 +157,7 @@
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
"set Server/Service[#attribute/name='NewService']/Engine[#attribute/name='AnotherEngine']/Realm/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='NewService']/Engine[#attribute/name='AnotherEngine']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/className org.apache.catalina.realm.JNDIRealm",
]
)
}
Expand All @@ -173,7 +177,7 @@
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Host[#attribute/name='localhost']/Realm/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Host[#attribute/name='localhost']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/className org.apache.catalina.realm.JNDIRealm",
]
)
}
Expand All @@ -194,7 +198,7 @@
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Host[#attribute/name='localhost']/Realm[#attribute/className='org.apache.catalina.realm.LockOutRealm']/Realm/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Host[#attribute/name='localhost']/Realm[#attribute/className='org.apache.catalina.realm.LockOutRealm']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/className org.apache.catalina.realm.JNDIRealm",
]
)
}
Expand All @@ -220,7 +224,7 @@
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.LockOutRealm']/Realm/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.LockOutRealm']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/className org.apache.catalina.realm.JNDIRealm",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.LockOutRealm']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/connectionURL 'ldap://localhost'",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.LockOutRealm']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/roleName 'cn'",
"set Server/Service[#attribute/name='Catalina']/Engine[#attribute/name='Catalina']/Realm[#attribute/className='org.apache.catalina.realm.LockOutRealm']/Realm[#attribute/className='org.apache.catalina.realm.JNDIRealm']/#attribute/roleSearch 'member={0}'",
Expand Down
15 changes: 15 additions & 0 deletions spec/defines/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@
'ensure' => 'installed',
)
}
context "with additional package_options set" do
let :params do
{
:install_from_source => false,
:package_name => 'tomcat',
:package_options => [ '/S' ],
}
end
it {
is_expected.to contain_package('tomcat').with(
'ensure' => 'installed',
'install_options' => [ '/S' ],
)
}
end
end
context "install from package, set $catalina_base" do
let :facts do default_facts end
Expand Down