martinjn | 0817e86 | 2002-07-10 14:10:28 +0000 | [diff] [blame^] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # 05/22/02 martinjn@us.ibm.com wrote this script for ltp automation using ssh instead of telnet |
| 4 | # 06/18/02 martinjn@us.ibm.com hacked this script up to try to make it work better with ltp_check |
| 5 | # |
| 6 | # If you create a config file to use the -f option, the host line format is: |
| 7 | # host,userid,password,number of instances,time |
| 8 | # |
| 9 | # time option should include m/h/d units(example: 72h = 72 hour run) |
| 10 | # |
| 11 | |
| 12 | use Net::SSH::Perl (); |
| 13 | use Net::SFTP (); |
| 14 | |
| 15 | $|=1; |
| 16 | $LTPRESULTS=$ENV{"HOME"} . "/ltpresults"; |
| 17 | $LTPSOURCE="/tmp/ltp.tgz"; |
| 18 | $LTPTARGET="/tmp/ltp.tgz"; |
| 19 | $ETIME=time(); |
| 20 | |
| 21 | if (!-d $LTPRESULTS) |
| 22 | { |
| 23 | print "Creating $LTPRESULTS \n"; |
| 24 | print `mkdir $LTPRESULTS`; |
| 25 | } |
| 26 | |
| 27 | if ( $ARGV[0] eq "-f" ) |
| 28 | { |
| 29 | if ( -f $ARGV[1] ) |
| 30 | { |
| 31 | open(FILE, $ARGV[1]) or die "Can't open $ARGV[1]"; |
| 32 | for ($i = 0; chomp($hosts[$i] = <FILE>); $i++) { ; } |
| 33 | $#hosts--; |
| 34 | close(FILE); |
| 35 | } |
| 36 | else { die "Please specify host list file with option -f\n"; } |
| 37 | } |
| 38 | elsif (@ARGV) |
| 39 | { @hosts = @ARGV; } |
| 40 | else |
| 41 | { |
| 42 | print "HOSTS separate with [ENTER] finish with [^D]\n"; |
| 43 | print "format: host,userid,password,instances,time\n"; |
| 44 | chomp(@hosts = <STDIN>); |
| 45 | } |
| 46 | |
| 47 | # had to fork off the remote transactions because Net::SSH waits for return code |
| 48 | |
| 49 | for($i=0; $i <= $#hosts; $i++) { |
| 50 | if (!fork) { |
| 51 | ($HOST,$USER,$PASS,$INSTANCES,$DURATION)=split(/,/,@hosts[$i]); |
| 52 | ($SHORTHOST,$TRASH)=split(/\./,$HOST); |
| 53 | $LTP_LOGS="$SHORTHOST-$ETIME-ltpoutput.tgz"; |
| 54 | $RUN_LOG="/root/runall.output"; |
| 55 | |
| 56 | #push tar.tgz |
| 57 | %args = {}; |
| 58 | $args{user}=$USER; |
| 59 | $args{password}=$PASS; |
| 60 | my $sftp = Net::SFTP->new($HOST,%args); |
| 61 | $sftp->put($LTPSOURCE,$LTPTARGET); |
| 62 | print("$LTPSOURCE copied to $LTPTARGET on $HOST\n"); |
| 63 | |
| 64 | #untar, build, and run |
| 65 | my $ssh = Net::SSH::Perl->new($HOST); |
| 66 | $ssh->login($USER,$PASS); |
| 67 | |
| 68 | print("Untar and build testcases on $HOST\n"); |
| 69 | if($ssh->cmd("tar -xzf $LTPTARGET > /dev/null && rm $LTPTARGET && cd ltp && make clean install > /dev/null")) { |
| 70 | print("Error untarring or building on $HOST. Giving up on this machine.\n"); |
| 71 | exit(); |
| 72 | } |
| 73 | else { |
| 74 | print("Untar and build complete on $HOST\n"); |
| 75 | } |
| 76 | |
| 77 | print("Starting sar on $HOST\n"); |
| 78 | $ssh->cmd("nohup sar -o sar.data 60 0 >/dev/null 2>&1 &"); |
| 79 | |
| 80 | print("Cranking up tests on " . $HOST . "\n"); |
| 81 | if($ssh->cmd("cd ltp* && nohup ./runalltests.sh $INSTANCES $DURATION >$RUN_LOG &")) { |
| 82 | print("Error starting tests on $HOST. Giving up on this machine.\n"); |
| 83 | exit(); |
| 84 | } |
| 85 | else { |
| 86 | print("Tests completed on $HOST\n"); |
| 87 | } |
| 88 | |
| 89 | #this looks lame, but ltp_check needs ltprun.out to grab the ltp version |
| 90 | $ssh->cmd('echo version: $(head -n1 ltp/ChangeLog) > ltprun.out'); |
| 91 | |
| 92 | #stop sar on client(s) |
| 93 | if($ssh->cmd("killall sar && killall sadc")) { |
| 94 | print("hmmm...couldn't stop sar automatically.\n"); |
| 95 | } |
| 96 | else { |
| 97 | print("Stopped sar on $HOST\n"); |
| 98 | } |
| 99 | |
| 100 | #tar up and remove the results files |
| 101 | if($tmp=$ssh->cmd("cd /root && tar --remove-files -czf $LTP_LOGS sar.data ltp-logfile runall.output ltprun.out")) { |
| 102 | print("Error returned $tmp tarring up results on $HOST. Some of the logs may be missing.\n"); |
| 103 | } |
| 104 | else { |
| 105 | print("Results tarred up on $HOST\n"); |
| 106 | } |
| 107 | |
| 108 | #upload the results back to the machine you ran from |
| 109 | print("Uploading results, $LTP_LOGS, to $LTPRESULTS for $HOST\n"); |
| 110 | if($sftp->get($LTP_LOGS,$LTPRESULTS."/$LTP_LOGS")) { |
| 111 | print("Error uploading results from " . $HOST . ". Giving up on this machine.\n"); |
| 112 | exit(); |
| 113 | } |
| 114 | else { |
| 115 | print("Results uploaded for $HOST\n"); |
| 116 | } |
| 117 | exit; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | for ($j=0; $j <= $#hosts; $j++) { |
| 122 | wait; |
| 123 | } |