[pve-devel] [PATCH v3 cluster] Add warning for pvecm commands if not part of cluster

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Mar 14 09:19:22 CET 2016


If the cluster config file is missing, pvecm status, nodes
and expected will probably not work. Add a helpful warning
because the corosync-quorumtool error message is not very
descriptive here.

Add a helper sub in Cluster.pm to actually do the check.
---
Changes compared to v2:
- hardcode msg in helper, drop $msg parameter
- add $silent parameter instead
- rebase on master

 data/PVE/CLI/pvecm.pm |  6 ++++++
 data/PVE/Cluster.pm   | 13 +++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
index 7fadb7d..0de16e6 100755
--- a/data/PVE/CLI/pvecm.pm
+++ b/data/PVE/CLI/pvecm.pm
@@ -601,6 +601,8 @@ __PACKAGE__->register_method ({
     code => sub {
 	my ($param) = @_;
 
+	PVE::Cluster::check_corosync_conf_exists();
+
 	my $cmd = ['corosync-quorumtool', '-siH'];
 
 	exec (@$cmd);
@@ -622,6 +624,8 @@ __PACKAGE__->register_method ({
     code => sub {
 	my ($param) = @_;
 
+	PVE::Cluster::check_corosync_conf_exists();
+
 	my $cmd = ['corosync-quorumtool', '-l'];
 
 	exec (@$cmd);
@@ -649,6 +653,8 @@ __PACKAGE__->register_method ({
     code => sub {
 	my ($param) = @_;
 
+	PVE::Cluster::check_corosync_conf_exists();
+
 	my $cmd = ['corosync-quorumtool', '-e', $param->{expected}];
 
 	exec (@$cmd);
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 8866217..5eabd7c 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -1501,6 +1501,19 @@ PVE::Cluster::cfs_register_file('corosync.conf', \&parse_corosync_conf);
 PVE::Cluster::cfs_register_file('corosync.conf.new', \&parse_corosync_conf, 
 				\&write_corosync_conf);
 
+sub check_corosync_conf_exists {
+    my ($silent) = @_;
+
+    $silent = $silent // 0;
+
+    my $exists = -f "$basedir/corosync.conf";
+
+    warn "Corosync config '$basedir/corosync.conf' does not exist - is this node part of a cluster?\n"
+	if !$silent;
+
+    return $exists;
+}
+
 # bash completion helpers
 
 sub complete_next_vmid {
-- 
2.1.4





More information about the pve-devel mailing list