[pve-devel] [PATCH v3 manager 2/2] vzdump: test: add first tests to the guest include logic

Aaron Lauterer a.lauterer at proxmox.com
Mon Jun 8 15:00:35 CEST 2020


Signed-off-by: Aaron Lauterer <a.lauterer at proxmox.com>
---

v2 -> v3:
* define pool in separate hash instead of in the return value
* changed the adding and processing of tests as suggested by Thomas [0]

v1 -> v2: adapt handling of return values, closer to what is used in
production code.


[0] https://pve.proxmox.com/pipermail/pve-devel/2020-June/043854.html

 test/Makefile                      |   5 +-
 test/vzdump_guest_included_test.pl | 200 +++++++++++++++++++++++++++++
 2 files changed, 204 insertions(+), 1 deletion(-)
 create mode 100755 test/vzdump_guest_included_test.pl

diff --git a/test/Makefile b/test/Makefile
index c26e16b1..44f3b0d7 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -5,7 +5,7 @@ all:
 export PERLLIB=..
 
 .PHONY: check
-check: replication_test balloon_test mail_test
+check: replication_test balloon_test mail_test vzdump_test
 
 balloon_test:
 	./balloontest.pl
@@ -21,6 +21,9 @@ replication_test:
 mail_test:
 	./mail_test.pl
 
+vzdump_test:
+	./vzdump_guest_included_test.pl
+
 .PHONY: install
 install:
 
diff --git a/test/vzdump_guest_included_test.pl b/test/vzdump_guest_included_test.pl
new file mode 100755
index 00000000..33748513
--- /dev/null
+++ b/test/vzdump_guest_included_test.pl
@@ -0,0 +1,200 @@
+#!/usr/bin/perl
+
+# Some of the tests can only be applied once the whole include logic is moved
+# into one single method. Right now parts of it, (all, exclude)  are in the
+# PVE::VZDump->exec_backup() method.
+
+use strict;
+use warnings;
+
+use lib '..';
+
+use Test::More tests => 7;
+use Test::MockModule;
+
+use PVE::VZDump;
+
+use Data::Dumper;
+
+my $vmlist = {
+    'ids' => {
+	100 => {
+	    'type' => 'qemu',
+	    'node' => 'node1',
+	},
+	101 => {
+	    'type' => 'qemu',
+	    'node' => 'node1',
+	},
+	112 => {
+	    'type' => 'lxc',
+	    'node' => 'node1',
+	},
+	113 => {
+	    'type' => 'lxc',
+	    'node' => 'node1',
+	},
+	200 => {
+	    'type' => 'qemu',
+	    'node' => 'node2',
+	},
+	201 => {
+	    'type' => 'qemu',
+	    'node' => 'node2',
+	},
+	212 => {
+	    'type' => 'lxc',
+	    'node' => 'node2',
+	},
+	213 => {
+	    'type' => 'lxc',
+	    'node' => 'node2',
+	},
+    }
+};
+
+my $pools = {
+    testpool => [100, 101, 200, 201],
+};
+
+my $pve_cluster_module = Test::MockModule->new('PVE::Cluster');
+$pve_cluster_module->mock(
+    get_vmlist => sub {
+	return $vmlist;
+    }
+);
+
+my $pve_inotify = Test::MockModule->new('PVE::INotify');
+$pve_inotify->mock(
+    nodename => sub {
+	return 'node1';
+    }
+);
+
+my $pve_api2tools = Test::MockModule->new('PVE::API2Tools');
+$pve_api2tools->mock(
+    get_resource_pool_guest_members => sub {
+	return $pools->{testpool};
+    }
+);
+
+my $tests = [];
+my $addtest = sub {
+    my ($name, $test) = @_;
+    push @$tests, {
+        name => $name,
+        test => $test,
+    };
+};
+
+# is handled in the PVE::VZDump->exec_backup() method for now
+# $addtest->('Test all guests', {
+#     expected_vmids => [ 100, 101, 112, 113, 200, 201, 212, 213 ],
+#     expected_skiplist => [ ],
+#     param => {
+# 	all => 1,
+#     }
+# });
+
+# is handled in the PVE::VZDump->exec_backup() method for now
+# $addtest->('Test all guests with cluster node limit', {
+#     expected_vmids => [ 100, 101, 112, 113, 200, 201, 212, 213 ],
+#     expected_skiplist => [],
+#     param => {
+# 	all => 1,
+# 	node => 'node2',
+#     }
+# });
+
+# is handled in the PVE::VZDump->exec_backup() method for now
+# $addtest->('Test all guests with local node limit', {
+#     expected_vmids => [ 100, 101, 112, 113 ],
+#     expected_skiplist => [ 200, 201, 212, 213 ],
+#     param => {
+# 	all => 1,
+# 	node => 'node1',
+#     }
+# });
+#
+# TODO: all test variants with exclude
+
+$addtest->('Test pool members', {
+    expected_vmids => [ 100, 101 ],
+    expected_skiplist => [ 200, 201 ],
+    param => {
+	pool => 'testpool',
+    }
+});
+
+$addtest->('Test pool members with cluster node limit', {
+    expected_vmids => [ 100, 101, 200, 201 ],
+    expected_skiplist => [],
+    param => {
+	pool => 'testpool',
+	node => 'node2',
+    }
+});
+
+$addtest->('Test pool members with local node limit', {
+    expected_vmids => [ 100, 101 ],
+    expected_skiplist => [ 200, 201 ],
+    param => {
+	pool => 'testpool',
+	node => 'node1',
+    }
+});
+
+$addtest->('Test selected VMIDs', {
+    expected_vmids => [ 100 ],
+    expected_skiplist => [ 201, 212 ],
+    param => {
+	vmid => '100, 201, 212',
+    }
+});
+
+
+$addtest->('Test selected VMIDs with cluster node limit', {
+    expected_vmids => [ 100, 201, 212 ],
+    expected_skiplist => [],
+    param => {
+	vmid => '100, 201, 212',
+	node => 'node2',
+    }
+});
+
+$addtest->('Test selected VMIDs with local node limit', {
+    expected_vmids => [ 100 ],
+    expected_skiplist => [ 201, 212 ],
+    param => {
+	vmid => '100, 201, 212',
+	node => 'node1',
+    }
+});
+
+$addtest->('Test selected VMIDs on other nodes', {
+    expected_vmids => [],
+    expected_skiplist => [ 201, 212 ],
+    param => {
+	vmid => '201, 212',
+	node => 'node1',
+    }
+});
+
+
+for my $test (@{$tests}) {
+    my $testname = $test->{name};
+    my $testdata = $test->{test};
+
+    note($testname);
+    my $expected = [ $testdata->{expected_vmids}, $testdata->{expected_skiplist} ];
+
+    my ($local, $cluster)  = PVE::VZDump::get_included_guests($testdata->{param});
+    my $result = [ $local, $cluster ];
+
+    # print "Expected: " . Dumper($expected);
+    # print "Returned: " . Dumper($result);
+
+    is_deeply($result, $expected, $testname);
+}
+
+exit(0);
-- 
2.20.1





More information about the pve-devel mailing list