]> git.proxmox.com Git - pve-storage.git/commitdiff
Fix: add missing snippets subdir
authorAlwin Antreich <a.antreich@proxmox.com>
Tue, 28 Apr 2020 13:58:21 +0000 (15:58 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 30 Apr 2020 16:37:19 +0000 (18:37 +0200)
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@proxmox.com>
PVE/Storage.pm
test/path_to_volume_id_test.pm

index 1ef5ed2c7f5d3ec709266567b1c9acb73d765d7e..5df074d2d5995bd1b6d34209713778c5a4bdf47b 100755 (executable)
@@ -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");
        }
     }
 
index 7d698691efaa3e033bd8f9d77eaf3422814d1e26..e5e24c121de63c8ec1f4ea6057f51b1ef681ce64 100644 (file)
@@ -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