]> git.proxmox.com Git - pve-manager.git/blame - bin/test/replication_test2.pl
PVE::Replication - pass guest_class to run_replication
[pve-manager.git] / bin / test / replication_test2.pl
CommitLineData
816c01f8
DM
1#!/usr/bin/perl
2
3# Note: Test replication scheduler
4
5use strict;
6use warnings;
7use JSON;
8
9use lib ('.', '../..');
10
11use Data::Dumper;
12
13use Test::MockModule;
14use ReplicationTestEnv;
15use Test::More tests => 1;
16
17$ReplicationTestEnv::mocked_nodename = 'node1';
18
19my $schedule = [];
20
21my $mocked_replicate = sub {
b9da11aa 22 my ($guest_class, $jobcfg, $state, $start_time, $logfunc) = @_;
816c01f8
DM
23
24 push @$schedule, {
25 id => $jobcfg->{id},
26 guest => $jobcfg->{guest},
27 vmtype => $jobcfg->{vmtype},
b9da11aa 28 guest_class => $guest_class,
356fbf79 29 last_sync => $state->{last_sync},
816c01f8
DM
30 start => $start_time,
31 };
32};
33
34my $pve_replication_module = Test::MockModule->new('PVE::Replication');
35$pve_replication_module->mock(replicate => $mocked_replicate);
36
816c01f8
DM
37$ReplicationTestEnv::mocked_replication_jobs = {
38 job_900_to_node2 => {
39 'type' => 'local',
40 'target' => 'node2',
41 'guest' => 900,
42 },
43 job_900_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
60ReplicationTestEnv::setup();
61
62for (my $i = 0; $i < 61; $i++) {
63 PVE::Replication::run_jobs($i*60);
64}
65
66#print Dumper($schedule);
67
68my $exptected_schedule = [
69 {
356fbf79
DM
70 last_sync => 0,
71 start => 900,
72 vmtype => 'qemu',
b9da11aa 73 guest_class => 'PVE::QemuConfig',
356fbf79
DM
74 id => 'job_900_to_node2',
75 guest => 900
816c01f8
DM
76 },
77 {
356fbf79
DM
78 last_sync => 900,
79 start => 1800,
80 vmtype => 'qemu',
b9da11aa 81 guest_class => 'PVE::QemuConfig',
356fbf79
DM
82 id => 'job_900_to_node2',
83 guest => 900,
84 },
816c01f8 85 {
356fbf79
DM
86 last_sync => 1800,
87 start => 2700,
88 vmtype => 'qemu',
b9da11aa 89 guest_class => 'PVE::QemuConfig',
356fbf79
DM
90 id => 'job_900_to_node2',
91 guest => 900
816c01f8
DM
92 },
93 {
356fbf79
DM
94 last_sync => 2700,
95 start => 3600,
96 vmtype => 'qemu',
b9da11aa 97 guest_class => 'PVE::QemuConfig',
356fbf79
DM
98 id => 'job_900_to_node2',
99 guest => 900
816c01f8
DM
100 }
101];
102
103is_deeply($schedule, $exptected_schedule);
104
105exit(0);