1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Moved get_error_message from TM to CommandManager

(cherry picked from commit f038c2c36afd3b899da428698e7d5cd29d281747)
This commit is contained in:
Javi Fontan 2011-03-21 18:46:05 +01:00 committed by Ruben S. Montero
parent c5d61293ab
commit da63aaadd4
2 changed files with 23 additions and 20 deletions

View File

@ -27,6 +27,20 @@ require 'stringio'
# * +stdout+: string of the standard output. Read-only
# * +stderr+: string of the standard error. Read-only
# * +command+: command to execute. Read-only
#
# The protocol for scripts to log is as follows:
#
# * Log messages will be sent to STDOUT
# * The script will return 0 if it succeded or any other value
# if there was a failure
# * In case of failure the cause of the error will be written to STDERR
# wrapped by start and end marks as follows:
#
# ERROR MESSAGE --8<------
# error message for the failure
# ERROR MESSAGE ------>8--
class GenericCommand
attr_reader :code, :stdout, :stderr, :command
@ -78,6 +92,13 @@ class GenericCommand
return @code
end
# Parses error message from +stderr+ output
def get_error_message
tmp=@stderr.scan(/^ERROR MESSAGE --8<------\n(.*?)ERROR MESSAGE ------>8--$/m)
return "Error message not available" if !tmp[0]
tmp[0].join(' ').strip
end
private

View File

@ -27,18 +27,7 @@ are the names of the commands (uppercase) and contain the path of
the script that will be executed for that command.
It also contains some methods to execute the scripts, get the output
of the script (success/failure, error and log messages). The protocol
for scripts to do so is as follows:
* Log messages will be sent to STDOUT
* The script will return 0 if it succeded or any other value
if there was a failure
* In case of failure the cause of the error will be written to STDERR
wrapped by start and end marks as follows:
ERROR MESSAGE --8<------
error message for the failure
ERROR MESSAGE ------>8--
of the script (success/failure, error and log messages).
=end
class TMPlugin < Hash
@ -150,7 +139,7 @@ class TMScript
if res.code == 0
res = [true, ""]
else
res = [false, get_error_message(res.stderr)]
res = [false, res.get_error_message]
end
end
@ -176,13 +165,6 @@ class TMScript
@lines<< command
}
end
# Parses error message from +stderr+ output
def get_error_message(str)
tmp=str.scan(/^ERROR MESSAGE --8<------\n(.*?)ERROR MESSAGE ------>8--$/m)
return "Error message not available" if !tmp[0]
tmp[0][0].strip
end
end