]> git.proxmox.com Git - pve-manager.git/blame - test/replication_test2.pl
ui: vm wizard: reword label for extra drive for virtio-drivers
[pve-manager.git] / 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
816c01f8 11use Test::MockModule;
816c01f8
DM
12use Test::More tests => 1;
13
d59f1fa8 14use ReplicationTestEnv;
810c6776
DM
15use PVE::API2::Replication;
16
816c01f8
DM
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 37$ReplicationTestEnv::mocked_replication_jobs = {
2f6e5f34 38 '900-1_to_node2' => {
816c01f8
DM
39 'type' => 'local',
40 'target' => 'node2',
41 'guest' => 900,
42 },
2f6e5f34 43 '900-2_to_node1' => {
816c01f8
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
60ReplicationTestEnv::setup();
61
62for (my $i = 0; $i < 61; $i++) {
810c6776 63 PVE::API2::Replication::run_jobs($i*60);
816c01f8
DM
64}
65
816c01f8
DM
66my $exptected_schedule = [
67 {
356fbf79
DM
68 last_sync => 0,
69 start => 900,
70 vmtype => 'qemu',
b9da11aa 71 guest_class => 'PVE::QemuConfig',
2f6e5f34 72 id => '900-1_to_node2',
356fbf79 73 guest => 900
816c01f8
DM
74 },
75 {
356fbf79
DM
76 last_sync => 900,
77 start => 1800,
78 vmtype => 'qemu',
b9da11aa 79 guest_class => 'PVE::QemuConfig',
2f6e5f34 80 id => '900-1_to_node2',
356fbf79
DM
81 guest => 900,
82 },
816c01f8 83 {
356fbf79
DM
84 last_sync => 1800,
85 start => 2700,
86 vmtype => 'qemu',
b9da11aa 87 guest_class => 'PVE::QemuConfig',
2f6e5f34 88 id => '900-1_to_node2',
356fbf79 89 guest => 900
816c01f8
DM
90 },
91 {
356fbf79
DM
92 last_sync => 2700,
93 start => 3600,
94 vmtype => 'qemu',
b9da11aa 95 guest_class => 'PVE::QemuConfig',
2f6e5f34 96 id => '900-1_to_node2',
356fbf79 97 guest => 900
816c01f8
DM
98 }
99];
100
101is_deeply($schedule, $exptected_schedule);
102
103exit(0);