[pve-devel] [PATCH storage 25/26] update tests

Wolfgang Bumiller
2025-07-29T11:18:22Z

src/test/list_volumes_test.pm | 73 ++++++++++++++++++++----------
src/test/parse_volname_test.pm | 34 ++++++++++++--
src/test/path_to_volume_id_test.pm | 27 +++++++----
src/test/run_test_lvmplugin.pl | 11 +++--
src/test/run_test_zfspoolplugin.pl | 45 ++++++++++--------
5 files changed, 129 insertions(+), 61 deletions(-)

diff --git a/src/test/list_volumes_test.pm b/src/test/list_volumes_test.pm
index e528fc3..fcc7beb 100644
--- a/src/test/list_volumes_test.pm
+++ b/src/test/list_volumes_test.pm
@@ -71,6 +71,8 @@ my $scfg = {
'rootdir' => 1,
'vztmpl' => 1,
'images' => 1,
+ 'vm-vol' => 1,
+ 'ct-vol' => 1,
'snippets' => 1,
'backup' => 1,
},
@@ -87,9 +89,9 @@ my @tests = (
description => 'VMID: 16110, VM, qcow2, backup, snippets',
vmid => '16110',
files => [
- "$storage_dir/images/16110/vm-16110-disk-0.qcow2",
- "$storage_dir/images/16110/vm-16110-disk-1.raw",
- "$storage_dir/images/16110/vm-16110-disk-2.vmdk",
+ "$storage_dir/vms/16110/vol-vm-16110-disk-0.qcow2",
+ "$storage_dir/vms/16110/vol-vm-16110-disk-1.raw",
+ "$storage_dir/vms/16110/vol-vm-16110-disk-2.vmdk",
"$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_11_40.vma.gz",
"$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_12_45.vma.lzo",
"$storage_dir/dump/vzdump-qemu-16110-2020_03_30-21_13_55.vma",
@@ -99,34 +101,37 @@ my @tests = (
],
expected => [
{
- 'content' => 'images',
+ 'content' => 'vm-vol',
+ 'vtype' => 'vm-vol',
'ctime' => DEFAULT_CTIME,
'format' => 'qcow2',
'parent' => undef,
'size' => DEFAULT_SIZE,
'used' => DEFAULT_USED,
'vmid' => '16110',
- 'volid' => 'local:16110/vm-16110-disk-0.qcow2',
+ 'volid' => 'local:16110/vol-vm-16110-disk-0.qcow2',
},
{
- 'content' => 'images',
+ 'content' => 'vm-vol',
+ 'vtype' => 'vm-vol',
'ctime' => DEFAULT_CTIME,
'format' => 'raw',
'parent' => undef,
'size' => DEFAULT_SIZE,
'used' => DEFAULT_USED,
'vmid' => '16110',
- 'volid' => 'local:16110/vm-16110-disk-1.raw',
+ 'volid' => 'local:16110/vol-vm-16110-disk-1.raw',
},
{
- 'content' => 'images',
+ 'content' => 'vm-vol',
+ 'vtype' => 'vm-vol',
'ctime' => DEFAULT_CTIME,
'format' => 'vmdk',
'parent' => undef,
'size' => DEFAULT_SIZE,
'used' => DEFAULT_USED,
'vmid' => '16110',
- 'volid' => 'local:16110/vm-16110-disk-2.vmdk',
+ 'volid' => 'local:16110/vol-vm-16110-disk-2.vmdk',
},
{
'content' => 'backup',
@@ -184,7 +189,8 @@ my @tests = (
description => 'VMID: 16112, lxc, raw, backup',
vmid => '16112',
files => [
- "$storage_dir/images/16112/vm-16112-disk-0.raw",
+ "$storage_dir/cts/16112/vol-ct-16112-disk-0.raw",
+ "$storage_dir/images/16112/vm-16112-disk-1.raw",
"$storage_dir/dump/vzdump-lxc-16112-2020_03_30-21_39_30.tar.lzo",
"$storage_dir/dump/vzdump-lxc-16112-2020_03_30-21_49_30.tar.gz",
"$storage_dir/dump/vzdump-lxc-16112-2020_03_30-21_49_30.tar.zst",
@@ -192,6 +198,17 @@ my @tests = (
"$storage_dir/dump/vzdump-openvz-16112-2020_03_30-21_39_30.tar.bz2",
],
expected => [
+ {
+ 'content' => 'ct-vol',
+ 'vtype' => 'ct-vol',
+ 'ctime' => DEFAULT_CTIME,
+ 'format' => 'raw',
+ 'parent' => undef,
+ 'size' => DEFAULT_SIZE,
+ 'used' => DEFAULT_USED,
+ 'vmid' => '16112',
+ 'volid' => 'local:16112/vol-ct-16112-disk-0.raw',
+ },
{
'content' => 'rootdir',
'ctime' => DEFAULT_CTIME,
@@ -200,7 +217,7 @@ my @tests = (
'size' => DEFAULT_SIZE,
'used' => DEFAULT_USED,
'vmid' => '16112',
- 'volid' => 'local:16112/vm-16112-disk-0.raw',
+ 'volid' => 'local:16112/vm-16112-disk-1.raw',
},
{
'content' => 'backup',
@@ -254,7 +271,7 @@ my @tests = (
vmid => '16114',
files => [
"$storage_dir/images/16114/vm-16114-disk-0.qcow2",
- "$storage_dir/images/16114/vm-16114-disk-1.qcow2",
+ "$storage_dir/vms/16114/vol-vm-16114-disk-1.qcow2",
],
parent => [
"../9004/base-9004-disk-0.qcow2", "../9004/base-9004-disk-1.qcow2",
@@ -271,14 +288,15 @@ my @tests = (
'volid' => 'local:9004/base-9004-disk-0.qcow2/16114/vm-16114-disk-0.qcow2',
},
{
- 'content' => 'images',
+ 'content' => 'vm-vol',
+ 'vtype' => 'vm-vol',
'ctime' => DEFAULT_CTIME,
'format' => 'qcow2',
'parent' => '../9004/base-9004-disk-1.qcow2',
'size' => DEFAULT_SIZE,
'used' => DEFAULT_USED,
'vmid' => '16114',
- 'volid' => 'local:9004/base-9004-disk-1.qcow2/16114/vm-16114-disk-1.qcow2',
+ 'volid' => 'local:9004/base-9004-disk-1.qcow2/16114/vol-vm-16114-disk-1.qcow2',
},
],
},
@@ -287,7 +305,7 @@ my @tests = (
vmid => '9004',
files => [
"$storage_dir/images/9004/base-9004-disk-0.qcow2",
- "$storage_dir/images/9004/base-9004-disk-1.qcow2",
+ "$storage_dir/vms/9004/base-vol-vm-9004-disk-1.qcow2",
],
expected => [
{
@@ -301,14 +319,15 @@ my @tests = (
'volid' => 'local:9004/base-9004-disk-0.qcow2',
},
{
- 'content' => 'images',
+ 'content' => 'vm-vol',
+ 'vtype' => 'vm-vol',
'ctime' => DEFAULT_CTIME,
'format' => 'qcow2',
'parent' => undef,
'size' => DEFAULT_SIZE,
'used' => DEFAULT_USED,
'vmid' => '9004',
- 'volid' => 'local:9004/base-9004-disk-1.qcow2',
+ 'volid' => 'local:9004/base-vol-vm-9004-disk-1.qcow2',
},
],
},
@@ -428,21 +447,22 @@ my @tests = (
#"$storage_dir/images/ssss/base-4321-disk-0.qcow2/1234/vm-1234-disk-0.qcow2",
vmid => undef,
files => [
- "$storage_dir/images/1234/vm-1234-disk-0.qcow2",
+ "$storage_dir/vms/1234/vol-vm-1234-disk-0.qcow2",
],
parent => [
- "../ssss/base-4321-disk-0.qcow2",
+ "../ssss/base-vol-vm-4321-disk-0.qcow2",
],
expected => [
{
- 'content' => 'images',
+ 'content' => 'vm-vol',
+ 'vtype' => 'vm-vol',
'ctime' => DEFAULT_CTIME,
'format' => 'qcow2',
- 'parent' => '../ssss/base-4321-disk-0.qcow2',
+ 'parent' => '../ssss/base-vol-vm-4321-disk-0.qcow2',
'size' => DEFAULT_SIZE,
'used' => DEFAULT_USED,
'vmid' => '1234',
- 'volid' => 'local:1234/vm-1234-disk-0.qcow2',
+ 'volid' => 'local:1234/vol-vm-1234-disk-0.qcow2',
},
],
},
@@ -521,7 +541,7 @@ plan tests => $plan + 1;

{
my $sid = 'local';
- my $types = ['rootdir', 'images', 'vztmpl', 'iso', 'backup', 'snippets'];
+ my $types = ['images', 'rootdir', 'vm-vol', 'ct-vol', 'vztmpl', 'iso', 'backup', 'snippets'];
my @suffixes = ('qcow2', 'raw', 'vmdk', 'vhdx');

# run through test cases
@@ -555,6 +575,13 @@ plan tests => $plan + 1;
eval { $got = PVE::Storage::Plugin->list_volumes($sid, $scfg, $vmid, $types) };
$got = $@ if $@;

+ sub sort_by_volid {
+ my ($data) = @_;
+ return [sort { $a->{volid} cmp $b->{volid} } @$data];
+ }
+
+ $got = sort_by_volid($got) if ref($got) && ref($got) eq 'ARRAY';
+ $expected = sort_by_volid($expected);
is_deeply($got, $expected, $description) || diag(explain($got));

# clean up after each test case, otherwise
diff --git a/src/test/parse_volname_test.pm b/src/test/parse_volname_test.pm
index 0d077a9..297e280 100644
--- a/src/test/parse_volname_test.pm
+++ b/src/test/parse_volname_test.pm
@@ -20,6 +20,19 @@ my $tests = [
#
{
description => 'VM disk image, linked, qcow2, vm- as base-',
+ volname => "$vmid/vol-vm-$vmid-disk-0.qcow2/$vmid/vol-vm-$vmid-disk-0.qcow2",
+ expected => [
+ 'vm-vol',
+ "vol-vm-$vmid-disk-0.qcow2",
+ "$vmid",
+ "vol-vm-$vmid-disk-0.qcow2",
+ "$vmid",
+ !!0,
+ 'qcow2',
+ ],
+ },
+ {
+ description => 'VM disk image, legacy, linked, qcow2, vm- as base-',
volname => "$vmid/vm-$vmid-disk-0.qcow2/$vmid/vm-$vmid-disk-0.qcow2",
expected => [
'images',
@@ -27,11 +40,21 @@ my $tests = [
"$vmid",
"vm-$vmid-disk-0.qcow2",
"$vmid",
- undef,
+ !!0,
'qcow2',
],
},
#
+ # Container volumes
+ #
+ {
+ description => 'CT rootdir image',
+ volname => "$vmid/vol-ct-$vmid-disk-0.raw",
+ expected => [
+ 'ct-vol', "vol-ct-$vmid-disk-0.raw", "$vmid", undef, undef, !!0, 'raw',
+ ],
+ },
+ #
# iso
#
{
@@ -94,7 +117,7 @@ my $tests = [
description => 'Container rootdir, subvol',
volname => "$vmid/subvol-$vmid-disk-0.subvol",
expected =>
- ['images', "subvol-$vmid-disk-0.subvol", "$vmid", undef, undef, undef, 'subvol'],
+ ['images', "subvol-$vmid-disk-0.subvol", "$vmid", undef, undef, !!0, 'subvol'],
},
{
description => 'Backup archive, no virtualization type',
@@ -209,7 +232,7 @@ foreach my $s (@$disk_suffix) {
description => "VM disk image, $s",
volname => "$vmid/vm-$vmid-disk-1.$s",
expected => [
- 'images', "vm-$vmid-disk-1.$s", "$vmid", undef, undef, undef, "$s",
+ 'images', "vm-$vmid-disk-1.$s", "$vmid", undef, undef, !!0, "$s",
],
},
{
@@ -221,7 +244,7 @@ foreach my $s (@$disk_suffix) {
"$vmid",
"base-$vmid-disk-0.$s",
"$vmid",
- undef,
+ !!0,
"$s",
],
},
@@ -229,7 +252,7 @@ foreach my $s (@$disk_suffix) {
description => "VM disk image, base, $s",
volname => "$vmid/base-$vmid-disk-0.$s",
expected => [
- 'images', "base-$vmid-disk-0.$s", "$vmid", undef, undef, 'base-', "$s",
+ 'images', "base-$vmid-disk-0.$s", "$vmid", undef, undef, !!1, "$s",
],
},
);
@@ -295,6 +318,7 @@ plan tests => scalar @$tests + 1;

my $seen_vtype;
my $vtype_subdirs = { map { $_ => 1 } keys %{ PVE::Storage::Plugin::get_vtype_subdirs() } };
+delete $vtype_subdirs->{rootdir}; # this one cannot be observed, it maps to the 'ct-vol' type.

foreach my $t (@$tests) {
my $description = $t->{description};
diff --git a/src/test/path_to_volume_id_test.pm b/src/test/path_to_volume_id_test.pm
index ab7e276..bb2d47f 100644
--- a/src/test/path_to_volume_id_test.pm
+++ b/src/test/path_to_volume_id_test.pm
@@ -25,8 +25,9 @@ my $scfg = {
'maxfiles' => 0,
'content' => {
'snippets' => 1,
- 'rootdir' => 1,
'images' => 1,
+ 'vm-vol' => 1,
+ 'ct-vol' => 1,
'iso' => 1,
'backup' => 1,
'vztmpl' => 1,
@@ -44,24 +45,31 @@ my $scfg = {
# expected => the result that path_to_volume_id should return
my @tests = (
{
- description => 'Image, qcow2',
+ description => 'Image, qcow2, legacy naming',
volname => "$storage_dir/images/16110/vm-16110-disk-0.qcow2",
expected => [
'images', 'local:16110/vm-16110-disk-0.qcow2',
],
},
+ {
+ description => 'Image, qcow2',
+ volname => "$storage_dir/vms/16110/vol-vm-16110-disk-0.qcow2",
+ expected => [
+ 'vm-vol', 'local:16110/vol-vm-16110-disk-0.qcow2',
+ ],
+ },
{
description => 'Image, raw',
- volname => "$storage_dir/images/16112/vm-16112-disk-0.raw",
+ volname => "$storage_dir/vms/16112/vol-vm-16112-disk-0.raw",
expected => [
- 'images', 'local:16112/vm-16112-disk-0.raw',
+ 'vm-vol', 'local:16112/vol-vm-16112-disk-0.raw',
],
},
{
description => 'Image template, qcow2',
- volname => "$storage_dir/images/9004/base-9004-disk-0.qcow2",
+ volname => "$storage_dir/vms/9004/base-vol-vm-9004-disk-0.qcow2",
expected => [
- 'images', 'local:9004/base-9004-disk-0.qcow2',
+ 'vm-vol', 'local:9004/base-vol-vm-9004-disk-0.qcow2',
],
},

@@ -141,14 +149,14 @@ my @tests = (
description => 'Rootdir, folder subvol, legacy naming',
volname => "$storage_dir/images/1234/subvol-1234-disk-0.subvol/", # fileparse needs / at the end
expected => [
- 'ct-vol', 'local:1234/subvol-1234-disk-0.subvol',
+ 'images', 'local:1234/subvol-1234-disk-0.subvol',
],
},
{
description => 'Rootdir, folder subvol',
- volname => "$storage_dir/images/1234/subvol-1234-disk-0.subvol/", # fileparse needs / at the end
+ volname => "$storage_dir/cts/1234/vol-ct-1234-disk-0.subvol/", # fileparse needs / at the end
expected => [
- 'images', 'local:1234/subvol-1234-disk-0.subvol',
+ 'ct-vol', 'local:1234/vol-ct-1234-disk-0.subvol',
],
},
{
@@ -239,6 +247,7 @@ plan tests => scalar @tests + 1;

my $seen_vtype;
my $vtype_subdirs = { map { $_ => 1 } keys %{ PVE::Storage::Plugin::get_vtype_subdirs() } };
+delete $vtype_subdirs->{rootdir}; # this one cannot be observed, it maps to the 'ct-vol' type.

foreach my $tt (@tests) {
my $file = $tt->{volname};
diff --git a/src/test/run_test_lvmplugin.pl b/src/test/run_test_lvmplugin.pl
index e87a3de..92e8d6e 100755
--- a/src/test/run_test_lvmplugin.pl
+++ b/src/test/run_test_lvmplugin.pl
@@ -159,7 +159,7 @@ my $test7 = sub {

eval {
my $tmp_volid =
- PVE::Storage::vdisk_alloc($cfg, $storagename, "112", "raw", undef, 1024 * 1024);
+ PVE::Storage::vdisk_alloc($cfg, $storagename, "112", "raw", undef, 1024 * 1024, undef);

if ($tmp_volid ne "$storagename:vm-112-disk-0") {
die "volname:$tmp_volid don't match\n";
@@ -186,15 +186,16 @@ my $test7 = sub {
}

eval {
- my $tmp_volid =
- PVE::Storage::vdisk_alloc($cfg, $storagename, "112", "raw", undef, 2048 * 1024);
+ my $tmp_volid = PVE::Storage::vdisk_alloc(
+ $cfg, $storagename, "112", "raw", undef, 2048 * 1024, 'vm-vol',
+ );

- if ($tmp_volid ne "$storagename:vm-112-disk-1") {
+ if ($tmp_volid ne "$storagename:vol-vm-112-disk-1") {
die "volname:$tmp_volid don't match\n";
}
eval {
run_command(
- "lvs --noheadings -o lv_size $vgname/vm-112-disk-1",
+ "lvs --noheadings -o lv_size $vgname/vol-vm-112-disk-1",
outfunc => sub {
my $tmp = shift;
if ($tmp !~ m/2\.00g/) {
diff --git a/src/test/run_test_zfspoolplugin.pl b/src/test/run_test_zfspoolplugin.pl
index 9bd70a8..99ab6e2 100755
--- a/src/test/run_test_zfspoolplugin.pl
+++ b/src/test/run_test_zfspoolplugin.pl
@@ -580,7 +580,7 @@ my $test13 = sub {

eval {
my $tmp_volid =
- PVE::Storage::vdisk_alloc($cfg, $storagename, "112", "raw", undef, 1024 * 1024);
+ PVE::Storage::vdisk_alloc($cfg, $storagename, "112", "raw", undef, 1024 * 1024, undef);

if ($tmp_volid ne "$storagename:vm-112-disk-0") {
die "volname:$tmp_volid don't match\n";
@@ -607,18 +607,19 @@ my $test13 = sub {
}

eval {
- my $tmp_volid =
- PVE::Storage::vdisk_alloc($cfg, $storagename, "112", "raw", undef, 2048 * 1024);
+ my $tmp_volid = PVE::Storage::vdisk_alloc(
+ $cfg, $storagename, "112", "raw", undef, 2048 * 1024, 'vm-vol',
+ );

- if ($tmp_volid ne "$storagename:vm-112-disk-1") {
+ if ($tmp_volid ne "$storagename:vol-vm-112-disk-1") {
die "volname:$tmp_volid don't match\n";
}
eval {
run_command(
- "zfs get -H volsize $zpath\/vm-112-disk-1",
+ "zfs get -H volsize $zpath\/vol-vm-112-disk-1",
outfunc => sub {
my $tmp = shift;
- if ($tmp !~ m/^$zpath\/vm-112-disk-1.*volsize.*2G.*$/) {
+ if ($tmp !~ m/^$zpath\/vol-vm-112-disk-1.*volsize.*2G.*$/) {
die "size don't match\n";
}
},
@@ -635,8 +636,9 @@ my $test13 = sub {
}

eval {
- my $tmp_volid =
- PVE::Storage::vdisk_alloc($cfg, $storagename, "113", "subvol", undef, 1024 * 1024);
+ my $tmp_volid = PVE::Storage::vdisk_alloc(
+ $cfg, $storagename, "113", "subvol", undef, 1024 * 1024, undef,
+ );

if ($tmp_volid ne "$storagename:subvol-113-disk-0") {
die "volname:$tmp_volid don't match\n";
@@ -663,18 +665,19 @@ my $test13 = sub {
}

eval {
- my $tmp_volid =
- PVE::Storage::vdisk_alloc($cfg, $storagename, "113", "subvol", undef, 2048 * 1024);
+ my $tmp_volid = PVE::Storage::vdisk_alloc(
+ $cfg, $storagename, "113", "subvol", undef, 2048 * 1024, 'ct-vol',
+ );

- if ($tmp_volid ne "$storagename:subvol-113-disk-1") {
+ if ($tmp_volid ne "$storagename:subvol-ct-113-disk-1") {
die "volname:$tmp_volid don't match\n";
}
eval {
run_command(
- "zfs get -H refquota $zpath\/subvol-113-disk-1",
+ "zfs get -H refquota $zpath\/subvol-ct-113-disk-1",
outfunc => sub {
my $tmp = shift;
- if ($tmp !~ m/^$zpath\/subvol-113-disk-1.*refquota.*G.*$/) {
+ if ($tmp !~ m/^$zpath\/subvol-ct-113-disk-1.*refquota.*G.*$/) {
die "size don't match\n";
}
},
@@ -778,7 +781,7 @@ my $test11 = sub {

print "\nrun test11 \"volume_is_base\"\n";

- eval { PVE::Storage::vdisk_clone($cfg, "$storagename:$vmdisk", 110); };
+ eval { PVE::Storage::vdisk_clone($cfg, "$storagename:$vmdisk", 110, undef, undef); };
if (!$@) {
$count++;
warn "Test11 a: clone_image only works on base images";
@@ -786,7 +789,7 @@ my $test11 = sub {

eval {
if ("$storagename:$vmbase\/vm-110-disk-0" ne
- PVE::Storage::vdisk_clone($cfg, "$storagename:$vmbase", 110, '__base__')
+ PVE::Storage::vdisk_clone($cfg, "$storagename:$vmbase", 110, '__base__', undef)
) {
$count++;
warn "Test11 b";
@@ -806,13 +809,15 @@ my $test11 = sub {
warn "Test11 b: $@";
}

- eval { PVE::Storage::vdisk_clone($cfg, "$storagename:$vmbase\/$vmlinked", 111); };
+ eval {
+ PVE::Storage::vdisk_clone($cfg, "$storagename:$vmbase\/$vmlinked", 111, undef, undef);
+ };
if (!$@) {
$count++;
warn "Test11 c: clone_image only works on base images";
}

- eval { PVE::Storage::vdisk_clone($cfg, "$storagename:$ctdisk", 110); };
+ eval { PVE::Storage::vdisk_clone($cfg, "$storagename:$ctdisk", 110, undef, undef); };
if (!$@) {
$count++;
warn "Test11 d: clone_image only works on base images";
@@ -820,7 +825,7 @@ my $test11 = sub {

eval {
if ("$storagename:$ctbase\/subvol-210-disk-0" ne
- PVE::Storage::vdisk_clone($cfg, "$storagename:$ctbase", 210, '__base__')
+ PVE::Storage::vdisk_clone($cfg, "$storagename:$ctbase", 210, '__base__', undef)
) {
$count++;
warn "Test11 e";
@@ -840,7 +845,9 @@ my $test11 = sub {
warn "Test11 e: $@";
}

- eval { PVE::Storage::vdisk_clone($cfg, "$storagename:$ctbase\/$ctlinked", 211); };
+ eval {
+ PVE::Storage::vdisk_clone($cfg, "$storagename:$ctbase\/$ctlinked", 211, undef, undef);
+ };
if (!$@) {
$count++;
warn "Test11 f: clone_image only works on base images";