[pve-devel] [PATCH pve-manager] replication - allow removal of jobs with target on local node

Dietmar Maurer dietmar at proxmox.com
Wed May 31 14:35:30 CEST 2017


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/Replication.pm             | 10 ++++---
 bin/test/replication_test6.log |  8 ++++++
 bin/test/replication_test6.pl  | 65 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 4 deletions(-)
 create mode 100644 bin/test/replication_test6.log
 create mode 100755 bin/test/replication_test6.pl

diff --git a/PVE/Replication.pm b/PVE/Replication.pm
index 01111787..742febec 100644
--- a/PVE/Replication.pm
+++ b/PVE/Replication.pm
@@ -92,10 +92,12 @@ sub job_status {
 	# only consider guest on local node
 	next if $vms->{ids}->{$vmid}->{node} ne $local_node;
 
-	# never sync to local node
-	next if $jobcfg->{target} eq $local_node;
+	if (!$jobcfg->{remove_job}) {
+	    # never sync to local node
+	    next if $jobcfg->{target} eq $local_node;
 
-	next if $jobcfg->{disable};
+	    next if $jobcfg->{disable};
+	}
 
 	my $state = $get_job_state->($stateobj, $jobcfg);
 	$jobcfg->{state} = $state;
@@ -310,7 +312,7 @@ sub replicate {
 
 	$logfunc->($start_time, "$jobid: start job removal - mode '${remove_job}'");
 
-	if ($remove_job eq 'full') {
+	if ($remove_job eq 'full' && $jobcfg->{target} ne $local_node) {
 	    # remove all remote volumes
 	    remote_prepare_local_job($ssh_info, $jobid, $vmid, [], 0, 1);
 
diff --git a/bin/test/replication_test6.log b/bin/test/replication_test6.log
new file mode 100644
index 00000000..a58ad26d
--- /dev/null
+++ b/bin/test/replication_test6.log
@@ -0,0 +1,8 @@
+1000 job_900_to_node1: new job next_sync => 1
+1000 job_900_to_node1: start replication job
+1000 job_900_to_node1: guest => 900, type => qemu, running => 0
+1000 job_900_to_node1: volumes => local-zfs:vm-900-disk-1
+1000 job_900_to_node1: start job removal - mode 'full'
+1000 job_900_to_node1: job removed
+1000 job_900_to_node1: end replication job
+1000 job_900_to_node1: vanished job
diff --git a/bin/test/replication_test6.pl b/bin/test/replication_test6.pl
new file mode 100755
index 00000000..91c4809e
--- /dev/null
+++ b/bin/test/replication_test6.pl
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+# Note: Try to delete replication job with target on same node
+
+use strict;
+use warnings;
+use JSON;
+
+use lib ('.', '../..');
+
+use Data::Dumper;
+
+use Test::MockModule;
+use ReplicationTestEnv;
+
+$ReplicationTestEnv::mocked_nodename = 'node1';
+
+my $mocked_delete_job = sub {
+    my ($jobid) = @_;
+
+    delete $ReplicationTestEnv::mocked_replication_jobs->{$jobid};
+};
+
+my $pve_replication_module = Test::MockModule->new('PVE::Replication');
+$pve_replication_module->mock(
+    delete_job => $mocked_delete_job);
+
+my $testjob = {
+    'type'  => 'local',
+    'target' => 'node1',
+    'guest' => 900,
+};
+
+$ReplicationTestEnv::mocked_replication_jobs = {
+    job_900_to_node1 => {
+	remove_job => 'full',
+	type  => 'local',
+	target => 'node1', # local node, job should be skipped
+	guest => 900,
+    },
+};
+
+$ReplicationTestEnv::mocked_vm_configs = {
+    900 => {
+	node => 'node1',
+	snapshots => {},
+	ide0 => 'local-zfs:vm-900-disk-1,size=4G',
+	memory => 512,
+	ide2 => 'none,media=cdrom',
+    },
+};
+
+ReplicationTestEnv::setup();
+
+ReplicationTestEnv::openlog();
+
+my $ctime = 1000;
+for (my $i = 0; $i < 15; $i++) {
+    ReplicationTestEnv::track_jobs($ctime);
+    $ctime += 60;
+}
+
+ReplicationTestEnv::commit_log();
+
+exit(0);
-- 
2.11.0




More information about the pve-devel mailing list