Skip to content

Commit

Permalink
Add parameters to configure negotiation module
Browse files Browse the repository at this point in the history
  • Loading branch information
amateo committed Jun 10, 2014
1 parent 3ad5b24 commit 198aa99
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 3 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Class: apache::mod::ssl](#class-apachemodssl)
* [Class: apache::mod::wsgi](#class-apachemodwsgi)
* [Class: apache::mod::fcgid](#class-apachemodfcgid)
* [Class: apache::mod::negotiation](#class-apachemodnegotiation)
* [Defined Type: apache::vhost](#defined-type-apachevhost)
* [Parameter: `directories` for apache::vhost](#parameter-directories-for-apachevhost)
* [SSL parameters for apache::vhost](#ssl-parameters-for-apachevhost)
Expand Down Expand Up @@ -641,6 +642,28 @@ It is also possible to set the FcgidWrapper per directory per vhost. You must en

See [FcgidWrapper documentation](https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidwrapper) for more information.

####Class: `apache::mod::negotiation`

Installs and configures mod_negotiation. If there are not provided any
parameter, default apache mod_negotiation configuration is done.

```puppet
class { '::apache::mod::negotiation':
force_language_priority => 'Prefer',
language_priority => [ 'es', 'en', 'ca', 'cs', 'da', 'de', 'el', 'eo' ],
}
```

**Parameters within `apache::mod::negotiation`:**

#####`force_language_priority`

A string that sets the `ForceLanguagePriority` option. Defaults to `Prefer Fallback`.

#####`language_priority`

An array of languages to set the `LanguagePriority` option of the module.

####Defined Type: `apache::vhost`

The Apache module allows a lot of flexibility in the setup and configuration of virtual hosts. This flexibility is due, in part, to `vhost`'s being a defined resource type, which allows it to be evaluated multiple times with different parameters.
Expand Down
11 changes: 10 additions & 1 deletion manifests/mod/negotiation.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
class apache::mod::negotiation {
class apache::mod::negotiation (
$force_language_priority = 'Prefer Fallback',
$language_priority = [ 'en', 'ca', 'cs', 'da', 'de', 'el', 'eo', 'es', 'et',
'fr', 'he', 'hr', 'it', 'ja', 'ko', 'ltz', 'nl', 'nn',
'no', 'pl', 'pt', 'pt-BR', 'ru', 'sv', 'zh-CN',
'zh-TW' ],
) {
validate_string($force_language_priority)
validate_array($language_priority)

::apache::mod { 'negotiation': }
# Template uses no variables
file { 'negotiation.conf':
Expand Down
80 changes: 80 additions & 0 deletions spec/acceptance/mod_negotiation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'spec_helper_acceptance'

describe 'apache::mod::negotiation class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
case fact('osfamily')
when 'Debian'
vhost_dir = '/etc/apache2/sites-enabled'
mod_dir = '/etc/apache2/mods-available'
service_name = 'apache2'
when 'RedHat'
vhost_dir = '/etc/httpd/conf.d'
mod_dir = '/etc/httpd/conf.d'
service_name = 'httpd'
when 'FreeBSD'
vhost_dir = '/usr/local/etc/apache22/Vhosts'
mod_dir = '/usr/local/etc/apache22/Modules'
service_name = 'apache22'
end

context "default negotiation config" do
it 'succeeds in puppeting negotiation' do
pp= <<-EOS
class { '::apache': }
class { '::apache::mod::negotiation': }
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file("#{$mod_dir}/negotiation.conf") do
it { should contain "LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
ForceLanguagePriority Prefer Fallback" }
end

describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end

context "with alternative force_language_priority" do
it 'succeeds in puppeting negotiation' do
pp= <<-EOS
class { '::apache': }
class { '::apache::mod::negotiation':
force_language_priority => 'Prefer',
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file("#{$mod_dir}/negotiation.conf") do
it { should contain "ForceLanguagePriority Prefer" }
end

describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end

context "with alternative language_priority" do
it 'succeeds in puppeting negotiation' do
pp= <<-EOS
class { '::apache': }
class { '::apache::mod::negotiation':
language_priority => [ 'en', 'es' ],
}
EOS
apply_manifest(pp, :catch_failures => true)
end

describe file("#{$mod_dir}/negotiation.conf") do
it { should contain "LanguagePriority en es" }
end

describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end
end
59 changes: 59 additions & 0 deletions spec/classes/mod/negotiation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'spec_helper'

describe 'apache::mod::negotiation', :type => :class do
describe "OS independent tests" do

let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
}
end

context "default params" do
let :pre_condition do
'class {"::apache": }'
end
it { should contain_class("apache") }
it do
should contain_file('negotiation.conf').with( {
:ensure => 'file',
:content => 'LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
ForceLanguagePriority Prefer Fallback
',
} )
end
end

context 'with force_language_priority parameter' do
let :pre_condition do
'class {"::apache": default_mods => ["negotiation"]}'
end
let :params do
{ :force_language_priority => 'Prefer' }
end
it do
should contain_file('negotiation.conf').with( {
:ensure => 'file',
:content => /^ForceLanguagePriority Prefer$/,
} )
end
end

context 'with language_priority parameter' do
let :pre_condition do
'class {"::apache": default_mods => ["negotiation"]}'
end
let :params do
{ :language_priority => [ 'en', 'es' ] }
end
it do
should contain_file('negotiation.conf').with( {
:ensure => 'file',
:content => /^LanguagePriority en es$/,
} )
end
end
end
end
4 changes: 4 additions & 0 deletions spec/fixtures/files/negotiation.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a file only for spec testing

LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
ForceLanguagePriority Prefer Fallback
4 changes: 4 additions & 0 deletions spec/fixtures/templates/negotiation.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a template only for spec testing

LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
ForceLanguagePriority Prefer Fallback
4 changes: 2 additions & 2 deletions templates/mod/negotiation.conf.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
ForceLanguagePriority Prefer Fallback
LanguagePriority <%= @language_priority.join(' ') %>
ForceLanguagePriority <%= @force_language_priority %>

0 comments on commit 198aa99

Please sign in to comment.