[pve-devel] [PATCH cluster v5 05/17] assert_joinable: simplify error and warning handling
Thomas Lamprecht
t.lamprecht at proxmox.com
Fri Jan 26 14:25:15 CET 2018
remove the if check for force, as we handle this on another level and
want to record errors independent of the value of force.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
data/PVE/Cluster.pm | 47 +++++++++++++++++++----------------------------
1 file changed, 19 insertions(+), 28 deletions(-)
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 2229972..afa47a7 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -1694,35 +1694,24 @@ sub ssh_info_to_command {
sub assert_joinable {
my ($ring0_addr, $ring1_addr, $force) = @_;
- my ($errors, $warnings) = ('', '');
- my $error = sub {
- my ($msg, $suppress) = @_;
+ my $errors = '';
+ my $error = sub { $errors .= "* $_[0]\n"; };
- if ($suppress) {
- $warnings .= "* $msg\n";
- } else {
- $errors .= "* $msg\n";
- }
- };
+ if (-f $authfile) {
+ $error->("authentication key '$authfile' already exists");
+ }
- if (!$force) {
+ if (-f $clusterconf) {
+ $error->("cluster config '$clusterconf' already exists");
+ }
- if (-f $authfile) {
- $error->("authentication key '$authfile' already exists", $force);
- }
+ my $vmlist = PVE::Cluster::get_vmlist();
+ if ($vmlist && $vmlist->{ids} && scalar(keys %{$vmlist->{ids}})) {
+ $error->("this host already contains virtual guests");
+ }
- if (-f $clusterconf) {
- $error->("cluster config '$clusterconf' already exists", $force);
- }
-
- my $vmlist = PVE::Cluster::get_vmlist();
- if ($vmlist && $vmlist->{ids} && scalar(keys %{$vmlist->{ids}})) {
- $error->("this host already contains virtual guests", $force);
- }
-
- if (system("corosync-quorumtool -l >/dev/null 2>&1") == 0) {
- $error->("corosync is already running, is this node already in a cluster?!", $force);
- }
+ if (system("corosync-quorumtool -l >/dev/null 2>&1") == 0) {
+ $error->("corosync is already running, is this node already in a cluster?!");
}
# check if corosync ring IPs are configured on the current nodes interfaces
@@ -1732,7 +1721,7 @@ sub assert_joinable {
my $host = $ip;
eval { $ip = PVE::Network::get_ip_from_hostname($host); };
if ($@) {
- $error->("cannot use '$host': $@\n", 1) ;
+ $error->("cannot use '$host': $@\n") ;
return;
}
}
@@ -1747,8 +1736,10 @@ sub assert_joinable {
$check_ip->($ring0_addr);
$check_ip->($ring1_addr);
- warn "warning, ignore the following errors:\n$warnings" if $warnings;
- die "detected the following error(s):\n$errors" if $errors;
+ if ($errors) {
+ warn "detected the following error(s):\n$errors";
+ die "Check if node may join a cluster failed!\n" if !$force;
+ }
}
my $backup_cfs_database = sub {
--
2.14.2
More information about the pve-devel
mailing list