]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
wip reorg ts-host-install
authorIan Jackson <iwj@woking.cam.xci-test.com>
Mon, 15 Oct 2012 17:00:10 +0000 (18:00 +0100)
committerIan Jackson <iwj@woking.cam.xci-test.com>
Mon, 15 Oct 2012 17:00:10 +0000 (18:00 +0100)
Osstest.pm
Osstest/Executive.pm
Osstest/HostDB/Executive.pm [new file with mode: 0644]
Osstest/HostDB/Static.pm
Osstest/JobDB/Executive.pm
Osstest/JobDB/Standalone.pm
Osstest/TestSupport.pm
README
standalone-config-example
ts-host-install
ts-hosts-allocate-Standalone

index 0cecb2a4a115f1da6175c2bf46bd08d8364e9b5c..f0105eec86a4887d90fd20172628c7abf9d7d0d3 100644 (file)
@@ -18,6 +18,7 @@ BEGIN {
                       getmethod
                       $dbh_tests db_retry db_begin_work                      
 get_filecontents ensuredir get_filecontents_core_quiet system_checked
+
                       );
     %EXPORT_TAGS = ( );
 
@@ -93,6 +94,8 @@ sub readglobalconfig () {
 
     $mjobdb = getmethod("Osstest::JobDB::$c{JobDb}");
     $mhostdb = getmethod("Osstest::HostDB::$c{HostDb}");
+
+    $c{TestHostDomain} ||= $c{DnsDomain};
 }
 
 sub augmentconfigdefaults {
index 13f798d129a4800fb7822d5f104234ceeaddea6e..dadba13858cb592e33cec38b9bd6ddf8593ac657 100644 (file)
@@ -81,8 +81,7 @@ BEGIN {
                       resource_check_allocated resource_shared_mark_ready
                       built_stash duration_estimator
                       csreadconfig ts_get_host_guest
-                      opendb_state selecthost get_hostflags
-                      get_host_property get_timeout
+                      opendb_state get_timeout
                       host_involves_pcipassthrough host_get_pcipassthrough_devs
                       postfork
                        link_file_contents create_webfile
@@ -1040,13 +1039,6 @@ sub get_hostflags ($) {
     return grep /./, split /\,/, $flags;
 }
 
-sub get_host_property ($$;$) {
-    my ($ho, $prop, $defval) = @_;
-    my $row= $ho->{Properties}{$prop};
-    return $defval unless $row && defined $row->{val};
-    return $row->{val};
-}
-
 sub host_involves_pcipassthrough ($) {
     my ($ho) = @_;
     return !!grep m/^pcipassthrough\-/, get_hostflags($ho->{Ident});
@@ -1070,100 +1062,6 @@ sub host_get_pcipassthrough_devs ($) {
     return @devs;
 }
 
-sub selecthost ($) {
-    my ($ident) = @_;
-    # must be run outside transaction
-    my $name;
-    if ($ident =~ m/=/) {
-        $ident= $`;
-        $name= $'; #'
-        $r{$ident}= $name;
-    } else {
-        $name= $r{$ident};
-        die "no specified $ident" unless defined $name;
-    }
-
-    my $ho= {
-        Ident => $ident,
-        Name => $name,
-        TcpCheckPort => 22,
-        Fqdn => "$name.$c{TestHostDomain}",
-        Info => [],
-        Suite => get_runvar_default("${ident}_suite",$job,$c{Suite}),
-    };
-
-    $ho->{Properties}= $dbh_tests->selectall_hashref(<<END, 'name', {}, $name);
-        SELECT * FROM resource_properties
-            WHERE restype='host' AND resname=?
-END
-
-    my $getprop= sub {
-        my ($k,$r) = @_;
-        my $row= $ho->{Properties}{$r};
-        return unless $row;
-        $ho->{$k}= $row->{val};
-    };
-    $ho->{Ether}= get_host_property($ho,'ether');
-    $ho->{Power}= get_host_property($ho,'power-method');
-    $ho->{DiskDevice}= get_host_property($ho,'disk-device');
-    $ho->{DhcpLeases}= get_host_property($ho,'dhcp-leases',$c{Dhcp3Leases});
-
-    if (!$ho->{Ether} || !$ho->{Power}) {
-        my $dbh_config= opendb('configdb');
-        my $selname= $ho->{Fqdn};
-        my $sth= $dbh_config->prepare(<<END);
-            SELECT * FROM ips WHERE reverse_dns = ?
-END
-        $sth->execute($selname);
-        my $row= $sth->fetchrow_hashref();
-        die "$ident $name $selname ?" unless $row;
-        die if $sth->fetchrow_hashref();
-        $sth->finish();
-        my $get= sub {
-            my ($k,$nowarn) = @_;
-            my $v= $row->{$k};
-            defined $v or $nowarn or
-                warn "host $name: undefined $k in configdb::ips\n";
-            return $v;
-        };
-        $ho->{Asset}= $get->('asset',1);
-        $ho->{Ether} ||= $get->('hardware');
-        $ho->{Power} ||= "statedb $ho->{Asset}";
-        push @{ $ho->{Info} }, "(asset=$ho->{Asset})" if defined $ho->{Asset};
-        $dbh_config->disconnect();
-    }
-
-    my $ip_packed= gethostbyname($ho->{Fqdn});
-    die "$ho->{Fqdn} ?" unless $ip_packed;
-    $ho->{Ip}= inet_ntoa($ip_packed);
-    die "$ho->{Fqdn} ?" unless defined $ho->{Ip};
-
-    $ho->{Flags}= { };
-    my $flagsq= $dbh_tests->prepare(<<END);
-        SELECT hostflag FROM hostflags WHERE hostname=?
-END
-    $flagsq->execute($name);
-    while (my ($flag) = $flagsq->fetchrow_array()) {
-        $ho->{Flags}{$flag}= 1;
-    }
-    $flagsq->finish();
-
-    $ho->{Shared}= resource_check_allocated('host', $name);
-    $ho->{SharedReady}=
-        $ho->{Shared} &&
-        $ho->{Shared}{State} eq 'ready' &&
-        !! grep { $_ eq "share-".$ho->{Shared}{Type} } get_hostflags($ident);
-    $ho->{SharedOthers}=
-        $ho->{Shared} ? $ho->{Shared}{Others} : 0;
-
-    logm("host: selected $ho->{Name} $ho->{Ether} $ho->{Ip}".
-         (!$ho->{Shared} ? '' :
-          sprintf(" - shared %s %s %d", $ho->{Shared}{Type},
-                  $ho->{Shared}{State}, $ho->{Shared}{Others}+1)));
-    
-    return $ho;
-}
-
 sub get_timeout ($$$) {
     my ($ho,$which,$default) = @_;
     return $default + get_host_property($ho, "$which-time-extra", 0);
diff --git a/Osstest/HostDB/Executive.pm b/Osstest/HostDB/Executive.pm
new file mode 100644 (file)
index 0000000..e7d9428
--- /dev/null
@@ -0,0 +1,84 @@
+
+package Osstest::HostDB::Executive;
+
+use strict;
+use warnings;
+
+use Osstest;
+use Osstest::Executive;
+
+BEGIN {
+    use Exporter ();
+    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
+    $VERSION     = 1.00;
+    @ISA         = qw(Exporter);
+    @EXPORT      = qw();
+    %EXPORT_TAGS = ( );
+
+    @EXPORT_OK   = qw();
+}
+
+sub new { return bless {}, $_[0]; }
+
+sub get_properties ($$) {
+    my ($hd, $name) = @_;
+    
+    return $dbh_tests->selectall_hashref(<<END, 'name', {}, $name);
+        SELECT * FROM resource_properties
+            WHERE restype='host' AND resname=?
+END
+}
+
+sub get_flags ($$) {
+    my ($hd, $ho) = @_;
+
+    my $flags = { };
+    my $flagsq= $dbh_tests->prepare(<<END);
+        SELECT hostflag FROM hostflags WHERE hostname=?
+END
+    $flagsq->execute($ho->{Name});
+
+    while (my ($flag) = $flagsq->fetchrow_array()) {
+        $flags->{$flag}= 1;
+    }
+    $flagsq->finish();
+    return $flags;
+}
+
+sub get_property ($$$;$) {
+    my ($hd, $ho, $prop, $defval) = @_;
+    my $row= $ho->{Properties}{$prop};
+    return $defval unless $row && defined $row->{val};
+    return $row->{val};
+}
+
+sub default_methods ($$) {
+    my ($hd, $ho) = @_;
+
+    return if $ho->{Ether} && $ho->{Power};
+
+    my $dbh_config= opendb('configdb');
+    my $selname= $ho->{Fqdn};
+    my $sth= $dbh_config->prepare(<<END);
+            SELECT * FROM ips WHERE reverse_dns = ?
+END
+    $sth->execute($selname);
+    my $row= $sth->fetchrow_hashref();
+    die "$ident $name $selname ?" unless $row;
+    die if $sth->fetchrow_hashref();
+    $sth->finish();
+    my $get= sub {
+       my ($k,$nowarn) = @_;
+       my $v= $row->{$k};
+       defined $v or $nowarn or
+           warn "host $name: undefined $k in configdb::ips\n";
+       return $v;
+    };
+    $ho->{Asset}= $get->('asset',1);
+    $ho->{Ether} ||= $get->('hardware');
+    $ho->{Power} ||= "statedb $ho->{Asset}";
+    push @{ $ho->{Info} }, "(asset=$ho->{Asset})" if defined $ho->{Asset};
+    $dbh_config->disconnect();
+}
+
+1;
index e882854809951310c8e8f6a8b0fc6867206f6e63..53456f40e56a5037b79fb4c65bcb112833f43402 100644 (file)
@@ -20,4 +20,63 @@ BEGIN {
 
 sub new { return bless {}, $_[0]; }
 
+sub get_properties ($$) { #method
+    my ($hd, $name) = @_;
+    my $hp = { };
+    my $k;
+    foreach $k (keys %c) {
+       next unless $k =~ m/^HostProp_([A-Z].*)$/;
+       $hp->{$1} = $c{$k};
+    }
+    foreach $k (keys %c) {
+       next unless $k =~ m/^HostProp_([a-z0-9]+)_(.*)$/;
+       next unless $1 eq $name;
+       $hp->{$2} = $c{$k};
+    }
+    return $hp;
+}
+
+sub get_property ($$$;$) { #method
+    my ($hd, $ho, $prop, $defval) = @_;
+
+    $prop = ucfirst $prop;
+    while ($prop =~ m/-/) {
+       $prop = $`.ucfirst $'; #';
+    }
+
+    my $val = $ho->{Properties}{$prop};
+    return $defval unless defined $val;
+    return $val;
+}
+
+sub get_flags ($$) { #method
+    my ($hd, $ho) = @_;
+
+    my $flags = { };
+    my $process = sub {
+       my $str = $c{$_[0]};
+       return unless defined $str;
+       foreach my $fl (split /[ \t,;]+/, $str) {
+           next unless length $fl;
+           if ($fl =~ s/^\!//) {
+               delete $flags->{$fl};
+           } else {
+               $flags->{$fl} = 1;
+           }
+       }
+    };
+
+    $process->('HostFlags');
+    $process->("HostFlags_$ho->{Name}");
+
+    return $flags;
+}
+
+sub default_methods ($$) { #method
+    my ($hd, $ho) = @_;
+
+    die "need ethernet address for $ho->{Name}" unless $ho->{Ether};
+    $ho->{Power} ||= "manual $ho->{Name}";
+}
+
 1;
index 1ccb2d089be2a49babe50d75ede32243fa4b843e..ee9a7826fe33340ad93befbd5e730286ace6bda6 100644 (file)
@@ -19,8 +19,8 @@ BEGIN {
 
 sub new { return bless {}, Osstest::JobDB::Standalone };
 
-sub begin_work ($$) {
-    my ($dbh,$tables) = @_;
+sub begin_work ($$$) { #method
+    my ($jd, $dbh,$tables) = @_;
     
     return if $ENV{'OSSTEST_DEBUG_NOSQLLOCK'};
     foreach my $tab (@$tables) {
@@ -28,11 +28,11 @@ sub begin_work ($$) {
     }
 }
 
-sub current_flight ($) {
+sub current_flight ($) { #method
     return $ENV{'OSSTEST_FLIGHT'};
 }
 
-sub open () {
+sub open ($) { #method
     return opendb('osstestdb');
 }
 
@@ -68,7 +68,8 @@ END
     }
 }
 
-sub flight_create () {
+sub flight_create ($) { #method
+    my ($jd) = @_;
     $dbh_tests->do(<<END, {}, $branch, $intended);
              INSERT INTO flights
                          (flight,  started, blessing,       branch, intended)
@@ -79,7 +80,9 @@ END
     return $fl
 }
 
-sub job_ensure_started ($) {
+sub job_ensure_started ($) { #method
+    my ($jd) = @_;
+
     my ($count) = $dbh_tests->selectrow_array(<<END,{}, $flight, $job);
             SELECT count(*) FROM jobs WHERE flight=? AND job=?
 END
@@ -97,3 +100,18 @@ END
 END
     logm("starting $flight started=$now") if $count>0;
 }
+
+sub host_check_allocated ($$) { #method
+    my ($jd, $ho) = @_;
+    $ho->{Shared}= resource_check_allocated('host', $name);
+    $ho->{SharedReady}=
+        $ho->{Shared} &&
+        $ho->{Shared}{State} eq 'ready' &&
+        !! grep { $_ eq "share-".$ho->{Shared}{Type} } get_hostflags($ident);
+    $ho->{SharedOthers}=
+        $ho->{Shared} ? $ho->{Shared}{Others} : 0;
+    
+    die if $ho->{SharedOthers} && !$ho->{SharedReady};
+}
+
+1;
index 0e8c196f3d1ef86470fed44d32604208bf11b388..9a115220df11762edbb00438a4bed4f01e05b757 100644 (file)
@@ -61,4 +61,8 @@ sub current_flight ($) {
 
 sub job_ensure_started ($) { }
 
+sub host_check_allocated ($$) { #method
+    my ($jd, $ho) = @_;
+}
+
 1;
index c60aca5db1497cea2214583a68bb3a50c3b4c46d..213b20151508c558bffadd90ca9e3456a565e545 100644 (file)
@@ -7,6 +7,7 @@ use warnings;
 use POSIX;
 use DBI;
 use IO::File;
+use IO::Socket::INET;
 
 use Osstest;
 
@@ -33,6 +34,9 @@ store_runvar get_runvar get_runvar_maybe get_runvar_default need_runvars
                       target_install_packages target_install_packages_norec
                       target_extract_jobdistpath
 poll_loop
+
+selecthost get_hostflags
+                      get_host_property 
                       );
     %EXPORT_TAGS = ( );
 
@@ -516,4 +520,60 @@ sub poll_loop ($$$&) {
     logm("$what: ok. (${waited}s)");
 }
 
+#---------- host selection and properties ----------
+
+sub selecthost ($) {
+    my ($ident) = @_;
+    # must be run outside transaction
+    my $name;
+    if ($ident =~ m/=/) {
+        $ident= $`;
+        $name= $'; #'
+        $r{$ident}= $name;
+    } else {
+        $name= $r{$ident};
+        die "no specified $ident" unless defined $name;
+    }
+
+    my $fqdn = $name;
+    $fqdn .= ".$c{TestHostDomain}" unless $fqdn =~ m/\./;
+    my $ho= {
+        Ident => $ident,
+        Name => $name,
+        TcpCheckPort => 22,
+        Fqdn => $fqdn,
+        Info => [],
+        Suite => get_runvar_default("${ident}_suite",$job,$c{Suite}),
+    };
+
+    $ho->{Properties} = $mhostdb->get_properties($name);
+
+    $ho->{Ether}= get_host_property($ho,'ether');
+    $ho->{Power}= get_host_property($ho,'power-method');
+    $ho->{DiskDevice}= get_host_property($ho,'disk-device');
+    $ho->{DhcpLeases}= get_host_property($ho,'dhcp-leases',$c{Dhcp3Leases});
+
+    $mhostdb->default_methods($ho);
+
+    my $ip_packed= gethostbyname($ho->{Fqdn});
+    die "$ho->{Fqdn} ?" unless $ip_packed;
+    $ho->{Ip}= inet_ntoa($ip_packed);
+    die "$ho->{Fqdn} ?" unless defined $ho->{Ip};
+
+    $ho->{Flags} = $mhostdb->get_flags($ho);
+
+    $mjobdb->host_check_allocated($ho);
+
+    logm("host: selected $ho->{Name} $ho->{Ether} $ho->{Ip}".
+         (!$ho->{Shared} ? '' :
+          sprintf(" - shared %s %s %d", $ho->{Shared}{Type},
+                  $ho->{Shared}{State}, $ho->{Shared}{Others}+1)));
+
+    return $ho;
+}
+
+sub get_host_property ($$;$) {
+    return $mhostdb->get_property(@_);
+}
+
 1;
diff --git a/README b/README
index e1753525f97cf78eccd64ceeeffc5cc64286c489..392ca09875fdf04fb6134346595bceb396e180cc 100644 (file)
--- a/README
+++ b/README
@@ -18,8 +18,15 @@ JobDbStandaloneFilename
    Database file to use to record the "jobs" and their run variables.
    Default: ./standalone.db (sqlite3)
 
-TargetHost_<ident>      where eg <ident> = "host"
-TargetHost
+TestHostDomain            defaults to DnsDomain
+
+TestHost_<ident>      where eg <ident> = "host"
+TestHost
+
+HostProp_<property>
+HostProp_<host>_<property>
+HostFlags                flag,flag,flag,...
+HostFlags_<host>         flag,!flag,!flag,flag...
 
 ========================================
 
index 08bb2cf1d474f4900636c6ac1880cba9617aa383..10406fd10fe93bf1ff6cb881963abd51e05822b5 100644 (file)
@@ -1,3 +1,4 @@
 DnsDomain cam.xci-test.com
 NetNameservers 10.80.248.2 10.80.16.28 10.80.16.67
 TargetHost bedbug
+HostProp_bedbug_Ether 00:13:72:14:c0:51
index 21a739181a4cd005ea4ee94e002e68214d296be3..a1ae3203788452a7fdb5fbaa270924e33b17d792 100755 (executable)
@@ -23,7 +23,6 @@ our ($whhost) = @ARGV;
 $whhost ||= 'host';
 our $ho= selecthost($whhost);
 exit 0 if $ho->{SharedReady};
-die if $ho->{SharedOthers};
 
 our %timeout= qw(ReadPreseed  350
                  Sshd        2400);
index cbdb725c08889c4caf75fd1f405b1f6cb2cbb861..bed3afb3323661f1609b7a94c3c1afc623b0adac 100755 (executable)
@@ -13,8 +13,8 @@ foreach my $ident (@ARGV) {
     }
     $host ||= $r{$ident};;
     $host ||= $ENV{'OSSTEST_HOST_'.uc $ident};
-    $host ||= $c{"TargetHost_$ident"};
-    $host ||= $c{TargetHost};
+    $host ||= $c{"TestHost_$ident"};
+    $host ||= $c{TestHost};
     $host || die "need host setting for $ident";
     store_runvar($ident, $host);
 }