forked from puppetlabs/puppetlabs-tomcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacceptance_1b_spec.rb
221 lines (207 loc) · 8.41 KB
/
acceptance_1b_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
require 'spec_helper_acceptance'
stop_test = (UNSUPPORTED_PLATFORMS.any? { |up| fact('osfamily') == up } || SKIP_TOMCAT_8 || SKIP_GCC)
describe 'Acceptance case one', unless: stop_test do
after :all do
shell('pkill -f tomcat', acceptable_exit_codes: [0, 1])
shell('rm -rf /opt/tomcat*', acceptable_exit_codes: [0, 1])
shell('rm -rf /opt/apache-tomcat*', acceptable_exit_codes: [0, 1])
end
let :java_home do
if fact('osfamily') == 'Debian'
if fact('operatingsystemmajrelease') == '18.04'
'"/usr/lib/jvm/java-11-openjdk-${::architecture}"'
elsif fact('operatingsystemmajrelease') == '16.04' || fact('operatingsystemmajrelease') == '9'
'"/usr/lib/jvm/java-8-openjdk-${::architecture}"'
else
'"/usr/lib/jvm/java-7-openjdk-${::architecture}"'
end
elsif fact('osfamily') == 'RedHat'
'"/etc/alternatives/java_sdk"'
else
'undef'
end
end
context 'Initial install Tomcat and verification' do
it 'applies the manifest without error' do
pp = <<-MANIFEST
class{'java':}
class{'gcc':}
$java_home = #{java_home}
class jsvc {
archive { 'commons-daemon-native.tar.gz':
extract => true,
cleanup => false,
path => "/opt/apache-tomcat/bin/commons-daemon-native.tar.gz",
extract_path => "/opt/apache-tomcat/bin",
creates => "/opt/apache-tomcat/bin/commons-daemon-1.1.0-native-src",
}
-> exec { 'configure jsvc':
command => "JAVA_HOME=${java_home} configure --with-java=${java_home}",
creates => "/opt/apache-tomcat/bin/commons-daemon-1.1.0-native-src/unix/Makefile",
cwd => "/opt/apache-tomcat/bin/commons-daemon-1.1.0-native-src/unix",
path => "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/apache-tomcat/bin/commons-daemon-1.1.0-native-src/unix",
require => [ Class['gcc'], Class['java'] ],
provider => shell,
}
-> exec { 'make jsvc':
command => 'make',
creates => "/opt/apache-tomcat/bin/commons-daemon-1.1.0-native-src/unix/jsvc",
cwd => "/opt/apache-tomcat/bin/commons-daemon-1.1.0-native-src/unix",
path => "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/apache-tomcat/bin/commons-daemon-1.1.0-native-src/unix",
provider => shell,
}
-> file { 'jsvc':
ensure => link,
path => "/opt/apache-tomcat/bin/jsvc",
target => "/opt/apache-tomcat/bin/commons-daemon-1.1.0-native-src/unix/jsvc",
}
}
# The default
tomcat::install { '/opt/apache-tomcat':
user => 'tomcat8',
group => 'tomcat8',
source_url => '#{TOMCAT8_RECENT_SOURCE}',
allow_insecure => true,
}
-> class { 'jsvc': } ->
tomcat::instance { 'tomcat_one':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
user => 'tomcat8',
group => 'tomcat8',
java_home => $java_home,
use_jsvc => true,
}
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'
},
}
tomcat::config::server::connector { 'tomcat8-jsvc-8080':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
port => '8080',
protocol => 'HTTP/1.1',
additional_attributes => {
'redirectPort' => '443'
},
}
tomcat::config::server::connector { 'tomcat8-ajp':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
connector_ensure => absent,
port => '8309',
}
tomcat::war { 'war_one.war':
user => 'tomcat8',
group => 'tomcat8',
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
war_source => '#{SAMPLE_WAR}',
allow_insecure => true,
}
tomcat::setenv::entry { 'JAVA_HOME':
user => 'tomcat8',
group => 'tomcat8',
value => $java_home,
}
MANIFEST
idempotent_apply(default, pp, {})
end
it 'is serving a page on port 80', retry: 5, retry_wait: 10 do
shell('curl --retry 10 --retry-delay 15 localhost:80/war_one/hello.jsp', acceptable_exit_codes: 0) do |r|
r.stdout.should match(%r{Sample Application JSP Page})
end
end
it 'is serving a page on port 8080', retry: 5, retry_wait: 10 do
shell('curl --retry 10 --retry-delay 15 localhost:8080/war_one/hello.jsp', acceptable_exit_codes: 0) do |r|
r.stdout.should match(%r{Sample Application JSP Page})
end
end
end
context 'Stop tomcat with verification!!!' do
it 'applies the manifest without error' do
pp = <<-MANIFEST
$java_home = #{java_home}
tomcat::service { 'jsvc-default':
service_ensure => stopped,
catalina_home => '/opt/apache-tomcat',
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
use_jsvc => true,
java_home => $java_home,
user => 'tomcat8',
}
MANIFEST
apply_manifest(pp, catch_failures: true, acceptable_exit_codes: [0, 2])
end
it 'is not serving a page on port 80', retry: 5, retry_wait: 10 do
shell('curl --retry 10 --retry-delay 15 localhost:80/war_one/hello.jsp', acceptable_exit_codes: 7)
end
end
context 'Start Tomcat with verification' do
it 'applies the manifest without error' do
pp = <<-MANIFEST
$java_home = #{java_home}
tomcat::service { 'jsvc-default':
service_ensure => running,
catalina_home => '/opt/apache-tomcat',
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
use_jsvc => true,
java_home => $java_home,
user => 'tomcat8',
}
MANIFEST
apply_manifest(pp, catch_failures: true, acceptable_exit_codes: [0, 2])
end
it 'is serving a page on port 80', retry: 5, retry_wait: 10 do
shell('curl --retry 10 --retry-delay 15 localhost:80/war_one/hello.jsp', acceptable_exit_codes: 0) do |r|
r.stdout.should match(%r{Sample Application JSP Page})
end
end
end
context 'un-deploy the war with verification' do
it 'applies the manifest without error' do
pp = <<-MANIFEST
tomcat::war { 'war_one.war':
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
war_source => '#{SAMPLE_WAR}',
war_ensure => absent,
}
MANIFEST
apply_manifest(pp, catch_failures: true, acceptable_exit_codes: [0, 2])
end
it 'does not have deployed the war', retry: 5, retry_wait: 10 do
shell('curl localhost:80/war_one/hello.jsp', acceptable_exit_codes: 0) do |r|
r.stdout.should match(%r{The origin server did not find a current representation for the target resource})
end
end
end
context 'remove the connector with verification' do
it 'applies the manifest without error' do
pp = <<-MANIFEST
$java_home = #{java_home}
tomcat::config::server::connector { 'tomcat8-jsvc':
connector_ensure => 'absent',
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
port => '80',
notify => Tomcat::Service['jsvc-default']
}
tomcat::service { 'jsvc-default':
service_ensure => running,
catalina_home => '/opt/apache-tomcat',
catalina_base => '/opt/apache-tomcat/tomcat8-jsvc',
java_home => $java_home,
use_jsvc => true,
user => 'tomcat8',
}
MANIFEST
apply_manifest(pp, catch_failures: true, acceptable_exit_codes: [0, 2])
end
it 'is not able to serve pages over port 80', retry: 5, retry_wait: 10 do
shell('curl --retry 10 --retry-delay 15 localhost:80', acceptable_exit_codes: 7)
end
end
end