Suggested-by: Thomas Lamprecht <t.lampre...@proxmox.com> Signed-off-by: Fabian Ebner <f.eb...@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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel