]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/acceptance/mod_passenger_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / acceptance / mod_passenger_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'apache::mod::passenger class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4   case fact('osfamily')
5   when 'Debian'
6     service_name = 'apache2'
7     mod_dir = '/etc/apache2/mods-available/'
8     conf_file = "#{mod_dir}passenger.conf"
9     load_file = "#{mod_dir}zpassenger.load"
10
11     case fact('operatingsystem')
12     when 'Ubuntu'
13       case fact('lsbdistrelease')
14       when '10.04'
15         passenger_root = '/usr'
16         passenger_ruby = '/usr/bin/ruby'
17       when '12.04'
18         passenger_root = '/usr'
19         passenger_ruby = '/usr/bin/ruby'
20       when '14.04'
21         passenger_root         = '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini'
22         passenger_ruby         = '/usr/bin/ruby'
23         passenger_default_ruby = '/usr/bin/ruby'
24       else
25         # This may or may not work on Ubuntu releases other than the above
26         passenger_root = '/usr'
27         passenger_ruby = '/usr/bin/ruby'
28       end
29     when 'Debian'
30       case fact('lsbdistcodename')
31       when 'wheezy'
32         passenger_root = '/usr'
33         passenger_ruby = '/usr/bin/ruby'
34       when 'jessie'
35         passenger_root         = '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini'
36         passenger_ruby         = '/usr/bin/ruby'
37         passenger_default_ruby = '/usr/bin/ruby'
38       else
39         # This may or may not work on Debian releases other than the above
40         passenger_root = '/usr'
41         passenger_ruby = '/usr/bin/ruby'
42       end
43     end
44
45     passenger_module_path = '/usr/lib/apache2/modules/mod_passenger.so'
46     rackapp_user = 'www-data'
47     rackapp_group = 'www-data'
48   when 'RedHat'
49     service_name = 'httpd'
50     mod_dir = '/etc/httpd/conf.d/'
51     conf_file = "#{mod_dir}passenger.conf"
52     load_file = "#{mod_dir}zpassenger.load"
53     # sometimes installs as 3.0.12, sometimes as 3.0.19 - so just check for the stable part
54     passenger_root = '/usr/lib/ruby/gems/1.8/gems/passenger-3.0.1'
55     passenger_ruby = '/usr/bin/ruby'
56     passenger_tempdir = '/var/run/rubygem-passenger'
57     passenger_module_path = 'modules/mod_passenger.so'
58     rackapp_user = 'apache'
59     rackapp_group = 'apache'
60   end
61
62   pp_rackapp = <<-EOS
63           /* a simple ruby rack 'hellow world' app */
64           file { '/var/www/passenger':
65             ensure  => directory,
66             owner   => '#{rackapp_user}',
67             group   => '#{rackapp_group}',
68             require => Class['apache::mod::passenger'],
69           }
70           file { '/var/www/passenger/config.ru':
71             ensure  => file,
72             owner   => '#{rackapp_user}',
73             group   => '#{rackapp_group}',
74             content => "app = proc { |env| [200, { \\"Content-Type\\" => \\"text/html\\" }, [\\"hello <b>world</b>\\"]] }\\nrun app",
75             require => File['/var/www/passenger'] ,
76           }
77           apache::vhost { 'passenger.example.com':
78             port    => '80',
79             docroot => '/var/www/passenger/public',
80             docroot_group => '#{rackapp_group}' ,
81             docroot_owner => '#{rackapp_user}' ,
82             custom_fragment => "PassengerRuby  #{passenger_ruby}\\nRailsEnv  development" ,
83             require => File['/var/www/passenger/config.ru'] ,
84           }
85           host { 'passenger.example.com': ip => '127.0.0.1', }
86   EOS
87
88   case fact('osfamily')
89   when 'Debian'
90     context "default passenger config" do
91       it 'succeeds in puppeting passenger' do
92         pp = <<-EOS
93           /* stock apache and mod_passenger */
94           class { 'apache': }
95           class { 'apache::mod::passenger': }
96           #{pp_rackapp}
97         EOS
98         apply_manifest(pp, :catch_failures => true)
99       end
100
101       describe service(service_name) do
102         it { is_expected.to be_enabled }
103         it { is_expected.to be_running }
104       end
105
106       describe file(conf_file) do
107         it { is_expected.to contain "PassengerRoot \"#{passenger_root}\"" }
108
109         case fact('operatingsystem')
110         when 'Ubuntu'
111           case fact('lsbdistrelease')
112           when '10.04'
113             it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
114             it { is_expected.not_to contain "/PassengerDefaultRuby/" }
115           when '12.04'
116             it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
117             it { is_expected.not_to contain "/PassengerDefaultRuby/" }
118           when '14.04'
119             it { is_expected.to contain "PassengerDefaultRuby \"#{passenger_ruby}\"" }
120             it { is_expected.not_to contain "/PassengerRuby/" }
121           else
122             # This may or may not work on Ubuntu releases other than the above
123             it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
124             it { is_expected.not_to contain "/PassengerDefaultRuby/" }
125           end
126         when 'Debian'
127           case fact('lsbdistcodename')
128           when 'wheezy'
129             it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
130             it { is_expected.not_to contain "/PassengerDefaultRuby/" }
131           when 'jessie'
132             it { is_expected.to contain "PassengerDefaultRuby \"#{passenger_ruby}\"" }
133             it { is_expected.not_to contain "/PassengerRuby/" }
134           else
135             # This may or may not work on Debian releases other than the above
136             it { is_expected.to contain "PassengerRuby \"#{passenger_ruby}\"" }
137             it { is_expected.not_to contain "/PassengerDefaultRuby/" }
138           end
139         end
140       end
141
142       describe file(load_file) do
143         it { is_expected.to contain "LoadModule passenger_module #{passenger_module_path}" }
144       end
145
146       it 'should output status via passenger-memory-stats' do
147         shell("PATH=/usr/bin:$PATH /usr/sbin/passenger-memory-stats") do |r|
148           expect(r.stdout).to match(/Apache processes/)
149           expect(r.stdout).to match(/Nginx processes/)
150           expect(r.stdout).to match(/Passenger processes/)
151
152           # passenger-memory-stats output on newer Debian/Ubuntu verions do not contain
153           # these two lines
154           unless ((fact('operatingsystem') == 'Ubuntu' && fact('operatingsystemrelease') == '14.04') or
155                  (fact('operatingsystem') == 'Debian' && fact('operatingsystemrelease') == '8.0'))
156             expect(r.stdout).to match(/### Processes: [0-9]+/)
157             expect(r.stdout).to match(/### Total private dirty RSS: [0-9\.]+ MB/)
158           end
159
160           expect(r.exit_code).to eq(0)
161         end
162       end
163
164       # passenger-status fails under stock ubuntu-server-12042-x64 + mod_passenger,
165       # even when the passenger process is successfully installed and running
166       unless fact('operatingsystem') == 'Ubuntu' && fact('operatingsystemrelease') == '12.04'
167         it 'should output status via passenger-status' do
168           # xml output not available on ubunutu <= 10.04, so sticking with default pool output
169           shell("PATH=/usr/bin:$PATH /usr/sbin/passenger-status") do |r|
170             # spacing may vary
171             expect(r.stdout).to match(/[\-]+ General information [\-]+/)
172             if fact('operatingsystem') == 'Ubuntu' && fact('operatingsystemrelease') == '14.04'
173               expect(r.stdout).to match(/Max pool size[ ]+: [0-9]+/)
174               expect(r.stdout).to match(/Processes[ ]+: [0-9]+/)
175               expect(r.stdout).to match(/Requests in top-level queue[ ]+: [0-9]+/)
176             else
177               expect(r.stdout).to match(/max[ ]+= [0-9]+/)
178               expect(r.stdout).to match(/count[ ]+= [0-9]+/)
179               expect(r.stdout).to match(/active[ ]+= [0-9]+/)
180               expect(r.stdout).to match(/inactive[ ]+= [0-9]+/)
181               expect(r.stdout).to match(/Waiting on global queue: [0-9]+/)
182             end
183
184             expect(r.exit_code).to eq(0)
185           end
186         end
187       end
188
189       it 'should answer to passenger.example.com' do
190         shell("/usr/bin/curl passenger.example.com:80") do |r|
191           expect(r.stdout).to match(/^hello <b>world<\/b>$/)
192           expect(r.exit_code).to eq(0)
193         end
194       end
195
196     end
197
198   when 'RedHat'
199     # no fedora 18 passenger package yet, and rhel5 packages only exist for ruby 1.8.5
200     unless (fact('operatingsystem') == 'Fedora' and fact('operatingsystemrelease').to_f >= 18) or (fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '5' and fact('rubyversion') != '1.8.5')
201
202       if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '7'
203         pending('test passenger - RHEL7 packages don\'t exist')
204       else
205         context "default passenger config" do
206           it 'succeeds in puppeting passenger' do
207             pp = <<-EOS
208               /* EPEL and passenger repositories */
209               class { 'epel': }
210               exec { 'passenger.repo GPG key':
211                 command => '/usr/bin/curl -o /etc/yum.repos.d/RPM-GPG-KEY-stealthymonkeys.asc http://passenger.stealthymonkeys.com/RPM-GPG-KEY-stealthymonkeys.asc',
212                 creates => '/etc/yum.repos.d/RPM-GPG-KEY-stealthymonkeys.asc',
213               }
214               file { 'passenger.repo GPG key':
215                 ensure  => file,
216                 path    => '/etc/yum.repos.d/RPM-GPG-KEY-stealthymonkeys.asc',
217                 require => Exec['passenger.repo GPG key'],
218               }
219               epel::rpm_gpg_key { 'passenger.stealthymonkeys.com':
220                 path    => '/etc/yum.repos.d/RPM-GPG-KEY-stealthymonkeys.asc',
221                 require => [
222                   Class['epel'],
223                   File['passenger.repo GPG key'],
224                 ]
225               }
226               $releasever_string = $operatingsystem ? {
227                 'Scientific' => '6',
228                 default      => '$releasever',
229               }
230               yumrepo { 'passenger':
231                 baseurl         => "http://passenger.stealthymonkeys.com/rhel/${releasever_string}/\\$basearch" ,
232                 descr           => "Red Hat Enterprise ${releasever_string} - Phusion Passenger",
233                 enabled         => 1,
234                 gpgcheck        => 1,
235                 gpgkey          => 'http://passenger.stealthymonkeys.com/RPM-GPG-KEY-stealthymonkeys.asc',
236                 mirrorlist      => 'http://passenger.stealthymonkeys.com/rhel/mirrors',
237                 require => [
238                   Epel::Rpm_gpg_key['passenger.stealthymonkeys.com'],
239                 ],
240               }
241               /* apache and mod_passenger */
242               class { 'apache':
243                   require => [
244                     Class['epel'],
245                 ],
246               }
247               class { 'apache::mod::passenger':
248                 require => [
249                   Yumrepo['passenger']
250                 ],
251               }
252               #{pp_rackapp}
253             EOS
254             apply_manifest(pp, :catch_failures => true)
255           end
256
257           describe service(service_name) do
258             it { is_expected.to be_enabled }
259             it { is_expected.to be_running }
260           end
261
262           describe file(conf_file) do
263             it { is_expected.to contain "PassengerRoot #{passenger_root}" }
264             it { is_expected.to contain "PassengerRuby #{passenger_ruby}" }
265             it { is_expected.to contain "PassengerTempDir #{passenger_tempdir}" }
266           end
267
268           describe file(load_file) do
269             it { is_expected.to contain "LoadModule passenger_module #{passenger_module_path}" }
270           end
271
272           it 'should output status via passenger-memory-stats' do
273             shell("/usr/bin/passenger-memory-stats", :pty => true) do |r|
274               expect(r.stdout).to match(/Apache processes/)
275               expect(r.stdout).to match(/Nginx processes/)
276               expect(r.stdout).to match(/Passenger processes/)
277               expect(r.stdout).to match(/### Processes: [0-9]+/)
278               expect(r.stdout).to match(/### Total private dirty RSS: [0-9\.]+ MB/)
279
280               expect(r.exit_code).to eq(0)
281             end
282           end
283
284           it 'should output status via passenger-status' do
285             shell("PASSENGER_TMPDIR=/var/run/rubygem-passenger /usr/bin/passenger-status") do |r|
286               # spacing may vary
287               r.stdout.should =~ /[\-]+ General information [\-]+/
288               r.stdout.should =~ /max[ ]+= [0-9]+/
289               r.stdout.should =~ /count[ ]+= [0-9]+/
290               r.stdout.should =~ /active[ ]+= [0-9]+/
291               r.stdout.should =~ /inactive[ ]+= [0-9]+/
292               r.stdout.should =~ /Waiting on global queue: [0-9]+/
293
294               r.exit_code.should == 0
295             end
296           end
297
298           it 'should answer to passenger.example.com' do
299             shell("/usr/bin/curl passenger.example.com:80") do |r|
300               r.stdout.should =~ /^hello <b>world<\/b>$/
301               r.exit_code.should == 0
302             end
303           end
304         end
305       end
306     end
307   end
308 end