[pve-devel] [PATCH storage v3 2/7] test: parse_volname

Alwin Antreich a.antreich at proxmox.com
Wed Apr 8 12:25:57 CEST 2020


Test to reduce the potential for accidental breakage on regex changes.

Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 test/run_parser_tests.pl   |  2 +-
 test/test_parse_volname.pm | 95 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 test/test_parse_volname.pm

diff --git a/test/run_parser_tests.pl b/test/run_parser_tests.pl
index 042112c..79093aa 100755
--- a/test/run_parser_tests.pl
+++ b/test/run_parser_tests.pl
@@ -6,7 +6,7 @@ use warnings;
 use TAP::Harness;
 
 my $harness = TAP::Harness->new( { verbosity => -1 });
-my $res = $harness->runtests("test_archive_info.pm");
+my $res = $harness->runtests("test_archive_info.pm", "test_parse_volname.pm");
 
 exit -1 if !$res || $res->{failed} || $res->{parse_errors};
 
diff --git a/test/test_parse_volname.pm b/test/test_parse_volname.pm
new file mode 100644
index 0000000..84665d3
--- /dev/null
+++ b/test/test_parse_volname.pm
@@ -0,0 +1,95 @@
+package PVE::Storage::TestParseVolname;
+
+use strict;
+use warnings;
+
+use lib qw(..);
+
+use PVE::Storage;
+use Test::More;
+
+my @tests = (
+    # VM images
+    [ '4321/base-4321-disk-0.raw/1234/vm-1234-disk-0.raw',     ['images', 'vm-1234-disk-0.raw',   '1234', 'base-4321-disk-0.raw',   '4321', undef, 'raw'],    'VM disk image, linked, raw' ],
+    [ '4321/base-4321-disk-0.qcow2/1234/vm-1234-disk-0.qcow2', ['images', 'vm-1234-disk-0.qcow2', '1234', 'base-4321-disk-0.qcow2', '4321', undef, 'qcow2'],  'VM disk image, linked, qcow2' ],
+    [ '4321/base-4321-disk-0.vmdk/1234/vm-1234-disk-0.vmdk',   ['images', 'vm-1234-disk-0.vmdk',  '1234', 'base-4321-disk-0.vmdk',  '4321', undef, 'vmdk'],   'VM disk image, linked, vmdk' ],
+
+    [ '4321/vm-4321-disk-0.qcow2/1234/vm-1234-disk-0.qcow2',    ['images', 'vm-1234-disk-0.qcow2', '1234', 'vm-4321-disk-0.qcow2', '4321', undef, 'qcow2'], 'VM disk image, linked, qcow2, vm- as base-' ],
+
+    [ '1234/vm-1234-disk-1.raw',   ['images', 'vm-1234-disk-1.raw',   '1234', undef, undef, undef, 'raw'],   'VM disk image, raw' ],
+    [ '1234/vm-1234-disk-1.qcow2', ['images', 'vm-1234-disk-1.qcow2', '1234', undef, undef, undef, 'qcow2'], 'VM disk image, qcow2' ],
+    [ '1234/vm-1234-disk-1.vmdk',  ['images', 'vm-1234-disk-1.vmdk',  '1234', undef, undef, undef, 'vmdk'],  'VM disk image, vmdk' ],
+
+    [ '4321/base-4321-disk-0.raw',   ['images', 'base-4321-disk-0.raw',   '4321', undef, undef, 'base-', 'raw'],   'VM disk image, base, raw' ],
+    [ '4321/base-4321-disk-0.qcow2', ['images', 'base-4321-disk-0.qcow2', '4321', undef, undef, 'base-', 'qcow2'], 'VM disk image, base, qcow2' ],
+    [ '4321/base-4321-disk-0.vmdk',  ['images', 'base-4321-disk-0.vmdk',  '4321', undef, undef, 'base-', 'vmdk'],  'VM disk image, base, vmdk' ],
+
+    # iso
+    [ 'iso/some-installation-disk.iso', ['iso', 'some-installation-disk.iso'], 'ISO image, iso' ],
+    [ 'iso/some-other-installation-disk.img', ['iso', 'some-other-installation-disk.img'], 'ISO image, img' ],
+
+    # container templates
+    [ 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz', ['vztmpl', 'debian-10.0-standard_10.0-1_amd64.tar.gz'], 'Container template tar.gz' ],
+    [ 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.xz', ['vztmpl', 'debian-10.0-standard_10.0-1_amd64.tar.xz'], 'Container template tar.xz' ],
+
+    # container rootdir
+    [ 'rootdir/1234',                   ['rootdir', '1234',                      '1234'],                                 'Container rootdir, sub directory' ],
+    [ '1234/subvol-1234-disk-0.subvol', ['images',  'subvol-1234-disk-0.subvol', '1234', undef, undef, undef, 'subvol'],  'Container rootdir, subvol' ],
+
+    # backup archives
+    [ 'backup/vzdump-qemu-16110-2020_03_30-21_12_40.vma',     ['backup', 'vzdump-qemu-16110-2020_03_30-21_12_40.vma',     '16110'], 'Backup archive, vma' ],
+    [ 'backup/vzdump-qemu-16110-2020_03_30-21_12_40.vma.gz',  ['backup', 'vzdump-qemu-16110-2020_03_30-21_12_40.vma.gz',  '16110'], 'Backup archive, vma, gz' ],
+    [ 'backup/vzdump-qemu-16110-2020_03_30-21_12_40.vma.lzo', ['backup', 'vzdump-qemu-16110-2020_03_30-21_12_40.vma.lzo', '16110'], 'Backup archive, vma, lzo' ],
+
+    [ 'backup/vzdump-lxc-16112-2020_03_30-21_39_30.tar',     ['backup', 'vzdump-lxc-16112-2020_03_30-21_39_30.tar',     '16112'], 'Backup archive, lxc' ],
+    [ 'backup/vzdump-lxc-16112-2020_03_30-21_39_30.tar.gz',  ['backup', 'vzdump-lxc-16112-2020_03_30-21_39_30.tar.gz',  '16112'], 'Backup archive, lxc, gz' ],
+    [ 'backup/vzdump-lxc-16112-2020_03_30-21_39_30.tgz',     ['backup', 'vzdump-lxc-16112-2020_03_30-21_39_30.tgz',     '16112'], 'Backup archive, lxc, tgz' ],
+    [ 'backup/vzdump-lxc-16112-2020_03_30-21_39_30.tar.lzo', ['backup', 'vzdump-lxc-16112-2020_03_30-21_39_30.tar.lzo', '16112'], 'Backup archive, lxc, lzo' ],
+
+    [ 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.tar',     ['backup', 'vzdump-openvz-16112-2020_03_30-21_39_30.tar',     '16112'], 'Backup archive, openvz' ],
+    [ 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.tar.gz',  ['backup', 'vzdump-openvz-16112-2020_03_30-21_39_30.tar.gz',  '16112'], 'Backup archive, openvz, gz' ],
+    [ 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.tgz',     ['backup', 'vzdump-openvz-16112-2020_03_30-21_39_30.tgz',     '16112'], 'Backup archive, openvz, tgz' ],
+    [ 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.tar.lzo', ['backup', 'vzdump-openvz-16112-2020_03_30-21_39_30.tar.lzo', '16112'], 'Backup archive, openvz, lzo' ],
+
+    [ 'backup/vzdump-none-16112-2020_03_30-21_39_30.tar',       ['backup', 'vzdump-none-16112-2020_03_30-21_39_30.tar'],       'Backup archive, no virtualization type' ],
+
+    # Snippets
+    [ 'snippets/userconfig.yaml', ['snippets', 'userconfig.yaml'], 'Snippets, yaml' ],
+    [ 'snippets/hookscript.pl',   ['snippets', 'hookscript.pl'],   'Snippets, perl' ],
+
+    # failed matches
+    [ 'ssss/base-4321-disk-0.raw',                              "unable to parse directory volume name 'ssss/base-4321-disk-0.raw'\n",                              'Failed match: VM disk image, base, raw' ],
+
+    [ 'iso/yet-again-a-installation-disk.dvd',                  "unable to parse directory volume name 'iso/yet-again-a-installation-disk.dvd'\n",                  'Failed match: ISO image, dvd' ],
+
+    [ 'vztmpl/debian-10.0-standard_10.0-1_amd64.zip.gz',        "unable to parse directory volume name 'vztmpl/debian-10.0-standard_10.0-1_amd64.zip.gz'\n",        'Failed match: Container template, zip.gz' ],
+    [ 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.bz2',       "unable to parse directory volume name 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.bz2'\n",       'Failed match: Container template, tar.bz2' ],
+
+    [ 'rootdir/subvol-19254-disk-0',                            "unable to parse directory volume name 'rootdir/subvol-19254-disk-0'\n",                            'Failed match: Container rootdir, subvol' ],
+
+    [ 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.tar.bz2', "unable to parse directory volume name 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.tar.bz2'\n", 'Failed match: Backup archive, openvz, bz2' ],
+    [ 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.zip.gz',  "unable to parse directory volume name 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.zip.gz'\n",  'Failed match: Backup archive, openvz, zip.gz' ],
+    [ 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.tgz.lzo', "unable to parse directory volume name 'backup/vzdump-openvz-16112-2020_03_30-21_39_30.tgz.lzo'\n", 'Failed match: Backup archive, openvz, tgz.lzo' ],
+    [ 'backup/vzdump-qemu-16110-2020_03_30-21_12_40.vma.xz',    "unable to parse directory volume name 'backup/vzdump-qemu-16110-2020_03_30-21_12_40.vma.xz'\n",    'Failed match: Backup archive, vma, xz' ],
+    [ 'backup/vzdump-qemu-16110-2020_03_30-21_12_40.vms.gz',    "unable to parse directory volume name 'backup/vzdump-qemu-16110-2020_03_30-21_12_40.vms.gz'\n",    'Failed match: Backup archive, vms, gz' ],
+
+    [ '4321/base-4321-disk-0.vhdx/1234/vm-1234-disk-0.vhdx',    "unable to parse volume filename 'base-4321-disk-0.vhdx'\n",                                        'Failed match: VM disk image, linked, vhdx' ],
+    [ 'ssss/base-4321-disk-0.qcow2/1234/vm-1234-disk-0.qcow2',  "unable to parse directory volume name 'ssss/base-4321-disk-0.qcow2/1234/vm-1234-disk-0.qcow2'\n",  'Failed match: VM disk image, linked, qcow2, first vmid' ],
+    [ '4321/base-4321-disk-0.qcow2/ssss/vm-1234-disk-0.qcow2',  "unable to parse volume filename 'base-4321-disk-0.qcow2/ssss/vm-1234-disk-0.qcow2'\n",             'Failed match: VM disk image, linked, qcow2, second vmid' ],
+
+);
+
+plan tests => scalar @tests;
+
+foreach my $t (@tests) {
+    my ($volname, $expected, $description) = @$t;
+    my $got;
+    eval { $got = [ PVE::Storage::Plugin->parse_volname($volname) ] };
+    $got = $@ if $@;
+
+    is_deeply($got, $expected, $description);
+}
+
+done_testing();
+
+1;
-- 
2.20.1





More information about the pve-devel mailing list