[pve-devel] [PATCH storage v5 08/12] Fix: add missing snippets subdir
Alwin Antreich
a.antreich at proxmox.com
Tue Apr 28 15:58:21 CEST 2020
since it is a valid content type and adapt the path_to_volume_id_test.
Also adds an extra check if all vtype_subdirs are returned.
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
PVE/Storage.pm | 4 ++++
test/path_to_volume_id_test.pm | 26 +++++++++++++++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 1ef5ed2..5df074d 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -512,6 +512,7 @@ sub path_to_volume_id {
my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
my $backupdir = $plugin->get_subdir($scfg, 'backup');
my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
+ my $snippetsdir = $plugin->get_subdir($scfg, 'snippets');
if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
my $vmid = $1;
@@ -537,6 +538,9 @@ sub path_to_volume_id {
} elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
my $name = $1;
return ('backup', "$sid:backup/$name");
+ } elsif ($path =~ m!^$snippetsdir/([^/]+)$!) {
+ my $name = $1;
+ return ('snippets', "$sid:snippets/$name");
}
}
diff --git a/test/path_to_volume_id_test.pm b/test/path_to_volume_id_test.pm
index 7d69869..e5e24c1 100644
--- a/test/path_to_volume_id_test.pm
+++ b/test/path_to_volume_id_test.pm
@@ -134,18 +134,24 @@ my @tests = (
'local:1234/subvol-1234-disk-0.subvol'
],
},
-
- # no matches
{
description => 'Snippets, yaml',
volname => "$storage_dir/snippets/userconfig.yaml",
- expected => [''],
+ expected => [
+ 'snippets',
+ 'local:snippets/userconfig.yaml',
+ ],
},
{
description => 'Snippets, hookscript',
volname => "$storage_dir/snippets/hookscript.pl",
- expected => [''],
+ expected => [
+ 'snippets',
+ 'local:snippets/hookscript.pl',
+ ],
},
+
+ # no matches
{
description => 'CT template, tar.xz',
volname => "$storage_dir/template/cache/debian-10.0-standard_10.0-1_amd64.tar.xz",
@@ -210,7 +216,10 @@ my @tests = (
},
);
-plan tests => scalar @tests;
+plan tests => scalar @tests + 1;
+
+my $seen_vtype;
+my $vtype_subdirs = { map { $_ => 1 } keys %{ PVE::Storage::Plugin::get_vtype_subdirs() } };
foreach my $tt (@tests) {
my $file = $tt->{volname};
@@ -232,8 +241,15 @@ foreach my $tt (@tests) {
$got = $@ if $@;
is_deeply($got, $expected, $description) || diag(explain($got));
+
+ $seen_vtype->{@$expected[0]} = 1
+ if ( @$expected[0] ne '' && scalar @$expected > 1);
}
+# to check if all $vtype_subdirs are defined in path_to_volume_id
+# or have a test
+is_deeply($seen_vtype, $vtype_subdirs, "vtype_subdir check");
+
#cleanup
# File::Temp unlinks tempdir on exit
--
2.20.1
More information about the pve-devel
mailing list