Skip to content

Commit

Permalink
Merge pull request #1699 from foursixnine/oopsitsbrokenagain
Browse files Browse the repository at this point in the history
Fix disabling of compression in qemu
  • Loading branch information
mergify[bot] committed Aug 3, 2021
2 parents a394b69 + eb207de commit ad28b4b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions OpenQA/Qemu/BlockDevConf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ sub gen_qemu_img_commit {
}

sub gen_qemu_img_convert {
my ($self, $filter, $img_dir, $name) = @_;
my ($self, $filter, $img_dir, $name, $qemu_compress_qcow) = @_;

return
map { $_->gen_qemu_img_convert($img_dir, $name) }
map { $_->gen_qemu_img_convert($img_dir, $name, $qemu_compress_qcow) }
grep { $_->id =~ $filter } @{$self->_drives};
}

Expand Down
7 changes: 4 additions & 3 deletions OpenQA/Qemu/DriveDevice.pm
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ sub gen_qemu_img_cmdlines {
}

sub gen_qemu_img_convert {
my ($self, $img_dir, $name) = @_;
my @cmd = qw(convert);
my ($self, $img_dir, $name, $qemu_compress_qcow) = @_;

# By compressing we are making the images self contained, i.e. they are
# portable by not requiring backing files referencing the openQA instance.
# Compressing takes longer but the transfer takes shorter amount of time.
my $compress = $bmwqemu::vars{QEMU_COMPRESS_QCOW2} //= 1;
my $compress = $qemu_compress_qcow;
my @cmd = qw(convert);
push @cmd, qw(-c) if $compress;
push @cmd, ('-O', QEMU_IMAGE_FORMAT, $self->drive->file, "$img_dir/$name");
return \@cmd;
Expand Down
3 changes: 2 additions & 1 deletion backend/qemu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ sub do_extract_assets {
$self->{proc}->load_state() unless $self->{proc}->has_state();
mkpath($img_dir);
bmwqemu::fctinfo("Extracting $pattern");
my $res = $self->{proc}->export_blockdev_images($pattern, $img_dir, $name);
my $qemu_compress_qcow = $bmwqemu::vars{QEMU_COMPRESS_QCOW2} // 1;
my $res = $self->{proc}->export_blockdev_images($pattern, $img_dir, $name, $qemu_compress_qcow);
die "Expected one drive to be exported, not $res" if $res != 1;
}

Expand Down
21 changes: 11 additions & 10 deletions t/18-qemu.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ is_deeply(\@gcmdl, \@cmdl, 'Generate qemu command line for single new drive');
@gcmdl = $bdc->gen_qemu_img_cmdlines();
is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img command line for single new drive');

@cmdl = [qw(convert -c -O qcow2 raid/hd1 images/hd1.qcow2)];
@gcmdl = $bdc->gen_qemu_img_convert(qr/^hd/, 'images', 'hd1.qcow2');
my $compress = 1;
@cmdl = (['convert', '-c', '-O', 'qcow2', 'raid/hd1', 'images/hd1.qcow2']);
@gcmdl = $bdc->gen_qemu_img_convert(qr/^hd/, 'images', 'hd1.qcow2', $compress);
is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img convert for single new drive');

@cmdl = [qw(convert -O qcow2 raid/hd1 images/hd2.qcow2)];
$bmwqemu::vars{QEMU_COMPRESS_QCOW2} = 0;
@gcmdl = $bdc->gen_qemu_img_convert(qr/^hd/, 'images', 'hd2.qcow2');
is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img convert with disabled compression');
$bmwqemu::vars{QEMU_COMPRESS_QCOW2} = 1;
$compress = 0;
@cmdl = (['convert', '-O', 'qcow2', 'raid/hd1', 'images/hd1.qcow2']);
@gcmdl = $bdc->gen_qemu_img_convert(qr/^hd/, 'images', 'hd1.qcow2', $compress);
is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img convert for single new drive, without compression');

@cmdl = ('-blockdev', 'driver=file,node-name=hd1-file,filename=raid/hd1,cache.no-flush=on',
'-blockdev', 'driver=qcow2,node-name=hd1,file=hd1-file,cache.no-flush=on',
Expand Down Expand Up @@ -92,8 +92,9 @@ is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img command line for single existing d
@gcmdl = $bdc->gen_unlink_list();
is_deeply(\@cmdl, \@gcmdl, 'Generate unlink list for single existing drive');

@cmdl = (['convert', '-c', '-O', 'qcow2', 'raid/hd1-overlay0', 'images/hd1.qcow2']);
@gcmdl = $bdc->gen_qemu_img_convert(qr/^hd1/, 'images', 'hd1.qcow2');
$compress = 1;
@cmdl = (['convert', '-c', '-O', 'qcow2', 'raid/hd1-overlay0', 'images/hd1.qcow2']);
@gcmdl = $bdc->gen_qemu_img_convert(qr/^hd1/, 'images', 'hd1.qcow2', $compress);
is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img convert for single existing drive');

my %vars;
Expand Down Expand Up @@ -238,7 +239,7 @@ is_deeply(\@gcmdl, \@cmdl, 'Generate reverted snapshot images');
is_deeply(\@gcmdl, \@cmdl, 'Generate unlink list of reverted snapshot images');

@cmdl = (['convert', '-c', '-O', 'qcow2', 'raid/hd0-overlay1', 'images/hd0.qcow2']);
@gcmdl = $bdc->gen_qemu_img_convert(qr/^hd0$/, 'images', 'hd0.qcow2');
@gcmdl = $bdc->gen_qemu_img_convert(qr/^hd0$/, 'images', 'hd0.qcow2', $compress);
is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img convert with snapshots');

@cmdl = ('qemu-kvm', '-static-args',
Expand Down

0 comments on commit ad28b4b

Please sign in to comment.