svdir 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/CHANGELOG +29 -0
  2. data/LICENSE +19 -0
  3. data/README +67 -0
  4. data/Rakefile +66 -0
  5. data/example/svctl +117 -0
  6. data/lib/sys/sv/statusbytes.rb +53 -0
  7. data/lib/sys/sv/svdir.rb +224 -0
  8. data/lib/sys/sv/util.rb +36 -0
  9. data/test/fixtures/PrefabSvDir.rb +22 -0
  10. data/test/fixtures/TempSvDir.rb +62 -0
  11. data/test/services/corrupt-normd/down +0 -0
  12. data/test/services/corrupt-normd/supervise/ok +0 -0
  13. data/test/services/corrupt-normd/supervise/status +0 -0
  14. data/test/services/corrupt-normu/supervise/ok +0 -0
  15. data/test/services/corrupt-normu/supervise/status +0 -0
  16. data/test/services/corrupt-zero-normd/down +0 -0
  17. data/test/services/corrupt-zero-normd/supervise/ok +0 -0
  18. data/test/services/corrupt-zero-normd/supervise/status +0 -0
  19. data/test/services/corrupt-zero-normu/supervise/ok +0 -0
  20. data/test/services/corrupt-zero-normu/supervise/status +0 -0
  21. data/test/services/down-0-normd-nowant/down +0 -0
  22. data/test/services/down-0-normd-nowant/supervise/ok +0 -0
  23. data/test/services/down-0-normd-nowant/supervise/status +0 -0
  24. data/test/services/down-0-normu-nowant/supervise/ok +0 -0
  25. data/test/services/down-0-normu-nowant/supervise/status +0 -0
  26. data/test/services/up-12526-normu-wantd/supervise/ok +0 -0
  27. data/test/services/up-12526-normu-wantd/supervise/status +0 -0
  28. data/test/services/up-12581-normd-wantd-paused/down +0 -0
  29. data/test/services/up-12581-normd-wantd-paused/supervise/ok +0 -0
  30. data/test/services/up-12581-normd-wantd-paused/supervise/status +0 -0
  31. data/test/services/up-12581-normu-wantd-paused/supervise/ok +0 -0
  32. data/test/services/up-12581-normu-wantd-paused/supervise/status +0 -0
  33. data/test/services/up-12816-normd-nowant/down +0 -0
  34. data/test/services/up-12816-normd-nowant/supervise/ok +0 -0
  35. data/test/services/up-12816-normd-nowant/supervise/status +0 -0
  36. data/test/services/up-12816-normu-nowant/supervise/ok +0 -0
  37. data/test/services/up-12816-normu-nowant/supervise/status +0 -0
  38. data/test/services/up-12868-normd-wantu-paused/down +0 -0
  39. data/test/services/up-12868-normd-wantu-paused/supervise/ok +0 -0
  40. data/test/services/up-12868-normd-wantu-paused/supervise/status +0 -0
  41. data/test/services/up-12868-normd-wantu/down +0 -0
  42. data/test/services/up-12868-normd-wantu/supervise/ok +0 -0
  43. data/test/services/up-12868-normd-wantu/supervise/status +0 -0
  44. data/test/services/up-12868-normu-wantu-paused/supervise/ok +0 -0
  45. data/test/services/up-12868-normu-wantu-paused/supervise/status +0 -0
  46. data/test/services/up-12868-normu-wantu/supervise/ok +0 -0
  47. data/test/services/up-12868-normu-wantu/supervise/status +0 -0
  48. data/test/services/up-16464-normd-wantd/down +0 -0
  49. data/test/services/up-16464-normd-wantd/supervise/ok +0 -0
  50. data/test/services/up-16464-normd-wantd/supervise/status +0 -0
  51. data/test/testbase.rb +30 -0
  52. data/test/ts_corrupt.rb +133 -0
  53. data/test/ts_nosupervisor.rb +81 -0
  54. data/test/ts_signal.rb +128 -0
  55. data/test/ts_svstat.rb +548 -0
  56. metadata +117 -0
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+ # Verify that the .signal method issues the appropriate bytes to a
3
+ # svdir control FIFO.
4
+ #
5
+ # Author:: Mike Pomraning
6
+ # Copyright:: Copyright (c) 2011 Qualys, Inc.
7
+ # License:: MIT (see the file LICENSE)
8
+ #
9
+
10
+ $:.unshift File.join(File.dirname(__FILE__), "lib")
11
+
12
+ require 'testbase'
13
+ require 'sys/sv/svdir'
14
+
15
+ class TestSvcSignal < Test::Unit::TestCase
16
+
17
+ include_fixture :TempSvDir
18
+
19
+ # Verify that unknown signal arguments generate ArgumentError
20
+ #
21
+ def test_signal_unknown
22
+ [ :invalid, 'invalid' ].each do |bogus|
23
+ assert_raise ArgumentError do
24
+ @svdir.signal bogus
25
+ end
26
+ end
27
+ end
28
+
29
+ # Verify each of the known signals, as symbols and strings
30
+ #
31
+ def test_signal_up
32
+ [:up, 'up'].each { |c| assert_expected_byte(c, 'u') }
33
+ end
34
+
35
+ def test_signal_down
36
+ [:down, 'down'].each { |c| assert_expected_byte(c, 'd') }
37
+ end
38
+
39
+ def test_signal_once
40
+ [:once, 'once'].each { |c| assert_expected_byte(c, 'o') }
41
+ end
42
+
43
+ def test_signal_pause
44
+ [:pause, 'pause'].each { |c| assert_expected_byte(c, 'p') }
45
+ end
46
+
47
+ def test_signal_STOP
48
+ [:STOP, 'STOP'].each { |c| assert_expected_byte(c, 'p') }
49
+ end
50
+
51
+ def test_signal_continue
52
+ [:continue, 'continue'].each { |c| assert_expected_byte(c, 'c') }
53
+ end
54
+
55
+ def test_signal_CONT
56
+ [:CONT, 'CONT'].each { |c| assert_expected_byte(c, 'c') }
57
+ end
58
+
59
+ def test_signal_hangup
60
+ [:hangup, 'hangup'].each { |c| assert_expected_byte(c, 'h') }
61
+ end
62
+
63
+ def test_signal_HUP
64
+ [:HUP, 'HUP'].each { |c| assert_expected_byte(c, 'h') }
65
+ end
66
+
67
+ def test_signal_alarm
68
+ [:alarm, 'alarm'].each { |c| assert_expected_byte(c, 'a') }
69
+ end
70
+
71
+ def test_signal_ALRM
72
+ [:ALRM, 'ALRM'].each { |c| assert_expected_byte(c, 'a') }
73
+ end
74
+
75
+ def test_signal_interrupt
76
+ [:interrupt, 'interrupt'].each { |c| assert_expected_byte(c, 'i') }
77
+ end
78
+
79
+ def test_signal_INT
80
+ [:INT, 'INT'].each { |c| assert_expected_byte(c, 'i') }
81
+ end
82
+
83
+ def test_signal_terminate
84
+ [:terminate, 'terminate'].each { |c| assert_expected_byte(c, 't') }
85
+ end
86
+
87
+ def test_signal_TERM
88
+ [:TERM, 'TERM'].each { |c| assert_expected_byte(c, 't') }
89
+ end
90
+
91
+ def test_signal_kill
92
+ [:kill, 'kill'].each { |c| assert_expected_byte(c, 'k') }
93
+ end
94
+
95
+ def test_signal_KILL
96
+ [:KILL, 'KILL'].each { |c| assert_expected_byte(c, 'k') }
97
+ end
98
+
99
+ def test_signal_exit
100
+ [:exit, 'exit'].each { |c| assert_expected_byte(c, 'x') }
101
+ end
102
+
103
+ def test_signal_user1
104
+ [:user1, 'user1'].each { |c| assert_expected_byte(c, '1') }
105
+ end
106
+
107
+ def test_signal_USR1
108
+ [:USR1, 'USR1'].each { |c| assert_expected_byte(c, '1') }
109
+ end
110
+
111
+ def test_signal_user2
112
+ [:user2, 'user2'].each { |c| assert_expected_byte(c, '2') }
113
+ end
114
+
115
+ def test_signal_USR2
116
+ [:USR2, 'USR2'].each { |c| assert_expected_byte(c, '2') }
117
+ end
118
+
119
+ private
120
+
121
+ def assert_expected_byte(signal, expected)
122
+ @svdir.signal(signal)
123
+ byte = fifo_control.sysread(1)
124
+ assert_equal byte, expected,
125
+ "read #{byte} after SvDir#signal(#{signal.inspect}), expected #{expected}"
126
+ end
127
+
128
+ end
@@ -0,0 +1,548 @@
1
+ # Test the basics of service status interrogation
2
+ #
3
+ # Author:: Mike Pomraning
4
+ # Copyright:: Copyright (c) 2011 Qualys, Inc.
5
+ # License:: MIT (see the file LICENSE)
6
+ #
7
+
8
+ require 'testbase'
9
+ require 'sys/sv/svdir'
10
+
11
+ class TC_down_0_normd_nowant < Test::Unit::TestCase
12
+ include_fixture :PrefabSvDir
13
+
14
+ def test_down?
15
+ assert_equal(@svdir.down?, true)
16
+ end
17
+
18
+ def test_want_up?
19
+ assert_equal(@svdir.want_up?, false)
20
+ end
21
+
22
+ def test_pid
23
+ assert(@svdir.pid.nil?)
24
+ end
25
+
26
+ def test_want_down?
27
+ assert_equal(@svdir.want_down?, false)
28
+ end
29
+
30
+ def test_normally_up?
31
+ assert_equal(@svdir.normally_up?, false)
32
+ end
33
+
34
+ def test_paused?
35
+ assert_equal(@svdir.paused?, false)
36
+ end
37
+
38
+ def test_normally_down?
39
+ assert_equal(@svdir.normally_down?, true)
40
+ end
41
+
42
+ def test_up?
43
+ assert_equal(@svdir.up?, false)
44
+ end
45
+
46
+ def test_downtime
47
+ assert_elapsed_time(@svdir.downtime)
48
+ end
49
+
50
+ def test_uptime
51
+ assert(@svdir.uptime.nil?, "uptime was not nil")
52
+ end
53
+ end
54
+
55
+
56
+ class TC_down_0_normu_nowant < Test::Unit::TestCase
57
+ include_fixture :PrefabSvDir
58
+
59
+ def test_down?
60
+ assert_equal(@svdir.down?, true)
61
+ end
62
+
63
+ def test_want_up?
64
+ assert_equal(@svdir.want_up?, false)
65
+ end
66
+
67
+ def test_pid
68
+ assert(@svdir.pid.nil?)
69
+ end
70
+
71
+ def test_want_down?
72
+ assert_equal(@svdir.want_down?, false)
73
+ end
74
+
75
+ def test_normally_up?
76
+ assert_equal(@svdir.normally_up?, true)
77
+ end
78
+
79
+ def test_paused?
80
+ assert_equal(@svdir.paused?, false)
81
+ end
82
+
83
+ def test_normally_down?
84
+ assert_equal(@svdir.normally_down?, false)
85
+ end
86
+
87
+ def test_up?
88
+ assert_equal(@svdir.up?, false)
89
+ end
90
+
91
+ def test_downtime
92
+ assert_elapsed_time(@svdir.downtime)
93
+ end
94
+
95
+ def test_uptime
96
+ assert(@svdir.uptime.nil?, "uptime was not nil")
97
+ end
98
+ end
99
+
100
+
101
+ class TC_up_12526_normu_wantd < Test::Unit::TestCase
102
+ include_fixture :PrefabSvDir
103
+
104
+ def test_down?
105
+ assert_equal(@svdir.down?, false)
106
+ end
107
+
108
+ def test_want_up?
109
+ assert_equal(@svdir.want_up?, false)
110
+ end
111
+
112
+ def test_pid
113
+ assert_equal(@svdir.pid, 12526)
114
+ end
115
+
116
+ def test_want_down?
117
+ assert_equal(@svdir.want_down?, true)
118
+ end
119
+
120
+ def test_normally_up?
121
+ assert_equal(@svdir.normally_up?, true)
122
+ end
123
+
124
+ def test_paused?
125
+ assert_equal(@svdir.paused?, false)
126
+ end
127
+
128
+ def test_normally_down?
129
+ assert_equal(@svdir.normally_down?, false)
130
+ end
131
+
132
+ def test_up?
133
+ assert_equal(@svdir.up?, true)
134
+ end
135
+
136
+ def test_downtime
137
+ assert(@svdir.downtime.nil?, "downtime was not nil")
138
+ end
139
+
140
+ def test_uptime
141
+ assert_elapsed_time(@svdir.uptime)
142
+ end
143
+ end
144
+
145
+
146
+ class TC_up_12581_normd_wantd_paused < Test::Unit::TestCase
147
+ include_fixture :PrefabSvDir
148
+
149
+ def test_down?
150
+ assert_equal(@svdir.down?, false)
151
+ end
152
+
153
+ def test_want_up?
154
+ assert_equal(@svdir.want_up?, false)
155
+ end
156
+
157
+ def test_pid
158
+ assert_equal(@svdir.pid, 12581)
159
+ end
160
+
161
+ def test_want_down?
162
+ assert_equal(@svdir.want_down?, true)
163
+ end
164
+
165
+ def test_normally_up?
166
+ assert_equal(@svdir.normally_up?, false)
167
+ end
168
+
169
+ def test_paused?
170
+ assert_equal(@svdir.paused?, true)
171
+ end
172
+
173
+ def test_normally_down?
174
+ assert_equal(@svdir.normally_down?, true)
175
+ end
176
+
177
+ def test_up?
178
+ assert_equal(@svdir.up?, true)
179
+ end
180
+
181
+ def test_downtime
182
+ assert(@svdir.downtime.nil?, "downtime was not nil")
183
+ end
184
+
185
+ def test_uptime
186
+ assert_elapsed_time(@svdir.uptime)
187
+ end
188
+ end
189
+
190
+
191
+ class TC_up_12581_normu_wantd_paused < Test::Unit::TestCase
192
+ include_fixture :PrefabSvDir
193
+
194
+ def test_down?
195
+ assert_equal(@svdir.down?, false)
196
+ end
197
+
198
+ def test_want_up?
199
+ assert_equal(@svdir.want_up?, false)
200
+ end
201
+
202
+ def test_pid
203
+ assert_equal(@svdir.pid, 12581)
204
+ end
205
+
206
+ def test_want_down?
207
+ assert_equal(@svdir.want_down?, true)
208
+ end
209
+
210
+ def test_normally_up?
211
+ assert_equal(@svdir.normally_up?, true)
212
+ end
213
+
214
+ def test_paused?
215
+ assert_equal(@svdir.paused?, true)
216
+ end
217
+
218
+ def test_normally_down?
219
+ assert_equal(@svdir.normally_down?, false)
220
+ end
221
+
222
+ def test_up?
223
+ assert_equal(@svdir.up?, true)
224
+ end
225
+
226
+ def test_downtime
227
+ assert(@svdir.downtime.nil?, "downtime was not nil")
228
+ end
229
+
230
+ def test_uptime
231
+ assert_elapsed_time(@svdir.uptime)
232
+ end
233
+ end
234
+
235
+
236
+ class TC_up_12816_normd_nowant < Test::Unit::TestCase
237
+ include_fixture :PrefabSvDir
238
+
239
+ def test_down?
240
+ assert_equal(@svdir.down?, false)
241
+ end
242
+
243
+ def test_want_up?
244
+ assert_equal(@svdir.want_up?, false)
245
+ end
246
+
247
+ def test_pid
248
+ assert_equal(@svdir.pid, 12816)
249
+ end
250
+
251
+ def test_want_down?
252
+ assert_equal(@svdir.want_down?, false)
253
+ end
254
+
255
+ def test_normally_up?
256
+ assert_equal(@svdir.normally_up?, false)
257
+ end
258
+
259
+ def test_paused?
260
+ assert_equal(@svdir.paused?, false)
261
+ end
262
+
263
+ def test_normally_down?
264
+ assert_equal(@svdir.normally_down?, true)
265
+ end
266
+
267
+ def test_up?
268
+ assert_equal(@svdir.up?, true)
269
+ end
270
+
271
+ def test_downtime
272
+ assert(@svdir.downtime.nil?, "downtime was not nil")
273
+ end
274
+
275
+ def test_uptime
276
+ assert_elapsed_time(@svdir.uptime)
277
+ end
278
+ end
279
+
280
+
281
+ class TC_up_12816_normu_nowant < Test::Unit::TestCase
282
+ include_fixture :PrefabSvDir
283
+
284
+ def test_down?
285
+ assert_equal(@svdir.down?, false)
286
+ end
287
+
288
+ def test_want_up?
289
+ assert_equal(@svdir.want_up?, false)
290
+ end
291
+
292
+ def test_pid
293
+ assert_equal(@svdir.pid, 12816)
294
+ end
295
+
296
+ def test_want_down?
297
+ assert_equal(@svdir.want_down?, false)
298
+ end
299
+
300
+ def test_normally_up?
301
+ assert_equal(@svdir.normally_up?, true)
302
+ end
303
+
304
+ def test_paused?
305
+ assert_equal(@svdir.paused?, false)
306
+ end
307
+
308
+ def test_normally_down?
309
+ assert_equal(@svdir.normally_down?, false)
310
+ end
311
+
312
+ def test_up?
313
+ assert_equal(@svdir.up?, true)
314
+ end
315
+
316
+ def test_downtime
317
+ assert(@svdir.downtime.nil?, "downtime was not nil")
318
+ end
319
+
320
+ def test_uptime
321
+ assert_elapsed_time(@svdir.uptime)
322
+ end
323
+ end
324
+
325
+
326
+ class TC_up_12868_normd_wantu < Test::Unit::TestCase
327
+ include_fixture :PrefabSvDir
328
+
329
+ def test_down?
330
+ assert_equal(@svdir.down?, false)
331
+ end
332
+
333
+ def test_want_up?
334
+ assert_equal(@svdir.want_up?, true)
335
+ end
336
+
337
+ def test_pid
338
+ assert_equal(@svdir.pid, 12868)
339
+ end
340
+
341
+ def test_want_down?
342
+ assert_equal(@svdir.want_down?, false)
343
+ end
344
+
345
+ def test_normally_up?
346
+ assert_equal(@svdir.normally_up?, false)
347
+ end
348
+
349
+ def test_paused?
350
+ assert_equal(@svdir.paused?, false)
351
+ end
352
+
353
+ def test_normally_down?
354
+ assert_equal(@svdir.normally_down?, true)
355
+ end
356
+
357
+ def test_up?
358
+ assert_equal(@svdir.up?, true)
359
+ end
360
+
361
+ def test_downtime
362
+ assert(@svdir.downtime.nil?, "downtime was not nil")
363
+ end
364
+
365
+ def test_uptime
366
+ assert_elapsed_time(@svdir.uptime)
367
+ end
368
+ end
369
+
370
+
371
+ class TC_up_12868_normd_wantu_paused < Test::Unit::TestCase
372
+ include_fixture :PrefabSvDir
373
+
374
+ def test_down?
375
+ assert_equal(@svdir.down?, false)
376
+ end
377
+
378
+ def test_want_up?
379
+ assert_equal(@svdir.want_up?, true)
380
+ end
381
+
382
+ def test_pid
383
+ assert_equal(@svdir.pid, 12868)
384
+ end
385
+
386
+ def test_want_down?
387
+ assert_equal(@svdir.want_down?, false)
388
+ end
389
+
390
+ def test_normally_up?
391
+ assert_equal(@svdir.normally_up?, false)
392
+ end
393
+
394
+ def test_paused?
395
+ assert_equal(@svdir.paused?, true)
396
+ end
397
+
398
+ def test_normally_down?
399
+ assert_equal(@svdir.normally_down?, true)
400
+ end
401
+
402
+ def test_up?
403
+ assert_equal(@svdir.up?, true)
404
+ end
405
+
406
+ def test_downtime
407
+ assert(@svdir.downtime.nil?, "downtime was not nil")
408
+ end
409
+
410
+ def test_uptime
411
+ assert_elapsed_time(@svdir.uptime)
412
+ end
413
+ end
414
+
415
+
416
+ class TC_up_12868_normu_wantu < Test::Unit::TestCase
417
+ include_fixture :PrefabSvDir
418
+
419
+ def test_down?
420
+ assert_equal(@svdir.down?, false)
421
+ end
422
+
423
+ def test_want_up?
424
+ assert_equal(@svdir.want_up?, true)
425
+ end
426
+
427
+ def test_pid
428
+ assert_equal(@svdir.pid, 12868)
429
+ end
430
+
431
+ def test_want_down?
432
+ assert_equal(@svdir.want_down?, false)
433
+ end
434
+
435
+ def test_normally_up?
436
+ assert_equal(@svdir.normally_up?, true)
437
+ end
438
+
439
+ def test_paused?
440
+ assert_equal(@svdir.paused?, false)
441
+ end
442
+
443
+ def test_normally_down?
444
+ assert_equal(@svdir.normally_down?, false)
445
+ end
446
+
447
+ def test_up?
448
+ assert_equal(@svdir.up?, true)
449
+ end
450
+
451
+ def test_downtime
452
+ assert(@svdir.downtime.nil?, "downtime was not nil")
453
+ end
454
+
455
+ def test_uptime
456
+ assert_elapsed_time(@svdir.uptime)
457
+ end
458
+ end
459
+
460
+
461
+ class TC_up_12868_normu_wantu_paused < Test::Unit::TestCase
462
+ include_fixture :PrefabSvDir
463
+
464
+ def test_down?
465
+ assert_equal(@svdir.down?, false)
466
+ end
467
+
468
+ def test_want_up?
469
+ assert_equal(@svdir.want_up?, true)
470
+ end
471
+
472
+ def test_pid
473
+ assert_equal(@svdir.pid, 12868)
474
+ end
475
+
476
+ def test_want_down?
477
+ assert_equal(@svdir.want_down?, false)
478
+ end
479
+
480
+ def test_normally_up?
481
+ assert_equal(@svdir.normally_up?, true)
482
+ end
483
+
484
+ def test_paused?
485
+ assert_equal(@svdir.paused?, true)
486
+ end
487
+
488
+ def test_normally_down?
489
+ assert_equal(@svdir.normally_down?, false)
490
+ end
491
+
492
+ def test_up?
493
+ assert_equal(@svdir.up?, true)
494
+ end
495
+
496
+ def test_downtime
497
+ assert(@svdir.downtime.nil?, "downtime was not nil")
498
+ end
499
+
500
+ def test_uptime
501
+ assert_elapsed_time(@svdir.uptime)
502
+ end
503
+ end
504
+
505
+
506
+ class TC_up_16464_normd_wantd < Test::Unit::TestCase
507
+ include_fixture :PrefabSvDir
508
+
509
+ def test_down?
510
+ assert_equal(@svdir.down?, false)
511
+ end
512
+
513
+ def test_want_up?
514
+ assert_equal(@svdir.want_up?, false)
515
+ end
516
+
517
+ def test_pid
518
+ assert_equal(@svdir.pid, 16464)
519
+ end
520
+
521
+ def test_want_down?
522
+ assert_equal(@svdir.want_down?, true)
523
+ end
524
+
525
+ def test_normally_up?
526
+ assert_equal(@svdir.normally_up?, false)
527
+ end
528
+
529
+ def test_paused?
530
+ assert_equal(@svdir.paused?, false)
531
+ end
532
+
533
+ def test_normally_down?
534
+ assert_equal(@svdir.normally_down?, true)
535
+ end
536
+
537
+ def test_up?
538
+ assert_equal(@svdir.up?, true)
539
+ end
540
+
541
+ def test_downtime
542
+ assert(@svdir.downtime.nil?, "downtime was not nil")
543
+ end
544
+
545
+ def test_uptime
546
+ assert_elapsed_time(@svdir.uptime)
547
+ end
548
+ end