From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B890E7078A for ; Tue, 14 Jun 2022 11:00:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B55B81C91E for ; Tue, 14 Jun 2022 11:00:51 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 618E01C912 for ; Tue, 14 Jun 2022 11:00:50 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 39A4743B1D for ; Tue, 14 Jun 2022 11:00:50 +0200 (CEST) From: Daniel Tschlatscher To: pve-devel@lists.proxmox.com Date: Tue, 14 Jun 2022 11:00:13 +0200 Message-Id: <20220614090013.84500-4-d.tschlatscher@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220614090013.84500-1-d.tschlatscher@proxmox.com> References: <20220614090013.84500-1-d.tschlatscher@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.113 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [plugin.pm, storage.pm] Subject: [pve-devel] [PATCH storage v4 4/4] Added a LOG_EXT constant as a counterpart to NOTES_EXT X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jun 2022 09:00:51 -0000 and refactored usages for .log and .notes with them. At some parts in the test case code I had to source new variables to shorten the line length to not exceed the 100 column line limit. Signed-off-by: Daniel Tschlatscher Reviewed-by: Fabian Ebner --- Changes from v3 * File extension constants are now ordered alphabetically PVE/Storage.pm | 4 ++-- PVE/Storage/Plugin.pm | 1 + test/archive_info_test.pm | 32 ++++++++++++++++++-------------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 0d53ba2..b9c53a1 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -1566,8 +1566,8 @@ sub archive_info { $info->{type} = $type; if ($volid =~ /^(vzdump-${type}-([1-9][0-9]{2,8})-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2}))\.${extension}$/) { - $info->{logfilename} = "$1.log"; - $info->{notesfilename} = "$filename.notes"; + $info->{logfilename} = "$1".PVE::Storage::Plugin::LOG_EXT; + $info->{notesfilename} = "$filename".PVE::Storage::Plugin::NOTES_EXT; $info->{vmid} = int($2); $info->{ctime} = timelocal($8, $7, $6, $5, $4 - 1, $3); $info->{is_std_name} = 1; diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index 0a100b7..8a41df1 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -20,6 +20,7 @@ use base qw(PVE::SectionConfig); use constant COMPRESSOR_RE => 'gz|lzo|zst'; +use constant LOG_EXT => ".log"; use constant NOTES_EXT => ".notes"; our @COMMON_TAR_FLAGS = qw( diff --git a/test/archive_info_test.pm b/test/archive_info_test.pm index bbc0e6f..cf03c3d 100644 --- a/test/archive_info_test.pm +++ b/test/archive_info_test.pm @@ -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 @@ -23,8 +26,8 @@ my $tests = [ 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", - 'notesfilename'=> "vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz.notes", + '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'], @@ -39,8 +42,8 @@ my $tests = [ 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", - 'notesfilename'=> "vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz.notes", + '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'], @@ -55,8 +58,8 @@ my $tests = [ 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", - 'notesfilename'=> "vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz.notes", + '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'], @@ -71,8 +74,8 @@ my $tests = [ 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", - 'notesfilename'=> "vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz.notes", + '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'], @@ -87,8 +90,8 @@ my $tests = [ 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", - 'notesfilename'=> "vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz.notes", + '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'], @@ -135,15 +138,16 @@ 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' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix", - 'logfilename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.log", - 'notesfilename'=> "vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix.notes", + 'filename' => "$archive_name.$format.$suffix", + 'logfilename' => $archive_name.$LOG_EXT, + 'notesfilename'=> "$archive_name.$format.$suffix".$NOTES_EXT, 'type' => "$virt", 'format' => "$format", 'decompressor' => $decomp->{$suffix}, -- 2.30.2