super-test 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGE.txt +9 -0
  3. data/README.txt +13 -0
  4. data/bin/idb +19 -0
  5. data/bin/ii +113 -0
  6. data/bin/istart_mock +36 -0
  7. data/bin/istop_mock +16 -0
  8. data/bin/kk +181 -0
  9. data/bin/rubyatp +42 -0
  10. data/bin/start_mock +36 -0
  11. data/bin/stop_mock +16 -0
  12. data/bin/xgo +45 -0
  13. data/conf/conf.rb +11 -0
  14. data/conf/db03.yml +31 -0
  15. data/conf/db13.yml +37 -0
  16. data/conf/db19.yml +33 -0
  17. data/conf/online.yml +32 -0
  18. data/conf/super_test.yml +40 -0
  19. data/conf/system.yml +26 -0
  20. data/conf/sz00.yml +31 -0
  21. data/conf/sz06.yml +34 -0
  22. data/conf/wise00.yml +11 -0
  23. data/data/case.house +0 -0
  24. data/data/char.house +0 -0
  25. data/data/images/Bluehills.jpg +0 -0
  26. data/data/images/Sunset.jpg +0 -0
  27. data/data/images/Waterlilies.jpg +0 -0
  28. data/data/images/Winter.jpg +0 -0
  29. data/data/query.house +18595 -0
  30. data/data/user.house +8 -0
  31. data/lib/action/module/check_action.rb +58 -0
  32. data/lib/action/module/cnnt_action.rb +161 -0
  33. data/lib/action/module/datacenter_action.rb +48 -0
  34. data/lib/action/module/http_pack_helper.rb +163 -0
  35. data/lib/action/module/httpserver_action.rb +297 -0
  36. data/lib/action/module/inc.rb +21 -0
  37. data/lib/action/module/mcpack_action.rb +57 -0
  38. data/lib/action/module/sql_action.rb +84 -0
  39. data/lib/action/module/ssh_action.rb +37 -0
  40. data/lib/action/system/user_action.rb +180 -0
  41. data/lib/common/appium_helper.rb +217 -0
  42. data/lib/common/atp_helper.rb +74 -0
  43. data/lib/common/atp_report.rb +344 -0
  44. data/lib/common/data_house.rb +405 -0
  45. data/lib/common/data_model.rb +87 -0
  46. data/lib/common/http/assert_helper.rb +343 -0
  47. data/lib/common/http/fix_hpricot.rb +118 -0
  48. data/lib/common/http/html_helper.rb +362 -0
  49. data/lib/common/http/http_helper.rb +469 -0
  50. data/lib/common/http/multipart.rb +81 -0
  51. data/lib/common/isandbox_helper.rb +195 -0
  52. data/lib/common/json_helper.rb +43 -0
  53. data/lib/common/mock_helper.rb +168 -0
  54. data/lib/common/mtop_helper.rb +141 -0
  55. data/lib/common/myconf_helper.rb +49 -0
  56. data/lib/common/mylog_helper.rb +77 -0
  57. data/lib/common/pairwise.rb +121 -0
  58. data/lib/common/query_house.rb +89 -0
  59. data/lib/common/report_helper.rb +97 -0
  60. data/lib/common/robot_helper.rb +85 -0
  61. data/lib/common/socket/check.rb +325 -0
  62. data/lib/common/socket/conf_modifier.rb +149 -0
  63. data/lib/common/socket/context.rb +55 -0
  64. data/lib/common/socket/data.rb +392 -0
  65. data/lib/common/socket/data_helper.rb +41 -0
  66. data/lib/common/socket/env.rb +317 -0
  67. data/lib/common/socket/inc.rb +24 -0
  68. data/lib/common/socket/log.rb +213 -0
  69. data/lib/common/socket/log4s.rb +58 -0
  70. data/lib/common/socket/log_helper.rb +332 -0
  71. data/lib/common/socket/my_sql.rb +77 -0
  72. data/lib/common/socket/net.rb +74 -0
  73. data/lib/common/socket/network.rb +115 -0
  74. data/lib/common/socket/rlib/conf_modifier.rb +130 -0
  75. data/lib/common/socket/rlib/data_helper.rb +33 -0
  76. data/lib/common/socket/rlib/log_helper.rb +303 -0
  77. data/lib/common/socket/rlib/process_helper.rb +91 -0
  78. data/lib/common/socket/stub.rb +276 -0
  79. data/lib/common/socket/util.rb +266 -0
  80. data/lib/patterns/inc.rb +10 -0
  81. data/lib/patterns/mc_base_pattern.rb +474 -0
  82. data/lib/patterns/some_pattern.rb +145 -0
  83. data/lib/super_test.rb +114 -0
  84. data/log/super_test.log +0 -0
  85. data/log/super_test.log.wf +0 -0
  86. data/test/cover_me.rb +6 -0
  87. data/tool/jenny +0 -0
  88. data/tool/mcsend/mcsend2 +0 -0
  89. data/tool/mcsend/mcsend2_shead +0 -0
  90. data/tool/mcserver/conf/mcserver.conf +77 -0
  91. data/tool/mcserver/conf/mcserverauthip +17 -0
  92. data/tool/mcserver/mcserver +0 -0
  93. data/tool/mcserver/mcserver_trans +0 -0
  94. data/tool/mysql +0 -0
  95. data/tool/net/mcsend/mcsend +0 -0
  96. data/tool/net/mcsend/mcsend_trans +0 -0
  97. data/tool/net/mcsend/nshead.data +7 -0
  98. data/tool/net/mcsend/res_nshead.data +7 -0
  99. data/tool/net/my_client/my_client +0 -0
  100. data/tool/net/tsclient/client.tcl +205 -0
  101. data/tool/others/kk +190 -0
  102. data/tool/others/rubyatp +42 -0
  103. data/tool/others/supertest_install.sh +34 -0
  104. data/tool/trip/idb +0 -0
  105. data/tool/ts-agent/nshead.bft +12 -0
  106. data/tool/ts-agent/server.conf +10 -0
  107. data/tool/ts-agent/server.tcl +376 -0
  108. metadata +275 -0
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require 'log4r'
5
+
6
+ # === 功能:
7
+ # 使用$log对象实现所有的写日志的功能
8
+ # === Example:
9
+ # Log4s::set_level "debug"
10
+ # $log.debug "test deb"
11
+ # $log.info "test info"
12
+ # $log.warn "test warn"
13
+ # $log.error "test error"
14
+ # $log.fatal "test fatal"
15
+ module Log4s
16
+ include Log4r
17
+ LOG_ROOT = File.join(File.dirname(__FILE__), '../../log/')
18
+
19
+ #第一步,配置log
20
+ log = Logger.new "mylog"
21
+ f = PatternFormatter.new(:pattern => "%5l %d %m")
22
+ file = FileOutputter.new('fileOutputter', :filename => "#{LOG_ROOT}mtest.log",:trunc => false)
23
+ file.only_at DEBUG,INFO
24
+ file.formatter = f
25
+ log.add file
26
+
27
+ file_wf = FileOutputter.new('fileOutputter', :filename => "#{LOG_ROOT}mtest.log.wf",:trunc => false)
28
+ file_wf.only_at WARN,ERROR,FATAL
29
+ file_wf.formatter = f
30
+ log.add file_wf
31
+ $log = log
32
+
33
+ def self.set_level(level)
34
+ case level.downcase
35
+ when "debug"
36
+ $log.level = DEBUG
37
+ when "info"
38
+ $log.level = INFO
39
+ when "warn"
40
+ $log.level = WARN
41
+ when "error"
42
+ $log.level = ERROR
43
+ when "fatal"
44
+ $log.level = FATAL
45
+ else
46
+ raise "bad log level"
47
+ end
48
+ end
49
+ end
50
+
51
+ if __FILE__ == $0
52
+ Log4s::set_level "debug"
53
+ $log.debug "test deb"
54
+ $log.info "test info"
55
+ $log.warn "test warn"
56
+ $log.error "test error"
57
+ $log.fatal "test fatal"
58
+ end
@@ -0,0 +1,332 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ LOG_LEVEL=["DEBUG", "NOTICE", "WARNING", "FATAL"]
4
+
5
+ #===========================================================
6
+ #class for scan local log file
7
+ #support log level : ["DEBUG", "NOTICE", "WARNING", "FATAL"]
8
+ #===========================================================
9
+
10
+ class LogHelper
11
+
12
+ # ===功能
13
+ #get the total lines of the log file
14
+ # ===参数
15
+ #params
16
+ #log_path: logfile path
17
+ #log_name: logfile name
18
+ #return: the total lines of the log file
19
+ # ===example
20
+ # LogHelper.get_lines logpath, "log1"
21
+ def LogHelper.get_lines(log_path, log_name)
22
+ log_file = log_path + "/" + log_name
23
+
24
+ #param check
25
+ if File::exists?(log_file) && File::file?(log_file) then
26
+ File.open(log_file) do |f|
27
+ lines = f.readlines.size
28
+ return lines
29
+ end
30
+ else
31
+ raise "logfile #{log_file} not exists or is not a regular file"
32
+ end
33
+ end
34
+
35
+
36
+ # ===功能
37
+ #get the last n lines's contents of the log file
38
+ # ===参数
39
+ #param
40
+ #log_path
41
+ #log_name
42
+ #start_lines: from which line we search the log content, newlog=[start_lines, log_end]
43
+ #return: an array contains the last n lines' contents
44
+ # ===example
45
+ # LogHelper.get_tail_contents logpath, "log1", 10
46
+ def LogHelper.get_tail_contents(log_path, log_name, start_lines)
47
+ last_lines = LogHelper.get_lines(log_path, log_name) - start_lines + 1
48
+ #param check
49
+ if last_lines <= 0 then
50
+ raise "params error: last_lines should bigger than 0"
51
+ end
52
+ log_file = log_path + "/" + log_name
53
+
54
+ contents = Array.new
55
+ if File::exists?(log_file) && File::file?(log_file) then
56
+ system "tail -#{last_lines} #{log_file} > tmp_file"
57
+ File.open("tmp_file") do |f|
58
+ contents = f.readlines
59
+ #remove the tmp file
60
+ system "rm tmp_file"
61
+ return contents
62
+ end
63
+ else
64
+ raise "file #{log_file} not exists or is not a regular file"
65
+ end
66
+
67
+ end
68
+
69
+ # === 功能:
70
+ # 获取匹配的次数
71
+ # === 参数:
72
+ # log_level: ["DEBUG", "NOTICE", "WARNING", "FATAL"]
73
+ # === Example:
74
+ # LogHelper.get_match_lines "/home/space/space/log/", "log1", 1, ["DEBUG", "NOTICE", "WARNING", "FATAL"], "time"
75
+ def LogHelper.get_match_lines log_path, log_name, start_lines, log_level, pattern
76
+ contents = get_tail_contents log_path, log_name, start_lines
77
+ lines = []
78
+
79
+ if contents == nil
80
+ return lines
81
+ else
82
+ contents.each{|line|
83
+ checkable = false
84
+ if log_level.size > 0
85
+ log_level.each{|level|
86
+ if line.include? level
87
+ checkable = true
88
+ break
89
+ end
90
+ }
91
+ else
92
+ checkable = true
93
+ end
94
+
95
+
96
+ if checkable
97
+ #match = line.scan pattern
98
+ #if match != nil && match.size > 0
99
+ # lines << line
100
+ #end
101
+ #match = pattern.match line
102
+ match = line.match pattern
103
+ if match != nil
104
+ lines << line
105
+ end
106
+ end
107
+ }
108
+
109
+ return lines
110
+ end
111
+ end
112
+
113
+ # ===功能
114
+ # get the match times with the giving log level and regex pattern
115
+ #
116
+ # ===参数
117
+ # -log_path:
118
+ # -log_name:
119
+ # -start_lines:from which line we search the log content, newlog=[start_lines, log_end]
120
+ # -log_level: an array whoes value from ["DEBUG", "NOTICE", "WARNING", "FATAL"]; nil for all levels
121
+ # -pattern: a string or a regex pattern
122
+ # return: int, the match times with the giving log level and regex pattern
123
+ #
124
+ # ===example:
125
+ # LogHelper.get_match_times("./", "chenjie.log", 1, nil, "openapptrans")
126
+ # LogHelper.get_match_times("./", "chenjie.log", 1, nil, /(\d{4})-(\d{2})-(\d{2})/)
127
+ def LogHelper.get_match_times(log_path, log_name, start_lines, log_level, pattern)
128
+ contents = get_tail_contents(log_path, log_name, start_lines)
129
+ count = 0
130
+ if contents == nil then
131
+ return 0
132
+ else
133
+ contents.each{|line|
134
+ checkable = false
135
+ if log_level.size > 0 then
136
+ #log_level is not nil, only the line contains the log_level, then should be check
137
+ log_level.each{|level|
138
+ if line.include?(level) then
139
+ checkable = true
140
+ break;
141
+ end
142
+ }
143
+ else
144
+ #log_level is nil, the line should be check
145
+ checkable = true
146
+ end
147
+
148
+ if checkable then
149
+ matches = line.scan(pattern)
150
+ count += matches.size
151
+ end
152
+ }
153
+ end
154
+
155
+ return count
156
+ end
157
+
158
+ # ===功能
159
+ #get the match values with the giving log level and regex pattern
160
+ # ===参数
161
+ #param
162
+ #log_path:
163
+ #log_name:
164
+ #last_lines:the lines read from tail to head
165
+ #log_level: an array whoes value from ["DEBUG", "NOTICE", "WARNING", "FATAL"]; nil for all levels
166
+ #pattern: a string or a regex pattern
167
+ #return: an array contains the match values with the giving log level and regex pattern
168
+ #
169
+ #===example:
170
+ #LogHelper.get_match_values("./", "chenjie.log", 1, nil, /(\d{4})-(\d{2})-(\d{2})/)
171
+ #LogHelper.get_match_values("./", "chenjie.log", 1, nil, "openapptrans")
172
+ def LogHelper.get_match_values(log_path, log_name, start_lines, log_level, pattern)
173
+ contents = get_tail_contents(log_path, log_name, start_lines)
174
+ values = Array.new
175
+ if contents == nil then
176
+ return 0
177
+ else
178
+ contents.each{|line|
179
+ checkable = false
180
+ if log_level.size > 0 then
181
+ #log_level is not nil, only the line contains the log_level, then should be check
182
+ log_level.each{|level|
183
+ if line.include?(level) then
184
+ checkable = true
185
+ break;
186
+ end
187
+ }
188
+ else
189
+ #log_level is nil, the line should be check
190
+ checkable = true
191
+ end
192
+
193
+ if checkable then
194
+ matches = line.scan(pattern)
195
+ matches.each{|m|
196
+ values << m
197
+ }
198
+ end
199
+ }
200
+ end
201
+
202
+ return values
203
+ end
204
+
205
+ # ===功能
206
+ #get the first match value, nil if no match found
207
+ # ===参数
208
+ #param
209
+ #log_path:
210
+ #log_name:
211
+ #last_lines:the lines read from tail to head
212
+ #log_level: an array whoes value from ["DEBUG", "NOTICE", "WARNING", "FATAL"]; nil for all levels
213
+ #pattern: a string or a regex pattern
214
+ #return: a string firstly matches the pattern, nil if no match found
215
+ #
216
+ #===example:
217
+ #LogHelper.get_match_value("./", "chenjie.log", 1, nil, /(\d{4})-(\d{2})-(\d{2})/)
218
+ #LogHelper.get_match_value("./", "chenjie.log", 1, nil, "openapptrans")
219
+ def LogHelper.get_match_value(log_path, log_name, start_lines, log_level, pattern)
220
+ contents = get_tail_contents(log_path, log_name, start_lines)
221
+ if contents == nil then
222
+ return nil
223
+ else
224
+ contents.each{|line|
225
+ checkable = false
226
+ if log_level.size > 0 then
227
+ #log_level is not nil, only the line contains the log_level, then should be check
228
+ log_level.each{|level|
229
+ if line.include?(level) then
230
+ checkable = true
231
+ break;
232
+ end
233
+ }
234
+ else
235
+ #log_level is nil, the line should be check
236
+ checkable = true
237
+ end
238
+
239
+ if checkable then
240
+ match = pattern.match(line)
241
+ if match != nil then
242
+ return match[0]
243
+ end
244
+ end
245
+ }
246
+ end
247
+
248
+ return nil
249
+ end
250
+
251
+ # ===功能
252
+ #turn log_level code into log level array(helper method)
253
+ #used to solve remote parameter passing problem(pass string format parameter)
254
+ # ===参数
255
+ #param
256
+ #code: "0:0:0:0" to "1:1:1:1"
257
+ #return: [] to ["DEBUG", "NOTICE", "WARNING", "FATAL"]
258
+ # ===example
259
+ #array1 = LogHelper.level_decode "0:0:0:1"
260
+ def LogHelper.level_decode(code)
261
+ levels = Array.new
262
+ arr = code.split(":")
263
+
264
+ i = 0
265
+ arr.each{|a|
266
+ if a == "1" then
267
+ levels << LOG_LEVEL[i]
268
+ end
269
+ i += 1
270
+ }
271
+ return levels
272
+ end
273
+
274
+ # ===功能
275
+ #translate log_level array into log level code(helper method)
276
+ #used to solve remote parameter passing problem(pass string format parameter)
277
+ # ===参数
278
+ #param
279
+ #code: "0:0:0:0" to "1:1:1:1"
280
+ #return: [] to ["DEBUG", "NOTICE", "WARNING", "FATAL"]
281
+ # ===example
282
+ # code1 = LogHelper.level_encode ["DEBUG", "WARNING"]
283
+ def LogHelper.level_encode arr
284
+ code = ""
285
+ if arr.include?("DEBUG") then
286
+ code += "1:"
287
+ else
288
+ code += "0:"
289
+ end
290
+
291
+ if arr.include?("NOTICE") then
292
+ code += "1:"
293
+ else
294
+ code += "0:"
295
+ end
296
+
297
+ if arr.include?("WARNING") then
298
+ code += "1:"
299
+ else
300
+ code += "0:"
301
+ end
302
+
303
+ if arr.include?("FATAL") then
304
+ code += "1"
305
+ else
306
+ code += "0"
307
+ end
308
+
309
+ return code
310
+ end
311
+
312
+ end
313
+
314
+ if ARGV.length > 0 then
315
+ case ARGV[0]
316
+ when "get_lines"
317
+ puts LogHelper.get_lines(ARGV[1], ARGV[2])
318
+ when "get_tail_contents"
319
+ puts LogHelper.get_tail_contents(ARGV[1], ARGV[2], ARGV[3].to_i)
320
+ when "get_match_times"
321
+ puts LogHelper.get_match_times(ARGV[1], ARGV[2], ARGV[3].to_i, LogHelper.level_decode(ARGV[4]) , Regexp.new(ARGV[5]))
322
+ when "get_match_lines"
323
+ puts LogHelper.get_match_lines(ARGV[1], ARGV[2], ARGV[3].to_i, LogHelper.level_decode(ARGV[4]) , Regexp.new(ARGV[5]))
324
+ when "get_match_values"
325
+ puts LogHelper.get_match_values(ARGV[1], ARGV[2], ARGV[3].to_i, LogHelper.level_decode(ARGV[4]) , Regexp.new(ARGV[5]))
326
+ when "get_match_value"
327
+ puts LogHelper.get_match_value(ARGV[1], ARGV[2], ARGV[3].to_i, LogHelper.level_decode(ARGV[4]) , Regexp.new(ARGV[5]))
328
+ # else
329
+ # puts "LogHelper: bad method name? #{ARGV[0]}"
330
+ end
331
+ end
332
+
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ # Author:: chenjie
4
+ # Date::2009-6-16
5
+
6
+ require 'dbi'
7
+ require "#{File.dirname(__FILE__)}/context"
8
+ #require "#{File.dirname(__FILE__)}/log4s"
9
+
10
+ # Mysql reated methods; context support
11
+ module MY_SQL
12
+ # ===功能
13
+ # 连接数据库
14
+ # ===example
15
+ # db_connect "newfriend", "127.0.0.1", 3306, "root", "root"
16
+ def db_connect db, host, port, user, pwd
17
+
18
+ dbh = DBI.connect("DBI:Mysql:#{db}:#{host}:#{port}", user, pwd)
19
+
20
+ #Context.set "#{host}.#{db}", dbh
21
+ Context.set :DATABASE, db
22
+ Context.set :DB_HOST, host
23
+ Context.set :DBH, dbh
24
+ return dbh
25
+ end
26
+
27
+ # ===功能
28
+ # 断开数据库连接
29
+ # ===example
30
+ # db_disconnect
31
+ def db_disconnect
32
+ #dbh = Context.get "#{host}.#{db}"
33
+ dbh = Context.get :DBH
34
+
35
+ if dbh != nil
36
+ dbh.disconnect
37
+ end
38
+ end
39
+
40
+ # ===功能
41
+ # 发送数据库操作命令
42
+ # ===example
43
+ # db_do "select * from table1;"
44
+ def db_do sql
45
+ dbh = Context.get :DBH
46
+ $log.info "DB=#{$globals[:DATABASE]}_HOST=#{$globals[:DB_HOST]}_SQL=#{sql}"
47
+ dbh.do sql
48
+ end
49
+
50
+ # ===功能
51
+ # 发送数据库操作命令
52
+ # ===example
53
+ # db_select_one "select * from table1;"
54
+ def db_select_one sql
55
+ dbh = Context.get :DBH
56
+ $log.info "DB=#{$globals[:DATABASE]}_HOST=#{$globals[:DB_HOST]}_SQL=#{sql}"
57
+ dbh.select_one sql
58
+ end
59
+
60
+ def db_execute sql
61
+ dbh = Context.get :DBH
62
+ $log.info "DB=#{$globals[:DATABASE]}_HOST=#{$globals[:DB_HOST]}_SQL=#{sql}"
63
+ dbh.execute(sql)
64
+ end
65
+
66
+ end
67
+
68
+
69
+ if __FILE__ == $0
70
+ include MY_SQL
71
+ dbh = db_connect 'spow', '10.241.14.39', '3306', 'root', ''
72
+ row = dbh.select_one("DESC opbox")
73
+ puts row[0].to_s
74
+ puts "-------"
75
+ puts row
76
+ dbh.disconnect if dbh
77
+ end