]> git.proxmox.com Git - pve-storage.git/blobdiff - test/archive_info_test.pm
Added a LOG_EXT constant as a counterpart to NOTES_EXT
[pve-storage.git] / test / archive_info_test.pm
index c0343aff4a4d9d38cfcbe29aec7dbdd0f1d2ed72..cf03c3d855aa07f20998253511edd2e2e6f9c783 100644 (file)
@@ -10,6 +10,9 @@ use Test::More;
 
 my $vmid = 16110;
 
+my $LOG_EXT = PVE::Storage::Plugin::LOG_EXT;
+my $NOTES_EXT = PVE::Storage::Plugin::NOTES_EXT;
+
 # an array of test cases, each test is comprised of the following keys:
 # description => to identify a single test
 # archive     => the input filename for archive_info
@@ -18,34 +21,96 @@ my $vmid = 16110;
 # most of them are created further below
 my $tests = [
     # backup archives
+    {
+       description => 'Backup archive, lxc, tgz, future millenium',
+       archive     => "backup/vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz",
+       expected    => {
+           'filename'     => "vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz",
+           'logfilename'  => "vzdump-lxc-$vmid-3070_01_01-00_00_00".$LOG_EXT,
+           'notesfilename'=> "vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz".$NOTES_EXT,
+           'type'         => 'lxc',
+           'format'       => 'tar',
+           'decompressor' => ['tar', '-z'],
+           'compression'  => 'gz',
+           'vmid'         => $vmid,
+           'ctime'        => 60*60*24 * (365*1100 + 267),
+           'is_std_name'  => 1,
+       },
+    },
+    {
+       description => 'Backup archive, lxc, tgz, very old',
+       archive     => "backup/vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz",
+       expected    => {
+           'filename'     => "vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz",
+           'logfilename'  => "vzdump-lxc-$vmid-1970_01_01-02_00_30".$LOG_EXT,
+           'notesfilename'=> "vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz".$NOTES_EXT,
+           'type'         => 'lxc',
+           'format'       => 'tar',
+           'decompressor' => ['tar', '-z'],
+           'compression'  => 'gz',
+           'vmid'         => $vmid,
+           'ctime'        => 60*60*2 + 30,
+           'is_std_name'  => 1,
+       },
+    },
     {
        description => 'Backup archive, lxc, tgz',
        archive     => "backup/vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
        expected    => {
+           'filename'     => "vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
+           'logfilename'  => "vzdump-lxc-$vmid-2020_03_30-21_39_30".$LOG_EXT,
+           'notesfilename'=> "vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz".$NOTES_EXT,
            'type'         => 'lxc',
            'format'       => 'tar',
            'decompressor' => ['tar', '-z'],
            'compression'  => 'gz',
+           'vmid'         => $vmid,
+           'ctime'        => 1585604370,
+           'is_std_name'  => 1,
        },
     },
     {
        description => 'Backup archive, openvz, tgz',
        archive     => "backup/vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
        expected    => {
+           'filename'     => "vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
+           'logfilename'  => "vzdump-openvz-$vmid-2020_03_30-21_39_30".$LOG_EXT,
+           'notesfilename'=> "vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz".$NOTES_EXT,
            'type'         => 'openvz',
            'format'       => 'tar',
            'decompressor' => ['tar', '-z'],
            'compression'  => 'gz',
+           'vmid'         => $vmid,
+           'ctime'        => 1585604370,
+           'is_std_name'  => 1,
+       },
+    },
+    {
+       description => 'Backup archive, custom dump directory, qemu, tgz',
+       archive     => "/here/be/Back-ups/vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
+       expected    => {
+           'filename'     => "vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
+           'logfilename'  => "vzdump-qemu-$vmid-2020_03_30-21_39_30".$LOG_EXT,
+           'notesfilename'=> "vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz".$NOTES_EXT,
+           'type'         => 'qemu',
+           'format'       => 'tar',
+           'decompressor' => ['tar', '-z'],
+           'compression'  => 'gz',
+           'vmid'         => $vmid,
+           'ctime'        => 1585604370,
+           'is_std_name'  => 1,
        },
     },
     {
        description => 'Backup archive, none, tgz',
-       archive     => "backup/whatever-the-name_is_here.tgz",
+       archive     => "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
        expected    => {
-           'type'         => 'unknown',
+           'filename'     => "vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
+           'type'         => 'qemu',
            'format'       => 'tar',
            'decompressor' => ['tar', '-z'],
            'compression'  => 'gz',
+           'is_std_name'  => 0,
        },
     },
 ];
@@ -73,16 +138,23 @@ my $bkp_suffix = {
 # create more test cases for backup files matches
 for my $virt (sort keys %$bkp_suffix) {
     my ($format, $decomp) = $bkp_suffix->{$virt}->@*;
+    my $archive_name = "vzdump-$virt-$vmid-2020_03_30-21_12_40";
 
     for my $suffix (sort keys %$decomp) {
        push @$tests, {
            description => "Backup archive, $virt, $format.$suffix",
-           archive     => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
+           archive     => "backup/$archive_name.$format.$suffix",
            expected    => {
+               'filename'     => "$archive_name.$format.$suffix",
+               'logfilename'  => $archive_name.$LOG_EXT,
+               'notesfilename'=> "$archive_name.$format.$suffix".$NOTES_EXT,
                'type'         => "$virt",
                'format'       => "$format",
                'decompressor' => $decomp->{$suffix},
                'compression'  => "$suffix",
+               'vmid'         => $vmid,
+               'ctime'        => 1585602760,
+               'is_std_name'  => 1,
            },
        };
     }
@@ -94,16 +166,18 @@ my $non_bkp_suffix = {
     'openvz' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
     'lxc'    => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
     'qemu'   => [ 'vma.xz', 'vms.gz', 'vmx.zst', '', ],
+    'none'   => [ 'tar.gz', ],
 };
 
 # create tests for failed matches
 for my $virt (sort keys %$non_bkp_suffix) {
     my $suffix = $non_bkp_suffix->{$virt};
     for my $s (@$suffix) {
+       my $archive = "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s";
        push @$tests, {
            description => "Failed match: Backup archive, $virt, $s",
-           archive     => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s",
-           expected    => "ERROR: couldn't determine format and compression type\n",
+           archive     => $archive,
+           expected    => "ERROR: couldn't determine archive info from '$archive'\n",
        };
     }
 }