1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-26 10:03:37 +03:00

L #-: Linting to make rubocop smile again

This commit is contained in:
Tino Vazquez 2019-09-12 16:56:17 +02:00
parent 3c2df22ad7
commit 9e67ae678d
No known key found for this signature in database
GPG Key ID: 2FE9C32E94AEABBE
6 changed files with 44 additions and 32 deletions

View File

@ -729,6 +729,9 @@ Style/SafeNavigation:
Style/FloatDivision:
Enabled: false
Style/RedundantBegin:
Enabled: false
######
# LINT
######

View File

@ -113,11 +113,13 @@ class OneHookHelper < OpenNebulaHelper::OneHelper
str = '%-18s: %-20s'
str_h1 = '%-80s'
level_lock = OpenNebulaHelper.level_lock_to_str(hook['LOCK/LOCKED'])
CLIHelper.print_header(str_h1 % "HOOK #{hook['ID']} INFORMATION")
puts format str, 'ID', hook.id.to_s
puts format str, 'NAME', hook.name
puts format str, 'TYPE', hook['TYPE']
puts format str, 'LOCK', OpenNebulaHelper.level_lock_to_str(hook['LOCK/LOCKED'])
puts format str, 'LOCK', level_lock
puts
if options[:execution]
@ -138,8 +140,9 @@ class OneHookHelper < OpenNebulaHelper::OneHelper
arguments = er['ARGUMENTS'] if er['ARGUMENTS'].class == String
timestamp = OpenNebulaHelper.time_to_str(er['TIMESTAMP'])
puts format str, 'EXECUTION ID', er['EXECUTION_ID']
puts format str, 'TIMESTAMP', OpenNebulaHelper.time_to_str(er['TIMESTAMP'])
puts format str, 'TIMESTAMP', timestamp
puts format str, 'COMMAND', er['EXECUTION_RESULT']['COMMAND']
puts format str, 'ARGUMENTS', arguments
puts format str, 'EXIT CODE', er['EXECUTION_RESULT']['CODE']
@ -149,11 +152,11 @@ class OneHookHelper < OpenNebulaHelper::OneHelper
puts
CLIHelper.print_header(str_h1 % 'EXECUTION STDOUT')
puts Base64.decode64(stdout) if stdout.class == String && !stdout.empty?
puts Base64.decode64(stdout.to_s) unless stdout.to_s.empty?
puts
CLIHelper.print_header(str_h1 % 'EXECUTION STDERR')
puts Base64.decode64(stderr) if stderr.class == String && !stderr.empty?
puts Base64.decode64(stderr.to_s) unless stderr.to_s.empty?
puts
return

View File

@ -99,7 +99,6 @@ CommandParser::CmdParser.new(ARGV) do
command :create, create_desc, :file, :options =>
[OpenNebulaHelper::DRY] do
helper.create_resource(options) do |tmpl|
begin
if args[0]
@ -235,5 +234,4 @@ CommandParser::CmdParser.new(ARGV) do
t.retry args[1].to_i
end
end
end

View File

@ -183,7 +183,9 @@ module HEMHook
when :api
self['TEMPLATE/CALL']
when :state
"#{self['TEMPLATE/RESOURCE']}/#{self['TEMPLATE/STATE']}/#{self['TEMPLATE/LCM_STATE']}"
"#{self['TEMPLATE/RESOURCE']}/"\
"#{self['TEMPLATE/STATE']}/"\
"#{self['TEMPLATE/LCM_STATE']}"
else
''
end
@ -455,19 +457,22 @@ class HookExecutionManager
end
def reload_hooks(call, info_xml)
id = -1
hook_xpath = '/HOOK_MESSAGE/CALL_INFO/PARAMETERS/'
if call == 'one.hook.allocate'
id = info_xml.xpath('/HOOK_MESSAGE/CALL_INFO/PARAMETERS/PARAMETER[TYPE="OUT" and POSITION=2]/VALUE').text.to_i
hook_xpath += 'PARAMETER[TYPE="OUT" and POSITION=2]/VALUE'
else
id = info_xml.xpath('/HOOK_MESSAGE/CALL_INFO/PARAMETERS/PARAMETER[TYPE="IN" and POSITION=2]/VALUE').text.to_i
hook_xpath += 'PARAMETER[TYPE="IN" and POSITION=2]/VALUE'
end
id = info_xml.xpath(hook_xpath).text.to_i
if call != 'one.hook.allocate'
hook = @hooks.get_hook_by_id(id)
@hooks.delete(id)
unsubscribe(hook.filter(hook.key)) if !STATIC_FILTERS.include? hook.key
is_static = STATIC_FILTERS.include? hook.key
unsubscribe(hook.filter(hook.key)) unless is_static
end
return if call == 'one.hook.delete'
@ -514,29 +519,31 @@ class HookExecutionManager
content = Base64.decode64(content)
hook = @hooks.get_hook(type, key)
body_xml = Nokogiri::XML(content)
body = Nokogiri::XML(content)
@am.trigger_action(ACTIONS[0], 0, hook, body_xml) unless hook.nil?
@am.trigger_action(ACTIONS[0], 0, hook, body) unless hook.nil?
reload_hooks(key, body_xml) if UPDATE_CALLS.include? key
when :RETRY
body = Base64.decode64(content.split(' ')[0])
body_xml = Nokogiri::XML(body)
body = Nokogiri::XML(body)
# Get Hook
hk_id = body_xml.xpath('//HOOK_ID')[0].text.to_i
hk_id = body.xpath('//HOOK_ID')[0].text.to_i
hook = @hooks.get_hook_by_id(hk_id)
@am.trigger_action(ACTIONS[1], 0, hook, body_xml)
@am.trigger_action(ACTIONS[1], 0, hook, body)
end
end
end
def build_response_body(args, as_stdin, rc, remote_host, remote, is_retry)
def build_response_body(args, return_code, remote_host, remote, is_retry)
xml_response = "<ARGUMENTS>#{args}</ARGUMENTS>" \
"#{rc.to_xml}"
"#{return_code.to_xml}"
xml_response.concat("<REMOTE_HOST>#{remote_host}</REMOTE_HOST>") if !remote_host.empty? && remote
if !remote_host.empty? && remote
xml_response.concat("<REMOTE_HOST>#{remote_host}</REMOTE_HOST>")
end
xml_response.concat('<RETRY>yes</RETRY>') if is_retry
@ -562,12 +569,12 @@ class HookExecutionManager
@logger.error("Failure executing hook for #{hook.key}")
end
xml_response = build_response_body(params, hook.as_stdin?, rc, host, hook.remote?, false)
xml_out = build_response_body(params, rc, host, hook.remote?, false)
@requester_lock.synchronize {
@requester.send_string("#{rc.code} #{hook.id} #{xml_response}")
@requester_lock.synchronize do
@requester.send_string("#{rc.code} #{hook.id} #{xml_out}")
@requester.recv_string(ack)
}
end
@logger.error("Wrong ACK message: #{ack}.") if ack != 'ACK'
end
@ -578,16 +585,17 @@ class HookExecutionManager
args = Base64.decode64(body.xpath('//ARGUMENTS')[0].text)
host = ''
host = body.xpath('//REMOTE_HOST')[0].text unless body.xpath('//REMOTE_HOST')[0].nil?
remote_host = body.xpath('//REMOTE_HOST')[0]
host = remote_host.text unless remote_host.nil?
rc = hook.execute(@conf[:hook_base_path], args, host)
xml_response = build_response_body(args, hook.as_stdin?, rc, host, !host.empty?, true)
xml_response = build_response_body(args, rc, host, !host.empty?, true)
@requester_lock.synchronize {
@requester_lock.synchronize do
@requester.send_string("#{rc.code} #{hook.id} #{xml_response}")
@requester.recv_string(ack)
}
end
@logger.error("Wrong ACK message: #{ack}.") if ack != 'ACK'
end

View File

@ -43,7 +43,7 @@ module OpenNebula
# Factory method to create Template objects
def factory(element_xml)
OpenNebula::Hook.new(element_xml,@client)
OpenNebula::Hook.new(element_xml, @client)
end
#######################################################################
@ -54,9 +54,9 @@ module OpenNebula
def info(*args)
case args.size
when 0
info_filter(HOOK_POOL_METHODS[:info],@user_id,-1,-1)
info_filter(HOOK_POOL_METHODS[:info], @user_id, -1, -1)
when 3
info_filter(HOOK_POOL_METHODS[:info],args[0],args[1],args[2])
info_filter(HOOK_POOL_METHODS[:info], args[0], args[1], args[2])
end
end

View File

@ -149,8 +149,8 @@ module OneProvision
raise OneProvisionLoopException, errors
end
rescue StandardError => error
raise OneProvisionLoopException, error.text
rescue StandardError => e
raise OneProvisionLoopException, e.text
end
# Retries ssh connection