Skip to content

Commit b0c524c

Browse files
committed
Add param package_manage
1 parent 9b1a148 commit b0c524c

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed

REFERENCE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class { 'haproxy':
109109
The following parameters are available in the `haproxy` class:
110110

111111
* [`package_ensure`](#-haproxy--package_ensure)
112+
* [`package_manage`](#-haproxy--package_manage)
112113
* [`package_name`](#-haproxy--package_name)
113114
* [`service_ensure`](#-haproxy--service_ensure)
114115
* [`service_manage`](#-haproxy--service_manage)
@@ -137,6 +138,15 @@ Defaults to 'present'
137138

138139
Default value: `'present'`
139140

141+
##### <a name="-haproxy--package_manage"></a>`package_manage`
142+
143+
Data type: `Boolean`
144+
145+
Decide whether the module should manage the installation of
146+
haproxy package. Defaults to true
147+
148+
Default value: `true`
149+
140150
##### <a name="-haproxy--package_name"></a>`package_name`
141151

142152
Data type: `String`

manifests/init.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
# from all balancer members.
1010
#
1111
#
12+
# @param package_manage
13+
# Decide whether the module should manage the installation of
14+
# haproxy package. Defaults to true
15+
#
1216
# @param package_ensure
1317
# Ensure the package is present (installed), absent or a specific version.
1418
# Defaults to 'present'
@@ -121,6 +125,7 @@
121125
#
122126
class haproxy (
123127
Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure = 'present',
128+
Boolean $package_manage = true,
124129
String $package_name = $haproxy::params::package_name,
125130
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
126131
Boolean $service_manage = true,
@@ -171,6 +176,7 @@
171176
}
172177

173178
haproxy::instance { $title:
179+
package_manage => $package_manage,
174180
package_ensure => $_package_ensure,
175181
package_name => $package_name,
176182
service_ensure => $_service_ensure,

manifests/install.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Install haproxy
33
# @api private
44
define haproxy::install (
5+
Boolean $package_manage,
56
# lint:ignore:140chars
67
Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure,
78
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.
@@ -11,7 +12,7 @@
1112
fail("Use of private class ${name} by ${caller_module_name}")
1213
}
1314

14-
if $package_name != undef {
15+
if $package_manage {
1516
package { $package_name:
1617
ensure => $package_ensure,
1718
alias => 'haproxy',

manifests/instance.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# uses storeconfigs on the Puppet Server to export/collect resources
1111
# from all balancer members.
1212
#
13+
# @param package_manage
14+
# Decide whether the module should manage the installation of
15+
# haproxy package. Defaults to true
1316
#
1417
# @param package_ensure
1518
# Ensure the package is present (installed), absent or a specific version.
@@ -160,6 +163,7 @@
160163
#
161164
define haproxy::instance (
162165
Variant[Enum['present', 'absent', 'purged', 'disabled', 'installed', 'latest'], String[1]] $package_ensure = 'present',
166+
Boolean $package_manage = true,
163167
Optional[String] $package_name = undef,
164168
Variant[Enum['running', 'stopped'], Boolean] $service_ensure = 'running',
165169
Boolean $service_manage = true,
@@ -223,6 +227,7 @@
223227
config_validate_cmd => $config_validate_cmd,
224228
}
225229
haproxy::install { $title:
230+
package_manage => $package_manage,
226231
package_name => $package_name,
227232
package_ensure => $package_ensure,
228233
}

spec/defines/instance_spec.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,94 @@
503503
end
504504
end
505505

506+
context "when on #{osfamily} family operatingsystems without managing the package" do
507+
let(:facts) do
508+
{ os: { family: osfamily } }.merge default_facts
509+
end
510+
let(:params) do
511+
{
512+
'package_ensure' => 'present',
513+
'package_name' => 'customhaproxy',
514+
'package_manage' => false,
515+
'service_ensure' => 'running',
516+
517+
}
518+
end
519+
520+
it 'does not manage the customhaproxy package' do
521+
subject.should_not contain_package('customhaproxy').with(
522+
'ensure' => 'present',
523+
)
524+
end
525+
526+
it 'installs the customhaproxy service' do
527+
subject.should contain_service('haproxy-group1').with(
528+
'ensure' => 'running', 'enable' => 'true',
529+
'hasrestart' => 'true', 'hasstatus' => 'true'
530+
)
531+
end
532+
533+
it 'sets up /etc/haproxy-group1/haproxy-group1.cfg as a concat resource' do
534+
subject.should contain_concat('/etc/haproxy-group1/haproxy-group1.cfg').with(
535+
'owner' => '0',
536+
'group' => '0',
537+
'mode' => '0640',
538+
)
539+
end
540+
541+
it 'manages the chroot directory' do
542+
subject.should contain_file('/var/lib/haproxy').with(
543+
'ensure' => 'directory',
544+
)
545+
end
546+
547+
it 'contains a header concat fragment' do
548+
subject.should contain_concat__fragment('haproxy-group1-00-header').with(
549+
'target' => '/etc/haproxy-group1/haproxy-group1.cfg',
550+
'order' => '01',
551+
'content' => "# This file is managed by Puppet\n",
552+
)
553+
end
554+
555+
it 'contains a haproxy-group1-haproxy-base concat fragment' do
556+
subject.should contain_concat__fragment('haproxy-group1-haproxy-base').with(
557+
'target' => '/etc/haproxy-group1/haproxy-group1.cfg',
558+
'order' => '10',
559+
)
560+
end
561+
562+
describe 'Base concat fragment contents' do
563+
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-group1-haproxy-base', 'content').split("\n") }
564+
565+
it 'contains global and defaults sections' do
566+
contents.should include('global')
567+
contents.should include('defaults')
568+
end
569+
570+
it 'logs to an ip address for local0' do
571+
contents.should be_any do |match|
572+
match =~ %r{ log \d+(\.\d+){3} local0}
573+
end
574+
end
575+
576+
it 'specifies the default chroot' do
577+
contents.should include(' chroot /var/lib/haproxy')
578+
end
579+
580+
it 'specifies the correct user' do
581+
contents.should include(' user haproxy')
582+
end
583+
584+
it 'specifies the correct group' do
585+
contents.should include(' group haproxy')
586+
end
587+
588+
it 'specifies the correct pidfile' do
589+
contents.should include(' pidfile /var/run/haproxy.pid')
590+
end
591+
end
592+
end
593+
506594
context "when on #{osfamily} when specifying a restart_command" do
507595
let(:facts) do
508596
{ os: { family: osfamily } }.merge default_facts

0 commit comments

Comments
 (0)