aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-11-02 14:35:37 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-11-18 11:23:11 -0500
commite48c5293bde398e253f83fdd0247fb2bc71cc92f (patch)
treed0b3fa90b5632e589b52ae0f7e59585b6c7aa515 /tools
parent7a849cd93ad2cf7d32427f3dbf5f524d5f588d20 (diff)
ktest/cleanups: Added version 0.2, ssh as options
Updated to version 0.2. Now have SSH_EXEC options. Also added some cleanups for keeping track of success and reading the config file. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/testing/ktest/ktest.pl81
1 files changed, 63 insertions, 18 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index e0e5935e94c8..7b6f8e1a82a4 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -11,7 +11,9 @@ use File::Path qw(mkpath);
11use File::Copy qw(cp); 11use File::Copy qw(cp);
12use FileHandle; 12use FileHandle;
13 13
14$#ARGV >= 0 || die "usage: ktest.pl config-file\n"; 14my $VERSION = "0.2";
15
16$#ARGV >= 0 || die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
15 17
16$| = 1; 18$| = 1;
17 19
@@ -40,9 +42,13 @@ $default{"CLEAR_LOG"} = 0;
40$default{"SUCCESS_LINE"} = "login:"; 42$default{"SUCCESS_LINE"} = "login:";
41$default{"BOOTED_TIMEOUT"} = 1; 43$default{"BOOTED_TIMEOUT"} = 1;
42$default{"DIE_ON_FAILURE"} = 1; 44$default{"DIE_ON_FAILURE"} = 1;
45$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";
46$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";
47$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";
43 48
44my $version; 49my $version;
45my $machine; 50my $machine;
51my $ssh_user;
46my $tmpdir; 52my $tmpdir;
47my $builddir; 53my $builddir;
48my $outputdir; 54my $outputdir;
@@ -53,11 +59,14 @@ my $build_options;
53my $reboot_type; 59my $reboot_type;
54my $reboot_script; 60my $reboot_script;
55my $power_cycle; 61my $power_cycle;
62my $reboot;
56my $reboot_on_error; 63my $reboot_on_error;
57my $poweroff_on_error; 64my $poweroff_on_error;
58my $die_on_failure; 65my $die_on_failure;
59my $powercycle_after_reboot; 66my $powercycle_after_reboot;
60my $poweroff_after_halt; 67my $poweroff_after_halt;
68my $ssh_exec;
69my $scp_to_target;
61my $power_off; 70my $power_off;
62my $grub_menu; 71my $grub_menu;
63my $grub_number; 72my $grub_number;
@@ -89,6 +98,7 @@ my $build_target;
89my $target_image; 98my $target_image;
90my $localversion; 99my $localversion;
91my $iteration = 0; 100my $iteration = 0;
101my $successes = 0;
92 102
93sub set_value { 103sub set_value {
94 my ($lvalue, $rvalue) = @_; 104 my ($lvalue, $rvalue) = @_;
@@ -133,6 +143,7 @@ sub read_config {
133 } 143 }
134 144
135 my $old_test_num = $test_num; 145 my $old_test_num = $test_num;
146 my $old_repeat = $repeat;
136 147
137 $test_num += $repeat; 148 $test_num += $repeat;
138 $default = 0; 149 $default = 0;
@@ -162,7 +173,7 @@ sub read_config {
162 173
163 if ($skip) { 174 if ($skip) {
164 $test_num = $old_test_num; 175 $test_num = $old_test_num;
165 $repeat = 1; 176 $repeat = $old_repeat;
166 } 177 }
167 178
168 } elsif (/^\s*DEFAULTS(.*)$/) { 179 } elsif (/^\s*DEFAULTS(.*)$/) {
@@ -261,7 +272,7 @@ sub run_command;
261 272
262sub reboot { 273sub reboot {
263 # try to reboot normally 274 # try to reboot normally
264 if (run_command "ssh $target reboot") { 275 if (run_command $reboot) {
265 if (defined($powercycle_after_reboot)) { 276 if (defined($powercycle_after_reboot)) {
266 sleep $powercycle_after_reboot; 277 sleep $powercycle_after_reboot;
267 run_command "$power_cycle"; 278 run_command "$power_cycle";
@@ -419,6 +430,9 @@ sub run_command {
419 my $dord = 0; 430 my $dord = 0;
420 my $pid; 431 my $pid;
421 432
433 $command =~ s/\$SSH_USER/$ssh_user/g;
434 $command =~ s/\$MACHINE/$machine/g;
435
422 doprint("$command ... "); 436 doprint("$command ... ");
423 437
424 $pid = open(CMD, "$command 2>&1 |") or 438 $pid = open(CMD, "$command 2>&1 |") or
@@ -457,6 +471,24 @@ sub run_command {
457 return !$failed; 471 return !$failed;
458} 472}
459 473
474sub run_ssh {
475 my ($cmd) = @_;
476 my $cp_exec = $ssh_exec;
477
478 $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;
479 return run_command "$cp_exec";
480}
481
482sub run_scp {
483 my ($src, $dst) = @_;
484 my $cp_scp = $scp_to_target;
485
486 $cp_scp =~ s/\$SRC_FILE/$src/g;
487 $cp_scp =~ s/\$DST_FILE/$dst/g;
488
489 return run_command "$cp_scp";
490}
491
460sub get_grub_index { 492sub get_grub_index {
461 493
462 if ($reboot_type ne "grub") { 494 if ($reboot_type ne "grub") {
@@ -466,8 +498,13 @@ sub get_grub_index {
466 498
467 doprint "Find grub menu ... "; 499 doprint "Find grub menu ... ";
468 $grub_number = -1; 500 $grub_number = -1;
469 open(IN, "ssh $target cat /boot/grub/menu.lst |") 501
502 my $ssh_grub = $ssh_exec;
503 $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;
504
505 open(IN, "$ssh_grub |")
470 or die "unable to get menu.lst"; 506 or die "unable to get menu.lst";
507
471 while (<IN>) { 508 while (<IN>) {
472 if (/^\s*title\s+$grub_menu\s*$/) { 509 if (/^\s*title\s+$grub_menu\s*$/) {
473 $grub_number++; 510 $grub_number++;
@@ -516,7 +553,7 @@ sub wait_for_input
516 553
517sub reboot_to { 554sub reboot_to {
518 if ($reboot_type eq "grub") { 555 if ($reboot_type eq "grub") {
519 run_command "ssh $target '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'"; 556 run_command "$ssh_exec '(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";
520 return; 557 return;
521 } 558 }
522 559
@@ -618,7 +655,7 @@ sub monitor {
618 655
619sub install { 656sub install {
620 657
621 run_command "scp $outputdir/$build_target $target:$target_image" or 658 run_scp "$outputdir/$build_target", "$target_image" or
622 dodie "failed to copy image"; 659 dodie "failed to copy image";
623 660
624 my $install_mods = 0; 661 my $install_mods = 0;
@@ -645,32 +682,29 @@ sub install {
645 my $modlib = "/lib/modules/$version"; 682 my $modlib = "/lib/modules/$version";
646 my $modtar = "ktest-mods.tar.bz2"; 683 my $modtar = "ktest-mods.tar.bz2";
647 684
648 run_command "ssh $target rm -rf $modlib" or 685 run_ssh "rm -rf $modlib" or
649 dodie "failed to remove old mods: $modlib"; 686 dodie "failed to remove old mods: $modlib";
650 687
651 # would be nice if scp -r did not follow symbolic links 688 # would be nice if scp -r did not follow symbolic links
652 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or 689 run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or
653 dodie "making tarball"; 690 dodie "making tarball";
654 691
655 run_command "scp $tmpdir/$modtar $target:/tmp" or 692 run_scp "$tmpdir/$modtar", "/tmp" or
656 dodie "failed to copy modules"; 693 dodie "failed to copy modules";
657 694
658 unlink "$tmpdir/$modtar"; 695 unlink "$tmpdir/$modtar";
659