Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clone_job.pl: Add option '--skip-download' #771

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions script/clone_job.pl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ =head1 OPTIONS

do not clone parent jobs of type chained. This makes the job use the downloaded hdd image instead of running the generator job again.

=item B<--skip-download>

do not try any download. You need to ensure all required assets are provided yourself.

=item B<--apikey> <value>

specify the public key needed for API authentication
Expand Down Expand Up @@ -117,7 +121,7 @@ ($)
}
}

GetOptions(\%options, "from=s", "host=s", "dir=s", "apikey:s", "apisecret:s", "verbose|v", "skip-deps", "skip-chained-deps", "help|h",) or usage(1);
GetOptions(\%options, "from=s", "host=s", "dir=s", "apikey:s", "apisecret:s", "verbose|v", "skip-deps", "skip-chained-deps", "skip-download", "help|h",) or usage(1);

usage(1) unless @ARGV;
usage(1) unless exists $options{'from'};
Expand Down Expand Up @@ -189,6 +193,36 @@ sub get_job {
return $job;
}

sub download_assets {
my ($job, $remote_url, $ua, %options) = @_;
my @parents = map { get_job($_) } @{$job->{parents}->{Chained}};
ASSET:
for my $type (keys %{$job->{assets}}) {
next if $type eq 'repo'; # we can't download repos
for my $file (@{$job->{assets}->{$type}}) {
my $dst = $file;
unless ($options{'skip-deps'} || $options{'skip-chained-deps'}) {
for my $j (@parents, $job) {
next ASSET if $j->{settings}->{PUBLISH_HDD_1} && $file eq $j->{settings}->{PUBLISH_HDD_1};
}
}
$dst =~ s,.*/,,;
$dst = join('/', $options{dir}, $type, $dst);
my $from = $remote_url->clone;
$from->path(sprintf '/tests/%d/asset/%s/%s', $jobid, $type, $file);
$from = $from->to_string;

die "can't write $options{dir}/$type\n" unless -w "$options{dir}/$type";

print "downloading\n$from\nto\n$dst\n";
my $r = $ua->mirror($from, $dst);
unless ($r->is_success || $r->code == 304) {
die "$jobid failed: ", $r->status_line, "\n";
}
}
}
}

sub clone_job {
my ($jobid, $clone_map, $depth) = @_;
$clone_map //= {};
Expand All @@ -215,32 +249,7 @@ sub clone_job {
$job->{settings}->{_START_AFTER_JOBS} = join(',', @new_chained) if @new_chained;
}

my @parents = map { get_job($_) } @{$job->{parents}->{Chained}};
ASSET:
for my $type (keys %{$job->{assets}}) {
next if $type eq 'repo'; # we can't download repos
for my $file (@{$job->{assets}->{$type}}) {
my $dst = $file;
unless ($options{'skip-deps'} || $options{'skip-chained-deps'}) {
for my $j (@parents, $job) {
next ASSET if $file eq $j->{settings}->{PUBLISH_HDD_1};
}
}
$dst =~ s,.*/,,;
$dst = join('/', $options{dir}, $type, $dst);
my $from = $remote_url->clone;
$from->path(sprintf '/tests/%d/asset/%s/%s', $jobid, $type, $file);
$from = $from->to_string;

die "can't write $options{dir}/$type\n" unless -w "$options{dir}/$type";

print "downloading\n$from\nto\n$dst\n";
my $r = $ua->mirror($from, $dst);
unless ($r->is_success || $r->code == 304) {
die "$jobid failed: ", $r->status_line, "\n";
}
}
}
download_assets($job, $remote_url, $ua, %options) unless $options{'skip-download'};

my $url = $local_url->clone;
my %settings = %{$job->{settings}};
Expand Down