[pve-devel] [PATCH 3/4] exec_resource_agent: return valid exit code instead of die's

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Oct 23 14:04:25 CEST 2015


Switch from die's to logging and return the respective exit codes.
This adds the possibility to handle (i.e.: fix) some errors outside
of the forked exec_resource_agent worker.

This does not changes behaviour for now, as the die returned an 255
exit code. We didn't checked on that exit code explicitly and so we
are safe to use the new exit codes, it results in the same behaviour
for the other code (most important the CRM Manager class).

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Env/PVE2.pm | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 7db8dac..49654a2 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -378,15 +378,18 @@ sub exec_resource_agent {
 
     my $nodename = $self->{nodename};
 
-    # fixme: return valid_exit code (instead of using die) ?
-
     my (undef, $service_type, $service_name) = PVE::HA::Tools::parse_sid($sid);
 
     my $plugin = PVE::HA::Resources->lookup($service_type);
-    die "service type '$service_type' not implemented" if !$plugin;
+    if (!$plugin) {
+	$self->log('err', "service type '$service_type' not implemented");
+	return EUNKNOWN_SERVICE_TYPE;
+    }
 
-    # fixme: return valid_exit code
-    die "service '$sid' not on this node" if $service_config->{node} ne $nodename;
+    if ($service_config->{node} ne $nodename) {
+	$self->log('err', "service '$sid' not on this node");
+	return EWRONG_NODE;
+    }
 
     my $vmid = $service_name;
 
@@ -444,7 +447,10 @@ sub exec_resource_agent {
     } elsif ($cmd eq 'migrate' || $cmd eq 'relocate') {
 
 	my $target = $params[0];
-	die "$cmd '$sid' failed - missing target\n" if !defined($target);
+	if (!defined($target)) {
+	    die "$cmd '$sid' failed - missing target\n" if !defined($target);
+	    return EINVALID_PARAMETER;
+	}
 
 	if ($service_config->{node} eq $target) {
 	    # already there
@@ -482,7 +488,8 @@ sub exec_resource_agent {
 
     }
 
-    die "implement me (cmd '$cmd')";
+    $self->log("err", "implement me (cmd '$cmd')");
+    return EUNKNOWN_COMMAND;
 }
 
 1;
-- 
2.1.4




More information about the pve-devel mailing list