]> git.proxmox.com Git - pve-manager.git/blame - bin/test/replication_test2.pl
cleanup: add network-hooks directory and move respective files
[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
810c6776
DM
17use PVE::API2::Replication;
18
816c01f8
DM
19$ReplicationTestEnv::mocked_nodename = 'node1';
20
21my $schedule = [];
22
23my $mocked_replicate = sub {
b9da11aa 24 my ($guest_class, $jobcfg, $state, $start_time, $logfunc) = @_;
816c01f8
DM
25
26 push @$schedule, {
27 id => $jobcfg->{id},
28 guest => $jobcfg->{guest},
29 vmtype => $jobcfg->{vmtype},
b9da11aa 30 guest_class => $guest_class,
356fbf79 31 last_sync => $state->{last_sync},
816c01f8
DM
32 start => $start_time,
33 };
34};
35
36my $pve_replication_module = Test::MockModule->new('PVE::Replication');
37$pve_replication_module->mock(replicate => $mocked_replicate);
38
816c01f8 39$ReplicationTestEnv::mocked_replication_jobs = {
2f6e5f34 40 '900-1_to_node2' => {
816c01f8
DM
41 'type' => 'local',
42 'target' => 'node2',
43 'guest' => 900,
44 },
2f6e5f34 45 '900-2_to_node1' => {
816c01f8
DM
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
62ReplicationTestEnv::setup();
63
64for (my $i = 0; $i < 61; $i++) {
810c6776 65 PVE::API2::Replication::run_jobs($i*60);
816c01f8
DM
66}
67
68#print Dumper($schedule);
69
70my $exptected_schedule = [
71 {
356fbf79
DM
72 last_sync => 0,
73 start => 900,
74 vmtype => 'qemu',
b9da11aa 75 guest_class => 'PVE::QemuConfig',
2f6e5f34 76 id => '900-1_to_node2',
356fbf79 77 guest => 900
816c01f8
DM
78 },
79 {
356fbf79
DM
80 last_sync => 900,
81 start => 1800,
82 vmtype => 'qemu',
b9da11aa 83 guest_class => 'PVE::QemuConfig',
2f6e5f34 84 id => '900-1_to_node2',
356fbf79
DM
85 guest => 900,
86 },
816c01f8 87 {
356fbf79
DM
88 last_sync => 1800,
89 start => 2700,
90 vmtype => 'qemu',
b9da11aa 91 guest_class => 'PVE::QemuConfig',
2f6e5f34 92 id => '900-1_to_node2',
356fbf79 93 guest => 900
816c01f8
DM
94 },
95 {
356fbf79
DM
96 last_sync => 2700,
97 start => 3600,
98 vmtype => 'qemu',
b9da11aa 99 guest_class => 'PVE::QemuConfig',
2f6e5f34 100 id => '900-1_to_node2',
356fbf79 101 guest => 900
816c01f8
DM
102 }
103];
104
105is_deeply($schedule, $exptected_schedule);
106
107exit(0);