~ubuntu-branches/debian/sid/resource-agents/sid

« back to all changes in this revision

Viewing changes to tools/ocft/ocft.in

  • Committer: Package Import Robot
  • Author(s): Martin Loschwitz
  • Date: 2012-10-09 11:16:59 UTC
  • mfrom: (3.1.1)
  • Revision ID: package-import@ubuntu.com-20121009111659-jrcwfqskcbh0iuio
Tags: 1:3.9.3+git20121009-1
* New upstream version
* debian/patches/01_docbook_patch.patch: Refactored for new release
* debian/patches/02_spelling_fixes.patch.new: Refatored for new release
* debian/control: Bumped Standards-Version to 3.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
2
 
3
 
# Copyright (c) 2010 Novell Inc, John Shi
 
3
# Copyright (c) 2010-2011 Novell Inc, John Shi
4
4
#           All Rights Reserved.
5
5
#
6
6
# This program is free software; you can redistribute it and/or modify
121
121
    die "${agent}: configuration file not found."
122
122
  fi
123
123
 
124
 
  rm -f $CASES_DIR/${agent}_macro.*
125
 
  rm -f $CASES_DIR/${agent}.preparse
126
 
 
127
124
  line_num=0
128
125
  while read -r line; do
129
126
    let line_num++
162
159
    esac
163
160
 
164
161
    if [ -n "$macro" ]; then
165
 
      if ! touch "$macro"; then
166
 
        die "No permission to create macro file: ${macro}."
167
 
      fi
168
162
      echo "$line$num" >>"$macro"
169
163
    else
170
 
      echo "$line$num" >>"$CASES_DIR/${agent}.preparse"
 
164
      echo "$line$num" >>"$CASES_DIR/${agent}_preparse"
171
165
    fi
172
166
  done <"$opt_cfgsdir/$agent"
173
 
 
174
 
  rm -f $CASES_DIR/${agent}_macro.*
175
167
}
176
168
 
177
169
case_finish()
180
172
 
181
173
  if [ -n "$sh" ]; then
182
174
    cat >>$sh <<EOF
183
 
if [ -n "\$OCFT_VERBOSE" ]; then
 
175
if [ -n "\$__OCFT__VERBOSE" ]; then
184
176
  echo
185
177
fi
186
 
# Clean up and exit
 
178
# Cleanup and exit
187
179
EOF
188
180
    for host in $hosts; do
189
181
      echo "backbash_stop $host" >>$sh
190
182
    done
191
183
    echo "quit 0" >>$sh
192
184
  fi
 
185
 
193
186
  atexit_num=0
194
187
  hosts=
195
188
  sh=
196
189
}
197
190
 
 
191
agent_finish()
 
192
{
 
193
  rm -f $CASES_DIR/${agent}_preparse
 
194
  rm -f $CASES_DIR/${agent}_macro.*
 
195
  rm -f $CASES_DIR/${agent}_setup
 
196
  rm -f $CASES_DIR/${agent}_cleanup
 
197
  rm -f $CASES_DIR/${agent}_var
 
198
  rm -f $CASES_DIR/${agent}_hosts
 
199
  cfg_agent=
 
200
  cfg_agent_root=
 
201
  cfg_install_package=()
 
202
  cfg_hang_timeout=20
 
203
}
 
204
 
198
205
parse_cfg()
199
206
{
200
207
  local agents i line stat sh trunk branch atexit_num host hosts
206
213
  fi
207
214
 
208
215
  for agent in "${agents[@]}"; do
 
216
    rm -f $CASES_DIR/*_${agent}.sh
 
217
    agent_finish
 
218
 
209
219
    i=0
210
220
    agent="$(basename "$agent")"
211
 
    rm -f $CASES_DIR/*_${agent}.sh
212
 
    rm -f $CASES_DIR/${agent}_setup
213
221
 
214
222
    echo "Making '$agent': "
215
223
    preparse_cfg "$agent"
225
233
          stat=1
226
234
          continue
227
235
          ;;
 
236
        VARIABLE)
 
237
          case_finish
 
238
          stat=2
 
239
          continue
 
240
          ;;
228
241
        SETUP-AGENT)
229
242
          case_finish
230
 
          stat=2
 
243
          stat=3
 
244
          continue
 
245
          ;;
 
246
        CLEANUP-AGENT)
 
247
          case_finish
 
248
          stat=4
231
249
          continue
232
250
          ;;
233
251
        CASE)
234
252
          case_finish
235
253
          trunk2branch
 
254
          echo "    - case ${i}: ${branch[0]}"
236
255
          sh="$CASES_DIR/${i}_${agent}.sh"
237
 
          echo "    - case ${i}: ${branch[0]}"
238
256
          cat >$sh <<EOF
239
257
#!/bin/bash
240
258
 
241
 
# Agent:   $agent
 
259
# Agent:   $cfg_agent
242
260
# Summary: ${branch[0]}
243
261
 
244
262
. $OCFT_DIR/caselib || {
246
264
  exit 2
247
265
}
248
266
 
249
 
MYROOT="$cfg_agent_root"
250
 
EOF
251
 
          if [ -n "$cfg_install_package" ]; then
252
 
            cat >>$sh <<EOF
253
 
agent_install ${cfg_install_package[@]}
254
 
EOF
255
 
          fi
256
 
          if [ -r "$CASES_DIR/${agent}_setup" ]; then
257
 
            cat >>$sh <<EOF
258
 
agent_setup $agent <<'CMD'
259
 
$(cat "$CASES_DIR/${agent}_setup")
260
 
CMD
261
 
EOF
262
 
          fi
263
 
          cat >>$sh <<EOF
264
 
if [ -n "\$OCFT_VERBOSE" ]; then
 
267
$(test -r $CASES_DIR/${agent}_var && cat $CASES_DIR/${agent}_var)
 
268
 
 
269
__OCFT__MYROOT="$cfg_agent_root"
 
270
 
 
271
$(test -n "$cfg_install_package" && echo "agent_install ${cfg_install_package[@]}")
 
272
 
 
273
if [ -n "\$__OCFT__VERBOSE" ]; then
265
274
  echo -e $(add_quotes 1 "Starting '\\033[33m${agent}\\033[0m' case $i '\\033[33m${branch[0]}\\033[0m':")
266
275
else
267
276
  echo -n "'${agent}' case ${i}: "
268
277
fi
269
278
EOF
270
279
          chmod a+x $sh
 
280
 
271
281
          let i++
272
 
          stat=3
 
282
          stat=5
273
283
          continue
274
284
          ;;
275
285
      esac
277
287
      case "$stat" in
278
288
        1)
279
289
          case "${trunk[0]}" in
 
290
            Agent)
 
291
              trunk2branch
 
292
              cfg_agent="${branch[0]}"
 
293
              ;;
280
294
            AgentRoot)
281
295
              trunk2branch
282
296
              cfg_agent_root="${branch[0]}"
283
297
              ;;
284
298
            InstallPackage)
285
299
              trunk2branch
286
 
              cfg_install_package=("${branch[@]}")
 
300
              cfg_install_package=(${cfg_install_package[@]} ${branch[@]})
287
301
              ;;
288
302
            HangTimeout)
289
303
              trunk2branch
298
312
          esac
299
313
          ;;
300
314
        2)
 
315
          if echo "$line" | grep -q '^__OCFT__'; then
 
316
            parse_die "reserved key word '__OCFT__'."
 
317
          fi
 
318
          echo "declare $line" >>$CASES_DIR/${agent}_var
 
319
          ;;
 
320
        3)
301
321
          echo "$line" >>$CASES_DIR/${agent}_setup
302
322
          ;;
303
 
        3)
 
323
        4)
 
324
          echo "$line" >>$CASES_DIR/${agent}_cleanup
 
325
          ;;
 
326
        5)
304
327
          host=$(echo ${trunk[0]} | awk -F@ '{print $2}')
305
328
          if [ -n "$host" ]; then
306
329
            if ! echo "$hosts" | grep -q "$host"; then
 
330
              echo "$host" >>$CASES_DIR/${agent}_hosts
307
331
              hosts=$hosts$'\n'$host
308
332
              cat >>$sh <<EOF
309
333
# Initialize remote shell
310
334
backbash_start $host
311
335
backbash $host <<CMD
312
 
OCFT_VERBOSE=\$OCFT_VERBOSE
313
 
showhost="${host}: "
 
336
__OCFT__VERBOSE=\$__OCFT__VERBOSE
314
337
CMD
315
338
backbash $host <$OCFT_DIR/caselib
316
339
backbash $host <<'CMD'
317
 
MYROOT="$cfg_agent_root"
318
 
EOF
319
 
              if [ -n "$cfg_install_package" ]; then
320
 
                cat >>$sh <<EOF
321
 
agent_install ${cfg_install_package[@]}
322
 
EOF
323
 
              fi
324
 
              if [ -r "$CASES_DIR/${agent}_setup" ]; then
325
 
                cat >>$sh <<EOF
326
 
agent_setup $agent <<'END'
327
 
$(cat "$CASES_DIR/${agent}_setup")
328
 
END
329
 
EOF
330
 
              fi
331
 
              echo "CMD" >>$sh
 
340
$(test -r $CASES_DIR/${agent}_var && cat $CASES_DIR/${agent}_var)
 
341
 
 
342
__OCFT__MYROOT="$cfg_agent_root"
 
343
__OCFT__showhost="${host}: "
 
344
 
 
345
$(test -n "$cfg_install_package" && echo "agent_install ${cfg_install_package[@]}")
 
346
CMD
 
347
EOF
332
348
            fi
333
349
          fi
334
350
 
340
356
          fi
341
357
 
342
358
          case "${trunk[0]}" in
343
 
            Var|Var@*)
 
359
            Env|Env@*)
344
360
              cat >>$sh <<EOF
345
 
if [ -n "\$OCFT_VERBOSE" ]; then
346
 
  echo $(add_quotes 2 "    \${showhost}Setting agent environment:    export ${trunk[1]}")
 
361
if [ -n "\$__OCFT__VERBOSE" ]; then
 
362
  echo $(add_quotes 2 "    \${__OCFT__showhost}Setting agent environment:    export ${trunk[1]}")
347
363
fi
348
364
export ${trunk[1]}
349
365
check_success \$? $(add_quotes 1 "export ${trunk[1]}")
350
366
EOF
351
367
              ;;
352
 
            Unvar|Unvar@*)
 
368
            Unenv|Unenv@*)
353
369
              cat >>$sh <<EOF
354
 
if [ -n "\$OCFT_VERBOSE" ]; then
355
 
  echo $(add_quotes 2 "    \${showhost}Removing agent environment:   unset ${trunk[1]}")
 
370
if [ -n "\$__OCFT__VERBOSE" ]; then
 
371
  echo $(add_quotes 2 "    \${__OCFT__showhost}Removing agent environment:   unset ${trunk[1]}")
356
372
fi
357
373
unset ${trunk[1]}
358
374
check_success \$? $(add_quotes 1 "unset ${trunk[1]}")
363
379
              if [ -z "${branch[1]}" ]; then
364
380
                if [ "${branch[0]}" = "start" ]; then
365
381
                  cat >>$sh <<EOF
366
 
agent_run $(add_quotes 1 "$agent") status $cfg_hang_timeout
367
 
rc=\$?
368
 
if [ \$rc -eq \$OCF_ERR_UNIMPLEMENTED ]; then
369
 
  agent_run $(add_quotes 1 "$agent") monitor $cfg_hang_timeout
370
 
  rc=\$?
371
 
fi
 
382
agent_run $(add_quotes 1 "$cfg_agent") monitor $cfg_hang_timeout
 
383
__OCFT__rc=\$?
372
384
 
373
 
if [ \$rc -eq \$OCF_SUCCESS ]; then
 
385
if [ \$__OCFT__rc -eq \$OCF_SUCCESS -o \$__OCFT__rc -eq \$OCF_RUNNING_MASTER ]; then
374
386
  : #The status I want, so I can do nothing.
375
 
elif [ \$rc -eq \$OCF_NOT_RUNNING ]; then
376
 
  if [ -n "\$OCFT_VERBOSE" ]; then
377
 
    echo $(add_quotes 2 "    \${showhost}Running agent:                ./$agent start")
 
387
elif [ \$__OCFT__rc -eq \$OCF_NOT_RUNNING ]; then
 
388
  if [ -n "\$__OCFT__VERBOSE" ]; then
 
389
    echo $(add_quotes 2 "    \${__OCFT__showhost}Running agent:                ./$cfg_agent ${branch[0]}")
378
390
  fi
379
 
  agent_run $(add_quotes 1 "$agent") start $cfg_hang_timeout
380
 
  check_success \$? $(add_quotes 1 "./$agent start")
 
391
  agent_run $(add_quotes 1 "$cfg_agent") start $cfg_hang_timeout
 
392
  check_success \$? $(add_quotes 1 "./$cfg_agent ${branch[0]}")
381
393
else
382
 
  check_success \$rc $(add_quotes 1 "./$agent status|monitor")
 
394
  check_success \$__OCFT__rc $(add_quotes 1 "./$cfg_agent monitor")
383
395
fi
384
396
EOF
385
397
                elif [ "${branch[0]}" = "stop" ]; then
386
398
                  cat >>$sh <<EOF
387
 
agent_run $(add_quotes 1 "$agent") status $cfg_hang_timeout
388
 
rc=\$?
389
 
if [ \$rc -eq \$OCF_ERR_UNIMPLEMENTED ]; then
390
 
  agent_run $(add_quotes 1 "$agent") monitor $cfg_hang_timeout
391
 
  rc=\$?
392
 
fi
 
399
agent_run $(add_quotes 1 "$cfg_agent") monitor $cfg_hang_timeout
 
400
__OCFT__rc=\$?
393
401
 
394
 
if [ \$rc -eq \$OCF_NOT_RUNNING ]; then
 
402
if [ \$__OCFT__rc -eq \$OCF_NOT_RUNNING ]; then
395
403
  : #The status I want, so I can do nothing.
396
 
elif [ \$rc -eq \$OCF_SUCCESS ]; then
397
 
  if [ -n "\$OCFT_VERBOSE" ]; then
398
 
    echo $(add_quotes 2 "    \${showhost}Running agent:                ./$agent stop")
 
404
elif [ \$__OCFT__rc -eq \$OCF_SUCCESS -o \$__OCFT__rc -eq \$OCF_RUNNING_MASTER ]; then
 
405
  if [ -n "\$__OCFT__VERBOSE" ]; then
 
406
    echo $(add_quotes 2 "    \${__OCFT__showhost}Running agent:                ./$cfg_agent ${branch[0]}")
399
407
  fi
400
 
  agent_run $(add_quotes 1 "$agent") stop $cfg_hang_timeout
401
 
  check_success \$? $(add_quotes 1 "./$agent stop")
 
408
  agent_run $(add_quotes 1 "$cfg_agent") stop $cfg_hang_timeout
 
409
  check_success \$? $(add_quotes 1 "./$cfg_agent ${branch[0]}")
402
410
else
403
 
  check_success \$rc $(add_quotes 1 "./$agent status|monitor")
 
411
  check_success \$__OCFT__rc $(add_quotes 1 "./$cfg_agent monitor")
404
412
fi
405
413
EOF
406
 
                elif [ "${branch[0]}" = "status" -o "${branch[0]}" = "monitor" ]; then
 
414
                elif [ "${branch[0]}" = "monitor" ]; then
407
415
                  cat >>$sh <<EOF
408
 
agent_run $(add_quotes 1 "$agent") $(add_quotes 1 "${branch[0]}") $cfg_hang_timeout
 
416
if [ -n "\$__OCFT__VERBOSE" ]; then
 
417
  echo $(add_quotes 2 "    \${__OCFT__showhost}Running agent:                ./$cfg_agent ${branch[0]}")
 
418
fi
 
419
agent_run $(add_quotes 1 "$cfg_agent") $(add_quotes 1 "${branch[0]}") $cfg_hang_timeout
409
420
EOF
410
421
                else
411
422
                  cat >>$sh <<EOF
412
 
agent_run $(add_quotes 1 "$agent") $(add_quotes 1 "${branch[0]}") $cfg_hang_timeout
413
 
check_success \$? $(add_quotes 1 "./$agent ${branch[0]}")
 
423
if [ -n "\$__OCFT__VERBOSE" ]; then
 
424
  echo $(add_quotes 2 "    \${__OCFT__showhost}Running agent:                ./$cfg_agent ${branch[0]}")
 
425
fi
 
426
agent_run $(add_quotes 1 "$cfg_agent") $(add_quotes 1 "${branch[0]}") $cfg_hang_timeout
 
427
check_success \$? $(add_quotes 1 "./$cfg_agent ${branch[0]}")
414
428
EOF
415
429
                fi
416
430
              else
417
431
                cat >>$sh <<EOF
418
432
test -n $(add_quotes 2 "\$${branch[1]}")
419
433
check_success \$? $(add_quotes 1 "test -n \"\$${branch[1]}\"")
420
 
if [ -n "\$OCFT_VERBOSE" ]; then
421
 
  echo $(add_quotes 2 "    \${showhost}Running agent:                ./$agent ${branch[0]}")
422
 
fi
423
 
agent_run $(add_quotes 1 "$agent") $(add_quotes 1 "${branch[0]}") $cfg_hang_timeout
424
 
ret=\$?
425
 
if [ -n "\$OCFT_VERBOSE" ]; then
426
 
  echo -n "    \${showhost}Checking return value:"
427
 
fi
428
 
if [ -n "\${retval[ret]}" ]; then
429
 
  retstr="\${retval[ret]}"
 
434
if [ -n "\$__OCFT__VERBOSE" ]; then
 
435
  echo $(add_quotes 2 "    \${__OCFT__showhost}Running agent:                ./$cfg_agent ${branch[0]}")
 
436
fi
 
437
agent_run $(add_quotes 1 "$cfg_agent") $(add_quotes 1 "${branch[0]}") $cfg_hang_timeout
 
438
__OCFT__ret=\$?
 
439
if [ -n "\$__OCFT__VERBOSE" ]; then
 
440
  echo -n "    \${__OCFT__showhost}Checking return value:"
 
441
fi
 
442
if [ -n "\${__OCFT__retval[__OCFT__ret]}" ]; then
 
443
  __OCFT__retstr="\${__OCFT__retval[__OCFT__ret]}"
430
444
else
431
 
  retstr=\$ret
 
445
  __OCFT__retstr=\$__OCFT__ret
432
446
fi
433
 
if [ \$ret -eq \$${branch[1]} ]; then
434
 
  if [ -n "\$OCFT_VERBOSE" ]; then
435
 
    echo -e $(add_quotes 2 "        \\033[32mOK\\033[0m. The return value '\\033[34m\$retstr\\033[0m' == '\\033[34m${branch[1]}\\033[0m'")
 
447
if [ \$__OCFT__ret -eq \$${branch[1]} ]; then
 
448
  if [ -n "\$__OCFT__VERBOSE" ]; then
 
449
    echo -e $(add_quotes 2 "        \\033[32mOK\\033[0m. The return value '\\033[34m\$__OCFT__retstr\\033[0m' == '\\033[34m${branch[1]}\\033[0m'")
436
450
  else
437
451
    echo -e "\t\\033[32mOK\\033[0m."
438
452
  fi
439
453
else
440
 
  if [ -n "\$OCFT_VERBOSE" ]; then
441
 
    echo -en $(add_quotes 2 "        \\033[31mFAILED\\033[0m. The return value '\\033[34m\$retstr\\033[0m' != '\\033[34m${branch[1]}\\033[0m'. ")
 
454
  if [ -n "\$__OCFT__VERBOSE" ]; then
 
455
    echo -en $(add_quotes 2 "        \\033[31mFAILED\\033[0m. The return value '\\033[34m\$__OCFT__retstr\\033[0m' != '\\033[34m${branch[1]}\\033[0m'. ")
442
456
  else
443
 
    echo -en "\t\\033[31mFAILED\\033[0m. Agent returns unexpected value: '\$retstr'. "
 
457
    echo -en "\t\\033[31mFAILED\\033[0m. Agent returns unexpected value: '\$__OCFT__retstr'. "
444
458
  fi
445
459
  echo "See details below:"
446
460
  cat /tmp/.ocft_runlog
452
466
              ;;
453
467
            Bash|Bash@*)
454
468
              cat >>$sh <<EOF
455
 
if [ -n "\$OCFT_VERBOSE" ]; then
456
 
  echo $(add_quotes 2 "    \${showhost}Setting system environment:   ${trunk[1]}")
 
469
if [ -n "\$__OCFT__VERBOSE" ]; then
 
470
  echo $(add_quotes 2 "    \${__OCFT__showhost}Setting system environment:   ${trunk[1]}")
457
471
fi
458
 
echo $(add_quotes 1 "${trunk[1]}") | /bin/bash
 
472
${trunk[1]}
459
473
check_success \$? $(add_quotes 1 "${trunk[1]}")
460
474
EOF
461
475
              ;;
464
478
              cat >>$sh <<EOF
465
479
atexit${atexit_num}()
466
480
{
467
 
  if [ -n "\$OCFT_VERBOSE" ]; then
468
 
    echo $(add_quotes 2 "    \${showhost}Setting system environment:   ${trunk[1]}")
 
481
  if [ -n "\$__OCFT__VERBOSE" ]; then
 
482
    echo $(add_quotes 2 "    \${__OCFT__showhost}Setting system environment:   ${trunk[1]}")
469
483
  fi
470
 
  echo $(add_quotes 1 "${trunk[1]}") | /bin/bash
 
484
  ${trunk[1]}
471
485
}
472
 
let atexit_num++
 
486
let __OCFT__atexit_num++
473
487
EOF
474
488
              ;;
475
489
            *)
484
498
          parse_die "unimplemented statement: ${trunk[0]}"
485
499
          ;;
486
500
      esac
487
 
    done <$CASES_DIR/${agent}.preparse
488
 
    rm -f $CASES_DIR/${agent}.preparse
489
 
    rm -f $CASES_DIR/${agent}_setup
 
501
    done <$CASES_DIR/${agent}_preparse
 
502
 
 
503
    if [ -r "$CASES_DIR/${agent}_setup" ]; then
 
504
      cat >$CASES_DIR/setup_${agent}.sh <<EOF
 
505
#!/bin/bash
 
506
 
 
507
# Agent:   $cfg_agent
 
508
# Summary: SETUP before test
 
509
 
 
510
echo "Initializing '$cfg_agent' ..."
 
511
 
 
512
. $OCFT_DIR/caselib || {
 
513
  echo "ERROR: '$OCFT_DIR/caselib' not found."
 
514
  exit 2
 
515
}
 
516
 
 
517
$(test -r "$CASES_DIR/${agent}_var" && cat $CASES_DIR/${agent}_var)
 
518
$(test -n "$cfg_install_package" && echo "agent_install ${cfg_install_package[@]}")
 
519
 
 
520
EOF
 
521
      for host in $(test -r $CASES_DIR/${agent}_hosts && cat $CASES_DIR/${agent}_hosts); do
 
522
        cat >>$CASES_DIR/setup_${agent}.sh <<EOF
 
523
# Initialize remote shell
 
524
backbash_start $host
 
525
backbash $host <<CMD
 
526
__OCFT__VERBOSE=\$__OCFT__VERBOSE
 
527
CMD
 
528
backbash $host <$OCFT_DIR/caselib
 
529
backbash $host <<'CMD'
 
530
$(test -r "$CASES_DIR/${agent}_var" && cat $CASES_DIR/${agent}_var)
 
531
 
 
532
__OCFT__MYROOT="$cfg_agent_root"
 
533
__OCFT__showhost="${host}: "
 
534
 
 
535
$(test -n "$cfg_install_package" && echo "agent_install ${cfg_install_package[@]}")
 
536
 
 
537
$(cat $CASES_DIR/${agent}_setup)
 
538
check_success \$? "SETUP-AGENT"
 
539
CMD
 
540
backbash_stop $host 
 
541
EOF
 
542
      done
 
543
      cat >>$CASES_DIR/setup_${agent}.sh <<EOF
 
544
$(cat $CASES_DIR/${agent}_setup)
 
545
check_success \$? "SETUP-AGENT"
 
546
 
 
547
echo "Done."
 
548
echo
 
549
quit 0
 
550
EOF
 
551
      chmod a+x $CASES_DIR/setup_${agent}.sh
 
552
    fi
 
553
 
 
554
    if [ -r "$CASES_DIR/${agent}_cleanup" ]; then
 
555
      cat >$CASES_DIR/cleanup_${agent}.sh <<EOF
 
556
#!/bin/bash
 
557
 
 
558
# Agent:   $cfg_agent
 
559
# Summary: CLEANUP after test
 
560
 
 
561
echo "Cleaning '$cfg_agent' ..."
 
562
 
 
563
. $OCFT_DIR/caselib || {
 
564
  echo "ERROR: '$OCFT_DIR/caselib' not found."
 
565
  exit 2
 
566
}
 
567
 
 
568
$(test -r "$CASES_DIR/${agent}_var" && cat $CASES_DIR/${agent}_var)
 
569
$(test -n "$cfg_install_package" && echo "agent_install ${cfg_install_package[@]}")
 
570
 
 
571
$(cat $CASES_DIR/${agent}_cleanup)
 
572
check_success \$? "CLEANUP-AGENT"
 
573
 
 
574
EOF
 
575
      for host in $(test -r $CASES_DIR/${agent}_hosts && cat $CASES_DIR/${agent}_hosts); do
 
576
        cat >>$CASES_DIR/cleanup_${agent}.sh <<EOF
 
577
# Initialize remote shell
 
578
backbash_start $host
 
579
backbash $host <<CMD
 
580
__OCFT__VERBOSE=\$__OCFT__VERBOSE
 
581
CMD
 
582
backbash $host <$OCFT_DIR/caselib
 
583
backbash $host <<'CMD'
 
584
$(test -r "$CASES_DIR/${agent}_var" && cat $CASES_DIR/${agent}_var)
 
585
 
 
586
__OCFT__MYROOT="$cfg_agent_root"
 
587
__OCFT__showhost="${host}: "
 
588
 
 
589
$(test -n "$cfg_install_package" && echo "agent_install ${cfg_install_package[@]}")
 
590
 
 
591
$(cat $CASES_DIR/${agent}_cleanup)
 
592
check_success \$? "CLEANUP-AGENT"
 
593
CMD
 
594
backbash_stop $host 
 
595
EOF
 
596
      done
 
597
      cat >>$CASES_DIR/cleanup_${agent}.sh <<EOF
 
598
echo "Done."
 
599
echo
 
600
quit 0
 
601
EOF
 
602
      chmod a+x $CASES_DIR/cleanup_${agent}.sh
 
603
    fi
490
604
    case_finish
 
605
    agent_finish
 
606
 
491
607
  done
492
608
}
493
609
 
494
610
start_test()
495
611
{
496
 
  local sh shs agents line ret
 
612
  local sh shs testsh agents line ret
497
613
 
498
614
  if ! cd $CASES_DIR >/dev/null 2>&1; then
499
615
    die "cases directory not found."
500
616
  fi
501
617
 
502
 
  export OCFT_VERBOSE=$opt_verbose
 
618
  export __OCFT__VERBOSE=$opt_verbose
503
619
 
504
620
  if [ $# -eq 0 ]; then
505
621
    agents=($(ls -1 *.sh 2>/dev/null | sed 's/.*_\([^_]*\)\.sh$/\1/' | sort | uniq))
508
624
  fi
509
625
 
510
626
  for shs in "${agents[@]}"; do
511
 
    for sh in $(ls -1 *_${shs}.sh 2>/dev/null | sort -n); do
512
 
      ./$sh
513
 
      ret=$?
514
 
      if [ $ret -eq 3 ]; then
515
 
        die "core function failed, break all tests."
516
 
      fi
517
 
      if [ $ret -eq 2 ]; then
518
 
        warn "core function failed, break all tests of '$shs'."
519
 
        break
 
627
    testsh="setup_${shs}.sh
 
628
$(ls -1 [0-9]*_${shs}.sh 2>/dev/null | sort -n)
 
629
cleanup_${shs}.sh"
 
630
    for sh in $testsh; do
 
631
      if [ -r "$sh" ]; then
 
632
        ./$sh
 
633
        ret=$?
 
634
        if [ $ret -eq 3 ]; then
 
635
          die "core function failed, break all tests."
 
636
        fi
 
637
        if [ $ret -eq 2 ]; then
 
638
          warn "core function failed, break all tests of '$shs'."
 
639
          break
 
640
        fi
520
641
      fi
521
642
    done
522
 
  done | while read -r line; do
 
643
  done 2>&1 | while read -r line; do
523
644
    echo "$line"
524
645
    echo "$(date '+%F %T'): $line" | cat -A |
525
646
    sed -r 's/\^\[\[[0-9]+m|\^I|.$//g' >>ocft.log
552
673
     clean           Delete the testing shell scripts.
553
674
     help [-v]       Show this help and exit.
554
675
                       -v  Show HOWTO and exit.
555
 
Version 0.42
 
676
Version 0.43
556
677
See '$OCFT_DIR/README' for detail.
557
678
EOF
558
679
}
571
692
    Hence it is useful to debuggers.
572
693
 
573
694
* Components
574
 
    ** Test case generator (@sbindir@/ocft)
 
695
    ** Test case generator (/usr/sbin/ocft)
575
696
      - Turning configuration files of test case to executable scripts.
576
697
 
577
698
    ** Configuration file  ($CONFIGS_DIR/)
615
736
line_num=
616
737
 
617
738
# default configuration
 
739
cfg_agent=
618
740
cfg_agent_root=
619
 
cfg_install_package=
 
741
cfg_install_package=()
620
742
cfg_hang_timeout=20
621
743
 
622
744
# default option