]> git.proxmox.com Git - qemu-server.git/commitdiff
cfg2cmd: allow to test for expected error messages
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 10 Dec 2019 10:07:00 +0000 (11:07 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 10 Dec 2019 10:08:33 +0000 (11:08 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
test/cfg2cmd/minimal-defaults-to-new-machine.conf [new file with mode: 0644]
test/run_config2command_tests.pl

diff --git a/test/cfg2cmd/minimal-defaults-to-new-machine.conf b/test/cfg2cmd/minimal-defaults-to-new-machine.conf
new file mode 100644 (file)
index 0000000..5c0486b
--- /dev/null
@@ -0,0 +1,5 @@
+# TEST: newer machine verison than QEMU version installed on node
+# QEMU_VERSION: 4.1.1
+# EXPECT_ERROR: Installed QEMU version '4.1.1' is too old to run machine type 'pc-q35-42.9', please upgrade node 'localhost'
+smbios1: uuid=6cf17dc3-8341-4ecc-aebd-7503f2583fb3
+machine: pc-q35-42.9
index c75be5385b0da5b0efe5628e40207ee4dd4d30cd..bad6501a143e427920ffe939bdfb5228ed014f25 100755 (executable)
@@ -117,6 +117,8 @@ sub parse_test($) {
            $current_test->{qemu_version} = "$1";
        } elsif ($line =~ /^HOST_ARCH:\s*(.*)\s*$/) {
            $current_test->{host_arch} = "$1";
+       } elsif ($line =~ /^EXPECT_ERROR:\s*(.*)\s*$/) {
+           $current_test->{expect_error} = "$1";
        }
     }
 }
@@ -280,7 +282,28 @@ sub do_test($) {
 
     my ($vmid, $storecfg) = $base_env->@{qw(vmid storage_config)};
 
-    my $cmdline = PVE::QemuServer::vm_commandline($storecfg, $vmid);
+    my $cmdline = eval { PVE::QemuServer::vm_commandline($storecfg, $vmid) };
+    my $err = $@;
+
+    if (my $err_expect = $current_test->{expect_error}) {
+       if (!$err) {
+           fail("$testname");
+           note("did NOT get any error, but expected error: $err_expect");
+           return;
+       }
+       chomp $err;
+       if ($err !~ /^\s*$err_expect\s*$/) {
+           fail("$testname");
+           note("error does not match expected error: '$err' !~ '$err_expect'");
+       } else {
+           pass("$testname");
+       }
+       return;
+    } elsif ($err) {
+       fail("$testname");
+       note("got unexpected error: $err");
+       return;
+    }
 
     # check if QEMU version set correctly and test version_cmp
     (my $qemu_major = get_test_qemu_version()) =~ s/\..*$//;