[pve-devel] [PATCH manager 2/3] test: replication: mock volume_snapshot_info

Fabian Ebner f.ebner at proxmox.com
Tue Oct 19 09:54:58 CEST 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 test/ReplicationTestEnv.pm | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/test/ReplicationTestEnv.pm b/test/ReplicationTestEnv.pm
index dea1921b..35653e75 100755
--- a/test/ReplicationTestEnv.pm
+++ b/test/ReplicationTestEnv.pm
@@ -154,6 +154,17 @@ my $pve_storage_module = Test::MockModule->new('PVE::Storage');
 
 my $mocked_storage_content = {};
 
+my $timestamp_counter = 0;
+
+sub generate_snapshot_info {
+    $timestamp_counter++;
+
+    return {
+	id => $timestamp_counter,
+	timestamp => $timestamp_counter,
+    };
+}
+
 sub register_mocked_volid {
     my ($volid, $snapname) = @_;
 
@@ -163,7 +174,7 @@ sub register_mocked_volid {
 
     my $d = $mocked_storage_content->{$storeid}->{$volname} //= {};
 
-    $d->{$snapname} = 1 if $snapname;
+    $d->{$snapname} = generate_snapshot_info() if $snapname;
 }
 
 my $mocked_volume_snapshot_list = sub {
@@ -186,7 +197,7 @@ my $mocked_volume_snapshot = sub {
 
     my $d = $mocked_storage_content->{$storeid}->{$volname};
     die "no such volid '$volid'\n" if !$d;
-    $d->{$snap} = 1;
+    $d->{$snap} = generate_snapshot_info();
 
     return;
 };
@@ -200,6 +211,14 @@ my $mocked_volume_snapshot_delete = sub {
     delete $d->{$snap} || die "no such snapshot '$snap' on '$volid'\n";
 };
 
+my $mocked_volume_snapshot_info = sub {
+    my ($cfg, $volid) = @_;
+
+    my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid);
+
+    return $mocked_storage_content->{$storeid}->{$volname} // {};
+};
+
 my $pve_replication_module = Test::MockModule->new('PVE::Replication');
 
 my $mocked_job_logfile_name = sub {
@@ -253,6 +272,7 @@ sub setup {
     $pve_storage_module->mock(volume_snapshot_list => $mocked_volume_snapshot_list);
     $pve_storage_module->mock(volume_snapshot => $mocked_volume_snapshot);
     $pve_storage_module->mock(volume_snapshot_delete => $mocked_volume_snapshot_delete);
+    $pve_storage_module->mock(volume_snapshot_info => $mocked_volume_snapshot_info);
 
     $pve_replication_config_module->mock(
 	new => $mocked_replication_config_new,
-- 
2.30.2






More information about the pve-devel mailing list