hydra/tests/Setup.pm

86 lines
2.6 KiB
Perl
Raw Normal View History

2011-03-16 13:18:12 +00:00
package Setup;
use strict;
use Exporter;
2011-03-17 13:25:27 +00:00
use Hydra::Helper::Nix;
2012-03-13 12:18:40 +00:00
use Hydra::Model::DB;
2011-03-17 13:25:27 +00:00
use Hydra::Helper::AddBuilds;
use Cwd;
2011-03-16 13:18:12 +00:00
our @ISA = qw(Exporter);
2012-04-15 01:17:35 +00:00
our @EXPORT = qw(hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild updateRepository);
2011-03-16 13:18:12 +00:00
sub hydra_setup {
my ($db) = @_;
$db->resultset('Users')->create({ username => "root", emailaddress => 'root@email.com', password => '' });
}
2011-03-17 11:55:39 +00:00
sub nrBuildsForJobset {
my ($jobset) = @_;
return $jobset->builds->search({},{})->count ;
}
2011-03-17 13:25:27 +00:00
sub queuedBuildsForJobset {
my ($jobset) = @_;
2012-03-12 20:13:50 +00:00
return $jobset->builds->search({finished => 0});
2011-03-17 13:25:27 +00:00
}
2011-03-17 11:55:39 +00:00
sub nrQueuedBuildsForJobset {
my ($jobset) = @_;
2011-03-17 13:25:27 +00:00
return queuedBuildsForJobset($jobset)->count ;
2011-03-17 11:55:39 +00:00
}
sub createBaseJobset {
my ($jobsetName, $nixexprpath) = @_;
2011-03-17 13:25:27 +00:00
2012-03-13 12:18:40 +00:00
my $db = Hydra::Model::DB->new;
my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"});
2011-03-17 11:55:39 +00:00
my $jobset = $project->jobsets->create({name => $jobsetName, nixexprinput => "jobs", nixexprpath => $nixexprpath, emailoverride => ""});
my $jobsetinput;
my $jobsetinputals;
$jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"});
return $jobset;
}
sub createJobsetWithOneInput {
my ($jobsetName, $nixexprpath, $name, $type, $uri) = @_;
my $jobset = createBaseJobset($jobsetName, $nixexprpath);
my $jobsetinput;
my $jobsetinputals;
$jobsetinput = $jobset->jobsetinputs->create({name => $name, type => $type});
2011-03-21 12:30:47 +00:00
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => $uri});
2011-03-17 11:55:39 +00:00
return $jobset;
}
sub evalSucceeds {
my ($jobset) = @_;
my ($res, $stdout, $stderr) = captureStdoutStderr(60, ("../src/script/hydra-evaluator", $jobset->project->name, $jobset->name));
chomp $stdout; chomp $stderr;
2011-03-17 11:55:39 +00:00
print STDERR "Evaluation errors for jobset ".$jobset->project->name.":".$jobset->name.": \n".$jobset->errormsg."\n" if $jobset->errormsg;
print STDERR "STDOUT: $stdout\n" if $stdout ne "";
print STDERR "STDERR: $stderr\n" if $stderr ne "";
2011-03-17 11:55:39 +00:00
return $res;
}
2011-03-17 13:25:27 +00:00
sub runBuild {
my ($build) = @_;
2011-11-30 17:03:50 +00:00
return captureStdoutStderr(60, ("../src/script/hydra-build", $build->id));
2011-03-17 13:25:27 +00:00
}
2012-04-15 01:17:35 +00:00
sub updateRepository {
my ($scm, $update, $repo) = @_;
my ($res, $stdout, $stderr) = captureStdoutStderr(60, ($update, $repo));
die "Unexpected update error with $scm: $stderr\n" unless $res;
print STDOUT "Update $scm repository: $stdout" if $stdout ne "";
return $stdout ne "";
}
2011-03-16 13:18:12 +00:00
1;