]> git.proxmox.com Git - pve-manager.git/blob - test/replication_test2.pl
cleanup: move bin/test to toplevel
[pve-manager.git] / test / replication_test2.pl
1 #!/usr/bin/perl
2
3 # Note: Test replication scheduler
4
5 use strict;
6 use warnings;
7 use JSON;
8
9 use lib ('.', '../..');
10
11 use Data::Dumper;
12
13 use Test::MockModule;
14 use ReplicationTestEnv;
15 use Test::More tests => 1;
16
17 use PVE::API2::Replication;
18
19 $ReplicationTestEnv::mocked_nodename = 'node1';
20
21 my $schedule = [];
22
23 my $mocked_replicate = sub {
24 my ($guest_class, $jobcfg, $state, $start_time, $logfunc) = @_;
25
26 push @$schedule, {
27 id => $jobcfg->{id},
28 guest => $jobcfg->{guest},
29 vmtype => $jobcfg->{vmtype},
30 guest_class => $guest_class,
31 last_sync => $state->{last_sync},
32 start => $start_time,
33 };
34 };
35
36 my $pve_replication_module = Test::MockModule->new('PVE::Replication');
37 $pve_replication_module->mock(replicate => $mocked_replicate);
38
39 $ReplicationTestEnv::mocked_replication_jobs = {
40 '900-1_to_node2' => {
41 'type' => 'local',
42 'target' => 'node2',
43 'guest' => 900,
44 },
45 '900-2_to_node1' => {
46 'type' => 'local',
47 'target' => 'node1', # local node, job should be skipped
48 'guest' => 900,
49 },
50 };
51
52 $ReplicationTestEnv::mocked_vm_configs = {
53 900 => {
54 node => 'node1',
55 snapshots => {},
56 ide0 => 'local-lvm:vm-900-disk-1,size=4G',
57 memory => 512,
58 ide2 => 'none,media=cdrom',
59 },
60 };
61
62 ReplicationTestEnv::setup();
63
64 for (my $i = 0; $i < 61; $i++) {
65 PVE::API2::Replication::run_jobs($i*60);
66 }
67
68 #print Dumper($schedule);
69
70 my $exptected_schedule = [
71 {
72 last_sync => 0,
73 start => 900,
74 vmtype => 'qemu',
75 guest_class => 'PVE::QemuConfig',
76 id => '900-1_to_node2',
77 guest => 900
78 },
79 {
80 last_sync => 900,
81 start => 1800,
82 vmtype => 'qemu',
83 guest_class => 'PVE::QemuConfig',
84 id => '900-1_to_node2',
85 guest => 900,
86 },
87 {
88 last_sync => 1800,
89 start => 2700,
90 vmtype => 'qemu',
91 guest_class => 'PVE::QemuConfig',
92 id => '900-1_to_node2',
93 guest => 900
94 },
95 {
96 last_sync => 2700,
97 start => 3600,
98 vmtype => 'qemu',
99 guest_class => 'PVE::QemuConfig',
100 id => '900-1_to_node2',
101 guest => 900
102 }
103 ];
104
105 is_deeply($schedule, $exptected_schedule);
106
107 exit(0);