mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
B #5065: Fix get_error_message
Removes uneeded error message wraps. (cherry picked from commit 82fb4f421696d5e0526c45f46f9abd6540167ca2)
This commit is contained in:
parent
16ca4cbb41
commit
2a8fbbb31b
@ -71,7 +71,7 @@ ds_id = drv_action['/DS_DRIVER_ACTION_DATA/DATASTORE/ID']
|
||||
if img_source.nil?
|
||||
message = 'Not enough information to export the image, '\
|
||||
'missing image source.'
|
||||
STDERR.puts error_message(message)
|
||||
STDERR.puts message
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
|
@ -188,37 +188,25 @@ class InformationManagerDriver < OpenNebulaDriver
|
||||
# Sends a log message to ONE. The +message+ can be multiline, it will
|
||||
# be automatically splitted by lines.
|
||||
def log(id, message, not_used=true)
|
||||
in_error = false
|
||||
msg = message.strip
|
||||
severity = 'I'
|
||||
msg = message.strip
|
||||
|
||||
msg.each_line do |line|
|
||||
l = line.strip
|
||||
severity = 'I'
|
||||
|
||||
if l == 'ERROR MESSAGE --8<------'
|
||||
in_error = true
|
||||
next
|
||||
elsif l == 'ERROR MESSAGE ------>8--'
|
||||
in_error = false
|
||||
next
|
||||
else
|
||||
m = line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
|
||||
m = line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
|
||||
|
||||
if in_error
|
||||
if m
|
||||
line = m[2]
|
||||
|
||||
case m[1]
|
||||
when 'ERROR'
|
||||
severity = 'E'
|
||||
elsif m
|
||||
line = m[2]
|
||||
|
||||
case m[1]
|
||||
when 'ERROR'
|
||||
severity = 'E'
|
||||
when 'DEBUG'
|
||||
severity = 'D'
|
||||
when 'INFO'
|
||||
severity = 'I'
|
||||
else
|
||||
severity = 'I'
|
||||
end
|
||||
when 'DEBUG'
|
||||
severity = 'D'
|
||||
when 'INFO'
|
||||
severity = 'I'
|
||||
else
|
||||
severity = 'I'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -105,10 +105,6 @@ begin
|
||||
]
|
||||
EOF
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -219,10 +219,6 @@ begin
|
||||
]
|
||||
EOF
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -127,10 +127,6 @@ begin
|
||||
|
||||
ec2.release_address({ :allocation_id => allocation_id })
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -103,10 +103,6 @@ begin
|
||||
]
|
||||
EOF
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -228,10 +228,6 @@ begin
|
||||
]
|
||||
EOF
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -116,10 +116,6 @@ begin
|
||||
|
||||
packet.delete_ip(packet_id)
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -90,10 +90,6 @@ begin
|
||||
]
|
||||
EOF
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -195,10 +195,6 @@ begin
|
||||
]
|
||||
EOF
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -112,10 +112,6 @@ begin
|
||||
|
||||
exit(0)
|
||||
rescue StandardError => e
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << e.to_s
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
STDERR.puts error_str
|
||||
STDERR.puts e.to_s
|
||||
exit(-1)
|
||||
end
|
||||
|
@ -34,17 +34,9 @@ require 'base64'
|
||||
# * 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--
|
||||
|
||||
# * In case of failure the cause of the error will be written to STDERR.
|
||||
|
||||
class GenericCommand
|
||||
ERROR_OPEN = "ERROR MESSAGE --8<------"
|
||||
ERROR_CLOSE = "ERROR MESSAGE ------>8--"
|
||||
|
||||
attr_reader :code, :stdout, :stderr, :command
|
||||
|
||||
@ -93,8 +85,9 @@ class GenericCommand
|
||||
end
|
||||
|
||||
log(error_message)
|
||||
@stderr = ERROR_OPEN + "\n" + error_message + "\n" + ERROR_CLOSE
|
||||
@code = 255
|
||||
|
||||
@stderr = error_message
|
||||
@code = 255
|
||||
end
|
||||
|
||||
return @code
|
||||
@ -102,9 +95,9 @@ class GenericCommand
|
||||
|
||||
# Parses error message from +stderr+ output
|
||||
def get_error_message
|
||||
tmp=@stderr.scan(/^#{ERROR_OPEN}\n(.*?)#{ERROR_CLOSE}$/m)
|
||||
return "-" if !tmp[0]
|
||||
tmp[0].join(' ').strip
|
||||
return '-' if @stderr.empty?
|
||||
|
||||
@stderr.tr("\n",' ').strip
|
||||
end
|
||||
|
||||
def to_xml
|
||||
|
@ -124,31 +124,21 @@ module DriverExecHelper
|
||||
# Sends a log message to ONE. The +message+ can be multiline, it will
|
||||
# be automatically splitted by lines.
|
||||
def log(number, message, all = true)
|
||||
in_error_message=false
|
||||
msg=message.strip
|
||||
msg = message.strip
|
||||
|
||||
msg.each_line do |line|
|
||||
all ? severity='I' : severity=nil
|
||||
l=line.strip
|
||||
|
||||
if l=='ERROR MESSAGE --8<------'
|
||||
in_error_message=true
|
||||
next
|
||||
elsif l=='ERROR MESSAGE ------>8--'
|
||||
in_error_message=false
|
||||
next
|
||||
else
|
||||
if in_error_message
|
||||
if line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
|
||||
line=Regexp.last_match(2)
|
||||
|
||||
case Regexp.last_match(1)
|
||||
when 'ERROR'
|
||||
severity='E'
|
||||
elsif line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
|
||||
line=Regexp.last_match(2)
|
||||
case Regexp.last_match(1)
|
||||
when 'ERROR'
|
||||
severity='E'
|
||||
when 'DEBUG'
|
||||
severity='D'
|
||||
when 'INFO'
|
||||
severity='I'
|
||||
end
|
||||
when 'DEBUG'
|
||||
severity='D'
|
||||
when 'INFO'
|
||||
severity='I'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -45,16 +45,7 @@ module OpenNebula
|
||||
|
||||
# This function is used to pass error message to the mad
|
||||
def self.error_message(message)
|
||||
STDERR.puts format_error_message(message)
|
||||
end
|
||||
|
||||
#This function formats an error message for OpenNebula
|
||||
def self.format_error_message(message)
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << message
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
return error_str
|
||||
STDERR.puts message
|
||||
end
|
||||
|
||||
def self.is_disk?(arg)
|
||||
|
@ -147,7 +147,7 @@ class SshStream
|
||||
message = "Error connecting to #{@host}"
|
||||
code = tmp[0][0].to_i
|
||||
|
||||
@err << OpenNebula.format_error_message(message)
|
||||
@err << message
|
||||
|
||||
@alive = false
|
||||
break
|
||||
@ -229,7 +229,7 @@ class SshStreamCommand < RemotesCommand
|
||||
@stderr = @stream.err
|
||||
|
||||
if @code != 0
|
||||
log("Command execution fail: #{command}")
|
||||
log("Command execution fail (exit code: #{@code}): #{command}")
|
||||
end
|
||||
|
||||
log(@stderr)
|
||||
|
@ -123,12 +123,8 @@ function log_debug
|
||||
# This function is used to pass error message to the mad
|
||||
function error_message
|
||||
{
|
||||
(
|
||||
echo "ERROR MESSAGE --8<------"
|
||||
echo "$1"
|
||||
echo "ERROR MESSAGE ------>8--"
|
||||
) 1>&2
|
||||
}
|
||||
echo "$1" 1>&2
|
||||
|
||||
|
||||
# Ensures the code is executed exclusively
|
||||
function exclusive
|
||||
|
@ -46,9 +46,6 @@ module OneProvision
|
||||
|
||||
class << self
|
||||
|
||||
ERROR_OPEN = 'ERROR MESSAGE --8<------'
|
||||
ERROR_CLOSE = 'ERROR MESSAGE ------>8--'
|
||||
|
||||
# Prints command and options in the debug output
|
||||
#
|
||||
# @param cmd [String] Command executed
|
||||
@ -95,22 +92,6 @@ module OneProvision
|
||||
raise OneProvisionLoopException, return_code.message if error
|
||||
end
|
||||
|
||||
# Gets error message
|
||||
#
|
||||
# @param text [String] Text with error message inside
|
||||
#
|
||||
# @return [String] Error message
|
||||
def get_error_message(text)
|
||||
msg = '-'
|
||||
|
||||
if text
|
||||
tmp = text.scan(/^#{ERROR_OPEN}\n(.*?)#{ERROR_CLOSE}$/m)
|
||||
msg = tmp[0].join(' ').strip if tmp[0]
|
||||
end
|
||||
|
||||
msg
|
||||
end
|
||||
|
||||
# Converts XML template to string
|
||||
#
|
||||
# @param attributes [Hash] XML attributes
|
||||
|
@ -65,7 +65,7 @@ begin
|
||||
packet_drv.cancel(deploy_id, vm.lcm_state_str)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts error_message(<<EOT)
|
||||
STDERR.puts <<EOT
|
||||
Cancel of VM #{deploy_id} failed due to "#{e.message}"
|
||||
#{e.backtrace}
|
||||
EOT
|
||||
|
@ -67,7 +67,7 @@ begin
|
||||
puts packet_drv.deploy_vm(id, host, text, vm.lcm_state_str, vm.deploy_id)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts error_message(<<EOT)
|
||||
STDERR.puts <<EOT
|
||||
Deploy of VM #{id} on Packet host #{host} with #{dfile} failed due to "#{e.message}"
|
||||
#{e.backtrace}"
|
||||
EOT
|
||||
|
@ -548,16 +548,6 @@ class PacketDriver
|
||||
|
||||
end
|
||||
|
||||
###
|
||||
|
||||
def error_message(message)
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << message
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
error_str
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# Module Interface
|
||||
# Interface for probe_db - VirtualMachineDB
|
||||
|
@ -61,7 +61,7 @@ begin
|
||||
packet_drv.poll(deploy_id)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts error_message(<<EOT)
|
||||
STDERR.puts <<EOT
|
||||
Cannot poll info for VM #{id} on Packet host #{host} due to "#{e.message}"
|
||||
#{e.backtrace}"
|
||||
EOT
|
||||
|
@ -61,7 +61,7 @@ begin
|
||||
packet_drv.reboot(deploy_id)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts error_message(<<EOT)
|
||||
STDERR.puts <<EOT
|
||||
Reboot of VM #{vm_id} on Packet host #{host} failed due to "#{e.message}"
|
||||
#{e.backtrace}"
|
||||
EOT
|
||||
|
@ -61,7 +61,7 @@ begin
|
||||
packet_drv.reset(deploy_id)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts error_message(<<EOT)
|
||||
STDERR.puts <<EOT
|
||||
Reset of VM #{vm_id} on Packet host #{host} failed due to "#{e.message}"
|
||||
#{e.backtrace}"
|
||||
EOT
|
||||
|
@ -65,7 +65,7 @@ begin
|
||||
packet_drv.shutdown(deploy_id, vm.lcm_state_str)
|
||||
|
||||
rescue Exception => e
|
||||
STDERR.puts error_message(<<EOT)
|
||||
STDERR.puts <<EOT
|
||||
Shutdown of VM #{vm_id} on Packet host #{host} failed due to "#{e.message}"
|
||||
#{e.backtrace}"
|
||||
EOT
|
||||
|
@ -133,19 +133,10 @@ end
|
||||
# Helper functions #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
def error_message(message)
|
||||
error_str = "ERROR MESSAGE --8<------\n"
|
||||
error_str << message
|
||||
error_str << "\nERROR MESSAGE ------>8--"
|
||||
|
||||
error_str
|
||||
end
|
||||
|
||||
def check_valid(parameter, label)
|
||||
return unless parameter.nil? || parameter.empty?
|
||||
|
||||
STDERR.puts error_message("The parameter '#{label}'\
|
||||
is required for this action.")
|
||||
STDERR.puts "The parameter '#{label}' is required for this action."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user