candlepin / rho

ssh scanner for your network
GNU General Public License v2.0
32 stars 20 forks source link

Detect command timeouts? #16

Open rrauenza opened 8 years ago

rrauenza commented 8 years ago

I was reviewing the code per my other bug report -- at one point I thought maybe the commands were timing out. I noticed a timeout isn't included in exec_command(). I'm wondering if that might be something you want to add, i.e.,

     def run_cmds(self, ssh_job,):
         for rho_cmd in ssh_job.rho_cmds:
             output = []
             for cmd_string in rho_cmd.cmd_strings:
-                stdin, stdout, stderr = self.ssh.exec_command(cmd_string)
-                output.append((stdout.read(), stderr.read()))
+                try:
+                    stdin, stdout, stderr = self.ssh.exec_command(cmd_string, timeout=30)
+                    output.append((stdout.read(), stderr.read()))
+                except paramiko.SSHException as e:
+                    log.error("Exception on %s: %s" % (ssh_job.ip, e))
             rho_cmd.populate_data(output)

Also, on the catch, perhaps stdin, stdout, stderr ought to be set to "", "", "". ...And the value of 30 was arbitrary.