|
84 | 84 | sys.exit(4) |
85 | 85 |
|
86 | 86 | __author__ = 'Hari Sekhon' |
87 | | -__version__ = '0.5' |
| 87 | +__version__ = '0.6' |
88 | 88 |
|
89 | 89 |
|
90 | 90 | class FindActiveServer(CLI): |
@@ -267,15 +267,26 @@ def check_ping(host, count=None, wait=None): |
267 | 267 | raise UnknownError("passed invalid wait '{0}' to check_ping method, must be a valid integer!"\ |
268 | 268 | .format(wait)) |
269 | 269 | log.info("pinging host '%s' (count=%s, wait=%s)", host, count, wait) |
270 | | - ping_count = '-c {0}'.format(count) |
| 270 | + count_switch = '-c' |
271 | 271 | if platform.system().lower() == 'windows': |
272 | | - ping_count = '-n {0}'.format(wait) |
273 | | - ping_wait = '-w {0}'.format(wait) |
| 272 | + count_switch = '-n' |
| 273 | + wait_switch = '-w' |
274 | 274 | if platform.system().lower() == 'darwin': |
275 | | - ping_wait = '-W {0}'.format(wait) |
| 275 | + wait_switch = '-W' |
| 276 | + # causes hang if count / wait are not cast to string |
| 277 | + cmd = ['ping', count_switch, '{0}'.format(count), wait_switch, '{0}'.format(wait), host] |
| 278 | + log.debug('cmd: %s', ' '.join(cmd)) |
| 279 | + #log.debug('args: %s', cmd) |
276 | 280 | try: |
277 | | - exitcode = subprocess.call(["ping", ping_count, ping_wait, host], |
278 | | - stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 281 | + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 282 | + #log.debug('communicating') |
| 283 | + (stdout, stderr) = process.communicate() |
| 284 | + #log.debug('waiting for child process') |
| 285 | + process.wait() |
| 286 | + exitcode = process.returncode |
| 287 | + log.debug('stdout: %s', stdout) |
| 288 | + log.debug('stderr: %s', stderr) |
| 289 | + log.debug('exitcode: %s', exitcode) |
279 | 290 | if exitcode == 0: |
280 | 291 | log.info("host '%s' responded to ping", host) |
281 | 292 | return host |
|
0 commit comments