From fa529caf4bd68aa140166dce6025cd80b5451986 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Sep 08 2021 19:39:16 +0000 Subject: Fix qemu-img invocation with qemu 6.1.0 Backports upstream PR #1764 and #1765 to explicitly specify the backing file format in qemu-img invocations (required from qemu 6.1.0 onwards). --- diff --git a/1764.patch b/1764.patch new file mode 100644 index 0000000..98c7682 --- /dev/null +++ b/1764.patch @@ -0,0 +1,85 @@ +From 9e0a29dacf60cb63edf20b6558207691abcf40e8 Mon Sep 17 00:00:00 2001 +From: Marius Kittler +Date: Wed, 8 Sep 2021 17:21:57 +0200 +Subject: [PATCH] Fix `qemu-img` failure with QEMU 6.1.0 due to missing file + format + +* Specify format of backing file on image creation with `qemu-img` +* See https://progress.opensuse.org/issues/98117 +--- + OpenQA/Qemu/BlockDev.pm | 10 ++++++---- + t/18-qemu.t | 16 ++++++++-------- + 2 files changed, 14 insertions(+), 12 deletions(-) + +diff --git a/OpenQA/Qemu/BlockDev.pm b/OpenQA/Qemu/BlockDev.pm +index 19f70a98bf..99a970ddb6 100644 +--- a/OpenQA/Qemu/BlockDev.pm ++++ b/OpenQA/Qemu/BlockDev.pm +@@ -158,13 +158,15 @@ creating. + + =cut + sub gen_qemu_img_cmdlines { +- my $self = shift; +- my @cmdlns = defined $self->backing_file ? $self->backing_file->gen_qemu_img_cmdlines : (); ++ my $self = shift; ++ ++ my $backing_file = $self->backing_file; ++ my @cmdlns = defined $backing_file ? $backing_file->gen_qemu_img_cmdlines : (); + return @cmdlns unless $self->needs_creating; + + my @params = ('create', '-f', $self->driver); +- push(@params, ('-b', $self->backing_file->file)) +- if defined $self->backing_file; ++ push(@params, '-F', $backing_file->driver, '-b', $backing_file->file) ++ if defined $backing_file; + push(@params, $self->file); + push(@params, $self->size); + +diff --git a/t/18-qemu.t b/t/18-qemu.t +index 147ed8a2e4..2d15dc1850 100755 +--- a/t/18-qemu.t ++++ b/t/18-qemu.t +@@ -84,7 +84,7 @@ $bdc->add_existing_drive('hd1', '/abs/path/sle15-minimal.qcow2', 'virtio-blk', 2 + @gcmdl = $bdc->gen_cmdline(); + is_deeply(\@gcmdl, \@cmdl, 'Generate qemu command line for single existing drive'); + +-@cmdl = ([qw(create -f qcow2 -b /abs/path/sle15-minimal.qcow2 raid/hd1-overlay0 22548578304)]); ++@cmdl = ([qw(create -f qcow2 -F qcow2 -b /abs/path/sle15-minimal.qcow2 raid/hd1-overlay0 22548578304)]); + @gcmdl = $bdc->gen_qemu_img_cmdlines(); + is_deeply(\@gcmdl, \@cmdl, 'Generate qemu-img command line for single existing drive'); + +@@ -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 -b), "$Bin/data/Core-7.2.iso", qw(raid/hd0-overlay0 11116544)]); ++@cmdl = ([qw(create -f qcow2 -F qcow2 -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'); + +@@ -229,8 +229,8 @@ $proc->deserialise_state(path($path)->slurp()); + is_deeply(\@gcmdl, \@cmdl, 'Command line after snapshot and serialisation') + || diag(explain(\@gcmdl)); + +-@cmdl = ([qw(create -f qcow2 -b raid/hd0 raid/hd0-overlay1 10G)], +- [qw(create -f qcow2 -b raid/cd0-overlay0 raid/cd0-overlay1 11116544)]); ++@cmdl = ([qw(create -f qcow2 -F qcow2 -b raid/hd0 raid/hd0-overlay1 10G)], ++ [qw(create -f qcow2 -F qcow2 -b raid/cd0-overlay0 raid/cd0-overlay1 11116544)]); + @gcmdl = $bdc->gen_qemu_img_cmdlines(); + is_deeply(\@gcmdl, \@cmdl, 'Generate reverted snapshot images'); + +@@ -384,10 +384,10 @@ subtest 'relative assets' => sub { + symlink("$Bin/data/Core-7.2.iso", "./Core-7.2.iso"); + $proc = qemu_proc('-foo', \%vars); + my @gcmdl = $proc->blockdev_conf->gen_qemu_img_cmdlines(); +- @cmdl = map { [qw(create -f qcow2 -b), "$dir/Core-7.2.iso", "raid/$_-overlay0", 11116544] } qw(hd0 cd0 cd1); +- push @cmdl, ["create", "-f", "qcow2", "-b", "$Bin/data/uefi-code.bin", "raid/pflash-code-overlay0", 1966080]; +- push @cmdl, ["create", "-f", "qcow2", "-b", "$dir/Core-7.2.iso", "raid/pflash-vars-overlay0", 11116544]; +- is_deeply(\@gcmdl, \@cmdl, 'find the asset real path'); ++ @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]; ++ is_deeply(\@gcmdl, \@cmdl, 'find the asset real path') or diag explain \@gcmdl; + }; + + subtest 'qemu was killed due to the system being out of memory' => sub { diff --git a/1765.patch b/1765.patch new file mode 100644 index 0000000..ab8cd30 --- /dev/null +++ b/1765.patch @@ -0,0 +1,102 @@ +From 489916d5a18113365a97eb3181cbb6c5e351c467 Mon Sep 17 00:00:00 2001 +From: Marius Kittler +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; + }; + diff --git a/os-autoinst.spec b/os-autoinst.spec index 41b9ed2..da96f75 100644 --- a/os-autoinst.spec +++ b/os-autoinst.spec @@ -43,11 +43,16 @@ Name: os-autoinst Version: %{github_version} -Release: 41%{?github_date:.%{github_date}git%{shortcommit}}%{?dist} +Release: 42%{?github_date:.%{github_date}git%{shortcommit}}%{?dist} Summary: OS-level test automation License: GPLv2+ URL: https://os-autoinst.github.io/openQA/ Source0: https://github.com/%{github_owner}/%{github_name}/archive/%{github_commit}/%{github_name}-%{github_commit}.tar.gz +# Fix qemu-img invocation with qemu 6.1.0 (next two patches) +# https://github.com/os-autoinst/os-autoinst/pull/1764 +Patch0: 1764.patch +# https://github.com/os-autoinst/os-autoinst/pull/1765 +Patch1: 1765.patch # on SUSE this is conditional, for us it doesn't have to be but we # still use a macro just to keep build_requires similar for ease of @@ -237,6 +242,9 @@ rm tools/lib/perlcritic/Perl/Critic/Policy/*.pm %files devel %changelog +* Fri Sep 03 2021 Adam Williamson - 4.6-42.20210803gitad28b4b +- Fix qemu-img invocation with qemu 6.1.0 (specify backing file format) + * Tue Aug 03 2021 Adam Williamson - 4.6-41.20210803gitad28b4b - Update to latest git