You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
os-autoinst/1765.patch

103 lines
4.8 KiB

From 489916d5a18113365a97eb3181cbb6c5e351c467 Mon Sep 17 00:00:00 2001
From: Marius Kittler <mkittler@suse.de>
Date: Wed, 8 Sep 2021 18:20:52 +0200
Subject: [PATCH] Deduce format of backing file from extension
* So even if we assign an ISO as HDD_x we would use the correct parameter
`-F raw` (and not `-F qcow2`)
* See https://github.com/os-autoinst/os-autoinst/pull/1764/files#r704549754
and https://progress.opensuse.org/issues/98117
---
OpenQA/Qemu/BlockDev.pm | 4 +++-
OpenQA/Qemu/BlockDevConf.pm | 10 ++++------
t/18-qemu.t | 16 +++++++++++-----
3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/OpenQA/Qemu/BlockDev.pm b/OpenQA/Qemu/BlockDev.pm
index 99a970ddb6..58f226fc65 100644
--- a/OpenQA/Qemu/BlockDev.pm
+++ b/OpenQA/Qemu/BlockDev.pm
@@ -33,7 +33,7 @@ weakened.
=cut
package OpenQA::Qemu::BlockDev;
-use Mojo::Base 'OpenQA::Qemu::MutParams';
+use Mojo::Base 'OpenQA::Qemu::MutParams', -signatures;
use Scalar::Util 'weaken';
use OpenQA::Qemu::SnapshotConf;
@@ -216,6 +216,8 @@ sub _from_map {
->snapshot($snap_conf->get_snapshot(sequence => $this->{snapshot}));
}
+sub deduce_driver ($self) { $self->driver($self->file =~ qr/\.qcow2$/ ? 'qcow2' : 'raw') }
+
sub CARP_TRACE { 'OpenQA::Qemu::BlockDev(' . (shift->node_name || '') . ')' }
1;
diff --git a/OpenQA/Qemu/BlockDevConf.pm b/OpenQA/Qemu/BlockDevConf.pm
index 2b8dacbf32..bac282dfbc 100644
--- a/OpenQA/Qemu/BlockDevConf.pm
+++ b/OpenQA/Qemu/BlockDevConf.pm
@@ -131,7 +131,7 @@ new overlay is created so that the existing qcow2 image is not modified.
sub add_existing_drive {
my ($self, $id, $file_name, $model, $size, $num_queues) = @_;
- my $base_drive = $self->add_existing_base($id, $file_name, $size)->implicit(1);
+ my $base_drive = $self->add_existing_base($id, $file_name, $size)->implicit(1)->deduce_driver;
my $overlay = $self->add_new_overlay($id . OVERLAY_POSTFIX . '0', $base_drive);
return $self->_push_new_drive_dev($id, $overlay, $model, $num_queues);
@@ -164,11 +164,9 @@ variables. See the OpenQA::Qemu::PFlashDevice class.
=cut
sub add_pflash_drive {
my ($self, $id, $file_name, $size) = @_;
- my $base_drive = $self->add_existing_base($id, $file_name, $size)
- ->implicit(1)
- ->driver($file_name =~ qr/\.qcow2$/ ? 'qcow2' : 'raw');
- my $overlay = $self->add_new_overlay($id . OVERLAY_POSTFIX . '0', $base_drive);
- my $pflash = OpenQA::Qemu::PFlashDevice->new()
+ my $base_drive = $self->add_existing_base($id, $file_name, $size)->implicit(1)->deduce_driver;
+ my $overlay = $self->add_new_overlay($id . OVERLAY_POSTFIX . '0', $base_drive);
+ my $pflash = OpenQA::Qemu::PFlashDevice->new()
->id($id)
->drive($overlay);
diff --git a/t/18-qemu.t b/t/18-qemu.t
index 2d15dc1850..9483b296d4 100755
--- a/t/18-qemu.t
+++ b/t/18-qemu.t
@@ -114,7 +114,7 @@ $proc = qemu_proc('-foo', \%vars);
@gcmdl = $proc->gen_cmdline();
is_deeply(\@gcmdl, \@cmdl, 'Generate qemu command line for single existing UEFI disk using vars');
-@cmdl = ([qw(create -f qcow2 -F qcow2 -b), "$Bin/data/Core-7.2.iso", qw(raid/hd0-overlay0 11116544)]);
+@cmdl = ([qw(create -f qcow2 -F raw -b), "$Bin/data/Core-7.2.iso", qw(raid/hd0-overlay0 11116544)]);
@gcmdl = $proc->blockdev_conf->gen_qemu_img_cmdlines();
is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img command line for single existing UEFI disk');
@@ -380,13 +380,19 @@ subtest DriveDevice => sub {
};
subtest 'relative assets' => sub {
- $vars{$_} = "Core-7.2.iso" for qw(ISO ISO_1 HDD_1 UEFI_PFLASH_VARS);
+ $vars{$_} = "Core-7.2.iso" for qw(ISO ISO_1 UEFI_PFLASH_VARS);
+ $vars{$_} = "some.qcow2" for qw(HDD_1 UEFI_PFLASH_VARS);
symlink("$Bin/data/Core-7.2.iso", "./Core-7.2.iso");
+ path('./some.qcow2')->spurt('123');
$proc = qemu_proc('-foo', \%vars);
my @gcmdl = $proc->blockdev_conf->gen_qemu_img_cmdlines();
- @cmdl = map { [qw(create -f qcow2 -F), $_ eq 'hd0' ? 'qcow2' : 'raw', '-b', "$dir/Core-7.2.iso", "raid/$_-overlay0", 11116544] } qw(hd0 cd0 cd1);
- push @cmdl, [qw(create -f qcow2 -F raw -b), "$Bin/data/uefi-code.bin", "raid/pflash-code-overlay0", 1966080];
- push @cmdl, [qw(create -f qcow2 -F raw -b), "$dir/Core-7.2.iso", "raid/pflash-vars-overlay0", 11116544];
+ @cmdl = (
+ [qw(create -f qcow2 -F qcow2 -b), "$dir/some.qcow2", "raid/hd0-overlay0", 512],
+ [qw(create -f qcow2 -F raw -b), "$dir/Core-7.2.iso", "raid/cd0-overlay0", 11116544],
+ [qw(create -f qcow2 -F raw -b), "$dir/Core-7.2.iso", "raid/cd1-overlay0", 11116544],
+ [qw(create -f qcow2 -F raw -b), "$Bin/data/uefi-code.bin", "raid/pflash-code-overlay0", 1966080],
+ [qw(create -f qcow2 -F qcow2 -b), "$dir/some.qcow2", "raid/pflash-vars-overlay0", 512],
+ );
is_deeply(\@gcmdl, \@cmdl, 'find the asset real path') or diag explain \@gcmdl;
};