forked from puppetlabs/puppetlabs-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql_server_spec.rb
288 lines (260 loc) · 7.74 KB
/
mysql_server_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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
require 'spec_helper_acceptance'
describe 'mysql class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
case fact('osfamily')
when 'RedHat'
if fact('operatingsystemmajrelease') == '7'
package_name = 'mariadb-server'
service_name = 'mariadb'
service_provider = 'undef'
mycnf = '/etc/my.cnf'
else
package_name = 'mysql-server'
service_name = 'mysqld'
service_provider = 'undef'
mycnf = '/etc/my.cnf'
end
when 'Suse'
case fact('operatingsystem')
when 'OpenSuSE'
package_name = 'mysql-community-server'
service_name = 'mysql'
service_provider = 'undef'
mycnf = '/etc/my.cnf'
when 'SLES'
package_name = 'mysql'
service_name = 'mysql'
service_provider = 'undef'
mycnf = '/etc/my.cnf'
end
when 'Debian'
package_name = 'mysql-server'
service_name = 'mysql'
service_provider = 'undef'
mycnf = '/etc/mysql/my.cnf'
when 'Ubuntu'
package_name = 'mysql-server'
service_name = 'mysql'
service_provider = 'upstart'
mycnf = '/etc/mysql/my.cnf'
end
describe 'running puppet code' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
class { 'mysql::server': }
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
end
describe package(package_name) do
it { should be_installed }
end
describe service(service_name) do
it { should be_running }
it { should be_enabled }
end
end
describe 'mycnf' do
it 'should contain sensible values' do
pp = <<-EOS
class { 'mysql::server': }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file(mycnf) do
it { should contain 'key_buffer_size = 16M' }
it { should contain 'max_binlog_size = 100M' }
it { should contain 'query_cache_size = 16M' }
end
end
describe 'my.cnf changes' do
it 'sets values' do
pp = <<-EOS
class { 'mysql::server':
override_options => { 'mysqld' =>
{ 'key_buffer' => '32M',
'max_binlog_size' => '200M',
'query_cache_size' => '32M',
}
}
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file(mycnf) do
it { should contain 'key_buffer = 32M' }
it { should contain 'max_binlog_size = 200M' }
it { should contain 'query_cache_size = 32M' }
end
end
describe 'my.cnf should contain multiple instances of the same option' do
it 'sets multiple values' do
pp = <<-EOS
class { 'mysql::server':
override_options => { 'mysqld' =>
{ 'replicate-do-db' => ['base1', 'base2', 'base3'], }
}
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file(mycnf) do
it { should contain 'replicate-do-db = base1' }
it { should contain 'replicate-do-db = base2' }
it { should contain 'replicate-do-db = base3' }
end
end
describe 'package_ensure => absent' do
it 'uninstalls mysql' do
pp = <<-EOS
class { 'mysql::server':
service_enabled => false,
package_ensure => absent,
package_name => #{package_name}
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe package(package_name) do
it { should_not be_installed }
end
end
describe 'package_ensure => present' do
it 'installs mysql' do
pp = <<-EOS
class { 'mysql::server':
package_ensure => present,
package_name => #{package_name}
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe package(package_name) do
it { should be_installed }
end
end
describe 'purge_conf_dir' do
it 'purges the conf dir' do
pp = <<-EOS
class { 'mysql::server':
purge_conf_dir => true
}
EOS
shell('touch /etc/mysql/conf.d/test.conf')
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/mysql/conf.d/test.conf') do
it { should_not be_file }
end
end
describe 'restart' do
it 'restart => true' do
pp = <<-EOS
class { 'mysql::server':
restart => true,
override_options => { 'mysqldump' => { 'default-character-set' => 'UTF-8' } }
}
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.exit_code).to eq(2)
expect(r.stdout).to match(/Scheduling refresh/)
end
end
it 'restart => false' do
pp = <<-EOS
class { 'mysql::server':
restart => false,
override_options => { 'mysqldump' => { 'default-character-set' => 'UTF-16' } }
}
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.exit_code).to eq(2)
expect(r.stdout).to_not match(/Scheduling refresh/)
end
end
end
describe 'root_group' do
it 'creates a group' do
pp = "group { 'test': ensure => present }"
apply_manifest(pp, :catch_failures => true)
end
it 'sets the group of files' do
pp = <<-EOS
class { 'mysql::server':
root_group => 'test',
config_file => '/tmp/mysql_group_test',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/tmp/mysql_group_test') do
it { should be_grouped_into 'test' }
end
end
describe 'service parameters' do
it 'calls all parameters' do
pp = <<-EOS
class { 'mysql::server':
service_enabled => true,
service_manage => true,
service_name => #{service_name},
service_provider => #{service_provider}
}
EOS
apply_manifest(pp, :catch_failures => true)
end
end
describe 'users, grants, and databases' do
it 'are created' do
pp = <<-EOS
class { 'mysql::server':
users => {
'zerg1@localhost' => {
ensure => 'present',
max_connections_per_hour => '0',
max_queries_per_hour => '0',
max_updates_per_hour => '0',
max_user_connections => '0',
password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF',
}
},
grants => {
'zerg1@localhost/zergdb.*' => {
ensure => 'present',
options => ['GRANT'],
privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
table => 'zergdb.*',
user => 'zerg1@localhost',
}
},
databases => {
'zergdb' => {
ensure => 'present',
charset => 'utf8',
}
},
}
EOS
apply_manifest(pp, :catch_failures => true)
end
it 'has a user' do
shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'zerg1@localhost'\"") do |r|
expect(r.stdout).to match(/^1$/)
expect(r.stderr).to be_empty
end
end
it 'has a grant' do
shell("mysql -NBe \"SHOW GRANTS FOR zerg1@localhost\"") do |r|
expect(r.stdout).to match(/GRANT SELECT, INSERT, UPDATE, DELETE ON `zergdb`.* TO 'zerg1'@'localhost' WITH GRANT OPTION/)
expect(r.stderr).to be_empty
end
end
it 'has a database' do
shell("mysql -NBe \"SHOW DATABASES LIKE 'zergdb'\"") do |r|
expect(r.stdout).to match(/zergdb/)
expect(r.stderr).to be_empty
end
end
end
end