getmethod
$dbh_tests db_retry db_begin_work
get_filecontents ensuredir get_filecontents_core_quiet system_checked
+
);
%EXPORT_TAGS = ( );
$mjobdb = getmethod("Osstest::JobDB::$c{JobDb}");
$mhostdb = getmethod("Osstest::HostDB::$c{HostDb}");
+
+ $c{TestHostDomain} ||= $c{DnsDomain};
}
sub augmentconfigdefaults {
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
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});
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);
--- /dev/null
+
+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;
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;
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) {
}
}
-sub current_flight ($) {
+sub current_flight ($) { #method
return $ENV{'OSSTEST_FLIGHT'};
}
-sub open () {
+sub open ($) { #method
return opendb('osstestdb');
}
}
}
-sub flight_create () {
+sub flight_create ($) { #method
+ my ($jd) = @_;
$dbh_tests->do(<<END, {}, $branch, $intended);
INSERT INTO flights
(flight, started, blessing, branch, intended)
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
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;
sub job_ensure_started ($) { }
+sub host_check_allocated ($$) { #method
+ my ($jd, $ho) = @_;
+}
+
1;
use POSIX;
use DBI;
use IO::File;
+use IO::Socket::INET;
use Osstest;
target_install_packages target_install_packages_norec
target_extract_jobdistpath
poll_loop
+
+selecthost get_hostflags
+ get_host_property
);
%EXPORT_TAGS = ( );
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;
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...
========================================
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
$whhost ||= 'host';
our $ho= selecthost($whhost);
exit 0 if $ho->{SharedReady};
-die if $ho->{SharedOthers};
our %timeout= qw(ReadPreseed 350
Sshd 2400);
}
$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);
}