Debian Codegraph @

spec/acceptance/frontbackend_spec.rb

raw
1 # frozen_string_literal: true
2
3 require 'spec_helper_acceptance'
4
5 describe 'frontend backend defines' do
6 pp_one = <<-PUPPETCODE
7 class { 'haproxy': }
8 haproxy::frontend { 'app00':
9 ipaddress => $facts['networking']['interfaces']['lo']['ip'],
10 mode => 'http',
11 ports => '5555',
12 options => { 'default_backend' => 'app00' },
13 }
14 haproxy::backend { 'app00':
15 collect_exported => false,
16 options => { 'mode' => 'http' },
17 }
18 haproxy::balancermember { 'port 5556':
19 listening_service => 'app00',
20 server_names => 'test00.example.com',
21 ports => '5556',
22 }
23 haproxy::balancermember { 'port 5557':
24 listening_service => 'app00',
25 server_names => 'test01.example.com',
26 ports => '5557',
27 }
28 PUPPETCODE
29 it 'is able to configure the frontend/backend with puppet' do
30 retry_on_error_matching do
31 apply_manifest(pp_one, catch_failures: true)
32 end
33 end
34
35 # This is not great since it depends on the ordering served by the load
36 # balancer. Something with retries would be better.
37 # C9945
38 it 'does a curl against the LB to make sure it gets a response from each port' do
39 response_connection = run_shell('curl localhost:5555').stdout.chomp
40 expect(response_connection).to match(%r{Response on 555(6|7)})
41 if response_connection == 'Response on 5556'
42 expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5557})
43 else
44 expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556})
45 end
46 end
47
48 pp_two = <<-PUPPETCODE
49 class { 'haproxy': }
50 haproxy::frontend { 'app00':
51 ipaddress => $facts['networking']['interfaces']['lo']['ip'],
52 mode => 'http',
53 ports => '5555',
54 options => { 'default_backend' => 'app00' },
55 }
56 haproxy::backend { 'app00':
57 collect_exported => false,
58 options => { 'mode' => 'http' },
59 }
60 haproxy::balancermember { 'port 5556':
61 listening_service => 'app00',
62 server_names => 'test00.example.com',
63 ports => '5556',
64 }
65 haproxy::balancermember { 'port 5557':
66 listening_service => 'app00',
67 server_names => 'test01.example.com',
68 ports => '5558',
69 }
70 PUPPETCODE
71 it 'is able to configure the frontend/backend with one node up' do
72 retry_on_error_matching do
73 apply_manifest(pp_two, catch_failures: true)
74 end
75 end
76
77 # C9951
78 it 'does a curl against the LB to make sure it gets a response from each port #onenodeup' do
79 expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556})
80 expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556})
81 end
82
83 pp_three = <<-PUPPETCODE
84 class { 'haproxy': }
85 haproxy::frontend { 'app0':
86 bind =>
87 { '127.0.0.1:5555' => [] }
88 ,
89 }
90 PUPPETCODE
91 it 'having no address set but setting bind' do
92 retry_on_error_matching do
93 apply_manifest(pp_three, catch_failures: true)
94 end
95 end
96 end