From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
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 243F56BAE7
for <pve-devel@lists.proxmox.com>; Thu, 18 Mar 2021 10:45:30 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id 02226EF01
for <pve-devel@lists.proxmox.com>; Thu, 18 Mar 2021 10:45:00 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
[212.186.127.180])
(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 294A3EEF0
for <pve-devel@lists.proxmox.com>; Thu, 18 Mar 2021 10:44:59 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E99B245936
for <pve-devel@lists.proxmox.com>; Thu, 18 Mar 2021 10:44:58 +0100 (CET)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Thomas Lamprecht <t.lamprecht@proxmox.com>
Date: Thu, 18 Mar 2021 10:44:52 +0100
Message-Id: <20210318094452.738-4-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210318094452.738-1-f.ebner@proxmox.com>
References: <20210318094452.738-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results: 0
AWL 0.003 Adjusted score from AWL reputation of From: address
KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/,
medium trust
SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record
SPF_PASS -0.001 SPF: sender matches SPF record
URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
information. [qemuserver.pm, proxmox.com]
Subject: [pve-devel] [PATCH v2 qemu-server 4/4] restore: sanitize config:
use new warning system
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 18 Mar 2021 09:45:30 -0000
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
Depends on pve-common having [0] or any other implementation of warn().
[0]: https://lists.proxmox.com/pipermail/pve-devel/2021-March/047303.html
PVE/QemuServer.pm | 8 +++++---
test/run_qemu_restore_config_tests.pl | 14 ++++++++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 69f7be2..11561be 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5905,6 +5905,8 @@ sub sanitize_restored_config {
return $new_config_raw if $authuser eq 'root@pam';
+ my $rpcenv = PVE::RPCEnvironment::get();
+
my $res = '';
$oldconf //= {};
@@ -5947,13 +5949,13 @@ sub sanitize_restored_config {
($key =~ m/^usb\d+$/ && $value !~ m/spice/) ||
$key =~ m/^parallel\d+$/ ||
$key =~ m/^hostpci\d+$/) {
- warn "WARN: skipping configuration line '$line' due to " .
- "privilege restrictions - restore as root to include it.\n";
+ $rpcenv->warn("skipping configuration line '$line' due to " .
+ "privilege restrictions - restore as root to include it.");
} else {
$res .= "$line\n";
}
} else {
- warn "WARN: invalid configuration line '$line'.\n";
+ $rpcenv->warn("invalid configuration line '$line'.");
}
}
diff --git a/test/run_qemu_restore_config_tests.pl b/test/run_qemu_restore_config_tests.pl
index 789711a..7e3a1cb 100755
--- a/test/run_qemu_restore_config_tests.pl
+++ b/test/run_qemu_restore_config_tests.pl
@@ -6,6 +6,7 @@ use warnings;
use lib qw(..);
use Test::More;
+use Test::MockModule;
use File::Basename;
@@ -21,6 +22,19 @@ my $NUMBER_OF_FILES = 7;
plan tests => 2 * $NUMBER_OF_FILES;
+my $rpc_environment_module = Test::MockModule->new('PVE::RPCEnvironment');
+$rpc_environment_module->mock(
+ get => sub {
+ my $self = {};
+ bless $self, 'PVE::RPCEnvironment';
+ return $self;
+ },
+ warn => sub {
+ my ($self, $message) = @_;
+ warn "$message\n";
+ },
+);
+
dir_glob_foreach('./restore-config-input', '[0-9]+.conf', sub {
my ($file) = @_;
--
2.20.1