Skip to content

Commit

Permalink
Render autoinst url from openQA url
Browse files Browse the repository at this point in the history
1.New subroutine render_autoinst_url in lib/utils.pm to render
autoinst url from openQA, in order to avoid direct downloading
from openQA instance.
2.Replace direct openQA address with rendered autoinst url in
lib/guest_installation_and_configuration_base.pm.
  • Loading branch information
waynechen55 authored and alice-suse committed Mar 4, 2025
1 parent e9811e9 commit 97468c5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/guest_installation_and_configuration_base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1882,17 +1882,17 @@ sub config_guest_installation_media {
}
}
elsif ($self->{guest_installation_media} =~ /^.*\.(raw|raw\.xz|qcow2)$/i) {
if (script_output("curl --silent -I $self->{guest_installation_media} | grep -E \"^HTTP\" | awk -F \" \" \'{print \$2}\'") == "200") {
if (script_output("curl --silent -I " . render_autoinst_url(url => $self->{guest_installation_media}) . " | grep -E \"^HTTP\" | awk -F \" \" \'{print \$2}\'") == "200") {
if ($self->{guest_installation_media} =~ /^.*\.raw\.xz$/i) {
assert_script_run("curl -s -o $self->{guest_storage_backing_path}.xz $self->{guest_installation_media}", timeout => 1200);
assert_script_run("curl -s -o $self->{guest_storage_backing_path}.xz " . render_autoinst_url(url => $self->{guest_installation_media}), timeout => 1200);
assert_script_run("xz -d $self->{guest_storage_backing_path}.xz", timeout => 120);
}
else {
assert_script_run("curl -s -o $self->{guest_storage_backing_path} $self->{guest_installation_media}", timeout => 3600);
assert_script_run("curl -s -o $self->{guest_storage_backing_path} " . render_autoinst_url(url => $self->{guest_installation_media}), timeout => 3600);
}
}
else {
record_info("Installation media $self->{guest_installation_media} does not exist", script_output("curl -I $self->{guest_installation_media}", proceed_on_failure => 1), result => 'fail');
record_info("Installation media $self->{guest_installation_media} does not exist", script_output("curl -I " . render_autoinst_url(url => $self->{guest_installation_media}), proceed_on_failure => 1), result => 'fail');
$self->record_guest_installation_result('FAILED');
}
}
Expand Down
33 changes: 33 additions & 0 deletions lib/utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ our @EXPORT = qw(
is_ipxe_with_disk_image
is_reboot_needed
install_extra_packages
render_autoinst_url
);

our @EXPORT_OK = qw(
Expand Down Expand Up @@ -3281,4 +3282,36 @@ sub install_extra_packages {
save_screenshot;
}

=head2 render_autoinst_url
render_autoinst_url(url => 'openQA url');
In order to avoid downloading resources directly from openQA instance, rendering
autoinst url from given openQA url is necessary. Argument url accetps legal HTTP
url addresses, but it will be returned directly without rendering if it is not an
openQA url.
=cut

sub render_autoinst_url {
my %args = @_;
$args{url} //= '';

croak("Can not render autoinst url from empty url") if (!$args{url});
if ($args{url} =~ /^(http|https)\:\/\/openqa\./im) {
my $openqa_instance = get_required_var('OPENQA_HOSTNAME');
$openqa_instance =~ s/\./\\\./g;
if ($args{url} !~ /(http|https)\:\/\/$openqa_instance\//im) {
record_info("Not url on running openQA $openqa_instance", "Can not render running openQA autoinst url from $args{url}", result => 'fail');
return $args{url};
}
my $autoinst_url = autoinst_url('/' . join('/', (split('/', $args{url}))[3 .. (scalar split('/', $args{url})) - 1]));
record_info("Rendered autoinst url from running openQA instance", "Rendered url $autoinst_url from $args{url}");
return $autoinst_url;
}
else {
record_info("Can not render autoinst url from non-openQA url", "Return original url $args{url}", result => 'fail');
return $args{url};
}
}

1;

0 comments on commit 97468c5

Please sign in to comment.