]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
Use new exitcodes instead of integers
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 23 Oct 2015 12:04:24 +0000 (14:04 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 29 Oct 2015 06:52:18 +0000 (07:52 +0100)
Use the new exitcodes introduced in the previous commit to gain
some readability.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/HA/Env/PVE2.pm
src/PVE/HA/LRM.pm
src/PVE/HA/Manager.pm

index d053dcc8b11ba2dd98e46a257efcb308dc2926a1..7db8daca5912584af2b5382d03ba2c959723ff41 100644 (file)
@@ -12,7 +12,7 @@ use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file
 use PVE::INotify;
 use PVE::RPCEnvironment;
 
-use PVE::HA::Tools;
+use PVE::HA::Tools ':exit_codes';
 use PVE::HA::Env;
 use PVE::HA::Config;
 
@@ -394,7 +394,7 @@ sub exec_resource_agent {
 
     if ($cmd eq 'started') {
 
-       return 0 if $running;
+       return SUCCESS if $running;
 
        $self->log("info", "starting service $sid");
 
@@ -409,15 +409,15 @@ sub exec_resource_agent {
 
        if ($running) {
            $self->log("info", "service status $sid started");
-           return 0;
+           return SUCCESS;
        } else {
            $self->log("warning", "unable to start service $sid");
-           return 1;
+           return ERROR;
        }
 
     } elsif ($cmd eq 'request_stop' || $cmd eq 'stopped') {
 
-       return 0 if !$running;
+       return SUCCESS if !$running;
 
        $self->log("info", "stopping service $sid");
 
@@ -436,9 +436,9 @@ sub exec_resource_agent {
 
        if (!$running) {
            $self->log("info", "service status $sid stopped");
-           return 0;
+           return SUCCESS;
        } else {
-           return 1;
+           return ERROR;
        }
 
     } elsif ($cmd eq 'migrate' || $cmd eq 'relocate') {
@@ -448,7 +448,7 @@ sub exec_resource_agent {
 
        if ($service_config->{node} eq $target) {
            # already there
-           return 0;
+           return SUCCESS;
        }
 
        # we always do (live) migration
@@ -466,10 +466,10 @@ sub exec_resource_agent {
        # something went wrong if old config file is still there
        if (-f $oldconfig) {
            $self->log("err", "service $sid not moved (migration error)");
-           return 1;
+           return ERROR;
        }
 
-       return 0;
+       return SUCCESS;
 
     } elsif ($cmd eq 'error') {
 
@@ -478,7 +478,7 @@ sub exec_resource_agent {
        } else {
            $self->log("warning", "service $sid is not running and in an error state");
        }
-       return 0;
+       return SUCCESS; # error always succeeds
 
     }
 
index ed2885fbfb5a9f68ba5fe0b174fcdaf63e63aa7f..89177ee79411f00fa842641c25a2ec50d074495d 100644 (file)
@@ -9,7 +9,7 @@ use POSIX qw(:sys_wait_h);
 
 use PVE::SafeSyslog;
 use PVE::Tools;
-use PVE::HA::Tools;
+use PVE::HA::Tools ':exit_codes';
 
 # Server can have several states:
 
@@ -489,13 +489,13 @@ sub handle_service_exitcode {
 
     if ($cmd eq 'started') {
 
-       if ($exit_code == 0) {
+       if ($exit_code == SUCCESS) {
 
            $tries->{$sid} = 0;
 
            return $exit_code;
 
-       } elsif ($exit_code == 1) {
+       } elsif ($exit_code == ERROR) {
 
            $tries->{$sid} = 0 if !defined($tries->{$sid});
 
@@ -504,10 +504,11 @@ sub handle_service_exitcode {
                $haenv->log('err', "unable to start service $sid on local node".
                           " after $tries->{$sid} retries");
                $tries->{$sid} = 0;
-               return 1;
+               return ERROR;
            }
 
-           return 2;
+           # tell CRM that we retry the start
+           return ETRY_AGAIN;
        }
     }
 
index 3aaecd6c89b395b27d2cfb40324b6d93e122ca64..6a98cd3dd267825e3523fb00af0c8ada4a833abe 100644 (file)
@@ -6,6 +6,7 @@ use Digest::MD5 qw(md5_base64);
 
 use Data::Dumper;
 use PVE::Tools;
+use PVE::HA::Tools ':exit_codes';
 use PVE::HA::NodeStatus;
 
 my $fence_delay = 60;
@@ -405,7 +406,7 @@ sub next_state_request_stop {
     # check result from LRM daemon
     if ($lrm_res) {
        my $exit_code = $lrm_res->{exit_code};
-       if ($exit_code == 0) {
+       if ($exit_code == SUCCESS) {
            &$change_service_state($self, $sid, 'stopped');
            return;
        } else {
@@ -429,7 +430,7 @@ sub next_state_migrate_relocate {
     # check result from LRM daemon
     if ($lrm_res) {
        my $exit_code = $lrm_res->{exit_code};
-       if ($exit_code == 0) {
+       if ($exit_code == SUCCESS) {
            &$change_service_state($self, $sid, 'started', node => $sd->{target});
            return;
        } else {
@@ -554,7 +555,7 @@ sub next_state_started {
 
            my $try_next = 0;
            if ($lrm_res) {
-               if ($lrm_res->{exit_code} == 1) {
+               if ($lrm_res->{exit_code} == ERROR) {
 
                    my $try = $master_status->{relocate_trial}->{$sid} || 0;
 
@@ -575,7 +576,7 @@ sub next_state_started {
                        return;
 
                    }
-               } elsif ($lrm_res->{exit_code} == 0) {
+               } elsif ($lrm_res->{exit_code} == SUCCESS) {
                    $master_status->{relocate_trial}->{$sid} = 0;
                }
            }