common/smoketest/ats3_testdrop.pl
changeset 192 d5964b46ccaf
parent 191 56e7098e1ace
parent 119 18300635256d
child 193 19a76650e06d
equal deleted inserted replaced
191:56e7098e1ace 192:d5964b46ccaf
     1 #!/usr/bin/perl
       
     2 
       
     3 #curl "http://sym-build01:8080/ats3/XTestRunExecute.do?username=admin&password=admin&testrunpath=D:\smoketests\test_drops\9.zip
       
     4 use strict;
       
     5 use Getopt::Long;
       
     6 use File::Copy;
       
     7 use File::Spec;
       
     8 
       
     9 my $username = "admin";
       
    10 my $password = "admin";
       
    11 my $host;
       
    12 my $schedule;
       
    13 my $host_drop_path;
       
    14 my $local_drop_path;
       
    15 my $local_test_pkg;
       
    16 my $help;
       
    17 my $dev_null = $^O =~ /^MSWin/ ? "nul" : "/dev/null";
       
    18 
       
    19 sub usage($);
       
    20 sub help();
       
    21 sub usage_error();
       
    22 
       
    23 my %optmap = (  'host' => \$host,
       
    24 			    'local-test-pkg' => \$local_test_pkg,
       
    25 				'host-drop-path' => \$host_drop_path,
       
    26 				'local-drop-path' =>\$local_drop_path,
       
    27 				'username' => \$username,
       
    28 				'password' => \$password,
       
    29 				'schedule' => \$schedule,
       
    30                 'help' => \$help);
       
    31 
       
    32 GetOptions(\%optmap,
       
    33           'host=s',
       
    34           'local-test-pkg=s',
       
    35           'host-drop-path=s',
       
    36           'local-drop-path=s',
       
    37           'username=s',
       
    38           'password=s',
       
    39           'schedule=s',
       
    40           'help!') 
       
    41           or usage_error();
       
    42 
       
    43 if ($help) {
       
    44 	help();
       
    45 }
       
    46 
       
    47 usage_error(), unless (defined($host) && defined($local_test_pkg) && defined($local_drop_path) && defined($host_drop_path));
       
    48 
       
    49 my $curl_version = $^O =~ /^MSWin/ ? `curl --version 1> $dev_null 2>&1` : `curl --version 1> $dev_null 2>&1`;
       
    50 die("Need program \"curl\". Not found"), if ($?);
       
    51 die("Test drop path \"$local_drop_path\" not found"), unless ( -d "$local_drop_path");
       
    52 
       
    53 $host .= ":8080", unless ($host =~ /:\d+$/);
       
    54 
       
    55 my ($vol,$dir,$pkg);
       
    56 my $local_test_drop;
       
    57 my $host_test_drop;
       
    58 
       
    59 if ($local_test_pkg =~ /^\.\.\.(.+)/ ) {
       
    60     $pkg = $1;
       
    61     $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);
       
    62     die("Test package file \"$local_test_drop\" not found"), unless ( -f "$local_test_drop");        
       
    63 }
       
    64 else {
       
    65     die("Test package file \"$local_test_pkg\" not found"), unless ( -f "$local_test_pkg");
       
    66     ($vol,$dir,$pkg) = File::Spec->splitpath($local_test_pkg);
       
    67     $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);
       
    68     if ( -f "$local_test_drop") {
       
    69         my $cmp_local_test_drop = $local_test_drop;
       
    70         my $cmp_local_test_pkg = $local_test_pkg;
       
    71         if ($^O =~ /^MSWin/) {
       
    72             $cmp_local_test_drop = lc($local_test_drop);
       
    73             $cmp_local_test_pkg = lc($local_test_pkg);        
       
    74         }   
       
    75         if ("$cmp_local_test_drop" eq "$cmp_local_test_pkg") {
       
    76             if (unlink($local_test_drop) == 0) {
       
    77                 die("Can't delete stale test drop \"$local_test_drop\". $!");
       
    78             }
       
    79             else {
       
    80                 print("A stale test drop \"$local_test_drop\" existed. Deleted\n");
       
    81             }
       
    82         }
       
    83     }
       
    84     copy("$local_test_pkg","$local_test_drop")
       
    85         or die("Cannot copy \"$local_test_pkg\" -> \"$local_test_drop\". $!");
       
    86 }
       
    87 $host_test_drop = File::Spec->catfile($host_drop_path,$pkg);
       
    88 my $url ="http://$host/ats3/XTestRunExecute.do?username=$username&password=$password&testrunpath=$host_test_drop";
       
    89 $url .= "&schedule=$schedule", if (defined($schedule));
       
    90 my $curl_cmd = "curl \"$url\"";
       
    91 system("$curl_cmd");
       
    92 die("\nTest drop failed: $!"), if ($?);
       
    93 print("\nTest drop done");
       
    94 
       
    95 exit 0;
       
    96 
       
    97 sub usage($)
       
    98 {
       
    99     my $error = shift;
       
   100     my $fh = $error == 0 ? *STDOUT : *STDERR;
       
   101     print $fh "ats3_testdrop.pl\n" .
       
   102             "Send a test drop to an ATS3 server for execution\n" .
       
   103             "usage:\n" .
       
   104             "  ats3_testdrop.pl --help\n" .
       
   105             "  ats3_testdrop.pl --host=HOSTNAME --local-test-pkg=PKGFILE --local-drop-path=LOCALPATH " .
       
   106                 " --host-drop-path=HOSTPATH " .
       
   107                 "[--username=ATS3USERNAME] [--password=ATS3PASSWORD] [--schedule=DD.MM.YYYY-HH:MM]\n" .
       
   108             "options:\n" .
       
   109             "  --help                        Display this help and exit\n" .
       
   110             "  --host=HOSTAME                HOSTNAME is ATS3 server\n" .
       
   111             "  --local-test-pkg=PKGFILE      PKGFILE is the test package.\n" .
       
   112             "                                If PKGFILE begins "..." a filename in LOCALPATH is assumed\n" .
       
   113             "  --local-drop-path=LOCALPATH   Path to local directory where PKGFILE will be dropped\n" .            
       
   114             "  --host-drop-path=HOSTPATH     Host directory that is mapped to LOCALPATH.\n" .
       
   115             "                                Must agree with the properties of the registered device that the test package nominates\n" .
       
   116             "  --username=ATS3USERNAME       ATS3 user to whome the test will belong. Default=admin\n" .
       
   117             "  --password=ATS3PASSWORD       Password of ATS3 user. Default=admin\n" .
       
   118             "  --schedule=DD.MM.YYYY-HH:MM   Date-time at which test is to run. Default=as soon as possible\n";
       
   119     exit $error;            
       
   120 }
       
   121 
       
   122 sub help()
       
   123 {
       
   124     usage(0);
       
   125 }
       
   126 
       
   127 sub usage_error()
       
   128 {
       
   129     usage(1);
       
   130 }             
       
   131 
       
   132 # EOF
       
   133