diff --git a/src/im_mad/im_ssh/one_im_ssh.rb b/src/im_mad/im_ssh/one_im_ssh.rb index 4d80598d1b..d31c958af0 100755 --- a/src/im_mad/im_ssh/one_im_ssh.rb +++ b/src/im_mad/im_ssh/one_im_ssh.rb @@ -60,8 +60,6 @@ class InformationManager < OpenNebulaDriver log_lambda=lambda do |message| log(number, message) end - - retries = 2 if do_update == "1" # Use SCP to sync: @@ -74,14 +72,8 @@ class InformationManager < OpenNebulaDriver cmd_string = "#{@remote_dir}/im/run_probes #{@hypervisor} #{host}" - cmd = RemotesCommand.run(cmd_string, host, @remote_dir, log_lambda) - - while cmd.code != 0 or retries != 0 - cmd = RemotesCommand.run(cmd_string, host, @remote_dir, log_lambda) - retries = retries - 1 - sleep 1 - end - + cmd = RemotesCommand.run(cmd_string, host, @remote_dir, log_lambda, 2) + if cmd.code == 0 send_message("MONITOR", RESULT[:success], number, cmd.stdout) else diff --git a/src/mad/ruby/CommandManager.rb b/src/mad/ruby/CommandManager.rb index 1d90fe44a9..4d54ba702e 100644 --- a/src/mad/ruby/CommandManager.rb +++ b/src/mad/ruby/CommandManager.rb @@ -150,7 +150,7 @@ class RemotesCommand < SSHCommand MAGIC_RC = 42 # Creates a command and runs it - def self.run(command, host, remote_dir, logger=nil, stdin=nil) + def self.run(command, host, remote_dir, logger=nil, stdin=nil, retries=1) cmd_file = command.split(' ')[0] cmd_string = "'if [ -x \"#{cmd_file}\" ]; then #{command}; else\ @@ -158,13 +158,19 @@ class RemotesCommand < SSHCommand cmd = self.new(cmd_string, host, logger, stdin) cmd.run - + if cmd.code == MAGIC_RC cmd.update_remotes(host, remote_dir, logger) @command = command cmd.run end + + while cmd.code != 0 or retries != 0 + sleep 1 + cmd.run + retries = retries - 1 + end cmd end diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index f696875926..a45646ad3a 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -107,9 +107,13 @@ class VirtualMachineDriver < OpenNebulaDriver # ------------------------------------------------------------------------- # Execute a command associated to an action and id in a remote host. # ------------------------------------------------------------------------- - def remotes_action(command, id, host, action, remote_dir, std_in=nil) - command_exe = RemotesCommand.run( - command, host, remote_dir, log_method(id), std_in) + def remotes_action(command, id, host, action, remote_dir, std_in=nil, retries=1) + command_exe = RemotesCommand.run(command, + host, + remote_dir, + log_method(id), + std_in, + retries) if command_exe.code == 0 result = :success