| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
require 'spec_helper' |
| 4 |
|
| 5 |
describe 'haproxy::instance' do |
| 6 |
let(:default_facts) do |
| 7 |
{ |
| 8 |
concat_basedir: '/dne', |
| 9 |
networking: { |
| 10 |
ip: '10.10.10.10' |
| 11 |
} |
| 12 |
} |
| 13 |
end |
| 14 |
|
| 15 |
let(:pre_condition) do |
| 16 |
'include haproxy::params' |
| 17 |
end |
| 18 |
|
| 19 |
# haproxy::instance with service name "haproxy". |
| 20 |
|
| 21 |
context 'with haproxy::instance with service name "haproxy' do |
| 22 |
let(:title) { 'haproxy' } |
| 23 |
|
| 24 |
describe 'for OS-agnostic configuration' do |
| 25 |
['Debian', 'RedHat', 'Archlinux', 'FreeBSD'].each do |osfamily| |
| 26 |
context "when on #{osfamily} family operatingsystems" do |
| 27 |
let(:facts) do |
| 28 |
{ os: { family: osfamily } }.merge default_facts |
| 29 |
end |
| 30 |
let(:params) do |
| 31 |
{ |
| 32 |
'service_ensure' => 'running', |
| 33 |
'package_ensure' => 'present', |
| 34 |
'package_name' => 'haproxy', |
| 35 |
'service_manage' => true |
| 36 |
} |
| 37 |
end |
| 38 |
|
| 39 |
it 'installs the haproxy package' do |
| 40 |
subject.should contain_package('haproxy').with( |
| 41 |
'ensure' => 'present', |
| 42 |
) |
| 43 |
end |
| 44 |
|
| 45 |
it 'installs the haproxy service' do |
| 46 |
subject.should contain_service('haproxy').with( |
| 47 |
'ensure' => 'running', 'enable' => 'true', |
| 48 |
'hasrestart' => 'true', 'hasstatus' => 'true' |
| 49 |
) |
| 50 |
end |
| 51 |
end |
| 52 |
|
| 53 |
context "when on #{osfamily} family specifying a package version" do |
| 54 |
let(:facts) do |
| 55 |
{ os: { family: osfamily } }.merge default_facts |
| 56 |
end |
| 57 |
let(:params) do |
| 58 |
{ |
| 59 |
'service_ensure' => 'running', |
| 60 |
'package_ensure' => '1.7.9-1', |
| 61 |
'package_name' => 'haproxy', |
| 62 |
'service_manage' => true |
| 63 |
} |
| 64 |
end |
| 65 |
|
| 66 |
it 'installs the haproxy package in a specific version' do |
| 67 |
subject.should contain_package('haproxy').with( |
| 68 |
'ensure' => '1.7.9-1', |
| 69 |
) |
| 70 |
end |
| 71 |
|
| 72 |
it 'installs the haproxy service' do |
| 73 |
subject.should contain_service('haproxy').with( |
| 74 |
'ensure' => 'running', 'enable' => 'true', |
| 75 |
'hasrestart' => 'true', 'hasstatus' => 'true' |
| 76 |
) |
| 77 |
end |
| 78 |
end |
| 79 |
|
| 80 |
# C9938 |
| 81 |
context "when on #{osfamily} when specifying custom content" do |
| 82 |
let(:facts) do |
| 83 |
{ os: { family: osfamily } }.merge default_facts |
| 84 |
end |
| 85 |
let(:params) do |
| 86 |
{ 'custom_fragment' => "listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n" } |
| 87 |
end |
| 88 |
|
| 89 |
it 'sets the haproxy package' do |
| 90 |
subject.should contain_concat__fragment('haproxy-haproxy-base').with_content( |
| 91 |
%r{listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n}, |
| 92 |
) |
| 93 |
end |
| 94 |
end |
| 95 |
end |
| 96 |
end |
| 97 |
|
| 98 |
describe 'for linux operating systems' do |
| 99 |
['Debian', 'RedHat', 'Archlinux'].each do |osfamily| |
| 100 |
context "when on #{osfamily} family operatingsystems" do |
| 101 |
let(:facts) do |
| 102 |
{ os: { family: osfamily } }.merge default_facts |
| 103 |
end |
| 104 |
|
| 105 |
it 'sets up /etc/haproxy/haproxy.cfg as a concat resource' do |
| 106 |
subject.should contain_concat('/etc/haproxy/haproxy.cfg').with( |
| 107 |
'owner' => '0', |
| 108 |
'group' => '0', |
| 109 |
'mode' => '0640', |
| 110 |
) |
| 111 |
end |
| 112 |
|
| 113 |
it 'manages the chroot directory' do |
| 114 |
subject.should contain_file('/var/lib/haproxy').with( |
| 115 |
'ensure' => 'directory', |
| 116 |
'owner' => 'haproxy', |
| 117 |
'group' => 'haproxy', |
| 118 |
) |
| 119 |
end |
| 120 |
|
| 121 |
it 'contains a header concat fragment' do |
| 122 |
subject.should contain_concat__fragment('haproxy-00-header').with( |
| 123 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 124 |
'order' => '01', |
| 125 |
'content' => "# This file is managed by Puppet\n", |
| 126 |
) |
| 127 |
end |
| 128 |
|
| 129 |
it 'contains a haproxy-haproxy-base concat fragment' do |
| 130 |
subject.should contain_concat__fragment('haproxy-haproxy-base').with( |
| 131 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 132 |
'order' => '10', |
| 133 |
) |
| 134 |
end |
| 135 |
|
| 136 |
describe 'Base concat fragment contents' do |
| 137 |
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") } |
| 138 |
|
| 139 |
# C9936 C9937 |
| 140 |
it 'contains global and defaults sections' do |
| 141 |
contents.should include('global') |
| 142 |
contents.should include('defaults') |
| 143 |
end |
| 144 |
|
| 145 |
it 'logs to an ip address for local0' do |
| 146 |
contents.should be_any do |match| |
| 147 |
match =~ %r{ log \d+(\.\d+){3} local0} |
| 148 |
end |
| 149 |
end |
| 150 |
|
| 151 |
it 'specifies the default chroot' do |
| 152 |
contents.should include(' chroot /var/lib/haproxy') |
| 153 |
end |
| 154 |
|
| 155 |
it 'specifies the correct user' do |
| 156 |
contents.should include(' user haproxy') |
| 157 |
end |
| 158 |
|
| 159 |
it 'specifies the correct group' do |
| 160 |
contents.should include(' group haproxy') |
| 161 |
end |
| 162 |
|
| 163 |
it 'specifies the correct pidfile' do |
| 164 |
contents.should include(' pidfile /var/run/haproxy.pid') |
| 165 |
end |
| 166 |
end |
| 167 |
end |
| 168 |
|
| 169 |
context "when on #{osfamily} family operatingsystems without managing the service" do |
| 170 |
let(:facts) do |
| 171 |
{ os: { family: osfamily } }.merge default_facts |
| 172 |
end |
| 173 |
let(:params) do |
| 174 |
{ |
| 175 |
'service_ensure' => true, |
| 176 |
'package_ensure' => 'present', |
| 177 |
'package_name' => 'haproxy', |
| 178 |
'service_manage' => false |
| 179 |
} |
| 180 |
end |
| 181 |
|
| 182 |
it 'installs the haproxy package' do |
| 183 |
subject.should contain_package('haproxy').with( |
| 184 |
'ensure' => 'present', |
| 185 |
) |
| 186 |
end |
| 187 |
|
| 188 |
it 'does not manage the haproxy service' do |
| 189 |
subject.should_not contain_service('haproxy') |
| 190 |
end |
| 191 |
|
| 192 |
it 'sets up /etc/haproxy/haproxy.cfg as a concat resource' do |
| 193 |
subject.should contain_concat('/etc/haproxy/haproxy.cfg').with( |
| 194 |
'owner' => '0', |
| 195 |
'group' => '0', |
| 196 |
'mode' => '0640', |
| 197 |
) |
| 198 |
end |
| 199 |
|
| 200 |
it 'manages the chroot directory' do |
| 201 |
subject.should contain_file('/var/lib/haproxy').with( |
| 202 |
'ensure' => 'directory', |
| 203 |
) |
| 204 |
end |
| 205 |
|
| 206 |
it 'contains a header concat fragment' do |
| 207 |
subject.should contain_concat__fragment('haproxy-00-header').with( |
| 208 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 209 |
'order' => '01', |
| 210 |
'content' => "# This file is managed by Puppet\n", |
| 211 |
) |
| 212 |
end |
| 213 |
|
| 214 |
it 'contains a haproxy-base concat fragment' do |
| 215 |
subject.should contain_concat__fragment('haproxy-haproxy-base').with( |
| 216 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 217 |
'order' => '10', |
| 218 |
) |
| 219 |
end |
| 220 |
|
| 221 |
describe 'Base concat fragment contents' do |
| 222 |
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") } |
| 223 |
|
| 224 |
it 'contains global and defaults sections' do |
| 225 |
contents.should include('global') |
| 226 |
contents.should include('defaults') |
| 227 |
end |
| 228 |
|
| 229 |
it 'logs to an ip address for local0' do |
| 230 |
contents.should be_any do |match| |
| 231 |
match =~ %r{ log \d+(\.\d+){3} local0} |
| 232 |
end |
| 233 |
end |
| 234 |
|
| 235 |
it 'specifies the default chroot' do |
| 236 |
contents.should include(' chroot /var/lib/haproxy') |
| 237 |
end |
| 238 |
|
| 239 |
it 'specifies the correct user' do |
| 240 |
contents.should include(' user haproxy') |
| 241 |
end |
| 242 |
|
| 243 |
it 'specifies the correct group' do |
| 244 |
contents.should include(' group haproxy') |
| 245 |
end |
| 246 |
|
| 247 |
it 'specifies the correct pidfile' do |
| 248 |
contents.should include(' pidfile /var/run/haproxy.pid') |
| 249 |
end |
| 250 |
end |
| 251 |
end |
| 252 |
|
| 253 |
context "when on #{osfamily} family operatingsystems without managing the chroot directory" do |
| 254 |
let(:facts) do |
| 255 |
{ os: { family: osfamily } }.merge default_facts |
| 256 |
end |
| 257 |
let(:params) do |
| 258 |
{ |
| 259 |
'chroot_dir_manage' => false |
| 260 |
} |
| 261 |
end |
| 262 |
|
| 263 |
it 'does not manage the haproxy chroot directory' do |
| 264 |
subject.should_not contain_file('/var/lib/haproxy') |
| 265 |
end |
| 266 |
end |
| 267 |
|
| 268 |
context "when on #{osfamily} when specifying a restart_command" do |
| 269 |
let(:facts) do |
| 270 |
{ os: { family: osfamily } }.merge default_facts |
| 271 |
end |
| 272 |
let(:params) do |
| 273 |
{ |
| 274 |
'restart_command' => '/etc/init.d/haproxy reload', |
| 275 |
'service_manage' => true |
| 276 |
} |
| 277 |
end |
| 278 |
|
| 279 |
it 'sets the haproxy package' do |
| 280 |
subject.should contain_service('haproxy').with( |
| 281 |
'restart' => '/etc/init.d/haproxy reload', |
| 282 |
) |
| 283 |
end |
| 284 |
end |
| 285 |
end |
| 286 |
end |
| 287 |
end |
| 288 |
|
| 289 |
# haproxy::instance with 2nd instance and with non-standard service name. |
| 290 |
|
| 291 |
context 'with haproxy::instance with 2nd instance and with non-standard service name' do |
| 292 |
let(:title) { 'group1' } |
| 293 |
|
| 294 |
describe 'for OS-agnostic configuration' do |
| 295 |
['Debian', 'RedHat', 'Archlinux', 'FreeBSD'].each do |osfamily| |
| 296 |
context "when on #{osfamily} family operatingsystems" do |
| 297 |
let(:facts) do |
| 298 |
{ os: { family: osfamily } }.merge default_facts |
| 299 |
end |
| 300 |
let(:params) do |
| 301 |
{ |
| 302 |
'service_ensure' => 'running', |
| 303 |
'package_ensure' => 'present', |
| 304 |
'package_name' => 'customhaproxy', |
| 305 |
'service_manage' => true |
| 306 |
} |
| 307 |
end |
| 308 |
|
| 309 |
it 'installs the customhaproxy package' do |
| 310 |
subject.should contain_package('customhaproxy').with( |
| 311 |
'ensure' => 'present', |
| 312 |
) |
| 313 |
end |
| 314 |
|
| 315 |
it 'installs the customhaproxy service' do |
| 316 |
subject.should contain_service('haproxy-group1').with( |
| 317 |
'ensure' => 'running', 'enable' => 'true', |
| 318 |
'hasrestart' => 'true', 'hasstatus' => 'true' |
| 319 |
) |
| 320 |
end |
| 321 |
|
| 322 |
it 'does not install the haproxy package' do |
| 323 |
subject.should_not contain_package('haproxy').with( |
| 324 |
'title' => 'haproxy', |
| 325 |
) |
| 326 |
end |
| 327 |
|
| 328 |
it 'does not install the haproxy service' do |
| 329 |
subject.should_not contain_service('haproxy') |
| 330 |
end |
| 331 |
end |
| 332 |
|
| 333 |
# C9938 |
| 334 |
context "when on #{osfamily} when specifying custom content" do |
| 335 |
let(:facts) do |
| 336 |
{ os: { family: osfamily } }.merge default_facts |
| 337 |
end |
| 338 |
let(:params) do |
| 339 |
{ 'custom_fragment' => "listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n" } |
| 340 |
end |
| 341 |
|
| 342 |
it 'sets the haproxy-group1 package' do |
| 343 |
subject.should contain_concat__fragment('haproxy-group1-haproxy-base').with_content( |
| 344 |
%r{listen stats :9090\n mode http\n stats uri /\n stats auth puppet:puppet\n}, |
| 345 |
) |
| 346 |
end |
| 347 |
end |
| 348 |
end |
| 349 |
end |
| 350 |
|
| 351 |
describe 'for linux operating systems' do |
| 352 |
['Debian', 'RedHat', 'Archlinux'].each do |osfamily| |
| 353 |
context "when on #{osfamily} family operatingsystems" do |
| 354 |
let(:facts) do |
| 355 |
{ os: { family: osfamily } }.merge default_facts |
| 356 |
end |
| 357 |
|
| 358 |
it 'sets up /etc/haproxy-group1/haproxy-group1.cfg as a concat resource' do |
| 359 |
subject.should contain_concat('/etc/haproxy-group1/haproxy-group1.cfg').with( |
| 360 |
'owner' => '0', |
| 361 |
'group' => '0', |
| 362 |
'mode' => '0640', |
| 363 |
) |
| 364 |
end |
| 365 |
|
| 366 |
it 'manages the chroot directory' do |
| 367 |
subject.should contain_file('/var/lib/haproxy').with( |
| 368 |
'ensure' => 'directory', |
| 369 |
'owner' => 'haproxy', |
| 370 |
'group' => 'haproxy', |
| 371 |
) |
| 372 |
end |
| 373 |
|
| 374 |
it 'contains a header concat fragment' do |
| 375 |
subject.should contain_concat__fragment('haproxy-group1-00-header').with( |
| 376 |
'target' => '/etc/haproxy-group1/haproxy-group1.cfg', |
| 377 |
'order' => '01', |
| 378 |
'content' => "# This file is managed by Puppet\n", |
| 379 |
) |
| 380 |
end |
| 381 |
|
| 382 |
it 'contains a haproxy-group1-haproxy-base concat fragment' do |
| 383 |
subject.should contain_concat__fragment('haproxy-group1-haproxy-base').with( |
| 384 |
'target' => '/etc/haproxy-group1/haproxy-group1.cfg', |
| 385 |
'order' => '10', |
| 386 |
) |
| 387 |
end |
| 388 |
|
| 389 |
describe 'Base concat fragment contents' do |
| 390 |
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-group1-haproxy-base', 'content').split("\n") } |
| 391 |
|
| 392 |
# C9936 C9937 |
| 393 |
it 'contains global and defaults sections' do |
| 394 |
contents.should include('global') |
| 395 |
contents.should include('defaults') |
| 396 |
end |
| 397 |
|
| 398 |
it 'logs to an ip address for local0' do |
| 399 |
contents.should be_any do |match| |
| 400 |
match =~ %r{ log \d+(\.\d+){3} local0} |
| 401 |
end |
| 402 |
end |
| 403 |
|
| 404 |
it 'specifies the default chroot' do |
| 405 |
contents.should include(' chroot /var/lib/haproxy') |
| 406 |
end |
| 407 |
|
| 408 |
it 'specifies the correct user' do |
| 409 |
contents.should include(' user haproxy') |
| 410 |
end |
| 411 |
|
| 412 |
it 'specifies the correct group' do |
| 413 |
contents.should include(' group haproxy') |
| 414 |
end |
| 415 |
|
| 416 |
it 'specifies the correct pidfile' do |
| 417 |
contents.should include(' pidfile /var/run/haproxy.pid') |
| 418 |
end |
| 419 |
end |
| 420 |
end |
| 421 |
|
| 422 |
context "when on #{osfamily} family operatingsystems without managing the service" do |
| 423 |
let(:facts) do |
| 424 |
{ os: { family: osfamily } }.merge default_facts |
| 425 |
end |
| 426 |
let(:params) do |
| 427 |
{ |
| 428 |
'service_ensure' => true, |
| 429 |
'package_ensure' => 'present', |
| 430 |
'package_name' => 'customhaproxy', |
| 431 |
'service_manage' => false |
| 432 |
} |
| 433 |
end |
| 434 |
|
| 435 |
it 'installs the customhaproxy package' do |
| 436 |
subject.should contain_package('customhaproxy').with( |
| 437 |
'ensure' => 'present', |
| 438 |
) |
| 439 |
end |
| 440 |
|
| 441 |
it 'does not manage the customhaproxy service' do |
| 442 |
subject.should_not contain_service('haproxy-group1') |
| 443 |
end |
| 444 |
|
| 445 |
it 'sets up /etc/haproxy-group1/haproxy-group1.cfg as a concat resource' do |
| 446 |
subject.should contain_concat('/etc/haproxy-group1/haproxy-group1.cfg').with( |
| 447 |
'owner' => '0', |
| 448 |
'group' => '0', |
| 449 |
'mode' => '0640', |
| 450 |
) |
| 451 |
end |
| 452 |
|
| 453 |
it 'manages the chroot directory' do |
| 454 |
subject.should contain_file('/var/lib/haproxy').with( |
| 455 |
'ensure' => 'directory', |
| 456 |
) |
| 457 |
end |
| 458 |
|
| 459 |
it 'contains a header concat fragment' do |
| 460 |
subject.should contain_concat__fragment('haproxy-group1-00-header').with( |
| 461 |
'target' => '/etc/haproxy-group1/haproxy-group1.cfg', |
| 462 |
'order' => '01', |
| 463 |
'content' => "# This file is managed by Puppet\n", |
| 464 |
) |
| 465 |
end |
| 466 |
|
| 467 |
it 'contains a haproxy-group1-haproxy-base concat fragment' do |
| 468 |
subject.should contain_concat__fragment('haproxy-group1-haproxy-base').with( |
| 469 |
'target' => '/etc/haproxy-group1/haproxy-group1.cfg', |
| 470 |
'order' => '10', |
| 471 |
) |
| 472 |
end |
| 473 |
|
| 474 |
describe 'Base concat fragment contents' do |
| 475 |
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-group1-haproxy-base', 'content').split("\n") } |
| 476 |
|
| 477 |
it 'contains global and defaults sections' do |
| 478 |
contents.should include('global') |
| 479 |
contents.should include('defaults') |
| 480 |
end |
| 481 |
|
| 482 |
it 'logs to an ip address for local0' do |
| 483 |
contents.should be_any do |match| |
| 484 |
match =~ %r{ log \d+(\.\d+){3} local0} |
| 485 |
end |
| 486 |
end |
| 487 |
|
| 488 |
it 'specifies the default chroot' do |
| 489 |
contents.should include(' chroot /var/lib/haproxy') |
| 490 |
end |
| 491 |
|
| 492 |
it 'specifies the correct user' do |
| 493 |
contents.should include(' user haproxy') |
| 494 |
end |
| 495 |
|
| 496 |
it 'specifies the correct group' do |
| 497 |
contents.should include(' group haproxy') |
| 498 |
end |
| 499 |
|
| 500 |
it 'specifies the correct pidfile' do |
| 501 |
contents.should include(' pidfile /var/run/haproxy.pid') |
| 502 |
end |
| 503 |
end |
| 504 |
end |
| 505 |
|
| 506 |
context "when on #{osfamily} when specifying a restart_command" do |
| 507 |
let(:facts) do |
| 508 |
{ os: { family: osfamily } }.merge default_facts |
| 509 |
end |
| 510 |
let(:params) do |
| 511 |
{ |
| 512 |
'restart_command' => '/etc/init.d/haproxy-group1 reload', |
| 513 |
'service_manage' => true |
| 514 |
} |
| 515 |
end |
| 516 |
|
| 517 |
it 'sets the customhaproxy package' do |
| 518 |
subject.should contain_service('haproxy-group1').with( |
| 519 |
'restart' => '/etc/init.d/haproxy-group1 reload', |
| 520 |
) |
| 521 |
end |
| 522 |
end |
| 523 |
end |
| 524 |
end |
| 525 |
|
| 526 |
# FreeBSD: haproxy::instance with service name "haproxy". |
| 527 |
|
| 528 |
describe 'for freebsd' do |
| 529 |
let(:title) { 'haproxy' } |
| 530 |
|
| 531 |
context 'when on freebsd family operatingsystems' do |
| 532 |
let(:facts) do |
| 533 |
{ os: { family: 'FreeBSD' } }.merge default_facts |
| 534 |
end |
| 535 |
|
| 536 |
it 'sets up /usr/local/etc/haproxy.conf as a concat resource' do |
| 537 |
subject.should contain_concat('/usr/local/etc/haproxy.conf').with( |
| 538 |
'owner' => '0', |
| 539 |
'group' => '0', |
| 540 |
'mode' => '0640', |
| 541 |
) |
| 542 |
end |
| 543 |
|
| 544 |
it 'manages the chroot directory' do |
| 545 |
subject.should contain_file('/usr/local/haproxy').with( |
| 546 |
'ensure' => 'directory', |
| 547 |
) |
| 548 |
end |
| 549 |
|
| 550 |
it 'contains a header concat fragment' do |
| 551 |
subject.should contain_concat__fragment('haproxy-00-header').with( |
| 552 |
'target' => '/usr/local/etc/haproxy.conf', |
| 553 |
'order' => '01', |
| 554 |
'content' => "# This file is managed by Puppet\n", |
| 555 |
) |
| 556 |
end |
| 557 |
|
| 558 |
it 'contains a haproxy-base concat fragment' do |
| 559 |
subject.should contain_concat__fragment('haproxy-haproxy-base').with( |
| 560 |
'target' => '/usr/local/etc/haproxy.conf', |
| 561 |
'order' => '10', |
| 562 |
) |
| 563 |
end |
| 564 |
|
| 565 |
describe 'Base concat fragment contents' do |
| 566 |
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") } |
| 567 |
|
| 568 |
# C9936 C9937 |
| 569 |
it 'contains global and defaults sections' do |
| 570 |
contents.should include('global') |
| 571 |
contents.should include('defaults') |
| 572 |
end |
| 573 |
|
| 574 |
it 'logs to an ip address for local0' do |
| 575 |
contents.should be_any do |match| |
| 576 |
match =~ %r{ log \d+(\.\d+){3} local0} |
| 577 |
end |
| 578 |
end |
| 579 |
|
| 580 |
it 'specifies the default chroot' do |
| 581 |
contents.should include(' chroot /usr/local/haproxy') |
| 582 |
end |
| 583 |
|
| 584 |
it 'specifies the correct pidfile' do |
| 585 |
contents.should include(' pidfile /var/run/haproxy.pid') |
| 586 |
end |
| 587 |
end |
| 588 |
end |
| 589 |
|
| 590 |
context 'when on freebsd family operatingsystems without managing the service' do |
| 591 |
let(:facts) do |
| 592 |
{ os: { family: 'FreeBSD' } }.merge default_facts |
| 593 |
end |
| 594 |
let(:params) do |
| 595 |
{ |
| 596 |
'service_ensure' => true, |
| 597 |
'package_ensure' => 'present', |
| 598 |
'package_name' => 'haproxy', |
| 599 |
'service_manage' => false |
| 600 |
} |
| 601 |
end |
| 602 |
|
| 603 |
it 'installs the haproxy package' do |
| 604 |
subject.should contain_package('haproxy').with( |
| 605 |
'ensure' => 'present', |
| 606 |
) |
| 607 |
end |
| 608 |
|
| 609 |
it 'does not manage the haproxy service' do |
| 610 |
subject.should_not contain_service('haproxy') |
| 611 |
end |
| 612 |
|
| 613 |
it 'sets up /usr/local/etc/haproxy.conf as a concat resource' do |
| 614 |
subject.should contain_concat('/usr/local/etc/haproxy.conf').with( |
| 615 |
'owner' => '0', |
| 616 |
'group' => '0', |
| 617 |
'mode' => '0640', |
| 618 |
) |
| 619 |
end |
| 620 |
|
| 621 |
it 'manages the chroot directory' do |
| 622 |
subject.should contain_file('/usr/local/haproxy').with( |
| 623 |
'ensure' => 'directory', |
| 624 |
) |
| 625 |
end |
| 626 |
|
| 627 |
it 'contains a header concat fragment' do |
| 628 |
subject.should contain_concat__fragment('haproxy-00-header').with( |
| 629 |
'target' => '/usr/local/etc/haproxy.conf', |
| 630 |
'order' => '01', |
| 631 |
'content' => "# This file is managed by Puppet\n", |
| 632 |
) |
| 633 |
end |
| 634 |
|
| 635 |
it 'contains a haproxy-base concat fragment' do |
| 636 |
subject.should contain_concat__fragment('haproxy-haproxy-base').with( |
| 637 |
'target' => '/usr/local/etc/haproxy.conf', |
| 638 |
'order' => '10', |
| 639 |
) |
| 640 |
end |
| 641 |
|
| 642 |
describe 'Base concat fragment contents' do |
| 643 |
let(:contents) { param_value(catalogue, 'concat::fragment', 'haproxy-haproxy-base', 'content').split("\n") } |
| 644 |
|
| 645 |
it 'contains global and defaults sections' do |
| 646 |
contents.should include('global') |
| 647 |
contents.should include('defaults') |
| 648 |
end |
| 649 |
|
| 650 |
it 'logs to an ip address for local0' do |
| 651 |
contents.should be_any do |match| |
| 652 |
match =~ %r{ log \d+(\.\d+){3} local0} |
| 653 |
end |
| 654 |
end |
| 655 |
|
| 656 |
it 'specifies the default chroot' do |
| 657 |
contents.should include(' chroot /usr/local/haproxy') |
| 658 |
end |
| 659 |
|
| 660 |
it 'specifies the correct pidfile' do |
| 661 |
contents.should include(' pidfile /var/run/haproxy.pid') |
| 662 |
end |
| 663 |
end |
| 664 |
end |
| 665 |
|
| 666 |
context 'when on freebsd when specifying a restart_command' do |
| 667 |
let(:facts) do |
| 668 |
{ os: { family: 'FreeBSD' } }.merge default_facts |
| 669 |
end |
| 670 |
let(:params) do |
| 671 |
{ |
| 672 |
'restart_command' => '/usr/local/etc/rc.d/haproxy reload', |
| 673 |
'service_manage' => true |
| 674 |
} |
| 675 |
end |
| 676 |
|
| 677 |
it 'sets the haproxy package' do |
| 678 |
subject.should contain_service('haproxy').with( |
| 679 |
'restart' => '/usr/local/etc/rc.d/haproxy reload', |
| 680 |
) |
| 681 |
end |
| 682 |
end |
| 683 |
end |
| 684 |
|
| 685 |
# OS-specific configurations: |
| 686 |
|
| 687 |
describe 'for OS-specific configuration' do |
| 688 |
context 'when only on Debian family operatingsystems' do |
| 689 |
let(:facts) do |
| 690 |
{ os: { family: 'Debian' } }.merge default_facts |
| 691 |
end |
| 692 |
|
| 693 |
it 'manages haproxy service defaults' do |
| 694 |
subject.should contain_file('/etc/default/haproxy-group1') |
| 695 |
verify_contents(catalogue, '/etc/default/haproxy-group1', ['ENABLED=1']) |
| 696 |
end |
| 697 |
end |
| 698 |
|
| 699 |
context 'when only on Debian family operatingsystems with custom /etc/default' do |
| 700 |
let(:facts) do |
| 701 |
{ os: { family: 'Debian' } }.merge default_facts |
| 702 |
end |
| 703 |
let(:params) do |
| 704 |
{ |
| 705 |
'service_options' => 'stuff' |
| 706 |
} |
| 707 |
end |
| 708 |
|
| 709 |
it 'manages haproxy service defaults' do |
| 710 |
subject.should contain_file('/etc/default/haproxy-group1') |
| 711 |
verify_contents(catalogue, '/etc/default/haproxy-group1', ['stuff']) |
| 712 |
end |
| 713 |
end |
| 714 |
|
| 715 |
context 'when only on RedHat family operatingsystems' do |
| 716 |
let(:facts) do |
| 717 |
{ os: { family: 'RedHat' } }.merge default_facts |
| 718 |
end |
| 719 |
|
| 720 |
it 'manages haproxy sysconfig options' do |
| 721 |
subject.should contain_file('/etc/sysconfig/haproxy-group1') |
| 722 |
verify_contents(catalogue, '/etc/sysconfig/haproxy-group1', ['OPTIONS=""']) |
| 723 |
end |
| 724 |
end |
| 725 |
end |
| 726 |
end |
| 727 |
|
| 728 |
# Unsupported OSs: |
| 729 |
|
| 730 |
context 'when on unsupported operatingsystems' do |
| 731 |
let(:title) { 'haproxy' } |
| 732 |
let(:facts) do |
| 733 |
{ os: { family: 'windows' } }.merge default_facts |
| 734 |
end |
| 735 |
|
| 736 |
it do |
| 737 |
expect { |
| 738 |
is_expected.to contain_service('haproxy') |
| 739 |
}.to raise_error(Puppet::Error, %r{operating system is not supported with the haproxy module}) |
| 740 |
end |
| 741 |
end |
| 742 |
# rubocop:enable RSpec/NestedGroups |
| 743 |
end |