forked from puppetlabs/puppetlabs-tomcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acceptance_1_spec.rb
223 lines (205 loc) · 8.15 KB
/
acceptance_1_spec.rb
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
require 'spec_helper_acceptance'
#fact based two stage confine
#confine array
confine_array = [
(fact('operatingsystem') == 'Ubuntu' && fact('operatingsystemrelease') == '10.04'),
(fact('osfamily') == 'RedHat' && fact('operatingsystemmajrelease') == '5'),
(fact('operatingsystem') == 'Debian' && fact('operatingsystemmajrelease') == '6'),
fact('osfamily') == 'Suse'
]
stop_test = false
stop_test = true if UNSUPPORTED_PLATFORMS.any?{ |up| fact('osfamily') == up} || confine_array.any?
tcat_version = String.new
shell('curl http://tomcat.apache.org/download-80.cgi?Preferred=http%3A%2F%2Fmirror.nexcess.net%2Fapache%2F', :acceptable_exit_codes => 0) do |r|
/apache-tomcat-(.{4,7}).tar.gz/.match(r.stdout).to_a.uniq.each do |m|
if m.length < 7
tcat_version = m
break
end
end
end
describe 'Acceptance case one', :unless => stop_test do
context 'Initial install Tomcat and verification' do
it 'Should apply the manifest without error' do
pp = <<-EOS
class{'tomcat':}
class{'java':}
class{'gcc':}
$java_home = $::osfamily ? {
'RedHat' => '/etc/alternatives/java_sdk',
'Debian' => "/usr/lib/jvm/java-7-openjdk-${::architecture}",
default => undef
}
tomcat::instance { 'tomcat_one':
source_url => "http://mirror.nexcess.net/apache/tomcat/tomcat-8/v#{tcat_version}/bin/apache-tomcat-#{tcat_version}.tar.gz",
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
}->
staging::extract { 'commons-daemon-native.tar.gz':
source => "/opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-native.tar.gz",
target => "/opt/apache-tomcat/tomcat8-jsvc/bin",
unless => "test -d /opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-1.0.15-native-src",
}->
exec { 'configure jsvc':
command => "JAVA_HOME=${java_home} configure --with-java=${java_home}",
creates => "/opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-1.0.15-native-src/unix/Makefile",
cwd => "/opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-1.0.15-native-src/unix",
path => "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-1.0.15-native-src/unix",
require => [ Class['gcc'], Class['java'] ],
provider => shell,
}->
exec { 'make jsvc':
command => 'make',
creates => "/opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-1.0.15-native-src/unix/jsvc",
cwd => "/opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-1.0.15-native-src/unix",
path => "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-1.0.15-native-src/unix",
provider => shell,
}->
file { 'jsvc':
ensure => link,
path => "/opt/apache-tomcat/tomcat8-jsvc/bin/jsvc",
target => "/opt/apache-tomcat/tomcat8-jsvc/bin/commons-daemon-1.0.15-native-src/unix/jsvc",
}->
tomcat::config::server { 'tomcat8-jsvc':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
port => '80',
}->
tomcat::config::server::connector { 'tomcat8-jsvc':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
port => '80',
protocol => 'HTTP/1.1',
additional_attributes => {
'redirectPort' => '443'
},
notify => Tomcat::Service['jsvc-default'],
}->
tomcat::config::server::connector { 'tomcat8-ajp':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
port => '8309',
protocol => 'AJP/1.3',
additional_attributes => {
'redirectPort' => '443'
},
connector_ensure => 'false',
}->
tomcat::war { 'war_one.war':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
war_source => 'https://tomcat.apache.org/tomcat-8.0-doc/appdev/sample/sample.war',
}->
tomcat::setenv::entry { 'JAVA_HOME':
base_path => '/opt/apache-tomcat/tomcat8-jsvc/bin',
value => $java_home,
}->
tomcat::service { 'jsvc-default':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
java_home => $java_home,
use_jsvc => true,
}
EOS
apply_manifest(pp, :catch_failures => true, :acceptable_exit_codes => [0,2])
shell('sleep 15')
end
it 'Should be serving a page on port 80' do
shell('curl localhost:80/war_one/hello.jsp', :acceptable_exit_codes => 0) do |r|
r.stdout.should match(/Sample Application JSP Page/)
end
end
end
context 'Stop tomcat with verification!!!' do
it 'Should apply the manifest without error' do
pp = <<-EOS
class{ 'tomcat':}
tomcat::service{ 'jsvc-default':
service_ensure => stopped,
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
use_jsvc => true,
}
EOS
apply_manifest(pp, :catch_failures => true, :acceptable_exit_codes => [0,2])
shell('sleep 15')
end
it 'Should not be serving a page on port 80' do
shell('curl localhost:80/war_one/hello.jsp', :acceptable_exit_codes => 7)
end
end
context 'Start Tomcat with verification' do
it 'Should apply the manifest without error' do
pp = <<-EOS
class{ 'tomcat':}
$java_home = $::osfamily ? {
'RedHat' => '/etc/alternatives/java_sdk',
'Debian' => "/usr/lib/jvm/java-7-openjdk-${::architecture}",
default => undef
}
tomcat::service{ 'jsvc-default':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
service_ensure => true,
use_jsvc => true,
java_home => $java_home,
}
EOS
apply_manifest(pp, :catch_failures => true, :acceptable_exit_codes => [0,2])
shell('sleep 15')
end
it 'Should be serving a page on port 80' do
shell('curl localhost:80/war_one/hello.jsp', :acceptable_exit_codes => 0) do |r|
r.stdout.should match(/Sample Application JSP Page/)
end
end
end
context 'un-deploy the war with verification' do
it 'Should apply the manifest without error' do
pp = <<-EOS
class{ 'tomcat':}
tomcat::war { 'war_one.war':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
war_source => 'https://tomcat.apache.org/tomcat-8.0-doc/appdev/sample/sample.war',
war_ensure => 'false',
}
EOS
apply_manifest(pp, :catch_failures => true, :acceptable_exit_codes => [0,2])
shell('sleep 15')
end
it 'Should not have deployed the war' do
shell('curl localhost:80/war_one/hello.jsp', :acceptable_exit_codes => 0) do |r|
r.stdout.should match(/The requested resource is not available/)
end
end
it 'Should still have the server running on port 80' do
shell('curl localhost:80', :acceptable_exit_codes => 0) do |r|
r.stdout.should match(/Apache Tomcat/)
end
end
end
context 'remove the connector with verification' do
it 'Should apply the manifest without error' do
pp = <<-EOS
class{ 'tomcat':}
$java_home = $::osfamily ? {
'RedHat' => '/etc/alternatives/java_sdk',
'Debian' => "/usr/lib/jvm/java-7-openjdk-${::architecture}",
default => undef
}
tomcat::config::server::connector { 'tomcat8-jsvc':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
port => '80',
protocol => 'HTTP/1.1',
additional_attributes => {
'redirectPort' => '443'
},
connector_ensure => 'absent',
notify => Tomcat::Service['jsvc-default']
}
tomcat::service { 'jsvc-default':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
java_home => $java_home,
use_jsvc => true,
}
EOS
apply_manifest(pp, :catch_failures => true, :acceptable_exit_codes => [0,2])
shell('sleep 15')
end
it 'Should not be able to serve pages over port 80' do
shell('curl localhost:80', :acceptable_exit_codes => 7)
end
end
end