[pve-devel] [PATCH v3 pve-manager 23/23] replication_test5.pl: add test for job removal

Dietmar Maurer dietmar at proxmox.com
Tue May 30 15:20:20 CEST 2017


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 bin/test/replication_test5.log |  9 +++++++++
 bin/test/replication_test5.pl  | 23 ++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/bin/test/replication_test5.log b/bin/test/replication_test5.log
index 26d50404..a46665f2 100644
--- a/bin/test/replication_test5.log
+++ b/bin/test/replication_test5.log
@@ -48,3 +48,12 @@
 3640 job_900_to_node2: end replication job
 3640 job_900_to_node2: changed config next_sync => 4500
 3640 job_900_to_node2: changed state last_try => 3640, last_sync => 3640
+3700 job_900_to_node2: start replication job
+3700 job_900_to_node2: guest => 900, type => qemu, running => 0
+3700 job_900_to_node2: volumes => local-zfs:vm-900-disk-1,local-zfs:vm-900-disk-2
+3700 job_900_to_node2: start job removal - mode 'full'
+3700 job_900_to_node2: delete stale snapshot 'replicate_job_900_to_node2_3640_snap' on local-zfs:vm-900-disk-1
+3700 job_900_to_node2: delete stale snapshot 'replicate_job_900_to_node2_3640_snap' on local-zfs:vm-900-disk-2
+3700 job_900_to_node2: job removed
+3700 job_900_to_node2: end replication job
+3700 job_900_to_node2: vanished job
diff --git a/bin/test/replication_test5.pl b/bin/test/replication_test5.pl
index a084cd34..5e31b859 100755
--- a/bin/test/replication_test5.pl
+++ b/bin/test/replication_test5.pl
@@ -4,6 +4,7 @@
 # 1.) Start replication job with single disk
 # 2.) add non-existent disk (replication fails)
 # 3.) create disk (replication continues).
+# 4.) remove job
 
 use strict;
 use warnings;
@@ -31,7 +32,7 @@ use PVE::Storage;
 my $replicated_volume_status = {};
 
 my $mocked_remote_prepare_local_job = sub {
-    my ($ssh_info, $jobid, $vmid, $volumes, $last_sync) = @_;
+    my ($ssh_info, $jobid, $vmid, $volumes, $last_sync, $force) = @_;
 
     my $target = $ssh_info->{node};
 
@@ -42,6 +43,10 @@ my $mocked_remote_prepare_local_job = sub {
     my $last_sync_snapname = PVE::Replication::replication_snapshot_name($jobid, $last_sync);
 
     foreach my $volid (keys %{$replicated_volume_status->{$target}}) {
+	if (!grep { $_ eq $volid } @$volumes) {
+	    delete $replicated_volume_status->{$target}->{$volid};
+	    next;
+	}
 	my $snapname = $replicated_volume_status->{$target}->{$volid};
 
 	$last_snapshots->{$volid} = 1 if $last_sync_snapname eq $snapname;
@@ -64,8 +69,15 @@ my $mocked_replicate_volume = sub {
     $replicated_volume_status->{$target}->{$volid} = $sync_snapname;
 };
 
+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,
     remote_prepare_local_job => $mocked_remote_prepare_local_job,
     remote_finalize_local_job => $mocked_remote_finalize_local_job,
     replicate_volume => $mocked_replicate_volume);
@@ -123,6 +135,15 @@ for (my $i = 0; $i < 15; $i++) {
     $ctime += 60;
 }
 
+# mark job for removal
+$ReplicationTestEnv::mocked_replication_jobs->{job_900_to_node2}->{remove_job} = 'full';
+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