| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
require 'spec_helper' |
| 4 |
|
| 5 |
describe 'haproxy::balancermember' do |
| 6 |
let(:pre_condition) { 'include haproxy' } |
| 7 |
let(:title) { 'tyler' } |
| 8 |
let(:facts) do |
| 9 |
{ |
| 10 |
networking: { |
| 11 |
ip: '1.1.1.1', |
| 12 |
hostname: 'dero' |
| 13 |
}, |
| 14 |
os: { |
| 15 |
family: 'Redhat' |
| 16 |
}, |
| 17 |
concat_basedir: '/dne' |
| 18 |
} |
| 19 |
end |
| 20 |
|
| 21 |
context 'with a single balancermember option' do |
| 22 |
let(:params) do |
| 23 |
{ |
| 24 |
name: 'tyler', |
| 25 |
listening_service: 'croy', |
| 26 |
ports: 18_140, |
| 27 |
options: 'check' |
| 28 |
} |
| 29 |
end |
| 30 |
|
| 31 |
it { |
| 32 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 33 |
'order' => '20-croy-01-tyler', |
| 34 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 35 |
'content' => " server dero 1.1.1.1:18140 check\n", |
| 36 |
) |
| 37 |
} |
| 38 |
|
| 39 |
context 'with stringy ports' do |
| 40 |
let(:params) do |
| 41 |
super().merge(ports: '18140') |
| 42 |
end |
| 43 |
|
| 44 |
it { |
| 45 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 46 |
'order' => '20-croy-01-tyler', |
| 47 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 48 |
'content' => " server dero 1.1.1.1:18140 check\n", |
| 49 |
) |
| 50 |
} |
| 51 |
end |
| 52 |
end |
| 53 |
|
| 54 |
context 'with multiple balancermember options' do |
| 55 |
let(:params) do |
| 56 |
{ |
| 57 |
name: 'tyler', |
| 58 |
listening_service: 'croy', |
| 59 |
ports: 18_140, |
| 60 |
options: ['check', 'close'] |
| 61 |
} |
| 62 |
end |
| 63 |
|
| 64 |
it { |
| 65 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 66 |
'order' => '20-croy-01-tyler', |
| 67 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 68 |
'content' => " server dero 1.1.1.1:18140 check close\n", |
| 69 |
) |
| 70 |
} |
| 71 |
end |
| 72 |
|
| 73 |
context 'with cookie and multiple balancermember options' do |
| 74 |
let(:params) do |
| 75 |
{ |
| 76 |
name: 'tyler', |
| 77 |
listening_service: 'croy', |
| 78 |
ports: 18_140, |
| 79 |
options: ['check', 'close'], |
| 80 |
define_cookies: true |
| 81 |
} |
| 82 |
end |
| 83 |
|
| 84 |
it { |
| 85 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 86 |
'order' => '20-croy-01-tyler', |
| 87 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 88 |
'content' => " server dero 1.1.1.1:18140 cookie dero check close\n", |
| 89 |
) |
| 90 |
} |
| 91 |
end |
| 92 |
|
| 93 |
context 'with verifyhost' do |
| 94 |
let(:params) do |
| 95 |
{ |
| 96 |
name: 'tyler', |
| 97 |
listening_service: 'croy', |
| 98 |
ports: 18_140, |
| 99 |
options: ['check', 'close'], |
| 100 |
verifyhost: true |
| 101 |
} |
| 102 |
end |
| 103 |
|
| 104 |
it { |
| 105 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 106 |
'order' => '20-croy-01-tyler', |
| 107 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 108 |
'content' => " server dero 1.1.1.1:18140 check close verifyhost dero\n", |
| 109 |
) |
| 110 |
} |
| 111 |
end |
| 112 |
|
| 113 |
context 'with multiple servers' do |
| 114 |
let(:params) do |
| 115 |
{ |
| 116 |
name: 'tyler', |
| 117 |
listening_service: 'croy', |
| 118 |
ports: 18_140, |
| 119 |
server_names: ['server01', 'server02'], |
| 120 |
ipaddresses: ['192.168.56.200', '192.168.56.201'], |
| 121 |
options: ['check'] |
| 122 |
} |
| 123 |
end |
| 124 |
|
| 125 |
it { |
| 126 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 127 |
'order' => '20-croy-01-tyler', |
| 128 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 129 |
'content' => " server server01 192.168.56.200:18140 check\n server server02 192.168.56.201:18140 check\n", |
| 130 |
) |
| 131 |
} |
| 132 |
end |
| 133 |
|
| 134 |
context 'with multiple servers and multiple ports' do |
| 135 |
let(:params) do |
| 136 |
{ |
| 137 |
name: 'tyler', |
| 138 |
listening_service: 'croy', |
| 139 |
ports: [18_140, 18_150], |
| 140 |
server_names: ['server01', 'server02'], |
| 141 |
ipaddresses: ['192.168.56.200', '192.168.56.201'], |
| 142 |
options: ['check'] |
| 143 |
} |
| 144 |
end |
| 145 |
|
| 146 |
it { |
| 147 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 148 |
'order' => '20-croy-01-tyler', |
| 149 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 150 |
'content' => " server server01 192.168.56.200:18140 check\n server server01 192.168.56.200:18150 check\n server server02 192.168.56.201:18140 check\n server server02 192.168.56.201:18150 check\n", # rubocop:disable Layout/LineLength |
| 151 |
) |
| 152 |
} |
| 153 |
|
| 154 |
context 'with stringy ports' do |
| 155 |
let(:params) do |
| 156 |
super().merge(ports: ['18140', '18150']) |
| 157 |
end |
| 158 |
|
| 159 |
it { |
| 160 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 161 |
'order' => '20-croy-01-tyler', |
| 162 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 163 |
'content' => " server server01 192.168.56.200:18140 check\n server server01 192.168.56.200:18150 check\n server server02 192.168.56.201:18140 check\n server server02 192.168.56.201:18150 check\n", # rubocop:disable Layout/LineLength |
| 164 |
) |
| 165 |
} |
| 166 |
end |
| 167 |
end |
| 168 |
|
| 169 |
context 'with multiple servers and no port' do |
| 170 |
let(:params) do |
| 171 |
{ |
| 172 |
name: 'tyler', |
| 173 |
listening_service: 'croy', |
| 174 |
server_names: ['server01', 'server02'], |
| 175 |
ipaddresses: ['192.168.56.200', '192.168.56.201'], |
| 176 |
options: ['check'] |
| 177 |
} |
| 178 |
end |
| 179 |
|
| 180 |
it { |
| 181 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 182 |
'order' => '20-croy-01-tyler', |
| 183 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 184 |
'content' => " server server01 192.168.56.200 check\n server server02 192.168.56.201 check\n", |
| 185 |
) |
| 186 |
} |
| 187 |
end |
| 188 |
|
| 189 |
context 'when a non-default config file is used' do |
| 190 |
let(:pre_condition) { 'class { "haproxy": config_file => "/etc/non-default.cfg" }' } |
| 191 |
let(:params) do |
| 192 |
{ |
| 193 |
name: 'haproxy', |
| 194 |
listening_service: 'baz', |
| 195 |
server_names: ['server01', 'server02'], |
| 196 |
ipaddresses: ['10.0.0.1', '10.0.0.2'], |
| 197 |
options: ['check'] |
| 198 |
} |
| 199 |
end |
| 200 |
|
| 201 |
it { |
| 202 |
is_expected.to contain_concat__fragment('haproxy-baz_balancermember_haproxy').with( |
| 203 |
'order' => '20-baz-01-haproxy', |
| 204 |
'target' => '/etc/non-default.cfg', |
| 205 |
'content' => " server server01 10.0.0.1 check\n server server02 10.0.0.2 check\n", |
| 206 |
) |
| 207 |
} |
| 208 |
end |
| 209 |
|
| 210 |
context 'with weight' do |
| 211 |
let(:params) do |
| 212 |
{ |
| 213 |
name: 'tyler', |
| 214 |
listening_service: 'croy', |
| 215 |
ports: 18_140, |
| 216 |
options: 'check', |
| 217 |
weight: '100' |
| 218 |
} |
| 219 |
end |
| 220 |
|
| 221 |
it { |
| 222 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 223 |
'order' => '20-croy-01-tyler', |
| 224 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 225 |
'content' => " server dero 1.1.1.1:18140 check weight 100\n", |
| 226 |
) |
| 227 |
} |
| 228 |
end |
| 229 |
|
| 230 |
context 'with server-template' do |
| 231 |
let(:params) do |
| 232 |
{ |
| 233 |
name: 'tyler', |
| 234 |
type: 'server-template', |
| 235 |
listening_service: 'croy', |
| 236 |
fqdn: 'myserver.example.local' |
| 237 |
} |
| 238 |
end |
| 239 |
|
| 240 |
it { |
| 241 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 242 |
'order' => '20-croy-01-tyler', |
| 243 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 244 |
'content' => " server-template server 1 myserver.example.local \n", |
| 245 |
) |
| 246 |
} |
| 247 |
end |
| 248 |
|
| 249 |
context 'with server-template with port' do |
| 250 |
let(:params) do |
| 251 |
{ |
| 252 |
name: 'tyler', |
| 253 |
type: 'server-template', |
| 254 |
listening_service: 'croy', |
| 255 |
fqdn: 'myserver.example.local', |
| 256 |
port: '8080' |
| 257 |
} |
| 258 |
end |
| 259 |
|
| 260 |
it { |
| 261 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 262 |
'order' => '20-croy-01-tyler', |
| 263 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 264 |
'content' => " server-template server 1 myserver.example.local:8080 \n", |
| 265 |
) |
| 266 |
} |
| 267 |
end |
| 268 |
|
| 269 |
context 'with server-template with port with num amount' do |
| 270 |
let(:params) do |
| 271 |
{ |
| 272 |
name: 'tyler', |
| 273 |
type: 'server-template', |
| 274 |
listening_service: 'croy', |
| 275 |
fqdn: 'myserver.example.local', |
| 276 |
port: '8080', |
| 277 |
amount: '5' |
| 278 |
} |
| 279 |
end |
| 280 |
|
| 281 |
it { |
| 282 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 283 |
'order' => '20-croy-01-tyler', |
| 284 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 285 |
'content' => " server-template server 5 myserver.example.local:8080 \n", |
| 286 |
) |
| 287 |
} |
| 288 |
end |
| 289 |
|
| 290 |
context 'with server-template with port with range amount' do |
| 291 |
let(:params) do |
| 292 |
{ |
| 293 |
name: 'tyler', |
| 294 |
type: 'server-template', |
| 295 |
listening_service: 'croy', |
| 296 |
fqdn: 'myserver.example.local', |
| 297 |
port: '8080', |
| 298 |
amount: '1-10' |
| 299 |
} |
| 300 |
end |
| 301 |
|
| 302 |
it { |
| 303 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 304 |
'order' => '20-croy-01-tyler', |
| 305 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 306 |
'content' => " server-template server 1-10 myserver.example.local:8080 \n", |
| 307 |
) |
| 308 |
} |
| 309 |
end |
| 310 |
|
| 311 |
context 'with server-template with port with range amount with server prefix' do |
| 312 |
let(:params) do |
| 313 |
{ |
| 314 |
name: 'tyler', |
| 315 |
type: 'server-template', |
| 316 |
listening_service: 'croy', |
| 317 |
fqdn: 'myserver.example.local', |
| 318 |
port: '8080', |
| 319 |
amount: '1-10', |
| 320 |
prefix: 'srv' |
| 321 |
} |
| 322 |
end |
| 323 |
|
| 324 |
it { |
| 325 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 326 |
'order' => '20-croy-01-tyler', |
| 327 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 328 |
'content' => " server-template srv 1-10 myserver.example.local:8080 \n", |
| 329 |
) |
| 330 |
} |
| 331 |
end |
| 332 |
|
| 333 |
context 'with server-template with port with range amount with server prefix with options' do |
| 334 |
let(:params) do |
| 335 |
{ |
| 336 |
name: 'tyler', |
| 337 |
type: 'server-template', |
| 338 |
listening_service: 'croy', |
| 339 |
fqdn: 'myserver.example.local', |
| 340 |
port: '8080', |
| 341 |
amount: '1-10', |
| 342 |
prefix: 'srv', |
| 343 |
options: 'check' |
| 344 |
} |
| 345 |
end |
| 346 |
|
| 347 |
it { |
| 348 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 349 |
'order' => '20-croy-01-tyler', |
| 350 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 351 |
'content' => " server-template srv 1-10 myserver.example.local:8080 check\n", |
| 352 |
) |
| 353 |
} |
| 354 |
end |
| 355 |
|
| 356 |
context 'with server-template with port with range amount with server prefix with multiple options' do |
| 357 |
let(:params) do |
| 358 |
{ |
| 359 |
name: 'tyler', |
| 360 |
type: 'server-template', |
| 361 |
listening_service: 'croy', |
| 362 |
fqdn: 'myserver.example.local', |
| 363 |
port: '8080', |
| 364 |
amount: '1-10', |
| 365 |
prefix: 'srv', |
| 366 |
options: ['check', 'close'] |
| 367 |
} |
| 368 |
end |
| 369 |
|
| 370 |
it { |
| 371 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 372 |
'order' => '20-croy-01-tyler', |
| 373 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 374 |
'content' => " server-template srv 1-10 myserver.example.local:8080 check close\n", |
| 375 |
) |
| 376 |
} |
| 377 |
end |
| 378 |
|
| 379 |
context 'with server-template with port with range amount with server prefix with options with weight' do |
| 380 |
let(:params) do |
| 381 |
{ |
| 382 |
name: 'tyler', |
| 383 |
type: 'server-template', |
| 384 |
listening_service: 'croy', |
| 385 |
fqdn: 'myserver.example.local', |
| 386 |
port: '8080', |
| 387 |
amount: '1-10', |
| 388 |
prefix: 'srv', |
| 389 |
options: 'check', |
| 390 |
weight: 100 |
| 391 |
} |
| 392 |
end |
| 393 |
|
| 394 |
it { |
| 395 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 396 |
'order' => '20-croy-01-tyler', |
| 397 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 398 |
'content' => " server-template srv 1-10 myserver.example.local:8080 check weight 100\n", |
| 399 |
) |
| 400 |
} |
| 401 |
end |
| 402 |
|
| 403 |
context 'with server-template with port with range amount with server prefix with options with weight with cookies' do |
| 404 |
let(:params) do |
| 405 |
{ |
| 406 |
name: 'tyler', |
| 407 |
type: 'server-template', |
| 408 |
listening_service: 'croy', |
| 409 |
fqdn: 'myserver.example.local', |
| 410 |
port: '8080', |
| 411 |
amount: '1-10', |
| 412 |
prefix: 'srv', |
| 413 |
options: 'check', |
| 414 |
weight: 100, |
| 415 |
define_cookies: true |
| 416 |
} |
| 417 |
end |
| 418 |
|
| 419 |
it { |
| 420 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 421 |
'order' => '20-croy-01-tyler', |
| 422 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 423 |
'content' => " server-template srv 1-10 myserver.example.local:8080 cookie myserver.example.local check weight 100\n", |
| 424 |
) |
| 425 |
} |
| 426 |
end |
| 427 |
|
| 428 |
context 'with server-template with port with range amount with server prefix with options with weight with cookies with verifyhost' do |
| 429 |
let(:params) do |
| 430 |
{ |
| 431 |
name: 'tyler', |
| 432 |
type: 'server-template', |
| 433 |
listening_service: 'croy', |
| 434 |
fqdn: 'myserver.example.local', |
| 435 |
port: '8080', |
| 436 |
amount: '1-10', |
| 437 |
prefix: 'srv', |
| 438 |
options: 'check', |
| 439 |
weight: 100, |
| 440 |
define_cookies: true, |
| 441 |
verifyhost: true |
| 442 |
} |
| 443 |
end |
| 444 |
|
| 445 |
it { |
| 446 |
is_expected.to contain_concat__fragment('haproxy-croy_balancermember_tyler').with( |
| 447 |
'order' => '20-croy-01-tyler', |
| 448 |
'target' => '/etc/haproxy/haproxy.cfg', |
| 449 |
'content' => " server-template srv 1-10 myserver.example.local:8080 cookie myserver.example.local check verifyhost myserver.example.local weight 100\n", |
| 450 |
) |
| 451 |
} |
| 452 |
end |
| 453 |
end |