]>
Commit | Line | Data |
---|---|---|
beaf68f9 DM |
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 | ||
beaf68f9 | 11 | use Test::MockModule; |
beaf68f9 DM |
12 | use Test::More tests => 1; |
13 | ||
e4e1fc86 | 14 | use ReplicationTestEnv; |
7feb60e9 DM |
15 | use PVE::API2::Replication; |
16 | ||
beaf68f9 DM |
17 | $ReplicationTestEnv::mocked_nodename = 'node1'; |
18 | ||
19 | my $schedule = []; | |
20 | ||
21 | my $mocked_replicate = sub { | |
6411310f | 22 | my ($guest_class, $jobcfg, $state, $start_time, $logfunc) = @_; |
beaf68f9 DM |
23 | |
24 | push @$schedule, { | |
25 | id => $jobcfg->{id}, | |
26 | guest => $jobcfg->{guest}, | |
27 | vmtype => $jobcfg->{vmtype}, | |
6411310f | 28 | guest_class => $guest_class, |
eda1b842 | 29 | last_sync => $state->{last_sync}, |
beaf68f9 DM |
30 | start => $start_time, |
31 | }; | |
32 | }; | |
33 | ||
34 | my $pve_replication_module = Test::MockModule->new('PVE::Replication'); | |
35 | $pve_replication_module->mock(replicate => $mocked_replicate); | |
36 | ||
beaf68f9 | 37 | $ReplicationTestEnv::mocked_replication_jobs = { |
37067118 | 38 | '900-1_to_node2' => { |
beaf68f9 DM |
39 | 'type' => 'local', |
40 | 'target' => 'node2', | |
41 | 'guest' => 900, | |
42 | }, | |
37067118 | 43 | '900-2_to_node1' => { |
beaf68f9 DM |
44 | 'type' => 'local', |
45 | 'target' => 'node1', # local node, job should be skipped | |
46 | 'guest' => 900, | |
47 | }, | |
48 | }; | |
49 | ||
50 | $ReplicationTestEnv::mocked_vm_configs = { | |
51 | 900 => { | |
52 | node => 'node1', | |
53 | snapshots => {}, | |
54 | ide0 => 'local-lvm:vm-900-disk-1,size=4G', | |
55 | memory => 512, | |
56 | ide2 => 'none,media=cdrom', | |
57 | }, | |
58 | }; | |
59 | ||
60 | ReplicationTestEnv::setup(); | |
61 | ||
62 | for (my $i = 0; $i < 61; $i++) { | |
7feb60e9 | 63 | PVE::API2::Replication::run_jobs($i*60); |
beaf68f9 DM |
64 | } |
65 | ||
beaf68f9 DM |
66 | my $exptected_schedule = [ |
67 | { | |
eda1b842 DM |
68 | last_sync => 0, |
69 | start => 900, | |
70 | vmtype => 'qemu', | |
6411310f | 71 | guest_class => 'PVE::QemuConfig', |
37067118 | 72 | id => '900-1_to_node2', |
eda1b842 | 73 | guest => 900 |
beaf68f9 DM |
74 | }, |
75 | { | |
eda1b842 DM |
76 | last_sync => 900, |
77 | start => 1800, | |
78 | vmtype => 'qemu', | |
6411310f | 79 | guest_class => 'PVE::QemuConfig', |
37067118 | 80 | id => '900-1_to_node2', |
eda1b842 DM |
81 | guest => 900, |
82 | }, | |
beaf68f9 | 83 | { |
eda1b842 DM |
84 | last_sync => 1800, |
85 | start => 2700, | |
86 | vmtype => 'qemu', | |
6411310f | 87 | guest_class => 'PVE::QemuConfig', |
37067118 | 88 | id => '900-1_to_node2', |
eda1b842 | 89 | guest => 900 |
beaf68f9 DM |
90 | }, |
91 | { | |
eda1b842 DM |
92 | last_sync => 2700, |
93 | start => 3600, | |
94 | vmtype => 'qemu', | |
6411310f | 95 | guest_class => 'PVE::QemuConfig', |
37067118 | 96 | id => '900-1_to_node2', |
eda1b842 | 97 | guest => 900 |
beaf68f9 DM |
98 | } |
99 | ]; | |
100 | ||
101 | is_deeply($schedule, $exptected_schedule); | |
102 | ||
103 | exit(0); |