]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
wip reorg move things into TestSupport
authorIan Jackson <iwj@woking.cam.xci-test.com>
Tue, 16 Oct 2012 10:37:26 +0000 (11:37 +0100)
committerIan Jackson <iwj@woking.cam.xci-test.com>
Tue, 16 Oct 2012 10:37:26 +0000 (11:37 +0100)
Osstest.pm
Osstest/Executive.pm
Osstest/JobDB/Executive.pm
Osstest/JobDB/Standalone.pm
Osstest/TestSupport.pm

index f0105eec86a4887d90fd20172628c7abf9d7d0d3..ebec77e2fc350c921bcb86e23fdb2cf1e26f139b 100644 (file)
@@ -16,8 +16,11 @@ BEGIN {
                       augmentconfigdefaults
                       csreadconfig
                       getmethod
+                      postfork
+
                       $dbh_tests db_retry db_begin_work                      
 get_filecontents ensuredir get_filecontents_core_quiet system_checked
+                      nonempty
 
                       );
     %EXPORT_TAGS = ( );
@@ -154,6 +157,10 @@ sub db_retry ($$$;$$) {
     return $r;
 }
 
+sub postfork () {
+    $mjobdb->postfork();
+}
+
 #---------- script entrypoints ----------
 
 sub csreadconfig () {
@@ -199,4 +206,9 @@ sub system_checked {
     die "@_: $? $!" if $? or $!;
 }
 
+sub nonempty ($) {
+    my ($v) = @_;
+    return defined($v) && length($v);
+}
+
 1;
index 386fa43728144026a32d6d95888da59d5d97ea85..d207a3ff1a44a27522f59614dfd04e2533890101 100644 (file)
@@ -68,14 +68,8 @@ BEGIN {
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     @EXPORT      = qw(
-                      $logm_handle
-                      %c
-                      nonempty
                       dbfl_check get_harness_rev grabrepolock_reexec
-                      get_stashed open_unique_stashfile
-                      broken fail
-                      unique_incrementing_runvar 
-                      tcpconnect findtask @all_lock_tables
+                       findtask @all_lock_tables
                       tcpconnect_queuedaemon plan_search
                       alloc_resources alloc_resources_rollback_begin_work
                       resource_check_allocated resource_shared_mark_ready
@@ -83,13 +77,11 @@ BEGIN {
                       csreadconfig ts_get_host_guest
                       opendb_state get_timeout
                       host_involves_pcipassthrough host_get_pcipassthrough_devs
-                      postfork
                        link_file_contents create_webfile
-                      contents_make_cpio file_simple_write_contents
                       setup_pxeboot setup_pxeboot_local
                       await_webspace_fetch_byleaf await_tcp
                       remote_perl_script_open remote_perl_script_done sshopts
-                      host_reboot host_pxedir target_reboot target_reboot_hard
+                       host_pxedir 
                       target_choose_vg target_umount_lv target_await_down
                       target_ping_check_down target_ping_check_up
                       target_kernkind_check target_kernkind_console_inittab
@@ -128,11 +120,6 @@ our %timeout= qw(RebootDown   100
                  RebootUp     400
                  HardRebootUp 600);
 
-sub nonempty ($) {
-    my ($v) = @_;
-    return defined($v) && length($v);
-}
-
 #---------- configuration reader etc. ----------
 
 sub opendb_tests () {
@@ -227,151 +214,6 @@ sub opendb ($) {
     return $dbh;
 }
 
-sub open_unique_stashfile ($) {
-    my ($leafref) = @_;
-    my $dh;
-    for (;;) {
-        my $df= $$leafref;
-        $dh= new IO::File "$stash/$df", O_WRONLY|O_EXCL|O_CREAT;
-        last if $dh;
-        die "$df $!" unless $!==&EEXIST;
-        $$leafref .= '+';
-    }
-    return $dh;
-}
-
-#---------- runvars ----------
-
-sub get_stashed ($$) {
-    my ($param, $otherflightjob) = @_; 
-    # may be run outside transaction, or with flights locked
-    my ($oflight, $ojob) = otherflightjob($otherflightjob);
-    my $path= get_runvar($param, $otherflightjob);
-    die "$path $& " if
-        $path =~ m,[^-+._0-9a-zA-Z/], or
-        $path =~ m/\.\./;
-    return "$c{Stash}/$oflight/$ojob/$path";
-}
-
-sub unique_incrementing_runvar ($$) {
-    my ($param,$start) = @_;
-    # must be run outside transaction
-    my $value;
-    db_retry($flight,'running', $dbh_tests,[qw(flights)], sub {
-       my $row= $dbh_tests->selectrow_arrayref(<<END,{}, $flight,$job,$param);
-            SELECT val FROM runvars WHERE flight=? AND job=? AND name=?
-END
-       $value= $row ? $row->[0] : $start;
-       $dbh_tests->do(<<END, undef, $flight, $job, $param);
-            DELETE FROM runvars WHERE flight=? AND job=? AND name=? AND synth
-END
-       $dbh_tests->do(<<END, undef, $flight, $job, $param, $value+1);
-            INSERT INTO runvars VALUES (?,?,?,?,'t')
-END
-    });
-    logm("runvar increment: $param=$value");
-    return $value;
-}
-
-#---------- other stuff ----------
-
-sub postfork () {
-    $dbh_tests->{InactiveDestroy}= 1;  undef $dbh_tests;
-}
-
-sub host_reboot ($) {
-    my ($ho) = @_;
-    target_reboot($ho);
-    poll_loop(40,2, 'reboot-confirm-booted', sub {
-        my $output;
-        if (!eval {
-            $output= target_cmd_output($ho,
-                "stat /dev/shm/osstest-confirm-booted 2>&1 >/dev/null ||:",
-                                       40);
-            1;
-        }) {
-            return $@;
-        }
-        return length($output) ? $output : undef;
-    });
-}
-
-sub target_reboot ($) {
-    my ($ho) = @_;
-    target_cmd_root($ho, "init 6");
-    target_await_down($ho, $timeout{RebootDown});
-    await_tcp(get_timeout($ho,'reboot',$timeout{RebootUp}), 5,$ho);
-}
-
-sub target_reboot_hard ($) {
-    my ($ho) = @_;
-    power_cycle($ho);
-    await_tcp(get_timeout($ho,'reboot',$timeout{HardRebootUp}), 5, $ho);
-}
-
-sub tcpconnect ($$) {
-    my ($host, $port) = @_;
-    my $h= new IO::Handle;
-    my $proto= getprotobyname('tcp');  die $! unless defined $proto;
-    my $fixedaddr= inet_aton($host);
-    my @addrs; my $atype;
-    if (defined $fixedaddr) {
-        @addrs= $fixedaddr;
-        $atype= AF_INET;
-    } else {
-        $!=0; $?=0; my @hi= gethostbyname($host);
-        @hi or die "host lookup failed for $host: $? $!";
-        $atype= $hi[2];
-        @addrs= @hi[4..$#hi];
-        die "connect $host:$port: no addresses for $host" unless @addrs;
-    }
-    foreach my $addr (@addrs) {
-        my $h= new IO::Handle;
-        my $sin; my $pfam; my $str;
-        if ($atype==AF_INET) {
-            $sin= sockaddr_in $port, $addr;
-            $pfam= PF_INET;
-            $str= inet_ntoa($addr);
-#        } elsif ($atype==AF_INET6) {
-#            $sin= sockaddr_in6 $port, $addr;
-#            $pfam= PF_INET6;
-#            $str= inet_ntoa6($addr);
-        } else {
-            warn "connect $host:$port: unknown AF $atype";
-            next;
-        }
-        if (!socket($h, $pfam, SOCK_STREAM, $proto)) {
-            warn "connect $host:$port: unsupported PF $pfam";
-            next;
-        }
-        if (!connect($h, $sin)) {
-            warn "connect $host:$port: [$str]: $!";
-            next;
-        }
-        return $h;
-
-    }
-    die "$host:$port all failed";
-}
-
-sub contents_make_cpio ($$$) {
-    my ($fh, $format, $srcdir) = @_;
-    my $child= fork;  defined $child or die $!;
-    if (!$child) {
-        postfork();
-        chdir($srcdir) or die $!;
-        open STDIN, 'find ! -name "*~" ! -name "#*" -type f -print0 |'
-            or die $!;
-        open STDOUT, '>&', $fh or die $!;
-        system "cpio -H$format -o --quiet -0 -R 1000:1000";
-        $? and die $?;
-        $!=0; close STDIN; die "$! $?" if $! or $?;
-        exit 0;
-    }
-    waitpid($child, 0) == $child or die $!;
-    $? and die $?;
-}
-
 #---------- building, vcs's, etc. ----------
 
 sub build_clone ($$$$) {
@@ -1568,21 +1410,6 @@ sub guest_check_remus_ok {
     die "crashed somewhere $compound" if grep { m/c/ } @ststrings;
 }
 
-sub file_simple_write_contents ($$) {
-    my ($real, $contents) = @_;
-    # $contents may be a coderef in which case we call it with the
-    #  filehandle to allow caller to fill in the file
-
-    unlink $real or $!==&ENOENT or die "$real $!";
-    my $flc= new IO::File "$real",'w' or die "$real $!";
-    if (ref $contents eq 'CODE') {
-        $contents->($flc);
-    } else {
-        print $flc $contents or die "$real $!";
-    }
-    close $flc or die "$real $!";
-}
-
 sub file_link_contents ($$) {
     my ($fn, $contents) = @_;
     # $contents as for file_write_contents
index ee9a7826fe33340ad93befbd5e730286ace6bda6..65623727126abae30225a7083c4f02679dba9852 100644 (file)
@@ -114,4 +114,9 @@ sub host_check_allocated ($$) { #method
     die if $ho->{SharedOthers} && !$ho->{SharedReady};
 }
 
+sub postfork ($) { #method
+    my ($jd) = @_;
+    $dbh_tests->{InactiveDestroy}= 1;  undef $dbh_tests;
+}
+
 1;
index 9a115220df11762edbb00438a4bed4f01e05b757..3a72668337beb54948872abe5a8c301136c4bb01 100644 (file)
@@ -65,4 +65,6 @@ sub host_check_allocated ($$) { #method
     my ($jd, $ho) = @_;
 }
 
+sub postfork ($) { }
+
 1;
index 5a5f051d6f13f31e50a643d33d3afe345b41e335..b3bb0569decddc943d1b58ac04ffab93eceff0ff 100644 (file)
@@ -20,10 +20,14 @@ BEGIN {
                       tsreadconfig %r $flight $job $stash
 
 fail logm
+                      broken                      $logm_handle
+
 
 store_runvar get_runvar get_runvar_maybe get_runvar_default need_runvars
  flight_otherjob
 
+                      unique_incrementing_runvar 
+
                       target_cmd_root target_cmd target_cmd_build
                       target_cmd_output_root target_cmd_output
                       target_getfile target_getfile_root
@@ -39,7 +43,13 @@ selecthost get_hostflags
                       get_host_property 
 
 power_state power_cycle power_cycle_time
-                      
+         
+                      get_stashed open_unique_stashfile
+
+host_reboot target_reboot target_reboot_hard            
+tcpconnect
+                      contents_make_cpio file_simple_write_contents
                       );
     %EXPORT_TAGS = ( );
 
@@ -214,6 +224,27 @@ sub otherflightjob ($) {
     return flight_otherjob($flight,$_[0]);
 }
 
+sub unique_incrementing_runvar ($$) {
+    my ($param,$start) = @_;
+    # must be run outside transaction
+    my $value;
+    db_retry($flight,'running', $dbh_tests,[qw(flights)], sub {
+       my $row= $dbh_tests->selectrow_arrayref(<<END,{}, $flight,$job,$param);
+            SELECT val FROM runvars WHERE flight=? AND job=? AND name=?
+END
+       $value= $row ? $row->[0] : $start;
+       $dbh_tests->do(<<END, undef, $flight, $job, $param);
+            DELETE FROM runvars
+                 WHERE flight=? AND job=? AND name=? AND synth='t'
+END
+       $dbh_tests->do(<<END, undef, $flight, $job, $param, $value+1);
+            INSERT INTO runvars VALUES (?,?,?,?,'t')
+END
+    });
+    logm("runvar increment: $param=$value");
+    return $value;
+}
+
 #---------- running commands eg on targets ----------
 
 sub cmd {
@@ -615,4 +646,142 @@ sub get_host_property ($$;$) {
     return $mhostdb->get_property(@_);
 }
 
+#---------- stashed files ----------
+
+sub open_unique_stashfile ($) {
+    my ($leafref) = @_;
+    my $dh;
+    for (;;) {
+        my $df= $$leafref;
+        $dh= new IO::File "$stash/$df", O_WRONLY|O_EXCL|O_CREAT;
+        last if $dh;
+        die "$df $!" unless $!==&EEXIST;
+        $$leafref .= '+';
+    }
+    return $dh;
+}
+
+sub get_stashed ($$) {
+    my ($param, $otherflightjob) = @_; 
+    # may be run outside transaction, or with flights locked
+    my ($oflight, $ojob) = otherflightjob($otherflightjob);
+    my $path= get_runvar($param, $otherflightjob);
+    die "$path $& " if
+        $path =~ m,[^-+._0-9a-zA-Z/], or
+        $path =~ m/\.\./;
+    return "$c{Stash}/$oflight/$ojob/$path";
+}
+
+#---------- other stuff ----------
+
+sub host_reboot ($) {
+    my ($ho) = @_;
+    target_reboot($ho);
+    poll_loop(40,2, 'reboot-confirm-booted', sub {
+        my $output;
+        if (!eval {
+            $output= target_cmd_output($ho,
+                "stat /dev/shm/osstest-confirm-booted 2>&1 >/dev/null ||:",
+                                       40);
+            1;
+        }) {
+            return $@;
+        }
+        return length($output) ? $output : undef;
+    });
+}
+
+sub target_reboot ($) {
+    my ($ho) = @_;
+    target_cmd_root($ho, "init 6");
+    target_await_down($ho, $timeout{RebootDown});
+    await_tcp(get_timeout($ho,'reboot',$timeout{RebootUp}), 5,$ho);
+}
+
+sub target_reboot_hard ($) {
+    my ($ho) = @_;
+    power_cycle($ho);
+    await_tcp(get_timeout($ho,'reboot',$timeout{HardRebootUp}), 5, $ho);
+}
+
+sub tcpconnect ($$) {
+    my ($host, $port) = @_;
+    my $h= new IO::Handle;
+    my $proto= getprotobyname('tcp');  die $! unless defined $proto;
+    my $fixedaddr= inet_aton($host);
+    my @addrs; my $atype;
+    if (defined $fixedaddr) {
+        @addrs= $fixedaddr;
+        $atype= AF_INET;
+    } else {
+        $!=0; $?=0; my @hi= gethostbyname($host);
+        @hi or die "host lookup failed for $host: $? $!";
+        $atype= $hi[2];
+        @addrs= @hi[4..$#hi];
+        die "connect $host:$port: no addresses for $host" unless @addrs;
+    }
+    foreach my $addr (@addrs) {
+        my $h= new IO::Handle;
+        my $sin; my $pfam; my $str;
+        if ($atype==AF_INET) {
+            $sin= sockaddr_in $port, $addr;
+            $pfam= PF_INET;
+            $str= inet_ntoa($addr);
+#        } elsif ($atype==AF_INET6) {
+#            $sin= sockaddr_in6 $port, $addr;
+#            $pfam= PF_INET6;
+#            $str= inet_ntoa6($addr);
+        } else {
+            warn "connect $host:$port: unknown AF $atype";
+            next;
+        }
+        if (!socket($h, $pfam, SOCK_STREAM, $proto)) {
+            warn "connect $host:$port: unsupported PF $pfam";
+            next;
+        }
+        if (!connect($h, $sin)) {
+            warn "connect $host:$port: [$str]: $!";
+            next;
+        }
+        return $h;
+
+    }
+    die "$host:$port all failed";
+}
+
+#---------- file handling ----------
+
+sub contents_make_cpio ($$$) {
+    my ($fh, $format, $srcdir) = @_;
+    my $child= fork;  defined $child or die $!;
+    if (!$child) {
+        postfork();
+        chdir($srcdir) or die $!;
+        open STDIN, 'find ! -name "*~" ! -name "#*" -type f -print0 |'
+            or die $!;
+        open STDOUT, '>&', $fh or die $!;
+        system "cpio -H$format -o --quiet -0 -R 1000:1000";
+        $? and die $?;
+        $!=0; close STDIN; die "$! $?" if $! or $?;
+        exit 0;
+    }
+    waitpid($child, 0) == $child or die $!;
+    $? and die $?;
+}
+
+sub file_simple_write_contents ($$) {
+    my ($real, $contents) = @_;
+    # $contents may be a coderef in which case we call it with the
+    #  filehandle to allow caller to fill in the file
+
+    unlink $real or $!==&ENOENT or die "$real $!";
+    my $flc= new IO::File "$real",'w' or die "$real $!";
+    if (ref $contents eq 'CODE') {
+        $contents->($flc);
+    } else {
+        print $flc $contents or die "$real $!";
+    }
+    close $flc or die "$real $!";
+}
+
 1;