]> git.proxmox.com Git - pve-cluster.git/commitdiff
add simple corosync config parser self check
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 26 Jun 2017 12:10:57 +0000 (14:10 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 27 Jun 2017 05:02:20 +0000 (07:02 +0200)
Each test reads and parses a config "writes" it again and then
re-parses it.
Then both the parsed hash structures and the raw config get compared
This is cheap and should catch simple regressions in either the
parser or writer, as currently we have no safety net that
modifications on either one didn't cause regressions.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
data/Makefile.am
data/test/Makefile [new file with mode: 0644]
data/test/corosync_configs/multiple-nodes.conf [new file with mode: 0644]
data/test/corosync_configs/single-node.conf [new file with mode: 0644]
data/test/corosync_parser_test.pl [new file with mode: 0755]

index ca180ca91693a7f1eb9967f722f401e822a6563e..51b1cd4aaa6a5b73e192f3222126ef092610b38f 100644 (file)
@@ -1,4 +1,4 @@
 
-SUBDIRS = src PVE
+SUBDIRS = src PVE test
 
 CLEANFILES = *~
diff --git a/data/test/Makefile b/data/test/Makefile
new file mode 100644 (file)
index 0000000..c3df52a
--- /dev/null
@@ -0,0 +1,9 @@
+all:
+
+.PHONY: check install clean distclean
+check:
+       ./corosync_parser_test.pl
+
+install: check
+distclean: clean
+clean:
diff --git a/data/test/corosync_configs/multiple-nodes.conf b/data/test/corosync_configs/multiple-nodes.conf
new file mode 100644 (file)
index 0000000..a67cc0c
--- /dev/null
@@ -0,0 +1,56 @@
+logging {
+  debug: off
+  to_syslog: yes
+}
+
+nodelist {
+  node {
+    name: prox1
+    nodeid: 1
+    quorum_votes: 1
+    ring0_addr: prox1
+    ring1_addr: prox1-ring1
+  }
+  node {
+    name: prox2
+    nodeid: 1
+    quorum_votes: 1
+    ring0_addr: prox2
+    ring1_addr: prox2-ring1
+  }
+  node {
+    name: prox3
+    nodeid: 1
+    quorum_votes: 1
+    ring0_addr: prox3
+    ring1_addr: prox3-ring1
+  }
+  node {
+    name: prox4
+    nodeid: 1
+    quorum_votes: 1
+    ring0_addr: prox4
+    ring1_addr: prox4-ring1
+  }
+}
+
+quorum {
+  provider: corosync_votequorum
+}
+
+totem {
+  cluster_name: cloud
+  config_version: 1
+  ip_version: ipv4
+  secauth: on
+  version: 2
+  interface {
+    bindnetaddr: 192.168.0.42
+    ringnumber: 0
+  }
+  interface {
+    bindnetaddr: 192.168.1.42
+    ringnumber: 1
+  }
+}
+
diff --git a/data/test/corosync_configs/single-node.conf b/data/test/corosync_configs/single-node.conf
new file mode 100644 (file)
index 0000000..7a23f9a
--- /dev/null
@@ -0,0 +1,30 @@
+logging {
+  debug: off
+  to_syslog: yes
+}
+
+nodelist {
+  node {
+    name: prox1
+    nodeid: 1
+    quorum_votes: 1
+    ring0_addr: prox1
+  }
+}
+
+quorum {
+  provider: corosync_votequorum
+}
+
+totem {
+  cluster_name: cloud
+  config_version: 1
+  ip_version: ipv4
+  secauth: on
+  version: 2
+  interface {
+    bindnetaddr: 192.168.0.42
+    ringnumber: 0
+  }
+}
+
diff --git a/data/test/corosync_parser_test.pl b/data/test/corosync_parser_test.pl
new file mode 100755 (executable)
index 0000000..18ee4f7
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+
+use lib '..';
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use PVE::Corosync;
+
+sub parser_self_check {
+    my $cfg_fn = shift;
+
+    my $outfile = "$cfg_fn.write";
+    my ($config1, $config2, $raw1, $raw2);
+
+    eval {
+       # read first time
+       $raw1 = PVE::Tools::file_get_contents($cfg_fn);
+       $config1 = PVE::Corosync::parse_conf($cfg_fn, $raw1);
+
+       # write config
+       $raw2 = PVE::Corosync::write_conf(undef, $config1);
+       # do not actually write cfg, but you can outcomment to do so, e.g. if
+       # you want to use diff for easy comparision
+       #PVE::Tools::file_set_contents($outfile, $raw2);
+
+       # reparse written config (must be the same as config1)
+       $config2 = PVE::Corosync::parse_conf(undef, $raw2);
+    }; warn $@ if $@;
+
+    # do not care for whitespace differences
+    delete $config1->{digest};
+    delete $config2->{digest};
+
+    is_deeply($config1, $config2, "self check hash: $cfg_fn");
+
+    # do not care about extra new lines
+    $raw1 =~ s/^\s*\n+//mg;
+    $raw2 =~ s/^\s*\n+//mg;
+
+    is($raw1, $raw2, "self check raw: $cfg_fn");
+}
+
+# exec tests
+if (my $file = shift) {
+    parser_self_check($file);
+} else {
+    foreach my $file (<corosync_configs/*.conf>) {
+       parser_self_check($file);
+    }
+}
+
+done_testing();