]>
git.proxmox.com Git - pve-cluster.git/blob - data/test/corosync_parser_test.pl
14 "prox1" => "127.0.1.1",
15 "prox1-ring1" => "127.0.2.1",
16 "prox2" => "127.0.1.2",
17 "prox2-ring1" => "127.0.2.2",
18 "prox3" => "127.0.1.3",
19 "prox3-ring1" => "127.0.2.3",
20 "prox4" => "127.0.1.4",
21 "prox4-ring1" => "127.0.2.4",
27 foreach my $host (keys %$known_hosts) {
28 return $known_hosts->{$host} if $hostname eq $host;
31 die "got unknown hostname '$hostname' during mocked resolve_hostname_like_corosync";
34 my $mocked_corosync_module = new Test
::MockModule
('PVE::Corosync');
35 $mocked_corosync_module->mock('resolve_hostname_like_corosync', \
&mocked_resolve
);
37 sub parser_self_check
{
40 my $outfile = "$cfg_fn.write";
41 my ($config1, $config2, $raw1, $raw2);
45 $raw1 = PVE
::Tools
::file_get_contents
($cfg_fn);
46 $config1 = PVE
::Corosync
::parse_conf
($cfg_fn, $raw1);
49 $raw2 = PVE
::Corosync
::write_conf
(undef, $config1);
50 # do not actually write cfg, but you can outcomment to do so, e.g. if
51 # you want to use diff for easy comparision
52 #PVE::Tools::file_set_contents($outfile, $raw2);
54 # reparse written config (must be the same as config1)
55 $config2 = PVE
::Corosync
::parse_conf
(undef, $raw2);
59 my ($err, $warn) = PVE
::Corosync
::verify_conf
($config1);
60 die "verify_conf failed: " . join(" ++ ", @$err) if scalar(@$err);
62 # do not care for whitespace differences
63 delete $config1->{digest
};
64 delete $config2->{digest
};
66 is_deeply
($config1, $config2, "self check hash: $cfg_fn");
68 # do not care about extra new lines
69 $raw1 =~ s/^\s*\n+//mg;
70 $raw2 =~ s/^\s*\n+//mg;
72 is($raw1, $raw2, "self check raw: $cfg_fn");
76 if (my $file = shift) {
77 parser_self_check
($file);
79 foreach my $file (<corosync_configs
/*.conf
>) {
80 parser_self_check
($file);