Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class { 'haproxy':
The following parameters are available in the `haproxy` class:

* [`package_ensure`](#-haproxy--package_ensure)
* [`package_manage`](#-haproxy--package_manage)
* [`package_name`](#-haproxy--package_name)
* [`service_ensure`](#-haproxy--service_ensure)
* [`service_manage`](#-haproxy--service_manage)
Expand Down Expand Up @@ -139,6 +140,15 @@ Defaults to 'present'

Default value: `'present'`

##### <a name="-haproxy--package_manage"></a>`package_manage`

Data type: `Boolean`

Decide whether the module should manage the installation of
haproxy package. Defaults to true

Default value: `true`

##### <a name="-haproxy--package_name"></a>`package_name`

Data type: `String`
Expand Down
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# from all balancer members.
#
#
# @param package_manage
# Decide whether the module should manage the installation of
# haproxy package. Defaults to true
#
# @param package_ensure
# Ensure the package is present (installed), absent or a specific version.
# Defaults to 'present'
Expand Down Expand Up @@ -121,6 +125,7 @@
#
class haproxy (
Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure = 'present',
Boolean $package_manage = true,
String $package_name = $haproxy::params::package_name,
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
Boolean $service_manage = true,
Expand Down Expand Up @@ -174,6 +179,7 @@
}

haproxy::instance { $title:
package_manage => $package_manage,
package_ensure => $_package_ensure,
package_name => $package_name,
service_ensure => $_service_ensure,
Expand Down
3 changes: 2 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Install haproxy
# @api private
define haproxy::install (
Boolean $package_manage,
# lint:ignore:140chars
Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure,
Optional[String] $package_name = undef, # A default is required for Puppet 2.7 compatibility. When 2.7 is no longer supported, this parameter default should be removed.
Expand All @@ -11,7 +12,7 @@
fail("Use of private class ${name} by ${caller_module_name}")
}

if $package_name != undef {
if $package_manage {
package { $package_name:
ensure => $package_ensure,
alias => 'haproxy',
Expand Down
5 changes: 5 additions & 0 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# uses storeconfigs on the Puppet Server to export/collect resources
# from all balancer members.
#
# @param package_manage
# Decide whether the module should manage the installation of
# haproxy package. Defaults to true
#
# @param package_ensure
# Ensure the package is present (installed), absent or a specific version.
Expand Down Expand Up @@ -160,6 +163,7 @@
#
define haproxy::instance (
Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure = 'present',
Boolean $package_manage = true,
Optional[String] $package_name = undef,
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
Boolean $service_manage = true,
Expand Down Expand Up @@ -223,6 +227,7 @@
config_validate_cmd => $config_validate_cmd,
}
haproxy::install { $title:
package_manage => $package_manage,
package_name => $package_name,
package_ensure => $package_ensure,
}
Expand Down
88 changes: 88 additions & 0 deletions spec/defines/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
{ 'custom_fragment' => "listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n" }
end

it 'sets the haproxy package' do

Check failure on line 89 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for OS-agnostic configuration when on FreeBSD when specifying custom content sets the haproxy package Failure/Error: subject.should contain_concat__fragment('haproxy-haproxy-base').with_content( %r{listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n}, ) Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net

Check failure on line 89 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for OS-agnostic configuration when on Archlinux when specifying custom content sets the haproxy package Failure/Error: subject.should contain_concat__fragment('haproxy-haproxy-base').with_content( %r{listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n}, ) Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net

Check failure on line 89 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for OS-agnostic configuration when on RedHat when specifying custom content sets the haproxy package Failure/Error: subject.should contain_concat__fragment('haproxy-haproxy-base').with_content( %r{listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n}, ) Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net

Check failure on line 89 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for OS-agnostic configuration when on Debian when specifying custom content sets the haproxy package Failure/Error: subject.should contain_concat__fragment('haproxy-haproxy-base').with_content( %r{listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n}, ) Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net
subject.should contain_concat__fragment('haproxy-haproxy-base').with_content(
%r{listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n},
)
Expand All @@ -102,7 +102,7 @@
{ os: { family: osfamily } }.merge default_facts
end

it 'sets up /etc/haproxy/haproxy.cfg as a concat resource' do

Check failure on line 105 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for linux operating systems when on Debian family operatingsystems sets up /etc/haproxy/haproxy.cfg as a concat resource Failure/Error: subject.should contain_concat('/etc/haproxy/haproxy.cfg').with( 'owner' => '0', 'group' => '0', 'mode' => '0640', ) Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net
subject.should contain_concat('/etc/haproxy/haproxy.cfg').with(
'owner' => '0',
'group' => '0',
Expand All @@ -110,7 +110,7 @@
)
end

it 'manages the chroot directory' do

Check failure on line 113 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for linux operating systems when on Debian family operatingsystems manages the chroot directory Failure/Error: subject.should contain_file('/var/lib/haproxy').with( 'ensure' => 'directory', 'owner' => 'haproxy', 'group' => 'haproxy', ) Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net
subject.should contain_file('/var/lib/haproxy').with(
'ensure' => 'directory',
'owner' => 'haproxy',
Expand All @@ -118,7 +118,7 @@
)
end

it 'contains a header concat fragment' do

Check failure on line 121 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for linux operating systems when on Debian family operatingsystems contains a header concat fragment Failure/Error: subject.should contain_concat__fragment('haproxy-00-header').with( 'target' => '/etc/haproxy/haproxy.cfg', 'order' => '01', 'content' => "# This file is managed by Puppet\n", ) Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net
subject.should contain_concat__fragment('haproxy-00-header').with(
'target' => '/etc/haproxy/haproxy.cfg',
'order' => '01',
Expand All @@ -126,7 +126,7 @@
)
end

it 'contains a haproxy-haproxy-base concat fragment' do

Check failure on line 129 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for linux operating systems when on Debian family operatingsystems contains a haproxy-haproxy-base concat fragment Failure/Error: subject.should contain_concat__fragment('haproxy-haproxy-base').with( 'target' => '/etc/haproxy/haproxy.cfg', 'order' => '10', ) Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net
subject.should contain_concat__fragment('haproxy-haproxy-base').with(
'target' => '/etc/haproxy/haproxy.cfg',
'order' => '10',
Expand All @@ -137,12 +137,12 @@
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") }

# C9936 C9937
it 'contains global and defaults sections' do

Check failure on line 140 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for linux operating systems when on Debian family operatingsystems Base concat fragment contents contains global and defaults sections Failure/Error: let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net
contents.should include('global')
contents.should include('defaults')
end

it 'logs to an ip address for local0' do

Check failure on line 145 in spec/defines/instance_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

haproxy::instance with haproxy::instance with service name "haproxy for linux operating systems when on Debian family operatingsystems Base concat fragment contents logs to an ip address for local0 Failure/Error: let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Missing title. The title expression resulted in undef (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/install.pp, line: 16, column: 15) (file: /home/runner/work/puppetlabs-haproxy/puppetlabs-haproxy/spec/fixtures/modules/haproxy/manifests/instance.pp, line: 229) on node runnervm3jd5f.bslcbgspqs0uxa3w1b2aduhsbc.cx.internal.cloudapp.net
contents.should be_any do |match|
match =~ %r{ log \d+(\.\d+){3} local0}
end
Expand Down Expand Up @@ -503,6 +503,94 @@
end
end

context "when on #{osfamily} family operatingsystems without managing the package" do
let(:facts) do
{ os: { family: osfamily } }.merge default_facts
end
let(:params) do
{
'package_ensure' => 'present',
'package_name' => 'customhaproxy',
'package_manage' => false,
'service_ensure' => 'running',

}
end

it 'does not manage the customhaproxy package' do
subject.should_not contain_package('customhaproxy').with(
'ensure' => 'present',
)
end

it 'installs the customhaproxy service' do
subject.should contain_service('haproxy-group1').with(
'ensure' => 'running', 'enable' => 'true',
'hasrestart' => 'true', 'hasstatus' => 'true'
)
end

it 'sets up /etc/haproxy-group1/haproxy-group1.cfg as a concat resource' do
subject.should contain_concat('/etc/haproxy-group1/haproxy-group1.cfg').with(
'owner' => '0',
'group' => '0',
'mode' => '0640',
)
end

it 'manages the chroot directory' do
subject.should contain_file('/var/lib/haproxy').with(
'ensure' => 'directory',
)
end

it 'contains a header concat fragment' do
subject.should contain_concat__fragment('haproxy-group1-00-header').with(
'target' => '/etc/haproxy-group1/haproxy-group1.cfg',
'order' => '01',
'content' => "# This file is managed by Puppet\n",
)
end

it 'contains a haproxy-group1-haproxy-base concat fragment' do
subject.should contain_concat__fragment('haproxy-group1-haproxy-base').with(
'target' => '/etc/haproxy-group1/haproxy-group1.cfg',
'order' => '10',
)
end

describe 'Base concat fragment contents' do
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-group1-haproxy-base', 'content').split("\n") }

it 'contains global and defaults sections' do
contents.should include('global')
contents.should include('defaults')
end

it 'logs to an ip address for local0' do
contents.should be_any do |match|
match =~ %r{ log \d+(\.\d+){3} local0}
end
end

it 'specifies the default chroot' do
contents.should include(' chroot /var/lib/haproxy')
end

it 'specifies the correct user' do
contents.should include(' user haproxy')
end

it 'specifies the correct group' do
contents.should include(' group haproxy')
end

it 'specifies the correct pidfile' do
contents.should include(' pidfile /var/run/haproxy.pid')
end
end
end

context "when on #{osfamily} when specifying a restart_command" do
let(:facts) do
{ os: { family: osfamily } }.merge default_facts
Expand Down
Loading