File: basic_spec.rb

package info (click to toggle)
puppet-module-puppetlabs-haproxy 8.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 816 kB
  • sloc: ruby: 3,979; sh: 14; makefile: 4
file content (203 lines) | stat: -rw-r--r-- 5,708 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# frozen_string_literal: true

require 'spec_helper_acceptance'

# C9708 C9709 WONTFIX
describe 'configuring haproxy' do
  # C9961
  describe 'not managing the service' do
    pp_one = <<-PUPPETCODE
      class { 'haproxy':
        service_manage => false,
      }
      haproxy::listen { 'stats':
        ipaddress => '127.0.0.1',
        ports     => ['9090','9091'],
        options   => {
          'mode'  => 'http',
          'stats' => ['uri /','auth puppet:puppet'],
        },
      }
      haproxy::listen { 'test00':
        ipaddress => '127.0.0.1',
        ports     => '80',
      }
    PUPPETCODE
    it 'does not listen on any ports' do
      retry_on_error_matching do
        apply_manifest(pp_one, catch_failures: true)
      end
    end

    ['9090', '9091'].each do |port|
      describe port(port) do
        it { is_expected.not_to be_listening }
      end
    end
  end

  describe 'configuring haproxy load balancing' do
    describe 'multiple ports' do
      pp_two = <<-PUPPETCODE
        class { 'haproxy': }
        haproxy::listen { 'stats':
          ipaddress => '127.0.0.1',
          ports     => [9090, 9091],
          mode      => 'http',
          options   => { 'stats' => ['uri /','auth puppet:puppet'], },
        }
      PUPPETCODE
      it 'is able to listen on an array of ports' do
        retry_on_error_matching do
          apply_manifest(pp_two, catch_failures: true)
        end
      end

      ['9090', '9091'].each do |port|
        it "port #{port} has stats listening on each port" do
          run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
            expect(r.stdout).to contain %r{HAProxy}
            expect(r.exit_code).to eq 0
          end
        end
      end
    end

    describe 'multiple ports as strings' do
      pp_two = <<-PUPPETCODE
        class { 'haproxy': }
        haproxy::listen { 'stats':
          ipaddress => '127.0.0.1',
          ports     => ['9090','9091'],
          mode      => 'http',
          options   => { 'stats' => ['uri /','auth puppet:puppet'], },
        }
      PUPPETCODE
      it 'is able to listen on an array of ports' do
        retry_on_error_matching do
          apply_manifest(pp_two, catch_failures: true)
        end
      end

      ['9090', '9091'].each do |port|
        it "port #{port} has stats listening on each port" do
          run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
            expect(r.stdout).to contain %r{HAProxy}
            expect(r.exit_code).to eq 0
          end
        end
      end
    end

    describe 'with sort_options_alphabetic false' do
      pp_three = <<-PUPPETCODE
        class { 'haproxy::globals':
          sort_options_alphabetic => false,
        }
        class { 'haproxy': }
        haproxy::listen { 'stats':
          ipaddress => '127.0.0.1',
          ports     => [9090,9091],
          mode      => 'http',
          options   => { 'stats' => ['uri /','auth puppet:puppet'], },
        }
      PUPPETCODE

      it 'starts' do
        retry_on_error_matching do
          apply_manifest(pp_three, catch_failures: true)
        end
      end

      ['9090', '9091'].each do |port|
        it "port #{port} has stats listening on each port" do
          run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
            expect(r.stdout).to contain %r{HAProxy}
            expect(r.exit_code).to eq 0
          end
        end
      end
    end

    describe 'when "httpchk" option is defined and $sort_options_aphabetic => true' do
      pp_httpchk_option = <<-PUPPETCODE
      class { 'haproxy::globals':
        sort_options_alphabetic => true,
      }
      class { 'haproxy': }
      haproxy::listen { 'stats':
        ipaddress => '127.0.0.1',
        ports     => [9091],
        mode      => 'http',
      }
      haproxy::backend { 'servers':
        mode => 'http',
        sort_options_alphabetic => true,
        options => {
          'option'  => [
            'httpchk',
          ],
          'http-check' => 'disable-on-404',
          'server' => [
              'srv1 127.0.0.1:9091 check',
          ],
        },
      }
      PUPPETCODE

      it 'overrides $sort_options_aphabetic to false and warn' do
        apply_manifest(pp_httpchk_option, catch_failures: true) do |r|
          expect(r.stderr).to contain %r{Overriding\sthe\svalue\sof\s\$sort_options_alphabetic\sto\s"false"\sdue\sto\s"httpchk"\soption\sdefined}
        end
      end

      describe file('/etc/haproxy/haproxy.cfg') do
        its(:content) do
          is_expected.to match %r{backend\sservers\n\s+mode\shttp\n\s+option\shttpchk\n\s+http-check\s+disable-on-404}
        end
      end
    end
  end

  # C9934
  describe 'uninstalling haproxy' do
    pp_four = <<-PUPPETCODE
        class { 'haproxy':
          package_ensure => 'absent',
          service_ensure => 'stopped',
        }
    PUPPETCODE
    it 'removes it' do
      retry_on_error_matching do
        apply_manifest(pp_four, catch_failures: true)
      end
    end

    describe package('haproxy') do
      it { is_expected.not_to be_installed }
    end
  end

  # C9935 C9939
  describe 'disabling haproxy' do
    pp_five = <<-PUPPETCODE
        class { 'haproxy':
          service_ensure => 'stopped',
        }
        haproxy::listen { 'stats':
          ipaddress => '127.0.0.1',
          ports     => '9090',
        }
    PUPPETCODE
    it 'stops the service' do
      retry_on_error_matching do
        apply_manifest(pp_five, catch_failures: true)
      end
    end

    describe service('haproxy') do
      it { is_expected.not_to be_running }
      it { is_expected.not_to be_enabled }
    end
  end
end