Skip to content

Commit

Permalink
mod_proxy_balancer manager
Browse files Browse the repository at this point in the history
  • Loading branch information
sathieu committed Nov 30, 2016
1 parent 2d70ca8 commit 8606dac
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1808,9 +1808,13 @@ Installs and manages [`mod_proxy_balancer`][], which provides load balancing.

**Parameters within `apache::mod::proxy_balancer`**:

- `manager`: Determines whether to enable balancer manager support. Default: `false`.
- `manager_path`: The server location of the balancer manager. Default: '/balancer-manager'.
- `allow_from`: An [array][] of IPv4 or IPv6 addresses that can access `/balancer-manager`. Default: ['127.0.0.1','::1'].
- `apache_version`: Apache's version number as a string, such as '2.2' or '2.4'. Default: the value of [`$::apache::apache_version`][`apache_version`].
- On Apache >= 2.4, `mod_slotmem_shm` is loaded.


##### Class: `apache::mod::php`

Installs and configures [`mod_php`][].
Expand Down
19 changes: 18 additions & 1 deletion manifests/mod/proxy_balancer.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
class apache::mod::proxy_balancer(
$manager = false,
$manager_path = '/balancer-manager',
$allow_from = ['127.0.0.1','::1'],
$apache_version = $::apache::apache_version,
) {
validate_bool($manager)
validate_string($manager_path)
validate_array($allow_from)

include ::apache::mod::proxy
include ::apache::mod::proxy_http
Expand All @@ -11,5 +17,16 @@
Class['::apache::mod::proxy'] -> Class['::apache::mod::proxy_balancer']
Class['::apache::mod::proxy_http'] -> Class['::apache::mod::proxy_balancer']
::apache::mod { 'proxy_balancer': }

if $manager {
include ::apache::mod::status
file { 'proxy_balancer.conf':
ensure => file,
path => "${::apache::mod_dir}/proxy_balancer.conf",
mode => $::apache::file_mode,
content => template('apache/mod/proxy_balancer.conf.erb'),
require => Exec["mkdir ${::apache::mod_dir}"],
before => File[$::apache::mod_dir],
notify => Class['apache::service'],
}
}
}
95 changes: 95 additions & 0 deletions spec/classes/mod/proxy_balancer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
require 'spec_helper'

# Helper function for testing the contents of `proxy_balancer.conf`
def balancer_manager_conf_spec(allow_from, manager_path)
it do
is_expected.to contain_file("proxy_balancer.conf").with_content(
"<Location #{manager_path}>\n"\
" SetHandler balancer-manager\n"\
" Require ip #{Array(allow_from).join(' ')}\n"\
"</Location>\n"
)
end
end

describe 'apache::mod::proxy_balancer', :type => :class do
let :pre_condition do
[
'include apache::mod::proxy',
]
end
it_behaves_like "a mod class, without including apache"

context "default configuration with default parameters" do
context "on a Debian OS" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '8',
:concat_basedir => '/dne',
:lsbdistcodename => 'jessie',
:operatingsystem => 'Debian',
:id => 'root',
:kernel => 'Linux',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
:is_pe => false,
}
end

it { is_expected.to contain_apache__mod("proxy_balancer") }

it { is_expected.to_not contain_file("proxy_balancer.conf") }
it { is_expected.to_not contain_file("proxy_balancer.conf symlink") }

end

context "on a RedHat OS" do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
:operatingsystem => 'RedHat',
:id => 'root',
:kernel => 'Linux',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
:is_pe => false,
}
end

it { is_expected.to contain_apache__mod("proxy_balancer") }

it { is_expected.to_not contain_file("proxy_balancer.conf") }
it { is_expected.to_not contain_file("proxy_balancer.conf symlink") }

end
end

context "default configuration with custom parameters $manager => true, $allow_from => ['10.10.10.10','11.11.11.11'], $status_path => '/custom-manager'" do
context "on a Debian OS" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '8',
:concat_basedir => '/dne',
:lsbdistcodename => 'jessie',
:operatingsystem => 'Debian',
:id => 'root',
:kernel => 'Linux',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
:is_pe => false,
}
end
let :params do
{
:manager => true,
:allow_from => ['10.10.10.10','11.11.11.11'],
:manager_path => '/custom-manager',
}
end

balancer_manager_conf_spec(["10.10.10.10", "11.11.11.11"], "/custom-manager")

end
end
end
10 changes: 10 additions & 0 deletions templates/mod/proxy_balancer.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Location <%= @manager_path %>>
SetHandler balancer-manager
<%- if scope.function_versioncmp([@apache_version, '2.4']) >= 0 -%>
Require ip <%= Array(@allow_from).join(" ") %>
<%- else -%>
Order deny,allow
Deny from all
Allow from <%= Array(@allow_from).join(" ") %>
<%- end -%>
</Location>

0 comments on commit 8606dac

Please sign in to comment.