blob: 003c725e3a91967ff5c4b5e2b51a06aea7f6b482 [file] [log] [blame]
robbiewa1c66572002-03-13 16:38:50 +00001#!/usr/bin/perl
2
3#Master control script; ltp_master
4# 3/12/02 William Jay Huie (creation)
robbiewdc61c582002-03-27 21:58:42 +00005# 3/28/02 William Jay Huie minor updates
robbiewa1c66572002-03-13 16:38:50 +00006#This will upload the ltprun script to the test system and kick off this script
7#uses the Net:Telnet and Net::Ftp modules from www.cpan.org
8#the ltprun script is a shell script to eliminate the need to write a script
9#to install these modules on all the target systems
10
11#FIXME: One problem is that the tests need to be run as root as as of now
12#this means that LTP_USER needs to be root, which means root needs to be
robbiewdc61c582002-03-27 21:58:42 +000013#able to telnet and ftp into the machine. Couldn't figure out how to add
14#a su -c to the LTP_CMD_LINE variable, ssh will probably be the solution
15#but for now this works
robbiewa1c66572002-03-13 16:38:50 +000016
17use Net::Telnet ();
18use Net::FTP ();
19
20#Leave this set to keep perl from buffering IO
21$| = 1;
22
robbiewdc61c582002-03-27 21:58:42 +000023#CHANGEME:
robbiewa1c66572002-03-13 16:38:50 +000024#change these for different defaults
25#Think carefully because things like ltprun.out are relied upon in the ltprun
26# script, so you need to change them there too, or better yet make them
27# cmd line parms
robbiewdc61c582002-03-27 21:58:42 +000028#$LTP_USER = "ltp";
29#$LTP_PASS = "ltp";
30$LTP_USER = "root";
31$LTP_PASS = "password";
robbiewa1c66572002-03-13 16:38:50 +000032$LTP_RUN = "ltprun";
33#CHANGEME:
34#Can't use ~/bin so have to explicitly hardcode this directory
35$LTP_RUN_DIR = "/home/wjhuie/bin/";
36$LTP_CMD_LINE = "chmod +x $LTP_RUN && nohup ./$LTP_RUN &> $LTP_RUN.out &";
37
robbiewa8dc2112002-05-03 15:57:43 +000038#print "For this to work root must be able to ftp and telnet into the machines\n";
39#print "Check #LTP_RUN_DIR/ltp_master for root password: $LTP_PASS\n";
40
41#print "FIXME: Need to change this to su to root, not login over telnet\n";
42#print " Or run in some other way like ssh\n";
robbiewa1c66572002-03-13 16:38:50 +000043
44if ( $ARGV[0] eq "-f" )
45{
46 if ( -f $ARGV[1] )
47 {
48 open(FILE, $ARGV[1]) or die "Can't open $ARGV[1]";
49 for ($i = 0; chomp($hosts[$i] = <FILE>); $i++) { ; }
50 $#hosts--;
51 close(FILE);
52 }
53 else { die "Please specify host list file with option -f\n"; }
54}
55elsif (@ARGV)
56{ @hosts = @ARGV; }
57else
58{
59 print "HOSTS separate with [ENTER] finish with [^D]\n";
60 chomp(@hosts = <STDIN>);
61}
62
robbiewcba89702002-09-05 20:48:35 +000063$t = new Net::Telnet (Timeout => 30, Prompt => '/.+[\$#] $/'
robbiewa1c66572002-03-13 16:38:50 +000064# ,Dump_Log => "ltp_control.log"
65#Remove the # on the line above and a copy of the
66# data exchange will be saved to the file 'ms.log'
67 );
68
69#FIXME: Need a better retry system, this would loop forever
70#$retry = 0;
71
72for ($j = 0; $j <= $#hosts; $j++)
73{
74 chdir "$LTP_RUN_DIR" or die "Can't change to $LTP_RUN_DIR";
robbiewdc61c582002-03-27 21:58:42 +000075 print "\nAttempting to Upload $LTP_RUN to: $hosts[$j]";
robbiewa1c66572002-03-13 16:38:50 +000076
robbiewdc61c582002-03-27 21:58:42 +000077 $ftp = Net::FTP->new($hosts[$j], Debug => 0) or
78 do { print "\n\tCouldn't connect to: $hosts[$j] --- skipping\n"; next; };
79 $ftp->login($LTP_USER, $LTP_PASS) or die "\nUnable to login";
80 $ftp->type('I') or die "\nUnable to set type to Binary";
81 $ftp->put($LTP_RUN) or die "\nUnable to put $LTP_RUN";
robbiewa1c66572002-03-13 16:38:50 +000082 $ftp->quit;
83 print "\nUploading $LTP_RUN Done";
84
85 print "\nConnecting to: $hosts[$j]";
86 $t->open($hosts[$j]);
87 $t->errmode("return");
88 $t->login($LTP_USER, $LTP_PASS) or
89 do { print "\n\tFailed Login to $hosts[$j]! "; next;
90#perhaps work in some sort of retry, but this way will loop forever
91# if ($retry) { $j--; } next;
92 };
93 @l = $t->cmd("$LTP_CMD_LINE");
94
95 if ($j == 0)
96 {
97 if ($l[0]) { print " >\n@l"; @base_output = @l; }
98 else { printf "\nReturned empty Buffer!\n"; }
99 }
100 $a = join("",@l);
101 $b = join("",@base_output);
102 if ($a ne $b)
103 { print "!>\n@l\n"; }
104
105 $t->buffer_empty();
106 $t->close();
107 print "\t Command Completed";
108}
109print "\nAll Done!\n";
110
111#Use snippit below in results script to convert timing info
112# from tar file name into human readable format
113#$foo = $ARGV[0];
114#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($foo);
115#print "$foo\n";
116#print "Hour: $hour Min: $min Sec: $sec\n";
117