]>
Commit | Line | Data |
---|---|---|
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 Test::MockModule; | |
12 | use Test::More tests => 1; | |
13 | ||
14 | use ReplicationTestEnv; | |
15 | use PVE::API2::Replication; | |
16 | ||
17 | $ReplicationTestEnv::mocked_nodename = 'node1'; | |
18 | ||
19 | my $schedule = []; | |
20 | ||
21 | my $mocked_replicate = sub { | |
22 | my ($guest_class, $jobcfg, $state, $start_time, $logfunc) = @_; | |
23 | ||
24 | push @$schedule, { | |
25 | id => $jobcfg->{id}, | |
26 | guest => $jobcfg->{guest}, | |
27 | vmtype => $jobcfg->{vmtype}, | |
28 | guest_class => $guest_class, | |
29 | last_sync => $state->{last_sync}, | |
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 | ||
37 | $ReplicationTestEnv::mocked_replication_jobs = { | |
38 | '900-1_to_node2' => { | |
39 | 'type' => 'local', | |
40 | 'target' => 'node2', | |
41 | 'guest' => 900, | |
42 | }, | |
43 | '900-2_to_node1' => { | |
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++) { | |
63 | PVE::API2::Replication::run_jobs($i*60); | |
64 | } | |
65 | ||
66 | my $exptected_schedule = [ | |
67 | { | |
68 | last_sync => 0, | |
69 | start => 900, | |
70 | vmtype => 'qemu', | |
71 | guest_class => 'PVE::QemuConfig', | |
72 | id => '900-1_to_node2', | |
73 | guest => 900 | |
74 | }, | |
75 | { | |
76 | last_sync => 900, | |
77 | start => 1800, | |
78 | vmtype => 'qemu', | |
79 | guest_class => 'PVE::QemuConfig', | |
80 | id => '900-1_to_node2', | |
81 | guest => 900, | |
82 | }, | |
83 | { | |
84 | last_sync => 1800, | |
85 | start => 2700, | |
86 | vmtype => 'qemu', | |
87 | guest_class => 'PVE::QemuConfig', | |
88 | id => '900-1_to_node2', | |
89 | guest => 900 | |
90 | }, | |
91 | { | |
92 | last_sync => 2700, | |
93 | start => 3600, | |
94 | vmtype => 'qemu', | |
95 | guest_class => 'PVE::QemuConfig', | |
96 | id => '900-1_to_node2', | |
97 | guest => 900 | |
98 | } | |
99 | ]; | |
100 | ||
101 | is_deeply($schedule, $exptected_schedule); | |
102 | ||
103 | exit(0); |