[pve-devel] [PATCH manager 2/4] vzdump: refactor parsing mailto and exclude-path

Fabian Ebner f.ebner at proxmox.com
Fri Feb 12 13:23:21 CET 2021


so it can be mocked.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/API2/VZDump.pm | 11 +----------
 PVE/VZDump.pm      | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm
index 806ac7fd..44376106 100644
--- a/PVE/API2/VZDump.pm
+++ b/PVE/API2/VZDump.pm
@@ -88,16 +88,7 @@ __PACKAGE__->register_method ({
 	# silent exit if specified VMs run on other nodes
 	return "OK" if !scalar(@{$local_vmids}) && !$param->{all};
 
-	# exclude-path list need to be 0 separated
-	if (defined($param->{'exclude-path'})) {
-	    my @expaths = split(/\0/, $param->{'exclude-path'} || '');
-	    $param->{'exclude-path'} = [ @expaths ];
-	}
-
-	if (defined($param->{mailto})) {
-	    my @mailto = PVE::Tools::split_list(extract_param($param, 'mailto'));
-	    $param->{mailto} = [ @mailto ];
-	}
+	PVE::VZDump::parse_mailto_exclude_path($param);
 
 	die "you can only backup a single VM with option --stdout\n"
 	    if $param->{stdout} && scalar(@{$local_vmids}) != 1;
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index a99d0565..2ddfa851 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -1177,6 +1177,27 @@ sub option_exists {
     return defined($confdesc->{$key});
 }
 
+# NOTE it might make sense to merge this and verify_vzdump_parameters(), but one
+# needs to adapt command_line() in guest-common's PVE/VZDump/Common.pm and detect
+# a second parsing attempt, because verify_vzdump_parameters() is called twice
+# during the update_job API call.
+sub parse_mailto_exclude_path {
+    my ($param) = @_;
+
+    # exclude-path list need to be 0 separated
+    if (defined($param->{'exclude-path'})) {
+	my @expaths = split(/\0/, $param->{'exclude-path'} || '');
+	$param->{'exclude-path'} = [ @expaths ];
+    }
+
+    if (defined($param->{mailto})) {
+	my @mailto = PVE::Tools::split_list(extract_param($param, 'mailto'));
+	$param->{mailto} = [ @mailto ];
+    }
+
+    return;
+}
+
 sub verify_vzdump_parameters {
     my ($param, $check_missing) = @_;
 
-- 
2.20.1






More information about the pve-devel mailing list