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

« back to all changes in this revision

Viewing changes to tools/ocft/ocft.in

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-06-10 16:26:35 UTC
  • Revision ID: james.westby@ubuntu.com-20110610162635-yiy0vfopqw4trzgx
Tags: upstream-3.9.0
ImportĀ upstreamĀ versionĀ 3.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
# Copyright (c) 2010 Novell Inc, John Shi
 
4
#           All Rights Reserved.
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of version 2 of the GNU General Public License as
 
8
# published by the Free Software Foundation.
 
9
#
 
10
# This program is distributed in the hope that it would be useful, but
 
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
13
#
 
14
# Further, this software is distributed without any warranty that it is
 
15
# free of the rightful claim of any third person regarding infringement
 
16
# or the like.  Any license provided herein, whether implied or
 
17
# otherwise, applies only to this software file.  Patent licenses, if
 
18
# any, provided herein do not apply to combinations of this program with
 
19
# other software, or any other product whatsoever.
 
20
#
 
21
# You should have received a copy of the GNU General Public License
 
22
# along with this program; if not, write the Free Software Foundation,
 
23
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
 
24
 
 
25
die()
 
26
{
 
27
  local str
 
28
  str="$1"
 
29
 
 
30
  echo "ERROR: $str" >&2
 
31
  exit 1
 
32
}
 
33
 
 
34
warn()
 
35
{
 
36
  local str
 
37
  str="$1"
 
38
 
 
39
  echo "WARNING: $str" >&2
 
40
}
 
41
 
 
42
parse_die()
 
43
{
 
44
  local str
 
45
  str="$1"
 
46
 
 
47
  die "${agent}: line ${line_num}: ${str}"
 
48
}
 
49
 
 
50
# add quotes to string for Here Documents
 
51
add_quotes()
 
52
{
 
53
  local typ str a b
 
54
  typ="$1"
 
55
  str="$2"
 
56
 
 
57
  case "$typ" in
 
58
    1) a=\'; b=\";;
 
59
    2) a=\"; b=\';;
 
60
  esac
 
61
 
 
62
  echo "$str" | sed "s/$a/$a$b$a$b$a/g; 1 s/^/$a/; $ s/$/$a/"
 
63
}
 
64
 
 
65
# split strings
 
66
explode()
 
67
{
 
68
  local str
 
69
  str="$1"
 
70
 
 
71
  echo "$str" | awk -F'"' '{
 
72
    if (NF > 0 && NF%2 == 0)
 
73
      exit(1);
 
74
    for (i=1; i<=NF; i++) {
 
75
      if (i%2 == 0)
 
76
        print $i;
 
77
      else {
 
78
        split($i, str, /[[:blank:]]+/);
 
79
        for (j=0; j<length(str); j++) {
 
80
          sb = sub(/#.*/, "", str[j]);
 
81
          if (str[j] != "")
 
82
            print str[j];
 
83
          if (sb)
 
84
            exit(0);
 
85
        }
 
86
      }
 
87
    }
 
88
  }'
 
89
}
 
90
 
 
91
# phase 1: parse the string to 'command' and 'argument collection'.
 
92
line2trunk()
 
93
{
 
94
  trunk[0]="${line%%[[:blank:]]*}"
 
95
  trunk[1]="${line#*[[:blank:]]}"
 
96
}
 
97
 
 
98
# phase 2: split the argument collection.
 
99
trunk2branch()
 
100
{
 
101
  local IFS
 
102
 
 
103
  # Some of statements need one parameter at least.
 
104
  if [ "$line" = "${trunk[0]}" ]; then
 
105
    parse_die "missing parameter."
 
106
  fi
 
107
 
 
108
  IFS=$'\n'
 
109
  branch=($(explode "${trunk[1]}"))
 
110
  if [ $? -ne 0 ]; then
 
111
    parse_die "missing '\"'."
 
112
  fi
 
113
}
 
114
 
 
115
preparse_cfg()
 
116
{
 
117
  local agent line trunk branch macro num host
 
118
  agent="$1"
 
119
 
 
120
  if [ ! -r "$opt_cfgsdir/$agent" ]; then
 
121
    die "${agent}: configuration file not found."
 
122
  fi
 
123
 
 
124
  rm -f $CASES_DIR/${agent}_macro.*
 
125
  rm -f $CASES_DIR/${agent}.preparse
 
126
 
 
127
  line_num=0
 
128
  while read -r line; do
 
129
    let line_num++
 
130
    num=" $line_num"
 
131
 
 
132
    case "$line" in
 
133
      ""|\#*) continue;;
 
134
    esac
 
135
 
 
136
    line2trunk
 
137
    case "${trunk[0]}" in
 
138
      CASE-BLOCK)
 
139
        trunk2branch
 
140
        macro="$CASES_DIR/${agent}_macro.${branch[0]}"
 
141
        continue
 
142
        ;;
 
143
      Include|Include@*)
 
144
        host=$(echo "${trunk[0]}" | awk -F@ '{print $2}')
 
145
        trunk2branch
 
146
        if [ ! -r "$CASES_DIR/${agent}_macro.${branch[0]}" ]; then
 
147
          parse_die "Macro '${branch[0]}' not found."
 
148
        fi
 
149
        if [ -n "$host" ]; then
 
150
          line="$(sed -e 's/^\([^[:blank:]]*\)@[^[:blank:]]*/\1/' -e "s/^[^[:blank:]]*/&@$host/" "$CASES_DIR/${agent}_macro.${branch[0]}")"
 
151
        else
 
152
          line="$(<"$CASES_DIR/${agent}_macro.${branch[0]}")"
 
153
        fi
 
154
        num=
 
155
        ;;
 
156
      *[!A-Z-]*)
 
157
        :
 
158
        ;;
 
159
      *)
 
160
        macro=
 
161
        ;;
 
162
    esac
 
163
 
 
164
    if [ -n "$macro" ]; then
 
165
      if ! touch "$macro"; then
 
166
        die "No permission to create macro file: ${macro}."
 
167
      fi
 
168
      echo "$line$num" >>"$macro"
 
169
    else
 
170
      echo "$line$num" >>"$CASES_DIR/${agent}.preparse"
 
171
    fi
 
172
  done <"$opt_cfgsdir/$agent"
 
173
 
 
174
  rm -f $CASES_DIR/${agent}_macro.*
 
175
}
 
176
 
 
177
case_finish()
 
178
{
 
179
  local host
 
180
 
 
181
  if [ -n "$sh" ]; then
 
182
    cat >>$sh <<EOF
 
183
if [ -n "\$OCFT_VERBOSE" ]; then
 
184
  echo
 
185
fi
 
186
# Clean up and exit
 
187
EOF
 
188
    for host in $hosts; do
 
189
      echo "backbash_stop $host" >>$sh
 
190
    done
 
191
    echo "quit 0" >>$sh
 
192
  fi
 
193
  atexit_num=0
 
194
  hosts=
 
195
  sh=
 
196
}
 
197
 
 
198
parse_cfg()
 
199
{
 
200
  local agents i line stat sh trunk branch atexit_num host hosts
 
201
 
 
202
  if [ $# -eq 0 ]; then
 
203
    agents=($opt_cfgsdir/*)
 
204
  else
 
205
    agents=("$@")
 
206
  fi
 
207
 
 
208
  for agent in "${agents[@]}"; do
 
209
    i=0
 
210
    agent="$(basename "$agent")"
 
211
    rm -f $CASES_DIR/*_${agent}.sh
 
212
    rm -f $CASES_DIR/${agent}_setup
 
213
 
 
214
    echo "Making '$agent': "
 
215
    preparse_cfg "$agent"
 
216
    while read -r line; do
 
217
      line_num="${line##* }"
 
218
      line="${line% *}"
 
219
      line2trunk
 
220
 
 
221
      # state switch
 
222
      case "${trunk[0]}" in
 
223
        CONFIG)
 
224
          case_finish
 
225
          stat=1
 
226
          continue
 
227
          ;;
 
228
        SETUP-AGENT)
 
229
          case_finish
 
230
          stat=2
 
231
          continue
 
232
          ;;
 
233
        CASE)
 
234
          case_finish
 
235
          trunk2branch
 
236
          sh="$CASES_DIR/${i}_${agent}.sh"
 
237
          echo "    - case ${i}: ${branch[0]}"
 
238
          cat >$sh <<EOF
 
239
#!/bin/bash
 
240
 
 
241
# Agent:   $agent
 
242
# Summary: ${branch[0]}
 
243
 
 
244
. $OCFT_DIR/caselib || {
 
245
  echo "ERROR: '$OCFT_DIR/caselib' not found."
 
246
  exit 2
 
247
}
 
248
 
 
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
 
265
  echo -e $(add_quotes 1 "Starting '\\033[33m${agent}\\033[0m' case $i '\\033[33m${branch[0]}\\033[0m':")
 
266
else
 
267
  echo -n "'${agent}' case ${i}: "
 
268
fi
 
269
EOF
 
270
          chmod a+x $sh
 
271
          let i++
 
272
          stat=3
 
273
          continue
 
274
          ;;
 
275
      esac
 
276
 
 
277
      case "$stat" in
 
278
        1)
 
279
          case "${trunk[0]}" in
 
280
            AgentRoot)
 
281
              trunk2branch
 
282
              cfg_agent_root="${branch[0]}"
 
283
              ;;
 
284
            InstallPackage)
 
285
              trunk2branch
 
286
              cfg_install_package=("${branch[@]}")
 
287
              ;;
 
288
            HangTimeout)
 
289
              trunk2branch
 
290
              if ! echo "${branch[0]}" | grep -qxE '[0-9]+'; then
 
291
                parse_die "numeric argument required."
 
292
              fi
 
293
              cfg_hang_timeout="${branch[0]}"
 
294
              ;;
 
295
            *)
 
296
              parse_die "unimplemented statement: ${trunk[0]}"
 
297
              ;;
 
298
          esac
 
299
          ;;
 
300
        2)
 
301
          echo "$line" >>$CASES_DIR/${agent}_setup
 
302
          ;;
 
303
        3)
 
304
          host=$(echo ${trunk[0]} | awk -F@ '{print $2}')
 
305
          if [ -n "$host" ]; then
 
306
            if ! echo "$hosts" | grep -q "$host"; then
 
307
              hosts=$hosts$'\n'$host
 
308
              cat >>$sh <<EOF
 
309
# Initialize remote shell
 
310
backbash_start $host
 
311
backbash $host <<CMD
 
312
OCFT_VERBOSE=\$OCFT_VERBOSE
 
313
showhost="${host}: "
 
314
CMD
 
315
backbash $host <$OCFT_DIR/caselib
 
316
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
 
332
            fi
 
333
          fi
 
334
 
 
335
          echo "
 
336
# CASE statement: $line" >>$sh
 
337
 
 
338
          if [ -n "$host" ]; then
 
339
            echo "backbash $host <<'CMD'" >>$sh
 
340
          fi
 
341
 
 
342
          case "${trunk[0]}" in
 
343
            Var|Var@*)
 
344
              cat >>$sh <<EOF
 
345
if [ -n "\$OCFT_VERBOSE" ]; then
 
346
  echo $(add_quotes 2 "    \${showhost}Setting agent environment:    export ${trunk[1]}")
 
347
fi
 
348
export ${trunk[1]}
 
349
check_success \$? $(add_quotes 1 "export ${trunk[1]}")
 
350
EOF
 
351
              ;;
 
352
            Unvar|Unvar@*)
 
353
              cat >>$sh <<EOF
 
354
if [ -n "\$OCFT_VERBOSE" ]; then
 
355
  echo $(add_quotes 2 "    \${showhost}Removing agent environment:   unset ${trunk[1]}")
 
356
fi
 
357
unset ${trunk[1]}
 
358
check_success \$? $(add_quotes 1 "unset ${trunk[1]}")
 
359
EOF
 
360
              ;;
 
361
            AgentRun|AgentRun@*)
 
362
              trunk2branch
 
363
              if [ -z "${branch[1]}" ]; then
 
364
                if [ "${branch[0]}" = "start" ]; then
 
365
                  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
 
372
 
 
373
if [ \$rc -eq \$OCF_SUCCESS ]; then
 
374
  : #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")
 
378
  fi
 
379
  agent_run $(add_quotes 1 "$agent") start $cfg_hang_timeout
 
380
  check_success \$? $(add_quotes 1 "./$agent start")
 
381
else
 
382
  check_success \$rc $(add_quotes 1 "./$agent status|monitor")
 
383
fi
 
384
EOF
 
385
                elif [ "${branch[0]}" = "stop" ]; then
 
386
                  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
 
393
 
 
394
if [ \$rc -eq \$OCF_NOT_RUNNING ]; then
 
395
  : #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")
 
399
  fi
 
400
  agent_run $(add_quotes 1 "$agent") stop $cfg_hang_timeout
 
401
  check_success \$? $(add_quotes 1 "./$agent stop")
 
402
else
 
403
  check_success \$rc $(add_quotes 1 "./$agent status|monitor")
 
404
fi
 
405
EOF
 
406
                elif [ "${branch[0]}" = "status" -o "${branch[0]}" = "monitor" ]; then
 
407
                  cat >>$sh <<EOF
 
408
agent_run $(add_quotes 1 "$agent") $(add_quotes 1 "${branch[0]}") $cfg_hang_timeout
 
409
EOF
 
410
                else
 
411
                  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]}")
 
414
EOF
 
415
                fi
 
416
              else
 
417
                cat >>$sh <<EOF
 
418
test -n $(add_quotes 2 "\$${branch[1]}")
 
419
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]}"
 
430
else
 
431
  retstr=\$ret
 
432
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'")
 
436
  else
 
437
    echo -e "\t\\033[32mOK\\033[0m."
 
438
  fi
 
439
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'. ")
 
442
  else
 
443
    echo -en "\t\\033[31mFAILED\\033[0m. Agent returns unexpected value: '\$retstr'. "
 
444
  fi
 
445
  echo "See details below:"
 
446
  cat /tmp/.ocft_runlog
 
447
  echo
 
448
  quit 1
 
449
fi
 
450
EOF
 
451
              fi
 
452
              ;;
 
453
            Bash|Bash@*)
 
454
              cat >>$sh <<EOF
 
455
if [ -n "\$OCFT_VERBOSE" ]; then
 
456
  echo $(add_quotes 2 "    \${showhost}Setting system environment:   ${trunk[1]}")
 
457
fi
 
458
echo $(add_quotes 1 "${trunk[1]}") | /bin/bash
 
459
check_success \$? $(add_quotes 1 "${trunk[1]}")
 
460
EOF
 
461
              ;;
 
462
            BashAtExit|BashAtExit@*)
 
463
              let atexit_num++
 
464
              cat >>$sh <<EOF
 
465
atexit${atexit_num}()
 
466
{
 
467
  if [ -n "\$OCFT_VERBOSE" ]; then
 
468
    echo $(add_quotes 2 "    \${showhost}Setting system environment:   ${trunk[1]}")
 
469
  fi
 
470
  echo $(add_quotes 1 "${trunk[1]}") | /bin/bash
 
471
}
 
472
let atexit_num++
 
473
EOF
 
474
              ;;
 
475
            *)
 
476
              parse_die "unimplemented statement: ${trunk[0]}"
 
477
              ;;
 
478
          esac
 
479
          if [ -n "$host" ]; then
 
480
            echo 'CMD' >>$sh
 
481
          fi
 
482
          ;;
 
483
        *)
 
484
          parse_die "unimplemented statement: ${trunk[0]}"
 
485
          ;;
 
486
      esac
 
487
    done <$CASES_DIR/${agent}.preparse
 
488
    rm -f $CASES_DIR/${agent}.preparse
 
489
    rm -f $CASES_DIR/${agent}_setup
 
490
    case_finish
 
491
  done
 
492
}
 
493
 
 
494
start_test()
 
495
{
 
496
  local sh shs agents line ret
 
497
 
 
498
  if ! cd $CASES_DIR >/dev/null 2>&1; then
 
499
    die "cases directory not found."
 
500
  fi
 
501
 
 
502
  export OCFT_VERBOSE=$opt_verbose
 
503
 
 
504
  if [ $# -eq 0 ]; then
 
505
    agents=($(ls -1 *.sh 2>/dev/null | sed 's/.*_\([^_]*\)\.sh$/\1/' | sort | uniq))
 
506
  else
 
507
    agents=("$@")
 
508
  fi
 
509
 
 
510
  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
 
520
      fi
 
521
    done
 
522
  done | while read -r line; do
 
523
    echo "$line"
 
524
    echo "$(date '+%F %T'): $line" | cat -A |
 
525
    sed -r 's/\^\[\[[0-9]+m|\^I|.$//g' >>ocft.log
 
526
  done
 
527
}
 
528
 
 
529
delete_cases()
 
530
{
 
531
  local shs
 
532
 
 
533
  if [ $# -eq 0 ]; then
 
534
    rm -f $CASES_DIR/*.sh
 
535
  else
 
536
    for shs in "$@"; do
 
537
      rm -f $CASES_DIR/*_${shs}.sh
 
538
    done
 
539
  fi
 
540
}
 
541
 
 
542
usage()
 
543
{
 
544
  cat <<EOF
 
545
$0 ACTION [OPTION] [agent1 [agent2] [...]]
 
546
ACTIONs include:
 
547
     make [-d dir]   Generate the testing shell scripts.
 
548
                       -d  The directory that contains 
 
549
                           configuration of cases.
 
550
     test [-v]       Execute the testing shell scripts.
 
551
                       -v  Verbose output mode.
 
552
     clean           Delete the testing shell scripts.
 
553
     help [-v]       Show this help and exit.
 
554
                       -v  Show HOWTO and exit.
 
555
Version 0.42
 
556
See '$OCFT_DIR/README' for detail.
 
557
EOF
 
558
}
 
559
 
 
560
howto()
 
561
{
 
562
  cat <<EOF
 
563
HOW TO USE THIS TOOL
 
564
 
 
565
  - Ocft is a testing tool for resource agents. Instead of the policy of HA,
 
566
    it mainly concerns whether resource agents run correct locally. It can 
 
567
    design types of complicated environments to test the reliability of 
 
568
    resource agents. Precisely, it is to display whether resource agents can 
 
569
    return to correct or expected value. The advantage of the tool provides 
 
570
    us with competence to design conditions which can be recorded or reproduced. 
 
571
    Hence it is useful to debuggers.
 
572
 
 
573
* Components
 
574
    ** Test case generator (@sbindir@/ocft)
 
575
      - Turning configuration files of test case to executable scripts.
 
576
 
 
577
    ** Configuration file  ($CONFIGS_DIR/)
 
578
      - Every configuration file directs only one resource agent and share the same 
 
579
        name with resource agent but contains more test cases.
 
580
 
 
581
    ** The testing script  ($CASES_DIR/)
 
582
      - After the generator reads configuration files and generates many testing 
 
583
        scripts and the script is underway, the test begins.
 
584
 
 
585
* How to customize the environment of testing
 
586
  - Ocft designs the running conditions through two ways, one is changing the 
 
587
    environment variables of resource agents (it is the interface left by OCF itself), 
 
588
    the other is modifying the OS environment of resource agents, such as altering 
 
589
    the permission of some key file or IP address of the machine.
 
590
 
 
591
* How to test
 
592
  - Firstly, you need to sketch the all complex and uncommon environments against 
 
593
    a certain resource agent and keep in mind what consequences may be caused by 
 
594
    these uncommon environments. 
 
595
    Secondly, write the designed conditions and foreknown consequences into 
 
596
    configuration files, and then run the generator to translate the test case to 
 
597
    executable scripts. 
 
598
    Finally, you need running these scripts to observe the output and learn 
 
599
    the running status of each test case, which will compares the predicated result 
 
600
    with the actual one. If they differ, you will be able to find the bugs of the 
 
601
    resource agent.
 
602
EOF
 
603
}
 
604
 
 
605
 
 
606
export LANG=C
 
607
 
 
608
# system variable
 
609
OCFT_DIR=@datadir@/@PACKAGE_NAME@/ocft
 
610
CONFIGS_DIR=@datadir@/@PACKAGE_NAME@/ocft/configs
 
611
CASES_DIR=/var/lib/@PACKAGE_NAME@/ocft/cases
 
612
 
 
613
# global variable
 
614
agent=
 
615
line_num=
 
616
 
 
617
# default configuration
 
618
cfg_agent_root=
 
619
cfg_install_package=
 
620
cfg_hang_timeout=20
 
621
 
 
622
# default option
 
623
opt_verbose=
 
624
opt_cfgsdir=$CONFIGS_DIR
 
625
 
 
626
command="$1"
 
627
shift
 
628
 
 
629
case "$command" in
 
630
  make)
 
631
    if [ "$1" = "-d" ]; then
 
632
      if [ ! -d "$2" ]; then
 
633
        usage
 
634
        exit 1
 
635
      fi
 
636
      opt_cfgsdir="$2"
 
637
      shift 2
 
638
    fi
 
639
    if [ ! -d "$CASES_DIR" ]; then
 
640
      mkdir -p "$CASES_DIR" || die "Can not create directory: ${CASES_DIR}."
 
641
    fi
 
642
    parse_cfg "$@"
 
643
    ;;
 
644
  test)
 
645
    if [ "$1" = "-v" ]; then
 
646
      opt_verbose=1
 
647
      shift
 
648
    fi
 
649
    start_test "$@"
 
650
    ;;
 
651
  clean)
 
652
    delete_cases "$@"
 
653
    ;;
 
654
  help)
 
655
    if [ "$1" = "-v" ]; then
 
656
      howto
 
657
    else
 
658
      usage
 
659
    fi
 
660
    exit 0
 
661
    ;;
 
662
  *)
 
663
    usage
 
664
    exit 1
 
665
    ;;
 
666
esac