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
Subject: [pve-devel] [PATCH v2 manager 4/8] backup: include IDs for non-existent guests
Date: Thu, 22 Oct 2020 12:30:13 +0200	[thread overview]
Message-ID: <20201022103017.19715-5-f.ebner@proxmox.com> (raw)
In-Reply-To: <20201022103017.19715-1-f.ebner@proxmox.com>

Like this, there will be a backup task (within the big worker task)
for such IDs, which will then visibly (i.e. also visible in the
notification mail) fail with, e.g.:
unable to find VM '123'

In get_included_guests, the key '' was chosen for the orphaned IDs,
because it cannot possibly denote a nodename.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/API2/VZDump.pm                 |  4 ++++
 PVE/VZDump.pm                      | 19 +++++++++++++------
 test/vzdump_guest_included_test.pl | 13 ++++++++++++-
 3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm
index 19fa1e3b..806ac7fd 100644
--- a/PVE/API2/VZDump.pm
+++ b/PVE/API2/VZDump.pm
@@ -74,6 +74,10 @@ __PACKAGE__->register_method ({
 
 	my $local_vmids = delete $vmids_per_node->{$nodename} // [];
 
+	# include IDs for deleted guests, and visibly fail later
+	my $orphaned_vmids = delete $vmids_per_node->{''} // [];
+	push @{$local_vmids}, @{$orphaned_vmids};
+
 	my $skiplist = [ map { @$_ } values $vmids_per_node->%* ];
 
 	if($param->{stop}){
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index e6082f3b..7ff32ce2 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -1073,9 +1073,12 @@ sub exec_backup {
 
     my $vmlist = PVE::Cluster::get_vmlist();
     foreach my $vmid (@{$opts->{vmids}}) {
-	my $guest_type = $vmlist->{ids}->{$vmid}->{type};
-	my $plugin = $vzdump_plugins->{$guest_type};
-	next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Backup' ], $opts->{all});
+	my $plugin;
+	if (defined($vmlist->{ids}->{$vmid})) {
+	    my $guest_type = $vmlist->{ids}->{$vmid}->{type};
+	    $plugin = $vzdump_plugins->{$guest_type};
+	    next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Backup' ], $opts->{all});
+	}
 	push @$tasklist, {
 	    mode => $opts->{mode},
 	    plugin => $plugin,
@@ -1217,10 +1220,14 @@ sub get_included_guests {
     $vmids = check_vmids(@$vmids);
 
     for my $vmid (@$vmids) {
-	my $node = $vmlist->{ids}->{$vmid}->{node};
-	next if (defined $job->{node} && $job->{node} ne $node);
+	if (defined($vmlist->{ids}->{$vmid})) {
+	    my $node = $vmlist->{ids}->{$vmid}->{node};
+	    next if (defined $job->{node} && $job->{node} ne $node);
 
-	push @{$vmids_per_node->{$node}}, $vmid;
+	    push @{$vmids_per_node->{$node}}, $vmid;
+	} else {
+	    push @{$vmids_per_node->{''}}, $vmid;
+	}
     }
 
     return $vmids_per_node;
diff --git a/test/vzdump_guest_included_test.pl b/test/vzdump_guest_included_test.pl
index eb663ad3..157644de 100755
--- a/test/vzdump_guest_included_test.pl
+++ b/test/vzdump_guest_included_test.pl
@@ -5,7 +5,7 @@ use warnings;
 
 use lib '..';
 
-use Test::More tests => 9;
+use Test::More tests => 10;
 use Test::MockModule;
 
 use PVE::VZDump;
@@ -174,6 +174,17 @@ $addtest->('Test selected VMIDs on other nodes', {
     }
 });
 
+$addtest->('Test VMID not present in vmlist', {
+    expected => {
+	node1 => [ 100 ],
+	node2 => [ 201, 212 ],
+	'' => [ 7654 ],
+   },
+    param => {
+	vmid => '100, 201, 212, 7654',
+    }
+});
+
 
 for my $test (@{$tests}) {
     my $testname = $test->{name};
-- 
2.20.1





  parent reply	other threads:[~2020-10-22 10:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22 10:30 [pve-devel] [PATCH-SERIES v2 manager] Make backup with IDs for non-existent guests visibly fail Fabian Ebner
2020-10-22 10:30 ` [pve-devel] [PATCH v2 manager 1/8] remove unused variable Fabian Ebner
2020-10-22 10:30 ` [pve-devel] [PATCH v2 manager 2/8] remove outdated comment Fabian Ebner
2020-10-22 10:30 ` [pve-devel] [PATCH v2 manager 3/8] only use plugin after truthiness check Fabian Ebner
2020-10-22 10:30 ` Fabian Ebner [this message]
2020-10-22 10:30 ` [pve-devel] [PATCH v2 manager 5/8] order guest IDs numerically in exec_backup Fabian Ebner
2020-10-22 10:30 ` [pve-devel] [PATCH v2 manager 6/8] sort the skip list numerically Fabian Ebner
2020-10-22 10:30 ` [pve-devel] [PATCH v2 manager 7/8] simplify get_included_vmids function Fabian Ebner
2020-10-22 10:30 ` [pve-devel] [RFC/PATCH v2 manager 8/8] don't group by node in get_included_guests Fabian Ebner
2020-10-22 16:52 ` [pve-devel] applied-partially: [PATCH-SERIES v2 manager] Make backup with IDs for non-existent guests visibly fail 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=20201022103017.19715-5-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.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