-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ruby.tar
269 lines (227 loc) · 10 KB
/
Ruby.tar
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
Ruby/ 0000775 0001750 0001750 00000000000 13572003726 011636 5 ustar goddino goddino Ruby/QL_mysql.rb 0000664 0001750 0001750 00000017577 13572003726 013745 0 ustar goddino goddino #!/usr/bin/env ruby -w
# Name: QL_mysql.rb
# Author: Steve Peralta
# Date: 9/15/07
# Description: Quicklook test tool for MySQL service
#
# Usage: QL_mysql --help
# Output: /tmp/QL_mysql/QL_mysql.log
# INSTALLATION OF QuickLookTool.rb
# Copy the QuickLookTool.rb file to the folder (based on system version):
# 10.5: /usr/lib/ruby/site_ruby/1.8/universal-darwin9.0/
# 10.6: /usr/lib/ruby/site_ruby/1.8/universal-darwin10.0/
require 'QuickLookTool'
#------------------------------------------------------------
# MySQLTool
#
# QuickLookTool class for MySQL
#------------------------------------------------------------
class MySQLTool < QuickLookTool
TOOL_NAME = "QL_mysql"
TOOL_VERSION = "1.7"
SERVICE_NAME = "MySQL"
SERVICE_ID = "mysql"
SERVICE_DESC = "MySQL Quicklook Test Suite"
MYSQL_DAEMON = "/usr/libexec/mysqld"
MYSQL_TOOL = "/usr/bin/mysql"
TEST_PWD = "admin"
MT_PREFIX = "#{MYSQL_TOOL} -S /var/mysql/mysql.sock --password=#{TEST_PWD}"
RESET_PWD_CMD = "#{MT_PREFIX} -e \"update mysql.user set password = PASSWORD('') where user='root';\""
QUERY_USER_CMD = "#{MT_PREFIX} -e \"use mysql; select Host,User from user;\""
MA_VARS_CMD = "mysqladmin -S /var/mysql/mysql.sock variables"
#----------------------------------------
def initialize
super(TOOL_NAME, TOOL_VERSION, SERVICE_NAME, SERVICE_ID, SERVICE_DESC)
# set additional execution prerequisites
self.setPrereqFiles([SACommand::SA_TOOL, MYSQL_DAEMON])
self.setTestCases([
StopService,
StartService,
SetDatabaseLocation,
VerifyDatabaseLocation,
RestoreDatabaseLocation,
DisableAllowNetworking,
VerifyDisableAllowNetworking,
EnableAllowNetworking,
VerifyEnableAllowNetworking,
RestoreAllowNetworking,
SetRootPassword,
VerifyRootPassword,
RestoreRootPassword,
])
# initialize data unique to this service
@dataDirPath = "#{self.tempDir}/data"
# create utility instance for accessing serveradmin functions
@saCommand = SACommand.new(self, "", nil, nil)
@savedAllowNet = ""
@savedDataDir = ""
end
#----------------------------------------
def dataDirPath
@dataDirPath
end
#----------------------------------------
def resetRootPassword
# Note: this method assumes the password was last set to MySQLTool::TEST_PWD
return if self.debugMode
`#{MySQLTool::RESET_PWD_CMD}`
end
#----------------------------------------
def restoreDefaultSetting(aKey, aVal)
self.logAndShow("- restoring default setting: #{aKey}")
@saCommand.writeSetting("#{aKey}", "#{aVal}")
end
#----------------------------------------
def doTestLoopSetup
# provided additional setup required before exectuing the test loop
return false unless super
self.removeDirectory(@dataDirPath) unless self.debugMode
@savedAllowNet = @saCommand.readSetting("allowNetwork", "no")
@savedDataDir = @saCommand.readSetting("databaseLocation", "/var/mysql")
return true
end
#----------------------------------------
def doTestLoopCleanup
# provided additional cleanup required after the test loop is finished
STDOUT.puts ""
self.logAndShow("END OF TESTS")
self.logAndShow("- restoring MySQL default settings")
self.doRestoreSettings
return super
end
#----------------------------------------
def doRestoreSettings
# called from RestoreSettingsCommand.doToolCommand
# restore default settings for MySQL service
self.logAndShow("- stopping MySQL service")
@saCommand.stopService
self.restoreDefaultSetting("allowNetwork", @savedAllowNet)
self.restoreDefaultSetting("databaseLocation", "\"/var/mysql\"")
# MySQL must be running to set the password
#self.logMessage("- starting MySQL service")
#@saCommand.startService
#self.logMessage(" restoring default setting: rootPassword")
#self.resetRootPassword
#@saCommand.stopService
return true
end
end
#------------------------------------------------------------
# Custom command classes for this service
#------------------------------------------------------------
class MySQLCheckDatabaseCommand < QLCommand
def initialize(qltool)
dp = qltool.dataDirPath
cmd = "ls \"#{dp}/ib_logfile0\""
super(qltool, cmd, "#{dp}/ib_logfile0", MANUAL_REDIRECT)
end
end
class MySQLCheckVarsCommand < QLCommand
def initialize(qltool, key, value)
cmd = "#{MySQLTool::MA_VARS_CMD} | grep #{key} | awk '{print $4}'"
super(qltool, cmd, value, MANUAL_REDIRECT)
end
end
class MySQLQueryUserCommand < QLCommand
def initialize(qltool, user)
cmd = "#{MySQLTool::QUERY_USER_CMD} | grep localhost | awk '{print $2}'"
super(qltool, cmd, user, MANUAL_REDIRECT)
end
end
class MySQLResetPasswordCommand < QLCommand
def initialize(qltool)
cmd = "#{MySQLTool::RESET_PWD_CMD}"
super(qltool, cmd, "", MANUAL_REDIRECT)
end
end
#------------------------------------------------------------
# Custom test case classes for this service
#------------------------------------------------------------
class StopService < QLTestCase
def initialize(seq, qltool)
qlcmd = SAStateCommand.new(qltool, SAStateCommand::STATE_STOP)
super(seq, qltool, "Basic", "Stop MySQL service", qlcmd)
end
end
class StartService < QLTestCase
def initialize(seq, qltool)
qlcmd = SAStateCommand.new(qltool, SAStateCommand::STATE_START)
super(seq, qltool, "Basic", "Start MySQL service", qlcmd)
end
end
class SetDatabaseLocation < QLTestCase
def initialize(seq, qltool)
dd = qltool.dataDirPath
qlcmd = SASettingsCommand.new(qltool, "databaseLocation", "\"#{dd}\"")
super(seq, qltool, "Database", "Set MySQL active database location", qlcmd)
end
end
class VerifyDatabaseLocation < QLTestCase
def initialize(seq, qltool)
qlcmd = MySQLCheckDatabaseCommand.new(qltool)
super(seq, qltool, "Database", "Verify MySQL active database location", qlcmd)
end
end
class RestoreDatabaseLocation < QLTestCase
def initialize(seq, qltool)
qlcmd = SASettingsCommand.new(qltool, "databaseLocation", "\"/var/mysql\"")
super(seq, qltool, "Database", "Restore default MySQL database location", qlcmd)
end
end
class DisableAllowNetworking < QLTestCase
def initialize(seq, qltool)
qlcmd = SASettingsCommand.new(qltool, "allowNetwork", "no")
super(seq, qltool, "Network", "Disable allow networking", qlcmd)
end
end
class VerifyDisableAllowNetworking < QLTestCase
def initialize(seq, qltool)
qlcmd = MySQLCheckVarsCommand.new(qltool, "skip_networking", "ON")
super(seq, qltool, "Network", "Verify allow networking disabled", qlcmd)
end
end
class EnableAllowNetworking < QLTestCase
def initialize(seq, qltool)
qlcmd = SASettingsCommand.new(qltool, "allowNetwork", "yes")
super(seq, qltool, "Network", "Enable allow networking", qlcmd)
end
end
class VerifyEnableAllowNetworking < QLTestCase
def initialize(seq, qltool)
qlcmd = MySQLCheckVarsCommand.new(qltool, "skip_networking", "OFF")
super(seq, qltool, "Network", "Verify allow networking enabled", qlcmd)
end
end
class RestoreAllowNetworking < QLTestCase
def initialize(seq, qltool)
qlcmd = SASettingsCommand.new(qltool, "allowNetwork", "no")
super(seq, qltool, "Network", "Restore default allow networking setting", qlcmd)
end
end
class SetRootPassword < QLTestCase
def initialize(seq, qltool)
qlcmd = SASettingsCommand.new(qltool, "rootPassword", "#{MySQLTool::TEST_PWD}", "\"\"")
super(seq, qltool, "Password", "Set MySQL root password to \'admin\'", qlcmd)
end
end
class VerifyRootPassword < QLTestCase
def initialize(seq, qltool)
qlcmd = MySQLQueryUserCommand.new(qltool, "root")
super(seq, qltool, "Password", "Verify MySQL root password == \'admin\'", qlcmd)
end
end
class RestoreRootPassword < QLTestCase
# See MySQLTool::resetRootPassword for the command to restore the root password to blank.
def initialize(seq, qltool)
qlcmd = MySQLResetPasswordCommand.new(qltool)
super(seq, qltool, "Password", "Restore default MySQL root password (blank)", qlcmd)
end
end
#--------------------
# MAIN
#--------------------
qltool = MySQLTool.new
status = qltool.runCommand ? 0 : 1
exit status
# END