Skip to content

Commit

Permalink
Merge pull request #56 from philipwigg/purge-connectors
Browse files Browse the repository at this point in the history
MODULES-1478: Add a $purge_connectors parameter.
  • Loading branch information
Morgan Haskel committed Nov 10, 2014
2 parents 80d4d86 + ad3bf5c commit 3ae328e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .fixtures.yml
@@ -1,7 +1,7 @@
fixtures:
repositories:
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
concat: "git://github.com/puppetlabs/puppetlabs-concat.git"
staging: "git://github.com/nanliu/puppet-staging.git"
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
concat: "https://github.com/puppetlabs/puppetlabs-concat.git"
staging: "https://github.com/nanliu/puppet-staging.git"
symlinks:
tomcat: "#{source_dir}"
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -228,6 +228,14 @@ Sets the group to run Tomcat as.

Specifies whether or not to install from source. A Boolean that defaults to 'true'.

#####`$purge_connectors`

Specifies whether or not to purge existing Connector elements from server.xml.

For example, if you specify an HTTP connector element using ```tomcat::instance::connector``` and ```purge_connectors``` is set to ```true``` then existing HTTP connectors will be removed and only the HTTP connector you have specified will remain once the module has been applied.

This is useful if you want to change the ports of existing connectors instead of adding additional connectors. Boolean that defaults to 'false'.

#####`$manage_user`

Specifies whether or not to manage the user. Boolean that defaults to 'true'.
Expand Down
12 changes: 11 additions & 1 deletion manifests/config/server/connector.pp
Expand Up @@ -23,13 +23,15 @@
$parent_service = 'Catalina',
$additional_attributes = {},
$attributes_to_remove = [],
$purge_connectors = $::tomcat::purge_connectors,
) {
if versioncmp($::augeasversion, '1.0.0') < 0 {
fail('Server configurations require Augeas >= 1.0.0')
}

validate_re($connector_ensure, '^(present|absent|true|false)$')
validate_hash($additional_attributes)
validate_bool($purge_connectors)

if $protocol {
$_protocol = $protocol
Expand All @@ -39,6 +41,14 @@

$path = "Server/Service[#attribute/name='${parent_service}']"

if $purge_connectors {
$_purge_connectors = "rm Server//Connector[#attribute/protocol='${_protocol}']"
}

if $purge_connectors and ($connector_ensure =~ /^(absent|false)$/) {
fail('$connector_ensure must be set to \'true\' or \'present\' to use $purge_connectors')
}

if $connector_ensure =~ /^(absent|false)$/ {
if ! $port {
$base_path = "${path}/Connector[#attribute/protocol='${_protocol}']"
Expand All @@ -65,7 +75,7 @@
$_attributes_to_remove = undef
}

$changes = delete_undef_values(flatten([$_port, $_protocol_change, $_additional_attributes, $_attributes_to_remove]))
$changes = delete_undef_values(flatten([ $_purge_connectors, $_port, $_protocol_change, $_additional_attributes, $_attributes_to_remove ]))
}

augeas { "server-${catalina_base}-${parent_service}-connector-${port}":
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Expand Up @@ -24,10 +24,12 @@
$user = $::tomcat::params::user,
$group = $::tomcat::params::group,
$install_from_source = true,
$purge_connectors = false,
$manage_user = true,
$manage_group = true,
) inherits ::tomcat::params {
validate_bool($install_from_source)
validate_bool($purge_connectors)
validate_bool($manage_user)
validate_bool($manage_group)

Expand Down
50 changes: 50 additions & 0 deletions spec/defines/config/server/connector_spec.rb
Expand Up @@ -46,6 +46,42 @@
)
}
end
context 'set all the things with purge_connectors' do
let :params do
{
:port => '8180',
:catalina_base => '/opt/apache-tomcat/test',
:protocol => 'AJP/1.3',
:purge_connectors => true,
:parent_service => 'Catalina2',
:additional_attributes => {
'redirectPort' => '8543',
'connectionTimeout' => '20000',
},
:attributes_to_remove => [
'foo',
'bar',
'baz'
],
}
end
it { is_expected.to contain_augeas('server-/opt/apache-tomcat/test-Catalina2-connector-8180'
).with(
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
'rm Server//Connector[#attribute/protocol=\'AJP/1.3\']',
'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',
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/connectionTimeout 20000',
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/foo',
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/bar',
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/baz',
],
)
}
end
context 'remove connector' do
let :params do
{
Expand Down Expand Up @@ -79,6 +115,20 @@
)
}
end
context 'remove connector with purge_connectors' do
let :params do
{
:catalina_base => 'opt/apache-tomcat/test',
:connector_ensure => 'absent',
:purge_connectors => true,
}
end
it do
expect {
should compile
}.to raise_error(Puppet::Error, /\$connector_ensure must be set to 'true' or 'present' to use \$purge_connectors/)
end
end
context 'two connectors with same protocol' do
let :pre_condition do
'class { "tomcat": }
Expand Down

0 comments on commit 3ae328e

Please sign in to comment.