From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id C3E056155B
 for <pve-devel@lists.proxmox.com>; Thu, 17 Dec 2020 10:37:07 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id BC308240D3
 for <pve-devel@lists.proxmox.com>; Thu, 17 Dec 2020 10:37:07 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 59664240C9
 for <pve-devel@lists.proxmox.com>; Thu, 17 Dec 2020 10:37:06 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 20AD445252
 for <pve-devel@lists.proxmox.com>; Thu, 17 Dec 2020 10:37:06 +0100 (CET)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 17 Dec 2020 10:37:02 +0100
Message-Id: <20201217093702.15182-1-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.008 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH v2 qemu-server] tests: allow running migration
 tests in parallel
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 17 Dec 2020 09:37:07 -0000

It's not easily possible to use separate JSON files for the test configuration,
because part of it is generated with perl code. While this could be encoded too,
it seems cleaner to use the "run a single test by specifing the name"
functionality while adding a way for make to obtain a list of the test names.

Each test has (and needs) its own directory now, meaning the log files do not
need to be renamed anymore.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v1:
    * add definedness check before comparing $single_test_name

 test/Makefile                  |  9 +++--
 test/run_qemu_migrate_tests.pl | 62 ++++++++++++++++++++--------------
 2 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/test/Makefile b/test/Makefile
index a356057..29b9db6 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,3 +1,6 @@
+MIGRATION_TEST_NAMES := $(shell ./run_qemu_migrate_tests.pl DUMP_NAMES)
+MIGRATION_TEST_TARGETS := $(addprefix test_migration_,$(MIGRATION_TEST_NAMES))
+
 all: test
 
 test: test_snapshot test_ovf test_cfg_to_cmd test_pci_addr_conflicts test_qemu_img_convert test_migration
@@ -18,5 +21,7 @@ test_qemu_img_convert: run_qemu_img_convert_tests.pl
 test_pci_addr_conflicts: run_pci_addr_checks.pl
 	./run_pci_addr_checks.pl
 
-test_migration: run_qemu_migrate_tests.pl MigrationTest/*.pm
-	./run_qemu_migrate_tests.pl
+test_migration: run_qemu_migrate_tests.pl MigrationTest/*.pm $(MIGRATION_TEST_TARGETS)
+
+$(MIGRATION_TEST_TARGETS):
+	./run_qemu_migrate_tests.pl $(@:test_migration_%=%)
diff --git a/test/run_qemu_migrate_tests.pl b/test/run_qemu_migrate_tests.pl
index 1e3f135..67b9d0e 100755
--- a/test/run_qemu_migrate_tests.pl
+++ b/test/run_qemu_migrate_tests.pl
@@ -417,7 +417,8 @@ sub local_volids_for_vm {
 
 my $tests = [
 # each test consists of the following:
-# name           - unique name for the test
+# name           - unique name for the test which also serves as a dir name and
+#                  gets passed to make, so don't use whitespace or slash
 # target         - hostname of target node
 # vmid           - ID of the VM to migrate
 # opts           - options for the migrate() call
@@ -1492,17 +1493,30 @@ my $tests = [
     },
 ];
 
-mkdir $RUN_DIR_PATH;
+my $single_test_name = shift;
 
-file_set_contents("${RUN_DIR_PATH}/replication_config", to_json($replication_config));
-file_set_contents("${RUN_DIR_PATH}/storage_config", to_json($storage_config));
-file_set_contents("${RUN_DIR_PATH}/source_vdisks", to_json($source_vdisks));
+if (defined($single_test_name) && $single_test_name eq 'DUMP_NAMES') {
+    my $output = '';
+    foreach my $test (@{$tests}) {
+	$output .= $test->{name} . ' ';
+    }
+    print "$output\n";
+    exit 0;
+}
 
-my $single_test_name = shift;
+mkdir $RUN_DIR_PATH;
 
 foreach my $test (@{$tests}) {
     my $name = $test->{name};
     next if defined($single_test_name) && $name ne $single_test_name;
+
+    my $run_dir = "${RUN_DIR_PATH}/${name}";
+
+    mkdir $run_dir;
+    file_set_contents("${run_dir}/replication_config", to_json($replication_config));
+    file_set_contents("${run_dir}/storage_config", to_json($storage_config));
+    file_set_contents("${run_dir}/source_vdisks", to_json($source_vdisks));
+
     my $expect_die = $test->{expect_die};
     my $expected = $test->{expected};
 
@@ -1525,18 +1539,18 @@ foreach my $test (@{$tests}) {
 	opts => $test->{opts},
     };
 
-    file_set_contents("${RUN_DIR_PATH}/nbd_info", to_json({}));
-    file_set_contents("${RUN_DIR_PATH}/source_volids", to_json($source_volids));
-    file_set_contents("${RUN_DIR_PATH}/target_volids", to_json($target_volids));
-    file_set_contents("${RUN_DIR_PATH}/vm_config", to_json($vm_config));
-    file_set_contents("${RUN_DIR_PATH}/vm_status", to_json($test->{vm_status}));
-    file_set_contents("${RUN_DIR_PATH}/expected_calls", to_json($test->{expected_calls}));
-    file_set_contents("${RUN_DIR_PATH}/fail_config", to_json($fail_config));
-    file_set_contents("${RUN_DIR_PATH}/storage_migrate_map", to_json($storage_migrate_map));
-    file_set_contents("${RUN_DIR_PATH}/migrate_params", to_json($migrate_params));
+    file_set_contents("${run_dir}/nbd_info", to_json({}));
+    file_set_contents("${run_dir}/source_volids", to_json($source_volids));
+    file_set_contents("${run_dir}/target_volids", to_json($target_volids));
+    file_set_contents("${run_dir}/vm_config", to_json($vm_config));
+    file_set_contents("${run_dir}/vm_status", to_json($test->{vm_status}));
+    file_set_contents("${run_dir}/expected_calls", to_json($test->{expected_calls}));
+    file_set_contents("${run_dir}/fail_config", to_json($fail_config));
+    file_set_contents("${run_dir}/storage_migrate_map", to_json($storage_migrate_map));
+    file_set_contents("${run_dir}/migrate_params", to_json($migrate_params));
 
     $ENV{QM_LIB_PATH} = $QM_LIB_PATH;
-    $ENV{RUN_DIR_PATH} = $RUN_DIR_PATH;
+    $ENV{RUN_DIR_PATH} = $run_dir;
     my $exitcode = run_command([
 	'/usr/bin/perl',
 	"-I${MIGRATE_LIB_PATH}",
@@ -1545,7 +1559,7 @@ foreach my $test (@{$tests}) {
     ], noerr => 1, errfunc => sub {print "#$name - $_[0]\n"} );
 
     if (defined($expect_die) && $exitcode) {
-	my $log = file_get_contents("${RUN_DIR_PATH}/log");
+	my $log = file_get_contents("${run_dir}/log");
 	my @lines = split /\n/, $log;
 
 	my $matched = 0;
@@ -1565,14 +1579,14 @@ foreach my $test (@{$tests}) {
 	note("mocked migrate call failed, but it was not expected - check log");
     }
 
-    my $expected_calls = decode_json(file_get_contents("${RUN_DIR_PATH}/expected_calls"));
+    my $expected_calls = decode_json(file_get_contents("${run_dir}/expected_calls"));
     foreach my $call (keys %{$expected_calls}) {
 	fail($name);
 	note("expected call '$call' was not made");
     }
 
     if (!defined($expect_die)) {
-	my $nbd_info = decode_json(file_get_contents("${RUN_DIR_PATH}/nbd_info"));
+	my $nbd_info = decode_json(file_get_contents("${run_dir}/nbd_info"));
 	foreach my $drive (keys %{$nbd_info}) {
 	    fail($name);
 	    note("drive '$drive' was not mirrored");
@@ -1580,15 +1594,13 @@ foreach my $test (@{$tests}) {
     }
 
     my $actual = {
-	source_volids => decode_json(file_get_contents("${RUN_DIR_PATH}/source_volids")),
-	target_volids => decode_json(file_get_contents("${RUN_DIR_PATH}/target_volids")),
-	vm_config => decode_json(file_get_contents("${RUN_DIR_PATH}/vm_config")),
-	vm_status => decode_json(file_get_contents("${RUN_DIR_PATH}/vm_status")),
+	source_volids => decode_json(file_get_contents("${run_dir}/source_volids")),
+	target_volids => decode_json(file_get_contents("${run_dir}/target_volids")),
+	vm_config => decode_json(file_get_contents("${run_dir}/vm_config")),
+	vm_status => decode_json(file_get_contents("${run_dir}/vm_status")),
     };
 
     is_deeply($actual, $expected, $name);
-
-    rename("${RUN_DIR_PATH}/log", "${RUN_DIR_PATH}/log-$name") or die "rename log failed\n";
 }
 
 done_testing();
-- 
2.20.1