public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Thomas Lamprecht <t.lamprecht@proxmox.com>
Subject: [pve-devel] [PATCH v2 qemu-server 4/4] restore: sanitize config: use new warning system
Date: Thu, 18 Mar 2021 10:44:52 +0100	[thread overview]
Message-ID: <20210318094452.738-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210318094452.738-1-f.ebner@proxmox.com>

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





  parent reply	other threads:[~2021-03-18  9:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18  9:44 [pve-devel] [PATCH v2 qemu-server 1/4] test: add tests for restoring config Fabian Ebner
2021-03-18  9:44 ` [pve-devel] [PATCH v2 qemu-server 2/4] restore: update config: remove unused parameter Fabian Ebner
2021-04-18 16:15   ` [pve-devel] applied: " Thomas Lamprecht
2021-03-18  9:44 ` [pve-devel] [PATCH v2 qemu-server 3/4] restore: sanitize config for non-root users Fabian Ebner
2021-04-18 16:17   ` Thomas Lamprecht
2021-03-18  9:44 ` Fabian Ebner [this message]
2021-04-18 16:15 ` [pve-devel] applied: [PATCH v2 qemu-server 1/4] test: add tests for restoring config Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210318094452.738-4-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=t.lamprecht@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal